[PATCH 1 of 1] Use tag dict code from tags.py

Dirkjan Ochtman dirkjan at ochtman.nl
Wed Jun 9 02:03:33 CDT 2010


On Wed, Jun 9, 2010 at 00:28, Friedrich Kastner-Masilko <face at snoopie.at> wrote:
> # HG changeset patch
> # User Friedrich Kastner-Masilko <face at snoopie.at>
> # Date 1276032532 -7200
> # Node ID acd47daa8805b47f8c5fee082aa3d7920addac0e
> # Parent  0e5ce2325795325e41f6df9203373d2858e88f88
> Use tag dict code from tags.py.

Nit: please fix this line to have a "bookmarks:" prefix. I'd also
change the rest of the message, since the method you're using here
doesn't really have anything to do with tags.py (that it's used there
would be more useful for the rest of the message).

> Instead of using lookup(), the same method as in tags.py is used to get the nodes hash.
> This speeds up operations with big bookmark tables. Although I have not scientifically
> benchmarked it, --time shows a increase of 2x execution speed for e.g. log with approx.
> 100 bookmarks.
>
> diff --git a/hgext/bookmarks.py b/hgext/bookmarks.py
> --- a/hgext/bookmarks.py
> +++ b/hgext/bookmarks.py
> @@ -29,7 +29,7 @@
>  '''
>
>  from mercurial.i18n import _
> -from mercurial.node import nullid, nullrev, hex, short
> +from mercurial.node import nullid, nullrev, hex, short, bin
>  from mercurial import util, commands, repair, extensions
>  import os
>
> @@ -218,7 +218,9 @@
>                 bookmarks = {}
>                 for line in self.opener('bookmarks'):
>                     sha, refspec = line.strip().split(' ', 1)
> -                    bookmarks[refspec] = super(bookmark_repo, self).lookup(sha)
> +                    nodebin = bin(sha)
> +                    if nodebin in self.changelog.nodemap:
> +                        bookmarks[refspec] = nodebin
>             except:
>                 pass
>             return bookmarks

Ah, nice. Do we have a guarantee that the file doesn't have some other
revision specifier (like a rev or a tag or something else)? As you
might be aware, 'lookup' allows a much wider range of input.

If it needs the wider range, maybe this can be done by testing for
len(sha.strip()) == 40, but I'm not sure how that would affect
performance.

Cheers,

Dirkjan


More information about the Mercurial-devel mailing list