Patchwork [2,of,2] manifest: move addlistdelta to module-level

login
register
mail settings
Submitter Augie Fackler
Date Sept. 10, 2014, 6:45 p.m.
Message ID <be53282bd69c489b3ad8.1410374751@arthedain.pit.corp.google.com>
Download mbox | patch
Permalink /patch/5770/
State Accepted
Headers show

Comments

Augie Fackler - Sept. 10, 2014, 6:45 p.m.
# HG changeset patch
# User Augie Fackler <raf@durin42.com>
# Date 1407430040 14400
#      Thu Aug 07 12:47:20 2014 -0400
# Node ID be53282bd69c489b3ad8909be0391fb04d6b512a
# Parent  9c62e343f996d00e90614f42b7148760974201f2
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.
Pierre-Yves David - Sept. 11, 2014, 12:32 p.m.
On 09/10/2014 08:45 PM, Augie Fackler wrote:
> # HG changeset patch
> # User Augie Fackler <raf@durin42.com>
> # Date 1407430040 14400
> #      Thu Aug 07 12:47:20 2014 -0400
> # Node ID be53282bd69c489b3ad8909be0391fb04d6b512a
> # Parent  9c62e343f996d00e90614f42b7148760974201f2
> manifest: move addlistdelta to module-level

killing some useless closure? Sure! pushed to the clowncopter.

consider renaming them as private to make sure clear they are used 
internally only. (_checkforbidden and _addlistdelta)

Patch

diff --git a/mercurial/manifest.py b/mercurial/manifest.py
--- a/mercurial/manifest.py
+++ b/mercurial/manifest.py
@@ -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)):