Patchwork [2,of,5,V2] record: move countChanges in the hunk class

login
register
mail settings
Submitter Laurent Charignon
Date March 10, 2015, 7:16 p.m.
Message ID <77b9e4dab19ca93c7012.1426014974@dev919.prn2.facebook.com>
Download mbox | patch
Permalink /patch/7974/
State Accepted
Headers show

Comments

Laurent Charignon - March 10, 2015, 7:16 p.m.
# HG changeset patch
# User Laurent Charignon <lcharignon@fb.com>
# Date 1425931699 25200
#      Mon Mar 09 13:08:19 2015 -0700
# Node ID 77b9e4dab19ca93c701275f8339ce78c3f088d6d
# Parent  9ec826349460426e40b8f08ea6644a77ea133db5
record: move countChanges in the hunk class

Part of a serie of patches to move record from hgext to core

Patch

diff --git a/hgext/record.py b/hgext/record.py
--- a/hgext/record.py
+++ b/hgext/record.py
@@ -69,11 +69,6 @@ 
             else:
                 yield 'other', line
 
-def countchanges(hunk):
-    """hunk -> (n+,n-)"""
-    add = len([h for h in hunk if h[0] == '+'])
-    rem = len([h for h in hunk if h[0] == '-'])
-    return add, rem
 
 class hunk(object):
     """patch hunk
@@ -94,7 +89,13 @@ 
         self.toline, self.after = trimcontext(toline, after)
         self.proc = proc
         self.hunk = hunk
-        self.added, self.removed = countchanges(self.hunk)
+        self.added, self.removed = self.countchanges(self.hunk)
+
+    def countchanges(self, hunk):
+        """hunk -> (n+,n-)"""
+        add = len([h for h in hunk if h[0] == '+'])
+        rem = len([h for h in hunk if h[0] == '-'])
+        return add, rem
 
     def write(self, fp):
         delta = len(self.before) + len(self.after)