[PATCH 5 of 8] localrepo: change readtags() from a closure in _findtags() to a method

Greg Ward greg-hg at gerg.ca
Sun Jul 12 20:02:08 CDT 2009


# HG changeset patch
# User Greg Ward <greg-hg at gerg.ca>
# Date 1247446898 14400
# Node ID 42204dd5d8ac9b16652582c22ecf17f267d9c076
# Parent  aea158ba8575f6b1276398eb62ca0f1dec63a508
localrepo: change readtags() from a closure in _findtags() to a method.

diff --git a/mercurial/localrepo.py b/mercurial/localrepo.py
--- a/mercurial/localrepo.py
+++ b/mercurial/localrepo.py
@@ -258,46 +258,6 @@
         # be one tagtype for all such "virtual" tags?  Or is the status
         # quo fine?
 
-        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 latest 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.'''
-
-            filetags = {}               # map tag name to (node, hist)
-            count = 0
-
-            def warn(msg):
-                self.ui.warn(_("%s, line %s: %s\n") % (fn, count, msg))
-
-            for line in lines:
-                count += 1
-                if not line:
-                    continue
-                try:
-                    (nodehex, name) = line.split(" ", 1)
-                except ValueError:
-                    warn(_("cannot parse entry"))
-                    continue
-                name = encoding.tolocal(name.strip()) # stored in UTF-8
-                try:
-                    nodebin = bin(nodehex)
-                except TypeError:
-                    warn(_("node '%s' is not well formed") % nodehex)
-                    continue
-                if nodebin not in self.changelog.nodemap:
-                    # silently ignore as pull -r might cause this
-                    continue
-
-                # 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 = {}
 
@@ -343,14 +303,14 @@
 
         # read the tags file from each head, ending with the tip
         for fctx in reversed(ctxs):
-            filetags = readtags(fctx.data().splitlines(), fctx)
+            filetags = self._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
-            filetags = readtags(data.splitlines(), "localtags")
+            filetags = self._readtags(data.splitlines(), "localtags")
             updatetags(filetags, "local")
         except IOError:
             pass
@@ -362,6 +322,46 @@
         tags['tip'] = self.changelog.tip()
         return (tags, tagtypes)
 
+    def _readtags(self, 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 latest 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.'''
+
+        filetags = {}               # map tag name to (node, hist)
+        count = 0
+
+        def warn(msg):
+            self.ui.warn(_("%s, line %s: %s\n") % (fn, count, msg))
+
+        for line in lines:
+            count += 1
+            if not line:
+                continue
+            try:
+                (nodehex, name) = line.split(" ", 1)
+            except ValueError:
+                warn(_("cannot parse entry"))
+                continue
+            name = encoding.tolocal(name.strip()) # stored in UTF-8
+            try:
+                nodebin = bin(nodehex)
+            except TypeError:
+                warn(_("node '%s' is not well formed") % nodehex)
+                continue
+            if nodebin not in self.changelog.nodemap:
+                # silently ignore as pull -r might cause this
+                continue
+
+            # update filetags
+            hist = []
+            if name in filetags:
+                n, hist = filetags[name]
+                hist.append(n)
+            filetags[name] = (nodebin, hist)
+        return filetags
+
     def tagtype(self, tagname):
         '''
         return the type of the given tag. result can be:


More information about the Mercurial-devel mailing list