[PATCH 3 of 3] tags: establish a list of (rev, node) for heads

Gregory Szorc gregory.szorc at gmail.com
Tue Apr 14 18:19:46 UTC 2015


# HG changeset patch
# User Gregory Szorc <gregory.szorc at gmail.com>
# Date 1429035402 14400
#      Tue Apr 14 14:16:42 2015 -0400
# Node ID b752d7abbd7ec2c210ca5d36e8f0ef2f1b7d644f
# Parent  3ff6f1a639e2633af1ee8be2c354ebd2fb023bf2
tags: establish a list of (rev, node) for heads

A future patch will introduce a function that needs to be fed both the
numeric revision and binary node for each head. Refactor the code to
establish this variable.

diff --git a/mercurial/tags.py b/mercurial/tags.py
--- a/mercurial/tags.py
+++ b/mercurial/tags.py
@@ -289,12 +289,18 @@ def _readtagcache(ui, repo):
         return (None, None, tags, False)
     if cachefile:
         cachefile.close()               # ignore rest of file
 
-    repoheads = repo.heads()
+    heads = []
+    headnodes = []
+    for rev in sorted(repo.changelog.headrevs(), reverse=True):
+        node = repo[rev].node()
+        heads.append((rev, node))
+        headnodes.append(node)
+
     # Case 2 (uncommon): empty repo; get out quickly and don't bother
     # writing an empty cache.
-    if repoheads == [nullid]:
+    if headnodes == [nullid]:
         return ([], {}, {}, False)
 
     # Case 3 (uncommon): cache file missing or empty.
 
@@ -311,14 +317,14 @@ def _readtagcache(ui, repo):
     # exposed".
     if not len(repo.file('.hgtags')):
         # No tags have ever been committed, so we can avoid a
         # potentially expensive search.
-        return (repoheads, cachefnode, None, True)
+        return (headnodes, cachefnode, None, True)
 
     starttime = time.time()
 
     newheads = [head
-                for head in repoheads
+                for head in headnodes
                 if head not in set(cacheheads)]
 
     # Now we have to lookup the .hgtags filenode for every new head.
     # This is the most expensive part of finding tags, so performance
@@ -340,9 +346,9 @@ def _readtagcache(ui, repo):
            len(cachefnode), len(newheads), duration)
 
     # Caller has to iterate over all heads, but can use the filenodes in
     # cachefnode to get to each .hgtags revision quickly.
-    return (repoheads, cachefnode, None, True)
+    return (headnodes, cachefnode, None, True)
 
 def _writetagcache(ui, repo, heads, tagfnode, cachetags):
     try:
         cachefile = repo.vfs('cache/tags', 'w', atomictemp=True)



More information about the Mercurial-devel mailing list