comparison mercurial/diffutil.py @ 51185: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
comparison
equal deleted inserted replaced
51184:204af2aa4931 51185:d6e5bec550f1
14 Dict, 14 Dict,
15 Optional, 15 Optional,
16 ) 16 )
17 17
18 from .i18n import _ 18 from .i18n import _
19 from .node import nullrev
19 20
20 from . import ( 21 from . import (
21 mdiff, 22 mdiff,
22 pycompat, 23 pycompat,
23 ) 24 )
153 buildopts[b'worddiff'] = get( 154 buildopts[b'worddiff'] = get(
154 b'word_diff', b'word-diff', forceplain=False 155 b'word_diff', b'word-diff', forceplain=False
155 ) 156 )
156 157
157 return mdiff.diffopts(**pycompat.strkwargs(buildopts)) 158 return mdiff.diffopts(**pycompat.strkwargs(buildopts))
159
160
161 def diff_parent(ctx):
162 """get the context object to use as parent when diffing
163
164
165 If diff.merge is enabled, an overlayworkingctx of the auto-merged parents will be returned.
166 """
167 repo = ctx.repo()
168 if repo.ui.configbool(b"diff", b"merge") and ctx.p2().rev() != nullrev:
169 # avoid circular import
170 from . import (
171 context,
172 merge,
173 )
174
175 wctx = context.overlayworkingctx(repo)
176 wctx.setbase(ctx.p1())
177 with repo.ui.configoverride(
178 {
179 (
180 b"ui",
181 b"forcemerge",
182 ): b"internal:merge3-lie-about-conflicts",
183 },
184 b"merge-diff",
185 ):
186 with repo.ui.silent():
187 merge.merge(ctx.p2(), wc=wctx)
188 return wctx
189 else:
190 return ctx.p1()