# HG changeset patch # User Pierre-Yves David # Date 1490673691 -7200 # Node ID 5eb4d206202bc3c440775b3d3524fd6b80e455be # Parent cbe0bea82c790140c70652b7e93487af6305890a 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. diff -r cbe0bea82c79 -r 5eb4d206202b mercurial/tags.py --- 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)