Mercurial > hg
changeset 31710:510267cf6c58
tags: extract tags computation from fnodes into its own function
I'm about to introduce code that needs to perform such computation on
"arbitrary" nodes. The logic is extracted into its own function for reuse.
author | Pierre-Yves David <pierre-yves.david@ens-lyon.org> |
---|---|
date | Tue, 28 Mar 2017 06:08:12 +0200 |
parents | c34c170b25f3 |
children | 472d726c1afd |
files | mercurial/tags.py |
diffstat | 1 files changed, 21 insertions(+), 9 deletions(-) [+] |
line wrap: on
line diff
--- a/mercurial/tags.py Tue Mar 28 07:41:23 2017 +0200 +++ b/mercurial/tags.py Tue Mar 28 06:08:12 2017 +0200 @@ -85,19 +85,18 @@ The tags cache is read and updated as a side-effect of calling. ''' - alltags = {} - (heads, tagfnode, valid, cachetags, shouldwrite) = _readtagcache(ui, repo) if cachetags is not None: assert not shouldwrite # XXX is this really 100% correct? are there oddball special # cases where a global tag should outrank a local tag but won't, # because cachetags does not contain rank info? + alltags = {} _updatetags(cachetags, alltags) return alltags seen = set() # set of fnode - fctx = None + fnodes = [] for head in reversed(heads): # oldest to newest assert head in repo.changelog.nodemap, \ "tag cache returned bogus head %s" % short(head) @@ -105,19 +104,32 @@ fnode = tagfnode.get(head) if fnode and fnode not in seen: seen.add(fnode) - if not fctx: - fctx = repo.filectx('.hgtags', fileid=fnode) - else: - fctx = fctx.filectx(fnode) + fnodes.append(fnode) - filetags = _readtags(ui, repo, fctx.data().splitlines(), fctx) - _updatetags(filetags, alltags) + alltags = _tagsfromfnodes(ui, repo, fnodes) # and update the cache (if necessary) if shouldwrite: _writetagcache(ui, repo, valid, alltags) return alltags +def _tagsfromfnodes(ui, repo, fnodes): + """return a tagsmap from a list of file-node + + tagsmap: tag name to (node, hist) 2-tuples. + + The order of the list matters.""" + alltags = {} + fctx = None + for fnode in fnodes: + if fctx is None: + fctx = repo.filectx('.hgtags', fileid=fnode) + else: + fctx = fctx.filectx(fnode) + filetags = _readtags(ui, repo, fctx.data().splitlines(), fctx) + _updatetags(filetags, alltags) + return alltags + def readlocaltags(ui, repo, alltags, tagtypes): '''Read local tags in repo. Update alltags and tagtypes.''' try: