532 # |
532 # |
533 # [p:foo, i:bar, x:baz] |
533 # [p:foo, i:bar, x:baz] |
534 # |
534 # |
535 # builds a match object from them and filters subset. Allowed |
535 # builds a match object from them and filters subset. Allowed |
536 # prefixes are 'p:' for regular patterns, 'i:' for include |
536 # prefixes are 'p:' for regular patterns, 'i:' for include |
537 # patterns and 'x:' for exclude patterns. |
537 # patterns and 'x:' for exclude patterns. Use 'r:' prefix to pass |
|
538 # a revision identifier, or the empty string to reference the |
|
539 # working directory, from which the match object is |
|
540 # initialized. At most one 'r:' argument can be passed. |
538 |
541 |
539 # i18n: "_matchfiles" is a keyword |
542 # i18n: "_matchfiles" is a keyword |
540 l = getargs(x, 1, -1, _("_matchfiles requires at least one argument")) |
543 l = getargs(x, 1, -1, _("_matchfiles requires at least one argument")) |
541 pats, inc, exc = [], [], [] |
544 pats, inc, exc = [], [], [] |
542 hasset = False |
545 hasset = False |
|
546 rev = None |
543 for arg in l: |
547 for arg in l: |
544 s = getstring(arg, _("_matchfiles requires string arguments")) |
548 s = getstring(arg, _("_matchfiles requires string arguments")) |
545 prefix, value = s[:2], s[2:] |
549 prefix, value = s[:2], s[2:] |
546 if prefix == 'p:': |
550 if prefix == 'p:': |
547 pats.append(value) |
551 pats.append(value) |
548 elif prefix == 'i:': |
552 elif prefix == 'i:': |
549 inc.append(value) |
553 inc.append(value) |
550 elif prefix == 'x:': |
554 elif prefix == 'x:': |
551 exc.append(value) |
555 exc.append(value) |
|
556 elif prefix == 'r:': |
|
557 if rev is not None: |
|
558 raise error.ParseError(_('_matchfiles expected at most one ' |
|
559 'revision')) |
|
560 rev = value |
552 else: |
561 else: |
553 raise error.ParseError(_('invalid _matchfiles prefix: %s') % prefix) |
562 raise error.ParseError(_('invalid _matchfiles prefix: %s') % prefix) |
554 if not hasset and matchmod.patkind(value) == 'set': |
563 if not hasset and matchmod.patkind(value) == 'set': |
555 hasset = True |
564 hasset = True |
556 m = None |
565 m = None |
557 s = [] |
566 s = [] |
558 for r in subset: |
567 for r in subset: |
559 c = repo[r] |
568 c = repo[r] |
560 if not m or hasset: |
569 if not m or (hasset and rev is None): |
|
570 ctx = c |
|
571 if rev is not None: |
|
572 ctx = repo[rev or None] |
561 m = matchmod.match(repo.root, repo.getcwd(), pats, include=inc, |
573 m = matchmod.match(repo.root, repo.getcwd(), pats, include=inc, |
562 exclude=exc, ctx=c) |
574 exclude=exc, ctx=ctx) |
563 for f in c.files(): |
575 for f in c.files(): |
564 if m(f): |
576 if m(f): |
565 s.append(r) |
577 s.append(r) |
566 break |
578 break |
567 return s |
579 return s |