merge: make hg.merge() take a context instead of a node
authorMartin von Zweigbergk <martinvonz@google.com>
Fri, 24 Jan 2020 15:28:37 -0800
changeset 44434 2f290136b7d6
parent 44433 f82d2d4e71db
child 44435 4152183acedd
merge: make hg.merge() take a context instead of a node 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. Differential Revision: https://phab.mercurial-scm.org/D7999
hgext/fetch.py
hgext/mq.py
mercurial/commands.py
mercurial/hg.py
mercurial/subrepo.py
relnotes/next
--- a/hgext/fetch.py	Fri Jan 17 21:22:23 2020 +0300
+++ b/hgext/fetch.py	Fri Jan 24 15:28:37 2020 -0800
@@ -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
--- a/hgext/mq.py	Fri Jan 17 21:22:23 2020 +0300
+++ b/hgext/mq.py	Fri Jan 24 15:28:37 2020 -0800
@@ -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)
--- a/mercurial/commands.py	Fri Jan 17 21:22:23 2020 +0300
+++ b/mercurial/commands.py	Fri Jan 24 15:28:37 2020 -0800
@@ -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
 
 
@@ -4878,7 +4878,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(
@@ -4887,15 +4887,15 @@
                     b'with'
                 )
             )
-        node = repo[destutil.destmerge(repo)].node()
-
-    if node is None:
+        ctx = repo[destutil.destmerge(repo)]
+
+    if ctx.node() is None:
         raise error.Abort(_(b'merging with the working copy has no effect'))
 
     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)
@@ -4909,7 +4909,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, labels=labels)
+        return hg.merge(ctx, force=force, labels=labels)
 
 
 statemod.addunfinished(
--- a/mercurial/hg.py	Fri Jan 17 21:22:23 2020 +0300
+++ b/mercurial/hg.py	Fri Jan 24 15:28:37 2020 -0800
@@ -1137,11 +1137,12 @@
 
 
 def merge(
-    repo, node, force=False, remind=True, labels=None,
+    ctx, force=False, remind=True, labels=None,
 ):
     """Branch merge with node, resolving changes. Return true if any
     unresolved conflicts."""
-    stats = mergemod.merge(repo[node], force=force, labels=labels)
+    repo = ctx.repo()
+    stats = mergemod.merge(ctx, force=force, labels=labels)
     _showstats(repo, stats)
     if stats.unresolvedcount:
         repo.ui.status(
--- a/mercurial/subrepo.py	Fri Jan 17 21:22:23 2020 +0300
+++ b/mercurial/subrepo.py	Fri Jan 24 15:28:37 2020 -0800
@@ -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():
--- a/relnotes/next	Fri Jan 17 21:22:23 2020 +0300
+++ b/relnotes/next	Fri Jan 24 15:28:37 2020 -0800
@@ -67,6 +67,9 @@
  * The deprecated `ui.progress()` has now been deleted. Please use
    `ui.makeprogress()` instead.
 
+ * `hg.merge()` now takes a `ctx` instead of the previous `repo` and
+   `node` arguments.
+
  * `hg.merge()` has lost its `abort` argument. Please call
    `hg.abortmerge()` directly instead.