From 82e9f2b259c61c3be8c0a49b7b18ddfbde58da9e Mon Sep 17 00:00:00 2001 From: Sverre Rabbelier Date: Sat, 7 Jun 2008 14:19:52 +0200 Subject: [PATCH] gitstats: Prefixed private methods with _ and and made parseFileDiff accept larger diffs Before, parseFileDiff died on diffs that contained hunks larger than 1, this was because it didn't parse the context information correctly. --- src/git_stats/diff.py | 24 ++++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/src/git_stats/diff.py b/src/git_stats/diff.py index c0ba023..cfdd293 100644 --- a/src/git_stats/diff.py +++ b/src/git_stats/diff.py @@ -114,7 +114,7 @@ def splitDiff(diff): return chunks -def splitFileDiff(diff): +def _splitFileDiff(diff): """Splits a file diff into chunks, one per area. Params: @@ -150,7 +150,7 @@ def splitFileDiff(diff): return header, chunks -def parseFileDiff(header, chunk): +def _parseFileDiff(header, chunk): """Takes a file diff and returns the parsed result Params: @@ -180,8 +180,8 @@ def parseFileDiff(header, chunk): a = split[0][1:] b = split[1][1:] - apos = int(a) - bpos = int(b) + apos = int(a.split(',')[0]) + bpos = int(b.split(',')[0]) result.astart = apos result.bstart = bpos @@ -217,17 +217,17 @@ def parseCommitDiff(diff): # Loop over all the file diffs and parse them for chunk in chunks: - header, filechunks = splitFileDiff(chunk) + header, filechunks = _splitFileDiff(chunk) # Loop over all the chunks and parse them for filechunk in filechunks: # Get the result and store it - fd = parseFileDiff(header, filechunk) + fd = _parseFileDiff(header, filechunk) result.append(fd) return result -def compareFileDiffs(adiff, bdiff, invert=False): +def _compareFileDiffs(adiff, bdiff, invert=False): """Compares two fileDiffs and returns whether they are equal Args: @@ -252,7 +252,7 @@ def compareFileDiffs(adiff, bdiff, invert=False): # Checked everything, accept return True -def compareDiffs(adiffs, bdiffs, compareChanges=False, invert=False): +def _compareDiffs(adiffs, bdiffs, compareChanges=False, invert=False): """Compares the two diffs and returns whether they are equal Args: @@ -273,7 +273,7 @@ def compareDiffs(adiffs, bdiffs, compareChanges=False, invert=False): # If we want to compare changes, do they match if compareChanges: # Reject if they are inequal - if not compareFileDiffs(fd, theirs, invert): + if not _compareFileDiffs(fd, theirs, invert): return False # It was indeed a match, stop searching through bdiffs @@ -286,7 +286,7 @@ def compareDiffs(adiffs, bdiffs, compareChanges=False, invert=False): # All items in adiffs checked, all had a matching pair, accept. return True -def difference(adiffs, bdiffs, compareChanges=False, invert=False): +def _difference(adiffs, bdiffs, compareChanges=False, invert=False): """Calculates the difference between two diffs and returns it Params: @@ -317,7 +317,7 @@ def difference(adiffs, bdiffs, compareChanges=False, invert=False): theirs = bfiles[key] - if not compareDiffs(fds, theirs, compareChanges, invert): + if not _compareDiffs(fds, theirs, compareChanges, invert): difference.append((fds, theirs)) return missing, difference @@ -352,7 +352,7 @@ def commitdiffEqual(original, potentialMatch, threshold=0, compareChanges=True, parsedOriginal = parseCommitDiff(diffOriginal[:-1]) parsedPotentialMatch = parseCommitDiff(diffPotentialMatch[:-1]) - missing, diff = difference(parsedOriginal, parsedPotentialMatch, compareChanges=compareChanges, invert=invert) + missing, diff = _difference(parsedOriginal, parsedPotentialMatch, compareChanges=compareChanges, invert=invert) if missing: print("Missing the following keys:") -- 2.11.4.GIT