comparison mercurial/logcmdutil.py @ 51140: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 204af2aa4931
children 9d3721552b6c
comparison
equal deleted inserted replaced
51139:204af2aa4931 51140:d6e5bec550f1
9 import itertools 9 import itertools
10 import os 10 import os
11 import posixpath 11 import posixpath
12 12
13 from .i18n import _ 13 from .i18n import _
14 from .node import nullrev, wdirrev 14 from .node import wdirrev
15 15
16 from .thirdparty import attr 16 from .thirdparty import attr
17 17
18 from . import ( 18 from . import (
19 dagop, 19 dagop,
20 diffutil,
20 error, 21 error,
21 formatter, 22 formatter,
22 graphmod, 23 graphmod,
23 match as matchmod, 24 match as matchmod,
24 mdiff, 25 mdiff,
25 merge,
26 patch, 26 patch,
27 pathutil, 27 pathutil,
28 pycompat, 28 pycompat,
29 revset, 29 revset,
30 revsetlang, 30 revsetlang,
65 if limit <= 0: 65 if limit <= 0:
66 raise error.InputError(_(b'limit must be positive')) 66 raise error.InputError(_(b'limit must be positive'))
67 else: 67 else:
68 limit = None 68 limit = None
69 return limit 69 return limit
70
71
72 def diff_parent(ctx):
73 """get the context object to use as parent when diffing
74
75
76 If diff.merge is enabled, an overlayworkingctx of the auto-merged parents will be returned.
77 """
78 repo = ctx.repo()
79 if repo.ui.configbool(b"diff", b"merge") and ctx.p2().rev() != nullrev:
80 # avoid cycle context -> subrepo -> cmdutil -> logcmdutil
81 from . import context
82
83 wctx = context.overlayworkingctx(repo)
84 wctx.setbase(ctx.p1())
85 with repo.ui.configoverride(
86 {
87 (
88 b"ui",
89 b"forcemerge",
90 ): b"internal:merge3-lie-about-conflicts",
91 },
92 b"merge-diff",
93 ):
94 with repo.ui.silent():
95 merge.merge(ctx.p2(), wc=wctx)
96 return wctx
97 else:
98 return ctx.p1()
99 70
100 71
101 def get_diff_chunks( 72 def get_diff_chunks(
102 ui, 73 ui,
103 repo, 74 repo,
271 def showdiff(self, ui, ctx, diffopts, graphwidth=0, stat=False): 242 def showdiff(self, ui, ctx, diffopts, graphwidth=0, stat=False):
272 diffordiffstat( 243 diffordiffstat(
273 ui, 244 ui,
274 ctx.repo(), 245 ctx.repo(),
275 diffopts, 246 diffopts,
276 diff_parent(ctx), 247 diffutil.diff_parent(ctx),
277 ctx, 248 ctx,
278 match=self._makefilematcher(ctx), 249 match=self._makefilematcher(ctx),
279 stat=stat, 250 stat=stat,
280 graphwidth=graphwidth, 251 graphwidth=graphwidth,
281 hunksfilterfn=self._makehunksfilter(ctx), 252 hunksfilterfn=self._makehunksfilter(ctx),
284 def getdiffstats(self, ui, ctx, diffopts, stat=False): 255 def getdiffstats(self, ui, ctx, diffopts, stat=False):
285 chunks = get_diff_chunks( 256 chunks = get_diff_chunks(
286 ui, 257 ui,
287 ctx.repo(), 258 ctx.repo(),
288 diffopts, 259 diffopts,
289 diff_parent(ctx), 260 diffutil.diff_parent(ctx),
290 ctx, 261 ctx,
291 match=self._makefilematcher(ctx), 262 match=self._makefilematcher(ctx),
292 stat=stat, 263 stat=stat,
293 hunksfilterfn=self._makehunksfilter(ctx), 264 hunksfilterfn=self._makehunksfilter(ctx),
294 ) 265 )