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

login
register
mail settings
Submitter phabricator
Date March 4, 2020, 7:52 p.m.
Message ID <90f8f89fd571ac8bbda45ae2cabde66b@localhost.localdomain>
Download mbox | patch
Permalink /patch/45483/
State Not Applicable
Headers show

Comments

phabricator - March 4, 2020, 7:52 p.m.
Closed by commit rHG2f290136b7d6: merge: make hg.merge() take a context instead of a node (authored by martinvonz).
This revision was automatically updated to reflect the committed changes.
This revision was not accepted when it landed; it landed in state "Needs Review".

REPOSITORY
  rHG Mercurial

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

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, durin42
Cc: durin42, mercurial-devel

Patch

diff --git a/relnotes/next b/relnotes/next
--- a/relnotes/next
+++ b/relnotes/next
@@ -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.
 
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
@@ -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(
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
 
 
@@ -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(
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