Patchwork [2,of,2,topic-ext] init: guard _namemap with repo.topics (issue5351)

login
register
mail settings
Submitter timeless
Date Aug. 26, 2016, 4:59 p.m.
Message ID <942a3b3b41b6179e3723.1472230779@gcc2-power8.osuosl.org>
Download mbox | patch
Permalink /patch/16454/
State Accepted
Headers show

Comments

timeless - Aug. 26, 2016, 4:59 p.m.
# HG changeset patch
# User timeless@gmail.com
# Date 1472230665 0
#      Fri Aug 26 16:57:45 2016 +0000
# Node ID 942a3b3b41b6179e3723a0b048ee2494d8252a7d
# Parent  81def069bd64c516610e507279070cef5ca72d7f
init: guard _namemap with repo.topics (issue5351)

This prevents reading extra data on all repo commits
when there is no topic for a given name.

_namemap is called a lot, and it is often called for commit
shas -- which should pretty much never be names of topics...
Pierre-Yves David - Aug. 26, 2016, 9:24 p.m.
On 08/26/2016 06:59 PM, timeless wrote:
> # HG changeset patch
> # User timeless@gmail.com
> # Date 1472230665 0
> #      Fri Aug 26 16:57:45 2016 +0000
> # Node ID 942a3b3b41b6179e3723a0b048ee2494d8252a7d
> # Parent  81def069bd64c516610e507279070cef5ca72d7f
> init: guard _namemap with repo.topics (issue5351)
>
> This prevents reading extra data on all repo commits
> when there is no topic for a given name.
>
> _namemap is called a lot, and it is often called for commit
> shas -- which should pretty much never be names of topics...
>
> diff -r 81def069bd64 -r 942a3b3b41b6 hgext3rd/topic/__init__.py
> --- a/hgext3rd/topic/__init__.py	Fri Aug 26 16:52:02 2016 +0000
> +++ b/hgext3rd/topic/__init__.py	Fri Aug 26 16:57:45 2016 +0000
> @@ -79,6 +79,8 @@
>              msg = _('cannot resolve "%s": topic "%s" has only %d changesets')
>              raise error.Abort(msg % (name, topic, len(revs)))
>          return [repo[r].node()]
> +    if not name in repo.topics:
> +        return []

Note that we'll probably will want a version of that list as a set to 
speed up lookup. We can probably have the cache as a set and sort it 
when actually needed.

Patch

diff -r 81def069bd64 -r 942a3b3b41b6 hgext3rd/topic/__init__.py
--- a/hgext3rd/topic/__init__.py	Fri Aug 26 16:52:02 2016 +0000
+++ b/hgext3rd/topic/__init__.py	Fri Aug 26 16:57:45 2016 +0000
@@ -79,6 +79,8 @@ 
             msg = _('cannot resolve "%s": topic "%s" has only %d changesets')
             raise error.Abort(msg % (name, topic, len(revs)))
         return [repo[r].node()]
+    if not name in repo.topics:
+        return []
     return [ctx.node() for ctx in
             repo.set('not public() and extra(topic, %s)', name)]