revset: add id() and rev() to allow explicitly referring to changes by hash or rev
--- a/mercurial/help/revsets.txt Sun Oct 10 12:41:36 2010 -0500
+++ b/mercurial/help/revsets.txt Mon Oct 11 09:44:19 2010 -0500
@@ -94,6 +94,9 @@
``heads(set)``
Members of set with no children in set.
+``id(string)``
+ Revision non-ambiguously specified by the given hex string prefix
+
``keyword(string)``
Search commit message, user name, and names of changed files for
string.
@@ -133,6 +136,9 @@
``removes(pattern)``
Changesets which remove files matching pattern.
+``rev(number)``
+ Revision with the given numeric identifier.
+
``reverse(set)``
Reverse order of set.
--- a/mercurial/revset.py Sun Oct 10 12:41:36 2010 -0500
+++ b/mercurial/revset.py Mon Oct 11 09:44:19 2010 -0500
@@ -173,6 +173,23 @@
# functions
+def node(repo, subset, x):
+ l = getargs(x, 1, 1, _("rev wants one argument"))
+ n = getstring(l[0], _("rev wants a string"))
+ if len(n) == 40:
+ rn = repo[n].rev()
+ else:
+ rn = repo.changelog.rev(repo.changelog._partialmatch(n))
+ return [r for r in subset if r == rn]
+
+def rev(repo, subset, x):
+ l = getargs(x, 1, 1, _("rev wants one argument"))
+ try:
+ l = int(getstring(l[0], _("rev wants a number")))
+ except ValueError:
+ raise error.ParseError(_("rev expects a number"))
+ return [r for r in subset if r == l]
+
def p1(repo, subset, x):
ps = set()
cl = repo.changelog
@@ -501,6 +518,7 @@
"min": minrev,
"merge": merge,
"modifies": modifies,
+ "id": node,
"outgoing": outgoing,
"p1": p1,
"p2": p2,
@@ -508,6 +526,7 @@
"present": present,
"removes": removes,
"reverse": reverse,
+ "rev": rev,
"roots": roots,
"sort": sort,
"tag": tag,
--- a/tests/test-revset.t Sun Oct 10 12:41:36 2010 -0500
+++ b/tests/test-revset.t Mon Oct 11 09:44:19 2010 -0500
@@ -247,6 +247,8 @@
6
$ log 'modifies(b)'
4
+ $ log 'id(5)'
+ 2
$ log 'outgoing()'
8
9
@@ -276,6 +278,8 @@
4
3
2
+ $ log 'rev(5)'
+ 5
$ log 'sort(limit(reverse(all()), 3))'
7
8