localrepo: unify changegroup and changegroupsubset code paths a bit
authorDirkjan Ochtman <dirkjan@ochtman.nl>
Sun, 07 Feb 2010 09:58:41 +0100
changeset 10356 bc2414948012
parent 10355 a5576908b589
child 10357 0d64b30b35c3
localrepo: unify changegroup and changegroupsubset code paths a bit
mercurial/changegroup.py
mercurial/localrepo.py
--- a/mercurial/changegroup.py	Sun Feb 07 00:51:59 2010 +0100
+++ b/mercurial/changegroup.py	Sun Feb 07 09:58:41 2010 +0100
@@ -54,6 +54,16 @@
     "HG10GZ": ("HG10GZ", lambda: zlib.compressobj()),
 }
 
+def collector(cl, mmfs, files):
+    # Gather information about changeset nodes going out in a bundle.
+    # We want to gather manifests needed and filelogs affected.
+    def collect(node):
+        c = cl.read(node)
+        for fn in c[3]:
+            files.setdefault(fn, fn)
+        mmfs.setdefault(c[0], node)
+    return collect
+
 # hgweb uses this list to communicate its preferred type
 bundlepriority = ['HG10GZ', 'HG10BZ', 'HG10UN']
 
--- a/mercurial/localrepo.py	Sun Feb 07 00:51:59 2010 +0100
+++ b/mercurial/localrepo.py	Sun Feb 07 09:58:41 2010 +0100
@@ -1716,28 +1716,6 @@
             for r in revlog.ancestors(*[revlog.rev(n) for n in hasset]):
                 msngset.pop(revlog.node(r), None)
 
-        # This is a function generating function used to set up an environment
-        # for the inner function to execute in.
-        def manifest_and_file_collector(changedfileset):
-            # This is an information gathering function that gathers
-            # information from each changeset node that goes out as part of
-            # the changegroup.  The information gathered is a list of which
-            # manifest nodes are potentially required (the recipient may
-            # already have them) and total list of all files which were
-            # changed in any changeset in the changegroup.
-            #
-            # We also remember the first changenode we saw any manifest
-            # referenced by so we can later determine which changenode 'owns'
-            # the manifest.
-            def collect_manifests_and_files(clnode):
-                c = cl.read(clnode)
-                for f in c[3]:
-                    # This is to make sure we only have one instance of each
-                    # filename string for each filename.
-                    changedfileset.setdefault(f, f)
-                msng_mnfst_set.setdefault(c[0], clnode)
-            return collect_manifests_and_files
-
         # Figure out which manifest nodes (of the ones we think might be part
         # of the changegroup) the recipient must know about and remove them
         # from the changegroup.
@@ -1838,10 +1816,11 @@
         def gengroup():
             # The set of changed files starts empty.
             changedfiles = {}
+            collect = changegroup.collector(cl, msng_mnfst_set, changedfiles)
+            
             # Create a changenode group generator that will call our functions
             # back to lookup the owning changenode and collect information.
-            group = cl.group(msng_cl_lst, identity,
-                             manifest_and_file_collector(changedfiles))
+            group = cl.group(msng_cl_lst, identity, collect)
             for chnk in group:
                 yield chnk
 
@@ -1936,12 +1915,6 @@
                 if log.linkrev(r) in revset:
                     yield log.node(r)
 
-        def changed_file_collector(changedfileset):
-            def collect_changed_files(clnode):
-                c = cl.read(clnode)
-                changedfileset.update(c[3])
-            return collect_changed_files
-
         def lookuprevlink_func(revlog):
             def lookuprevlink(n):
                 return cl.node(revlog.linkrev(revlog.rev(n)))
@@ -1950,10 +1923,11 @@
         def gengroup():
             '''yield a sequence of changegroup chunks (strings)'''
             # construct a list of all changed files
-            changedfiles = set()
+            changedfiles = {}
+            mmfs = {}
+            collect = changegroup.collector(cl, mmfs, changedfiles)
 
-            for chnk in cl.group(nodes, identity,
-                                 changed_file_collector(changedfiles)):
+            for chnk in cl.group(nodes, identity, collect):
                 yield chnk
 
             mnfst = self.manifest