[Updated] [+-- ] D9957: diff: extract function for getting possibly re-merged parent to diff against

martinvonz (Martin von Zweigbergk) phabricator at mercurial-scm.org
Fri Feb 5 08:19:20 UTC 2021


martinvonz updated this revision to Diff 25487.

REPOSITORY
  rHG Mercurial

CHANGES SINCE LAST UPDATE
  https://phab.mercurial-scm.org/D9957?vs=25485&id=25487

BRANCH
  default

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

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

AFFECTED FILES
  mercurial/commands.py
  mercurial/logcmdutil.py

CHANGE DETAILS

diff --git a/mercurial/logcmdutil.py b/mercurial/logcmdutil.py
--- a/mercurial/logcmdutil.py
+++ b/mercurial/logcmdutil.py
@@ -27,6 +27,7 @@
     graphmod,
     match as matchmod,
     mdiff,
+    merge,
     patch,
     pathutil,
     pycompat,
@@ -73,6 +74,36 @@
     return limit
 
 
+def diff_parent(ctx):
+    """get the context object to use as parent when diffing
+
+
+    If diff.merge is enabled, an overlayworkingctx of the auto-merged parents will be returned.
+    """
+    repo = ctx.repo()
+    if repo.ui.configbool(b"diff", b"merge") and ctx.p2().node() != nullid:
+        # avoid cycle context -> subrepo -> cmdutil -> logcmdutil
+        from . import context
+
+        wctx = context.overlayworkingctx(repo)
+        wctx.setbase(ctx.p1())
+        with repo.ui.configoverride(
+            {
+                (
+                    b"ui",
+                    b"forcemerge",
+                ): b"internal:merge3-lie-about-conflicts",
+            },
+            b"merge-diff",
+        ):
+            repo.ui.pushbuffer()
+            merge.merge(ctx.p2(), wc=wctx)
+            repo.ui.popbuffer()
+        return wctx
+    else:
+        return ctx.p1()
+
+
 def diffordiffstat(
     ui,
     repo,
diff --git a/mercurial/commands.py b/mercurial/commands.py
--- a/mercurial/commands.py
+++ b/mercurial/commands.py
@@ -29,7 +29,6 @@
     bundlecaches,
     changegroup,
     cmdutil,
-    context as contextmod,
     copies,
     debugcommands as debugcommandsmod,
     destutil,
@@ -2545,33 +2544,13 @@
     to_rev = opts.get(b'to')
     stat = opts.get(b'stat')
     reverse = opts.get(b'reverse')
-    diffmerge = ui.configbool(b'diff', b'merge')
 
     cmdutil.check_incompatible_arguments(opts, b'from', [b'rev', b'change'])
     cmdutil.check_incompatible_arguments(opts, b'to', [b'rev', b'change'])
     if change:
         repo = scmutil.unhidehashlikerevs(repo, [change], b'nowarn')
         ctx2 = scmutil.revsingle(repo, change, None)
-        if diffmerge and ctx2.p2().node() != nullid:
-            pctx1 = ctx2.p1()
-            pctx2 = ctx2.p2()
-            wctx = contextmod.overlayworkingctx(repo)
-            wctx.setbase(pctx1)
-            with ui.configoverride(
-                {
-                    (
-                        b'ui',
-                        b'forcemerge',
-                    ): b'internal:merge3-lie-about-conflicts',
-                },
-                b'diff --merge',
-            ):
-                repo.ui.pushbuffer()
-                mergemod.merge(pctx2, wc=wctx)
-                repo.ui.popbuffer()
-            ctx1 = wctx
-        else:
-            ctx1 = ctx2.p1()
+        ctx1 = logcmdutil.diff_parent(ctx2)
     elif from_rev or to_rev:
         repo = scmutil.unhidehashlikerevs(
             repo, [from_rev] + [to_rev], b'nowarn'



To: martinvonz, #hg-reviewers
Cc: mercurial-patches
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.mercurial-scm.org/pipermail/mercurial-patches/attachments/20210205/77873bb6/attachment-0002.html>


More information about the Mercurial-patches mailing list