Patchwork [1,of,3,STABLE] revset: allow rev(-1) to indicate null revision (BC)

login
register
mail settings
Submitter Yuya Nishihara
Date Jan. 25, 2015, 2:09 p.m.
Message ID <2c01b019a43ddc3ccaed.1422194979@mimosa>
Download mbox | patch
Permalink /patch/7553/
State Accepted
Commit 310222feb9a8671d48a8df6b57300d0326176ba0
Headers show

Comments

Yuya Nishihara - Jan. 25, 2015, 2:09 p.m.
# HG changeset patch
# User Yuya Nishihara <yuya@tcha.org>
# Date 1420862198 -32400
#      Sat Jan 10 12:56:38 2015 +0900
# Branch stable
# Node ID 2c01b019a43ddc3ccaed54c2a7869aa88625e13b
# Parent  ea61e278ae9201d4b66146285bde689b4f26868e
revset: allow rev(-1) to indicate null revision (BC)

This can simplify the conversion from numeric revision to string. Without it,
we have to handle -1 specially because repo['-1'] != repo[-1].

The -1 revision is not officially documented, but this change makes sense
assuming that "rev(%d)" exists for scripting or third-party tools.

Patch

diff --git a/mercurial/revset.py b/mercurial/revset.py
--- a/mercurial/revset.py
+++ b/mercurial/revset.py
@@ -1545,7 +1545,7 @@  def rev(repo, subset, x):
     except (TypeError, ValueError):
         # i18n: "rev" is a keyword
         raise error.ParseError(_("rev expects a number"))
-    if l not in fullreposet(repo):
+    if l not in fullreposet(repo) and l != node.nullrev:
         return baseset()
     return subset & baseset([l])
 
diff --git a/tests/test-revset.t b/tests/test-revset.t
--- a/tests/test-revset.t
+++ b/tests/test-revset.t
@@ -465,7 +465,9 @@  Test the order of operations
   9
 
 Test explicit numeric revision
+  $ log 'rev(-2)'
   $ log 'rev(-1)'
+  -1
   $ log 'rev(0)'
   0
   $ log 'rev(9)'