mirror of
https://github.com/ejwa/gitinspector.git
synced 2025-01-03 11:22:15 +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):
|
for i in range(0, NUM_THREADS):
|
||||||
__thread_lock__.release()
|
__thread_lock__.release()
|
||||||
|
|
||||||
def __add__(self, other):
|
def __iadd__(self, other):
|
||||||
if other == None:
|
try:
|
||||||
return self
|
self.blames.update(other.blames)
|
||||||
|
return self;
|
||||||
self.blames.update(other.blames)
|
except AttributeError:
|
||||||
return self
|
return other;
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def is_revision(string):
|
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]),
|
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]))
|
int(self.commits[-1].date[8:10]))
|
||||||
|
|
||||||
def __add__(self, other):
|
def __iadd__(self, other):
|
||||||
if other == None:
|
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
|
return self
|
||||||
|
except AttributeError:
|
||||||
self.authors.update(other.authors)
|
return other;
|
||||||
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
|
|
||||||
|
|
||||||
def get_commits(self):
|
def get_commits(self):
|
||||||
return self.commits
|
return self.commits
|
||||||
|
|
|
@ -60,19 +60,19 @@ class Runner(object):
|
||||||
terminal.skip_escapes(not sys.stdout.isatty())
|
terminal.skip_escapes(not sys.stdout.isatty())
|
||||||
terminal.set_stdout_encoding()
|
terminal.set_stdout_encoding()
|
||||||
previous_directory = os.getcwd()
|
previous_directory = os.getcwd()
|
||||||
summed_blames = None
|
summed_blames = Blame.__new__(Blame)
|
||||||
summed_changes = None
|
summed_changes = Changes.__new__(Changes)
|
||||||
summed_metrics = None
|
summed_metrics = MetricsLogic.__new__(MetricsLogic)
|
||||||
|
|
||||||
for repo in repos:
|
for repo in repos:
|
||||||
os.chdir(repo.location)
|
os.chdir(repo.location)
|
||||||
repo = repo if len(repos) > 1 else None
|
repo = repo if len(repos) > 1 else None
|
||||||
changes = Changes(repo, self.hard)
|
changes = Changes(repo, self.hard)
|
||||||
summed_blames = Blame(repo, self.hard, self.useweeks, changes) + summed_blames
|
summed_blames += Blame(repo, self.hard, self.useweeks, changes)
|
||||||
summed_changes = changes + summed_changes
|
summed_changes += changes
|
||||||
|
|
||||||
if self.include_metrics:
|
if self.include_metrics:
|
||||||
summed_metrics = MetricsLogic() + summed_metrics
|
summed_metrics += MetricsLogic()
|
||||||
|
|
||||||
if sys.stdout.isatty() and format.is_interactive_format():
|
if sys.stdout.isatty() and format.is_interactive_format():
|
||||||
terminal.clear_row()
|
terminal.clear_row()
|
||||||
|
@ -80,7 +80,7 @@ class Runner(object):
|
||||||
os.chdir(previous_directory)
|
os.chdir(previous_directory)
|
||||||
|
|
||||||
format.output_header(repos)
|
format.output_header(repos)
|
||||||
outputable.output(ChangesOutput(changes))
|
outputable.output(ChangesOutput(summed_changes))
|
||||||
|
|
||||||
if changes.get_commits():
|
if changes.get_commits():
|
||||||
outputable.output(BlameOutput(summed_changes, summed_blames))
|
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):
|
if lines > 0 and METRIC_CYCLOMATIC_COMPLEXITY_DENSITY_THRESHOLD < cycc / float(lines):
|
||||||
self.cyclomatic_complexity_density[i.strip()] = cycc / float(lines)
|
self.cyclomatic_complexity_density[i.strip()] = cycc / float(lines)
|
||||||
|
|
||||||
def __add__(self, other):
|
def __iadd__(self, other):
|
||||||
if other == None:
|
try:
|
||||||
|
self.eloc.update(other.eloc)
|
||||||
|
self.cyclomatic_complexity.update(other.cyclomatic_complexity)
|
||||||
|
self.cyclomatic_complexity_density.update(other.cyclomatic_complexity_density)
|
||||||
return self
|
return self
|
||||||
|
except AttributeError:
|
||||||
self.eloc.update(other.eloc)
|
return other;
|
||||||
self.cyclomatic_complexity.update(other.cyclomatic_complexity)
|
|
||||||
self.cyclomatic_complexity_density.update(other.cyclomatic_complexity_density)
|
|
||||||
return self
|
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def get_cyclomatic_complexity(file_r, extension):
|
def get_cyclomatic_complexity(file_r, extension):
|
||||||
|
|
Loading…
Reference in a new issue