summaryrefslogtreecommitdiff
path: root/gitdm
diff options
context:
space:
mode:
authorGermán Póo-Caamaño <gpoo@gnome.org>2011-06-22 18:31:08 -0700
committerGermán Póo-Caamaño <gpoo@gnome.org>2011-06-22 19:27:47 -0700
commit27bb2eca315c6c0a0eb49af4402cc5c81815047c (patch)
tree4a975bd0dbdd6615009352f86820e3ccab715a1d /gitdm
parent70df53f20f22f3a591a1e3dbf30fb6c934be1c78 (diff)
Added a function to parse the stats per file
In order to make cleaner the code, I created a function that parses a numstat line, which is useful to determine the modified filename, and to calculate lines added and removed. Signed-off-by: Germán Póo-Caamaño <gpoo@gnome.org>
Diffstat (limited to 'gitdm')
-rwxr-xr-xgitdm40
1 files changed, 26 insertions, 14 deletions
diff --git a/gitdm b/gitdm
index 87e6446..d5cf60e 100755
--- a/gitdm
+++ b/gitdm
@@ -161,6 +161,30 @@ class patch:
def addreporter (self, reporter):
self.reports.append (reporter)
+
+def parse_numstat(line, file_filter):
+ """
+ Receive a line of text, determine if fits a numstat line and
+ parse the added and removed lines as well as the file type.
+ """
+ m = patterns['numstat'].match (line)
+ if m:
+ filename = m.group (3)
+ # If we have a file filter, check for file lines.
+ if file_filter and not file_filter.search (filename):
+ return None, None, None
+
+ try:
+ added = int (m.group (1))
+ removed = int (m.group (2))
+ except ValueError:
+ # A binary file (image, etc.) is marked with '-'
+ added = removed = 0
+
+ return filename, added, removed
+ else:
+ return None, None, None
+
#
# The core hack for grabbing the information about a changeset.
#
@@ -272,20 +296,8 @@ def grabpatch():
else:
# Get the statistics (lines added/removes) using numstats
# and without requiring a diff (--numstat instead -p)
- m = patterns['numstat'].match (Line)
- if m:
- filename = m.group(3)
- # If we have a file filter, check for file lines.
- if FileFilter and not FileFilter.search (filename):
- continue
-
- try:
- added = int(m.group(1))
- removed = int(m.group(2))
- except ValueError:
- # A binary file (image, etc.) is marked with '-'
- added = removed = 0
-
+ (filename, added, removed) = parse_numstat (Line, FileFilter)
+ if filename:
p.added += added
p.removed += removed