diff --git a/mercurial/commands.py b/mercurial/commands.py --- a/mercurial/commands.py +++ b/mercurial/commands.py @@ -29,6 +29,7 @@ from . import ( copies, debugcommands as debugcommandsmod, destutil, + diffutil, discovery, encoding, error, @@ -2655,7 +2656,7 @@ def diff(ui, repo, *pats, **opts): if change: repo = scmutil.unhidehashlikerevs(repo, [change], b'nowarn') ctx2 = logcmdutil.revsingle(repo, change, None) - ctx1 = logcmdutil.diff_parent(ctx2) + ctx1 = diffutil.diff_parent(ctx2) elif from_rev or to_rev: repo = scmutil.unhidehashlikerevs( repo, [from_rev] + [to_rev], b'nowarn' diff --git a/mercurial/diffutil.py b/mercurial/diffutil.py --- a/mercurial/diffutil.py +++ b/mercurial/diffutil.py @@ -16,6 +16,7 @@ from typing import ( ) from .i18n import _ +from .node import nullrev from . import ( mdiff, @@ -155,3 +156,35 @@ def difffeatureopts( ) 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() diff --git a/mercurial/logcmdutil.py b/mercurial/logcmdutil.py --- a/mercurial/logcmdutil.py +++ b/mercurial/logcmdutil.py @@ -11,18 +11,18 @@ import os import posixpath from .i18n import _ -from .node import nullrev, wdirrev +from .node import wdirrev from .thirdparty import attr from . import ( dagop, + diffutil, error, formatter, graphmod, match as matchmod, mdiff, - merge, patch, pathutil, pycompat, @@ -69,35 +69,6 @@ def getlimit(opts): 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().rev() != nullrev: - # 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", - ): - with repo.ui.silent(): - merge.merge(ctx.p2(), wc=wctx) - return wctx - else: - return ctx.p1() - - def get_diff_chunks( ui, repo, @@ -273,7 +244,7 @@ class changesetdiffer: ui, ctx.repo(), diffopts, - diff_parent(ctx), + diffutil.diff_parent(ctx), ctx, match=self._makefilematcher(ctx), stat=stat, @@ -286,7 +257,7 @@ class changesetdiffer: ui, ctx.repo(), diffopts, - diff_parent(ctx), + diffutil.diff_parent(ctx), ctx, match=self._makefilematcher(ctx), stat=stat,