Patchwork [STABLE,V2] repoview: do not crash when localtags refers to non existing revisions

login
register
mail settings
Submitter Angel Ezquerra
Date June 30, 2014, 10:53 p.m.
Message ID <0f977cb11be3938e1da6.1404168835@ubuntu>
Download mbox | patch
Permalink /patch/5089/
State Accepted
Commit 925d1bb9a971c6605f026bde488b4b730924f92b
Headers show

Comments

Angel Ezquerra - June 30, 2014, 10:53 p.m.
# HG changeset patch
# User Angel Ezquerra <angel.ezquerra@gmail.com>
# Date 1404042755 -7200
#      Sun Jun 29 13:52:35 2014 +0200
# Branch stable
# Node ID 0f977cb11be3938e1da6c54389712f2070960917
# Parent  a4b67bf1f0a5051736c14d9c13fae50fd5f5e464
repoview: do not crash when localtags refers to non existing revisions

This fixes a crash that may happen when using mercurial 3.0.x.

The _gethiddenblockers function assumed that the output of tags.readlocaltags()
was a dict mapping tags to of valid nodes. However this was not necessarily the
case. When a repository had obsolete revisions and had local tag pointing to a
non existing revision was found, many mercurial commands would crash.

This revision fixes the problem by removing any tags from the output of
tags.readlocaltags() which point to invalid nodes.

We may want to add a warning when this happens (although it might be
annoying to get that warning for every command, possibly even more than once per
command).

A test for this problem has been added to test-obsolete.t. Without this fix the
test would output:

  $ hg tags
  abort: 00changelog.i@3816541e5485: no node!
  [255]

Instead of:

  $ hg tags
  tiptag                             2:3816541e5485
  tip                                2:3816541e5485
  visible                            0:193e9254ce7e
Angel Ezquerra - June 30, 2014, 10:56 p.m.
On Tue, Jul 1, 2014 at 12:53 AM, Angel Ezquerra
<angel.ezquerra@gmail.com> wrote:
> # HG changeset patch
> # User Angel Ezquerra <angel.ezquerra@gmail.com>
> # Date 1404042755 -7200
> #      Sun Jun 29 13:52:35 2014 +0200
> # Branch stable
> # Node ID 0f977cb11be3938e1da6c54389712f2070960917
> # Parent  a4b67bf1f0a5051736c14d9c13fae50fd5f5e464
> repoview: do not crash when localtags refers to non existing revisions
>
> This fixes a crash that may happen when using mercurial 3.0.x.
>
> The _gethiddenblockers function assumed that the output of tags.readlocaltags()
> was a dict mapping tags to of valid nodes. However this was not necessarily the
> case. When a repository had obsolete revisions and had local tag pointing to a
> non existing revision was found, many mercurial commands would crash.
>
> This revision fixes the problem by removing any tags from the output of
> tags.readlocaltags() which point to invalid nodes.
>
> We may want to add a warning when this happens (although it might be
> annoying to get that warning for every command, possibly even more than once per
> command).
>
> A test for this problem has been added to test-obsolete.t. Without this fix the
> test would output:
>
>   $ hg tags
>   abort: 00changelog.i@3816541e5485: no node!
>   [255]
>
> Instead of:
>
>   $ hg tags
>   tiptag                             2:3816541e5485
>   tip                                2:3816541e5485
>   visible                            0:193e9254ce7e

Note that this fixes an issue that happened in
repoview._gethiddenblockers(), but the fix has been done in tags.py.
Thus I don't know if the revision subject should say repoview or tags.

Cheers,

Angel
Matt Mackall - July 1, 2014, 8:45 p.m.
On Tue, 2014-07-01 at 00:53 +0200, Angel Ezquerra wrote:
> # HG changeset patch
> # User Angel Ezquerra <angel.ezquerra@gmail.com>
> # Date 1404042755 -7200
> #      Sun Jun 29 13:52:35 2014 +0200
> # Branch stable
> # Node ID 0f977cb11be3938e1da6c54389712f2070960917
> # Parent  a4b67bf1f0a5051736c14d9c13fae50fd5f5e464
> repoview: do not crash when localtags refers to non existing revisions

Queued for stable, thanks.

Patch

diff -r a4b67bf1f0a5 -r 0f977cb11be3 mercurial/tags.py
--- a/mercurial/tags.py	Wed Jun 25 14:50:48 2014 -0700
+++ b/mercurial/tags.py	Sun Jun 29 13:52:35 2014 +0200
@@ -72,6 +72,15 @@ 
     filetags = _readtags(
         ui, repo, data.splitlines(), "localtags",
         recode=encoding.fromlocal)
+
+    # remove tags pointing to invalid nodes
+    cl = repo.changelog
+    for t in filetags.keys():
+        try:
+            cl.rev(filetags[t][0])
+        except (LookupError, ValueError):
+            del filetags[t]
+
     _updatetags(filetags, "local", alltags, tagtypes)
 
 def _readtags(ui, repo, lines, fn, recode=None):
diff -r a4b67bf1f0a5 -r 0f977cb11be3 tests/test-obsolete.t
--- a/tests/test-obsolete.t	Wed Jun 25 14:50:48 2014 -0700
+++ b/tests/test-obsolete.t	Sun Jun 29 13:52:35 2014 +0200
@@ -907,3 +907,15 @@ 
      date:        Thu Jan 01 00:00:00 1970 +0000
      summary:     A
   
+Test that removing a local tag does not cause some commands to fail
+
+  $ hg tag -l -r tip tiptag
+  $ hg tags
+  tiptag                             2:3816541e5485
+  tip                                2:3816541e5485
+  visible                            0:193e9254ce7e
+  $ hg --config extensions.strip= strip -r tip --no-backup
+  0 files updated, 0 files merged, 1 files removed, 0 files unresolved
+  $ hg tags
+  visible                            0:193e9254ce7e
+  tip                                0:193e9254ce7e