This patch creates cmdutil.continuegraft() function
which contains the logic to resume graft when called directly.
This function is then registered as continuefunc to support
hg continue.
Results are shown as tests.
durin42 |
hg-reviewers |
This patch creates cmdutil.continuegraft() function
which contains the logic to resume graft when called directly.
This function is then registered as continuefunc to support
hg continue.
Results are shown as tests.
Lint Skipped |
Unit Tests Skipped |
Path | Packages | |||
---|---|---|---|---|
M | mercurial/cmdutil.py (23 lines) | |||
M | mercurial/commands.py (1 line) | |||
M | tests/test-graft.t (39 lines) | |||
M | tests/test-issue1175.t (10 lines) |
Commit | Parents | Author | Summary | Date |
---|---|---|---|---|
03bedefd266f | 157610e18a46 | Taapas Agrawal | Jul 21 2019, 1:54 PM |
Status | Author | Revision | |
---|---|---|---|
Abandoned | taapas1128 | ||
Closed | taapas1128 | ||
Closed | taapas1128 | ||
Accepted | taapas1128 | ||
Accepted | taapas1128 | ||
Closed | taapas1128 | ||
Needs Revision | taapas1128 |
return {'nodes': nodes} | return {'nodes': nodes} | ||||
def hgabortgraft(ui, repo): | def hgabortgraft(ui, repo): | ||||
""" abort logic for aborting graft using 'hg abort'""" | """ abort logic for aborting graft using 'hg abort'""" | ||||
with repo.wlock(): | with repo.wlock(): | ||||
graftstate = statemod.cmdstate(repo, 'graftstate') | graftstate = statemod.cmdstate(repo, 'graftstate') | ||||
return abortgraft(ui, repo, graftstate) | return abortgraft(ui, repo, graftstate) | ||||
def continuegraft(ui, repo): | |||||
"""logic to resume interrupted graft using 'hg continue'""" | |||||
with repo.wlock(): | |||||
graftstate = statemod.cmdstate(repo, 'graftstate') | |||||
opts = {} | |||||
statedata = {} | |||||
cont = True | |||||
basectx = None | |||||
nodes, opts = updateopts(repo, graftstate, opts) | |||||
revs = [repo[node].rev() for node in nodes] | |||||
skipped = set() | |||||
if basectx is None: | |||||
# check for merges | |||||
for rev in repo.revs('%ld and merge()', revs): | |||||
ui.warn(_('skipping ungraftable merge revision %d\n') % rev) | |||||
skipped.add(rev) | |||||
revs = [r for r in revs if r not in skipped] | |||||
if not revs: | |||||
return -1 | |||||
finishgraft(repo, ui, basectx, revs, statedata, cont, opts) | |||||
graftstate.delete() | |||||
return 0 | |||||
def finishgraft(repo, ui, basectx, revs, statedata, cont, opts, | def finishgraft(repo, ui, basectx, revs, statedata, cont, opts, | ||||
graftstate=None): | graftstate=None): | ||||
"""logic to execute graft once revs are generated""" | """logic to execute graft once revs are generated""" | ||||
if not graftstate: | if not graftstate: | ||||
graftstate = statemod.cmdstate(repo, 'graftstate') | graftstate = statemod.cmdstate(repo, 'graftstate') | ||||
for pos, ctx in enumerate(repo.set("%ld", revs)): | for pos, ctx in enumerate(repo.set("%ld", revs)): | ||||
desc = '%d:%s "%s"' % (ctx.rev(), ctx, | desc = '%d:%s "%s"' % (ctx.rev(), ctx, | ||||
ctx.description().split('\n', 1)[0]) | ctx.description().split('\n', 1)[0]) |
graftstate.delete() | graftstate.delete() | ||||
ui.status(_("stopped the interrupted graft\n")) | ui.status(_("stopped the interrupted graft\n")) | ||||
ui.status(_("working directory is now at %s\n") % pctx.hex()[:12]) | ui.status(_("working directory is now at %s\n") % pctx.hex()[:12]) | ||||
return 0 | return 0 | ||||
statemod.addunfinished( | statemod.addunfinished( | ||||
'graft', fname='graftstate', clearable=True, stopflag=True, | 'graft', fname='graftstate', clearable=True, stopflag=True, | ||||
continueflag=True, abortfunc=cmdutil.hgabortgraft, | continueflag=True, abortfunc=cmdutil.hgabortgraft, | ||||
continuefunc=cmdutil.continuegraft, | |||||
cmdhint=_("use 'hg graft --continue' or 'hg graft --stop' to stop") | cmdhint=_("use 'hg graft --continue' or 'hg graft --stop' to stop") | ||||
) | ) | ||||
@command('grep', | @command('grep', | ||||
[('0', 'print0', None, _('end fields with NUL')), | [('0', 'print0', None, _('end fields with NUL')), | ||||
('', 'all', None, _('print all revisions that match (DEPRECATED) ')), | ('', 'all', None, _('print all revisions that match (DEPRECATED) ')), | ||||
('', 'diff', None, _('print all revisions when the term was introduced ' | ('', 'diff', None, _('print all revisions when the term was introduced ' | ||||
'or removed')), | 'or removed')), |
#testcases abortcommand abortflag | #testcases commandmode abortflag continueflag | ||||
$ cat >> $HGRCPATH <<EOF | $ cat >> $HGRCPATH <<EOF | ||||
> [extdiff] | > [extdiff] | ||||
> # for portability: | > # for portability: | ||||
> pdiff = sh "$RUNTESTDIR/pdiff" | > pdiff = sh "$RUNTESTDIR/pdiff" | ||||
> EOF | > EOF | ||||
#if abortflag | #if abortflag | ||||
$ cat >> $HGRCPATH <<EOF | $ cat >> $HGRCPATH <<EOF | ||||
> [alias] | > [alias] | ||||
> abort = graft --abort | > abort = graft --abort | ||||
> EOF | > EOF | ||||
#endif | #endif | ||||
#if continueflag | |||||
$ cat >> $HGRCPATH <<EOF | |||||
> [alias] | |||||
> continue = graft --continue | |||||
> EOF | |||||
#endif | |||||
Create a repo with some stuff in it: | Create a repo with some stuff in it: | ||||
$ hg init a | $ hg init a | ||||
$ cd a | $ cd a | ||||
$ echo a > a | $ echo a > a | ||||
$ echo a > d | $ echo a > d | ||||
$ echo a > e | $ echo a > e | ||||
$ hg ci -qAm0 | $ hg ci -qAm0 | ||||
note: possible conflict - c was deleted and renamed to: | note: possible conflict - c was deleted and renamed to: | ||||
a | a | ||||
note: graft of 2:5c095ad7e90f created no changes to commit | note: graft of 2:5c095ad7e90f created no changes to commit | ||||
Can't continue without starting: | Can't continue without starting: | ||||
$ hg -q up -cr tip | $ hg -q up -cr tip | ||||
$ hg rm -q e | $ hg rm -q e | ||||
$ hg graft --continue | $ hg continue | ||||
abort: no graft in progress | abort: no graft in progress (continueflag !) | ||||
abort: no operation in progress (no-continueflag !) | |||||
[255] | [255] | ||||
$ hg revert -r . -q e | $ hg revert -r . -q e | ||||
Need to specify a rev: | Need to specify a rev: | ||||
$ hg graft | $ hg graft | ||||
abort: no revisions specified | abort: no revisions specified | ||||
[255] | [255] | ||||
Writing the nodes in old format to graftstate | Writing the nodes in old format to graftstate | ||||
$ hg log -r 1 -r 2 -T '{node}\n' > .hg/graftstate | $ hg log -r 1 -r 2 -T '{node}\n' > .hg/graftstate | ||||
$ echo foo > b | $ echo foo > b | ||||
$ hg resolve -m | $ hg resolve -m | ||||
(no more unresolved files) | (no more unresolved files) | ||||
continue: hg graft --continue | continue: hg graft --continue | ||||
$ hg graft --continue | |||||
#if commandmode | |||||
$ hg continue --dry-run | |||||
graft in progress, will be resumed | |||||
#endif | |||||
$ hg continue | |||||
grafting 1:80e6d2c47cfe "added b" | grafting 1:80e6d2c47cfe "added b" | ||||
grafting 2:8be98ac1a569 "added c" | grafting 2:8be98ac1a569 "added c" | ||||
Testing that --user is preserved during conflicts and value is reused while | Testing that --user is preserved during conflicts and value is reused while | ||||
running `hg graft --continue` | running `hg graft --continue` | ||||
$ hg log -G | $ hg log -G | ||||
@ changeset: 5:711e9fa999f1 | @ changeset: 5:711e9fa999f1 | ||||
(use 'hg resolve' and 'hg graft --continue') | (use 'hg resolve' and 'hg graft --continue') | ||||
[255] | [255] | ||||
$ echo wat > b | $ echo wat > b | ||||
$ hg resolve -m | $ hg resolve -m | ||||
(no more unresolved files) | (no more unresolved files) | ||||
continue: hg graft --continue | continue: hg graft --continue | ||||
$ hg graft --continue | $ hg continue | ||||
grafting 1:80e6d2c47cfe "added b" | grafting 1:80e6d2c47cfe "added b" | ||||
grafting 2:8be98ac1a569 "added c" | grafting 2:8be98ac1a569 "added c" | ||||
$ hg log -Gr 3:: | $ hg log -Gr 3:: | ||||
@ changeset: 7:11a36ffaacf2 | @ changeset: 7:11a36ffaacf2 | ||||
| tag: tip | | tag: tip | ||||
| user: batman | | user: batman | ||||
| date: Thu Jan 01 00:00:00 1970 +0000 | | date: Thu Jan 01 00:00:00 1970 +0000 | ||||
abort: unresolved conflicts, can't continue | abort: unresolved conflicts, can't continue | ||||
(use 'hg resolve' and 'hg graft --continue') | (use 'hg resolve' and 'hg graft --continue') | ||||
[255] | [255] | ||||
$ echo foobar > b | $ echo foobar > b | ||||
$ hg resolve -m | $ hg resolve -m | ||||
(no more unresolved files) | (no more unresolved files) | ||||
continue: hg graft --continue | continue: hg graft --continue | ||||
$ hg graft --continue | $ hg continue | ||||
grafting 1:80e6d2c47cfe "added b" | grafting 1:80e6d2c47cfe "added b" | ||||
grafting 2:8be98ac1a569 "added c" | grafting 2:8be98ac1a569 "added c" | ||||
$ hg log -Gr '.^^::.' | $ hg log -Gr '.^^::.' | ||||
@ changeset: 9:1896b76e007a | @ changeset: 9:1896b76e007a | ||||
| tag: tip | | tag: tip | ||||
| user: test | | user: test | ||||
| date: Fri Feb 13 21:18:00 2009 -0002 | | date: Fri Feb 13 21:18:00 2009 -0002 | ||||
(use 'hg resolve' and 'hg graft --continue') | (use 'hg resolve' and 'hg graft --continue') | ||||
[255] | [255] | ||||
$ echo foobar > b | $ echo foobar > b | ||||
$ hg resolve -m | $ hg resolve -m | ||||
(no more unresolved files) | (no more unresolved files) | ||||
continue: hg graft --continue | continue: hg graft --continue | ||||
$ hg graft --continue | $ hg continue | ||||
grafting 1:80e6d2c47cfe "added b" | grafting 1:80e6d2c47cfe "added b" | ||||
grafting 2:8be98ac1a569 "added c" | grafting 2:8be98ac1a569 "added c" | ||||
$ hg log -GT "{rev}:{node|short} {desc}" -r '.^^::.' | $ hg log -GT "{rev}:{node|short} {desc}" -r '.^^::.' | ||||
@ 11:30c1050a58b2 added c | @ 11:30c1050a58b2 added c | ||||
| (grafted from 8be98ac1a56990c2d9ca6861041b8390af7bd6f3) | | (grafted from 8be98ac1a56990c2d9ca6861041b8390af7bd6f3) | ||||
o 10:ec7eda2313e2 added b | o 10:ec7eda2313e2 added b | ||||
| (grafted from 80e6d2c47cfe5b3185519568327a17a061c7efb6) | | (grafted from 80e6d2c47cfe5b3185519568327a17a061c7efb6) | ||||
| | | | ||||
o 0:9092f1db7931 added a | o 0:9092f1db7931 added a | ||||
$ hg up 9150fe93bec6 | $ hg up 9150fe93bec6 | ||||
2 files updated, 0 files merged, 0 files removed, 0 files unresolved | 2 files updated, 0 files merged, 0 files removed, 0 files unresolved | ||||
$ hg abort | $ hg abort | ||||
abort: no interrupted graft to abort (abortflag !) | abort: no interrupted graft to abort (abortflag !) | ||||
abort: no operation in progress (abortcommand !) | abort: no operation in progress (no-abortflag !) | ||||
[255] | [255] | ||||
when stripping is required | when stripping is required | ||||
$ hg graft -r 4 -r 5 | $ hg graft -r 4 -r 5 | ||||
grafting 4:863a25e1a9ea "added x" | grafting 4:863a25e1a9ea "added x" | ||||
grafting 5:36b793615f78 "added foo to c" (tip) | grafting 5:36b793615f78 "added foo to c" (tip) | ||||
merging c | merging c | ||||
warning: conflicts while merging c! (edit, then use 'hg resolve --mark') | warning: conflicts while merging c! (edit, then use 'hg resolve --mark') | ||||
$ hg graft --abort --currentuser | $ hg graft --abort --currentuser | ||||
abort: cannot specify any other flag with '--abort' | abort: cannot specify any other flag with '--abort' | ||||
[255] | [255] | ||||
$ hg graft --abort --edit | $ hg graft --abort --edit | ||||
abort: cannot specify any other flag with '--abort' | abort: cannot specify any other flag with '--abort' | ||||
[255] | [255] | ||||
#if abortcommand | #if commandmode | ||||
when in dry-run mode | when in dry-run mode | ||||
$ hg abort --dry-run | $ hg abort --dry-run | ||||
graft in progress, will be aborted | graft in progress, will be aborted | ||||
#endif | #endif | ||||
$ hg abort | $ hg abort | ||||
graft aborted | graft aborted | ||||
working directory is now at 9150fe93bec6 | working directory is now at 9150fe93bec6 | ||||
[255] | [255] | ||||
Resolve conflict: | Resolve conflict: | ||||
$ echo A>a | $ echo A>a | ||||
$ hg resolve --mark | $ hg resolve --mark | ||||
(no more unresolved files) | (no more unresolved files) | ||||
continue: hg graft --continue | continue: hg graft --continue | ||||
$ hg graft --continue | $ hg continue | ||||
grafting 3:09e253b87e17 "A in file a" | grafting 3:09e253b87e17 "A in file a" | ||||
$ hg log -GT "{rev}:{node|short} {desc}\n" | $ hg log -GT "{rev}:{node|short} {desc}\n" | ||||
@ 4:2aa9ad1006ff B in file a | @ 4:2aa9ad1006ff B in file a | ||||
| | | | ||||
| o 3:09e253b87e17 A in file a | | o 3:09e253b87e17 A in file a | ||||
| | | | | | ||||
| o 2:d36c0562f908 c | | o 2:d36c0562f908 c | ||||
| | | | | | ||||
abort: unresolved conflicts, can't continue | abort: unresolved conflicts, can't continue | ||||
(use 'hg resolve' and 'hg graft --continue') | (use 'hg resolve' and 'hg graft --continue') | ||||
[255] | [255] | ||||
$ echo A>a | $ echo A>a | ||||
$ hg resolve --mark | $ hg resolve --mark | ||||
(no more unresolved files) | (no more unresolved files) | ||||
continue: hg graft --continue | continue: hg graft --continue | ||||
$ hg graft --continue | $ hg continue | ||||
grafting 3:09e253b87e17 "A in file a" | grafting 3:09e253b87e17 "A in file a" | ||||
$ hg diff | $ hg diff | ||||
diff -r 2aa9ad1006ff a | diff -r 2aa9ad1006ff a | ||||
--- a/a Thu Jan 01 00:00:00 1970 +0000 | --- a/a Thu Jan 01 00:00:00 1970 +0000 | ||||
+++ b/a Thu Jan 01 00:00:00 1970 +0000 | +++ b/a Thu Jan 01 00:00:00 1970 +0000 | ||||
@@ -1,1 +1,1 @@ | @@ -1,1 +1,1 @@ | ||||
-B | -B | ||||
+A | +A |
#testcases continueflag continuecommand | |||||
#if continueflag | |||||
$ cat >> $HGRCPATH <<EOF | |||||
> [alias] | |||||
> continue = graft --continue | |||||
> EOF | |||||
#endif | |||||
https://bz.mercurial-scm.org/1175 | https://bz.mercurial-scm.org/1175 | ||||
$ hg init | $ hg init | ||||
$ touch a | $ touch a | ||||
$ hg ci -Am0 | $ hg ci -Am0 | ||||
adding a | adding a | ||||
$ hg mv a a1 | $ hg mv a a1 | ||||
abort: unresolved conflicts, can't continue | abort: unresolved conflicts, can't continue | ||||
(use 'hg resolve' and 'hg graft --continue') | (use 'hg resolve' and 'hg graft --continue') | ||||
[255] | [255] | ||||
$ echo a > b | $ echo a > b | ||||
$ echo b3 >> b | $ echo b3 >> b | ||||
$ hg resolve --mark b | $ hg resolve --mark b | ||||
(no more unresolved files) | (no more unresolved files) | ||||
continue: hg graft --continue | continue: hg graft --continue | ||||
$ hg graft --continue | $ hg continue | ||||
grafting 1:5974126fad84 "b1" | grafting 1:5974126fad84 "b1" | ||||
warning: can't find ancestor for 'b' copied from 'a'! | warning: can't find ancestor for 'b' copied from 'a'! | ||||
$ hg log -f b -T 'changeset: {rev}:{node|short}\nsummary: {desc}\n\n' | $ hg log -f b -T 'changeset: {rev}:{node|short}\nsummary: {desc}\n\n' | ||||
changeset: 3:376d30ccffc0 | changeset: 3:376d30ccffc0 | ||||
summary: b1 | summary: b1 | ||||
changeset: 2:416baaa2e5e4 | changeset: 2:416baaa2e5e4 | ||||
summary: b2 | summary: b2 | ||||
changeset: 0:3903775176ed | changeset: 0:3903775176ed | ||||
summary: a | summary: a | ||||