Patchwork revset: add update() revset to return target rev for 'hg update'

login
register
mail settings
Submitter Kevin Bullock
Date Feb. 9, 2013, 9:46 p.m.
Message ID <57ba45c914886c80342d.1360446418@s0-0.paconsult7.bbnplanet.net>
Download mbox | patch
Permalink /patch/911/
State Changes Requested
Headers show

Comments

Kevin Bullock - Feb. 9, 2013, 9:46 p.m.
# HG changeset patch
# User Kevin Bullock <kbullock@ringworld.org>
# Date 1360405949 0
# Node ID 57ba45c914886c80342df5d0f130fbc72780f2e7
# Parent  9d727e125244520c4fe60a4b8d60e29269d24af3
revset: add update() revset to return target rev for 'hg update'
Matt Mackall - Feb. 9, 2013, 9:55 p.m.
On Sat, 2013-02-09 at 21:46 +0000, Kevin Bullock wrote:
> # HG changeset patch
> # User Kevin Bullock <kbullock@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

Hrm, circular import.

>  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()

Hmm. don't see how this deals with the current branch.

> +    repo.ui.debug(repr(target) + '\n')

Left-over?

> +    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
>  
> _______________________________________________
> Mercurial-devel mailing list
> Mercurial-devel@selenic.com
> http://selenic.com/mailman/listinfo/mercurial-devel

Patch

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