[PATCH] Implement persistent tag caching

Matt Mackall mpm at selenic.com
Tue May 12 10:05:57 CDT 2009


On Tue, May 12, 2009 at 09:53:09AM -0400, Greg Ward wrote:
> # HG changeset patch
> # User Greg Ward <greg-hg at gerg.ca>
> # Date 1242136298 0
> # Node ID dfa1e342c02d5ec5171865d9e64462836585fa8a
> # Parent  1f0f01bc86a505ce227d6778af38bc67cff7e85e
> Implement persistent tag caching.
> 
> The implementation is fairly straightforward: after iterating over
> heads, save the global tags in .hg/tags.cache.  Do not cache local
> tags or 'tip', because they are much cheaper to read and would greatly
> complicate cache invalidation.  Discard the cache on every commit that
> touches .hgtags.
> 
> This is a rough draft, posted for review and feedback rather than for
> immediate push to crew.  Known flaws:
>   - only invalidates the cache on commit (i.e. does nothing about
>     pulled/pushed changes to .hgtags)
>   - the tag cache is a pickle, which seems un-Mercurial to me
>   - makes localrepository, a large and complex class, even more
>     large and complex
>   - invalidating the entire cache every time someone runs "hg tag x"
>     is a bit harsh: is it worth a special case to update the
>     cache in that case?
>   - lots of debug output

As much as we all love Python, you're not allowed to use pickle as a
format.

To determine whether tags have appeared, we need to know if the
revisions of the repository heads have changed and if their
corresponding .hgtags have changed. Most of the time spent finding
tags is spent opening the manifest to look this data up.

This suggests the following layout for tags:

<head 1 hash> <head 1 rev> <.hgtags hash>
<head 2 hash> <head 2 rev> <.hgtags hash>
...
[blank line]
<tag 1 hash> <tag 1 name>
<tag 2 hash> <tag 2 name>
...

This lets us (a) quickly check whether the tags are valid and (b)
quickly find all the relevant .hgtags revisions without visiting the
manifest.

The following validity test should work:

- if first head == current tip, we're done
- find heads
- check that all heads match in order
- if the tip doesn't match, but it has the same .hgtags as the cached
  tip, all is still good

-- 
Mathematics is the supreme nostalgia of our time.


More information about the Mercurial-devel mailing list