Submitter | Sean Farley |
---|---|
Date | March 28, 2014, 5:53 p.m. |
Message ID | <f51c9fb7d5e024e9c200.1396029195@laptop.local> |
Download | mbox | patch |
Permalink | /patch/4101/ |
State | Superseded |
Headers | show |
Comments
Sean Farley <sean.michael.farley@gmail.com> writes: > # HG changeset patch > # User Sean Farley <sean.michael.farley@gmail.com> > # Date 1395964833 18000 > # Thu Mar 27 19:00:33 2014 -0500 > # Node ID f51c9fb7d5e024e9c200787f06bb7409d7ce785c > # Parent dfad9bb23ab49bd461544c1d5fab3318ab637d23 > localrepo: add _findlocaltags method > > This method will be used in future patches to allow access to only getting the > local tags. This will allow us to improve performance to avoid the cost of > building the tag cache for large repos with many heads. > > diff --git a/mercurial/localrepo.py b/mercurial/localrepo.py > --- a/mercurial/localrepo.py > +++ b/mercurial/localrepo.py > @@ -603,15 +603,39 @@ class localrepository(object): > > # Build the return dicts. Have to re-encode tag names because > # the tags module always uses UTF-8 (in order not to lose info > # writing to the cache), but the rest of Mercurial wants them in > # local encoding. > + for (name, (node, hist)) in alltags.iteritems(): > + if node != nullid: > + tags[encoding.tolocal(name)] = node > + tags['tip'] = self.changelog.tip() > + tagtypes = dict([(encoding.tolocal(name), value) > + for (name, value) in tagtypes.iteritems()]) > + I suggest encapsulating this into a function as we use it at least twice and should avoid the copying, so that this part becomes tags, tagtypes = _maptags(alltags) tags['tip'] = self.cahngelog.tip() return tags,tagtypes
David Soria Parra <davidsp@fb.com> writes: > Sean Farley <sean.michael.farley@gmail.com> writes: > >> # HG changeset patch >> # User Sean Farley <sean.michael.farley@gmail.com> >> # Date 1395964833 18000 >> # Thu Mar 27 19:00:33 2014 -0500 >> # Node ID f51c9fb7d5e024e9c200787f06bb7409d7ce785c >> # Parent dfad9bb23ab49bd461544c1d5fab3318ab637d23 >> localrepo: add _findlocaltags method >> >> This method will be used in future patches to allow access to only getting the >> local tags. This will allow us to improve performance to avoid the cost of >> building the tag cache for large repos with many heads. >> >> diff --git a/mercurial/localrepo.py b/mercurial/localrepo.py >> --- a/mercurial/localrepo.py >> +++ b/mercurial/localrepo.py >> @@ -603,15 +603,39 @@ class localrepository(object): >> >> # Build the return dicts. Have to re-encode tag names because >> # the tags module always uses UTF-8 (in order not to lose info >> # writing to the cache), but the rest of Mercurial wants them in >> # local encoding. >> + for (name, (node, hist)) in alltags.iteritems(): >> + if node != nullid: >> + tags[encoding.tolocal(name)] = node >> + tags['tip'] = self.changelog.tip() >> + tagtypes = dict([(encoding.tolocal(name), value) >> + for (name, value) in tagtypes.iteritems()]) >> + > > I suggest encapsulating this into a function as we use it at least twice > and should avoid the copying, so that this part becomes > > tags, tagtypes = _maptags(alltags) > tags['tip'] = self.cahngelog.tip() > return tags,tagtypes Fair enough.
Patch
diff --git a/mercurial/localrepo.py b/mercurial/localrepo.py --- a/mercurial/localrepo.py +++ b/mercurial/localrepo.py @@ -603,15 +603,39 @@ class localrepository(object): # Build the return dicts. Have to re-encode tag names because # the tags module always uses UTF-8 (in order not to lose info # writing to the cache), but the rest of Mercurial wants them in # local encoding. + for (name, (node, hist)) in alltags.iteritems(): + if node != nullid: + tags[encoding.tolocal(name)] = node + tags['tip'] = self.changelog.tip() + tagtypes = dict([(encoding.tolocal(name), value) + for (name, value) in tagtypes.iteritems()]) + + return (tags, tagtypes) + + def _findlocaltags(self): + '''Do the hard work of finding local tags. Return a pair of dicts + (tags, tagtypes) where tags maps local tag name to node, and tagtypes + maps tag name to \'local\'. + Subclasses or extensions are free to add their own tags, but + should be aware that the returned dicts will be retained for the + duration of the localrepo object.''' + alltags = {} + tagtypes = {} + + tagsmod.readlocaltags(self.ui, self, alltags, tagtypes) + + # Build the return dicts. Have to re-encode tag names because + # the tags module always uses UTF-8 (in order not to lose info + # writing to the cache), but the rest of Mercurial wants them in + # local encoding. tags = {} for (name, (node, hist)) in alltags.iteritems(): if node != nullid: tags[encoding.tolocal(name)] = node - tags['tip'] = self.changelog.tip() tagtypes = dict([(encoding.tolocal(name), value) for (name, value) in tagtypes.iteritems()]) return (tags, tagtypes) def tagtype(self, tagname):