manifest: move addlistdelta to module-level
authorAugie Fackler <raf@durin42.com>
Thu, 07 Aug 2014 12:47:20 -0400
changeset 22409 8f09b785b59b
parent 22408 dc97e04c12ad
child 22410 9fdbf96fc0e0
manifest: move addlistdelta to module-level Again, there's no reason for this to be inside manifest.add, so we'll define it only once.
mercurial/manifest.py
--- a/mercurial/manifest.py	Thu Aug 07 09:46:05 2014 -0400
+++ b/mercurial/manifest.py	Thu Aug 07 12:47:20 2014 -0400
@@ -49,6 +49,28 @@
                 _("'\\n' and '\\r' disallowed in filenames: %r") % f)
 
 
+# apply the changes collected during the bisect loop to our addlist
+# return a delta suitable for addrevision
+def addlistdelta(addlist, x):
+    # for large addlist arrays, building a new array is cheaper
+    # than repeatedly modifying the existing one
+    currentposition = 0
+    newaddlist = array.array('c')
+
+    for start, end, content in x:
+        newaddlist += addlist[currentposition:start]
+        if content:
+            newaddlist += array.array('c', content)
+
+        currentposition = end
+
+    newaddlist += addlist[currentposition:]
+
+    deltatext = "".join(struct.pack(">lll", start, end, len(content))
+                   + content for start, end, content in x)
+    return deltatext, newaddlist
+
+
 class manifest(revlog.revlog):
     def __init__(self, opener):
         # we expect to deal with not more than four revs at a time,
@@ -140,27 +162,6 @@
 
     def add(self, map, transaction, link, p1=None, p2=None,
             changed=None):
-        # apply the changes collected during the bisect loop to our addlist
-        # return a delta suitable for addrevision
-        def addlistdelta(addlist, x):
-            # for large addlist arrays, building a new array is cheaper
-            # than repeatedly modifying the existing one
-            currentposition = 0
-            newaddlist = array.array('c')
-
-            for start, end, content in x:
-                newaddlist += addlist[currentposition:start]
-                if content:
-                    newaddlist += array.array('c', content)
-
-                currentposition = end
-
-            newaddlist += addlist[currentposition:]
-
-            deltatext = "".join(struct.pack(">lll", start, end, len(content))
-                           + content for start, end, content in x)
-            return deltatext, newaddlist
-
         # if we're using the cache, make sure it is valid and
         # parented by the same node we're diffing against
         if not (changed and p1 and (p1 in self._mancache)):