[PATCH 1 of 4 V3] histedit: add a method to cleanup nodes safely

Jun Wu quark at fb.com
Mon Mar 20 20:15:28 EDT 2017


# HG changeset patch
# User Jun Wu <quark at fb.com>
# Date 1489464645 25200
#      Mon Mar 13 21:10:45 2017 -0700
# Node ID 016fcb6e44e0e903d590b63135fa785955068737
# Parent  44c591f634584c721778c5a77edeb04cd919ac43
# Available At https://bitbucket.org/quark-zju/hg-draft
#              hg pull https://bitbucket.org/quark-zju/hg-draft -r 016fcb6e44e0
histedit: add a method to cleanup nodes safely

The new method will decide between:

  - cleanupnode, which calls the unsafe repair.strip
  - create obsmarkers

Ideally, nobody calls "cleanupnode" directly except for "safecleanupnode".

diff --git a/hgext/histedit.py b/hgext/histedit.py
--- a/hgext/histedit.py
+++ b/hgext/histedit.py
@@ -1619,4 +1619,32 @@ def cleanupnode(ui, repo, name, nodes):
             repair.strip(ui, repo, c)
 
+def safecleanupnode(ui, repo, name, nodes):
+    """strip or obsolete nodes
+
+    nodes could be either a set or dict which maps to replacements.
+    nodes could be unknown (outside the repo).
+    """
+    supportsmarkers = obsolete.isenabled(repo, obsolete.createmarkersopt)
+    if supportsmarkers:
+        if util.safehasattr(nodes, 'get'):
+            # nodes is a dict-like mapping
+            # use unfiltered repo for successors in case they are hidden
+            urepo = repo.unfiltered()
+            def getmarker(prec):
+                succs = tuple(urepo[n] for n in nodes.get(prec, ()))
+                return (repo[prec], succs)
+        else:
+            # nodes is a set-like
+            def getmarker(prec):
+                return (repo[prec], ())
+        # sort by revision number because it sound "right"
+        sortednodes = sorted([n for n in nodes if n in repo],
+                             key=repo.changelog.rev)
+        markers = [getmarker(t) for t in sortednodes]
+        if markers:
+            obsolete.createmarkers(repo, markers)
+    else:
+        return cleanupnode(ui, repo, name, nodes)
+
 def stripwrapper(orig, ui, repo, nodelist, *args, **kwargs):
     if isinstance(nodelist, str):


More information about the Mercurial-devel mailing list