[PATCH STABLE] repoview: do not crash when localtags refers to non existing or hidden revisions

Angel Ezquerra angel.ezquerra at gmail.com
Mon Jun 30 12:19:03 CDT 2014


# HG changeset patch
# User Angel Ezquerra <angel.ezquerra at gmail.com>
# Date 1404042755 -7200
#      Sun Jun 29 13:52:35 2014 +0200
# Branch stable
# Node ID 5d8dbdb8b15c5f33f1acd8281e695af003013637
# Parent  a4b67bf1f0a5051736c14d9c13fae50fd5f5e464
repoview: do not crash when localtags refers to non existing or hidden revisions

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

The _gethiddenblockers function assumed that the output of readlocaltags was a
dict mapping tags to of valid nodes. However this is not necessarily the case.
When a local tag pointing to a non existing or no reachable hidden revision was
found, many mercurial commands would crash.

There are two possible solutions:

1. Make sure that tags.readlocaltags() always returns a dict mapping tags to
valid nodes
2. Check the output of readlocaltags() where it is used

This revision does #2 although #1 is probably more correct. I did not do #1
because I am unsure of the performance implications of #1.

tags.readlocaltags() is only used twice: where I made this fix and in
localrepo._findtags(). The latter is called whenever the localrepo.tags()
method is called with a filtered changelog.

If #1 is fine from a performance point of view I could send a new patch that
implemented it.

We may also 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).

diff -r a4b67bf1f0a5 -r 5d8dbdb8b15c mercurial/repoview.py
--- a/mercurial/repoview.py	Wed Jun 25 14:50:48 2014 -0700
+++ b/mercurial/repoview.py	Sun Jun 29 13:52:35 2014 +0200
@@ -41,7 +41,14 @@
         tags = {}
         tagsmod.readlocaltags(repo.ui, repo, tags, {})
         if tags:
-            blockers.extend(cl.rev(t[0]) for t in tags.values())
+            validtagrevs = []
+            for t in tags.values():
+                try:
+                    validtagrevs.append(cl.rev(t[0]))
+                except LookupError:
+                    # Ignore invalid tags
+                    pass
+            blockers.extend(validtagrevs)
     return blockers
 
 def computehidden(repo):


More information about the Mercurial-devel mailing list