Patchwork D3668: graft: add a new `--stop` flag to stop interrupted graft

login
register
mail settings
Submitter phabricator
Date May 29, 2018, 8:44 p.m.
Message ID <differential-rev-PHID-DREV-bk3gs4qg4e55x7ss2cod-req@phab.mercurial-scm.org>
Download mbox | patch
Permalink /patch/31897/
State Superseded
Headers show

Comments

phabricator - May 29, 2018, 8:44 p.m.
pulkit created this revision.
Herald added a subscriber: mercurial-devel.
Herald added a reviewer: hg-reviewers.

REVISION SUMMARY
  This patch adds a new flag `--stop` to `hg graft` command which stops the
  interrupted graft.
  
  The `--stop` flag takes back you to the last successful step i.e. it will keep
  your grafted commits, it will just clear the mergestate and interrupted graft
  state.
  
  The `--stop` is different from `--abort` flag as the latter also undoes all the
  work done till now which is sometimes not what the user wants.
  
  Suppose you grafted a lot of changesets, you encountered conflicts, you resolved
  them, did `hg graft --continue`, again encountered conflicts, continue, again
  encountered conflicts. Now you are tired of solving merge conflicts and want to
  resume this sometimes later. If you use the `--abort` functionality, it will
  strip your already grafted changesets, making you loose the work you have done
  resolving merge conflicts.
  
  A general goal related to this flag is to add this flag to `rebase` and
  `histedit` too. The evolve command already has this --stop flag.
  
  Tests are added for the new flag.
  
  ..  feature:: `hg graft` now has a `--stop` flag to stop interrupted graft

REPOSITORY
  rHG Mercurial

REVISION DETAIL
  https://phab.mercurial-scm.org/D3668

AFFECTED FILES
  mercurial/commands.py
  tests/test-completion.t
  tests/test-graft.t

CHANGE DETAILS




To: pulkit, #hg-reviewers
Cc: mercurial-devel
Yuya Nishihara - June 5, 2018, 12:06 p.m.
>   The `--stop` flag takes back you to the last successful step i.e. it will keep
>   your grafted commits, it will just clear the mergestate and interrupted graft
>   state.

No idea if git is right regarding UI, but they appear to have `--quit` for
this.

https://git-scm.com/docs/git-cherry-pick

The code looks good to me. We'll need to update `cmdutil.unfinishedstates`
as well.
phabricator - June 5, 2018, 12:07 p.m.
yuja added a comment.


  >   The `--stop` flag takes back you to the last successful step i.e. it will keep
  >   your grafted commits, it will just clear the mergestate and interrupted graft
  >   state.
  
  No idea if git is right regarding UI, but they appear to have `--quit` for
  this.
  
  https://git-scm.com/docs/git-cherry-pick
  
  The code looks good to me. We'll need to update `cmdutil.unfinishedstates`
  as well.

REPOSITORY
  rHG Mercurial

REVISION DETAIL
  https://phab.mercurial-scm.org/D3668

To: pulkit, #hg-reviewers
Cc: yuja, mercurial-devel
phabricator - June 11, 2018, 7:45 p.m.
pulkit added a comment.


  In https://phab.mercurial-scm.org/D3668#58070, @yuja wrote:
  
  > >   The `--stop` flag takes back you to the last successful step i.e. it will keep
  > >   your grafted commits, it will just clear the mergestate and interrupted graft
  > >   state.
  >
  > No idea if git is right regarding UI, but they appear to have `--quit` for
  >  this.
  >
  > https://git-scm.com/docs/git-cherry-pick
  
  
  I asked people on IRC, nbjoerg and one more said '--stop' is better. However I am fine with changing that to `--quit`
  
  > The code looks good to me. We'll need to update `cmdutil.unfinishedstates`
  >  as well.
  
  Will do. I was also thinking to add a new general help topic which will document about `--continue`, `--abort` and `--stop` flags and point them as help text or "help text of help text" there.

REPOSITORY
  rHG Mercurial

REVISION DETAIL
  https://phab.mercurial-scm.org/D3668

To: pulkit, #hg-reviewers
Cc: yuja, mercurial-devel
Yuya Nishihara - June 12, 2018, 12:18 p.m.
>   In https://phab.mercurial-scm.org/D3668#58070, @yuja wrote:
>   
>   > >   The `--stop` flag takes back you to the last successful step i.e. it will keep
>   > >   your grafted commits, it will just clear the mergestate and interrupted graft
>   > >   state.
>   >
>   > No idea if git is right regarding UI, but they appear to have `--quit` for
>   >  this.
>   >
>   > https://git-scm.com/docs/git-cherry-pick
>   
>   I asked people on IRC, nbjoerg and one more said '--stop' is better. However I am fine with changing that to `--quit`

Good. Since I don't have any preference either, let's just stick to --stop.

Replaced some --abort in error message and queued, thanks.
phabricator - June 12, 2018, 12:18 p.m.
yuja added a comment.


  >   In https://phab.mercurial-scm.org/D3668#58070, @yuja wrote:
  >   
  >   > >   The `--stop` flag takes back you to the last successful step i.e. it will keep
  >   > >   your grafted commits, it will just clear the mergestate and interrupted graft
  >   > >   state.
  >   >
  >   > No idea if git is right regarding UI, but they appear to have `--quit` for
  >   >  this.
  >   >
  >   > https://git-scm.com/docs/git-cherry-pick
  >   
  >   I asked people on IRC, nbjoerg and one more said '--stop' is better. However I am fine with changing that to `--quit`
  
  Good. Since I don't have any preference either, let's just stick to --stop.
  
  Replaced some --abort in error message and queued, thanks.

REPOSITORY
  rHG Mercurial

REVISION DETAIL
  https://phab.mercurial-scm.org/D3668

To: pulkit, #hg-reviewers
Cc: yuja, mercurial-devel
David Demelier - June 15, 2018, 9:56 a.m.
On Tue, 2018-06-12 at 21:18 +0900, Yuya Nishihara wrote:
> >   In https://phab.mercurial-scm.org/D3668#58070, @yuja wrote:
> >   
> >   > >   The `--stop` flag takes back you to the last successful
> > step i.e. it will keep
> >   > >   your grafted commits, it will just clear the mergestate and
> > interrupted graft
> >   > >   state.
> >   >
> >   > No idea if git is right regarding UI, but they appear to have
> > `--quit` for
> >   >  this.
> >   >
> >   > https://git-scm.com/docs/git-cherry-pick
> >   
> >   I asked people on IRC, nbjoerg and one more said '--stop' is
> > better. However I am fine with changing that to `--quit`
> 
> Good. Since I don't have any preference either, let's just stick to
> --stop.

But histedit and rebase already use --abort, why not using that
convention? We should use the same thing everywhere.

Regards,
Yuya Nishihara - June 15, 2018, 11:49 a.m.
> > Good. Since I don't have any preference either, let's just stick to
> > --stop.
> 
> But histedit and rebase already use --abort, why not using that
> convention? We should use the same thing everywhere.

That's because graft --stop doesn't roll back to the state before starting
the graft.
David Demelier - June 15, 2018, 12:36 p.m.
On Fri, 2018-06-15 at 20:49 +0900, Yuya Nishihara wrote:
> > > Good. Since I don't have any preference either, let's just stick
> > > to
> > > --stop.
> > 
> > But histedit and rebase already use --abort, why not using that
> > convention? We should use the same thing everywhere.
> 
> That's because graft --stop doesn't roll back to the state before
> starting
> the graft.
> 

Oh understood, sorry for the noise :-)

Patch

diff --git a/tests/test-graft.t b/tests/test-graft.t
--- a/tests/test-graft.t
+++ b/tests/test-graft.t
@@ -1624,3 +1624,108 @@ 
      date:        Thu Jan 01 00:00:00 1970 +0000
      summary:     bar to b
   
+
+  $ cd ..
+
+Testing the --stop flag of `hg graft` which stops the interrupted graft
+
+  $ hg init stopgraft
+  $ cd stopgraft
+  $ for ch in a b c d; do echo $ch > $ch; hg add $ch; hg ci -Aqm "added "$ch; done;
+
+  $ hg log -G
+  @  changeset:   3:9150fe93bec6
+  |  tag:         tip
+  |  user:        test
+  |  date:        Thu Jan 01 00:00:00 1970 +0000
+  |  summary:     added d
+  |
+  o  changeset:   2:155349b645be
+  |  user:        test
+  |  date:        Thu Jan 01 00:00:00 1970 +0000
+  |  summary:     added c
+  |
+  o  changeset:   1:5f6d8a4bf34a
+  |  user:        test
+  |  date:        Thu Jan 01 00:00:00 1970 +0000
+  |  summary:     added b
+  |
+  o  changeset:   0:9092f1db7931
+     user:        test
+     date:        Thu Jan 01 00:00:00 1970 +0000
+     summary:     added a
+  
+  $ hg up '.^^'
+  0 files updated, 0 files merged, 2 files removed, 0 files unresolved
+
+  $ echo foo > d
+  $ hg ci -Aqm "added foo to d"
+
+  $ hg graft --stop
+  abort: no interrupted graft found
+  [255]
+
+  $ hg graft -r 3
+  grafting 3:9150fe93bec6 "added d"
+  merging d
+  warning: conflicts while merging d! (edit, then use 'hg resolve --mark')
+  abort: unresolved conflicts, can't continue
+  (use 'hg resolve' and 'hg graft --continue')
+  [255]
+
+  $ hg graft --stop --continue
+  abort: cannot use '--continue' and '--abort' together
+  [255]
+
+  $ hg graft --stop -U
+  abort: cannot specify any other flag with '--abort'
+  [255]
+  $ hg graft --stop --rev 4
+  abort: cannot specify any other flag with '--abort'
+  [255]
+  $ hg graft --stop --log
+  abort: cannot specify any other flag with '--abort'
+  [255]
+
+  $ hg graft --stop
+  stopped the interrupted graft
+  working directory is now at a0deacecd59d
+
+  $ hg diff
+
+  $ hg log -Gr '.'
+  @  changeset:   4:a0deacecd59d
+  |  tag:         tip
+  ~  parent:      1:5f6d8a4bf34a
+     user:        test
+     date:        Thu Jan 01 00:00:00 1970 +0000
+     summary:     added foo to d
+  
+  $ hg graft -r 2 -r 3
+  grafting 2:155349b645be "added c"
+  grafting 3:9150fe93bec6 "added d"
+  merging d
+  warning: conflicts while merging d! (edit, then use 'hg resolve --mark')
+  abort: unresolved conflicts, can't continue
+  (use 'hg resolve' and 'hg graft --continue')
+  [255]
+
+  $ hg graft --stop
+  stopped the interrupted graft
+  working directory is now at 75b447541a9e
+
+  $ hg diff
+
+  $ hg log -G -T "{rev}:{node|short} {desc}"
+  @  5:75b447541a9e added c
+  |
+  o  4:a0deacecd59d added foo to d
+  |
+  | o  3:9150fe93bec6 added d
+  | |
+  | o  2:155349b645be added c
+  |/
+  o  1:5f6d8a4bf34a added b
+  |
+  o  0:9092f1db7931 added a
+  
diff --git a/tests/test-completion.t b/tests/test-completion.t
--- a/tests/test-completion.t
+++ b/tests/test-completion.t
@@ -311,7 +311,7 @@ 
   debugwireargs: three, four, five, ssh, remotecmd, insecure
   debugwireproto: localssh, peer, noreadstderr, nologhandshake, ssh, remotecmd, insecure
   files: rev, print0, include, exclude, template, subrepos
-  graft: rev, continue, edit, log, force, currentdate, currentuser, date, user, tool, dry-run
+  graft: rev, continue, stop, edit, log, force, currentdate, currentuser, date, user, tool, dry-run
   grep: print0, all, text, follow, ignore-case, files-with-matches, line-number, rev, user, date, template, include, exclude
   heads: rev, topo, active, closed, style, template
   help: extension, command, keyword, system
diff --git a/mercurial/commands.py b/mercurial/commands.py
--- a/mercurial/commands.py
+++ b/mercurial/commands.py
@@ -2127,6 +2127,7 @@ 
     'graft',
     [('r', 'rev', [], _('revisions to graft'), _('REV')),
      ('c', 'continue', False, _('resume interrupted graft')),
+     ('', 'stop', False, _('stop interrupted graft')),
      ('e', 'edit', False, _('invoke editor on commit messages')),
      ('', 'log', None, _('append graft info to log message')),
      ('f', 'force', False, _('force graft')),
@@ -2212,6 +2213,15 @@ 
 
     cont = False
     graftstate = statemod.cmdstate(repo, 'graftstate')
+    if opts.get('stop'):
+        if opts.get('continue'):
+            raise error.Abort(_("cannot use '--continue' and"
+                                " '--abort' together"))
+        if any((opts.get('edit'), opts.get('log'), opts.get('user'),
+                opts.get('date'), opts.get('currentdate'),
+                opts.get('currentuser'), opts.get('rev'))):
+            raise error.Abort(_("cannot specify any other flag with '--abort'"))
+        return _stopgraft(ui, repo, graftstate)
     if opts.get('continue'):
         cont = True
         if revs:
@@ -2395,6 +2405,17 @@ 
         nodes = repo.vfs.read('graftstate').splitlines()
         return {'nodes': nodes}
 
+def _stopgraft(ui, repo, graftstate):
+    """stop the interrupted graft"""
+    if not graftstate.exists():
+        raise error.Abort(_("no interrupted graft found"))
+    pctx = repo['.']
+    hg.updaterepo(repo, pctx.node(), True)
+    graftstate.delete()
+    ui.status(_("stopped the interrupted graft\n"))
+    ui.status(_("working directory is now at %s\n") % pctx.hex()[:12])
+    return 0
+
 @command('grep',
     [('0', 'print0', None, _('end fields with NUL')),
     ('', 'all', None, _('print all revisions that match')),