[PATCH 2 of 5] Adding bundle -r, which will only bundle the changesets needed to reach the

Eric Hopper hopper at omnifarious.org
Fri Sep 30 12:10:55 CDT 2005


# HG changeset patch
# User Eric Hopper <hopper at omnifarious.org>
# Node ID e91ea9bb945d76c0f58fcc030d501e650904fddb
# Parent  0e58a4547982146b59a93500b34b785dc5095eb5
Adding bundle -r, which will only bundle the changesets needed to reach the
given revision.

diff -r 0e58a4547982 -r e91ea9bb945d mercurial/commands.py
--- a/mercurial/commands.py	Fri Sep 30 04:12:53 2005
+++ b/mercurial/commands.py	Fri Sep 30 15:36:18 2005
@@ -554,8 +554,11 @@
     f = open(fname, "wb")
     dest = ui.expandpath(dest)
     other = hg.repository(ui, dest)
+    node = None
+    if opts['rev']:
+        node = repo.lookup(opts['rev'])
     o = repo.findoutgoing(other)
-    cg = repo.changegroup(o)
+    cg = repo.changegroup(o, node)
 
     try:
         f.write("HG10")
@@ -1763,7 +1766,7 @@
          'hg annotate [OPTION]... FILE...'),
     "bundle":
         (bundle,
-         [],
+         [('r', 'rev', '', 'revision')],
          'hg bundle FILE DEST'),
     "cat":
         (cat,
diff -r 0e58a4547982 -r e91ea9bb945d mercurial/localrepo.py
--- a/mercurial/localrepo.py	Fri Sep 30 04:12:53 2005
+++ b/mercurial/localrepo.py	Fri Sep 30 15:36:18 2005
@@ -726,6 +726,50 @@
 
         return nl
 
+    def newertarget(self, nodes, targetnode):
+        import sys
+        self.ui.debug("nodes: [%s]\n" % (', '.join(map(short, nodes),)))
+        self.ui.debug("targetnode: %s\n" % (short(targetnode),))
+        cl = self.changelog
+        targetrev = lowestrev = cl.rev(targetnode)
+
+        # find the lowest numbered node
+        for n in nodes:
+            i = cl.rev(n)
+            if i > targetrev:
+                continue
+            lowestrev = min(lowestrev, cl.rev(n))
+
+        self.ui.debug('%u:%u\n' % (lowestrev, targetrev))
+        selected = {targetnode: 1}
+        prunedset = selected.copy()
+        for i in xrange(targetrev, lowestrev, -1):
+            n = cl.node(i)
+            if n in prunedset:
+                for p in cl.parents(n):
+                    if (p != nullid) and cl.rev(p) >= lowestrev:
+                        prunedset[p] = 1
+        self.ui.debug('prunedset contains %u nodes.\n' % (len(prunedset),))
+        sendany = False
+        for n in nodes:
+            if n in prunedset:
+                sendany = True
+                selected[n] = 1
+        if not sendany:
+            self.ui.debug("No outgoing nodes needed.\n")
+            return []
+
+        for i in xrange(lowestrev, targetrev):
+            n = cl.node(i)
+            if n not in prunedset:
+                continue
+            if n not in selected: # not listed yet
+                for p in cl.parents(n):
+                    if p in selected: # parent listed
+                        selected[n] = 1
+        self.ui.debug('Sending %u changesets.\n' % (len(selected),))
+        return selected.keys()
+
     def findincoming(self, remote, base=None, heads=None):
         m = self.changelog.nodemap
         search = []
@@ -750,6 +794,7 @@
                 base[h] = 1
 
         if not unknown:
+            self.ui.debug("Remote has no versions unknown to our side.\n")
             return None
 
         rep = {}
@@ -918,11 +963,14 @@
         cg = self.changegroup(update)
         return remote.addchangegroup(cg)
 
-    def changegroup(self, basenodes):
+    def changegroup(self, basenodes, targetnode = None):
         genread = util.chunkbuffer
 
         def gengroup():
-            nodes = self.newer(basenodes)
+            if targetnode is None:
+                nodes = self.newer(basenodes)
+            else:
+                nodes = self.newertarget(basenodes, targetnode)
 
             # construct the link map
             linkmap = {}


More information about the Mercurial mailing list