##// END OF EJS Templates
match: resolve filesets against the passed `cwd`, not the current one...
Matt Harbison -
r44461:e685fac5 default
parent child Browse files
Show More
@@ -52,7 +52,7 b' def pygmentize(web, field, fctx, tmpl):'
52 52 filenameonly = web.configbool(b'web', b'highlightonlymatchfilename', False)
53 53
54 54 ctx = fctx.changectx()
55 m = ctx.matchfileset(expr)
55 m = ctx.matchfileset(fctx.repo().root, expr)
56 56 if m(fctx.path()):
57 57 highlight.pygmentize(
58 58 field, fctx, style, tmpl, guessfilenameonly=filenameonly
@@ -200,8 +200,8 b' class basectx(object):'
200 200 def mutable(self):
201 201 return self.phase() > phases.public
202 202
203 def matchfileset(self, expr, badfn=None):
204 return fileset.match(self, expr, badfn=badfn)
203 def matchfileset(self, cwd, expr, badfn=None):
204 return fileset.match(self, cwd, expr, badfn=badfn)
205 205
206 206 def obsolete(self):
207 207 """True if the changeset is obsolete"""
@@ -328,11 +328,14 b' class basectx(object):'
328 328 default=b'glob',
329 329 listsubrepos=False,
330 330 badfn=None,
331 cwd=None,
331 332 ):
332 333 r = self._repo
334 if not cwd:
335 cwd = r.getcwd()
333 336 return matchmod.match(
334 337 r.root,
335 r.getcwd(),
338 cwd,
336 339 pats,
337 340 include,
338 341 exclude,
@@ -1694,15 +1697,18 b' class workingctx(committablectx):'
1694 1697 default=b'glob',
1695 1698 listsubrepos=False,
1696 1699 badfn=None,
1700 cwd=None,
1697 1701 ):
1698 1702 r = self._repo
1703 if not cwd:
1704 cwd = r.getcwd()
1699 1705
1700 1706 # Only a case insensitive filesystem needs magic to translate user input
1701 1707 # to actual case in the filesystem.
1702 1708 icasefs = not util.fscasesensitive(r.root)
1703 1709 return matchmod.match(
1704 1710 r.root,
1705 r.getcwd(),
1711 cwd,
1706 1712 pats,
1707 1713 include,
1708 1714 exclude,
@@ -1171,7 +1171,7 b' def debugfileset(ui, repo, expr, **opts)'
1171 1171 files.update(ctx.files())
1172 1172 files.update(ctx.substate)
1173 1173
1174 m = ctx.matchfileset(expr)
1174 m = ctx.matchfileset(repo.getcwd(), expr)
1175 1175 if opts[b'show_matcher'] or (opts[b'show_matcher'] is None and ui.verbose):
1176 1176 ui.writenoi18n(b'* matcher:\n', stringutil.prettyrepr(m), b'\n')
1177 1177 for f in sorted(files):
@@ -520,29 +520,30 b' methods = {'
520 520
521 521
522 522 class matchctx(object):
523 def __init__(self, basectx, ctx, badfn=None):
523 def __init__(self, basectx, ctx, cwd, badfn=None):
524 524 self._basectx = basectx
525 525 self.ctx = ctx
526 526 self._badfn = badfn
527 527 self._match = None
528 528 self._status = None
529 self.cwd = cwd
529 530
530 531 def narrowed(self, match):
531 532 """Create matchctx for a sub-tree narrowed by the given matcher"""
532 mctx = matchctx(self._basectx, self.ctx, self._badfn)
533 mctx = matchctx(self._basectx, self.ctx, self.cwd, self._badfn)
533 534 mctx._match = match
534 535 # leave wider status which we don't have to care
535 536 mctx._status = self._status
536 537 return mctx
537 538
538 539 def switch(self, basectx, ctx):
539 mctx = matchctx(basectx, ctx, self._badfn)
540 mctx = matchctx(basectx, ctx, self.cwd, self._badfn)
540 541 mctx._match = self._match
541 542 return mctx
542 543
543 544 def withstatus(self, keys):
544 545 """Create matchctx which has precomputed status specified by the keys"""
545 mctx = matchctx(self._basectx, self.ctx, self._badfn)
546 mctx = matchctx(self._basectx, self.ctx, self.cwd, self._badfn)
546 547 mctx._match = self._match
547 548 mctx._buildstatus(keys)
548 549 return mctx
@@ -560,7 +561,7 b' class matchctx(object):'
560 561 return self._status
561 562
562 563 def matcher(self, patterns):
563 return self.ctx.match(patterns, badfn=self._badfn)
564 return self.ctx.match(patterns, badfn=self._badfn, cwd=self.cwd)
564 565
565 566 def predicate(self, predfn, predrepr=None, cache=False):
566 567 """Create a matcher to select files by predfn(filename)"""
@@ -617,12 +618,12 b' class matchctx(object):'
617 618 return matchmod.never(badfn=self._badfn)
618 619
619 620
620 def match(ctx, expr, badfn=None):
621 def match(ctx, cwd, expr, badfn=None):
621 622 """Create a matcher for a single fileset expression"""
622 623 tree = filesetlang.parse(expr)
623 624 tree = filesetlang.analyze(tree)
624 625 tree = filesetlang.optimize(tree)
625 mctx = matchctx(ctx.p1(), ctx, badfn=badfn)
626 mctx = matchctx(ctx.p1(), ctx, cwd, badfn=badfn)
626 627 return getmatch(mctx, tree)
627 628
628 629
@@ -57,7 +57,7 b' def _rematcher(regex):'
57 57 return m.match
58 58
59 59
60 def _expandsets(kindpats, ctx=None, listsubrepos=False, badfn=None):
60 def _expandsets(cwd, kindpats, ctx=None, listsubrepos=False, badfn=None):
61 61 '''Returns the kindpats list with the 'set' patterns expanded to matchers'''
62 62 matchers = []
63 63 other = []
@@ -68,11 +68,11 b' def _expandsets(kindpats, ctx=None, list'
68 68 raise error.ProgrammingError(
69 69 b"fileset expression with no context"
70 70 )
71 matchers.append(ctx.matchfileset(pat, badfn=badfn))
71 matchers.append(ctx.matchfileset(cwd, pat, badfn=badfn))
72 72
73 73 if listsubrepos:
74 74 for subpath in ctx.substate:
75 sm = ctx.sub(subpath).matchfileset(pat, badfn=badfn)
75 sm = ctx.sub(subpath).matchfileset(cwd, pat, badfn=badfn)
76 76 pm = prefixdirmatcher(subpath, sm, badfn=badfn)
77 77 matchers.append(pm)
78 78
@@ -117,11 +117,11 b' def _kindpatsalwaysmatch(kindpats):'
117 117
118 118
119 119 def _buildkindpatsmatcher(
120 matchercls, root, kindpats, ctx=None, listsubrepos=False, badfn=None
120 matchercls, root, cwd, kindpats, ctx=None, listsubrepos=False, badfn=None,
121 121 ):
122 122 matchers = []
123 123 fms, kindpats = _expandsets(
124 kindpats, ctx=ctx, listsubrepos=listsubrepos, badfn=badfn
124 cwd, kindpats, ctx=ctx, listsubrepos=listsubrepos, badfn=badfn,
125 125 )
126 126 if kindpats:
127 127 m = matchercls(root, kindpats, badfn=badfn)
@@ -261,6 +261,7 b' def match('
261 261 m = _buildkindpatsmatcher(
262 262 patternmatcher,
263 263 root,
264 cwd,
264 265 kindpats,
265 266 ctx=ctx,
266 267 listsubrepos=listsubrepos,
@@ -276,6 +277,7 b' def match('
276 277 im = _buildkindpatsmatcher(
277 278 includematcher,
278 279 root,
280 cwd,
279 281 kindpats,
280 282 ctx=ctx,
281 283 listsubrepos=listsubrepos,
@@ -287,6 +289,7 b' def match('
287 289 em = _buildkindpatsmatcher(
288 290 includematcher,
289 291 root,
292 cwd,
290 293 kindpats,
291 294 ctx=ctx,
292 295 listsubrepos=listsubrepos,
@@ -355,7 +355,7 b' class abstractsubrepo(object):'
355 355 """return file flags"""
356 356 return b''
357 357
358 def matchfileset(self, expr, badfn=None):
358 def matchfileset(self, cwd, expr, badfn=None):
359 359 """Resolve the fileset expression for this repo"""
360 360 return matchmod.never(badfn=badfn)
361 361
@@ -896,20 +896,20 b' class hgsubrepo(abstractsubrepo):'
896 896 return cmdutil.files(ui, ctx, m, uipathfn, fm, fmt, subrepos)
897 897
898 898 @annotatesubrepoerror
899 def matchfileset(self, expr, badfn=None):
899 def matchfileset(self, cwd, expr, badfn=None):
900 900 if self._ctx.rev() is None:
901 901 ctx = self._repo[None]
902 902 else:
903 903 rev = self._state[1]
904 904 ctx = self._repo[rev]
905 905
906 matchers = [ctx.matchfileset(expr, badfn=badfn)]
906 matchers = [ctx.matchfileset(cwd, expr, badfn=badfn)]
907 907
908 908 for subpath in ctx.substate:
909 909 sub = ctx.sub(subpath)
910 910
911 911 try:
912 sm = sub.matchfileset(expr, badfn=badfn)
912 sm = sub.matchfileset(cwd, expr, badfn=badfn)
913 913 pm = matchmod.prefixdirmatcher(subpath, sm, badfn=badfn)
914 914 matchers.append(pm)
915 915 except error.LookupError:
@@ -1335,24 +1335,20 b' reasonable with that.'
1335 1335 Apparently fixing p1() and its descendants doesn't include wdir() unless
1336 1336 explicitly stated.
1337 1337
1338 BROKEN: fileset matches aren't relative to repo.root for commits
1339
1340 1338 $ hg fix -r '.::'
1341 1339 $ hg cat -r . ../quux
1342 1340 quux
1343 1341 $ hg cat -r tip ../quux
1344 quux
1342 fs: $TESTTMP/subprocesscwd
1345 1343 $ cat ../quux
1346 1344 quux
1347 1345
1348 1346 Clean files are not fixed unless explicitly named
1349 1347 $ echo 'dirty' > ../quux
1350 1348
1351 BROKEN: fileset matches aren't relative to repo.root for wdir
1352
1353 1349 $ hg fix --working-dir
1354 1350 $ cat ../quux
1355 dirty
1351 fs: $TESTTMP/subprocesscwd
1356 1352
1357 1353 $ cd ../..
1358 1354
General Comments 0
You need to be logged in to leave comments. Login now