Patchwork D6695: transplant: added support for --abort flag

login
register
mail settings
Submitter phabricator
Date July 25, 2019, 8:16 p.m.
Message ID <differential-rev-PHID-DREV-hd5vwhb24ugaeo3uaonp-req@mercurial-scm.org>
Download mbox | patch
Permalink /patch/41072/
State Superseded
Headers show

Comments

phabricator - July 25, 2019, 8:16 p.m.
taapas1128 created this revision.
Herald added subscribers: mercurial-devel, mjpieters.
Herald added a reviewer: hg-reviewers.

REVISION SUMMARY
  This adds fuctionality for `--abort` flag to `transplant`.
  A new method `abort` is added to `transplanter` class
  containing logic to abort transplant.
  
  Tests are updated as shown.

REPOSITORY
  rHG Mercurial

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

AFFECTED FILES
  hgext/transplant.py
  tests/test-transplant.t

CHANGE DETAILS




To: taapas1128, #hg-reviewers
Cc: mjpieters, mercurial-devel
phabricator - Aug. 7, 2019, 9:25 p.m.
pulkit added inline comments.

INLINE COMMENTS

> transplant.py:416
>  
> +    def clear(self):
> +        """clear the state file if it exists"""

We already have `self.unlog` doing the same here.

> transplant.py:421
> +
> +    def abort(self, ui ,repo):
> +        """logic to abort an interrupted transplant"""

the `,` after ui is misplaced a bit

> transplant.py:705
> +                raise error.Abort(_('no transplant to abort'))
> +            tp.abort(ui, repo)
> +            return

`return tp.abort(...)` here

> transplant.py:801
>          continuefunc=continuetransplant,
>          statushint=_('To continue:    hg transplant --continue\n'
> +                     'To abort:       hg transplant --abort'),

IIUC, we don't need to manually pass statushint and cmdhint now.

> test-transplant.t:466
> +  working directory is now at e8643552fde5
> +Repo log after abort
> +  $ hg glog

A better candidate here will be to show `hg status -v` as that will show whether there is an unfinished transplant or not.

REPOSITORY
  rHG Mercurial

CHANGES SINCE LAST ACTION
  https://phab.mercurial-scm.org/D6695/new/

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

To: taapas1128, #hg-reviewers
Cc: pulkit, mjpieters, mercurial-devel
phabricator - Aug. 8, 2019, 4:23 p.m.
pulkit added inline comments.

INLINE COMMENTS

> transplant.py:417
> +        """logic to abort an interrupted transplant"""
> +        if repo.vfs.exists('transplant/journal'):
> +            startctx = repo['.']

`canresume` above can be used for doing this check.

REPOSITORY
  rHG Mercurial

CHANGES SINCE LAST ACTION
  https://phab.mercurial-scm.org/D6695/new/

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

To: taapas1128, #hg-reviewers
Cc: pulkit, mjpieters, mercurial-devel
phabricator - Aug. 8, 2019, 8:37 p.m.
pulkit added inline comments.

INLINE COMMENTS

> pulkit wrote in test-transplant.t:466
> A better candidate here will be to show `hg status -v` as that will show whether there is an unfinished transplant or not.

This one is not done.

REPOSITORY
  rHG Mercurial

CHANGES SINCE LAST ACTION
  https://phab.mercurial-scm.org/D6695/new/

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

To: taapas1128, #hg-reviewers
Cc: pulkit, mjpieters, mercurial-devel
phabricator - Aug. 8, 2019, 8:40 p.m.
pulkit added a comment.


  Sorry for missing this earlier, but what happens when we are transplanting mutliple revisions and we have conflicts in a revision after the first one?

REPOSITORY
  rHG Mercurial

CHANGES SINCE LAST ACTION
  https://phab.mercurial-scm.org/D6695/new/

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

To: taapas1128, #hg-reviewers
Cc: pulkit, mjpieters, mercurial-devel
phabricator - Aug. 15, 2019, 3:32 p.m.
pulkit added a comment.


  Let's rename this to `transplant --stop` instead.

REPOSITORY
  rHG Mercurial

CHANGES SINCE LAST ACTION
  https://phab.mercurial-scm.org/D6695/new/

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

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

Patch

diff --git a/tests/test-transplant.t b/tests/test-transplant.t
--- a/tests/test-transplant.t
+++ b/tests/test-transplant.t
@@ -2,6 +2,7 @@ 
   $ cat <<EOF >> $HGRCPATH
   > [extensions]
   > transplant=
+  > graphlog=
   > EOF
 
 #if continueflag
@@ -19,6 +20,9 @@ 
   $ hg transplant --continue --all
   abort: --continue is incompatible with --branch, --all and --merge
   [255]
+  $ hg transplant --abort --all
+  abort: --abort is incompatible with --branch, --all and --merge
+  [255]
   $ hg transplant --all tip
   abort: --all requires a branch revision
   [255]
@@ -376,7 +380,8 @@ 
   applying 722f4667af76
   722f4667af76 transplanted to 76e321915884
 
-transplant --continue
+
+transplant --continue and --abort behaviour
 
   $ hg init ../tc
   $ cd ../tc
@@ -416,6 +421,36 @@ 
   $ echo foobar > foo
   $ hg ci -mfoobar
   created new head
+
+Repo log before transplant
+  $ hg glog
+  @  changeset:   4:e8643552fde5
+  |  tag:         tip
+  |  parent:      0:493149fa1541
+  |  user:        test
+  |  date:        Thu Jan 01 00:00:00 1970 +0000
+  |  summary:     foobar
+  |
+  | o  changeset:   3:1dab759070cf
+  | |  user:        test
+  | |  date:        Thu Jan 01 00:00:00 1970 +0000
+  | |  summary:     bar2
+  | |
+  | o  changeset:   2:9d6d6b5a8275
+  | |  user:        test
+  | |  date:        Thu Jan 01 00:00:00 1970 +0000
+  | |  summary:     bar
+  | |
+  | o  changeset:   1:46ae92138f3c
+  |/   user:        test
+  |    date:        Thu Jan 01 00:00:00 1970 +0000
+  |    summary:     foo2
+  |
+  o  changeset:   0:493149fa1541
+     user:        test
+     date:        Thu Jan 01 00:00:00 1970 +0000
+     summary:     foo
+  
   $ hg transplant 1:3
   applying 46ae92138f3c
   patching file foo
@@ -425,6 +460,49 @@ 
   abort: fix up the working directory and run hg transplant --continue
   [255]
 
+  $ hg transplant --abort
+  transplant aborted
+  working directory is now at e8643552fde5
+Repo log after abort
+  $ hg glog
+  @  changeset:   4:e8643552fde5
+  |  tag:         tip
+  |  parent:      0:493149fa1541
+  |  user:        test
+  |  date:        Thu Jan 01 00:00:00 1970 +0000
+  |  summary:     foobar
+  |
+  | o  changeset:   3:1dab759070cf
+  | |  user:        test
+  | |  date:        Thu Jan 01 00:00:00 1970 +0000
+  | |  summary:     bar2
+  | |
+  | o  changeset:   2:9d6d6b5a8275
+  | |  user:        test
+  | |  date:        Thu Jan 01 00:00:00 1970 +0000
+  | |  summary:     bar
+  | |
+  | o  changeset:   1:46ae92138f3c
+  |/   user:        test
+  |    date:        Thu Jan 01 00:00:00 1970 +0000
+  |    summary:     foo2
+  |
+  o  changeset:   0:493149fa1541
+     user:        test
+     date:        Thu Jan 01 00:00:00 1970 +0000
+     summary:     foo
+  
+  $ hg transplant 1:3
+  applying 46ae92138f3c
+  file added already exists
+  1 out of 1 hunks FAILED -- saving rejects to file added.rej
+  patching file foo
+  Hunk #1 FAILED at 0
+  1 out of 1 hunks FAILED -- saving rejects to file foo.rej
+  patch failed to apply
+  abort: fix up the working directory and run hg transplant --continue
+  [255]
+
 transplant -c shouldn't use an old changeset
 
   $ hg up -C
@@ -436,6 +514,9 @@ 
   abort: no transplant to continue (continueflag !)
   abort: no operation in progress (no-continueflag !)
   [255]
+  $ hg transplant --abort
+  abort: no transplant to abort
+  [255]
   $ hg transplant 1
   applying 46ae92138f3c
   patching file foo
@@ -493,6 +574,7 @@ 
   [255]
   $ hg status -v
   A bar
+  ? added.rej
   ? baz.rej
   ? foo.rej
   # The repository is in an unfinished *transplant* state.
@@ -505,7 +587,6 @@ 
   9d6d6b5a8275 transplanted as d80c49962290
   applying 1dab759070cf
   1dab759070cf transplanted to aa0ffe6bd5ae
-
   $ cd ..
 
 Issue1111: Test transplant --merge
diff --git a/hgext/transplant.py b/hgext/transplant.py
--- a/hgext/transplant.py
+++ b/hgext/transplant.py
@@ -119,6 +119,7 @@ 
 class transplanter(object):
     def __init__(self, ui, repo, opts):
         self.ui = ui
+        self.repo = repo
         self.path = repo.vfs.join('transplant')
         self.opener = vfsmod.vfs(self.path)
         self.transplants = transplants(self.path, 'transplants',
@@ -412,6 +413,23 @@ 
             # this is kept only to reduce changes in a patch.
             pass
 
+    def clear(self):
+        """clear the state file if it exists"""
+        util.unlinkpath(self.repo.vfs.join('transplant/journal'),
+                         ignoremissing=True)
+
+    def abort(self, ui ,repo):
+        """logic to abort an interrupted transplant"""
+        node, user, date, message, parents = self.readlog()
+        if not user or not date or not message or not parents[0]:
+            raise error.Abort(_('transplant log file is corrupt'))
+        startctx = repo['.']
+        hg.updaterepo(repo, startctx.node(), overwrite=True)
+        ui.status(_("transplant aborted\n"))
+        ui.status(_("working directory is now at %s\n") % startctx.hex()[:12])
+        self.clear()
+        return 0
+
     def readseries(self):
         nodes = []
         merges = []
@@ -559,6 +577,7 @@ 
      _('parent to choose when transplanting merge'), _('REV')),
     ('e', 'edit', False, _('invoke editor on commit messages')),
     ('', 'log', None, _('append transplant info to log message')),
+    ('', 'abort', False, _('abort interrupted transplant')),
     ('c', 'continue', None, _('continue last transplant session '
                               'after fixing conflicts')),
     ('', 'filter', '',
@@ -646,6 +665,11 @@ 
                 raise error.Abort(_('--continue is incompatible with '
                                    '--branch, --all and --merge'))
             return
+        if opts.get('abort'):
+            if opts.get('branch') or opts.get('all') or opts.get('merge'):
+                raise error.Abort(_('--abort is incompatible with '
+                                   '--branch, --all and --merge'))
+            return
         if not (opts.get('source') or revs or
                 opts.get('merge') or opts.get('branch')):
             raise error.Abort(_('no source URL, branch revision, or revision '
@@ -676,6 +700,11 @@ 
         if not tp.canresume():
             raise error.Abort(_('no transplant to continue'))
     else:
+        if opts.get('abort'):
+            if not tp.canresume():
+                raise error.Abort(_('no transplant to abort'))
+            tp.abort(ui, repo)
+            return
         cmdutil.checkunfinished(repo)
         cmdutil.bailifchanged(repo)