Patchwork D8127: graft: always allow hg graft --base . (issue6248)

login
register
mail settings
Submitter phabricator
Date Feb. 18, 2020, 2:30 a.m.
Message ID <differential-rev-PHID-DREV-6leswftg64vqvvbdw7xa-req@mercurial-scm.org>
Download mbox | patch
Permalink /patch/45266/
State Superseded
Headers show

Comments

phabricator - Feb. 18, 2020, 2:30 a.m.
valentin.gatienbaron created this revision.
Herald added a subscriber: mercurial-devel.
Herald added a reviewer: hg-reviewers.

REVISION SUMMARY
  `hg graft --base . -r abc` is rejected before this change with a
  "nothing to merge" error, if `abc` does not descend from `.`.
  
  This looks like an artifact of the implementation rather than intended
  behavior. It makes perfect sense to apply the diff between `.` and
  `abc` to the working copy (i.e. degenerate into `hg revert`),
  regardless of what `abc` is.

REPOSITORY
  rHG Mercurial

BRANCH
  default

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

AFFECTED FILES
  mercurial/merge.py
  tests/test-graft.t

CHANGE DETAILS




To: valentin.gatienbaron, #hg-reviewers
Cc: mercurial-devel
phabricator - Feb. 24, 2020, 3:36 p.m.
marmoute added a comment.
marmoute accepted this revision.


  The usecase looks correct, the test change seems correct and the test is good. I can't think of any issue here.

REPOSITORY
  rHG Mercurial

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

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

To: valentin.gatienbaron, #hg-reviewers, marmoute
Cc: marmoute, mercurial-devel

Patch

diff --git a/tests/test-graft.t b/tests/test-graft.t
--- a/tests/test-graft.t
+++ b/tests/test-graft.t
@@ -813,13 +813,14 @@ 
   note: graft of 19:9627f653b421 created no changes to commit
   grafting 0:68795b066622 "0"
 
-graft --force after backout
+graft --force after backout. Do the backout with graft too, to make
+sure we support issue6248.
 
   $ echo abc > a
   $ hg ci -m 24
-  $ hg backout 24
-  reverting a
-  changeset 25:71c4e63d4f98 backs out changeset 24:2e7ea477be26
+  $ hg graft --base . -r ".^" --no-commit
+  grafting 23:b1cac6de36a9 "0"
+  $ hg commit -m 'Backed out changeset 2e7ea477be26'
   $ hg graft 24
   skipping ancestor revision 24:2e7ea477be26
   [255]
diff --git a/mercurial/merge.py b/mercurial/merge.py
--- a/mercurial/merge.py
+++ b/mercurial/merge.py
@@ -2654,10 +2654,15 @@ 
     # to copy commits), and 2) informs update that the incoming changes are
     # newer than the destination so it doesn't prompt about "remote changed foo
     # which local deleted".
+    # We also pass mergeancestor=True when base is the same revision as p1. 2)
+    # doesn't matter as there can't possibly be conflicts, but 1) is necessary.
     wctx = wctx or repo[None]
     pctx = wctx.p1()
     base = base or ctx.p1()
-    mergeancestor = repo.changelog.isancestor(pctx.node(), ctx.node())
+    mergeancestor = (
+        repo.changelog.isancestor(pctx.node(), ctx.node())
+        or pctx.rev() == base.rev()
+    )
 
     stats = update(
         repo,