##// END OF EJS Templates
revset: introduce a `nodefromfile` revset...
marmoute -
r47566:56d44125 default
parent child Browse files
Show More
@@ -1335,6 +1335,29 b' def followlines(repo, subset, x):'
1335 return subset & rs
1335 return subset & rs
1336
1336
1337
1337
1338 @predicate(b'nodefromfile(path)')
1339 def nodefromfile(repo, subset, x):
1340 """
1341 An alias for ``::.`` (ancestors of the working directory's first parent).
1342 If file pattern is specified, the histories of files matching given
1343 pattern in the revision given by startrev are followed, including copies.
1344 """
1345 path = getstring(x, _(b"nodefromfile require a file path"))
1346 listed_rev = set()
1347 try:
1348 with pycompat.open(path, 'rb') as f:
1349 for line in f:
1350 n = line.strip()
1351 rn = _node(repo, n)
1352 if rn is not None:
1353 listed_rev.add(rn)
1354 except IOError as exc:
1355 m = _(b'cannot open nodes file "%s": %s')
1356 m %= (path, encoding.strtolocal(exc.strerror))
1357 raise error.Abort(m)
1358 return subset & baseset(listed_rev)
1359
1360
1338 @predicate(b'all()', safe=True)
1361 @predicate(b'all()', safe=True)
1339 def getall(repo, subset, x):
1362 def getall(repo, subset, x):
1340 """All changesets, the same as ``0:tip``."""
1363 """All changesets, the same as ``0:tip``."""
@@ -1697,13 +1720,9 b' def named(repo, subset, x):'
1697 return subset & names
1720 return subset & names
1698
1721
1699
1722
1700 @predicate(b'id(string)', safe=True)
1723 def _node(repo, n):
1701 def node_(repo, subset, x):
1724 """process a node input"""
1702 """Revision non-ambiguously specified by the given hex string prefix."""
1725 rn = None
1703 # i18n: "id" is a keyword
1704 l = getargs(x, 1, 1, _(b"id requires one argument"))
1705 # i18n: "id" is a keyword
1706 n = getstring(l[0], _(b"id requires a string"))
1707 if len(n) == 40:
1726 if len(n) == 40:
1708 try:
1727 try:
1709 rn = repo.changelog.rev(bin(n))
1728 rn = repo.changelog.rev(bin(n))
@@ -1712,7 +1731,6 b' def node_(repo, subset, x):'
1712 except (LookupError, TypeError):
1731 except (LookupError, TypeError):
1713 rn = None
1732 rn = None
1714 else:
1733 else:
1715 rn = None
1716 try:
1734 try:
1717 pm = scmutil.resolvehexnodeidprefix(repo, n)
1735 pm = scmutil.resolvehexnodeidprefix(repo, n)
1718 if pm is not None:
1736 if pm is not None:
@@ -1721,6 +1739,17 b' def node_(repo, subset, x):'
1721 pass
1739 pass
1722 except error.WdirUnsupported:
1740 except error.WdirUnsupported:
1723 rn = wdirrev
1741 rn = wdirrev
1742 return rn
1743
1744
1745 @predicate(b'id(string)', safe=True)
1746 def node_(repo, subset, x):
1747 """Revision non-ambiguously specified by the given hex string prefix."""
1748 # i18n: "id" is a keyword
1749 l = getargs(x, 1, 1, _(b"id requires one argument"))
1750 # i18n: "id" is a keyword
1751 n = getstring(l[0], _(b"id requires a string"))
1752 rn = _node(repo, n)
1724
1753
1725 if rn is None:
1754 if rn is None:
1726 return baseset()
1755 return baseset()
@@ -137,6 +137,7 b' Invalid :pushrev raises appropriately'
137 $ hg --config 'paths.default:pushrev=notdefined()' push
137 $ hg --config 'paths.default:pushrev=notdefined()' push
138 pushing to file:/*/$TESTTMP/pushurlsource/../pushurldest (glob)
138 pushing to file:/*/$TESTTMP/pushurlsource/../pushurldest (glob)
139 hg: parse error: unknown identifier: notdefined
139 hg: parse error: unknown identifier: notdefined
140 (did you mean nodefromfile?)
140 [10]
141 [10]
141
142
142 $ hg --config 'paths.default:pushrev=(' push
143 $ hg --config 'paths.default:pushrev=(' push
@@ -3108,3 +3108,18 b" abort if the revset doesn't expect given"
3108 $ log 'expectsize(0:2, :2)'
3108 $ log 'expectsize(0:2, :2)'
3109 abort: revset size mismatch. expected between 0 and 2, got 3
3109 abort: revset size mismatch. expected between 0 and 2, got 3
3110 [255]
3110 [255]
3111
3112 Test getting list of node from file
3113
3114 $ hg log -r '0:2' -T '{node}\n' > some.nodes
3115 $ hg log -r 'nodefromfile("some.nodes")' -T '{rev}\n'
3116 0
3117 1
3118 2
3119 $ hg log -r 'nodefromfile("missing-file")' -T '{rev}\n'
3120 abort: cannot open nodes file "missing-file": $ENOENT$
3121 [255]
3122 $ echo bad-node > bad.nodes
3123 $ hg log -r 'nodefromfile("bad.nodes")' -T '{rev}\n'
3124 $ echo abcdefabcdefabcdeabcdeabcdeabcdeabcdeabc > missing.nodes
3125
General Comments 0
You need to be logged in to leave comments. Login now