Patchwork [05,of,11,RFC] histedit: add support for continuing after an exec

login
register
mail settings
Submitter Olle Lundberg
Date March 5, 2014, 4:15 p.m.
Message ID <cb0ccd948579f1ccbcb3.1394036116@SE-C02KQ0DADR55>
Download mbox | patch
Permalink /patch/3856/
State Changes Requested
Headers show

Comments

Olle Lundberg - March 5, 2014, 4:15 p.m.
# HG changeset patch
# User Olle Lundberg <geek@nerd.sh>
# Date 1394034779 -3600
#      Wed Mar 05 16:52:59 2014 +0100
# Node ID cb0ccd948579f1ccbcb39e3749b77268985d0a7b
# Parent  950c8d5b77e8d5eb610cbea159b7c02387bde211
histedit: add support for continuing after an exec

Bail if there are any uncommited changes/merges in the working
directory. Else set the currentnode to the working directories
first parent and let histedit do its magic. Unless the current
node ctx matches the parent ctx, then we can short circuit the
logic since there are no changes and we can just return the
parent with an empty replacements list.
Olle Lundberg - March 5, 2014, 6:53 p.m.
On Wed, Mar 5, 2014 at 5:15 PM, Olle Lundberg <olle.lundberg@gmail.com>wrote:

> # HG changeset patch
> # User Olle Lundberg <geek@nerd.sh>
> # Date 1394034779 -3600
> #      Wed Mar 05 16:52:59 2014 +0100
> # Node ID cb0ccd948579f1ccbcb39e3749b77268985d0a7b
> # Parent  950c8d5b77e8d5eb610cbea159b7c02387bde211
> histedit: add support for continuing after an exec
>
> Bail if there are any uncommited changes/merges in the working
> directory. Else set the currentnode to the working directories
> first parent and let histedit do its magic. Unless the current
> node ctx matches the parent ctx, then we can short circuit the
> logic since there are no changes and we can just return the
> parent with an empty replacements list.
>
> diff --git a/hgext/histedit.py b/hgext/histedit.py
> --- a/hgext/histedit.py
> +++ b/hgext/histedit.py
> @@ -664,10 +664,28 @@
>          os.unlink(repo.sjoin('undo'))
>
>
>  def bootstrapcontinue(ui, repo, parentctx, rules, opts):
>      action, currentnode = rules.pop(0)
> +
> +    # track replacements
> +    replacements = []
> +
> +    if action in ('x', 'exec'):
> +        # TODO: Do we want to auto-commit anything that the exec did for
> us?
> +        # That would be useful in cases where there is an external tool
> +        # modifying commits for us. The auto-commit behaviour is present
> in
> +        # the case when a used have used edit to split/add commits.
> Whatever
> +        # is present in the working dir gets commited.
> +        # If the first parent of the working direcroty is the same as the
> +        # parentctx from the histedit state, we can short circuit the
> logic
> +        # and just return the parentctx with no replacements.
> +        cmdutil.bailifchanged(repo)
>

Should we treat this as an edit flow instead? E.g prepare a commit with
what is in the wd and force a commit window on the user?


> +        currentnode = repo[None].p1()
> +        if currentnode == parentctx:
> +            return parentctx, replacements
> +
>      ctx = repo[currentnode]
>      # is there any new commit between the expected parent and "."
>      #
>      # note: does not take non linear new change in account (but previous
>      #       implementation didn't used them anyway (issue3655)
> @@ -698,12 +716,10 @@
>                       date=ctx.date(), extra=ctx.extra(),
>                       editor=editor)
>          if new is not None:
>              newchildren.append(new)
>
> -    replacements = []
> -    # track replacements
>      if ctx.node() not in newchildren:
>          # note: new children may be empty when the changeset is dropped.
>          # this happen e.g during conflicting pick where we revert content
>          # to parent.
>          replacements.append((ctx.node(), tuple(newchildren)))
>
David Soria Parra - March 5, 2014, 9:56 p.m.
Olle Lundberg <olle.lundberg@gmail.com> writes:

> # HG changeset patch
> # User Olle Lundberg <geek@nerd.sh>
> # Date 1394034779 -3600
> #      Wed Mar 05 16:52:59 2014 +0100
> # Node ID cb0ccd948579f1ccbcb39e3749b77268985d0a7b
> # Parent  950c8d5b77e8d5eb610cbea159b7c02387bde211
> histedit: add support for continuing after an exec
>
> Bail if there are any uncommited changes/merges in the working
> directory. Else set the currentnode to the working directories
> first parent and let histedit do its magic. Unless the current
> node ctx matches the parent ctx, then we can short circuit the
> logic since there are no changes and we can just return the
> parent with an empty replacements list.
>
> diff --git a/hgext/histedit.py b/hgext/histedit.py
> --- a/hgext/histedit.py
> +++ b/hgext/histedit.py
> @@ -664,10 +664,28 @@
>          os.unlink(repo.sjoin('undo'))
>  
>  
>  def bootstrapcontinue(ui, repo, parentctx, rules, opts):
>      action, currentnode = rules.pop(0)
> +
> +    # track replacements
> +    replacements = []
> +
> +    if action in ('x', 'exec'):
> +        # TODO: Do we want to auto-commit anything that the exec did for us?
> +        # That would be useful in cases where there is an external tool
> +        # modifying commits for us. The auto-commit behaviour is present in
> +        # the case when a used have used edit to split/add commits. Whatever
> +        # is present in the working dir gets commited.
> +        # If the first parent of the working direcroty is the same as the
> +        # parentctx from the histedit state, we can short circuit the logic
> +        # and just return the parentctx with no replacements.
> +        cmdutil.bailifchanged(repo)
> +        currentnode = repo[None].p1()
> +        if currentnode == parentctx:
> +            return parentctx, replacements

auto commit won't be necessary if we drop locks and allow the command to
commit.
Olle Lundberg - March 5, 2014, 10:34 p.m.
On Wed, Mar 5, 2014 at 10:56 PM, David Soria Parra <
dsp@experimentalworks.net> wrote:

> Olle Lundberg <olle.lundberg@gmail.com> writes:
>
> > # HG changeset patch
> > # User Olle Lundberg <geek@nerd.sh>
> > # Date 1394034779 -3600
> > #      Wed Mar 05 16:52:59 2014 +0100
> > # Node ID cb0ccd948579f1ccbcb39e3749b77268985d0a7b
> > # Parent  950c8d5b77e8d5eb610cbea159b7c02387bde211
> > histedit: add support for continuing after an exec
> >
> > Bail if there are any uncommited changes/merges in the working
> > directory. Else set the currentnode to the working directories
> > first parent and let histedit do its magic. Unless the current
> > node ctx matches the parent ctx, then we can short circuit the
> > logic since there are no changes and we can just return the
> > parent with an empty replacements list.
> >
> > diff --git a/hgext/histedit.py b/hgext/histedit.py
> > --- a/hgext/histedit.py
> > +++ b/hgext/histedit.py
> > @@ -664,10 +664,28 @@
> >          os.unlink(repo.sjoin('undo'))
> >
> >
> >  def bootstrapcontinue(ui, repo, parentctx, rules, opts):
> >      action, currentnode = rules.pop(0)
> > +
> > +    # track replacements
> > +    replacements = []
> > +
> > +    if action in ('x', 'exec'):
> > +        # TODO: Do we want to auto-commit anything that the exec did
> for us?
> > +        # That would be useful in cases where there is an external tool
> > +        # modifying commits for us. The auto-commit behaviour is
> present in
> > +        # the case when a used have used edit to split/add commits.
> Whatever
> > +        # is present in the working dir gets commited.
> > +        # If the first parent of the working direcroty is the same as
> the
> > +        # parentctx from the histedit state, we can short circuit the
> logic
> > +        # and just return the parentctx with no replacements.
> > +        cmdutil.bailifchanged(repo)
> > +        currentnode = repo[None].p1()
> > +        if currentnode == parentctx:
> > +            return parentctx, replacements
>
> auto commit won't be necessary if we drop locks and allow the command to
> commit.
>
That's only partly true.
If we end up in a state when the user needs to clean stuff up, but forgets
to commit, we either need to bail or go with the edit logic.

> _______________________________________________
> Mercurial-devel mailing list
> Mercurial-devel@selenic.com
> http://selenic.com/mailman/listinfo/mercurial-devel
>

Patch

diff --git a/hgext/histedit.py b/hgext/histedit.py
--- a/hgext/histedit.py
+++ b/hgext/histedit.py
@@ -664,10 +664,28 @@ 
         os.unlink(repo.sjoin('undo'))
 
 
 def bootstrapcontinue(ui, repo, parentctx, rules, opts):
     action, currentnode = rules.pop(0)
+
+    # track replacements
+    replacements = []
+
+    if action in ('x', 'exec'):
+        # TODO: Do we want to auto-commit anything that the exec did for us?
+        # That would be useful in cases where there is an external tool
+        # modifying commits for us. The auto-commit behaviour is present in
+        # the case when a used have used edit to split/add commits. Whatever
+        # is present in the working dir gets commited.
+        # If the first parent of the working direcroty is the same as the
+        # parentctx from the histedit state, we can short circuit the logic
+        # and just return the parentctx with no replacements.
+        cmdutil.bailifchanged(repo)
+        currentnode = repo[None].p1()
+        if currentnode == parentctx:
+            return parentctx, replacements
+
     ctx = repo[currentnode]
     # is there any new commit between the expected parent and "."
     #
     # note: does not take non linear new change in account (but previous
     #       implementation didn't used them anyway (issue3655)
@@ -698,12 +716,10 @@ 
                      date=ctx.date(), extra=ctx.extra(),
                      editor=editor)
         if new is not None:
             newchildren.append(new)
 
-    replacements = []
-    # track replacements
     if ctx.node() not in newchildren:
         # note: new children may be empty when the changeset is dropped.
         # this happen e.g during conflicting pick where we revert content
         # to parent.
         replacements.append((ctx.node(), tuple(newchildren)))