mercurial/logcmdutil.py
changeset 46497 4a012e531066
parent 46042 1bf2b44c4007
child 46498 3caa3698335e
--- a/mercurial/logcmdutil.py	Thu Feb 04 13:05:51 2021 -0800
+++ b/mercurial/logcmdutil.py	Thu Feb 04 13:21:01 2021 -0800
@@ -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,