Mercurial > hg
changeset 23480:88d2d77eb981
match: introduce uipath() to properly style a file path
Several methods print files relative to the repo root, unless files are named on
the command line, in which case they are printed relative to cwd. Since the
check relies on the 'pats' parameter, which needs to be replaced by a matcher
when adding subrepo support, this logic gets folded into the matcher to tidy up
the callers.
Prior to 3778884197f0, this style decision was based off of whether or not the
'pats' list was empty. That change altered the check to test match.anypats()
instead, in order to make paths printed consistent when -I/-X is specified.
That however, changed the style when a file is given to the command. So now we
test the pattern list to get the old behavior for files, as well as test -I/-X
to get the consistency for patterns.
author | Matt Harbison <matt_harbison@yahoo.com> |
---|---|
date | Thu, 04 Dec 2014 23:04:55 -0500 |
parents | 406dfc63a1ad |
children | 94091ab9d112 |
files | mercurial/match.py |
diffstat | 1 files changed, 8 insertions(+), 0 deletions(-) [+] |
line wrap: on
line diff
--- a/mercurial/match.py Fri Dec 05 12:10:56 2014 -0600 +++ b/mercurial/match.py Thu Dec 04 23:04:55 2014 -0500 @@ -65,6 +65,7 @@ self._anypats = bool(include or exclude) self._ctx = ctx self._always = False + self._pathrestricted = bool(include or exclude or patterns) matchfns = [] if include: @@ -128,6 +129,12 @@ '''Convert repo path back to path that is relative to cwd of matcher.''' return util.pathto(self._root, self._cwd, f) + def uipath(self, f): + '''Convert repo path to a display path. If patterns or -I/-X were used + to create this matcher, the display path will be relative to cwd. + Otherwise it is relative to the root of the repo.''' + return (self._pathrestricted and self.rel(f)) or f + def files(self): '''Explicitly listed files or patterns or roots: if no patterns or .always(): empty list, @@ -191,6 +198,7 @@ self._path = path self._matcher = matcher self._always = matcher._always + self._pathrestricted = matcher._pathrestricted self._files = [f[len(path) + 1:] for f in matcher._files if f.startswith(path + "/")]