comparison mercurial/revset.py @ 29825:cbf9984a7957

revset: support "follow(renamed.py, e22f4f3f06c3)" (issue5334) v2: fixes from review
author G?bor Stefanik <gabor.stefanik@nng.com>
date Thu, 18 Aug 2016 17:25:10 +0200
parents 531e85eec23c
children 104914b03b83
comparison
equal deleted inserted replaced
29824:5f86818c95e5 29825:cbf9984a7957
997 """An alias for limit(). 997 """An alias for limit().
998 """ 998 """
999 return limit(repo, subset, x) 999 return limit(repo, subset, x)
1000 1000
1001 def _follow(repo, subset, x, name, followfirst=False): 1001 def _follow(repo, subset, x, name, followfirst=False):
1002 l = getargs(x, 0, 1, _("%s takes no arguments or a pattern") % name) 1002 l = getargs(x, 0, 2, _("%s takes no arguments or a pattern "
1003 "and an optional revset") % name)
1003 c = repo['.'] 1004 c = repo['.']
1004 if l: 1005 if l:
1005 x = getstring(l[0], _("%s expected a pattern") % name) 1006 x = getstring(l[0], _("%s expected a pattern") % name)
1007 rev = None
1008 if len(l) >= 2:
1009 rev = getset(repo, fullreposet(repo), l[1]).last()
1010 if rev is None:
1011 raise error.RepoLookupError(
1012 _("%s: starting revision set cannot be empty") % name)
1013 c = repo[rev]
1006 matcher = matchmod.match(repo.root, repo.getcwd(), [x], 1014 matcher = matchmod.match(repo.root, repo.getcwd(), [x],
1007 ctx=repo[None], default='path') 1015 ctx=repo[rev], default='path')
1008 1016
1009 files = c.manifest().walk(matcher) 1017 files = c.manifest().walk(matcher)
1010 1018
1011 s = set() 1019 s = set()
1012 for fname in files: 1020 for fname in files:
1017 else: 1025 else:
1018 s = _revancestors(repo, baseset([c.rev()]), followfirst) 1026 s = _revancestors(repo, baseset([c.rev()]), followfirst)
1019 1027
1020 return subset & s 1028 return subset & s
1021 1029
1022 @predicate('follow([pattern])', safe=True) 1030 @predicate('follow([pattern[, startrev]])', safe=True)
1023 def follow(repo, subset, x): 1031 def follow(repo, subset, x):
1024 """ 1032 """
1025 An alias for ``::.`` (ancestors of the working directory's first parent). 1033 An alias for ``::.`` (ancestors of the working directory's first parent).
1026 If pattern is specified, the histories of files matching given 1034 If pattern is specified, the histories of files matching given
1027 pattern is followed, including copies. 1035 pattern in the revision given by startrev are followed, including copies.
1028 """ 1036 """
1029 return _follow(repo, subset, x, 'follow') 1037 return _follow(repo, subset, x, 'follow')
1030 1038
1031 @predicate('_followfirst', safe=True) 1039 @predicate('_followfirst', safe=True)
1032 def _followfirst(repo, subset, x): 1040 def _followfirst(repo, subset, x):
1033 # ``followfirst([pattern])`` 1041 # ``followfirst([pattern[, startrev]])``
1034 # Like ``follow([pattern])`` but follows only the first parent of 1042 # Like ``follow([pattern[, startrev]])`` but follows only the first parent
1035 # every revisions or files revisions. 1043 # of every revisions or files revisions.
1036 return _follow(repo, subset, x, '_followfirst', followfirst=True) 1044 return _follow(repo, subset, x, '_followfirst', followfirst=True)
1037 1045
1038 @predicate('all()', safe=True) 1046 @predicate('all()', safe=True)
1039 def getall(repo, subset, x): 1047 def getall(repo, subset, x):
1040 """All changesets, the same as ``0:tip``. 1048 """All changesets, the same as ``0:tip``.