tags: extract filenode filtering into its own function
authorPierre-Yves David <pierre-yves.david@ens-lyon.org>
Tue, 28 Mar 2017 06:23:28 +0200
changeset 31716 472d726c1afd
parent 31715 510267cf6c58
child 31717 b3640334a43a
tags: extract filenode filtering into its own function We'll also need to reuse this logic so we extract it into its own function. We document some of the logic in the process.
mercurial/tags.py
--- a/mercurial/tags.py	Tue Mar 28 06:08:12 2017 +0200
+++ b/mercurial/tags.py	Tue Mar 28 06:23:28 2017 +0200
@@ -95,17 +95,10 @@
         _updatetags(cachetags, alltags)
         return alltags
 
-    seen = set()  # set of fnode
-    fnodes = []
     for head in reversed(heads):  # oldest to newest
         assert head in repo.changelog.nodemap, \
                "tag cache returned bogus head %s" % short(head)
-
-        fnode = tagfnode.get(head)
-        if fnode and fnode not in seen:
-            seen.add(fnode)
-            fnodes.append(fnode)
-
+    fnodes = _filterfnodes(tagfnode, reversed(heads))
     alltags = _tagsfromfnodes(ui, repo, fnodes)
 
     # and update the cache (if necessary)
@@ -113,6 +106,21 @@
         _writetagcache(ui, repo, valid, alltags)
     return alltags
 
+def _filterfnodes(tagfnode, nodes):
+    """return a list of unique fnodes
+
+    The order of this list matches the order of "nodes". Preserving this order
+    is important as reading tags in different order provides different
+    results."""
+    seen = set()  # set of fnode
+    fnodes = []
+    for no in nodes:  # oldest to newest
+        fnode = tagfnode.get(no)
+        if fnode and fnode not in seen:
+            seen.add(fnode)
+            fnodes.append(fnode)
+    return fnodes
+
 def _tagsfromfnodes(ui, repo, fnodes):
     """return a tagsmap from a list of file-node