comparison mercurial/fileset.py @ 31203:4140d49d2efb

fileset: add revs(revs, fileset) to evaluate set in working directory Unlike other functions, "revs()" does not select files but switches the evaluation context. This allow to match file with property in another revision that the one currently evaluated. This changeset is based on work from Yuya Nishihara.
author Pierre-Yves David <pierre-yves.david@ens-lyon.org>
date Fri, 03 Mar 2017 12:44:56 +0100
parents 951d95b13487
children 016c63d6658c
comparison
equal deleted inserted replaced
31202:951d95b13487 31203:4140d49d2efb
13 from . import ( 13 from . import (
14 error, 14 error,
15 merge, 15 merge,
16 parser, 16 parser,
17 registrar, 17 registrar,
18 scmutil,
18 util, 19 util,
19 ) 20 )
20 21
21 elements = { 22 elements = {
22 # token-type: binding-strength, primary, prefix, infix, suffix 23 # token-type: binding-strength, primary, prefix, infix, suffix
436 p = mctx.ctx[f].parents() 437 p = mctx.ctx[f].parents()
437 if p and p[0].path() != f: 438 if p and p[0].path() != f:
438 s.append(f) 439 s.append(f)
439 return s 440 return s
440 441
442 @predicate('revs(revs, pattern)')
443 def revs(mctx, x):
444 """``revs(set, revspec)``
445
446 Evaluate set in the specified revisions. If the revset match multiple revs,
447 this will return file matching pattern in any of the revision.
448 """
449 # i18n: "revs" is a keyword
450 r, x = getargs(x, 2, 2, _("revs takes two arguments"))
451 # i18n: "revs" is a keyword
452 revspec = getstring(r, _("first argument to revs must be a revision"))
453 repo = mctx.ctx.repo()
454 revs = scmutil.revrange(repo, [revspec])
455
456 found = set()
457 result = []
458 for r in revs:
459 ctx = repo[r]
460 for f in getset(mctx.switch(ctx, _buildstatus(ctx, x)), x):
461 if f not in found:
462 found.add(f)
463 result.append(f)
464 return result
465
441 @predicate('subrepo([pattern])') 466 @predicate('subrepo([pattern])')
442 def subrepo(mctx, x): 467 def subrepo(mctx, x):
443 """Subrepositories whose paths match the given pattern. 468 """Subrepositories whose paths match the given pattern.
444 """ 469 """
445 # i18n: "subrepo" is a keyword 470 # i18n: "subrepo" is a keyword
510 def switch(self, ctx, status=None): 535 def switch(self, ctx, status=None):
511 return fullmatchctx(ctx, status) 536 return fullmatchctx(ctx, status)
512 537
513 # filesets using matchctx.switch() 538 # filesets using matchctx.switch()
514 _switchcallers = [ 539 _switchcallers = [
540 'revs',
515 ] 541 ]
516 542
517 def _intree(funcs, tree): 543 def _intree(funcs, tree):
518 if isinstance(tree, tuple): 544 if isinstance(tree, tuple):
519 if tree[0] == 'func' and tree[1][0] == 'symbol': 545 if tree[0] == 'func' and tree[1][0] == 'symbol':