[PATCH 8 of 8 evolve-ext, V2] metaedit: make metaedit work nice when new unstable commits are disallowed

Mateusz Kwapich mitrandir at fb.com
Tue Dec 6 11:41:17 EST 2016


# HG changeset patch
# User Mateusz Kwapich <mitrandir at fb.com>
# Date 1481041359 28800
#      Tue Dec 06 08:22:39 2016 -0800
# Branch stable
# Node ID 50ef3a1f97fb8faf1506d7751ba3f7ffe7e0e7db
# Parent  a7cc11231c424e435252e7388dd05b139e766af2
metaedit: make metaedit work nice when new unstable commits are disallowed

Now, when metaedit is using a lightweight commits (reusing manifest) we can
easily afford to actually rewrite all descendants if we attempt to metaedit a
commit in the middle of a stack.

diff --git a/hgext/evolve.py b/hgext/evolve.py
--- a/hgext/evolve.py
+++ b/hgext/evolve.py
@@ -929,7 +929,7 @@ def metarewrite(repo, old, newbases, com
         extra = dict(commitopts.get('extra', old.extra()))
         extra['branch'] = old.branch()
 
-        new = context.memlightctx(repo,
+        new = context.metadataonlyctx(repo,
                           old,
                           parents=newbases,
                           text=message,
@@ -3310,9 +3310,14 @@ def metaedit(ui, repo, *revs, **opts):
                 replacemap = {}
                 # we need topological order
                 allctx = sorted(allctx, key=lambda c: c.rev())
-                for c in allctx:
-                    if commitopts['edit']:
-                        commitopts['message'] = \
+                # all descendats that can be safely rewritten
+                newunstable = _disallowednewunstable(repo, revs)
+                newunstablectx = sorted([repo[r] for r in newunstable],
+                                 key=lambda c: c.rev())
+
+                def _rewritesingle(c, _commitopts):
+                    if _commitopts.get('edit', False):
+                        _commitopts['message'] = \
                             "HG: Commit message of changeset %s\n%s" %\
                             (str(c), c.description())
                     bases = [
@@ -3320,9 +3325,13 @@ def metaedit(ui, repo, *revs, **opts):
                         replacemap.get(c.p2().node(), c.p2().node()),
                     ]
                     newid, created = metarewrite(repo, c, bases,
-                                                 commitopts=commitopts)
+                                                 commitopts=_commitopts)
                     if created:
                         replacemap[c.node()] = newid
+                for c in allctx:
+                    _rewritesingle(c, commitopts)
+                for c in newunstablectx:
+                    _rewritesingle(c, {})
 
                 if p1.node() in replacemap:
                     newp1 = replacemap[p1.node()]
diff --git a/tests/test-evolve.t b/tests/test-evolve.t
--- a/tests/test-evolve.t
+++ b/tests/test-evolve.t
@@ -1574,3 +1574,54 @@ TODO: don't create a new commit in this 
   48: foobar3
   $ hg st -amr
   M newfile
+
+metaedit a commit in the middle of the stack:
+  $ glog -r '(.^)::'
+  o  48:2603fdb715ea at default(draft) will cause conflict at evolve
+  |
+  | o  47:f72774e0c084 at default(draft) amended
+  | |
+  x |  38:f8e30e9317aa at default(draft) will be evolved safely
+  | |
+  x |  37:36030b147271 at default(draft) will be amended
+  |/
+  @  36:43c3f5ef149f at default(draft) add uu
+  |
+  o  35:7a555adf2b4a at default(draft) _pp
+  |
+  ~
+  $ hg metaedit -m "add uu (with metaedit)" --config 'experimental.evolution=createmarkers, allnewcommands'
+  abort: cannot edit commit information in the middle of a stack
+  (f72774e0c084 will be affected)
+  [255]
+  $ glog -r '(.^)::'
+  o  48:2603fdb715ea at default(draft) will cause conflict at evolve
+  |
+  | o  47:f72774e0c084 at default(draft) amended
+  | |
+  x |  38:f8e30e9317aa at default(draft) will be evolved safely
+  | |
+  x |  37:36030b147271 at default(draft) will be amended
+  |/
+  @  36:43c3f5ef149f at default(draft) add uu
+  |
+  o  35:7a555adf2b4a at default(draft) _pp
+  |
+  ~
+  $ hg metaedit -m "add uu (with metaedit)"
+  $ glog -r '(.^)::'
+  @  49:d56769f6b2a5 at default(draft) add uu (with metaedit)
+  |
+  | o  48:2603fdb715ea at default(draft) will cause conflict at evolve
+  | |
+  | | o  47:f72774e0c084 at default(draft) amended
+  | | |
+  | x |  38:f8e30e9317aa at default(draft) will be evolved safely
+  | | |
+  | x |  37:36030b147271 at default(draft) will be amended
+  | |/
+  | x  36:43c3f5ef149f at default(draft) add uu
+  |/
+  o  35:7a555adf2b4a at default(draft) _pp
+  |
+  ~


More information about the Mercurial-devel mailing list