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

login
register
mail settings
Submitter phabricator
Date Jan. 25, 2020, 6:08 a.m.
Message ID <1f715a58cabed8a09fdb6670b31f9acd@localhost.localdomain>
Download mbox | patch
Permalink /patch/44658/
State Not Applicable
Headers show

Comments

phabricator - Jan. 25, 2020, 6:08 a.m.
martinvonz updated this revision to Diff 19605.

REPOSITORY
  rHG Mercurial

CHANGES SINCE LAST UPDATE
  https://phab.mercurial-scm.org/D7999?vs=19590&id=19605

BRANCH
  default

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

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

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,7 +4874,7 @@ 
                     b'with'
                 )
             )
-        node = repo[destutil.destmerge(repo)].node()
+        ctx = repo[destutil.destmerge(repo)]
 
     if node is None:
         raise error.Abort(_(b'merging with the working copy has no effect'))
@@ -4882,7 +4882,7 @@ 
     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)
@@ -4896,9 +4896,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