Re: D3754: graft: introduce --abort flag to abort interrupted graft

2018-06-25 Thread Yuya Nishihara
> +# changeset from which graft operation was started
> +startctx = None
> +if len(newnodes) > 0:
> +startctx = repo[newnodes[0]].p1()

This can be moved under `if newnodes:`

> +else:
> +startctx = repo['.']
> +# whether to strip or not
> +cleanup = False
> +if newnodes:
> +newnodes = [repo[r].rev() for r in newnodes]

...

> +if not cleanup:
> +# we don't update to the startnode if we can't strip
> +startctx = repo['.']

since startctx is re-initialized here.

> +hg.updaterepo(repo, startctx.node(), True)
___
Mercurial-devel mailing list
Mercurial-devel@mercurial-scm.org
https://www.mercurial-scm.org/mailman/listinfo/mercurial-devel


D3754: graft: introduce --abort flag to abort interrupted graft

2018-06-25 Thread pulkit (Pulkit Goyal)
This revision was automatically updated to reflect the committed changes.
Closed by commit rHG5cdfc20bfd5f: graft: introduce --abort flag to abort 
interrupted graft (authored by pulkit, committed by ).

CHANGED PRIOR TO COMMIT
  https://phab.mercurial-scm.org/D3754?vs=9275=9282#toc

REPOSITORY
  rHG Mercurial

CHANGES SINCE LAST UPDATE
  https://phab.mercurial-scm.org/D3754?vs=9275=9282

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

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

CHANGE DETAILS

diff --git a/tests/test-graft.t b/tests/test-graft.t
--- a/tests/test-graft.t
+++ b/tests/test-graft.t
@@ -1670,3 +1670,218 @@
   |
   o  0:9092f1db7931 added a
   
+  $ cd ..
+
+Testing the --abort flag for `hg graft` which aborts and rollback to state
+before the graft
+
+  $ hg init abortgraft
+  $ cd abortgraft
+  $ for ch in a b c d; do echo $ch > $ch; hg add $ch; hg ci -Aqm "added "$ch; 
done;
+
+  $ hg up '.^^'
+  0 files updated, 0 files merged, 2 files removed, 0 files unresolved
+
+  $ echo x > x
+  $ hg ci -Aqm "added x"
+  $ hg up '.^'
+  0 files updated, 0 files merged, 1 files removed, 0 files unresolved
+  $ echo foo > c
+  $ hg ci -Aqm "added foo to c"
+
+  $ hg log -GT "{rev}:{node|short} {desc}"
+  @  5:36b793615f78 added foo to c
+  |
+  | o  4:863a25e1a9ea added x
+  |/
+  | o  3:9150fe93bec6 added d
+  | |
+  | o  2:155349b645be added c
+  |/
+  o  1:5f6d8a4bf34a added b
+  |
+  o  0:9092f1db7931 added a
+  
+  $ hg up 9150fe93bec6
+  2 files updated, 0 files merged, 0 files removed, 0 files unresolved
+
+  $ hg graft --abort
+  abort: no interrupted graft to abort
+  [255]
+
+when stripping is required
+  $ hg graft -r 4 -r 5
+  grafting 4:863a25e1a9ea "added x"
+  grafting 5:36b793615f78 "added foo to c" (tip)
+  merging c
+  warning: conflicts while merging c! (edit, then use 'hg resolve --mark')
+  abort: unresolved conflicts, can't continue
+  (use 'hg resolve' and 'hg graft --continue')
+  [255]
+
+  $ hg graft --continue --abort
+  abort: cannot use '--continue' and '--abort' together
+  [255]
+
+  $ hg graft --abort --stop
+  abort: cannot use '--abort' and '--stop' together
+  [255]
+
+  $ hg graft --abort --currentuser
+  abort: cannot specify any other flag with '--abort'
+  [255]
+
+  $ hg graft --abort --edit
+  abort: cannot specify any other flag with '--abort'
+  [255]
+
+  $ hg graft --abort
+  graft aborted
+  working directory is now at 9150fe93bec6
+  $ hg log -GT "{rev}:{node|short} {desc}"
+  o  5:36b793615f78 added foo to c
+  |
+  | o  4:863a25e1a9ea added x
+  |/
+  | @  3:9150fe93bec6 added d
+  | |
+  | o  2:155349b645be added c
+  |/
+  o  1:5f6d8a4bf34a added b
+  |
+  o  0:9092f1db7931 added a
+  
+when stripping is not required
+  $ hg graft -r 5
+  grafting 5:36b793615f78 "added foo to c" (tip)
+  merging c
+  warning: conflicts while merging c! (edit, then use 'hg resolve --mark')
+  abort: unresolved conflicts, can't continue
+  (use 'hg resolve' and 'hg graft --continue')
+  [255]
+
+  $ hg graft --abort
+  graft aborted
+  working directory is now at 9150fe93bec6
+  $ hg log -GT "{rev}:{node|short} {desc}"
+  o  5:36b793615f78 added foo to c
+  |
+  | o  4:863a25e1a9ea added x
+  |/
+  | @  3:9150fe93bec6 added d
+  | |
+  | o  2:155349b645be added c
+  |/
+  o  1:5f6d8a4bf34a added b
+  |
+  o  0:9092f1db7931 added a
+  
+when some of the changesets became public
+
+  $ hg graft -r 4 -r 5
+  grafting 4:863a25e1a9ea "added x"
+  grafting 5:36b793615f78 "added foo to c" (tip)
+  merging c
+  warning: conflicts while merging c! (edit, then use 'hg resolve --mark')
+  abort: unresolved conflicts, can't continue
+  (use 'hg resolve' and 'hg graft --continue')
+  [255]
+
+  $ hg log -GT "{rev}:{node|short} {desc}"
+  @  6:6ec71c037d94 added x
+  |
+  | o  5:36b793615f78 added foo to c
+  | |
+  | | o  4:863a25e1a9ea added x
+  | |/
+  o |  3:9150fe93bec6 added d
+  | |
+  o |  2:155349b645be added c
+  |/
+  o  1:5f6d8a4bf34a added b
+  |
+  o  0:9092f1db7931 added a
+  
+  $ hg phase -r 6 --public
+
+  $ hg graft --abort
+  cannot clean up public changesets 6ec71c037d94
+  graft aborted
+  working directory is now at 6ec71c037d94
+
+when we created new changesets on top of existing one
+
+  $ hg up '.^^'
+  0 files updated, 0 files merged, 2 files removed, 0 files unresolved
+  $ echo y > y
+  $ hg ci -Aqm "added y"
+  $ echo z > z
+  $ hg ci -Aqm "added z"
+
+  $ hg up 3
+  1 files updated, 0 files merged, 3 files removed, 0 files unresolved
+  $ hg log -GT "{rev}:{node|short} {desc}"
+  o  8:637f9e9bbfd4 added z
+  |
+  o  7:123221671fd4 added y
+  |
+  | o  6:6ec71c037d94 added x
+  | |
+  | | o  5:36b793615f78 added foo to c
+  | | |
+  | | | o  4:863a25e1a9ea added x
+  | | |/
+  | @ |  3:9150fe93bec6 added d
+  |/ /
+  o /  2:155349b645be added c
+  |/
+  o  1:5f6d8a4bf34a added b
+  |
+  o  0:9092f1db7931 added a
+  
+  $ hg graft -r 8 -r 7 -r 5
+  grafting 8:637f9e9bbfd4 "added z" (tip)
+  grafting 

Re: D3754: graft: introduce --abort flag to abort interrupted graft

2018-06-25 Thread Yuya Nishihara
Fixed minor string nits, and queued, thanks.

> +if newnodes:
> +newnodes = [repo[r].rev() for r in newnodes]
> +cleanup =  True
> +# checking that none of the newnodes turned public or is public
> +immutable = [c for c in newnodes if not repo[c].mutable()]
> +if immutable:
> +repo.ui.warn(_("cannot clean up public changesets %s\n")
> + % ','.join(bytes(repo[r]) for r in immutable),
> + hint=_("see 'hg help phases' for details"))
> +cleanup = False

It's better to use r/rev, c/ctx, n/node in variable names consistently. Can
you send a followup?

> +ui.write(_("graft aborted\nworking directory is now at %s\n")
> + % startctx.hex()[:12])

s/ui.write/ui.status/ as we do that for graft --stop.
___
Mercurial-devel mailing list
Mercurial-devel@mercurial-scm.org
https://www.mercurial-scm.org/mailman/listinfo/mercurial-devel


D3754: graft: introduce --abort flag to abort interrupted graft

2018-06-25 Thread yuja (Yuya Nishihara)
yuja added a comment.


  Fixed minor string nits, and queued, thanks.
  
  > +if newnodes:
  >  +newnodes = [repo[r].rev() for r in newnodes]
  >  +cleanup =  True
  >  +# checking that none of the newnodes turned public or is public
  >  +immutable = [c for c in newnodes if not repo[c].mutable()]
  >  +if immutable:
  >  +repo.ui.warn(_("cannot clean up public changesets %s\n")
  >  + % ','.join(bytes(repo[r]) for r in immutable),
  >  + hint=_("see 'hg help phases' for details"))
  >  +cleanup = False
  
  It's better to use r/rev, c/ctx, n/node in variable names consistently. Can
  you send a followup?
  
  > +ui.write(_("graft aborted\nworking directory is now at %s\n")
  >  + % startctx.hex()[:12])
  
  s/ui.write/ui.status/ as we do that for graft --stop.

REPOSITORY
  rHG Mercurial

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

To: pulkit, #hg-reviewers
Cc: yuja, mercurial-devel
___
Mercurial-devel mailing list
Mercurial-devel@mercurial-scm.org
https://www.mercurial-scm.org/mailman/listinfo/mercurial-devel


D3754: graft: introduce --abort flag to abort interrupted graft

2018-06-25 Thread pulkit (Pulkit Goyal)
pulkit added a comment.


  In https://phab.mercurial-scm.org/D3754#59872, @yuja wrote:
  
  > >   > This looks quite similar to rebase.abort(). Can we factor out a 
common part?
  > >   
  > >   
  > >   We need to cleanup some of the rebase code first to factor out the 
common part. I will do that.
  >
  > Awesome, thanks. Should I review the current patch? or are you planning to
  >  revise it?
  
  
  I incorporated other reviews except the cleanup one. I haven't yet started 
the cleanup work, so if you feel that's necessary, you can leave reviewing for 
now.

REPOSITORY
  rHG Mercurial

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

To: pulkit, #hg-reviewers
Cc: yuja, mercurial-devel
___
Mercurial-devel mailing list
Mercurial-devel@mercurial-scm.org
https://www.mercurial-scm.org/mailman/listinfo/mercurial-devel


Re: D3754: graft: introduce --abort flag to abort interrupted graft

2018-06-25 Thread Yuya Nishihara
>   > This looks quite similar to rebase.abort(). Can we factor out a common 
> part?
>   
>   
>   We need to cleanup some of the rebase code first to factor out the common 
> part. I will do that.

Awesome, thanks. Should I review the current patch? or are you planning to
revise it?
___
Mercurial-devel mailing list
Mercurial-devel@mercurial-scm.org
https://www.mercurial-scm.org/mailman/listinfo/mercurial-devel


D3754: graft: introduce --abort flag to abort interrupted graft

2018-06-25 Thread yuja (Yuya Nishihara)
yuja added a comment.


  >   > This looks quite similar to rebase.abort(). Can we factor out a common 
part?
  >   
  >   
  >   We need to cleanup some of the rebase code first to factor out the common 
part. I will do that.
  
  Awesome, thanks. Should I review the current patch? or are you planning to
  revise it?

REPOSITORY
  rHG Mercurial

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

To: pulkit, #hg-reviewers
Cc: yuja, mercurial-devel
___
Mercurial-devel mailing list
Mercurial-devel@mercurial-scm.org
https://www.mercurial-scm.org/mailman/listinfo/mercurial-devel


D3754: graft: introduce --abort flag to abort interrupted graft

2018-06-25 Thread pulkit (Pulkit Goyal)
pulkit added a comment.


  In https://phab.mercurial-scm.org/D3754#58886, @yuja wrote:
  
  > This looks quite similar to rebase.abort(). Can we factor out a common part?
  
  
  We need to cleanup some of the rebase code first to factor out the common 
part. I will do that.
  
  > Maybe it's time to add a new module for rebase/graft thingy.
  
  I agree.

REPOSITORY
  rHG Mercurial

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

To: pulkit, #hg-reviewers
Cc: yuja, mercurial-devel
___
Mercurial-devel mailing list
Mercurial-devel@mercurial-scm.org
https://www.mercurial-scm.org/mailman/listinfo/mercurial-devel


D3754: graft: introduce --abort flag to abort interrupted graft

2018-06-25 Thread pulkit (Pulkit Goyal)
pulkit updated this revision to Diff 9275.

REPOSITORY
  rHG Mercurial

CHANGES SINCE LAST UPDATE
  https://phab.mercurial-scm.org/D3754?vs=9100=9275

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

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

CHANGE DETAILS

diff --git a/tests/test-graft.t b/tests/test-graft.t
--- a/tests/test-graft.t
+++ b/tests/test-graft.t
@@ -1670,3 +1670,218 @@
   |
   o  0:9092f1db7931 added a
   
+  $ cd ..
+
+Testing the --abort flag for `hg graft` which aborts and rollback to state
+before the graft
+
+  $ hg init abortgraft
+  $ cd abortgraft
+  $ for ch in a b c d; do echo $ch > $ch; hg add $ch; hg ci -Aqm "added "$ch; 
done;
+
+  $ hg up '.^^'
+  0 files updated, 0 files merged, 2 files removed, 0 files unresolved
+
+  $ echo x > x
+  $ hg ci -Aqm "added x"
+  $ hg up '.^'
+  0 files updated, 0 files merged, 1 files removed, 0 files unresolved
+  $ echo foo > c
+  $ hg ci -Aqm "added foo to c"
+
+  $ hg log -GT "{rev}:{node|short} {desc}"
+  @  5:36b793615f78 added foo to c
+  |
+  | o  4:863a25e1a9ea added x
+  |/
+  | o  3:9150fe93bec6 added d
+  | |
+  | o  2:155349b645be added c
+  |/
+  o  1:5f6d8a4bf34a added b
+  |
+  o  0:9092f1db7931 added a
+  
+  $ hg up 9150fe93bec6
+  2 files updated, 0 files merged, 0 files removed, 0 files unresolved
+
+  $ hg graft --abort
+  abort: no interrupted graft to abort
+  [255]
+
+when stripping is required
+  $ hg graft -r 4 -r 5
+  grafting 4:863a25e1a9ea "added x"
+  grafting 5:36b793615f78 "added foo to c" (tip)
+  merging c
+  warning: conflicts while merging c! (edit, then use 'hg resolve --mark')
+  abort: unresolved conflicts, can't continue
+  (use 'hg resolve' and 'hg graft --continue')
+  [255]
+
+  $ hg graft --continue --abort
+  abort: cannot use '--continue' and '--abort' together
+  [255]
+
+  $ hg graft --abort --stop
+  abort: cannot use '--abort' and '--stop' together
+  [255]
+
+  $ hg graft --abort --currentuser
+  abort: cannot specify any other flag with '--abort'
+  [255]
+
+  $ hg graft --abort --edit
+  abort: cannot specify any other flag with '--abort'
+  [255]
+
+  $ hg graft --abort
+  graft aborted
+  working directory is now at 9150fe93bec6
+  $ hg log -GT "{rev}:{node|short} {desc}"
+  o  5:36b793615f78 added foo to c
+  |
+  | o  4:863a25e1a9ea added x
+  |/
+  | @  3:9150fe93bec6 added d
+  | |
+  | o  2:155349b645be added c
+  |/
+  o  1:5f6d8a4bf34a added b
+  |
+  o  0:9092f1db7931 added a
+  
+when stripping is not required
+  $ hg graft -r 5
+  grafting 5:36b793615f78 "added foo to c" (tip)
+  merging c
+  warning: conflicts while merging c! (edit, then use 'hg resolve --mark')
+  abort: unresolved conflicts, can't continue
+  (use 'hg resolve' and 'hg graft --continue')
+  [255]
+
+  $ hg graft --abort
+  graft aborted
+  working directory is now at 9150fe93bec6
+  $ hg log -GT "{rev}:{node|short} {desc}"
+  o  5:36b793615f78 added foo to c
+  |
+  | o  4:863a25e1a9ea added x
+  |/
+  | @  3:9150fe93bec6 added d
+  | |
+  | o  2:155349b645be added c
+  |/
+  o  1:5f6d8a4bf34a added b
+  |
+  o  0:9092f1db7931 added a
+  
+when some of the changesets became public
+
+  $ hg graft -r 4 -r 5
+  grafting 4:863a25e1a9ea "added x"
+  grafting 5:36b793615f78 "added foo to c" (tip)
+  merging c
+  warning: conflicts while merging c! (edit, then use 'hg resolve --mark')
+  abort: unresolved conflicts, can't continue
+  (use 'hg resolve' and 'hg graft --continue')
+  [255]
+
+  $ hg log -GT "{rev}:{node|short} {desc}"
+  @  6:6ec71c037d94 added x
+  |
+  | o  5:36b793615f78 added foo to c
+  | |
+  | | o  4:863a25e1a9ea added x
+  | |/
+  o |  3:9150fe93bec6 added d
+  | |
+  o |  2:155349b645be added c
+  |/
+  o  1:5f6d8a4bf34a added b
+  |
+  o  0:9092f1db7931 added a
+  
+  $ hg phase -r 6 --public
+
+  $ hg graft --abort
+  cannot clean up public changesets 6ec71c037d94
+  graft aborted
+  working directory is now at 6ec71c037d94
+
+when we created new changesets on top of existing one
+
+  $ hg up '.^^'
+  0 files updated, 0 files merged, 2 files removed, 0 files unresolved
+  $ echo y > y
+  $ hg ci -Aqm "added y"
+  $ echo z > z
+  $ hg ci -Aqm "added z"
+
+  $ hg up 3
+  1 files updated, 0 files merged, 3 files removed, 0 files unresolved
+  $ hg log -GT "{rev}:{node|short} {desc}"
+  o  8:637f9e9bbfd4 added z
+  |
+  o  7:123221671fd4 added y
+  |
+  | o  6:6ec71c037d94 added x
+  | |
+  | | o  5:36b793615f78 added foo to c
+  | | |
+  | | | o  4:863a25e1a9ea added x
+  | | |/
+  | @ |  3:9150fe93bec6 added d
+  |/ /
+  o /  2:155349b645be added c
+  |/
+  o  1:5f6d8a4bf34a added b
+  |
+  o  0:9092f1db7931 added a
+  
+  $ hg graft -r 8 -r 7 -r 5
+  grafting 8:637f9e9bbfd4 "added z" (tip)
+  grafting 7:123221671fd4 "added y"
+  grafting 5:36b793615f78 "added foo to c"
+  merging c
+  warning: conflicts while merging c! (edit, then use 'hg resolve --mark')
+  abort: unresolved conflicts, can't continue
+  (use 'hg resolve' and 'hg graft 

D3754: graft: introduce --abort flag to abort interrupted graft

2018-06-16 Thread yuja (Yuya Nishihara)
yuja added a comment.


  > +def _abortgraft(ui, repo, graftstate):
  >  +"""abort the interrupted graft and rollbacks to the state before 
interrupted
  >  +graft"""
  >  +if not graftstate.exists():
  >  +raise error.Abort(_("no interrupted graft to abort"))
  >  +statedata = _readgraftstate(repo, graftstate)
  >  +startnode = statedata.get('startnode')
  >  +if not startnode:
  >  +# and old graft state which does not have all the data required 
to abort
  >  +# the graft
  >  +raise error.Abort(_("cannot abort using an old graftstate"))
  >  +newnodes = statedata.get('newnodes')
  >  +hg.updaterepo(repo, startnode, True)
  >  +if newnodes:
  
  It's probably better to not updating to the startnode if we can't strip
  grafted revisions.
  
  > +newnodes = [repo[r].rev() for r in newnodes]
  >  +
  >  +# checking that none of the newnodes turned public or is public
  >  +immutable = [c for c in newnodes if not repo[c].mutable()]
  >  +if immutable:
  >  +repo.ui.warn(_("cannot clean up public changesets %s\n")
  >  + % ','.join(bytes(repo[r]) for r in immutable),
  >  + hint=_("see 'hg help phases' for details"))
  >  +
  >  +# checking that no new nodes are created on top of grafted revs
  >  +desc = set(repo.changelog.descendants(newnodes))
  >  +if desc - set(newnodes):
  >  +repo.ui.warn(_("new changesets detected on destination "
  >  +   "branch, can't strip\n"))
  >  +
  >  +with repo.wlock(), repo.lock():
  >  +# stripping the new nodes created
  >  +strippoints = [c.node() for c in repo.set("roots(%ld)", 
newnodes)]
  >  +repair.strip(repo.ui, repo, strippoints, False)
  >  +
  >  +ui.write(_("graft aborted\nworking directory is now at %s\n")
  >  + % repo[startnode].hex()[:12])
  >  +graftstate.delete()
  >  +return 0
  
  This looks quite similar to rebase.abort(). Can we factor out a common part?
  Maybe it's time to add a new module for rebase/graft thingy.

REPOSITORY
  rHG Mercurial

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

To: pulkit, #hg-reviewers
Cc: yuja, mercurial-devel
___
Mercurial-devel mailing list
Mercurial-devel@mercurial-scm.org
https://www.mercurial-scm.org/mailman/listinfo/mercurial-devel


Re: D3754: graft: introduce --abort flag to abort interrupted graft

2018-06-16 Thread Yuya Nishihara
> +def _abortgraft(ui, repo, graftstate):
> +"""abort the interrupted graft and rollbacks to the state before 
> interrupted
> +graft"""
> +if not graftstate.exists():
> +raise error.Abort(_("no interrupted graft to abort"))
> +statedata = _readgraftstate(repo, graftstate)
> +startnode = statedata.get('startnode')
> +if not startnode:
> +# and old graft state which does not have all the data required to 
> abort
> +# the graft
> +raise error.Abort(_("cannot abort using an old graftstate"))
> +newnodes = statedata.get('newnodes')
> +hg.updaterepo(repo, startnode, True)
> +if newnodes:

It's probably better to not updating to the startnode if we can't strip
grafted revisions.

> +newnodes = [repo[r].rev() for r in newnodes]
> +
> +# checking that none of the newnodes turned public or is public
> +immutable = [c for c in newnodes if not repo[c].mutable()]
> +if immutable:
> +repo.ui.warn(_("cannot clean up public changesets %s\n")
> + % ','.join(bytes(repo[r]) for r in immutable),
> + hint=_("see 'hg help phases' for details"))
> +
> +# checking that no new nodes are created on top of grafted revs
> +desc = set(repo.changelog.descendants(newnodes))
> +if desc - set(newnodes):
> +repo.ui.warn(_("new changesets detected on destination "
> +   "branch, can't strip\n"))
> +
> +with repo.wlock(), repo.lock():
> +# stripping the new nodes created
> +strippoints = [c.node() for c in repo.set("roots(%ld)", 
> newnodes)]
> +repair.strip(repo.ui, repo, strippoints, False)
> +
> +ui.write(_("graft aborted\nworking directory is now at %s\n")
> + % repo[startnode].hex()[:12])
> +graftstate.delete()
> +return 0

This looks quite similar to rebase.abort(). Can we factor out a common part?
Maybe it's time to add a new module for rebase/graft thingy.
___
Mercurial-devel mailing list
Mercurial-devel@mercurial-scm.org
https://www.mercurial-scm.org/mailman/listinfo/mercurial-devel


D3754: graft: introduce --abort flag to abort interrupted graft

2018-06-15 Thread pulkit (Pulkit Goyal)
pulkit created this revision.
Herald added a subscriber: mercurial-devel.
Herald added a reviewer: hg-reviewers.

REVISION SUMMARY
  This patch introduces a new --abort flag to `hg graft` command which aborts an
  interrupted graft and rollbacks to the state before graft.
  
  The behavior when some of grafted changeset get's published while interrupted
  graft or we have new descendants on grafted changesets is same as that of 
rebase
  which is warn the user, don't strip and abort the abort the graft.
  
  Tests are added for the new flag.
  
  .. feature::
  
`hg graft` now has a `--abort` flag which aborts the interrupted graft and
rollbacks to state before the graft.

REPOSITORY
  rHG Mercurial

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

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

CHANGE DETAILS

diff --git a/tests/test-graft.t b/tests/test-graft.t
--- a/tests/test-graft.t
+++ b/tests/test-graft.t
@@ -1670,3 +1670,219 @@
   |
   o  0:9092f1db7931 added a
   
+  $ cd ..
+
+Testing the --abort flag for `hg graft` which aborts and rollback to state
+before the graft
+
+  $ hg init abortgraft
+  $ cd abortgraft
+  $ for ch in a b c d; do echo $ch > $ch; hg add $ch; hg ci -Aqm "added "$ch; 
done;
+
+  $ hg up '.^^'
+  0 files updated, 0 files merged, 2 files removed, 0 files unresolved
+
+  $ echo x > x
+  $ hg ci -Aqm "added x"
+  $ hg up '.^'
+  0 files updated, 0 files merged, 1 files removed, 0 files unresolved
+  $ echo foo > c
+  $ hg ci -Aqm "added foo to c"
+
+  $ hg log -GT "{rev}:{node|short} {desc}"
+  @  5:36b793615f78 added foo to c
+  |
+  | o  4:863a25e1a9ea added x
+  |/
+  | o  3:9150fe93bec6 added d
+  | |
+  | o  2:155349b645be added c
+  |/
+  o  1:5f6d8a4bf34a added b
+  |
+  o  0:9092f1db7931 added a
+  
+  $ hg up 9150fe93bec6
+  2 files updated, 0 files merged, 0 files removed, 0 files unresolved
+
+  $ hg graft --abort
+  abort: no interrupted graft to abort
+  [255]
+
+when stripping is required
+  $ hg graft -r 4 -r 5
+  grafting 4:863a25e1a9ea "added x"
+  grafting 5:36b793615f78 "added foo to c" (tip)
+  merging c
+  warning: conflicts while merging c! (edit, then use 'hg resolve --mark')
+  abort: unresolved conflicts, can't continue
+  (use 'hg resolve' and 'hg graft --continue')
+  [255]
+
+  $ hg graft --continue --abort
+  abort: cannot use '--continue' and '--abort' together
+  [255]
+
+  $ hg graft --abort --stop
+  abort: cannot use '--abort' and '--stop' together
+  [255]
+
+  $ hg graft --abort --currentuser
+  abort: cannot specify any other flag with '--abort'
+  [255]
+
+  $ hg graft --abort --edit
+  abort: cannot specify any other flag with '--abort'
+  [255]
+
+  $ hg graft --abort
+  graft aborted
+  working directory is now at 9150fe93bec6
+  $ hg log -GT "{rev}:{node|short} {desc}"
+  o  5:36b793615f78 added foo to c
+  |
+  | o  4:863a25e1a9ea added x
+  |/
+  | @  3:9150fe93bec6 added d
+  | |
+  | o  2:155349b645be added c
+  |/
+  o  1:5f6d8a4bf34a added b
+  |
+  o  0:9092f1db7931 added a
+  
+when stripping is not required
+  $ hg graft -r 5
+  grafting 5:36b793615f78 "added foo to c" (tip)
+  merging c
+  warning: conflicts while merging c! (edit, then use 'hg resolve --mark')
+  abort: unresolved conflicts, can't continue
+  (use 'hg resolve' and 'hg graft --continue')
+  [255]
+
+  $ hg graft --abort
+  graft aborted
+  working directory is now at 9150fe93bec6
+  $ hg log -GT "{rev}:{node|short} {desc}"
+  o  5:36b793615f78 added foo to c
+  |
+  | o  4:863a25e1a9ea added x
+  |/
+  | @  3:9150fe93bec6 added d
+  | |
+  | o  2:155349b645be added c
+  |/
+  o  1:5f6d8a4bf34a added b
+  |
+  o  0:9092f1db7931 added a
+  
+when some of the changesets became public
+
+  $ hg graft -r 4 -r 5
+  grafting 4:863a25e1a9ea "added x"
+  grafting 5:36b793615f78 "added foo to c" (tip)
+  merging c
+  warning: conflicts while merging c! (edit, then use 'hg resolve --mark')
+  abort: unresolved conflicts, can't continue
+  (use 'hg resolve' and 'hg graft --continue')
+  [255]
+
+  $ hg log -GT "{rev}:{node|short} {desc}"
+  @  6:6ec71c037d94 added x
+  |
+  | o  5:36b793615f78 added foo to c
+  | |
+  | | o  4:863a25e1a9ea added x
+  | |/
+  o |  3:9150fe93bec6 added d
+  | |
+  o |  2:155349b645be added c
+  |/
+  o  1:5f6d8a4bf34a added b
+  |
+  o  0:9092f1db7931 added a
+  
+  $ hg phase -r 6 --public
+
+  $ hg graft --abort
+  cannot clean up public changesets 6ec71c037d94
+  graft aborted
+  working directory is now at 9150fe93bec6
+
+when we created new changesets on top of existing one
+
+  $ hg up '.^'
+  0 files updated, 0 files merged, 1 files removed, 0 files unresolved
+  $ echo y > y
+  $ hg ci -Aqm "added y"
+  $ echo z > z
+  $ hg ci -Aqm "added z"
+
+  $ hg up 3
+  1 files updated, 0 files merged, 3 files removed, 0 files unresolved
+  $ hg log -GT "{rev}:{node|short} {desc}"
+  o  7:637f9e9bbfd4 added z
+  |
+  o  6:123221671fd4 added y
+  |
+  | o  5:36b793615f78 added foo to c
+  |