# HG changeset patch # User Alexis S. L. Carvalho # Date 1162089479 10800 # Node ID 7f7425306925d1dd35a5dcf2d59dc133b4f8a521 # Parent 00427c4b533b487a24b911013c3314ea4d104508 Correct optimization from 3464f5e77f34; add a test. If there are two (or more) heads that point to the same .hgtags node, we can safely skip parsing the file in all but the last head. (In 3464f5e77f34, we were parsing the file in the first head and skipping all the others.) diff -r 00427c4b533b -r 7f7425306925 mercurial/localrepo.py --- a/mercurial/localrepo.py Sat Oct 28 20:21:59 2006 -0300 +++ b/mercurial/localrepo.py Sat Oct 28 23:37:59 2006 -0300 @@ -244,13 +244,10 @@ # read the tags file from each head, ending with the tip, # and add each tag found to the map, with "newer" ones # taking precedence - heads = self.heads() - heads.reverse() - seen = {} - for node in heads: - f = self.filectx('.hgtags', node) - if not f or f.filerev() in seen: continue - seen[f.filerev()] = 1 + f = None + for rev, node, fnode in self._hgtagsnodes(): + f = (f and f.filectx(fnode) or + self.filectx('.hgtags', fileid=fnode)) count = 0 for l in f.data().splitlines(): count += 1 @@ -269,6 +266,24 @@ return self.tagscache + def _hgtagsnodes(self): + heads = self.heads() + heads.reverse() + last = {} + ret = [] + for node in heads: + c = self.changectx(node) + rev = c.rev() + try: + fnode = c.filenode('.hgtags') + except repo.LookupError: + continue + ret.append((rev, node, fnode)) + if fnode in last: + ret[last[fnode]] = None + last[fnode] = len(ret) - 1 + return [item for item in ret if item] + def tagslist(self): '''return a list of tags ordered by revision''' l = [] diff -r 00427c4b533b -r 7f7425306925 tests/test-tags --- a/tests/test-tags Sat Oct 28 20:21:59 2006 -0300 +++ b/tests/test-tags Sat Oct 28 23:37:59 2006 -0300 @@ -60,3 +60,19 @@ hg tags hg tip +# tags from later heads override previous ones +cd .. +hg init t2 +cd t2 +echo foo > foo +hg add foo +hg ci -m 'add foo' -d '1000000 0' # rev 0 +hg tag -d '1000000 0' bar # rev 1 +echo >> foo +hg ci -m 'change foo 1' -d '1000000 0' # rev 2 +hg up -C 1 +hg tag -r 1 -d '1000000 0' bar # rev 3 +hg up -C 1 +echo >> foo +hg ci -m 'change foo 2' -d '1000000 0' # rev 4 +hg tags diff -r 00427c4b533b -r 7f7425306925 tests/test-tags.out --- a/tests/test-tags.out Sat Oct 28 20:21:59 2006 -0300 +++ b/tests/test-tags.out Sat Oct 28 23:37:59 2006 -0300 @@ -36,3 +36,7 @@ date: Mon Jan 12 13:46:40 1970 +0000 summary: head +1 files updated, 0 files merged, 0 files removed, 0 files unresolved +1 files updated, 0 files merged, 0 files removed, 0 files unresolved +tip 4:36195b728445 +bar 0:b409d9da318e