[PATCH 2 of 5] record: move countChanges in the hunk class

Laurent Charignon lcharignon at fb.com
Tue Mar 10 12:13:00 CDT 2015


# HG changeset patch
# User Laurent Charignon <lcharignon at fb.com>
# Date 1425931699 25200
#      Mon Mar 09 13:08:19 2015 -0700
# Node ID 84edda1593c613e864e652ce42cdcaa069d4adb5
# Parent  6f6b0d8c18fd84b70009fcc6f4a88b6a883116c6
record: move countChanges in the hunk class

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

diff --git a/hgext/record.py b/hgext/record.py
--- a/hgext/record.py
+++ b/hgext/record.py
@@ -70,11 +70,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
@@ -95,7 +90,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)


More information about the Mercurial-devel mailing list