Patchwork D6665: continue: added support for graft

login
register
mail settings
Submitter phabricator
Date July 21, 2019, 6:06 p.m.
Message ID <differential-rev-PHID-DREV-oppkxzxovajqunyelr2b-req@mercurial-scm.org>
Download mbox | patch
Permalink /patch/40996/
State New
Headers show

Comments

phabricator - July 21, 2019, 6:06 p.m.
taapas1128 created this revision.
Herald added a subscriber: mercurial-devel.
Herald added a reviewer: hg-reviewers.

REVISION SUMMARY
  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.

REPOSITORY
  rHG Mercurial

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

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

CHANGE DETAILS




To: taapas1128, #hg-reviewers
Cc: mercurial-devel

Patch

diff --git a/tests/test-issue1175.t b/tests/test-issue1175.t
--- a/tests/test-issue1175.t
+++ b/tests/test-issue1175.t
@@ -1,3 +1,11 @@ 
+#testcases continueflag continuecommand
+#if continueflag
+  $ cat >> $HGRCPATH <<EOF
+  > [alias]
+  > continue = graft --continue
+  > EOF
+#endif
+
 https://bz.mercurial-scm.org/1175
 
   $ hg init
@@ -80,7 +88,7 @@ 
   $ hg resolve --mark b
   (no more unresolved files)
   continue: hg graft --continue
-  $ hg graft --continue
+  $ hg continue
   grafting 1:5974126fad84 "b1"
   warning: can't find ancestor for 'b' copied from 'a'!
   $ hg log -f b -T 'changeset:   {rev}:{node|short}\nsummary:     {desc}\n\n'
diff --git a/tests/test-graft.t b/tests/test-graft.t
--- a/tests/test-graft.t
+++ b/tests/test-graft.t
@@ -1,4 +1,4 @@ 
-#testcases abortcommand abortflag
+#testcases commandmode abortflag continueflag
 
   $ cat >> $HGRCPATH <<EOF
   > [extdiff]
@@ -13,6 +13,13 @@ 
   > EOF
 #endif
 
+#if continueflag
+  $ cat >> $HGRCPATH <<EOF
+  > [alias]
+  > continue = graft --continue
+  > EOF
+#endif
+
 Create a repo with some stuff in it:
 
   $ hg init a
@@ -92,9 +99,11 @@ 
 
   $ hg -q up -cr tip
   $ hg rm -q e
-  $ hg graft --continue
-  abort: no graft in progress
-  [255]
+  $ hg continue
+  abort: no graft in progress (continueflag !)
+  abort: no operation in progress (no-continueflag !)
+  [255]
+
   $ hg revert -r . -q e
 
 Need to specify a rev:
@@ -1697,7 +1706,13 @@ 
   $ hg resolve -m
   (no more unresolved files)
   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 2:8be98ac1a569 "added c"
 
@@ -1754,7 +1769,7 @@ 
   (no more unresolved files)
   continue: hg graft --continue
 
-  $ hg graft --continue
+  $ hg continue
   grafting 1:80e6d2c47cfe "added b"
   grafting 2:8be98ac1a569 "added c"
 
@@ -1803,7 +1818,7 @@ 
   $ hg resolve -m
   (no more unresolved files)
   continue: hg graft --continue
-  $ hg graft --continue
+  $ hg continue
   grafting 1:80e6d2c47cfe "added b"
   grafting 2:8be98ac1a569 "added c"
 
@@ -1843,7 +1858,7 @@ 
   (no more unresolved files)
   continue: hg graft --continue
 
-  $ hg graft --continue
+  $ hg continue
   grafting 1:80e6d2c47cfe "added b"
   grafting 2:8be98ac1a569 "added c"
 
@@ -1997,7 +2012,7 @@ 
 
   $ hg abort
   abort: no interrupted graft to abort (abortflag !)
-  abort: no operation in progress (abortcommand !)
+  abort: no operation in progress (no-abortflag !)
   [255]
 
 when stripping is required
@@ -2026,7 +2041,7 @@ 
   abort: cannot specify any other flag with '--abort'
   [255]
 
-#if abortcommand
+#if commandmode
 when in dry-run mode
   $ hg abort --dry-run
   graft in progress, will be aborted
@@ -2273,7 +2288,7 @@ 
   (no more unresolved files)
   continue: hg graft --continue
 
-  $ hg graft --continue
+  $ hg continue
   grafting 3:09e253b87e17 "A in file a"
   $ hg log -GT "{rev}:{node|short} {desc}\n"
   @  4:2aa9ad1006ff B in file a
@@ -2350,7 +2365,7 @@ 
   $ hg resolve --mark
   (no more unresolved files)
   continue: hg graft --continue
-  $ hg graft --continue
+  $ hg continue
   grafting 3:09e253b87e17 "A in file a"
   $ hg diff
   diff -r 2aa9ad1006ff a
diff --git a/mercurial/commands.py b/mercurial/commands.py
--- a/mercurial/commands.py
+++ b/mercurial/commands.py
@@ -2628,6 +2628,7 @@ 
 statemod.addunfinished(
     'graft', fname='graftstate', clearable=True, stopflag=True,
     continueflag=True, abortfunc=cmdutil.hgabortgraft,
+    continuefunc=cmdutil.continuegraft,
     cmdhint=_("use 'hg graft --continue' or 'hg graft --stop' to stop")
 )
 
diff --git a/mercurial/cmdutil.py b/mercurial/cmdutil.py
--- a/mercurial/cmdutil.py
+++ b/mercurial/cmdutil.py
@@ -3426,6 +3426,28 @@ 
         graftstate = statemod.cmdstate(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
+        revs = continuegraftstate(repo, graftstate, opts)
+        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):
     """logic to execute graft once revs are generated"""
     graftstate = statemod.cmdstate(repo, 'graftstate')