[PATCH] revset: add update() revset to return target rev for 'hg update'

Kevin Bullock kbullock+mercurial at ringworld.org
Sat Feb 9 15:46:58 CST 2013


# HG changeset patch
# User Kevin Bullock <kbullock at ringworld.org>
# Date 1360405949 0
# Node ID 57ba45c914886c80342df5d0f130fbc72780f2e7
# Parent  9d727e125244520c4fe60a4b8d60e29269d24af3
revset: add update() revset to return target rev for 'hg update'

diff --git a/mercurial/revset.py b/mercurial/revset.py
--- a/mercurial/revset.py
+++ b/mercurial/revset.py
@@ -13,6 +13,7 @@ from i18n import _
 import encoding
 import obsolete as obsmod
 import repoview
+import bookmarks, scmutil
 
 def _revancestors(repo, revs, followfirst):
     """Like revlog.ancestors(), but supports followfirst."""
@@ -1514,6 +1515,15 @@ def unstable(repo, subset, x):
     unstables = obsmod.getrevs(repo, 'unstable')
     return [r for r in subset if r in unstables]
 
+def update(repo, subset, x):
+    """``update()``
+    The target revisions that a bare 'hg update' will update to.
+    """
+    if repo._bookmarkcurrent and not bookmarks.iscurrent(repo):
+        target = repo._bookmarks[repo._bookmarkcurrent].rev()
+    target = scmutil.revsingle(repo, None, 'tip').rev()
+    repo.ui.debug(repr(target) + '\n')
+    return [r for r in subset if r == target]
 
 def user(repo, subset, x):
     """``user(string)``
@@ -1600,6 +1610,7 @@ symbols = {
     "tagged": tagged,
     "user": user,
     "unstable": unstable,
+    "update": update,
     "_list": _list,
 }
 
diff --git a/tests/test-revset.t b/tests/test-revset.t
--- a/tests/test-revset.t
+++ b/tests/test-revset.t
@@ -446,6 +446,11 @@ we can use patterns when searching for t
   $ log 'branch(unknown)'
   abort: unknown revision 'unknown'!
   [255]
+  $ log 'update()'
+  9
+  $ hg up 8
+  $ log 'update()'
+  9
   $ log 'user(bob)'
   2
 


More information about the Mercurial-devel mailing list