mirror of
https://github.com/ejwa/gitinspector.git
synced 2024-11-16 00:28:25 +01:00
Repositories are now merged with __iadd__() instead of __add__().
Thus, we are overriding the "+=" operator instead of "+". This implementation results in a much cleaner solution as we were directly updating "self" when overriding __add__(), something which isn't really an acceptable solution as we were changing the supplied in-parameters.
This commit is contained in:
parent
9bd4b979b3
commit
ecc67a31a5
4 changed files with 32 additions and 32 deletions
|
@ -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):
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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))
|
||||
|
|
|
@ -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):
|
||||
|
|
Loading…
Reference in a new issue