[PATCH 03 of 12] histedit: factorise node stripping logic

pierre-yves.david at logilab.fr pierre-yves.david at logilab.fr
Thu Sep 27 07:23:22 CDT 2012


# HG changeset patch
# User Pierre-Yves David <pierre-yves.david at logilab.fr>
# Date 1348663568 -7200
# Node ID e09b7339b5e6a5406b6fa59a8321b9d59c585763
# Parent  6d94e9a3da09906d4a7daa382e5f80d37aa14414
histedit: factorise node stripping logic

Create a function dedicated to stripping a group of node. All existing
duplicated code is replaced by call to this function.

This new function take care of stripping known and relevant node only.

diff --git a/hgext/histedit.py b/hgext/histedit.py
--- a/hgext/histedit.py
+++ b/hgext/histedit.py
@@ -480,25 +480,12 @@ def histedit(ui, repo, *parent, **opts):
             raise util.Abort(_('no arguments allowed with --abort'))
         (parentctxnode, created, replaced, tmpnodes,
          existing, rules, keep, tip, replacemap) = readstate(repo)
         ui.debug('restore wc to old tip %s\n' % node.hex(tip))
         hg.clean(repo, tip)
-        ui.debug('should strip created nodes %s\n' %
-                 ', '.join([node.short(n) for n in created]))
-        ui.debug('should strip temp nodes %s\n' %
-                 ', '.join([node.short(n) for n in tmpnodes]))
-        for nodes in (created, tmpnodes):
-            lock = None
-            try:
-                lock = repo.lock()
-                for n in reversed(nodes):
-                    try:
-                        repair.strip(ui, repo, n)
-                    except error.LookupError:
-                        pass
-            finally:
-                lockmod.release(lock)
+        cleanupnode(ui, repo, 'created', created)
+        cleanupnode(ui, repo, 'temp', tmpnodes)
         os.unlink(os.path.join(repo.path, 'histedit-state'))
         return
     else:
         cmdutil.bailifchanged(repo)
         if os.path.exists(os.path.join(repo.path, 'histedit-state')):
@@ -602,36 +589,13 @@ def histedit(ui, repo, *parent, **opts):
 
     if not keep:
         if replacemap:
             movebookmarks(ui, repo, replacemap, tmpnodes, created)
             # TODO update mq state
+        cleanupnode(ui, repo, 'replaced', replaced)
 
-        ui.debug('should strip replaced nodes %s\n' %
-                 ', '.join([node.short(n) for n in replaced]))
-        lock = None
-        try:
-            lock = repo.lock()
-            for n in sorted(replaced, key=lambda x: repo[x].rev()):
-                try:
-                    repair.strip(ui, repo, n)
-                except error.LookupError:
-                    pass
-        finally:
-            lockmod.release(lock)
-
-    ui.debug('should strip temp nodes %s\n' %
-             ', '.join([node.short(n) for n in tmpnodes]))
-    lock = None
-    try:
-        lock = repo.lock()
-        for n in reversed(tmpnodes):
-            try:
-                repair.strip(ui, repo, n)
-            except error.LookupError:
-                pass
-    finally:
-        lockmod.release(lock)
+    cleanupnode(ui, repo, 'temp', tmpnodes)
     os.unlink(os.path.join(repo.path, 'histedit-state'))
     if os.path.exists(repo.sjoin('undo')):
         os.unlink(repo.sjoin('undo'))
 
 
@@ -745,5 +709,28 @@ def movebookmarks(ui, repo, replacemap, 
     newtip = sorted(replacemap.values(), key=repo.changelog.rev)[-1]
     copybms(oldtip, newtip)
 
     for old, new in sorted(replacemap.iteritems()):
         copybms(old, new)
+
+def cleanupnode(ui, repo, name, nodes):
+    """strip a group of nodes from the repository
+
+    The set of node to strip may contains unknown nodes."""
+    ui.debug('should strip %s nodes %s\n' %
+             (name, ', '.join([node.short(n) for n in nodes])))
+    lock = None
+    try:
+        lock = repo.lock()
+        # Find all node that need to be stripped
+        # (we hg %lr instead of %ln to silently ignore unknown item
+        nm = repo.changelog.nodemap
+        nodes = [n for n in nodes if n in nm]
+        roots = [c.node() for c in repo.set("roots(%ln)", nodes)]
+        for c in roots:
+            # We should process node in reverse order to strip tip most first.
+            # but this trigger a bug in changegroup hook.
+            # This would reduce bundle overhead
+            repair.strip(ui, repo, c)
+    finally:
+        lockmod.release(lock)
+


More information about the Mercurial-devel mailing list