[PATCH 1 of 3 evolve-ext V2] evolve: factor out sanity checks for folds

Siddharth Agarwal sid0 at fb.com
Sun Mar 20 01:02:25 EDT 2016


# HG changeset patch
# User Siddharth Agarwal <sid0 at fb.com>
# Date 1458449988 25200
#      Sat Mar 19 21:59:48 2016 -0700
# Branch stable
# Node ID 6a025b84e174d08fdb485d1f049be17077c671c8
# Parent  498329a3c90048f5c211dabcfaab1bfc7bdbd3fa
evolve: factor out sanity checks for folds

We're going to use the same checks in another context in an upcoming patch.

diff --git a/hgext/evolve.py b/hgext/evolve.py
--- a/hgext/evolve.py
+++ b/hgext/evolve.py
@@ -2961,6 +2961,44 @@ def fold(ui, repo, *revs, **opts):
         ui.write_err(_('single revision specified, nothing to fold\n'))
         return 1
 
+    root, head = _foldcheck(repo, revs)
+
+    wlock = lock = None
+    try:
+        wlock = repo.wlock()
+        lock = repo.lock()
+        tr = repo.transaction('touch')
+        try:
+            commitopts = opts.copy()
+            allctx = [repo[r] for r in revs]
+            targetphase = max(c.phase() for c in allctx)
+
+            if commitopts.get('message') or commitopts.get('logfile'):
+                commitopts['edit'] = False
+            else:
+                msgs = ["HG: This is a fold of %d changesets." % len(allctx)]
+                msgs += ["HG: Commit message of changeset %s.\n\n%s\n" %
+                         (c.rev(), c.description()) for c in allctx]
+                commitopts['message'] =  "\n".join(msgs)
+                commitopts['edit'] = True
+
+            newid, unusedvariable = rewrite(repo, root, allctx, head,
+                                            [root.p1().node(),
+                                             root.p2().node()],
+                                            commitopts=commitopts)
+            phases.retractboundary(repo, tr, targetphase, [newid])
+            obsolete.createmarkers(repo, [(ctx, (repo[newid],))
+                                 for ctx in allctx])
+            tr.close()
+        finally:
+            tr.release()
+        ui.status('%i changesets folded\n' % len(revs))
+        if repo['.'].rev() in revs:
+            hg.update(repo, newid)
+    finally:
+        lockmod.release(lock, wlock)
+
+def _foldcheck(repo, revs):
     roots = repo.revs('roots(%ld)', revs)
     if len(roots) > 1:
         raise error.Abort(_("cannot fold non-linear revisions "
@@ -2978,42 +3016,7 @@ def fold(ui, repo, *revs, **opts):
         if repo.revs("(%ld::) - %ld", revs, revs):
             raise error.Abort(_("cannot fold chain not ending with a head "\
                                "or with branching"))
-    wlock = lock = None
-    try:
-        wlock = repo.wlock()
-        lock = repo.lock()
-        tr = repo.transaction('touch')
-        try:
-            commitopts = opts.copy()
-            allctx = [repo[r] for r in revs]
-            targetphase = max(c.phase() for c in allctx)
-
-            if commitopts.get('message') or commitopts.get('logfile'):
-                commitopts['edit'] = False
-            else:
-                msgs = ["HG: This is a fold of %d changesets." % len(allctx)]
-                msgs += ["HG: Commit message of changeset %s.\n\n%s\n" %
-                         (c.rev(), c.description()) for c in allctx]
-                commitopts['message'] =  "\n".join(msgs)
-                commitopts['edit'] = True
-
-            newid, unusedvariable = rewrite(repo, root, allctx, head,
-                                            [root.p1().node(),
-                                             root.p2().node()],
-                                            commitopts=commitopts)
-            phases.retractboundary(repo, tr, targetphase, [newid])
-            obsolete.createmarkers(repo, [(ctx, (repo[newid],))
-                                 for ctx in allctx])
-            tr.close()
-        finally:
-            tr.release()
-        ui.status('%i changesets folded\n' % len(revs))
-        if repo['.'].rev() in revs:
-            hg.update(repo, newid)
-    finally:
-        lockmod.release(lock, wlock)
-
-
+    return root, head
 
 @eh.wrapcommand('graft')
 def graftwrapper(orig, ui, repo, *revs, **kwargs):


More information about the Mercurial-devel mailing list