changeset 31705:5eb4d206202b

tags: extract fnode retrieval into its own function My main goal here is to be able to reuse this logic easily. As a side effect this important logic is now insulated and the code is clearer.
author Pierre-Yves David <pierre-yves.david@ens-lyon.org>
date Tue, 28 Mar 2017 06:01:31 +0200
parents cbe0bea82c79
children 63d4deda1b31
files mercurial/tags.py
diffstat 1 files changed, 15 insertions(+), 6 deletions(-) [+]
line wrap: on
line diff
--- a/mercurial/tags.py	Wed Mar 29 12:07:07 2017 +0200
+++ b/mercurial/tags.py	Tue Mar 28 06:01:31 2017 +0200
@@ -341,15 +341,27 @@
         # potentially expensive search.
         return ([], {}, valid, None, True)
 
-    starttime = util.timer()
 
     # Now we have to lookup the .hgtags filenode for every new head.
     # This is the most expensive part of finding tags, so performance
     # depends primarily on the size of newheads.  Worst case: no cache
     # file, so newheads == repoheads.
+    cachefnode = _getfnodes(ui, repo, repoheads)
+
+    # Caller has to iterate over all heads, but can use the filenodes in
+    # cachefnode to get to each .hgtags revision quickly.
+    return (repoheads, cachefnode, valid, None, True)
+
+def _getfnodes(ui, repo, nodes):
+    """return .hgtags fnodes for a list of changeset nodes
+
+    Return value is a {node: fnode} mapping. There will be no entry for nodes
+    without a '.hgtags' file.
+    """
+    starttime = util.timer()
     fnodescache = hgtagsfnodescache(repo.unfiltered())
     cachefnode = {}
-    for head in reversed(repoheads):
+    for head in reversed(nodes):
         fnode = fnodescache.getfnode(head)
         if fnode != nullid:
             cachefnode[head] = fnode
@@ -361,10 +373,7 @@
            '%d/%d cache hits/lookups in %0.4f '
            'seconds\n',
            fnodescache.hitcount, fnodescache.lookupcount, 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, valid, None, True)
+    return cachefnode
 
 def _writetagcache(ui, repo, valid, cachetags):
     filename = _filename(repo)