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

login
register
mail settings
Submitter Mateusz Kwapich
Date Dec. 6, 2016, 4:41 p.m.
Message ID <50ef3a1f97fb8faf1506.1481042477@devvm314.lla2.facebook.com>
Download mbox | patch
Permalink /patch/17838/
State Changes Requested
Headers show

Comments

Mateusz Kwapich - Dec. 6, 2016, 4:41 p.m.
# HG changeset patch
# User Mateusz Kwapich <mitrandir@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.
Pierre-Yves David - Dec. 20, 2016, 6:48 p.m.
On 12/06/2016 05:41 PM, Mateusz Kwapich wrote:
> # HG changeset patch
> # User Mateusz Kwapich <mitrandir@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.

I don't see why using memlightctx change anything there. The lack of 
autorewrite of the whole stack is mostly here to fight squarish 
obs-marker creation (and consistency with other commands).

What is your usecase here ?

Also, Changeset 5, 7 and 8 seems unrelated to the main intend (using 
memlightctx) can you delay them in a second series to be sent when we 
are done with memlightctx.


> 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@default(draft) will cause conflict at evolve
> +  |
> +  | o  47:f72774e0c084@default(draft) amended
> +  | |
> +  x |  38:f8e30e9317aa@default(draft) will be evolved safely
> +  | |
> +  x |  37:36030b147271@default(draft) will be amended
> +  |/
> +  @  36:43c3f5ef149f@default(draft) add uu
> +  |
> +  o  35:7a555adf2b4a@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@default(draft) will cause conflict at evolve
> +  |
> +  | o  47:f72774e0c084@default(draft) amended
> +  | |
> +  x |  38:f8e30e9317aa@default(draft) will be evolved safely
> +  | |
> +  x |  37:36030b147271@default(draft) will be amended
> +  |/
> +  @  36:43c3f5ef149f@default(draft) add uu
> +  |
> +  o  35:7a555adf2b4a@default(draft) _pp
> +  |
> +  ~
> +  $ hg metaedit -m "add uu (with metaedit)"
> +  $ glog -r '(.^)::'
> +  @  49:d56769f6b2a5@default(draft) add uu (with metaedit)
> +  |
> +  | o  48:2603fdb715ea@default(draft) will cause conflict at evolve
> +  | |
> +  | | o  47:f72774e0c084@default(draft) amended
> +  | | |
> +  | x |  38:f8e30e9317aa@default(draft) will be evolved safely
> +  | | |
> +  | x |  37:36030b147271@default(draft) will be amended
> +  | |/
> +  | x  36:43c3f5ef149f@default(draft) add uu
> +  |/
> +  o  35:7a555adf2b4a@default(draft) _pp
> +  |
> +  ~

Patch

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@default(draft) will cause conflict at evolve
+  |
+  | o  47:f72774e0c084@default(draft) amended
+  | |
+  x |  38:f8e30e9317aa@default(draft) will be evolved safely
+  | |
+  x |  37:36030b147271@default(draft) will be amended
+  |/
+  @  36:43c3f5ef149f@default(draft) add uu
+  |
+  o  35:7a555adf2b4a@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@default(draft) will cause conflict at evolve
+  |
+  | o  47:f72774e0c084@default(draft) amended
+  | |
+  x |  38:f8e30e9317aa@default(draft) will be evolved safely
+  | |
+  x |  37:36030b147271@default(draft) will be amended
+  |/
+  @  36:43c3f5ef149f@default(draft) add uu
+  |
+  o  35:7a555adf2b4a@default(draft) _pp
+  |
+  ~
+  $ hg metaedit -m "add uu (with metaedit)"
+  $ glog -r '(.^)::'
+  @  49:d56769f6b2a5@default(draft) add uu (with metaedit)
+  |
+  | o  48:2603fdb715ea@default(draft) will cause conflict at evolve
+  | |
+  | | o  47:f72774e0c084@default(draft) amended
+  | | |
+  | x |  38:f8e30e9317aa@default(draft) will be evolved safely
+  | | |
+  | x |  37:36030b147271@default(draft) will be amended
+  | |/
+  | x  36:43c3f5ef149f@default(draft) add uu
+  |/
+  o  35:7a555adf2b4a@default(draft) _pp
+  |
+  ~