From 55505a6d7a495524ee12a55b0843663259250c97 Mon Sep 17 00:00:00 2001 From: Sverre Rabbelier Date: Sun, 20 Jul 2008 23:45:38 +0200 Subject: [PATCH] gitstats: Replace backslashes with parens to do line continuation In python one can use a backslash at the end of a line to do line continuations. A better alternative however, is to surround the long lines in parens and have python's auto unpacking do it's magic on a tuple with only one element. --- src/git_stats/author.py | 4 ++-- src/git_stats/branch.py | 4 ++-- src/git_stats/bug.py | 16 ++++++++-------- src/git_stats/diff.py | 16 ++++++++-------- src/git_stats/matcher.py | 4 ++-- src/git_stats/testing.py | 4 ++-- 6 files changed, 24 insertions(+), 24 deletions(-) diff --git a/src/git_stats/author.py b/src/git_stats/author.py index 4e0e490..769330d 100644 --- a/src/git_stats/author.py +++ b/src/git_stats/author.py @@ -18,8 +18,8 @@ class Activity: self.id = [] def __str__(self): - return "%4d: %5d+ %5d- %5d~" % \ - (self.count, self.added, self.deleted, self.added-self.deleted) + return ("%4d: %5d+ %5d- %5d~" % + (self.count, self.added, self.deleted, self.added-self.deleted)) def activityInArea(log): """Parses the specified file containing commit logs. diff --git a/src/git_stats/branch.py b/src/git_stats/branch.py index 8c9f333..d30d449 100644 --- a/src/git_stats/branch.py +++ b/src/git_stats/branch.py @@ -41,8 +41,8 @@ class Metric: self.dilution = "" def __str__(self): - res = "Branch %s, dilution: %d." % \ - (prettyName(self.branch), self.dilution) + res = ("Branch %s, dilution: %d." % + (prettyName(self.branch), self.dilution)) return res diff --git a/src/git_stats/bug.py b/src/git_stats/bug.py index 15e4bcd..e83e1ea 100644 --- a/src/git_stats/bug.py +++ b/src/git_stats/bug.py @@ -46,10 +46,10 @@ class CommitInfo: Returns: Whether branches, reverts, msg_matches or diff_matches is set. """ - return self.branches \ - or self.reverts \ - or self.msg_matches \ - or self.diff_matches + return (self.branches + or self.reverts + or self.msg_matches + or self.diff_matches) def bugfixRating(self): """Calculates the bugfix rating for this commit @@ -187,13 +187,13 @@ def determineType(target, memory, options): parsed_diffs=memory.parsed_diffs, touched_files=memory.touched_files) - msg_matches = options.msg_filter and \ - commit.commitmsgMatches(target, options.msg_filter) + msg_matches = (options.msg_filter and + commit.commitmsgMatches(target, options.msg_filter)) - diff_matches = options.diff_filter and \ + diff_matches = (options.diff_filter and commit.commitdiffMatches( target, options.diff_filter, - raw_diffs=memory.raw_diffs) + raw_diffs=memory.raw_diffs)) result = CommitInfo(target, options) diff --git a/src/git_stats/diff.py b/src/git_stats/diff.py index 04fc808..31a0f7a 100644 --- a/src/git_stats/diff.py +++ b/src/git_stats/diff.py @@ -246,20 +246,20 @@ def _compareDiffs(adiffs, bdiffs, compareChanges=False, invert=False): for theirs in bdiffs: # Check for empty diffs - if ((not fd.linesAdded and not fd.linesDeleted) and \ - (theirs.linesAdded or theirs.linesDeleted)) or \ - ((not theirs.linesAdded and not theirs.linesDeleted) and\ - (fd.linesAdded and fd.linesDeleted)): + if (((not fd.linesAdded and not fd.linesDeleted) and + (theirs.linesAdded or theirs.linesDeleted)) or + ((not theirs.linesAdded and not theirs.linesDeleted) and + (fd.linesAdded and fd.linesDeleted))): return False # Check if both are empty diffs - if not fd.linesAdded and not theirs.linesAdded and \ - not fd.linesDeleted and not theirs.linesDeleted: + if (not fd.linesAdded and not theirs.linesAdded and + not fd.linesDeleted and not theirs.linesDeleted): return True # Looks like we have a match - if (theirs.astart <= fd.astart and theirs.bstart >= fd.bstart) or \ - (invert and theirs.astart <= fd.bstart and theirs.bstart >= fd.astart): + if ((theirs.astart <= fd.astart and theirs.bstart >= fd.bstart) or + (invert and theirs.astart <= fd.bstart and theirs.bstart >= fd.astart)): # If we want to compare changes, do they match if compareChanges: diff --git a/src/git_stats/matcher.py b/src/git_stats/matcher.py index 68883ae..749eea7 100644 --- a/src/git_stats/matcher.py +++ b/src/git_stats/matcher.py @@ -16,8 +16,8 @@ def calculateDiffSize(difference): # Take each line and only count if it is part of the diff for line in difference: - if len(line) == 1 or line[1] == '\t' and \ - (line[0] == '+' or line[0] == '-'): + if (len(line) == 1 or line[1] == '\t' and + (line[0] == '+' or line[0] == '-')): size += 1 return size diff --git a/src/git_stats/testing.py b/src/git_stats/testing.py index 4309542..abc66fc 100644 --- a/src/git_stats/testing.py +++ b/src/git_stats/testing.py @@ -96,8 +96,8 @@ class GitResult(unittest.TestResult): """Outputs an error message for the specified test """ - msg = "* FAIL %d: %s\n\t %s\n" % \ - (self.test_count, test.shortDescription(), test.__str__()) + msg = ("* FAIL %d: %s\n\t %s\n" % + (self.test_count, test.shortDescription(), test.__str__())) self.output.error(msg) def addError(self, test, err): -- 2.11.4.GIT