Mercurial > hg-stable
diff mercurial/logcmdutil.py @ 41657:d4c9eebdd72d
patch: replace "prefix" and "relroot" arguments by "pathfn" (API)
The two arguments serve a very similar purpose: "relroot" is stripped
from the front of the path, and then "prefix" (a subrepo path) is
added (also to the front). Passing in a function that does that is
more generic and will make it easier to respect ui.relative-paths in
later patches (don't worry, I'm not going to respect that option for
regular patches, only for --stat). I'm deliberately not calling it
"uipathfn", because it's generally for producing valid diffs
(including when prefix is non-empty), so things like using backslash
on Windows is not an option.
Differential Revision: https://phab.mercurial-scm.org/D5894
author | Martin von Zweigbergk <martinvonz@google.com> |
---|---|
date | Wed, 06 Feb 2019 23:12:56 -0800 |
parents | 3d094bfaf885 |
children | ec37db02fc72 |
line wrap: on
line diff
--- a/mercurial/logcmdutil.py Sat Feb 09 01:24:32 2019 +0100 +++ b/mercurial/logcmdutil.py Wed Feb 06 23:12:56 2019 -0800 @@ -9,6 +9,7 @@ import itertools import os +import posixpath from .i18n import _ from .node import ( @@ -65,6 +66,8 @@ else: relroot = '' copysourcematch = None + def pathfn(f): + return posixpath.join(prefix, f) if relroot != '': # XXX relative roots currently don't work if the root is within a # subrepo @@ -79,14 +82,22 @@ match = matchmod.intersectmatchers(match, relrootmatch) copysourcematch = relrootmatch + checkroot = (repo.ui.configbool('devel', 'all-warnings') or + repo.ui.configbool('devel', 'check-relroot')) + def pathfn(f): + if checkroot and not f.startswith(relroot): + raise AssertionError( + "file %s doesn't start with relroot %s" % (f, relroot)) + return posixpath.join(prefix, f[len(relroot):]) + if stat: diffopts = diffopts.copy(context=0, noprefix=False) width = 80 if not ui.plain(): width = ui.termwidth() - graphwidth - chunks = ctx2.diff(ctx1, match, changes, opts=diffopts, prefix=prefix, - relroot=relroot, copysourcematch=copysourcematch, + chunks = ctx2.diff(ctx1, match, changes, opts=diffopts, pathfn=pathfn, + copysourcematch=copysourcematch, hunksfilterfn=hunksfilterfn) if fp is not None or ui.canwritewithoutlabels():