Patchwork changectx: fix the handling of `tip`

login
register
mail settings
Submitter Pierre-Yves David
Date Jan. 22, 2013, 10:40 a.m.
Message ID <ea495f12479657a8a74a.1358851251@crater1.logilab.fr>
Download mbox | patch
Permalink /patch/710/
State Accepted
Commit a2e9fe93d9eaba4ad2727d6bcde3afe3985ac00b
Headers show

Comments

Pierre-Yves David - Jan. 22, 2013, 10:40 a.m.
# HG changeset patch
# User Pierre-Yves David <pierre-yves.david@logilab.fr>
# Date 1358851154 -3600
# Branch stable
# Node ID ea495f12479657a8a74ac9961140233e5c8f244e
# Parent  8a811fa9a9c0785b843e032ed82ce5316a645631
changectx: fix the handling of `tip`

We can not use `len(repo,changelog)`, it may be a filtered revision. We now use
`repo,changelog.tip()` to fetch this information.

The `tip` command is also fixed and tested

Thanks goes to Idan Kamara for the initial report.
Matt Mackall - Jan. 22, 2013, 11:44 p.m.
On Tue, 2013-01-22 at 11:40 +0100, pierre-yves.david@logilab.fr wrote:
> # HG changeset patch
> # User Pierre-Yves David <pierre-yves.david@logilab.fr>
> # Date 1358851154 -3600
> # Branch stable
> # Node ID ea495f12479657a8a74ac9961140233e5c8f244e
> # Parent  8a811fa9a9c0785b843e032ed82ce5316a645631
> changectx: fix the handling of `tip`

Queued for stable, thanks.

Patch

diff --git a/mercurial/commands.py b/mercurial/commands.py
--- a/mercurial/commands.py
+++ b/mercurial/commands.py
@@ -5864,11 +5864,11 @@  def tip(ui, repo, **opts):
     and cannot be renamed or assigned to a different changeset.
 
     Returns 0 on success.
     """
     displayer = cmdutil.show_changeset(ui, repo, opts)
-    displayer.show(repo[len(repo) - 1])
+    displayer.show(repo['tip'])
     displayer.close()
 
 @command('unbundle',
     [('u', 'update', None,
      _('update to new branch head if changesets were unbundled'))],
diff --git a/mercurial/context.py b/mercurial/context.py
--- a/mercurial/context.py
+++ b/mercurial/context.py
@@ -42,12 +42,12 @@  class changectx(object):
         if changeid == 'null':
             self._node = nullid
             self._rev = nullrev
             return
         if changeid == 'tip':
-            self._rev = len(repo.changelog) - 1
-            self._node = repo.changelog.node(self._rev)
+            self._node = repo.changelog.tip()
+            self._rev = repo.changelog.rev(self._node)
             return
         if len(changeid) == 20:
             try:
                 self._node = changeid
                 self._rev = repo.changelog.rev(changeid)
diff --git a/tests/test-obsolete.t b/tests/test-obsolete.t
--- a/tests/test-obsolete.t
+++ b/tests/test-obsolete.t
@@ -53,10 +53,21 @@  Killing a single changeset without repla
   abort: changeset references must be full hexadecimal node identifiers
   [255]
   $ hg debugobsolete -d '0 0' `getid kill_me` -u babar
   $ hg debugobsolete
   97b7c2d76b1845ed3eb988cd612611e72406cef0 0 {'date': '0 0', 'user': 'babar'}
+
+(test that mercurial is not confused)
+
+  $ hg up null --quiet # having 0 as parent prevents it to be hidden
+  $ hg tip
+  changeset:   -1:000000000000
+  tag:         tip
+  user:        
+  date:        Thu Jan 01 00:00:00 1970 +0000
+  
+  $ hg up --hidden tip --quiet
   $ cd ..
 
 Killing a single changeset with replacement
 
   $ hg init tmpb