Patchwork D7999: merge: make hg.merge() take a context instead of a node

login
register
mail settings
Submitter phabricator
Date Jan. 25, 2020, 12:19 a.m.
Message ID <differential-rev-PHID-DREV-lv25m7d5le5udepuuyga-req@mercurial-scm.org>
Download mbox | patch
Permalink /patch/44648/
State Superseded
Headers show

Comments

phabricator - Jan. 25, 2020, 12:19 a.m.
martinvonz created this revision.
Herald added a subscriber: mercurial-devel.
Herald added a reviewer: hg-reviewers.

REVISION SUMMARY
  Many callers already have a repo, so we might as well pass
  that. `merge.update()` will look up the context object later. This
  patch is part of making it so we pass around the context object all
  the way down instead.
  
  I also removed the `repo` argument since it can be retrieved from the
  context.

REPOSITORY
  rHG Mercurial

BRANCH
  default

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

AFFECTED FILES
  hgext/fetch.py
  hgext/mq.py
  mercurial/commands.py
  mercurial/hg.py
  mercurial/subrepo.py
  relnotes/next

CHANGE DETAILS




To: martinvonz, #hg-reviewers
Cc: mercurial-devel
phabricator - Jan. 29, 2020, 11:09 p.m.
This revision now requires changes to proceed.
durin42 added a comment.
durin42 requested changes to this revision.


  Breaks `test-merge2.t` but otherwise seems like a good series.

REPOSITORY
  rHG Mercurial

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

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

To: martinvonz, #hg-reviewers, durin42
Cc: durin42, mercurial-devel
phabricator - Jan. 29, 2020, 11:17 p.m.
martinvonz added a comment.


  In D7999#118496 <https://phab.mercurial-scm.org/D7999#118496>, @durin42 wrote:
  
  > Breaks `test-merge2.t` but otherwise seems like a good series.
  
  Doesn't break it for me (I think I just re-ran that test on all the commits in this series). I guess it's a (semantic) conflict with some other of my patches that have recently been queue. I'll rebase and try again once you're done with your current batch of queuing.

REPOSITORY
  rHG Mercurial

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

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

To: martinvonz, #hg-reviewers, durin42
Cc: durin42, mercurial-devel
phabricator - Jan. 29, 2020, 11:39 p.m.
martinvonz added a comment.


  In D7999#118500 <https://phab.mercurial-scm.org/D7999#118500>, @martinvonz wrote:
  
  > In D7999#118496 <https://phab.mercurial-scm.org/D7999#118496>, @durin42 wrote:
  >
  >> Breaks `test-merge2.t` but otherwise seems like a good series.
  >
  > Doesn't break it for me (I think I just re-ran that test on all the commits in this series). I guess it's a (semantic) conflict with some other of my patches that have recently been queue. I'll rebase and try again once you're done with your current batch of queuing.
  
  Rebase done and it still passes for me. How does it fail for you?  I wonder if it's flaky. I've seen one of those tests be flaky before.

REPOSITORY
  rHG Mercurial

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

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

To: martinvonz, #hg-reviewers, durin42
Cc: durin42, mercurial-devel
phabricator - March 3, 2020, 10:09 p.m.
martinvonz added a comment.


  I've rebased the remaining two patches in this series. I'm still unable to get the test to fail.

REPOSITORY
  rHG Mercurial

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

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

To: martinvonz, #hg-reviewers, durin42
Cc: durin42, mercurial-devel

Patch

diff --git a/relnotes/next b/relnotes/next
--- a/relnotes/next
+++ b/relnotes/next
@@ -17,3 +17,6 @@ 
 
  * `hg.merge()` has lost its `abort` argument. Please call
    `hg.abortmerge()` directly instead.
+
+ * `hg.merge()` now takes a `ctx` instead of the previous `repo` and
+   `node` arguments.
diff --git a/mercurial/subrepo.py b/mercurial/subrepo.py
--- a/mercurial/subrepo.py
+++ b/mercurial/subrepo.py
@@ -806,7 +806,7 @@ 
                 self.ui.debug(
                     b'merging subrepository "%s"\n' % subrelpath(self)
                 )
-                hg.merge(self._repo, state[1], remind=False)
+                hg.merge(dst, remind=False)
 
         wctx = self._repo[None]
         if self.dirty():
diff --git a/mercurial/hg.py b/mercurial/hg.py
--- a/mercurial/hg.py
+++ b/mercurial/hg.py
@@ -1138,13 +1138,14 @@ 
 
 
 def merge(
-    repo, node, force=None, remind=True, mergeforce=False, labels=None,
+    ctx, force=None, remind=True, mergeforce=False, labels=None,
 ):
     """Branch merge with node, resolving changes. Return true if any
     unresolved conflicts."""
+    repo = ctx.repo()
     stats = mergemod.update(
         repo,
-        node,
+        ctx.node(),
         branchmerge=True,
         force=force,
         mergeforce=mergeforce,
diff --git a/mercurial/commands.py b/mercurial/commands.py
--- a/mercurial/commands.py
+++ b/mercurial/commands.py
@@ -876,7 +876,7 @@ 
         )
         overrides = {(b'ui', b'forcemerge'): opts.get(b'tool', b'')}
         with ui.configoverride(overrides, b'backout'):
-            return hg.merge(repo, hex(repo.changelog.tip()))
+            return hg.merge(repo[b'tip'])
     return 0
 
 
@@ -4865,7 +4865,7 @@ 
         node = opts.get(b'rev')
 
     if node:
-        node = scmutil.revsingle(repo, node).node()
+        ctx = scmutil.revsingle(repo, node)
     else:
         if ui.configbool(b'commands', b'merge.require-rev'):
             raise error.Abort(
@@ -4874,12 +4874,12 @@ 
                     b'with'
                 )
             )
-        node = repo[destutil.destmerge(repo)].node()
+        ctx = repo[destutil.destmerge(repo)]
 
     if opts.get(b'preview'):
         # find nodes that are ancestors of p2 but not of p1
         p1 = repo[b'.'].node()
-        p2 = node
+        p2 = ctx.node()
         nodes = repo.changelog.findmissing(common=[p1], heads=[p2])
 
         displayer = logcmdutil.changesetdisplayer(ui, repo, opts)
@@ -4893,9 +4893,7 @@ 
     with ui.configoverride(overrides, b'merge'):
         force = opts.get(b'force')
         labels = [b'working copy', b'merge rev']
-        return hg.merge(
-            repo, node, force=force, mergeforce=force, labels=labels
-        )
+        return hg.merge(ctx, force=force, mergeforce=force, labels=labels)
 
 
 statemod.addunfinished(
diff --git a/hgext/mq.py b/hgext/mq.py
--- a/hgext/mq.py
+++ b/hgext/mq.py
@@ -858,7 +858,7 @@ 
         strip(self.ui, repo, [n], update=False, backup=False)
 
         ctx = repo[rev]
-        ret = hg.merge(repo, rev)
+        ret = hg.merge(ctx)
         if ret:
             raise error.Abort(_(b"update returned %d") % ret)
         n = newcommit(repo, None, ctx.description(), ctx.user(), force=True)
diff --git a/hgext/fetch.py b/hgext/fetch.py
--- a/hgext/fetch.py
+++ b/hgext/fetch.py
@@ -171,11 +171,11 @@ 
                     % (repo.changelog.rev(firstparent), short(firstparent))
                 )
             hg.clean(repo, firstparent)
+            p2ctx = repo[secondparent]
             ui.status(
-                _(b'merging with %d:%s\n')
-                % (repo.changelog.rev(secondparent), short(secondparent))
+                _(b'merging with %d:%s\n') % (p2ctx.rev(), short(secondparent))
             )
-            err = hg.merge(repo, secondparent, remind=False)
+            err = hg.merge(p2ctx, remind=False)
 
         if not err:
             # we don't translate commit messages