[PATCH] commands.update() now works properly with a revision of 0

Matt Mackall mpm at selenic.com
Tue Mar 8 12:17:27 CST 2011


On Tue, 2011-03-08 at 08:43 -0500, Mark Drago wrote:
> # HG changeset patch
> # User Mark Drago <markdrago at gmail.com>
> # Date 1299591699 18000
> # Node ID b52e177849c06e4427f73f51cf5360ba1cef19f4
> # Parent  997e6ce5396b55ab4fd1407baa59a066ed51c3e4
> commands.update() now works properly with a revision of 0
> 
> Without this change commands.update() treats an integer 0 as if no revision
> was passed and updates to the branch head.  This fix allows an integer 0 to
> be detected as a revision number so the working directory is correctly
> changed to revision 0 rather than the branch head.
> 
> diff -r 997e6ce5396b -r b52e177849c0 mercurial/commands.py
> --- a/mercurial/commands.py	Mon Mar 07 18:35:27 2011 -0500
> +++ b/mercurial/commands.py	Tue Mar 08 08:41:39 2011 -0500
> @@ -4053,7 +4053,7 @@
>      if rev and node:
>          raise util.Abort(_("please specify just one revision"))
>  
> -    if not rev:
> +    if rev is None or rev == '':
>          rev = node
>  
>      # if we defined a bookmark, we have to remember the original bookmark name
> diff -r 997e6ce5396b -r b52e177849c0 tests/test-update-rev-0.t
> --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
> +++ b/tests/test-update-rev-0.t	Tue Mar 08 08:41:39 2011 -0500
> @@ -0,0 +1,23 @@
> +
> +verify that updating to revision 0 via commands.update() works properly
> +
> +  $ hg init
> +  $ echo 'rev0 content' > rev0
> +  $ hg add rev0
> +  $ hg commit -m 'rev0 commit'
> +  $ echo 'rev1 content' > rev1
> +  $ hg add rev1
> +  $ hg commit -m 'rev1 commit'
> +  $ hg identify -n
> +  1
> +  $ cat <<EOF > update_to_rev0.py
> +  > from mercurial import ui, hg, commands
> +  > 
> +  > myui = ui.ui()
> +  > repo = hg.repository(myui, path='.')
> +  > commands.update(myui, repo, rev=0)
> +  > EOF
> +  $ python ./update_to_rev0.py
> +  0 files updated, 0 files merged, 1 files removed, 0 files unresolved
> +  $ hg identify -n
> +  0

Queued, thanks. I've folded your test into test-basic, so that we don't
have to duplicate the repo creation.

-- 
Mathematics is the supreme nostalgia of our time.




More information about the Mercurial-devel mailing list