Details
Details
- Reviewers
- None
- Group Reviewers
hg-reviewers - Commits
- rHGc4f023b656cf: match: delete unused rel() (API)
Diff Detail
Diff Detail
- Repository
- rHG Mercurial
- Lint
Lint Skipped - Unit
Unit Tests Skipped
( )
hg-reviewers |
Lint Skipped |
Unit Tests Skipped |
Path | Packages | |||
---|---|---|---|---|
M | mercurial/match.py (10 lines) |
Commit | Parents | Author | Summary | Date |
---|---|---|---|---|
Martin von Zweigbergk | Feb 9 2019, 7:46 PM |
Status | Author | Revision | |
---|---|---|---|
Closed | martinvonz | ||
Closed | martinvonz | ||
Closed | martinvonz | ||
Closed | martinvonz | ||
Closed | martinvonz | ||
Closed | martinvonz | ||
Closed | martinvonz | ||
Closed | martinvonz | ||
Closed | martinvonz | ||
Closed | martinvonz | ||
Closed | martinvonz | ||
Closed | martinvonz | ||
Closed | martinvonz | ||
Closed | martinvonz | ||
Closed | martinvonz | ||
Closed | martinvonz | ||
Closed | martinvonz | ||
Closed | martinvonz | ||
Closed | martinvonz | ||
Closed | martinvonz | ||
Closed | martinvonz | ||
Closed | martinvonz | ||
Closed | martinvonz | ||
Closed | martinvonz | ||
Closed | martinvonz | ||
Closed | martinvonz | ||
Closed | martinvonz | ||
Closed | martinvonz |
# If an explicitdir is set, it will be called when an explicitly listed | # If an explicitdir is set, it will be called when an explicitly listed | ||||
# directory is visited. | # directory is visited. | ||||
explicitdir = None | explicitdir = None | ||||
# If an traversedir is set, it will be called when a directory discovered | # If an traversedir is set, it will be called when a directory discovered | ||||
# by recursive traversal is visited. | # by recursive traversal is visited. | ||||
traversedir = None | traversedir = None | ||||
def rel(self, f): | |||||
'''Convert repo path back to path that is relative to cwd of matcher.''' | |||||
return util.pathto(self._root, self._cwd, f) | |||||
@propertycache | @propertycache | ||||
def _files(self): | def _files(self): | ||||
return [] | return [] | ||||
def files(self): | def files(self): | ||||
'''Explicitly listed files or patterns or roots: | '''Explicitly listed files or patterns or roots: | ||||
if no patterns or .always(): empty list, | if no patterns or .always(): empty list, | ||||
if exact: list exact files, | if exact: list exact files, | ||||
return m1 or m2 | return m1 or m2 | ||||
if m1.always(): | if m1.always(): | ||||
m = copy.copy(m2) | m = copy.copy(m2) | ||||
# TODO: Consider encapsulating these things in a class so there's only | # TODO: Consider encapsulating these things in a class so there's only | ||||
# one thing to copy from m1. | # one thing to copy from m1. | ||||
m.bad = m1.bad | m.bad = m1.bad | ||||
m.explicitdir = m1.explicitdir | m.explicitdir = m1.explicitdir | ||||
m.traversedir = m1.traversedir | m.traversedir = m1.traversedir | ||||
m.rel = m1.rel | |||||
return m | return m | ||||
if m2.always(): | if m2.always(): | ||||
m = copy.copy(m1) | m = copy.copy(m1) | ||||
return m | return m | ||||
return intersectionmatcher(m1, m2) | return intersectionmatcher(m1, m2) | ||||
class intersectionmatcher(basematcher): | class intersectionmatcher(basematcher): | ||||
def __init__(self, m1, m2): | def __init__(self, m1, m2): | ||||
>>> bool(m2.matchfn(b'a.txt')) | >>> bool(m2.matchfn(b'a.txt')) | ||||
False | False | ||||
>>> bool(m2.matchfn(b'b.txt')) | >>> bool(m2.matchfn(b'b.txt')) | ||||
True | True | ||||
>>> m2.files() | >>> m2.files() | ||||
['b.txt'] | ['b.txt'] | ||||
>>> m2.exact(b'b.txt') | >>> m2.exact(b'b.txt') | ||||
True | True | ||||
>>> util.pconvert(m2.rel(b'b.txt')) | |||||
'sub/b.txt' | |||||
>>> def bad(f, msg): | >>> def bad(f, msg): | ||||
... print(pycompat.sysstr(b"%s: %s" % (f, msg))) | ... print(pycompat.sysstr(b"%s: %s" % (f, msg))) | ||||
>>> m1.bad = bad | >>> m1.bad = bad | ||||
>>> m2.bad(b'x.txt', b'No such file') | >>> m2.bad(b'x.txt', b'No such file') | ||||
sub/x.txt: No such file | sub/x.txt: No such file | ||||
""" | """ | ||||
def __init__(self, path, matcher): | def __init__(self, path, matcher): | ||||
super(subdirmatcher, self).__init__(matcher._root, matcher._cwd) | super(subdirmatcher, self).__init__(matcher._root, matcher._cwd) | ||||
self._path = path | self._path = path | ||||
self._matcher = matcher | self._matcher = matcher | ||||
self._always = matcher.always() | self._always = matcher.always() | ||||
self._files = [f[len(path) + 1:] for f in matcher._files | self._files = [f[len(path) + 1:] for f in matcher._files | ||||
if f.startswith(path + "/")] | if f.startswith(path + "/")] | ||||
# If the parent repo had a path to this subrepo and the matcher is | # If the parent repo had a path to this subrepo and the matcher is | ||||
# a prefix matcher, this submatcher always matches. | # a prefix matcher, this submatcher always matches. | ||||
if matcher.prefix(): | if matcher.prefix(): | ||||
self._always = any(f == path for f in matcher._files) | self._always = any(f == path for f in matcher._files) | ||||
def bad(self, f, msg): | def bad(self, f, msg): | ||||
self._matcher.bad(self._path + "/" + f, msg) | self._matcher.bad(self._path + "/" + f, msg) | ||||
def rel(self, f): | |||||
return self._matcher.rel(self._path + "/" + f) | |||||
def matchfn(self, f): | def matchfn(self, f): | ||||
# Some information is lost in the superclass's constructor, so we | # Some information is lost in the superclass's constructor, so we | ||||
# can not accurately create the matching function for the subdirectory | # can not accurately create the matching function for the subdirectory | ||||
# from the inputs. Instead, we override matchfn() and visitdir() to | # from the inputs. Instead, we override matchfn() and visitdir() to | ||||
# call the original matcher with the subdirectory path prepended. | # call the original matcher with the subdirectory path prepended. | ||||
return self._matcher.matchfn(self._path + "/" + f) | return self._matcher.matchfn(self._path + "/" + f) | ||||
def visitdir(self, dir): | def visitdir(self, dir): |