diff --git a/gitinspector/blame.py b/gitinspector/blame.py index d284d89..8580fe9 100644 --- a/gitinspector/blame.py +++ b/gitinspector/blame.py @@ -156,12 +156,12 @@ class Blame(object): for i in range(0, NUM_THREADS): __thread_lock__.release() - def __add__(self, other): - if other == None: - return self - - self.blames.update(other.blames) - return self + def __iadd__(self, other): + try: + self.blames.update(other.blames) + return self; + except AttributeError: + return other; @staticmethod def is_revision(string): diff --git a/gitinspector/changes.py b/gitinspector/changes.py index 4b95f89..1d1f620 100644 --- a/gitinspector/changes.py +++ b/gitinspector/changes.py @@ -230,19 +230,19 @@ class Changes(object): self.last_commit_date = datetime.date(int(self.commits[-1].date[0:4]), int(self.commits[-1].date[5:7]), int(self.commits[-1].date[8:10])) - def __add__(self, other): - if other == None: + def __iadd__(self, other): + try: + self.authors.update(other.authors) + self.authors_dateinfo.update(other.authors_dateinfo) + self.authors_by_email.update(other.authors_by_email) + self.emails_by_author.update(other.emails_by_author) + + for commit in other.commits: + bisect.insort(self.commits, commit) + return self - - self.authors.update(other.authors) - self.authors_dateinfo.update(other.authors_dateinfo) - self.authors_by_email.update(other.authors_by_email) - self.emails_by_author.update(other.emails_by_author) - - for commit in other.commits: - bisect.insort(self.commits, commit) - - return self + except AttributeError: + return other; def get_commits(self): return self.commits diff --git a/gitinspector/gitinspector.py b/gitinspector/gitinspector.py index d8a19be..b725fb2 100644 --- a/gitinspector/gitinspector.py +++ b/gitinspector/gitinspector.py @@ -60,19 +60,19 @@ class Runner(object): terminal.skip_escapes(not sys.stdout.isatty()) terminal.set_stdout_encoding() previous_directory = os.getcwd() - summed_blames = None - summed_changes = None - summed_metrics = None + summed_blames = Blame.__new__(Blame) + summed_changes = Changes.__new__(Changes) + summed_metrics = MetricsLogic.__new__(MetricsLogic) for repo in repos: os.chdir(repo.location) repo = repo if len(repos) > 1 else None changes = Changes(repo, self.hard) - summed_blames = Blame(repo, self.hard, self.useweeks, changes) + summed_blames - summed_changes = changes + summed_changes + summed_blames += Blame(repo, self.hard, self.useweeks, changes) + summed_changes += changes if self.include_metrics: - summed_metrics = MetricsLogic() + summed_metrics + summed_metrics += MetricsLogic() if sys.stdout.isatty() and format.is_interactive_format(): terminal.clear_row() @@ -80,7 +80,7 @@ class Runner(object): os.chdir(previous_directory) format.output_header(repos) - outputable.output(ChangesOutput(changes)) + outputable.output(ChangesOutput(summed_changes)) if changes.get_commits(): outputable.output(BlameOutput(summed_changes, summed_blames)) diff --git a/gitinspector/metrics.py b/gitinspector/metrics.py index d683e28..d4aeead 100644 --- a/gitinspector/metrics.py +++ b/gitinspector/metrics.py @@ -69,14 +69,14 @@ class MetricsLogic(object): if lines > 0 and METRIC_CYCLOMATIC_COMPLEXITY_DENSITY_THRESHOLD < cycc / float(lines): self.cyclomatic_complexity_density[i.strip()] = cycc / float(lines) - def __add__(self, other): - if other == None: + def __iadd__(self, other): + try: + self.eloc.update(other.eloc) + self.cyclomatic_complexity.update(other.cyclomatic_complexity) + self.cyclomatic_complexity_density.update(other.cyclomatic_complexity_density) return self - - self.eloc.update(other.eloc) - self.cyclomatic_complexity.update(other.cyclomatic_complexity) - self.cyclomatic_complexity_density.update(other.cyclomatic_complexity_density) - return self + except AttributeError: + return other; @staticmethod def get_cyclomatic_complexity(file_r, extension):