Skip to content

Replace 'row' with 'line' #116

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 7 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion docs/gitinspector.1
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ Show statistics and information in a way that is formatted for grading of studen
.PP
\fB\-H, \-\-hard\fR[=BOOL]
.RS 4
Track rows and look for duplicates harder; this can be quite slow with big repositories
Track lines and look for duplicates harder; this can be quite slow with big repositories
.RE
.PP
\fB\-l, \-\-list\-file\-types\fR[=BOOL]
Expand Down
2 changes: 1 addition & 1 deletion docs/gitinspector.html
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
</dd><dt><span class="term">
<span class="strong"><strong>-H, --hard</strong></span>[=BOOL]
</span></dt><dd>
Track rows and look for duplicates harder; this can be quite slow with big repositories
Track lines and look for duplicates harder; this can be quite slow with big repositories
</dd><dt><span class="term">
<span class="strong"><strong>-l, --list-file-types</strong></span>[=BOOL]
</span></dt><dd>
Expand Down
2 changes: 1 addition & 1 deletion docs/gitinspector.txt
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ Mandatory arguments to long options are mandatory for short options too. Boolean
Show statistics and information in a way that is formatted for grading of student projects; this is the same as supplying the options *-HlmrTw*

*-H, --hard*[=BOOL]::
Track rows and look for duplicates harder; this can be quite slow with big repositories
Track lines and look for duplicates harder; this can be quite slow with big repositories

*-l, --list-file-types*[=BOOL]::
List all the file extensions available in the current branch of the repository
Expand Down
40 changes: 20 additions & 20 deletions gitinspector/blame.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
NUM_THREADS = multiprocessing.cpu_count()

class BlameEntry(object):
rows = 0
lines = 0
skew = 0 # Used when calculating average code age.
comments = 0

Expand Down Expand Up @@ -82,7 +82,7 @@ def __handle_blamechunk_content__(self, content):
self.blames[(author, self.filename)] = BlameEntry()

self.blames[(author, self.filename)].comments += comments
self.blames[(author, self.filename)].rows += 1
self.blames[(author, self.filename)].lines += 1

if (self.blamechunk_time - self.changes.first_commit_date).days > 0:
self.blames[(author, self.filename)].skew += ((self.changes.last_commit_date - self.blamechunk_time).days /
Expand All @@ -92,18 +92,18 @@ def __handle_blamechunk_content__(self, content):

def run(self):
git_blame_r = subprocess.Popen(self.blame_command, bufsize=1, stdout=subprocess.PIPE).stdout
rows = git_blame_r.readlines()
lines = git_blame_r.readlines()
git_blame_r.close()

self.__clear_blamechunk_info__()

#pylint: disable=W0201
for j in range(0, len(rows)):
row = rows[j].decode("utf-8", "replace").strip()
keyval = row.split(" ", 2)
for j in range(0, len(lines)):
line = lines[j].decode("utf-8", "replace").strip()
keyval = line.split(" ", 2)

if self.blamechunk_is_last:
self.__handle_blamechunk_content__(row)
self.__handle_blamechunk_content__(line)
self.__clear_blamechunk_info__()
elif keyval[0] == "boundary":
self.blamechunk_is_prior = True
Expand All @@ -118,7 +118,7 @@ def run(self):

__thread_lock__.release() # Lock controlling the number of threads running

PROGRESS_TEXT = N_("Checking how many rows belong to each author (2 of 2): {0:.0f}%")
PROGRESS_TEXT = N_("Checking how many lines belong to each author (2 of 2): {0:.0f}%")

class Blame(object):
def __init__(self, repo, hard, useweeks, changes):
Expand All @@ -134,18 +134,18 @@ def __init__(self, repo, hard, useweeks, changes):
if repo != None:
progress_text = "[%s] " % repo.name + progress_text

for i, row in enumerate(lines):
row = row.strip().decode("unicode_escape", "ignore")
row = row.encode("latin-1", "replace")
row = row.decode("utf-8", "replace").strip("\"").strip("'").strip()
for i, line in enumerate(lines):
line = line.strip().decode("unicode_escape", "ignore")
line = line.encode("latin-1", "replace")
line = line.decode("utf-8", "replace").strip("\"").strip("'").strip()

if FileDiff.get_extension(row) in extensions.get_located() and \
FileDiff.is_valid_extension(row) and not filtering.set_filtered(FileDiff.get_filename(row)):
if FileDiff.get_extension(line) in extensions.get_located() and \
FileDiff.is_valid_extension(line) and not filtering.set_filtered(FileDiff.get_filename(line)):
blame_command = filter(None, ["git", "blame", "--line-porcelain", "-w"] + \
(["-C", "-C", "-M"] if hard else []) +
[interval.get_since(), interval.get_ref(), "--", row])
thread = BlameThread(useweeks, changes, blame_command, FileDiff.get_extension(row),
self.blames, row.strip())
[interval.get_since(), interval.get_ref(), "--", line])
thread = BlameThread(useweeks, changes, blame_command, FileDiff.get_extension(line),
self.blames, line.strip())
thread.daemon = True
thread.start()

Expand Down Expand Up @@ -177,10 +177,10 @@ def is_revision(string):
return revision.group(1).strip()

@staticmethod
def get_stability(author, blamed_rows, changes):
def get_stability(author, blamed_lines, changes):
if author in changes.get_authorinfo_list():
author_insertions = changes.get_authorinfo_list()[author].insertions
return 100 if author_insertions == 0 else 100.0 * blamed_rows / author_insertions
return 100 if author_insertions == 0 else 100.0 * blamed_lines / author_insertions
return 100

@staticmethod
Expand All @@ -194,7 +194,7 @@ def get_summed_blames(self):
if summed_blames.get(i[0][0], None) == None:
summed_blames[i[0][0]] = BlameEntry()

summed_blames[i[0][0]].rows += i[1].rows
summed_blames[i[0][0]].lines += i[1].lines
summed_blames[i[0][0]].skew += i[1].skew
summed_blames[i[0][0]].comments += i[1].comments

Expand Down
4 changes: 2 additions & 2 deletions gitinspector/format.py
Original file line number Diff line number Diff line change
Expand Up @@ -106,8 +106,8 @@ def output_header(repos):
repos_string, localization.get_date()),
show_minor_authors=_("Show minor authors"),
hide_minor_authors=_("Hide minor authors"),
show_minor_rows=_("Show rows with minor work"),
hide_minor_rows=_("Hide rows with minor work")))
show_minor_lines=_("Show lines with minor work"),
hide_minor_lines=_("Hide lines with minor work")))
elif __selected_format__ == "json":
print("{\n\t\"gitinspector\": {")
print("\t\t\"version\": \"" + version.__version__ + "\",")
Expand Down
2 changes: 1 addition & 1 deletion gitinspector/gitinspector.py
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ def process(self, repos):
summed_metrics += MetricsLogic()

if sys.stdout.isatty() and format.is_interactive_format():
terminal.clear_row()
terminal.clear_line()
else:
os.chdir(previous_directory)

Expand Down
2 changes: 1 addition & 1 deletion gitinspector/help.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@
is formatted for grading of student
projects; this is the same as supplying the
options -HlmrTw
-H, --hard[=BOOL] track rows and look for duplicates harder;
-H, --hard[=BOOL] track lines and look for duplicates harder;
this can be quite slow with big repositories
-l, --list-file-types[=BOOL] list all the file extensions available in the
current branch of the repository
Expand Down
30 changes: 15 additions & 15 deletions gitinspector/html/html.header
Original file line number Diff line number Diff line change
Expand Up @@ -10,19 +10,19 @@
<script type="application/javascript">{jquery_flot_resize}</script>
<script type="application/javascript">
$(document).ready(function() {{
var row = 0;
var line = 0;
var MINOR_AUTHOR_PERCENTAGE = 1.00;
var isReversed = false;

var colorRows = function() {{
var colorLines = function() {{
$(this).removeClass("odd");

if (row++ % 2 == 1) {{
if (line++ % 2 == 1) {{
$(this).addClass("odd");
}}

if(this == $(this).parent().find("tr:visible").get(-1)) {{
row = 0;
line = 0;
}}
}}

Expand Down Expand Up @@ -52,15 +52,15 @@
return parseFloat(this.innerHTML) < MINOR_AUTHOR_PERCENTAGE;
}}).parent().hide();

$("table.git tbody tr:visible").each(colorRows);
$("table.git tbody tr:visible").each(colorLines);

$("table#changes, table#blame").tablesorter({{
sortList: [[0,0]],
headers: {{
0: {{ sorter: "text" }}
}}
}}).bind("sortEnd", function() {{
$(this).find("tbody tr:visible").each(colorRows);
$(this).find("tbody tr:visible").each(colorLines);
}});

$("table#changes thead tr th, table#blame thead tr th").click(function() {{
Expand Down Expand Up @@ -91,20 +91,20 @@

if (this.clicked) {{
this.innerHTML = "{hide_minor_authors} (" + this.hiddenCount + ") &and;";
$(this).parent().parent().parent().find("tbody tr").show().each(colorRows);
$(this).parent().parent().parent().find("tbody tr").show().each(colorLines);
}} else {{
this.innerHTML = "{show_minor_authors} (" + this.hiddenCount + ") &or;";
$(this).parent().parent().parent().find("tbody tr td:last-child").filter(function() {{
return parseFloat(this.innerHTML) < MINOR_AUTHOR_PERCENTAGE;
}}).parent().hide();
$("table.git tbody tr:visible").each(colorRows);
$("table.git tbody tr:visible").each(colorLines);
}}
}});

filterResponsibilities();
var hiddenResponsibilitiesCount = $("div#responsibilities div h3:hidden").length;
if (hiddenResponsibilitiesCount > 0) {{
$("div#responsibilities div h3:visible").each(colorRows);
$("div#responsibilities div h3:visible").each(colorLines);
$("div#responsibilities").prepend("<div class=\"button\">{show_minor_authors} (" + hiddenResponsibilitiesCount + ") &or;</div>");

$("div#responsibilities div.button").click(function() {{
Expand All @@ -123,18 +123,18 @@
filterTimeLine();
var hiddenTimelineCount = $("div#timeline table.git tbody tr:hidden").length;
if (hiddenTimelineCount > 0) {{
$("div#timeline table.git tbody tr:visible").each(colorRows);
$("div#timeline").prepend("<div class=\"button\">{show_minor_rows} (" + hiddenTimelineCount + ") &or;</div>");
$("div#timeline table.git tbody tr:visible").each(colorLines);
$("div#timeline").prepend("<div class=\"button\">{show_minor_lines} (" + hiddenTimelineCount + ") &or;</div>");

$("div#timeline div.button").click(function() {{
this.clicked = !this.clicked;
if (this.clicked) {{
this.innerHTML = "{hide_minor_rows} (" + hiddenTimelineCount + ") &and;";
$("div#timeline table.git tbody tr").show().each(colorRows);
this.innerHTML = "{hide_minor_lines} (" + hiddenTimelineCount + ") &and;";
$("div#timeline table.git tbody tr").show().each(colorLines);
}} else {{
this.innerHTML = "{show_minor_rows} (" + hiddenTimelineCount + ") &or;";
this.innerHTML = "{show_minor_lines} (" + hiddenTimelineCount + ") &or;";
filterTimeLine();
$("div#timeline table.git tbody tr:visible").each(colorRows);
$("div#timeline table.git tbody tr:visible").each(colorLines);
}}
}});
}}
Expand Down
48 changes: 24 additions & 24 deletions gitinspector/output/blameoutput.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
from ..blame import Blame
from .outputable import Outputable

BLAME_INFO_TEXT = N_("Below are the number of rows from each author that have survived and are still "
BLAME_INFO_TEXT = N_("Below are the number of lines from each author that have survived and are still "
"intact in the current revision")

class BlameOutput(Outputable):
Expand All @@ -43,17 +43,17 @@ def output_html(self):
blame_xml = "<div><div class=\"box\">"
blame_xml += "<p>" + _(BLAME_INFO_TEXT) + ".</p><div><table id=\"blame\" class=\"git\">"
blame_xml += "<thead><tr> <th>{0}</th> <th>{1}</th> <th>{2}</th> <th>{3}</th> <th>{4}</th> </tr></thead>".format(
_("Author"), _("Rows"), _("Stability"), _("Age"), _("% in comments"))
_("Author"), _("Lines"), _("Stability"), _("Age"), _("% in comments"))
blame_xml += "<tbody>"
chart_data = ""
blames = sorted(self.blame.get_summed_blames().items())
total_blames = 0

for i in blames:
total_blames += i[1].rows
total_blames += i[1].lines

for i, entry in enumerate(blames):
work_percentage = str("{0:.2f}".format(100.0 * entry[1].rows / total_blames))
work_percentage = str("{0:.2f}".format(100.0 * entry[1].lines / total_blames))
blame_xml += "<tr " + ("class=\"odd\">" if i % 2 == 1 else ">")

if format.get_selected() == "html":
Expand All @@ -62,10 +62,10 @@ def output_html(self):
else:
blame_xml += "<td>" + entry[0] + "</td>"

blame_xml += "<td>" + str(entry[1].rows) + "</td>"
blame_xml += "<td>" + ("{0:.1f}".format(Blame.get_stability(entry[0], entry[1].rows, self.changes)) + "</td>")
blame_xml += "<td>" + "{0:.1f}".format(float(entry[1].skew) / entry[1].rows) + "</td>"
blame_xml += "<td>" + "{0:.2f}".format(100.0 * entry[1].comments / entry[1].rows) + "</td>"
blame_xml += "<td>" + str(entry[1].lines) + "</td>"
blame_xml += "<td>" + ("{0:.1f}".format(Blame.get_stability(entry[0], entry[1].lines, self.changes)) + "</td>")
blame_xml += "<td>" + "{0:.1f}".format(float(entry[1].skew) / entry[1].lines) + "</td>"
blame_xml += "<td>" + "{0:.2f}".format(100.0 * entry[1].comments / entry[1].lines) + "</td>"
blame_xml += "<td style=\"display: none\">" + work_percentage + "</td>"
blame_xml += "</tr>"
chart_data += "{{label: {0}, data: {1}}}".format(json.dumps(entry[0]), work_percentage)
Expand Down Expand Up @@ -104,13 +104,13 @@ def output_json(self):
name_json = "\t\t\t\t\"name\": \"" + i[0] + "\",\n"
email_json = "\t\t\t\t\"email\": \"" + author_email + "\",\n"
gravatar_json = "\t\t\t\t\"gravatar\": \"" + gravatar.get_url(author_email) + "\",\n"
rows_json = "\t\t\t\t\"rows\": " + str(i[1].rows) + ",\n"
stability_json = ("\t\t\t\t\"stability\": " + "{0:.1f}".format(Blame.get_stability(i[0], i[1].rows,
lines_json = "\t\t\t\t\"lines\": " + str(i[1].lines) + ",\n"
stability_json = ("\t\t\t\t\"stability\": " + "{0:.1f}".format(Blame.get_stability(i[0], i[1].lines,
self.changes)) + ",\n")
age_json = ("\t\t\t\t\"age\": " + "{0:.1f}".format(float(i[1].skew) / i[1].rows) + ",\n")
age_json = ("\t\t\t\t\"age\": " + "{0:.1f}".format(float(i[1].skew) / i[1].lines) + ",\n")
percentage_in_comments_json = ("\t\t\t\t\"percentage_in_comments\": " +
"{0:.2f}".format(100.0 * i[1].comments / i[1].rows) + "\n")
blame_json += ("{\n" + name_json + email_json + gravatar_json + rows_json + stability_json + age_json +
"{0:.2f}".format(100.0 * i[1].comments / i[1].lines) + "\n")
blame_json += ("{\n" + name_json + email_json + gravatar_json + lines_json + stability_json + age_json +
percentage_in_comments_json + "\t\t\t},")
else:
blame_json = blame_json[:-1]
Expand All @@ -119,18 +119,18 @@ def output_json(self):

def output_text(self):
if sys.stdout.isatty() and format.is_interactive_format():
terminal.clear_row()
terminal.clear_line()

print(textwrap.fill(_(BLAME_INFO_TEXT) + ":", width=terminal.get_size()[0]) + "\n")
terminal.printb(terminal.ljust(_("Author"), 21) + terminal.rjust(_("Rows"), 10) + terminal.rjust(_("Stability"), 15) +
terminal.printb(terminal.ljust(_("Author"), 21) + terminal.rjust(_("Lines"), 10) + terminal.rjust(_("Stability"), 15) +
terminal.rjust(_("Age"), 13) + terminal.rjust(_("% in comments"), 20))

for i in sorted(self.blame.get_summed_blames().items()):
print(terminal.ljust(i[0], 20)[0:20 - terminal.get_excess_column_count(i[0])], end=" ")
print(str(i[1].rows).rjust(10), end=" ")
print("{0:.1f}".format(Blame.get_stability(i[0], i[1].rows, self.changes)).rjust(14), end=" ")
print("{0:.1f}".format(float(i[1].skew) / i[1].rows).rjust(12), end=" ")
print("{0:.2f}".format(100.0 * i[1].comments / i[1].rows).rjust(19))
print(str(i[1].lines).rjust(10), end=" ")
print("{0:.1f}".format(Blame.get_stability(i[0], i[1].lines, self.changes)).rjust(14), end=" ")
print("{0:.1f}".format(float(i[1].skew) / i[1].lines).rjust(12), end=" ")
print("{0:.2f}".format(100.0 * i[1].comments / i[1].lines).rjust(19))

def output_xml(self):
message_xml = "\t\t<message>" + _(BLAME_INFO_TEXT) + "</message>\n"
Expand All @@ -142,13 +142,13 @@ def output_xml(self):
name_xml = "\t\t\t\t<name>" + i[0] + "</name>\n"
email_xml = "\t\t\t\t<email>" + author_email + "</email>\n"
gravatar_xml = "\t\t\t\t<gravatar>" + gravatar.get_url(author_email) + "</gravatar>\n"
rows_xml = "\t\t\t\t<rows>" + str(i[1].rows) + "</rows>\n"
stability_xml = ("\t\t\t\t<stability>" + "{0:.1f}".format(Blame.get_stability(i[0], i[1].rows,
lines_xml = "\t\t\t\t<lines>" + str(i[1].lines) + "</lines>\n"
stability_xml = ("\t\t\t\t<stability>" + "{0:.1f}".format(Blame.get_stability(i[0], i[1].lines,
self.changes)) + "</stability>\n")
age_xml = ("\t\t\t\t<age>" + "{0:.1f}".format(float(i[1].skew) / i[1].rows) + "</age>\n")
percentage_in_comments_xml = ("\t\t\t\t<percentage-in-comments>" + "{0:.2f}".format(100.0 * i[1].comments / i[1].rows) +
age_xml = ("\t\t\t\t<age>" + "{0:.1f}".format(float(i[1].skew) / i[1].lines) + "</age>\n")
percentage_in_comments_xml = ("\t\t\t\t<percentage-in-comments>" + "{0:.2f}".format(100.0 * i[1].comments / i[1].lines) +
"</percentage-in-comments>\n")
blame_xml += ("\t\t\t<author>\n" + name_xml + email_xml + gravatar_xml + rows_xml + stability_xml +
blame_xml += ("\t\t\t<author>\n" + name_xml + email_xml + gravatar_xml + lines_xml + stability_xml +
age_xml + percentage_in_comments_xml + "\t\t\t</author>\n")

print("\t<blame>\n" + message_xml + "\t\t<authors>\n" + blame_xml + "\t\t</authors>\n\t</blame>")
4 changes: 2 additions & 2 deletions gitinspector/output/responsibilitiesoutput.py
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ def output_json(self):
for j, entry in enumerate(responsibilities):
resp_json += "{\n"
resp_json += "\t\t\t\t\t\"name\": \"" + entry[1] + "\",\n"
resp_json += "\t\t\t\t\t\"rows\": " + str(entry[0]) + "\n"
resp_json += "\t\t\t\t\t\"lines\": " + str(entry[0]) + "\n"
resp_json += "\t\t\t\t},"

if j >= 9:
Expand Down Expand Up @@ -131,7 +131,7 @@ def output_xml(self):
for j, entry in enumerate(responsibilities):
resp_xml += "\t\t\t\t\t<file>\n"
resp_xml += "\t\t\t\t\t\t<name>" + entry[1] + "</name>\n"
resp_xml += "\t\t\t\t\t\t<rows>" + str(entry[0]) + "</rows>\n"
resp_xml += "\t\t\t\t\t\t<lines>" + str(entry[0]) + "</lines>\n"
resp_xml += "\t\t\t\t\t</file>\n"

if j >= 9:
Expand Down
Loading