Patchwork [7,of,7,V2] tags: extract filenode filtering into its own function

login
register
mail settings
Submitter Pierre-Yves David
Date March 28, 2017, 12:03 p.m.
Message ID <b493530ef220110a608c.1490702630@nodosa.octopoid.net>
Download mbox | patch
Permalink /patch/19784/
State Accepted
Headers show

Comments

Pierre-Yves David - March 28, 2017, 12:03 p.m.
# HG changeset patch
# User Pierre-Yves David <pierre-yves.david@ens-lyon.org>
# Date 1490675008 -7200
#      Tue Mar 28 06:23:28 2017 +0200
# Node ID b493530ef220110a608c69145c82dff8c72f1950
# Parent  c2abcd1197667b2e603169352ad9f620bdbe7333
# EXP-Topic tags
# Available At https://www.mercurial-scm.org/repo/users/marmoute/mercurial/
#              hg pull https://www.mercurial-scm.org/repo/users/marmoute/mercurial/ -r b493530ef220
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.

Patch

diff --git a/mercurial/tags.py b/mercurial/tags.py
--- a/mercurial/tags.py
+++ b/mercurial/tags.py
@@ -95,17 +95,10 @@  def findglobaltags(ui, repo):
         _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 @@  def findglobaltags(ui, repo):
         _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