Patchwork [4,of,9,V3] localrepo: use _findlocaltags in _findtags

login
register
mail settings
Submitter Sean Farley
Date March 28, 2014, 10:06 p.m.
Message ID <ee90b9a274e93bf091e9.1396044362@laptop.local>
Download mbox | patch
Permalink /patch/4112/
State Superseded
Headers show

Comments

Sean Farley - March 28, 2014, 10:06 p.m.
# HG changeset patch
# User Sean Farley <sean.michael.farley@gmail.com>
# Date 1395964989 18000
#      Thu Mar 27 19:03:09 2014 -0500
# Node ID ee90b9a274e93bf091e9c00f9bfc916eb98e2408
# Parent  ccf260976f55dd32cc8d5158d9f164c365275ee4
localrepo: use _findlocaltags in _findtags

This makes the only caller of tags.readlocaltags localrepo._findlocaltags now.
Pierre-Yves David - April 1, 2014, 3:13 a.m.
On 03/28/2014 03:06 PM, Sean Farley wrote:
> # HG changeset patch
> # User Sean Farley <sean.michael.farley@gmail.com>
> # Date 1395964989 18000
> #      Thu Mar 27 19:03:09 2014 -0500
> # Node ID ee90b9a274e93bf091e9c00f9bfc916eb98e2408
> # Parent  ccf260976f55dd32cc8d5158d9f164c365275ee4
> localrepo: use _findlocaltags in _findtags
>
> This makes the only caller of tags.readlocaltags localrepo._findlocaltags now.
>
> diff --git a/mercurial/localrepo.py b/mercurial/localrepo.py
> --- a/mercurial/localrepo.py
> +++ b/mercurial/localrepo.py
> @@ -611,13 +611,21 @@ class localrepository(object):
>
>           alltags = {}                    # map tag name to (node, hist)
>           tagtypes = {}
>
>           tagsmod.findglobaltags(self.ui, self, alltags, tagtypes)
> -        tagsmod.readlocaltags(self.ui, self, alltags, tagtypes)
> +        tags, tagtypes = self._encodetags(alltags, tagtypes)
>
> -        tags, tagtypes = self._encodetags(alltags, tagtypes)
> +        ltags, ltagtypes = self._findlocaltags()
> +        # global tags take precedence, so we only update distinct local tags
> +        ltags = dict([(name, node) for name, node in ltags.iteritems()
> +                      if name not in tags])
> +        ltagtypes = dict([(name, type) for name, type in ltagtypes.iteritems()
> +                          if name not in tagtypes])
> +        tags.update(ltags)
> +        tagtypes.update(ltagtypes)
> +

If global tags overwrite local ones. Why don't you "simply do"

   alltags, alltagtypes = self._findlocaltags()
   gtabs, gtypes = {}, {}
   tagsmod.findglobaltags(self.ui, self, gtags, gtypes)
   gtags, gtypes = self._encodetags(gtags, gtypes)
   alltags.update(gtags)
   alltagtypes.update(gtypes)

(or even better, moving the encoding part in the findglobaltags logic 
and drop the intermediate dict.


(also consider moving the logic into the tag module for humanity goods)

Patch

diff --git a/mercurial/localrepo.py b/mercurial/localrepo.py
--- a/mercurial/localrepo.py
+++ b/mercurial/localrepo.py
@@ -611,13 +611,21 @@  class localrepository(object):
 
         alltags = {}                    # map tag name to (node, hist)
         tagtypes = {}
 
         tagsmod.findglobaltags(self.ui, self, alltags, tagtypes)
-        tagsmod.readlocaltags(self.ui, self, alltags, tagtypes)
+        tags, tagtypes = self._encodetags(alltags, tagtypes)
 
-        tags, tagtypes = self._encodetags(alltags, tagtypes)
+        ltags, ltagtypes = self._findlocaltags()
+        # global tags take precedence, so we only update distinct local tags
+        ltags = dict([(name, node) for name, node in ltags.iteritems()
+                      if name not in tags])
+        ltagtypes = dict([(name, type) for name, type in ltagtypes.iteritems()
+                          if name not in tagtypes])
+        tags.update(ltags)
+        tagtypes.update(ltagtypes)
+
         tags['tip'] = self.changelog.tip()
         return (tags, tagtypes)
 
     def _findlocaltags(self):
         '''Do the hard work of finding local tags.  Return a pair of dicts