changeset 31525:8633d3e21443

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".
author Jun Wu <quark@fb.com>
date Mon, 13 Mar 2017 21:10:45 -0700
parents 935a1b1117c7
children 9d55494bd0db
files hgext/histedit.py
diffstat 1 files changed, 28 insertions(+), 0 deletions(-) [+]
line wrap: on
line diff
--- a/hgext/histedit.py	Tue Mar 21 07:22:13 2017 +0530
+++ b/hgext/histedit.py	Mon Mar 13 21:10:45 2017 -0700
@@ -1618,6 +1618,34 @@
             # This would reduce bundle overhead
             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):
         nodelist = [nodelist]