Skip to content

Commit e902f7b

Browse files
Fixed possible exception occurring during stability value gathering.
For now, we return 100 % whenever an author is not found to have any entries in the changes log. This can happen whenever an author uses the same email but with different author names. The solution would probably be to consider these commits to belong to the same person and merge the results. This will require some additional changes to the code and a redesign in the way that author names and emails are mapped.
1 parent 02e0858 commit e902f7b

File tree

1 file changed

+13
-7
lines changed

1 file changed

+13
-7
lines changed

gitinspector/blame.py

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# coding: utf-8
22
#
3-
# Copyright © 2012-2013 Ejwa Software. All rights reserved.
3+
# Copyright © 2012-2014 Ejwa Software. All rights reserved.
44
#
55
# This file is part of gitinspector.
66
#
@@ -41,7 +41,7 @@
4141

4242
class BlameEntry:
4343
rows = 0
44-
skew = 0 # Used when calculating average code age (time-adjusted stability value).
44+
skew = 0 # Used when calculating average code age.
4545
comments = 0
4646

4747
__thread_lock__ = threading.BoundedSemaphore(NUM_THREADS)
@@ -151,6 +151,13 @@ def get_content(string):
151151
content = re.search(" \d+\)(.*)", string)
152152
return content.group(1).lstrip()
153153

154+
@staticmethod
155+
def get_stability(author, blamed_rows, changes):
156+
if author in changes.get_authorinfo_list():
157+
return 100.0 * blamed_rows / changes.get_authorinfo_list()[author].insertions
158+
159+
return 100
160+
154161
@staticmethod
155162
def get_time(string):
156163
time = re.search(" \(.*?(\d\d\d\d-\d\d-\d\d)", string)
@@ -215,8 +222,7 @@ def output_html(self):
215222
blame_xml += "<td>" + entry[0] + "</td>"
216223

217224
blame_xml += "<td>" + str(entry[1].rows) + "</td>"
218-
blame_xml += "<td>" + ("{0:.1f}".format(100.0 * entry[1].rows /
219-
self.changes.get_authorinfo_list()[entry[0]].insertions) + "</td>")
225+
blame_xml += "<td>" + ("{0:.1f}".format(Blame.get_stability(entry[0], entry[1].rows, self.changes)) + "</td>")
220226
blame_xml += "<td>" + "{0:.1f}".format(float(entry[1].skew) / entry[1].rows) + "</td>"
221227
blame_xml += "<td>" + "{0:.2f}".format(100.0 * entry[1].comments / entry[1].rows) + "</td>"
222228
blame_xml += "<td style=\"display: none\">" + work_percentage + "</td>"
@@ -257,7 +263,7 @@ def output_text(self):
257263
for i in sorted(__blame__.get_summed_blames().items()):
258264
print(i[0].ljust(20)[0:20], end=" ")
259265
print(str(i[1].rows).rjust(10), end=" ")
260-
print("{0:.1f}".format(100.0 * i[1].rows / self.changes.get_authorinfo_list()[i[0]].insertions).rjust(14), end=" ")
266+
print("{0:.1f}".format(Blame.get_stability(i[0], i[1].rows, self.changes)).rjust(14), end=" ")
261267
print("{0:.1f}".format(float(i[1].skew) / i[1].rows).rjust(12), end=" ")
262268
print("{0:.2f}".format(100.0 * i[1].comments / i[1].rows).rjust(19))
263269

@@ -271,8 +277,8 @@ def output_xml(self):
271277
name_xml = "\t\t\t\t<name>" + i[0] + "</name>\n"
272278
gravatar_xml = "\t\t\t\t<gravatar>" + gravatar.get_url(author_email) + "</gravatar>\n"
273279
rows_xml = "\t\t\t\t<rows>" + str(i[1].rows) + "</rows>\n"
274-
stability_xml = ("\t\t\t\t<stability>" + "{0:.1f}".format(100.0 * i[1].rows /
275-
self.changes.get_authorinfo_list()[i[0]].insertions) + "</stability>\n")
280+
stability_xml = ("\t\t\t\t<stability>" + "{0:.1f}".format(Blame.get_stability(i[0], i[1].rows,
281+
self.changes)) + "</stability>\n")
276282
age_xml = ("\t\t\t\t<age>" + "{0:.1f}".format(float(i[1].skew) / i[1].rows) + "</age>\n")
277283
percentage_in_comments_xml = ("\t\t\t\t<percentage-in-comments>" + "{0:.2f}".format(100.0 * i[1].comments / i[1].rows) +
278284
"</percentage-in-comments>\n")

0 commit comments

Comments
 (0)