[PATCH 06 of 10] localrepo: factor updatetags() out of readtags() (issue548)

Greg Ward greg-hg at gerg.ca
Thu Jul 16 09:42:52 CDT 2009


# HG changeset patch
# User Greg Ward <greg-hg at gerg.ca>
# Date 1247755181 14400
# Node ID 4630649ba193485101b629c0f4b0997d63ab101c
# Parent  36a2adea4f05dbb2726a074d5ce716fcdedf7c71
localrepo: factor updatetags() out of readtags() (issue548).

diff --git a/mercurial/localrepo.py b/mercurial/localrepo.py
--- a/mercurial/localrepo.py
+++ b/mercurial/localrepo.py
@@ -258,10 +258,13 @@
         # be one tagtype for all such "virtual" tags?  Or is the status
         # quo fine?
 
-        alltags = {}                    # map tag name to (node, hist)
-        tagtypes = {}
+        def readtags(lines, fn):
+            '''Read tag definitions from a file (or any source of
+            lines).  Return a mapping from tag name to (node, hist):
+            node is the node id from the last line read for that name,
+            and hist is the list of node ids previously associated with
+            it (in file order).  All node ids are binary, not hex.'''
 
-        def readtags(lines, fn, tagtype):
             filetags = {}               # map tag name to (node, hist)
             count = 0
 
@@ -287,15 +290,21 @@
                     # silently ignore as pull -r might cause this
                     continue
 
-                # update filetags: map tag name to (node, hist) where
-                # node is the node from the latest line read with
-                # 'name', and hist is the list of nodes previously
-                # associated with 'name'
+                # update filetags
                 hist = []
                 if name in filetags:
                     n, hist = filetags[name]
                     hist.append(n)
                 filetags[name] = (nodebin, hist)
+            return filetags
+
+        alltags = {}                    # map tag name to (node, hist)
+        tagtypes = {}
+
+        def updatetags(filetags, tagtype):
+            '''Incorporate the tag info read from one file into the two
+            dictionaries, alltags and tagtypes, that contain all tag
+            info (global across all heads plus local).'''
 
             for name, nodehist in filetags.iteritems():
                 if name not in alltags:
@@ -334,13 +343,15 @@
 
         # read the tags file from each head, ending with the tip
         for fctx in reversed(ctxs):
-            readtags(fctx.data().splitlines(), fctx, "global")
+            filetags = readtags(fctx.data().splitlines(), fctx)
+            updatetags(filetags, "global")
 
         try:
             data = encoding.fromlocal(self.opener("localtags").read())
             # localtags are stored in the local character set
             # while the internal tag table is stored in UTF-8
-            readtags(data.splitlines(), "localtags", "local")
+            filetags = readtags(data.splitlines(), "localtags")
+            updatetags(filetags, "local")
         except IOError:
             pass
 


More information about the Mercurial-devel mailing list