comparison mercurial/match.py @ 32496:ca77a243ffa7

match: move entire uipath() implementation to basematcher Even though most matchers will always want to use the relative path in uipath(), when we add support for intersecting matcher, we will want to control which form to use for any kind of matcher without knowing the type (see next patch), so we need the implementation on the base class. Also rename the attribute from "pathrestricted" to "relativeuipath" since there actually are cases where we match everything but still use relative paths (like when the user runs "hg files .." from inside mercurial/).
author Martin von Zweigbergk <martinvonz@google.com>
date Thu, 25 May 2017 14:32:56 -0700
parents 12e241b2713c
children 9eccd559c592
comparison
equal deleted inserted replaced
32495:a25cc3ca874f 32496:ca77a243ffa7
207 kindpats.append((kind, pat, '')) 207 kindpats.append((kind, pat, ''))
208 return kindpats 208 return kindpats
209 209
210 class basematcher(object): 210 class basematcher(object):
211 211
212 def __init__(self, root, cwd, badfn=None): 212 def __init__(self, root, cwd, badfn=None, relativeuipath=True):
213 self._root = root 213 self._root = root
214 self._cwd = cwd 214 self._cwd = cwd
215 if badfn is not None: 215 if badfn is not None:
216 self.bad = badfn 216 self.bad = badfn
217 self._relativeuipath = relativeuipath
217 218
218 def __call__(self, fn): 219 def __call__(self, fn):
219 return self.matchfn(fn) 220 return self.matchfn(fn)
220 def __iter__(self): 221 def __iter__(self):
221 for f in self._files: 222 for f in self._files:
246 247
247 def uipath(self, f): 248 def uipath(self, f):
248 '''Convert repo path to a display path. If patterns or -I/-X were used 249 '''Convert repo path to a display path. If patterns or -I/-X were used
249 to create this matcher, the display path will be relative to cwd. 250 to create this matcher, the display path will be relative to cwd.
250 Otherwise it is relative to the root of the repo.''' 251 Otherwise it is relative to the root of the repo.'''
251 return self.rel(f) 252 return (self._relativeuipath and self.rel(f)) or self.abs(f)
252 253
253 @propertycache 254 @propertycache
254 def _files(self): 255 def _files(self):
255 return [] 256 return []
256 257
305 class matcher(basematcher): 306 class matcher(basematcher):
306 307
307 def __init__(self, root, cwd, normalize, patterns, include=None, 308 def __init__(self, root, cwd, normalize, patterns, include=None,
308 default='glob', exact=False, auditor=None, ctx=None, 309 default='glob', exact=False, auditor=None, ctx=None,
309 listsubrepos=False, warn=None, badfn=None): 310 listsubrepos=False, warn=None, badfn=None):
310 super(matcher, self).__init__(root, cwd, badfn) 311 super(matcher, self).__init__(root, cwd, badfn,
312 relativeuipath=bool(include or patterns))
311 if include is None: 313 if include is None:
312 include = [] 314 include = []
313 315
314 self._anypats = bool(include) 316 self._anypats = bool(include)
315 self._anyincludepats = False 317 self._anyincludepats = False
316 self._always = False 318 self._always = False
317 self._pathrestricted = bool(include or patterns)
318 self.patternspat = None 319 self.patternspat = None
319 self.includepat = None 320 self.includepat = None
320 321
321 # roots are directories which are recursively included. 322 # roots are directories which are recursively included.
322 self._includeroots = set() 323 self._includeroots = set()
359 if not matchfn(f): 360 if not matchfn(f):
360 return False 361 return False
361 return True 362 return True
362 363
363 self.matchfn = m 364 self.matchfn = m
364
365 def uipath(self, f):
366 return (self._pathrestricted and self.rel(f)) or self.abs(f)
367 365
368 @propertycache 366 @propertycache
369 def _dirs(self): 367 def _dirs(self):
370 return set(util.dirs(self._fileset)) | {'.'} 368 return set(util.dirs(self._fileset)) | {'.'}
371 369