diff mercurial/diffutil.py @ 51143:d6e5bec550f1

util: move diff_parent from logcmdutil to diffutil This function will be used outside of the log command (in templatekw, used by hgweb, for which logcmdutil is not available). Let's move this function together with the rest of the diff-related utils instead.
author pacien <pacien.trangirard@pacien.net>
date Wed, 15 Nov 2023 02:39:53 +0100
parents a6b8b1ab9116
children f4733654f144
line wrap: on
line diff
--- a/mercurial/diffutil.py	Thu Sep 07 08:39:21 2023 +0200
+++ b/mercurial/diffutil.py	Wed Nov 15 02:39:53 2023 +0100
@@ -16,6 +16,7 @@
 )
 
 from .i18n import _
+from .node import nullrev
 
 from . import (
     mdiff,
@@ -155,3 +156,35 @@
         )
 
     return mdiff.diffopts(**pycompat.strkwargs(buildopts))
+
+
+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().rev() != nullrev:
+        # avoid circular import
+        from . import (
+            context,
+            merge,
+        )
+
+        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",
+        ):
+            with repo.ui.silent():
+                merge.merge(ctx.p2(), wc=wctx)
+        return wctx
+    else:
+        return ctx.p1()