]> xenbits.xensource.com Git - people/larsk/xenproject-org-gitdm.git/commitdiff
Added a function to parse the stats per file
authorGermán Póo-Caamaño <gpoo@gnome.org>
Thu, 23 Jun 2011 01:31:08 +0000 (18:31 -0700)
committerGermán Póo-Caamaño <gpoo@gnome.org>
Thu, 23 Jun 2011 02:27:47 +0000 (19:27 -0700)
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>
gitdm

diff --git a/gitdm b/gitdm
index 87e64469676345e74c037a36d463a550d010ad4a..d5cf60ed58317b5e99aa8da406671581ec169e9c 100755 (executable)
--- 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