Mercurial > hg > mercurial-source
annotate mercurial/tags.py @ 32447:7d0459706716
tags: move '_tags' from 'repo' to 'tags' module
As far as I understand, that function do not needs to be on the local repository
class, so we extract it in the 'tags' module were it will be nice and
comfortable. We keep the '_' in the name since its only user will follow in the
next changeset.
author | Pierre-Yves David <pierre-yves.david@ens-lyon.org> |
---|---|
date | Mon, 27 Mar 2017 15:55:07 +0200 (2017-03-27) |
parents | 37acdf027ae2 |
children | a719f3315366 |
rev | line source |
---|---|
9157
abb7d4d43a5f
Factor tags module out of localrepo (issue548).
Greg Ward <greg-hg@gerg.ca>
parents:
diff
changeset
|
1 # tags.py - read tag info from local repository |
abb7d4d43a5f
Factor tags module out of localrepo (issue548).
Greg Ward <greg-hg@gerg.ca>
parents:
diff
changeset
|
2 # |
abb7d4d43a5f
Factor tags module out of localrepo (issue548).
Greg Ward <greg-hg@gerg.ca>
parents:
diff
changeset
|
3 # Copyright 2009 Matt Mackall <mpm@selenic.com> |
abb7d4d43a5f
Factor tags module out of localrepo (issue548).
Greg Ward <greg-hg@gerg.ca>
parents:
diff
changeset
|
4 # Copyright 2009 Greg Ward <greg@gerg.ca> |
abb7d4d43a5f
Factor tags module out of localrepo (issue548).
Greg Ward <greg-hg@gerg.ca>
parents:
diff
changeset
|
5 # |
abb7d4d43a5f
Factor tags module out of localrepo (issue548).
Greg Ward <greg-hg@gerg.ca>
parents:
diff
changeset
|
6 # This software may be used and distributed according to the terms of the |
10263 | 7 # GNU General Public License version 2 or any later version. |
9157
abb7d4d43a5f
Factor tags module out of localrepo (issue548).
Greg Ward <greg-hg@gerg.ca>
parents:
diff
changeset
|
8 |
9159
f528d1a93491
tags: implement persistent tag caching (issue548).
Greg Ward <greg-hg@gerg.ca>
parents:
9157
diff
changeset
|
9 # Currently this module only deals with reading and caching tags. |
f528d1a93491
tags: implement persistent tag caching (issue548).
Greg Ward <greg-hg@gerg.ca>
parents:
9157
diff
changeset
|
10 # Eventually, it could take care of updating (adding/removing/moving) |
f528d1a93491
tags: implement persistent tag caching (issue548).
Greg Ward <greg-hg@gerg.ca>
parents:
9157
diff
changeset
|
11 # tags too. |
9157
abb7d4d43a5f
Factor tags module out of localrepo (issue548).
Greg Ward <greg-hg@gerg.ca>
parents:
diff
changeset
|
12 |
26566
b2f3f185e458
tags: use absolute_import
Gregory Szorc <gregory.szorc@gmail.com>
parents:
26214
diff
changeset
|
13 from __future__ import absolute_import |
b2f3f185e458
tags: use absolute_import
Gregory Szorc <gregory.szorc@gmail.com>
parents:
26214
diff
changeset
|
14 |
14038
0e6f622f31ca
tags: loosen IOError filtering when reading localtags
Idan Kamara <idankk86@gmail.com>
parents:
14020
diff
changeset
|
15 import errno |
9157
abb7d4d43a5f
Factor tags module out of localrepo (issue548).
Greg Ward <greg-hg@gerg.ca>
parents:
diff
changeset
|
16 |
26566
b2f3f185e458
tags: use absolute_import
Gregory Szorc <gregory.szorc@gmail.com>
parents:
26214
diff
changeset
|
17 from .node import ( |
b2f3f185e458
tags: use absolute_import
Gregory Szorc <gregory.szorc@gmail.com>
parents:
26214
diff
changeset
|
18 bin, |
b2f3f185e458
tags: use absolute_import
Gregory Szorc <gregory.szorc@gmail.com>
parents:
26214
diff
changeset
|
19 hex, |
b2f3f185e458
tags: use absolute_import
Gregory Szorc <gregory.szorc@gmail.com>
parents:
26214
diff
changeset
|
20 nullid, |
b2f3f185e458
tags: use absolute_import
Gregory Szorc <gregory.szorc@gmail.com>
parents:
26214
diff
changeset
|
21 short, |
b2f3f185e458
tags: use absolute_import
Gregory Szorc <gregory.szorc@gmail.com>
parents:
26214
diff
changeset
|
22 ) |
32447
7d0459706716
tags: move '_tags' from 'repo' to 'tags' module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
32139
diff
changeset
|
23 from .i18n import _ |
26566
b2f3f185e458
tags: use absolute_import
Gregory Szorc <gregory.szorc@gmail.com>
parents:
26214
diff
changeset
|
24 from . import ( |
b2f3f185e458
tags: use absolute_import
Gregory Szorc <gregory.szorc@gmail.com>
parents:
26214
diff
changeset
|
25 encoding, |
b2f3f185e458
tags: use absolute_import
Gregory Szorc <gregory.szorc@gmail.com>
parents:
26214
diff
changeset
|
26 error, |
32447
7d0459706716
tags: move '_tags' from 'repo' to 'tags' module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
32139
diff
changeset
|
27 match as matchmod, |
31804
6cf2857526c7
scmutil: proxy revrange() through repo to break import cycles
Yuya Nishihara <yuya@tcha.org>
parents:
31754
diff
changeset
|
28 scmutil, |
26566
b2f3f185e458
tags: use absolute_import
Gregory Szorc <gregory.szorc@gmail.com>
parents:
26214
diff
changeset
|
29 util, |
b2f3f185e458
tags: use absolute_import
Gregory Szorc <gregory.szorc@gmail.com>
parents:
26214
diff
changeset
|
30 ) |
b2f3f185e458
tags: use absolute_import
Gregory Szorc <gregory.szorc@gmail.com>
parents:
26214
diff
changeset
|
31 |
24914
07200e3332a1
tags: extract .hgtags filenodes cache to a standalone file
Gregory Szorc <gregory.szorc@gmail.com>
parents:
24665
diff
changeset
|
32 # Tags computation can be expensive and caches exist to make it fast in |
07200e3332a1
tags: extract .hgtags filenodes cache to a standalone file
Gregory Szorc <gregory.szorc@gmail.com>
parents:
24665
diff
changeset
|
33 # the common case. |
07200e3332a1
tags: extract .hgtags filenodes cache to a standalone file
Gregory Szorc <gregory.szorc@gmail.com>
parents:
24665
diff
changeset
|
34 # |
07200e3332a1
tags: extract .hgtags filenodes cache to a standalone file
Gregory Szorc <gregory.szorc@gmail.com>
parents:
24665
diff
changeset
|
35 # The "hgtagsfnodes1" cache file caches the .hgtags filenode values for |
07200e3332a1
tags: extract .hgtags filenodes cache to a standalone file
Gregory Szorc <gregory.szorc@gmail.com>
parents:
24665
diff
changeset
|
36 # each revision in the repository. The file is effectively an array of |
07200e3332a1
tags: extract .hgtags filenodes cache to a standalone file
Gregory Szorc <gregory.szorc@gmail.com>
parents:
24665
diff
changeset
|
37 # fixed length records. Read the docs for "hgtagsfnodescache" for technical |
07200e3332a1
tags: extract .hgtags filenodes cache to a standalone file
Gregory Szorc <gregory.szorc@gmail.com>
parents:
24665
diff
changeset
|
38 # details. |
07200e3332a1
tags: extract .hgtags filenodes cache to a standalone file
Gregory Szorc <gregory.szorc@gmail.com>
parents:
24665
diff
changeset
|
39 # |
07200e3332a1
tags: extract .hgtags filenodes cache to a standalone file
Gregory Szorc <gregory.szorc@gmail.com>
parents:
24665
diff
changeset
|
40 # The .hgtags filenode cache grows in proportion to the length of the |
07200e3332a1
tags: extract .hgtags filenodes cache to a standalone file
Gregory Szorc <gregory.szorc@gmail.com>
parents:
24665
diff
changeset
|
41 # changelog. The file is truncated when the # changelog is stripped. |
07200e3332a1
tags: extract .hgtags filenodes cache to a standalone file
Gregory Szorc <gregory.szorc@gmail.com>
parents:
24665
diff
changeset
|
42 # |
07200e3332a1
tags: extract .hgtags filenodes cache to a standalone file
Gregory Szorc <gregory.szorc@gmail.com>
parents:
24665
diff
changeset
|
43 # The purpose of the filenode cache is to avoid the most expensive part |
07200e3332a1
tags: extract .hgtags filenodes cache to a standalone file
Gregory Szorc <gregory.szorc@gmail.com>
parents:
24665
diff
changeset
|
44 # of finding global tags, which is looking up the .hgtags filenode in the |
07200e3332a1
tags: extract .hgtags filenodes cache to a standalone file
Gregory Szorc <gregory.szorc@gmail.com>
parents:
24665
diff
changeset
|
45 # manifest for each head. This can take dozens or over 100ms for |
07200e3332a1
tags: extract .hgtags filenodes cache to a standalone file
Gregory Szorc <gregory.szorc@gmail.com>
parents:
24665
diff
changeset
|
46 # repositories with very large manifests. Multiplied by dozens or even |
07200e3332a1
tags: extract .hgtags filenodes cache to a standalone file
Gregory Szorc <gregory.szorc@gmail.com>
parents:
24665
diff
changeset
|
47 # hundreds of heads and there is a significant performance concern. |
07200e3332a1
tags: extract .hgtags filenodes cache to a standalone file
Gregory Szorc <gregory.szorc@gmail.com>
parents:
24665
diff
changeset
|
48 # |
24941
1062663808ce
tags: write a separate tags cache file for unfiltered repos
Gregory Szorc <gregory.szorc@gmail.com>
parents:
24940
diff
changeset
|
49 # There also exist a separate cache file for each repository filter. |
1062663808ce
tags: write a separate tags cache file for unfiltered repos
Gregory Szorc <gregory.szorc@gmail.com>
parents:
24940
diff
changeset
|
50 # These "tags-*" files store information about the history of tags. |
24575
c71edbafe603
tags: improve documentation
Gregory Szorc <gregory.szorc@gmail.com>
parents:
24198
diff
changeset
|
51 # |
24941
1062663808ce
tags: write a separate tags cache file for unfiltered repos
Gregory Szorc <gregory.szorc@gmail.com>
parents:
24940
diff
changeset
|
52 # The tags cache files consists of a cache validation line followed by |
1062663808ce
tags: write a separate tags cache file for unfiltered repos
Gregory Szorc <gregory.szorc@gmail.com>
parents:
24940
diff
changeset
|
53 # a history of tags. |
24914
07200e3332a1
tags: extract .hgtags filenodes cache to a standalone file
Gregory Szorc <gregory.szorc@gmail.com>
parents:
24665
diff
changeset
|
54 # |
24939
410f3856196f
tags: change format of tags cache files
Gregory Szorc <gregory.szorc@gmail.com>
parents:
24938
diff
changeset
|
55 # The cache validation line has the format: |
24575
c71edbafe603
tags: improve documentation
Gregory Szorc <gregory.szorc@gmail.com>
parents:
24198
diff
changeset
|
56 # |
24939
410f3856196f
tags: change format of tags cache files
Gregory Szorc <gregory.szorc@gmail.com>
parents:
24938
diff
changeset
|
57 # <tiprev> <tipnode> [<filteredhash>] |
24575
c71edbafe603
tags: improve documentation
Gregory Szorc <gregory.szorc@gmail.com>
parents:
24198
diff
changeset
|
58 # |
24939
410f3856196f
tags: change format of tags cache files
Gregory Szorc <gregory.szorc@gmail.com>
parents:
24938
diff
changeset
|
59 # <tiprev> is an integer revision and <tipnode> is a 40 character hex |
410f3856196f
tags: change format of tags cache files
Gregory Szorc <gregory.szorc@gmail.com>
parents:
24938
diff
changeset
|
60 # node for that changeset. These redundantly identify the repository |
410f3856196f
tags: change format of tags cache files
Gregory Szorc <gregory.szorc@gmail.com>
parents:
24938
diff
changeset
|
61 # tip from the time the cache was written. In addition, <filteredhash>, |
410f3856196f
tags: change format of tags cache files
Gregory Szorc <gregory.szorc@gmail.com>
parents:
24938
diff
changeset
|
62 # if present, is a 40 character hex hash of the contents of the filtered |
410f3856196f
tags: change format of tags cache files
Gregory Szorc <gregory.szorc@gmail.com>
parents:
24938
diff
changeset
|
63 # revisions for this filter. If the set of filtered revs changes, the |
410f3856196f
tags: change format of tags cache files
Gregory Szorc <gregory.szorc@gmail.com>
parents:
24938
diff
changeset
|
64 # hash will change and invalidate the cache. |
24575
c71edbafe603
tags: improve documentation
Gregory Szorc <gregory.szorc@gmail.com>
parents:
24198
diff
changeset
|
65 # |
24939
410f3856196f
tags: change format of tags cache files
Gregory Szorc <gregory.szorc@gmail.com>
parents:
24938
diff
changeset
|
66 # The history part of the tags cache consists of lines of the form: |
24575
c71edbafe603
tags: improve documentation
Gregory Szorc <gregory.szorc@gmail.com>
parents:
24198
diff
changeset
|
67 # |
c71edbafe603
tags: improve documentation
Gregory Szorc <gregory.szorc@gmail.com>
parents:
24198
diff
changeset
|
68 # <node> <tag> |
c71edbafe603
tags: improve documentation
Gregory Szorc <gregory.szorc@gmail.com>
parents:
24198
diff
changeset
|
69 # |
c71edbafe603
tags: improve documentation
Gregory Szorc <gregory.szorc@gmail.com>
parents:
24198
diff
changeset
|
70 # (This format is identical to that of .hgtags files.) |
c71edbafe603
tags: improve documentation
Gregory Szorc <gregory.szorc@gmail.com>
parents:
24198
diff
changeset
|
71 # |
c71edbafe603
tags: improve documentation
Gregory Szorc <gregory.szorc@gmail.com>
parents:
24198
diff
changeset
|
72 # <tag> is the tag name and <node> is the 40 character hex changeset |
c71edbafe603
tags: improve documentation
Gregory Szorc <gregory.szorc@gmail.com>
parents:
24198
diff
changeset
|
73 # the tag is associated with. |
c71edbafe603
tags: improve documentation
Gregory Szorc <gregory.szorc@gmail.com>
parents:
24198
diff
changeset
|
74 # |
c71edbafe603
tags: improve documentation
Gregory Szorc <gregory.szorc@gmail.com>
parents:
24198
diff
changeset
|
75 # Tags are written sorted by tag name. |
c71edbafe603
tags: improve documentation
Gregory Szorc <gregory.szorc@gmail.com>
parents:
24198
diff
changeset
|
76 # |
c71edbafe603
tags: improve documentation
Gregory Szorc <gregory.szorc@gmail.com>
parents:
24198
diff
changeset
|
77 # Tags associated with multiple changesets have an entry for each changeset. |
c71edbafe603
tags: improve documentation
Gregory Szorc <gregory.szorc@gmail.com>
parents:
24198
diff
changeset
|
78 # The most recent changeset (in terms of revlog ordering for the head |
c71edbafe603
tags: improve documentation
Gregory Szorc <gregory.szorc@gmail.com>
parents:
24198
diff
changeset
|
79 # setting it) for each tag is last. |
c71edbafe603
tags: improve documentation
Gregory Szorc <gregory.szorc@gmail.com>
parents:
24198
diff
changeset
|
80 |
11351
1cdc8b5e5729
tags: remove the old non-caching implementation of findglobaltags().
Greg Ward <greg-hg@gerg.ca>
parents:
11078
diff
changeset
|
81 def findglobaltags(ui, repo, alltags, tagtypes): |
24575
c71edbafe603
tags: improve documentation
Gregory Szorc <gregory.szorc@gmail.com>
parents:
24198
diff
changeset
|
82 '''Find global tags in a repo. |
c71edbafe603
tags: improve documentation
Gregory Szorc <gregory.szorc@gmail.com>
parents:
24198
diff
changeset
|
83 |
c71edbafe603
tags: improve documentation
Gregory Szorc <gregory.szorc@gmail.com>
parents:
24198
diff
changeset
|
84 "alltags" maps tag name to (node, hist) 2-tuples. |
c71edbafe603
tags: improve documentation
Gregory Szorc <gregory.szorc@gmail.com>
parents:
24198
diff
changeset
|
85 |
c71edbafe603
tags: improve documentation
Gregory Szorc <gregory.szorc@gmail.com>
parents:
24198
diff
changeset
|
86 "tagtypes" maps tag name to tag type. Global tags always have the |
c71edbafe603
tags: improve documentation
Gregory Szorc <gregory.szorc@gmail.com>
parents:
24198
diff
changeset
|
87 "global" tag type. |
c71edbafe603
tags: improve documentation
Gregory Szorc <gregory.szorc@gmail.com>
parents:
24198
diff
changeset
|
88 |
c71edbafe603
tags: improve documentation
Gregory Szorc <gregory.szorc@gmail.com>
parents:
24198
diff
changeset
|
89 The "alltags" and "tagtypes" dicts are updated in place. Empty dicts |
c71edbafe603
tags: improve documentation
Gregory Szorc <gregory.szorc@gmail.com>
parents:
24198
diff
changeset
|
90 should be passed in. |
c71edbafe603
tags: improve documentation
Gregory Szorc <gregory.szorc@gmail.com>
parents:
24198
diff
changeset
|
91 |
c71edbafe603
tags: improve documentation
Gregory Szorc <gregory.szorc@gmail.com>
parents:
24198
diff
changeset
|
92 The tags cache is read and updated as a side-effect of calling. |
c71edbafe603
tags: improve documentation
Gregory Szorc <gregory.szorc@gmail.com>
parents:
24198
diff
changeset
|
93 ''' |
9160
4017291c4c48
tags: support 'instant' tag retrieval (issue548)
Greg Ward <greg-hg@gerg.ca>
parents:
9159
diff
changeset
|
94 # This is so we can be lazy and assume alltags contains only global |
4017291c4c48
tags: support 'instant' tag retrieval (issue548)
Greg Ward <greg-hg@gerg.ca>
parents:
9159
diff
changeset
|
95 # tags when we pass it to _writetagcache(). |
4017291c4c48
tags: support 'instant' tag retrieval (issue548)
Greg Ward <greg-hg@gerg.ca>
parents:
9159
diff
changeset
|
96 assert len(alltags) == len(tagtypes) == 0, \ |
4017291c4c48
tags: support 'instant' tag retrieval (issue548)
Greg Ward <greg-hg@gerg.ca>
parents:
9159
diff
changeset
|
97 "findglobaltags() should be called first" |
4017291c4c48
tags: support 'instant' tag retrieval (issue548)
Greg Ward <greg-hg@gerg.ca>
parents:
9159
diff
changeset
|
98 |
24939
410f3856196f
tags: change format of tags cache files
Gregory Szorc <gregory.szorc@gmail.com>
parents:
24938
diff
changeset
|
99 (heads, tagfnode, valid, cachetags, shouldwrite) = _readtagcache(ui, repo) |
9160
4017291c4c48
tags: support 'instant' tag retrieval (issue548)
Greg Ward <greg-hg@gerg.ca>
parents:
9159
diff
changeset
|
100 if cachetags is not None: |
4017291c4c48
tags: support 'instant' tag retrieval (issue548)
Greg Ward <greg-hg@gerg.ca>
parents:
9159
diff
changeset
|
101 assert not shouldwrite |
4017291c4c48
tags: support 'instant' tag retrieval (issue548)
Greg Ward <greg-hg@gerg.ca>
parents:
9159
diff
changeset
|
102 # XXX is this really 100% correct? are there oddball special |
4017291c4c48
tags: support 'instant' tag retrieval (issue548)
Greg Ward <greg-hg@gerg.ca>
parents:
9159
diff
changeset
|
103 # cases where a global tag should outrank a local tag but won't, |
4017291c4c48
tags: support 'instant' tag retrieval (issue548)
Greg Ward <greg-hg@gerg.ca>
parents:
9159
diff
changeset
|
104 # because cachetags does not contain rank info? |
4017291c4c48
tags: support 'instant' tag retrieval (issue548)
Greg Ward <greg-hg@gerg.ca>
parents:
9159
diff
changeset
|
105 _updatetags(cachetags, 'global', alltags, tagtypes) |
4017291c4c48
tags: support 'instant' tag retrieval (issue548)
Greg Ward <greg-hg@gerg.ca>
parents:
9159
diff
changeset
|
106 return |
9159
f528d1a93491
tags: implement persistent tag caching (issue548).
Greg Ward <greg-hg@gerg.ca>
parents:
9157
diff
changeset
|
107 |
24575
c71edbafe603
tags: improve documentation
Gregory Szorc <gregory.szorc@gmail.com>
parents:
24198
diff
changeset
|
108 seen = set() # set of fnode |
9159
f528d1a93491
tags: implement persistent tag caching (issue548).
Greg Ward <greg-hg@gerg.ca>
parents:
9157
diff
changeset
|
109 fctx = None |
24575
c71edbafe603
tags: improve documentation
Gregory Szorc <gregory.szorc@gmail.com>
parents:
24198
diff
changeset
|
110 for head in reversed(heads): # oldest to newest |
9159
f528d1a93491
tags: implement persistent tag caching (issue548).
Greg Ward <greg-hg@gerg.ca>
parents:
9157
diff
changeset
|
111 assert head in repo.changelog.nodemap, \ |
f528d1a93491
tags: implement persistent tag caching (issue548).
Greg Ward <greg-hg@gerg.ca>
parents:
9157
diff
changeset
|
112 "tag cache returned bogus head %s" % short(head) |
f528d1a93491
tags: implement persistent tag caching (issue548).
Greg Ward <greg-hg@gerg.ca>
parents:
9157
diff
changeset
|
113 |
f528d1a93491
tags: implement persistent tag caching (issue548).
Greg Ward <greg-hg@gerg.ca>
parents:
9157
diff
changeset
|
114 fnode = tagfnode.get(head) |
f528d1a93491
tags: implement persistent tag caching (issue548).
Greg Ward <greg-hg@gerg.ca>
parents:
9157
diff
changeset
|
115 if fnode and fnode not in seen: |
f528d1a93491
tags: implement persistent tag caching (issue548).
Greg Ward <greg-hg@gerg.ca>
parents:
9157
diff
changeset
|
116 seen.add(fnode) |
f528d1a93491
tags: implement persistent tag caching (issue548).
Greg Ward <greg-hg@gerg.ca>
parents:
9157
diff
changeset
|
117 if not fctx: |
f528d1a93491
tags: implement persistent tag caching (issue548).
Greg Ward <greg-hg@gerg.ca>
parents:
9157
diff
changeset
|
118 fctx = repo.filectx('.hgtags', fileid=fnode) |
f528d1a93491
tags: implement persistent tag caching (issue548).
Greg Ward <greg-hg@gerg.ca>
parents:
9157
diff
changeset
|
119 else: |
f528d1a93491
tags: implement persistent tag caching (issue548).
Greg Ward <greg-hg@gerg.ca>
parents:
9157
diff
changeset
|
120 fctx = fctx.filectx(fnode) |
f528d1a93491
tags: implement persistent tag caching (issue548).
Greg Ward <greg-hg@gerg.ca>
parents:
9157
diff
changeset
|
121 |
f528d1a93491
tags: implement persistent tag caching (issue548).
Greg Ward <greg-hg@gerg.ca>
parents:
9157
diff
changeset
|
122 filetags = _readtags(ui, repo, fctx.data().splitlines(), fctx) |
f528d1a93491
tags: implement persistent tag caching (issue548).
Greg Ward <greg-hg@gerg.ca>
parents:
9157
diff
changeset
|
123 _updatetags(filetags, 'global', alltags, tagtypes) |
f528d1a93491
tags: implement persistent tag caching (issue548).
Greg Ward <greg-hg@gerg.ca>
parents:
9157
diff
changeset
|
124 |
f528d1a93491
tags: implement persistent tag caching (issue548).
Greg Ward <greg-hg@gerg.ca>
parents:
9157
diff
changeset
|
125 # and update the cache (if necessary) |
f528d1a93491
tags: implement persistent tag caching (issue548).
Greg Ward <greg-hg@gerg.ca>
parents:
9157
diff
changeset
|
126 if shouldwrite: |
24939
410f3856196f
tags: change format of tags cache files
Gregory Szorc <gregory.szorc@gmail.com>
parents:
24938
diff
changeset
|
127 _writetagcache(ui, repo, valid, alltags) |
9159
f528d1a93491
tags: implement persistent tag caching (issue548).
Greg Ward <greg-hg@gerg.ca>
parents:
9157
diff
changeset
|
128 |
9157
abb7d4d43a5f
Factor tags module out of localrepo (issue548).
Greg Ward <greg-hg@gerg.ca>
parents:
diff
changeset
|
129 def readlocaltags(ui, repo, alltags, tagtypes): |
24575
c71edbafe603
tags: improve documentation
Gregory Szorc <gregory.szorc@gmail.com>
parents:
24198
diff
changeset
|
130 '''Read local tags in repo. Update alltags and tagtypes.''' |
9157
abb7d4d43a5f
Factor tags module out of localrepo (issue548).
Greg Ward <greg-hg@gerg.ca>
parents:
diff
changeset
|
131 try: |
23889
7cc77030c557
localrepo: remove all external users of localrepo.opener
Angel Ezquerra <angel.ezquerra@gmail.com>
parents:
23139
diff
changeset
|
132 data = repo.vfs.read("localtags") |
26214
328739ea70c3
global: mass rewrite to use modern exception syntax
Gregory Szorc <gregory.szorc@gmail.com>
parents:
25902
diff
changeset
|
133 except IOError as inst: |
14038
0e6f622f31ca
tags: loosen IOError filtering when reading localtags
Idan Kamara <idankk86@gmail.com>
parents:
14020
diff
changeset
|
134 if inst.errno != errno.ENOENT: |
0e6f622f31ca
tags: loosen IOError filtering when reading localtags
Idan Kamara <idankk86@gmail.com>
parents:
14020
diff
changeset
|
135 raise |
0e6f622f31ca
tags: loosen IOError filtering when reading localtags
Idan Kamara <idankk86@gmail.com>
parents:
14020
diff
changeset
|
136 return |
0e6f622f31ca
tags: loosen IOError filtering when reading localtags
Idan Kamara <idankk86@gmail.com>
parents:
14020
diff
changeset
|
137 |
0e6f622f31ca
tags: loosen IOError filtering when reading localtags
Idan Kamara <idankk86@gmail.com>
parents:
14020
diff
changeset
|
138 # localtags is in the local encoding; re-encode to UTF-8 on |
0e6f622f31ca
tags: loosen IOError filtering when reading localtags
Idan Kamara <idankk86@gmail.com>
parents:
14020
diff
changeset
|
139 # input for consistency with the rest of this module. |
0e6f622f31ca
tags: loosen IOError filtering when reading localtags
Idan Kamara <idankk86@gmail.com>
parents:
14020
diff
changeset
|
140 filetags = _readtags( |
0e6f622f31ca
tags: loosen IOError filtering when reading localtags
Idan Kamara <idankk86@gmail.com>
parents:
14020
diff
changeset
|
141 ui, repo, data.splitlines(), "localtags", |
0e6f622f31ca
tags: loosen IOError filtering when reading localtags
Idan Kamara <idankk86@gmail.com>
parents:
14020
diff
changeset
|
142 recode=encoding.fromlocal) |
21823
925d1bb9a971
repoview: do not crash when localtags refers to non existing revisions
Angel Ezquerra <angel.ezquerra@gmail.com>
parents:
21030
diff
changeset
|
143 |
925d1bb9a971
repoview: do not crash when localtags refers to non existing revisions
Angel Ezquerra <angel.ezquerra@gmail.com>
parents:
21030
diff
changeset
|
144 # remove tags pointing to invalid nodes |
925d1bb9a971
repoview: do not crash when localtags refers to non existing revisions
Angel Ezquerra <angel.ezquerra@gmail.com>
parents:
21030
diff
changeset
|
145 cl = repo.changelog |
925d1bb9a971
repoview: do not crash when localtags refers to non existing revisions
Angel Ezquerra <angel.ezquerra@gmail.com>
parents:
21030
diff
changeset
|
146 for t in filetags.keys(): |
925d1bb9a971
repoview: do not crash when localtags refers to non existing revisions
Angel Ezquerra <angel.ezquerra@gmail.com>
parents:
21030
diff
changeset
|
147 try: |
925d1bb9a971
repoview: do not crash when localtags refers to non existing revisions
Angel Ezquerra <angel.ezquerra@gmail.com>
parents:
21030
diff
changeset
|
148 cl.rev(filetags[t][0]) |
925d1bb9a971
repoview: do not crash when localtags refers to non existing revisions
Angel Ezquerra <angel.ezquerra@gmail.com>
parents:
21030
diff
changeset
|
149 except (LookupError, ValueError): |
925d1bb9a971
repoview: do not crash when localtags refers to non existing revisions
Angel Ezquerra <angel.ezquerra@gmail.com>
parents:
21030
diff
changeset
|
150 del filetags[t] |
925d1bb9a971
repoview: do not crash when localtags refers to non existing revisions
Angel Ezquerra <angel.ezquerra@gmail.com>
parents:
21030
diff
changeset
|
151 |
14038
0e6f622f31ca
tags: loosen IOError filtering when reading localtags
Idan Kamara <idankk86@gmail.com>
parents:
14020
diff
changeset
|
152 _updatetags(filetags, "local", alltags, tagtypes) |
9157
abb7d4d43a5f
Factor tags module out of localrepo (issue548).
Greg Ward <greg-hg@gerg.ca>
parents:
diff
changeset
|
153 |
21892
89cdebc31cda
tags: introduce _readtaghist function
Angel Ezquerra <angel.ezquerra@gmail.com>
parents:
21832
diff
changeset
|
154 def _readtaghist(ui, repo, lines, fn, recode=None, calcnodelines=False): |
9157
abb7d4d43a5f
Factor tags module out of localrepo (issue548).
Greg Ward <greg-hg@gerg.ca>
parents:
diff
changeset
|
155 '''Read tag definitions from a file (or any source of lines). |
24575
c71edbafe603
tags: improve documentation
Gregory Szorc <gregory.szorc@gmail.com>
parents:
24198
diff
changeset
|
156 |
21892
89cdebc31cda
tags: introduce _readtaghist function
Angel Ezquerra <angel.ezquerra@gmail.com>
parents:
21832
diff
changeset
|
157 This function returns two sortdicts with similar information: |
24575
c71edbafe603
tags: improve documentation
Gregory Szorc <gregory.szorc@gmail.com>
parents:
24198
diff
changeset
|
158 |
23139
e53f6b72a0e4
spelling: fixes from proofreading of spell checker issues
Mads Kiilerich <madski@unity3d.com>
parents:
21892
diff
changeset
|
159 - the first dict, bintaghist, contains the tag information as expected by |
21892
89cdebc31cda
tags: introduce _readtaghist function
Angel Ezquerra <angel.ezquerra@gmail.com>
parents:
21832
diff
changeset
|
160 the _readtags function, i.e. a mapping from tag name to (node, hist): |
89cdebc31cda
tags: introduce _readtaghist function
Angel Ezquerra <angel.ezquerra@gmail.com>
parents:
21832
diff
changeset
|
161 - node is the node id from the last line read for that name, |
89cdebc31cda
tags: introduce _readtaghist function
Angel Ezquerra <angel.ezquerra@gmail.com>
parents:
21832
diff
changeset
|
162 - hist is the list of node ids previously associated with it (in file |
24575
c71edbafe603
tags: improve documentation
Gregory Szorc <gregory.szorc@gmail.com>
parents:
24198
diff
changeset
|
163 order). All node ids are binary, not hex. |
c71edbafe603
tags: improve documentation
Gregory Szorc <gregory.szorc@gmail.com>
parents:
24198
diff
changeset
|
164 |
21892
89cdebc31cda
tags: introduce _readtaghist function
Angel Ezquerra <angel.ezquerra@gmail.com>
parents:
21832
diff
changeset
|
165 - the second dict, hextaglines, is a mapping from tag name to a list of |
89cdebc31cda
tags: introduce _readtaghist function
Angel Ezquerra <angel.ezquerra@gmail.com>
parents:
21832
diff
changeset
|
166 [hexnode, line number] pairs, ordered from the oldest to the newest node. |
24575
c71edbafe603
tags: improve documentation
Gregory Szorc <gregory.szorc@gmail.com>
parents:
24198
diff
changeset
|
167 |
21892
89cdebc31cda
tags: introduce _readtaghist function
Angel Ezquerra <angel.ezquerra@gmail.com>
parents:
21832
diff
changeset
|
168 When calcnodelines is False the hextaglines dict is not calculated (an |
89cdebc31cda
tags: introduce _readtaghist function
Angel Ezquerra <angel.ezquerra@gmail.com>
parents:
21832
diff
changeset
|
169 empty dict is returned). This is done to improve this function's |
89cdebc31cda
tags: introduce _readtaghist function
Angel Ezquerra <angel.ezquerra@gmail.com>
parents:
21832
diff
changeset
|
170 performance in cases where the line numbers are not needed. |
89cdebc31cda
tags: introduce _readtaghist function
Angel Ezquerra <angel.ezquerra@gmail.com>
parents:
21832
diff
changeset
|
171 ''' |
9157
abb7d4d43a5f
Factor tags module out of localrepo (issue548).
Greg Ward <greg-hg@gerg.ca>
parents:
diff
changeset
|
172 |
21892
89cdebc31cda
tags: introduce _readtaghist function
Angel Ezquerra <angel.ezquerra@gmail.com>
parents:
21832
diff
changeset
|
173 bintaghist = util.sortdict() |
89cdebc31cda
tags: introduce _readtaghist function
Angel Ezquerra <angel.ezquerra@gmail.com>
parents:
21832
diff
changeset
|
174 hextaglines = util.sortdict() |
9157
abb7d4d43a5f
Factor tags module out of localrepo (issue548).
Greg Ward <greg-hg@gerg.ca>
parents:
diff
changeset
|
175 count = 0 |
abb7d4d43a5f
Factor tags module out of localrepo (issue548).
Greg Ward <greg-hg@gerg.ca>
parents:
diff
changeset
|
176 |
29788
a9dd92c48a1c
tags: silence cache parsing errors
Matt Mackall <mpm@selenic.com>
parents:
27585
diff
changeset
|
177 def dbg(msg): |
a9dd92c48a1c
tags: silence cache parsing errors
Matt Mackall <mpm@selenic.com>
parents:
27585
diff
changeset
|
178 ui.debug("%s, line %s: %s\n" % (fn, count, msg)) |
9157
abb7d4d43a5f
Factor tags module out of localrepo (issue548).
Greg Ward <greg-hg@gerg.ca>
parents:
diff
changeset
|
179 |
21892
89cdebc31cda
tags: introduce _readtaghist function
Angel Ezquerra <angel.ezquerra@gmail.com>
parents:
21832
diff
changeset
|
180 for nline, line in enumerate(lines): |
9157
abb7d4d43a5f
Factor tags module out of localrepo (issue548).
Greg Ward <greg-hg@gerg.ca>
parents:
diff
changeset
|
181 count += 1 |
abb7d4d43a5f
Factor tags module out of localrepo (issue548).
Greg Ward <greg-hg@gerg.ca>
parents:
diff
changeset
|
182 if not line: |
abb7d4d43a5f
Factor tags module out of localrepo (issue548).
Greg Ward <greg-hg@gerg.ca>
parents:
diff
changeset
|
183 continue |
abb7d4d43a5f
Factor tags module out of localrepo (issue548).
Greg Ward <greg-hg@gerg.ca>
parents:
diff
changeset
|
184 try: |
abb7d4d43a5f
Factor tags module out of localrepo (issue548).
Greg Ward <greg-hg@gerg.ca>
parents:
diff
changeset
|
185 (nodehex, name) = line.split(" ", 1) |
abb7d4d43a5f
Factor tags module out of localrepo (issue548).
Greg Ward <greg-hg@gerg.ca>
parents:
diff
changeset
|
186 except ValueError: |
29788
a9dd92c48a1c
tags: silence cache parsing errors
Matt Mackall <mpm@selenic.com>
parents:
27585
diff
changeset
|
187 dbg("cannot parse entry") |
9157
abb7d4d43a5f
Factor tags module out of localrepo (issue548).
Greg Ward <greg-hg@gerg.ca>
parents:
diff
changeset
|
188 continue |
9160
4017291c4c48
tags: support 'instant' tag retrieval (issue548)
Greg Ward <greg-hg@gerg.ca>
parents:
9159
diff
changeset
|
189 name = name.strip() |
4017291c4c48
tags: support 'instant' tag retrieval (issue548)
Greg Ward <greg-hg@gerg.ca>
parents:
9159
diff
changeset
|
190 if recode: |
4017291c4c48
tags: support 'instant' tag retrieval (issue548)
Greg Ward <greg-hg@gerg.ca>
parents:
9159
diff
changeset
|
191 name = recode(name) |
9157
abb7d4d43a5f
Factor tags module out of localrepo (issue548).
Greg Ward <greg-hg@gerg.ca>
parents:
diff
changeset
|
192 try: |
abb7d4d43a5f
Factor tags module out of localrepo (issue548).
Greg Ward <greg-hg@gerg.ca>
parents:
diff
changeset
|
193 nodebin = bin(nodehex) |
abb7d4d43a5f
Factor tags module out of localrepo (issue548).
Greg Ward <greg-hg@gerg.ca>
parents:
diff
changeset
|
194 except TypeError: |
29788
a9dd92c48a1c
tags: silence cache parsing errors
Matt Mackall <mpm@selenic.com>
parents:
27585
diff
changeset
|
195 dbg("node '%s' is not well formed" % nodehex) |
9157
abb7d4d43a5f
Factor tags module out of localrepo (issue548).
Greg Ward <greg-hg@gerg.ca>
parents:
diff
changeset
|
196 continue |
abb7d4d43a5f
Factor tags module out of localrepo (issue548).
Greg Ward <greg-hg@gerg.ca>
parents:
diff
changeset
|
197 |
abb7d4d43a5f
Factor tags module out of localrepo (issue548).
Greg Ward <greg-hg@gerg.ca>
parents:
diff
changeset
|
198 # update filetags |
21892
89cdebc31cda
tags: introduce _readtaghist function
Angel Ezquerra <angel.ezquerra@gmail.com>
parents:
21832
diff
changeset
|
199 if calcnodelines: |
89cdebc31cda
tags: introduce _readtaghist function
Angel Ezquerra <angel.ezquerra@gmail.com>
parents:
21832
diff
changeset
|
200 # map tag name to a list of line numbers |
89cdebc31cda
tags: introduce _readtaghist function
Angel Ezquerra <angel.ezquerra@gmail.com>
parents:
21832
diff
changeset
|
201 if name not in hextaglines: |
89cdebc31cda
tags: introduce _readtaghist function
Angel Ezquerra <angel.ezquerra@gmail.com>
parents:
21832
diff
changeset
|
202 hextaglines[name] = [] |
89cdebc31cda
tags: introduce _readtaghist function
Angel Ezquerra <angel.ezquerra@gmail.com>
parents:
21832
diff
changeset
|
203 hextaglines[name].append([nodehex, nline]) |
89cdebc31cda
tags: introduce _readtaghist function
Angel Ezquerra <angel.ezquerra@gmail.com>
parents:
21832
diff
changeset
|
204 continue |
89cdebc31cda
tags: introduce _readtaghist function
Angel Ezquerra <angel.ezquerra@gmail.com>
parents:
21832
diff
changeset
|
205 # map tag name to (node, hist) |
89cdebc31cda
tags: introduce _readtaghist function
Angel Ezquerra <angel.ezquerra@gmail.com>
parents:
21832
diff
changeset
|
206 if name not in bintaghist: |
89cdebc31cda
tags: introduce _readtaghist function
Angel Ezquerra <angel.ezquerra@gmail.com>
parents:
21832
diff
changeset
|
207 bintaghist[name] = [] |
89cdebc31cda
tags: introduce _readtaghist function
Angel Ezquerra <angel.ezquerra@gmail.com>
parents:
21832
diff
changeset
|
208 bintaghist[name].append(nodebin) |
89cdebc31cda
tags: introduce _readtaghist function
Angel Ezquerra <angel.ezquerra@gmail.com>
parents:
21832
diff
changeset
|
209 return bintaghist, hextaglines |
89cdebc31cda
tags: introduce _readtaghist function
Angel Ezquerra <angel.ezquerra@gmail.com>
parents:
21832
diff
changeset
|
210 |
89cdebc31cda
tags: introduce _readtaghist function
Angel Ezquerra <angel.ezquerra@gmail.com>
parents:
21832
diff
changeset
|
211 def _readtags(ui, repo, lines, fn, recode=None, calcnodelines=False): |
89cdebc31cda
tags: introduce _readtaghist function
Angel Ezquerra <angel.ezquerra@gmail.com>
parents:
21832
diff
changeset
|
212 '''Read tag definitions from a file (or any source of lines). |
24575
c71edbafe603
tags: improve documentation
Gregory Szorc <gregory.szorc@gmail.com>
parents:
24198
diff
changeset
|
213 |
c71edbafe603
tags: improve documentation
Gregory Szorc <gregory.szorc@gmail.com>
parents:
24198
diff
changeset
|
214 Returns a mapping from tag name to (node, hist). |
c71edbafe603
tags: improve documentation
Gregory Szorc <gregory.szorc@gmail.com>
parents:
24198
diff
changeset
|
215 |
c71edbafe603
tags: improve documentation
Gregory Szorc <gregory.szorc@gmail.com>
parents:
24198
diff
changeset
|
216 "node" is the node id from the last line read for that name. "hist" |
c71edbafe603
tags: improve documentation
Gregory Szorc <gregory.szorc@gmail.com>
parents:
24198
diff
changeset
|
217 is the list of node ids previously associated with it (in file order). |
c71edbafe603
tags: improve documentation
Gregory Szorc <gregory.szorc@gmail.com>
parents:
24198
diff
changeset
|
218 All node ids are binary, not hex. |
c71edbafe603
tags: improve documentation
Gregory Szorc <gregory.szorc@gmail.com>
parents:
24198
diff
changeset
|
219 ''' |
21892
89cdebc31cda
tags: introduce _readtaghist function
Angel Ezquerra <angel.ezquerra@gmail.com>
parents:
21832
diff
changeset
|
220 filetags, nodelines = _readtaghist(ui, repo, lines, fn, recode=recode, |
89cdebc31cda
tags: introduce _readtaghist function
Angel Ezquerra <angel.ezquerra@gmail.com>
parents:
21832
diff
changeset
|
221 calcnodelines=calcnodelines) |
27585
8a256cee72c8
tags: create new sortdict for performance reasons
Gregory Szorc <gregory.szorc@gmail.com>
parents:
26566
diff
changeset
|
222 # util.sortdict().__setitem__ is much slower at replacing then inserting |
8a256cee72c8
tags: create new sortdict for performance reasons
Gregory Szorc <gregory.szorc@gmail.com>
parents:
26566
diff
changeset
|
223 # new entries. The difference can matter if there are thousands of tags. |
8a256cee72c8
tags: create new sortdict for performance reasons
Gregory Szorc <gregory.szorc@gmail.com>
parents:
26566
diff
changeset
|
224 # Create a new sortdict to avoid the performance penalty. |
8a256cee72c8
tags: create new sortdict for performance reasons
Gregory Szorc <gregory.szorc@gmail.com>
parents:
26566
diff
changeset
|
225 newtags = util.sortdict() |
21892
89cdebc31cda
tags: introduce _readtaghist function
Angel Ezquerra <angel.ezquerra@gmail.com>
parents:
21832
diff
changeset
|
226 for tag, taghist in filetags.items(): |
27585
8a256cee72c8
tags: create new sortdict for performance reasons
Gregory Szorc <gregory.szorc@gmail.com>
parents:
26566
diff
changeset
|
227 newtags[tag] = (taghist[-1], taghist[:-1]) |
8a256cee72c8
tags: create new sortdict for performance reasons
Gregory Szorc <gregory.szorc@gmail.com>
parents:
26566
diff
changeset
|
228 return newtags |
9157
abb7d4d43a5f
Factor tags module out of localrepo (issue548).
Greg Ward <greg-hg@gerg.ca>
parents:
diff
changeset
|
229 |
abb7d4d43a5f
Factor tags module out of localrepo (issue548).
Greg Ward <greg-hg@gerg.ca>
parents:
diff
changeset
|
230 def _updatetags(filetags, tagtype, alltags, tagtypes): |
abb7d4d43a5f
Factor tags module out of localrepo (issue548).
Greg Ward <greg-hg@gerg.ca>
parents:
diff
changeset
|
231 '''Incorporate the tag info read from one file into the two |
abb7d4d43a5f
Factor tags module out of localrepo (issue548).
Greg Ward <greg-hg@gerg.ca>
parents:
diff
changeset
|
232 dictionaries, alltags and tagtypes, that contain all tag |
abb7d4d43a5f
Factor tags module out of localrepo (issue548).
Greg Ward <greg-hg@gerg.ca>
parents:
diff
changeset
|
233 info (global across all heads plus local).''' |
abb7d4d43a5f
Factor tags module out of localrepo (issue548).
Greg Ward <greg-hg@gerg.ca>
parents:
diff
changeset
|
234 |
abb7d4d43a5f
Factor tags module out of localrepo (issue548).
Greg Ward <greg-hg@gerg.ca>
parents:
diff
changeset
|
235 for name, nodehist in filetags.iteritems(): |
abb7d4d43a5f
Factor tags module out of localrepo (issue548).
Greg Ward <greg-hg@gerg.ca>
parents:
diff
changeset
|
236 if name not in alltags: |
abb7d4d43a5f
Factor tags module out of localrepo (issue548).
Greg Ward <greg-hg@gerg.ca>
parents:
diff
changeset
|
237 alltags[name] = nodehist |
abb7d4d43a5f
Factor tags module out of localrepo (issue548).
Greg Ward <greg-hg@gerg.ca>
parents:
diff
changeset
|
238 tagtypes[name] = tagtype |
abb7d4d43a5f
Factor tags module out of localrepo (issue548).
Greg Ward <greg-hg@gerg.ca>
parents:
diff
changeset
|
239 continue |
abb7d4d43a5f
Factor tags module out of localrepo (issue548).
Greg Ward <greg-hg@gerg.ca>
parents:
diff
changeset
|
240 |
abb7d4d43a5f
Factor tags module out of localrepo (issue548).
Greg Ward <greg-hg@gerg.ca>
parents:
diff
changeset
|
241 # we prefer alltags[name] if: |
17407
e7cfe3587ea4
fix trivial spelling errors
Mads Kiilerich <mads@kiilerich.com>
parents:
17257
diff
changeset
|
242 # it supersedes us OR |
e7cfe3587ea4
fix trivial spelling errors
Mads Kiilerich <mads@kiilerich.com>
parents:
17257
diff
changeset
|
243 # mutual supersedes and it has a higher rank |
9157
abb7d4d43a5f
Factor tags module out of localrepo (issue548).
Greg Ward <greg-hg@gerg.ca>
parents:
diff
changeset
|
244 # otherwise we win because we're tip-most |
abb7d4d43a5f
Factor tags module out of localrepo (issue548).
Greg Ward <greg-hg@gerg.ca>
parents:
diff
changeset
|
245 anode, ahist = nodehist |
abb7d4d43a5f
Factor tags module out of localrepo (issue548).
Greg Ward <greg-hg@gerg.ca>
parents:
diff
changeset
|
246 bnode, bhist = alltags[name] |
abb7d4d43a5f
Factor tags module out of localrepo (issue548).
Greg Ward <greg-hg@gerg.ca>
parents:
diff
changeset
|
247 if (bnode != anode and anode in bhist and |
abb7d4d43a5f
Factor tags module out of localrepo (issue548).
Greg Ward <greg-hg@gerg.ca>
parents:
diff
changeset
|
248 (bnode not in ahist or len(bhist) > len(ahist))): |
abb7d4d43a5f
Factor tags module out of localrepo (issue548).
Greg Ward <greg-hg@gerg.ca>
parents:
diff
changeset
|
249 anode = bnode |
19108
cb95716da5fe
tags: update tag type only if tag node is updated (issue3911)
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
17407
diff
changeset
|
250 else: |
cb95716da5fe
tags: update tag type only if tag node is updated (issue3911)
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
17407
diff
changeset
|
251 tagtypes[name] = tagtype |
9157
abb7d4d43a5f
Factor tags module out of localrepo (issue548).
Greg Ward <greg-hg@gerg.ca>
parents:
diff
changeset
|
252 ahist.extend([n for n in bhist if n not in ahist]) |
abb7d4d43a5f
Factor tags module out of localrepo (issue548).
Greg Ward <greg-hg@gerg.ca>
parents:
diff
changeset
|
253 alltags[name] = anode, ahist |
abb7d4d43a5f
Factor tags module out of localrepo (issue548).
Greg Ward <greg-hg@gerg.ca>
parents:
diff
changeset
|
254 |
24916
b061a2049662
tags: have a different cache file per filter level
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
24914
diff
changeset
|
255 def _filename(repo): |
b061a2049662
tags: have a different cache file per filter level
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
24914
diff
changeset
|
256 """name of a tagcache file for a given repo or repoview""" |
24941
1062663808ce
tags: write a separate tags cache file for unfiltered repos
Gregory Szorc <gregory.szorc@gmail.com>
parents:
24940
diff
changeset
|
257 filename = 'cache/tags2' |
24916
b061a2049662
tags: have a different cache file per filter level
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
24914
diff
changeset
|
258 if repo.filtername: |
b061a2049662
tags: have a different cache file per filter level
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
24914
diff
changeset
|
259 filename = '%s-%s' % (filename, repo.filtername) |
b061a2049662
tags: have a different cache file per filter level
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
24914
diff
changeset
|
260 return filename |
b061a2049662
tags: have a different cache file per filter level
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
24914
diff
changeset
|
261 |
24575
c71edbafe603
tags: improve documentation
Gregory Szorc <gregory.szorc@gmail.com>
parents:
24198
diff
changeset
|
262 def _readtagcache(ui, repo): |
c71edbafe603
tags: improve documentation
Gregory Szorc <gregory.szorc@gmail.com>
parents:
24198
diff
changeset
|
263 '''Read the tag cache. |
9159
f528d1a93491
tags: implement persistent tag caching (issue548).
Greg Ward <greg-hg@gerg.ca>
parents:
9157
diff
changeset
|
264 |
24939
410f3856196f
tags: change format of tags cache files
Gregory Szorc <gregory.szorc@gmail.com>
parents:
24938
diff
changeset
|
265 Returns a tuple (heads, fnodes, validinfo, cachetags, shouldwrite). |
24575
c71edbafe603
tags: improve documentation
Gregory Szorc <gregory.szorc@gmail.com>
parents:
24198
diff
changeset
|
266 |
c71edbafe603
tags: improve documentation
Gregory Szorc <gregory.szorc@gmail.com>
parents:
24198
diff
changeset
|
267 If the cache is completely up-to-date, "cachetags" is a dict of the |
24939
410f3856196f
tags: change format of tags cache files
Gregory Szorc <gregory.szorc@gmail.com>
parents:
24938
diff
changeset
|
268 form returned by _readtags() and "heads", "fnodes", and "validinfo" are |
410f3856196f
tags: change format of tags cache files
Gregory Szorc <gregory.szorc@gmail.com>
parents:
24938
diff
changeset
|
269 None and "shouldwrite" is False. |
9159
f528d1a93491
tags: implement persistent tag caching (issue548).
Greg Ward <greg-hg@gerg.ca>
parents:
9157
diff
changeset
|
270 |
24575
c71edbafe603
tags: improve documentation
Gregory Szorc <gregory.szorc@gmail.com>
parents:
24198
diff
changeset
|
271 If the cache is not up to date, "cachetags" is None. "heads" is a list |
c71edbafe603
tags: improve documentation
Gregory Szorc <gregory.szorc@gmail.com>
parents:
24198
diff
changeset
|
272 of all heads currently in the repository, ordered from tip to oldest. |
24939
410f3856196f
tags: change format of tags cache files
Gregory Szorc <gregory.szorc@gmail.com>
parents:
24938
diff
changeset
|
273 "validinfo" is a tuple describing cache validation info. This is used |
410f3856196f
tags: change format of tags cache files
Gregory Szorc <gregory.szorc@gmail.com>
parents:
24938
diff
changeset
|
274 when writing the tags cache. "fnodes" is a mapping from head to .hgtags |
410f3856196f
tags: change format of tags cache files
Gregory Szorc <gregory.szorc@gmail.com>
parents:
24938
diff
changeset
|
275 filenode. "shouldwrite" is True. |
24575
c71edbafe603
tags: improve documentation
Gregory Szorc <gregory.szorc@gmail.com>
parents:
24198
diff
changeset
|
276 |
c71edbafe603
tags: improve documentation
Gregory Szorc <gregory.szorc@gmail.com>
parents:
24198
diff
changeset
|
277 If the cache is not up to date, the caller is responsible for reading tag |
c71edbafe603
tags: improve documentation
Gregory Szorc <gregory.szorc@gmail.com>
parents:
24198
diff
changeset
|
278 info from each returned head. (See findglobaltags().) |
c71edbafe603
tags: improve documentation
Gregory Szorc <gregory.szorc@gmail.com>
parents:
24198
diff
changeset
|
279 ''' |
9159
f528d1a93491
tags: implement persistent tag caching (issue548).
Greg Ward <greg-hg@gerg.ca>
parents:
9157
diff
changeset
|
280 try: |
24916
b061a2049662
tags: have a different cache file per filter level
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
24914
diff
changeset
|
281 cachefile = repo.vfs(_filename(repo), 'r') |
11066
26abd91d9e84
static-http: mimic more closely localrepo (issue2164: allow clone -r )
Nicolas Dumazet <nicdumz.commits@gmail.com>
parents:
10263
diff
changeset
|
282 # force reading the file for static-http |
26abd91d9e84
static-http: mimic more closely localrepo (issue2164: allow clone -r )
Nicolas Dumazet <nicdumz.commits@gmail.com>
parents:
10263
diff
changeset
|
283 cachelines = iter(cachefile) |
9159
f528d1a93491
tags: implement persistent tag caching (issue548).
Greg Ward <greg-hg@gerg.ca>
parents:
9157
diff
changeset
|
284 except IOError: |
f528d1a93491
tags: implement persistent tag caching (issue548).
Greg Ward <greg-hg@gerg.ca>
parents:
9157
diff
changeset
|
285 cachefile = None |
f528d1a93491
tags: implement persistent tag caching (issue548).
Greg Ward <greg-hg@gerg.ca>
parents:
9157
diff
changeset
|
286 |
24939
410f3856196f
tags: change format of tags cache files
Gregory Szorc <gregory.szorc@gmail.com>
parents:
24938
diff
changeset
|
287 cacherev = None |
410f3856196f
tags: change format of tags cache files
Gregory Szorc <gregory.szorc@gmail.com>
parents:
24938
diff
changeset
|
288 cachenode = None |
410f3856196f
tags: change format of tags cache files
Gregory Szorc <gregory.szorc@gmail.com>
parents:
24938
diff
changeset
|
289 cachehash = None |
9159
f528d1a93491
tags: implement persistent tag caching (issue548).
Greg Ward <greg-hg@gerg.ca>
parents:
9157
diff
changeset
|
290 if cachefile: |
12758
2d754eae430c
tags: do not fail if tags.cache is corrupted (issue2444)
Nicolas Dumazet <nicdumz.commits@gmail.com>
parents:
11352
diff
changeset
|
291 try: |
29966
ead25aa27a43
py3: convert to next() function
timeless <timeless@mozdev.org>
parents:
29789
diff
changeset
|
292 validline = next(cachelines) |
24939
410f3856196f
tags: change format of tags cache files
Gregory Szorc <gregory.szorc@gmail.com>
parents:
24938
diff
changeset
|
293 validline = validline.split() |
410f3856196f
tags: change format of tags cache files
Gregory Szorc <gregory.szorc@gmail.com>
parents:
24938
diff
changeset
|
294 cacherev = int(validline[0]) |
410f3856196f
tags: change format of tags cache files
Gregory Szorc <gregory.szorc@gmail.com>
parents:
24938
diff
changeset
|
295 cachenode = bin(validline[1]) |
410f3856196f
tags: change format of tags cache files
Gregory Szorc <gregory.szorc@gmail.com>
parents:
24938
diff
changeset
|
296 if len(validline) > 2: |
410f3856196f
tags: change format of tags cache files
Gregory Szorc <gregory.szorc@gmail.com>
parents:
24938
diff
changeset
|
297 cachehash = bin(validline[2]) |
14020
98f79a5c3086
tags: catch more corruption during cache parsing (issue2779)
Matt Mackall <mpm@selenic.com>
parents:
13341
diff
changeset
|
298 except Exception: |
24938
d082c6ef9ec3
tags: don't read .hgtags fnodes from tags cache files
Gregory Szorc <gregory.szorc@gmail.com>
parents:
24916
diff
changeset
|
299 # corruption of the cache, just recompute it. |
d082c6ef9ec3
tags: don't read .hgtags fnodes from tags cache files
Gregory Szorc <gregory.szorc@gmail.com>
parents:
24916
diff
changeset
|
300 pass |
9159
f528d1a93491
tags: implement persistent tag caching (issue548).
Greg Ward <greg-hg@gerg.ca>
parents:
9157
diff
changeset
|
301 |
f528d1a93491
tags: implement persistent tag caching (issue548).
Greg Ward <greg-hg@gerg.ca>
parents:
9157
diff
changeset
|
302 tipnode = repo.changelog.tip() |
f528d1a93491
tags: implement persistent tag caching (issue548).
Greg Ward <greg-hg@gerg.ca>
parents:
9157
diff
changeset
|
303 tiprev = len(repo.changelog) - 1 |
f528d1a93491
tags: implement persistent tag caching (issue548).
Greg Ward <greg-hg@gerg.ca>
parents:
9157
diff
changeset
|
304 |
f528d1a93491
tags: implement persistent tag caching (issue548).
Greg Ward <greg-hg@gerg.ca>
parents:
9157
diff
changeset
|
305 # Case 1 (common): tip is the same, so nothing has changed. |
f528d1a93491
tags: implement persistent tag caching (issue548).
Greg Ward <greg-hg@gerg.ca>
parents:
9157
diff
changeset
|
306 # (Unchanged tip trivially means no changesets have been added. |
f528d1a93491
tags: implement persistent tag caching (issue548).
Greg Ward <greg-hg@gerg.ca>
parents:
9157
diff
changeset
|
307 # But, thanks to localrepository.destroyed(), it also means none |
f528d1a93491
tags: implement persistent tag caching (issue548).
Greg Ward <greg-hg@gerg.ca>
parents:
9157
diff
changeset
|
308 # have been destroyed by strip or rollback.) |
24939
410f3856196f
tags: change format of tags cache files
Gregory Szorc <gregory.szorc@gmail.com>
parents:
24938
diff
changeset
|
309 if (cacherev == tiprev |
410f3856196f
tags: change format of tags cache files
Gregory Szorc <gregory.szorc@gmail.com>
parents:
24938
diff
changeset
|
310 and cachenode == tipnode |
410f3856196f
tags: change format of tags cache files
Gregory Szorc <gregory.szorc@gmail.com>
parents:
24938
diff
changeset
|
311 and cachehash == scmutil.filteredhash(repo, tiprev)): |
11066
26abd91d9e84
static-http: mimic more closely localrepo (issue2164: allow clone -r )
Nicolas Dumazet <nicdumz.commits@gmail.com>
parents:
10263
diff
changeset
|
312 tags = _readtags(ui, repo, cachelines, cachefile.name) |
9160
4017291c4c48
tags: support 'instant' tag retrieval (issue548)
Greg Ward <greg-hg@gerg.ca>
parents:
9159
diff
changeset
|
313 cachefile.close() |
24939
410f3856196f
tags: change format of tags cache files
Gregory Szorc <gregory.szorc@gmail.com>
parents:
24938
diff
changeset
|
314 return (None, None, None, tags, False) |
9160
4017291c4c48
tags: support 'instant' tag retrieval (issue548)
Greg Ward <greg-hg@gerg.ca>
parents:
9159
diff
changeset
|
315 if cachefile: |
4017291c4c48
tags: support 'instant' tag retrieval (issue548)
Greg Ward <greg-hg@gerg.ca>
parents:
9159
diff
changeset
|
316 cachefile.close() # ignore rest of file |
9312
c5f0825c1dbb
kill trailing whitespace
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
9160
diff
changeset
|
317 |
24939
410f3856196f
tags: change format of tags cache files
Gregory Szorc <gregory.szorc@gmail.com>
parents:
24938
diff
changeset
|
318 valid = (tiprev, tipnode, scmutil.filteredhash(repo, tiprev)) |
410f3856196f
tags: change format of tags cache files
Gregory Szorc <gregory.szorc@gmail.com>
parents:
24938
diff
changeset
|
319 |
9159
f528d1a93491
tags: implement persistent tag caching (issue548).
Greg Ward <greg-hg@gerg.ca>
parents:
9157
diff
changeset
|
320 repoheads = repo.heads() |
f528d1a93491
tags: implement persistent tag caching (issue548).
Greg Ward <greg-hg@gerg.ca>
parents:
9157
diff
changeset
|
321 # Case 2 (uncommon): empty repo; get out quickly and don't bother |
f528d1a93491
tags: implement persistent tag caching (issue548).
Greg Ward <greg-hg@gerg.ca>
parents:
9157
diff
changeset
|
322 # writing an empty cache. |
f528d1a93491
tags: implement persistent tag caching (issue548).
Greg Ward <greg-hg@gerg.ca>
parents:
9157
diff
changeset
|
323 if repoheads == [nullid]: |
24939
410f3856196f
tags: change format of tags cache files
Gregory Szorc <gregory.szorc@gmail.com>
parents:
24938
diff
changeset
|
324 return ([], {}, valid, {}, False) |
9159
f528d1a93491
tags: implement persistent tag caching (issue548).
Greg Ward <greg-hg@gerg.ca>
parents:
9157
diff
changeset
|
325 |
f528d1a93491
tags: implement persistent tag caching (issue548).
Greg Ward <greg-hg@gerg.ca>
parents:
9157
diff
changeset
|
326 # Case 3 (uncommon): cache file missing or empty. |
f528d1a93491
tags: implement persistent tag caching (issue548).
Greg Ward <greg-hg@gerg.ca>
parents:
9157
diff
changeset
|
327 |
f528d1a93491
tags: implement persistent tag caching (issue548).
Greg Ward <greg-hg@gerg.ca>
parents:
9157
diff
changeset
|
328 # Case 4 (uncommon): tip rev decreased. This should only happen |
f528d1a93491
tags: implement persistent tag caching (issue548).
Greg Ward <greg-hg@gerg.ca>
parents:
9157
diff
changeset
|
329 # when we're called from localrepository.destroyed(). Refresh the |
f528d1a93491
tags: implement persistent tag caching (issue548).
Greg Ward <greg-hg@gerg.ca>
parents:
9157
diff
changeset
|
330 # cache so future invocations will not see disappeared heads in the |
f528d1a93491
tags: implement persistent tag caching (issue548).
Greg Ward <greg-hg@gerg.ca>
parents:
9157
diff
changeset
|
331 # cache. |
f528d1a93491
tags: implement persistent tag caching (issue548).
Greg Ward <greg-hg@gerg.ca>
parents:
9157
diff
changeset
|
332 |
f528d1a93491
tags: implement persistent tag caching (issue548).
Greg Ward <greg-hg@gerg.ca>
parents:
9157
diff
changeset
|
333 # Case 5 (common): tip has changed, so we've added/replaced heads. |
f528d1a93491
tags: implement persistent tag caching (issue548).
Greg Ward <greg-hg@gerg.ca>
parents:
9157
diff
changeset
|
334 |
11352
b19067ee4507
tags: remove inactive debugging code.
Greg Ward <greg-hg@gerg.ca>
parents:
11351
diff
changeset
|
335 # As it happens, the code to handle cases 3, 4, 5 is the same. |
9159
f528d1a93491
tags: implement persistent tag caching (issue548).
Greg Ward <greg-hg@gerg.ca>
parents:
9157
diff
changeset
|
336 |
f528d1a93491
tags: implement persistent tag caching (issue548).
Greg Ward <greg-hg@gerg.ca>
parents:
9157
diff
changeset
|
337 # N.B. in case 4 (nodes destroyed), "new head" really means "newly |
f528d1a93491
tags: implement persistent tag caching (issue548).
Greg Ward <greg-hg@gerg.ca>
parents:
9157
diff
changeset
|
338 # exposed". |
16731
dd4ce44ff53c
tags: short-circuit if no tags have ever been committed
Bryan O'Sullivan <bryano@fb.com>
parents:
16589
diff
changeset
|
339 if not len(repo.file('.hgtags')): |
dd4ce44ff53c
tags: short-circuit if no tags have ever been committed
Bryan O'Sullivan <bryano@fb.com>
parents:
16589
diff
changeset
|
340 # No tags have ever been committed, so we can avoid a |
dd4ce44ff53c
tags: short-circuit if no tags have ever been committed
Bryan O'Sullivan <bryano@fb.com>
parents:
16589
diff
changeset
|
341 # potentially expensive search. |
24940
61a6d83280d3
tags: return empty list of heads for no .hgtags case
Gregory Szorc <gregory.szorc@gmail.com>
parents:
24939
diff
changeset
|
342 return ([], {}, valid, None, True) |
16731
dd4ce44ff53c
tags: short-circuit if no tags have ever been committed
Bryan O'Sullivan <bryano@fb.com>
parents:
16589
diff
changeset
|
343 |
31754
22fbca1d11ed
mercurial: switch to util.timer for all interval timings
Simon Farnsworth <simonfar@fb.com>
parents:
29966
diff
changeset
|
344 starttime = util.timer() |
21030
9ea132aee96c
tags: log events related to tags cache
Gregory Szorc <gregory.szorc@gmail.com>
parents:
19650
diff
changeset
|
345 |
9159
f528d1a93491
tags: implement persistent tag caching (issue548).
Greg Ward <greg-hg@gerg.ca>
parents:
9157
diff
changeset
|
346 # Now we have to lookup the .hgtags filenode for every new head. |
f528d1a93491
tags: implement persistent tag caching (issue548).
Greg Ward <greg-hg@gerg.ca>
parents:
9157
diff
changeset
|
347 # This is the most expensive part of finding tags, so performance |
f528d1a93491
tags: implement persistent tag caching (issue548).
Greg Ward <greg-hg@gerg.ca>
parents:
9157
diff
changeset
|
348 # depends primarily on the size of newheads. Worst case: no cache |
f528d1a93491
tags: implement persistent tag caching (issue548).
Greg Ward <greg-hg@gerg.ca>
parents:
9157
diff
changeset
|
349 # file, so newheads == repoheads. |
24914
07200e3332a1
tags: extract .hgtags filenodes cache to a standalone file
Gregory Szorc <gregory.szorc@gmail.com>
parents:
24665
diff
changeset
|
350 fnodescache = hgtagsfnodescache(repo.unfiltered()) |
24938
d082c6ef9ec3
tags: don't read .hgtags fnodes from tags cache files
Gregory Szorc <gregory.szorc@gmail.com>
parents:
24916
diff
changeset
|
351 cachefnode = {} |
d082c6ef9ec3
tags: don't read .hgtags fnodes from tags cache files
Gregory Szorc <gregory.szorc@gmail.com>
parents:
24916
diff
changeset
|
352 for head in reversed(repoheads): |
24914
07200e3332a1
tags: extract .hgtags filenodes cache to a standalone file
Gregory Szorc <gregory.szorc@gmail.com>
parents:
24665
diff
changeset
|
353 fnode = fnodescache.getfnode(head) |
07200e3332a1
tags: extract .hgtags filenodes cache to a standalone file
Gregory Szorc <gregory.szorc@gmail.com>
parents:
24665
diff
changeset
|
354 if fnode != nullid: |
9159
f528d1a93491
tags: implement persistent tag caching (issue548).
Greg Ward <greg-hg@gerg.ca>
parents:
9157
diff
changeset
|
355 cachefnode[head] = fnode |
24914
07200e3332a1
tags: extract .hgtags filenodes cache to a standalone file
Gregory Szorc <gregory.szorc@gmail.com>
parents:
24665
diff
changeset
|
356 |
07200e3332a1
tags: extract .hgtags filenodes cache to a standalone file
Gregory Szorc <gregory.szorc@gmail.com>
parents:
24665
diff
changeset
|
357 fnodescache.write() |
9159
f528d1a93491
tags: implement persistent tag caching (issue548).
Greg Ward <greg-hg@gerg.ca>
parents:
9157
diff
changeset
|
358 |
31754
22fbca1d11ed
mercurial: switch to util.timer for all interval timings
Simon Farnsworth <simonfar@fb.com>
parents:
29966
diff
changeset
|
359 duration = util.timer() - starttime |
21030
9ea132aee96c
tags: log events related to tags cache
Gregory Szorc <gregory.szorc@gmail.com>
parents:
19650
diff
changeset
|
360 ui.log('tagscache', |
24914
07200e3332a1
tags: extract .hgtags filenodes cache to a standalone file
Gregory Szorc <gregory.szorc@gmail.com>
parents:
24665
diff
changeset
|
361 '%d/%d cache hits/lookups in %0.4f ' |
21030
9ea132aee96c
tags: log events related to tags cache
Gregory Szorc <gregory.szorc@gmail.com>
parents:
19650
diff
changeset
|
362 'seconds\n', |
24914
07200e3332a1
tags: extract .hgtags filenodes cache to a standalone file
Gregory Szorc <gregory.szorc@gmail.com>
parents:
24665
diff
changeset
|
363 fnodescache.hitcount, fnodescache.lookupcount, duration) |
21030
9ea132aee96c
tags: log events related to tags cache
Gregory Szorc <gregory.szorc@gmail.com>
parents:
19650
diff
changeset
|
364 |
9159
f528d1a93491
tags: implement persistent tag caching (issue548).
Greg Ward <greg-hg@gerg.ca>
parents:
9157
diff
changeset
|
365 # Caller has to iterate over all heads, but can use the filenodes in |
f528d1a93491
tags: implement persistent tag caching (issue548).
Greg Ward <greg-hg@gerg.ca>
parents:
9157
diff
changeset
|
366 # cachefnode to get to each .hgtags revision quickly. |
24939
410f3856196f
tags: change format of tags cache files
Gregory Szorc <gregory.szorc@gmail.com>
parents:
24938
diff
changeset
|
367 return (repoheads, cachefnode, valid, None, True) |
9159
f528d1a93491
tags: implement persistent tag caching (issue548).
Greg Ward <greg-hg@gerg.ca>
parents:
9157
diff
changeset
|
368 |
24939
410f3856196f
tags: change format of tags cache files
Gregory Szorc <gregory.szorc@gmail.com>
parents:
24938
diff
changeset
|
369 def _writetagcache(ui, repo, valid, cachetags): |
24942
a698e088ad29
tags: explicitly log which tags cache file is being written
Gregory Szorc <gregory.szorc@gmail.com>
parents:
24941
diff
changeset
|
370 filename = _filename(repo) |
9366
9ff178e7b627
tags: don't crash if unable to write tag cache
Greg Ward <greg-hg@gerg.ca>
parents:
9312
diff
changeset
|
371 try: |
24942
a698e088ad29
tags: explicitly log which tags cache file is being written
Gregory Szorc <gregory.szorc@gmail.com>
parents:
24941
diff
changeset
|
372 cachefile = repo.vfs(filename, 'w', atomictemp=True) |
9366
9ff178e7b627
tags: don't crash if unable to write tag cache
Greg Ward <greg-hg@gerg.ca>
parents:
9312
diff
changeset
|
373 except (OSError, IOError): |
9ff178e7b627
tags: don't crash if unable to write tag cache
Greg Ward <greg-hg@gerg.ca>
parents:
9312
diff
changeset
|
374 return |
9159
f528d1a93491
tags: implement persistent tag caching (issue548).
Greg Ward <greg-hg@gerg.ca>
parents:
9157
diff
changeset
|
375 |
24942
a698e088ad29
tags: explicitly log which tags cache file is being written
Gregory Szorc <gregory.szorc@gmail.com>
parents:
24941
diff
changeset
|
376 ui.log('tagscache', 'writing .hg/%s with %d tags\n', |
a698e088ad29
tags: explicitly log which tags cache file is being written
Gregory Szorc <gregory.szorc@gmail.com>
parents:
24941
diff
changeset
|
377 filename, len(cachetags)) |
21030
9ea132aee96c
tags: log events related to tags cache
Gregory Szorc <gregory.szorc@gmail.com>
parents:
19650
diff
changeset
|
378 |
24939
410f3856196f
tags: change format of tags cache files
Gregory Szorc <gregory.szorc@gmail.com>
parents:
24938
diff
changeset
|
379 if valid[2]: |
410f3856196f
tags: change format of tags cache files
Gregory Szorc <gregory.szorc@gmail.com>
parents:
24938
diff
changeset
|
380 cachefile.write('%d %s %s\n' % (valid[0], hex(valid[1]), hex(valid[2]))) |
410f3856196f
tags: change format of tags cache files
Gregory Szorc <gregory.szorc@gmail.com>
parents:
24938
diff
changeset
|
381 else: |
410f3856196f
tags: change format of tags cache files
Gregory Szorc <gregory.szorc@gmail.com>
parents:
24938
diff
changeset
|
382 cachefile.write('%d %s\n' % (valid[0], hex(valid[1]))) |
9159
f528d1a93491
tags: implement persistent tag caching (issue548).
Greg Ward <greg-hg@gerg.ca>
parents:
9157
diff
changeset
|
383 |
9160
4017291c4c48
tags: support 'instant' tag retrieval (issue548)
Greg Ward <greg-hg@gerg.ca>
parents:
9159
diff
changeset
|
384 # Tag names in the cache are in UTF-8 -- which is the whole reason |
4017291c4c48
tags: support 'instant' tag retrieval (issue548)
Greg Ward <greg-hg@gerg.ca>
parents:
9159
diff
changeset
|
385 # we keep them in UTF-8 throughout this module. If we converted |
4017291c4c48
tags: support 'instant' tag retrieval (issue548)
Greg Ward <greg-hg@gerg.ca>
parents:
9159
diff
changeset
|
386 # them local encoding on input, we would lose info writing them to |
4017291c4c48
tags: support 'instant' tag retrieval (issue548)
Greg Ward <greg-hg@gerg.ca>
parents:
9159
diff
changeset
|
387 # the cache. |
24198
7b09dbbbd502
tags: write tags cache deterministically
Gregory Szorc <gregory.szorc@gmail.com>
parents:
23889
diff
changeset
|
388 for (name, (node, hist)) in sorted(cachetags.iteritems()): |
19650
335a558f81dc
tags: write tag overwriting history also into tag cache file (issue3911)
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
19108
diff
changeset
|
389 for n in hist: |
335a558f81dc
tags: write tag overwriting history also into tag cache file (issue3911)
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
19108
diff
changeset
|
390 cachefile.write("%s %s\n" % (hex(n), name)) |
9160
4017291c4c48
tags: support 'instant' tag retrieval (issue548)
Greg Ward <greg-hg@gerg.ca>
parents:
9159
diff
changeset
|
391 cachefile.write("%s %s\n" % (hex(node), name)) |
4017291c4c48
tags: support 'instant' tag retrieval (issue548)
Greg Ward <greg-hg@gerg.ca>
parents:
9159
diff
changeset
|
392 |
14662
2b30124c7d8a
tags: don't allow environment errors to be raised from _writetagscache
Steve Borho <steve@borho.org>
parents:
14170
diff
changeset
|
393 try: |
15057
774da7121fc9
atomictempfile: make close() consistent with other file-like objects.
Greg Ward <greg@gerg.ca>
parents:
14662
diff
changeset
|
394 cachefile.close() |
14662
2b30124c7d8a
tags: don't allow environment errors to be raised from _writetagscache
Steve Borho <steve@borho.org>
parents:
14170
diff
changeset
|
395 except (OSError, IOError): |
2b30124c7d8a
tags: don't allow environment errors to be raised from _writetagscache
Steve Borho <steve@borho.org>
parents:
14170
diff
changeset
|
396 pass |
24914
07200e3332a1
tags: extract .hgtags filenodes cache to a standalone file
Gregory Szorc <gregory.szorc@gmail.com>
parents:
24665
diff
changeset
|
397 |
32447
7d0459706716
tags: move '_tags' from 'repo' to 'tags' module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
32139
diff
changeset
|
398 def _tag(repo, names, node, message, local, user, date, extra=None, |
7d0459706716
tags: move '_tags' from 'repo' to 'tags' module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
32139
diff
changeset
|
399 editor=False): |
7d0459706716
tags: move '_tags' from 'repo' to 'tags' module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
32139
diff
changeset
|
400 if isinstance(names, str): |
7d0459706716
tags: move '_tags' from 'repo' to 'tags' module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
32139
diff
changeset
|
401 names = (names,) |
7d0459706716
tags: move '_tags' from 'repo' to 'tags' module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
32139
diff
changeset
|
402 |
7d0459706716
tags: move '_tags' from 'repo' to 'tags' module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
32139
diff
changeset
|
403 branches = repo.branchmap() |
7d0459706716
tags: move '_tags' from 'repo' to 'tags' module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
32139
diff
changeset
|
404 for name in names: |
7d0459706716
tags: move '_tags' from 'repo' to 'tags' module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
32139
diff
changeset
|
405 repo.hook('pretag', throw=True, node=hex(node), tag=name, |
7d0459706716
tags: move '_tags' from 'repo' to 'tags' module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
32139
diff
changeset
|
406 local=local) |
7d0459706716
tags: move '_tags' from 'repo' to 'tags' module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
32139
diff
changeset
|
407 if name in branches: |
7d0459706716
tags: move '_tags' from 'repo' to 'tags' module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
32139
diff
changeset
|
408 repo.ui.warn(_("warning: tag %s conflicts with existing" |
7d0459706716
tags: move '_tags' from 'repo' to 'tags' module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
32139
diff
changeset
|
409 " branch name\n") % name) |
7d0459706716
tags: move '_tags' from 'repo' to 'tags' module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
32139
diff
changeset
|
410 |
7d0459706716
tags: move '_tags' from 'repo' to 'tags' module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
32139
diff
changeset
|
411 def writetags(fp, names, munge, prevtags): |
7d0459706716
tags: move '_tags' from 'repo' to 'tags' module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
32139
diff
changeset
|
412 fp.seek(0, 2) |
7d0459706716
tags: move '_tags' from 'repo' to 'tags' module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
32139
diff
changeset
|
413 if prevtags and prevtags[-1] != '\n': |
7d0459706716
tags: move '_tags' from 'repo' to 'tags' module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
32139
diff
changeset
|
414 fp.write('\n') |
7d0459706716
tags: move '_tags' from 'repo' to 'tags' module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
32139
diff
changeset
|
415 for name in names: |
7d0459706716
tags: move '_tags' from 'repo' to 'tags' module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
32139
diff
changeset
|
416 if munge: |
7d0459706716
tags: move '_tags' from 'repo' to 'tags' module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
32139
diff
changeset
|
417 m = munge(name) |
7d0459706716
tags: move '_tags' from 'repo' to 'tags' module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
32139
diff
changeset
|
418 else: |
7d0459706716
tags: move '_tags' from 'repo' to 'tags' module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
32139
diff
changeset
|
419 m = name |
7d0459706716
tags: move '_tags' from 'repo' to 'tags' module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
32139
diff
changeset
|
420 |
7d0459706716
tags: move '_tags' from 'repo' to 'tags' module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
32139
diff
changeset
|
421 if (repo._tagscache.tagtypes and |
7d0459706716
tags: move '_tags' from 'repo' to 'tags' module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
32139
diff
changeset
|
422 name in repo._tagscache.tagtypes): |
7d0459706716
tags: move '_tags' from 'repo' to 'tags' module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
32139
diff
changeset
|
423 old = repo.tags().get(name, nullid) |
7d0459706716
tags: move '_tags' from 'repo' to 'tags' module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
32139
diff
changeset
|
424 fp.write('%s %s\n' % (hex(old), m)) |
7d0459706716
tags: move '_tags' from 'repo' to 'tags' module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
32139
diff
changeset
|
425 fp.write('%s %s\n' % (hex(node), m)) |
7d0459706716
tags: move '_tags' from 'repo' to 'tags' module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
32139
diff
changeset
|
426 fp.close() |
7d0459706716
tags: move '_tags' from 'repo' to 'tags' module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
32139
diff
changeset
|
427 |
7d0459706716
tags: move '_tags' from 'repo' to 'tags' module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
32139
diff
changeset
|
428 prevtags = '' |
7d0459706716
tags: move '_tags' from 'repo' to 'tags' module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
32139
diff
changeset
|
429 if local: |
7d0459706716
tags: move '_tags' from 'repo' to 'tags' module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
32139
diff
changeset
|
430 try: |
7d0459706716
tags: move '_tags' from 'repo' to 'tags' module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
32139
diff
changeset
|
431 fp = repo.vfs('localtags', 'r+') |
7d0459706716
tags: move '_tags' from 'repo' to 'tags' module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
32139
diff
changeset
|
432 except IOError: |
7d0459706716
tags: move '_tags' from 'repo' to 'tags' module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
32139
diff
changeset
|
433 fp = repo.vfs('localtags', 'a') |
7d0459706716
tags: move '_tags' from 'repo' to 'tags' module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
32139
diff
changeset
|
434 else: |
7d0459706716
tags: move '_tags' from 'repo' to 'tags' module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
32139
diff
changeset
|
435 prevtags = fp.read() |
7d0459706716
tags: move '_tags' from 'repo' to 'tags' module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
32139
diff
changeset
|
436 |
7d0459706716
tags: move '_tags' from 'repo' to 'tags' module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
32139
diff
changeset
|
437 # local tags are stored in the current charset |
7d0459706716
tags: move '_tags' from 'repo' to 'tags' module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
32139
diff
changeset
|
438 writetags(fp, names, None, prevtags) |
7d0459706716
tags: move '_tags' from 'repo' to 'tags' module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
32139
diff
changeset
|
439 for name in names: |
7d0459706716
tags: move '_tags' from 'repo' to 'tags' module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
32139
diff
changeset
|
440 repo.hook('tag', node=hex(node), tag=name, local=local) |
7d0459706716
tags: move '_tags' from 'repo' to 'tags' module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
32139
diff
changeset
|
441 return |
7d0459706716
tags: move '_tags' from 'repo' to 'tags' module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
32139
diff
changeset
|
442 |
7d0459706716
tags: move '_tags' from 'repo' to 'tags' module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
32139
diff
changeset
|
443 try: |
7d0459706716
tags: move '_tags' from 'repo' to 'tags' module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
32139
diff
changeset
|
444 fp = repo.wvfs('.hgtags', 'rb+') |
7d0459706716
tags: move '_tags' from 'repo' to 'tags' module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
32139
diff
changeset
|
445 except IOError as e: |
7d0459706716
tags: move '_tags' from 'repo' to 'tags' module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
32139
diff
changeset
|
446 if e.errno != errno.ENOENT: |
7d0459706716
tags: move '_tags' from 'repo' to 'tags' module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
32139
diff
changeset
|
447 raise |
7d0459706716
tags: move '_tags' from 'repo' to 'tags' module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
32139
diff
changeset
|
448 fp = repo.wvfs('.hgtags', 'ab') |
7d0459706716
tags: move '_tags' from 'repo' to 'tags' module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
32139
diff
changeset
|
449 else: |
7d0459706716
tags: move '_tags' from 'repo' to 'tags' module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
32139
diff
changeset
|
450 prevtags = fp.read() |
7d0459706716
tags: move '_tags' from 'repo' to 'tags' module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
32139
diff
changeset
|
451 |
7d0459706716
tags: move '_tags' from 'repo' to 'tags' module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
32139
diff
changeset
|
452 # committed tags are stored in UTF-8 |
7d0459706716
tags: move '_tags' from 'repo' to 'tags' module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
32139
diff
changeset
|
453 writetags(fp, names, encoding.fromlocal, prevtags) |
7d0459706716
tags: move '_tags' from 'repo' to 'tags' module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
32139
diff
changeset
|
454 |
7d0459706716
tags: move '_tags' from 'repo' to 'tags' module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
32139
diff
changeset
|
455 fp.close() |
7d0459706716
tags: move '_tags' from 'repo' to 'tags' module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
32139
diff
changeset
|
456 |
7d0459706716
tags: move '_tags' from 'repo' to 'tags' module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
32139
diff
changeset
|
457 repo.invalidatecaches() |
7d0459706716
tags: move '_tags' from 'repo' to 'tags' module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
32139
diff
changeset
|
458 |
7d0459706716
tags: move '_tags' from 'repo' to 'tags' module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
32139
diff
changeset
|
459 if '.hgtags' not in repo.dirstate: |
7d0459706716
tags: move '_tags' from 'repo' to 'tags' module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
32139
diff
changeset
|
460 repo[None].add(['.hgtags']) |
7d0459706716
tags: move '_tags' from 'repo' to 'tags' module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
32139
diff
changeset
|
461 |
7d0459706716
tags: move '_tags' from 'repo' to 'tags' module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
32139
diff
changeset
|
462 m = matchmod.exact(repo.root, '', ['.hgtags']) |
7d0459706716
tags: move '_tags' from 'repo' to 'tags' module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
32139
diff
changeset
|
463 tagnode = repo.commit(message, user, date, extra=extra, match=m, |
7d0459706716
tags: move '_tags' from 'repo' to 'tags' module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
32139
diff
changeset
|
464 editor=editor) |
7d0459706716
tags: move '_tags' from 'repo' to 'tags' module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
32139
diff
changeset
|
465 |
7d0459706716
tags: move '_tags' from 'repo' to 'tags' module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
32139
diff
changeset
|
466 for name in names: |
7d0459706716
tags: move '_tags' from 'repo' to 'tags' module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
32139
diff
changeset
|
467 repo.hook('tag', node=hex(node), tag=name, local=local) |
7d0459706716
tags: move '_tags' from 'repo' to 'tags' module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
32139
diff
changeset
|
468 |
7d0459706716
tags: move '_tags' from 'repo' to 'tags' module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
32139
diff
changeset
|
469 return tagnode |
7d0459706716
tags: move '_tags' from 'repo' to 'tags' module
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
32139
diff
changeset
|
470 |
24914
07200e3332a1
tags: extract .hgtags filenodes cache to a standalone file
Gregory Szorc <gregory.szorc@gmail.com>
parents:
24665
diff
changeset
|
471 _fnodescachefile = 'cache/hgtagsfnodes1' |
07200e3332a1
tags: extract .hgtags filenodes cache to a standalone file
Gregory Szorc <gregory.szorc@gmail.com>
parents:
24665
diff
changeset
|
472 _fnodesrecsize = 4 + 20 # changeset fragment + filenode |
07200e3332a1
tags: extract .hgtags filenodes cache to a standalone file
Gregory Szorc <gregory.szorc@gmail.com>
parents:
24665
diff
changeset
|
473 _fnodesmissingrec = '\xff' * 24 |
07200e3332a1
tags: extract .hgtags filenodes cache to a standalone file
Gregory Szorc <gregory.szorc@gmail.com>
parents:
24665
diff
changeset
|
474 |
07200e3332a1
tags: extract .hgtags filenodes cache to a standalone file
Gregory Szorc <gregory.szorc@gmail.com>
parents:
24665
diff
changeset
|
475 class hgtagsfnodescache(object): |
07200e3332a1
tags: extract .hgtags filenodes cache to a standalone file
Gregory Szorc <gregory.szorc@gmail.com>
parents:
24665
diff
changeset
|
476 """Persistent cache mapping revisions to .hgtags filenodes. |
07200e3332a1
tags: extract .hgtags filenodes cache to a standalone file
Gregory Szorc <gregory.szorc@gmail.com>
parents:
24665
diff
changeset
|
477 |
07200e3332a1
tags: extract .hgtags filenodes cache to a standalone file
Gregory Szorc <gregory.szorc@gmail.com>
parents:
24665
diff
changeset
|
478 The cache is an array of records. Each item in the array corresponds to |
07200e3332a1
tags: extract .hgtags filenodes cache to a standalone file
Gregory Szorc <gregory.szorc@gmail.com>
parents:
24665
diff
changeset
|
479 a changelog revision. Values in the array contain the first 4 bytes of |
07200e3332a1
tags: extract .hgtags filenodes cache to a standalone file
Gregory Szorc <gregory.szorc@gmail.com>
parents:
24665
diff
changeset
|
480 the node hash and the 20 bytes .hgtags filenode for that revision. |
07200e3332a1
tags: extract .hgtags filenodes cache to a standalone file
Gregory Szorc <gregory.szorc@gmail.com>
parents:
24665
diff
changeset
|
481 |
07200e3332a1
tags: extract .hgtags filenodes cache to a standalone file
Gregory Szorc <gregory.szorc@gmail.com>
parents:
24665
diff
changeset
|
482 The first 4 bytes are present as a form of verification. Repository |
07200e3332a1
tags: extract .hgtags filenodes cache to a standalone file
Gregory Szorc <gregory.szorc@gmail.com>
parents:
24665
diff
changeset
|
483 stripping and rewriting may change the node at a numeric revision in the |
07200e3332a1
tags: extract .hgtags filenodes cache to a standalone file
Gregory Szorc <gregory.szorc@gmail.com>
parents:
24665
diff
changeset
|
484 changelog. The changeset fragment serves as a verifier to detect |
07200e3332a1
tags: extract .hgtags filenodes cache to a standalone file
Gregory Szorc <gregory.szorc@gmail.com>
parents:
24665
diff
changeset
|
485 rewriting. This logic is shared with the rev branch cache (see |
07200e3332a1
tags: extract .hgtags filenodes cache to a standalone file
Gregory Szorc <gregory.szorc@gmail.com>
parents:
24665
diff
changeset
|
486 branchmap.py). |
07200e3332a1
tags: extract .hgtags filenodes cache to a standalone file
Gregory Szorc <gregory.szorc@gmail.com>
parents:
24665
diff
changeset
|
487 |
07200e3332a1
tags: extract .hgtags filenodes cache to a standalone file
Gregory Szorc <gregory.szorc@gmail.com>
parents:
24665
diff
changeset
|
488 The instance holds in memory the full cache content but entries are |
07200e3332a1
tags: extract .hgtags filenodes cache to a standalone file
Gregory Szorc <gregory.szorc@gmail.com>
parents:
24665
diff
changeset
|
489 only parsed on read. |
07200e3332a1
tags: extract .hgtags filenodes cache to a standalone file
Gregory Szorc <gregory.szorc@gmail.com>
parents:
24665
diff
changeset
|
490 |
07200e3332a1
tags: extract .hgtags filenodes cache to a standalone file
Gregory Szorc <gregory.szorc@gmail.com>
parents:
24665
diff
changeset
|
491 Instances behave like lists. ``c[i]`` works where i is a rev or |
07200e3332a1
tags: extract .hgtags filenodes cache to a standalone file
Gregory Szorc <gregory.szorc@gmail.com>
parents:
24665
diff
changeset
|
492 changeset node. Missing indexes are populated automatically on access. |
07200e3332a1
tags: extract .hgtags filenodes cache to a standalone file
Gregory Szorc <gregory.szorc@gmail.com>
parents:
24665
diff
changeset
|
493 """ |
07200e3332a1
tags: extract .hgtags filenodes cache to a standalone file
Gregory Szorc <gregory.szorc@gmail.com>
parents:
24665
diff
changeset
|
494 def __init__(self, repo): |
07200e3332a1
tags: extract .hgtags filenodes cache to a standalone file
Gregory Szorc <gregory.szorc@gmail.com>
parents:
24665
diff
changeset
|
495 assert repo.filtername is None |
07200e3332a1
tags: extract .hgtags filenodes cache to a standalone file
Gregory Szorc <gregory.szorc@gmail.com>
parents:
24665
diff
changeset
|
496 |
07200e3332a1
tags: extract .hgtags filenodes cache to a standalone file
Gregory Szorc <gregory.szorc@gmail.com>
parents:
24665
diff
changeset
|
497 self._repo = repo |
07200e3332a1
tags: extract .hgtags filenodes cache to a standalone file
Gregory Szorc <gregory.szorc@gmail.com>
parents:
24665
diff
changeset
|
498 |
07200e3332a1
tags: extract .hgtags filenodes cache to a standalone file
Gregory Szorc <gregory.szorc@gmail.com>
parents:
24665
diff
changeset
|
499 # Only for reporting purposes. |
07200e3332a1
tags: extract .hgtags filenodes cache to a standalone file
Gregory Szorc <gregory.szorc@gmail.com>
parents:
24665
diff
changeset
|
500 self.lookupcount = 0 |
07200e3332a1
tags: extract .hgtags filenodes cache to a standalone file
Gregory Szorc <gregory.szorc@gmail.com>
parents:
24665
diff
changeset
|
501 self.hitcount = 0 |
07200e3332a1
tags: extract .hgtags filenodes cache to a standalone file
Gregory Szorc <gregory.szorc@gmail.com>
parents:
24665
diff
changeset
|
502 |
07200e3332a1
tags: extract .hgtags filenodes cache to a standalone file
Gregory Szorc <gregory.szorc@gmail.com>
parents:
24665
diff
changeset
|
503 |
29789
e3055b46ed1b
tags: silence hgtagsfnodes reading failures
Matt Mackall <mpm@selenic.com>
parents:
29788
diff
changeset
|
504 try: |
e3055b46ed1b
tags: silence hgtagsfnodes reading failures
Matt Mackall <mpm@selenic.com>
parents:
29788
diff
changeset
|
505 data = repo.vfs.read(_fnodescachefile) |
e3055b46ed1b
tags: silence hgtagsfnodes reading failures
Matt Mackall <mpm@selenic.com>
parents:
29788
diff
changeset
|
506 except (OSError, IOError): |
e3055b46ed1b
tags: silence hgtagsfnodes reading failures
Matt Mackall <mpm@selenic.com>
parents:
29788
diff
changeset
|
507 data = "" |
32125
2a18e9e6ca43
py3: use bytearray() instead of array('c', ...) constructions
Augie Fackler <augie@google.com>
parents:
31804
diff
changeset
|
508 self._raw = bytearray(data) |
24914
07200e3332a1
tags: extract .hgtags filenodes cache to a standalone file
Gregory Szorc <gregory.szorc@gmail.com>
parents:
24665
diff
changeset
|
509 |
07200e3332a1
tags: extract .hgtags filenodes cache to a standalone file
Gregory Szorc <gregory.szorc@gmail.com>
parents:
24665
diff
changeset
|
510 # The end state of self._raw is an array that is of the exact length |
07200e3332a1
tags: extract .hgtags filenodes cache to a standalone file
Gregory Szorc <gregory.szorc@gmail.com>
parents:
24665
diff
changeset
|
511 # required to hold a record for every revision in the repository. |
07200e3332a1
tags: extract .hgtags filenodes cache to a standalone file
Gregory Szorc <gregory.szorc@gmail.com>
parents:
24665
diff
changeset
|
512 # We truncate or extend the array as necessary. self._dirtyoffset is |
07200e3332a1
tags: extract .hgtags filenodes cache to a standalone file
Gregory Szorc <gregory.szorc@gmail.com>
parents:
24665
diff
changeset
|
513 # defined to be the start offset at which we need to write the output |
07200e3332a1
tags: extract .hgtags filenodes cache to a standalone file
Gregory Szorc <gregory.szorc@gmail.com>
parents:
24665
diff
changeset
|
514 # file. This offset is also adjusted when new entries are calculated |
07200e3332a1
tags: extract .hgtags filenodes cache to a standalone file
Gregory Szorc <gregory.szorc@gmail.com>
parents:
24665
diff
changeset
|
515 # for array members. |
07200e3332a1
tags: extract .hgtags filenodes cache to a standalone file
Gregory Szorc <gregory.szorc@gmail.com>
parents:
24665
diff
changeset
|
516 cllen = len(repo.changelog) |
07200e3332a1
tags: extract .hgtags filenodes cache to a standalone file
Gregory Szorc <gregory.szorc@gmail.com>
parents:
24665
diff
changeset
|
517 wantedlen = cllen * _fnodesrecsize |
07200e3332a1
tags: extract .hgtags filenodes cache to a standalone file
Gregory Szorc <gregory.szorc@gmail.com>
parents:
24665
diff
changeset
|
518 rawlen = len(self._raw) |
07200e3332a1
tags: extract .hgtags filenodes cache to a standalone file
Gregory Szorc <gregory.szorc@gmail.com>
parents:
24665
diff
changeset
|
519 |
07200e3332a1
tags: extract .hgtags filenodes cache to a standalone file
Gregory Szorc <gregory.szorc@gmail.com>
parents:
24665
diff
changeset
|
520 self._dirtyoffset = None |
07200e3332a1
tags: extract .hgtags filenodes cache to a standalone file
Gregory Szorc <gregory.szorc@gmail.com>
parents:
24665
diff
changeset
|
521 |
07200e3332a1
tags: extract .hgtags filenodes cache to a standalone file
Gregory Szorc <gregory.szorc@gmail.com>
parents:
24665
diff
changeset
|
522 if rawlen < wantedlen: |
07200e3332a1
tags: extract .hgtags filenodes cache to a standalone file
Gregory Szorc <gregory.szorc@gmail.com>
parents:
24665
diff
changeset
|
523 self._dirtyoffset = rawlen |
07200e3332a1
tags: extract .hgtags filenodes cache to a standalone file
Gregory Szorc <gregory.szorc@gmail.com>
parents:
24665
diff
changeset
|
524 self._raw.extend('\xff' * (wantedlen - rawlen)) |
07200e3332a1
tags: extract .hgtags filenodes cache to a standalone file
Gregory Szorc <gregory.szorc@gmail.com>
parents:
24665
diff
changeset
|
525 elif rawlen > wantedlen: |
07200e3332a1
tags: extract .hgtags filenodes cache to a standalone file
Gregory Szorc <gregory.szorc@gmail.com>
parents:
24665
diff
changeset
|
526 # There's no easy way to truncate array instances. This seems |
07200e3332a1
tags: extract .hgtags filenodes cache to a standalone file
Gregory Szorc <gregory.szorc@gmail.com>
parents:
24665
diff
changeset
|
527 # slightly less evil than copying a potentially large array slice. |
07200e3332a1
tags: extract .hgtags filenodes cache to a standalone file
Gregory Szorc <gregory.szorc@gmail.com>
parents:
24665
diff
changeset
|
528 for i in range(rawlen - wantedlen): |
07200e3332a1
tags: extract .hgtags filenodes cache to a standalone file
Gregory Szorc <gregory.szorc@gmail.com>
parents:
24665
diff
changeset
|
529 self._raw.pop() |
07200e3332a1
tags: extract .hgtags filenodes cache to a standalone file
Gregory Szorc <gregory.szorc@gmail.com>
parents:
24665
diff
changeset
|
530 self._dirtyoffset = len(self._raw) |
07200e3332a1
tags: extract .hgtags filenodes cache to a standalone file
Gregory Szorc <gregory.szorc@gmail.com>
parents:
24665
diff
changeset
|
531 |
25901
eaa456c5e699
tags: support reading tags cache without populating
Gregory Szorc <gregory.szorc@gmail.com>
parents:
25498
diff
changeset
|
532 def getfnode(self, node, computemissing=True): |
24914
07200e3332a1
tags: extract .hgtags filenodes cache to a standalone file
Gregory Szorc <gregory.szorc@gmail.com>
parents:
24665
diff
changeset
|
533 """Obtain the filenode of the .hgtags file at a specified revision. |
07200e3332a1
tags: extract .hgtags filenodes cache to a standalone file
Gregory Szorc <gregory.szorc@gmail.com>
parents:
24665
diff
changeset
|
534 |
07200e3332a1
tags: extract .hgtags filenodes cache to a standalone file
Gregory Szorc <gregory.szorc@gmail.com>
parents:
24665
diff
changeset
|
535 If the value is in the cache, the entry will be validated and returned. |
25901
eaa456c5e699
tags: support reading tags cache without populating
Gregory Szorc <gregory.szorc@gmail.com>
parents:
25498
diff
changeset
|
536 Otherwise, the filenode will be computed and returned unless |
eaa456c5e699
tags: support reading tags cache without populating
Gregory Szorc <gregory.szorc@gmail.com>
parents:
25498
diff
changeset
|
537 "computemissing" is False, in which case None will be returned without |
eaa456c5e699
tags: support reading tags cache without populating
Gregory Szorc <gregory.szorc@gmail.com>
parents:
25498
diff
changeset
|
538 any potentially expensive computation being performed. |
24914
07200e3332a1
tags: extract .hgtags filenodes cache to a standalone file
Gregory Szorc <gregory.szorc@gmail.com>
parents:
24665
diff
changeset
|
539 |
07200e3332a1
tags: extract .hgtags filenodes cache to a standalone file
Gregory Szorc <gregory.szorc@gmail.com>
parents:
24665
diff
changeset
|
540 If an .hgtags does not exist at the specified revision, nullid is |
07200e3332a1
tags: extract .hgtags filenodes cache to a standalone file
Gregory Szorc <gregory.szorc@gmail.com>
parents:
24665
diff
changeset
|
541 returned. |
07200e3332a1
tags: extract .hgtags filenodes cache to a standalone file
Gregory Szorc <gregory.szorc@gmail.com>
parents:
24665
diff
changeset
|
542 """ |
07200e3332a1
tags: extract .hgtags filenodes cache to a standalone file
Gregory Szorc <gregory.szorc@gmail.com>
parents:
24665
diff
changeset
|
543 ctx = self._repo[node] |
07200e3332a1
tags: extract .hgtags filenodes cache to a standalone file
Gregory Szorc <gregory.szorc@gmail.com>
parents:
24665
diff
changeset
|
544 rev = ctx.rev() |
07200e3332a1
tags: extract .hgtags filenodes cache to a standalone file
Gregory Szorc <gregory.szorc@gmail.com>
parents:
24665
diff
changeset
|
545 |
07200e3332a1
tags: extract .hgtags filenodes cache to a standalone file
Gregory Szorc <gregory.szorc@gmail.com>
parents:
24665
diff
changeset
|
546 self.lookupcount += 1 |
07200e3332a1
tags: extract .hgtags filenodes cache to a standalone file
Gregory Szorc <gregory.szorc@gmail.com>
parents:
24665
diff
changeset
|
547 |
07200e3332a1
tags: extract .hgtags filenodes cache to a standalone file
Gregory Szorc <gregory.szorc@gmail.com>
parents:
24665
diff
changeset
|
548 offset = rev * _fnodesrecsize |
32125
2a18e9e6ca43
py3: use bytearray() instead of array('c', ...) constructions
Augie Fackler <augie@google.com>
parents:
31804
diff
changeset
|
549 record = '%s' % self._raw[offset:offset + _fnodesrecsize] |
24914
07200e3332a1
tags: extract .hgtags filenodes cache to a standalone file
Gregory Szorc <gregory.szorc@gmail.com>
parents:
24665
diff
changeset
|
550 properprefix = node[0:4] |
07200e3332a1
tags: extract .hgtags filenodes cache to a standalone file
Gregory Szorc <gregory.szorc@gmail.com>
parents:
24665
diff
changeset
|
551 |
07200e3332a1
tags: extract .hgtags filenodes cache to a standalone file
Gregory Szorc <gregory.szorc@gmail.com>
parents:
24665
diff
changeset
|
552 # Validate and return existing entry. |
07200e3332a1
tags: extract .hgtags filenodes cache to a standalone file
Gregory Szorc <gregory.szorc@gmail.com>
parents:
24665
diff
changeset
|
553 if record != _fnodesmissingrec: |
07200e3332a1
tags: extract .hgtags filenodes cache to a standalone file
Gregory Szorc <gregory.szorc@gmail.com>
parents:
24665
diff
changeset
|
554 fileprefix = record[0:4] |
07200e3332a1
tags: extract .hgtags filenodes cache to a standalone file
Gregory Szorc <gregory.szorc@gmail.com>
parents:
24665
diff
changeset
|
555 |
07200e3332a1
tags: extract .hgtags filenodes cache to a standalone file
Gregory Szorc <gregory.szorc@gmail.com>
parents:
24665
diff
changeset
|
556 if fileprefix == properprefix: |
07200e3332a1
tags: extract .hgtags filenodes cache to a standalone file
Gregory Szorc <gregory.szorc@gmail.com>
parents:
24665
diff
changeset
|
557 self.hitcount += 1 |
07200e3332a1
tags: extract .hgtags filenodes cache to a standalone file
Gregory Szorc <gregory.szorc@gmail.com>
parents:
24665
diff
changeset
|
558 return record[4:] |
07200e3332a1
tags: extract .hgtags filenodes cache to a standalone file
Gregory Szorc <gregory.szorc@gmail.com>
parents:
24665
diff
changeset
|
559 |
07200e3332a1
tags: extract .hgtags filenodes cache to a standalone file
Gregory Szorc <gregory.szorc@gmail.com>
parents:
24665
diff
changeset
|
560 # Fall through. |
07200e3332a1
tags: extract .hgtags filenodes cache to a standalone file
Gregory Szorc <gregory.szorc@gmail.com>
parents:
24665
diff
changeset
|
561 |
25901
eaa456c5e699
tags: support reading tags cache without populating
Gregory Szorc <gregory.szorc@gmail.com>
parents:
25498
diff
changeset
|
562 # If we get here, the entry is either missing or invalid. |
eaa456c5e699
tags: support reading tags cache without populating
Gregory Szorc <gregory.szorc@gmail.com>
parents:
25498
diff
changeset
|
563 |
eaa456c5e699
tags: support reading tags cache without populating
Gregory Szorc <gregory.szorc@gmail.com>
parents:
25498
diff
changeset
|
564 if not computemissing: |
eaa456c5e699
tags: support reading tags cache without populating
Gregory Szorc <gregory.szorc@gmail.com>
parents:
25498
diff
changeset
|
565 return None |
eaa456c5e699
tags: support reading tags cache without populating
Gregory Szorc <gregory.szorc@gmail.com>
parents:
25498
diff
changeset
|
566 |
eaa456c5e699
tags: support reading tags cache without populating
Gregory Szorc <gregory.szorc@gmail.com>
parents:
25498
diff
changeset
|
567 # Populate missing entry. |
24914
07200e3332a1
tags: extract .hgtags filenodes cache to a standalone file
Gregory Szorc <gregory.szorc@gmail.com>
parents:
24665
diff
changeset
|
568 try: |
07200e3332a1
tags: extract .hgtags filenodes cache to a standalone file
Gregory Szorc <gregory.szorc@gmail.com>
parents:
24665
diff
changeset
|
569 fnode = ctx.filenode('.hgtags') |
07200e3332a1
tags: extract .hgtags filenodes cache to a standalone file
Gregory Szorc <gregory.szorc@gmail.com>
parents:
24665
diff
changeset
|
570 except error.LookupError: |
07200e3332a1
tags: extract .hgtags filenodes cache to a standalone file
Gregory Szorc <gregory.szorc@gmail.com>
parents:
24665
diff
changeset
|
571 # No .hgtags file on this revision. |
07200e3332a1
tags: extract .hgtags filenodes cache to a standalone file
Gregory Szorc <gregory.szorc@gmail.com>
parents:
24665
diff
changeset
|
572 fnode = nullid |
07200e3332a1
tags: extract .hgtags filenodes cache to a standalone file
Gregory Szorc <gregory.szorc@gmail.com>
parents:
24665
diff
changeset
|
573 |
25902
47edeff19139
tags: support setting hgtags fnodes cache entries
Gregory Szorc <gregory.szorc@gmail.com>
parents:
25901
diff
changeset
|
574 self._writeentry(offset, properprefix, fnode) |
47edeff19139
tags: support setting hgtags fnodes cache entries
Gregory Szorc <gregory.szorc@gmail.com>
parents:
25901
diff
changeset
|
575 return fnode |
47edeff19139
tags: support setting hgtags fnodes cache entries
Gregory Szorc <gregory.szorc@gmail.com>
parents:
25901
diff
changeset
|
576 |
47edeff19139
tags: support setting hgtags fnodes cache entries
Gregory Szorc <gregory.szorc@gmail.com>
parents:
25901
diff
changeset
|
577 def setfnode(self, node, fnode): |
47edeff19139
tags: support setting hgtags fnodes cache entries
Gregory Szorc <gregory.szorc@gmail.com>
parents:
25901
diff
changeset
|
578 """Set the .hgtags filenode for a given changeset.""" |
47edeff19139
tags: support setting hgtags fnodes cache entries
Gregory Szorc <gregory.szorc@gmail.com>
parents:
25901
diff
changeset
|
579 assert len(fnode) == 20 |
47edeff19139
tags: support setting hgtags fnodes cache entries
Gregory Szorc <gregory.szorc@gmail.com>
parents:
25901
diff
changeset
|
580 ctx = self._repo[node] |
47edeff19139
tags: support setting hgtags fnodes cache entries
Gregory Szorc <gregory.szorc@gmail.com>
parents:
25901
diff
changeset
|
581 |
47edeff19139
tags: support setting hgtags fnodes cache entries
Gregory Szorc <gregory.szorc@gmail.com>
parents:
25901
diff
changeset
|
582 # Do a lookup first to avoid writing if nothing has changed. |
47edeff19139
tags: support setting hgtags fnodes cache entries
Gregory Szorc <gregory.szorc@gmail.com>
parents:
25901
diff
changeset
|
583 if self.getfnode(ctx.node(), computemissing=False) == fnode: |
47edeff19139
tags: support setting hgtags fnodes cache entries
Gregory Szorc <gregory.szorc@gmail.com>
parents:
25901
diff
changeset
|
584 return |
47edeff19139
tags: support setting hgtags fnodes cache entries
Gregory Szorc <gregory.szorc@gmail.com>
parents:
25901
diff
changeset
|
585 |
47edeff19139
tags: support setting hgtags fnodes cache entries
Gregory Szorc <gregory.szorc@gmail.com>
parents:
25901
diff
changeset
|
586 self._writeentry(ctx.rev() * _fnodesrecsize, node[0:4], fnode) |
47edeff19139
tags: support setting hgtags fnodes cache entries
Gregory Szorc <gregory.szorc@gmail.com>
parents:
25901
diff
changeset
|
587 |
47edeff19139
tags: support setting hgtags fnodes cache entries
Gregory Szorc <gregory.szorc@gmail.com>
parents:
25901
diff
changeset
|
588 def _writeentry(self, offset, prefix, fnode): |
24914
07200e3332a1
tags: extract .hgtags filenodes cache to a standalone file
Gregory Szorc <gregory.szorc@gmail.com>
parents:
24665
diff
changeset
|
589 # Slices on array instances only accept other array. |
32125
2a18e9e6ca43
py3: use bytearray() instead of array('c', ...) constructions
Augie Fackler <augie@google.com>
parents:
31804
diff
changeset
|
590 entry = bytearray(prefix + fnode) |
24914
07200e3332a1
tags: extract .hgtags filenodes cache to a standalone file
Gregory Szorc <gregory.szorc@gmail.com>
parents:
24665
diff
changeset
|
591 self._raw[offset:offset + _fnodesrecsize] = entry |
07200e3332a1
tags: extract .hgtags filenodes cache to a standalone file
Gregory Szorc <gregory.szorc@gmail.com>
parents:
24665
diff
changeset
|
592 # self._dirtyoffset could be None. |
07200e3332a1
tags: extract .hgtags filenodes cache to a standalone file
Gregory Szorc <gregory.szorc@gmail.com>
parents:
24665
diff
changeset
|
593 self._dirtyoffset = min(self._dirtyoffset, offset) or 0 |
07200e3332a1
tags: extract .hgtags filenodes cache to a standalone file
Gregory Szorc <gregory.szorc@gmail.com>
parents:
24665
diff
changeset
|
594 |
07200e3332a1
tags: extract .hgtags filenodes cache to a standalone file
Gregory Szorc <gregory.szorc@gmail.com>
parents:
24665
diff
changeset
|
595 def write(self): |
07200e3332a1
tags: extract .hgtags filenodes cache to a standalone file
Gregory Szorc <gregory.szorc@gmail.com>
parents:
24665
diff
changeset
|
596 """Perform all necessary writes to cache file. |
07200e3332a1
tags: extract .hgtags filenodes cache to a standalone file
Gregory Szorc <gregory.szorc@gmail.com>
parents:
24665
diff
changeset
|
597 |
07200e3332a1
tags: extract .hgtags filenodes cache to a standalone file
Gregory Szorc <gregory.szorc@gmail.com>
parents:
24665
diff
changeset
|
598 This may no-op if no writes are needed or if a write lock could |
07200e3332a1
tags: extract .hgtags filenodes cache to a standalone file
Gregory Szorc <gregory.szorc@gmail.com>
parents:
24665
diff
changeset
|
599 not be obtained. |
07200e3332a1
tags: extract .hgtags filenodes cache to a standalone file
Gregory Szorc <gregory.szorc@gmail.com>
parents:
24665
diff
changeset
|
600 """ |
07200e3332a1
tags: extract .hgtags filenodes cache to a standalone file
Gregory Szorc <gregory.szorc@gmail.com>
parents:
24665
diff
changeset
|
601 if self._dirtyoffset is None: |
07200e3332a1
tags: extract .hgtags filenodes cache to a standalone file
Gregory Szorc <gregory.szorc@gmail.com>
parents:
24665
diff
changeset
|
602 return |
07200e3332a1
tags: extract .hgtags filenodes cache to a standalone file
Gregory Szorc <gregory.szorc@gmail.com>
parents:
24665
diff
changeset
|
603 |
07200e3332a1
tags: extract .hgtags filenodes cache to a standalone file
Gregory Szorc <gregory.szorc@gmail.com>
parents:
24665
diff
changeset
|
604 data = self._raw[self._dirtyoffset:] |
07200e3332a1
tags: extract .hgtags filenodes cache to a standalone file
Gregory Szorc <gregory.szorc@gmail.com>
parents:
24665
diff
changeset
|
605 if not data: |
07200e3332a1
tags: extract .hgtags filenodes cache to a standalone file
Gregory Szorc <gregory.szorc@gmail.com>
parents:
24665
diff
changeset
|
606 return |
07200e3332a1
tags: extract .hgtags filenodes cache to a standalone file
Gregory Szorc <gregory.szorc@gmail.com>
parents:
24665
diff
changeset
|
607 |
07200e3332a1
tags: extract .hgtags filenodes cache to a standalone file
Gregory Szorc <gregory.szorc@gmail.com>
parents:
24665
diff
changeset
|
608 repo = self._repo |
07200e3332a1
tags: extract .hgtags filenodes cache to a standalone file
Gregory Szorc <gregory.szorc@gmail.com>
parents:
24665
diff
changeset
|
609 |
07200e3332a1
tags: extract .hgtags filenodes cache to a standalone file
Gregory Szorc <gregory.szorc@gmail.com>
parents:
24665
diff
changeset
|
610 try: |
07200e3332a1
tags: extract .hgtags filenodes cache to a standalone file
Gregory Szorc <gregory.szorc@gmail.com>
parents:
24665
diff
changeset
|
611 lock = repo.wlock(wait=False) |
24985
61aea11fb83d
tags: do not abort if failed to write lock file to save cache
Yuya Nishihara <yuya@tcha.org>
parents:
24942
diff
changeset
|
612 except error.LockError: |
24914
07200e3332a1
tags: extract .hgtags filenodes cache to a standalone file
Gregory Szorc <gregory.szorc@gmail.com>
parents:
24665
diff
changeset
|
613 repo.ui.log('tagscache', |
24985
61aea11fb83d
tags: do not abort if failed to write lock file to save cache
Yuya Nishihara <yuya@tcha.org>
parents:
24942
diff
changeset
|
614 'not writing .hg/%s because lock cannot be acquired\n' % |
24914
07200e3332a1
tags: extract .hgtags filenodes cache to a standalone file
Gregory Szorc <gregory.szorc@gmail.com>
parents:
24665
diff
changeset
|
615 (_fnodescachefile)) |
07200e3332a1
tags: extract .hgtags filenodes cache to a standalone file
Gregory Szorc <gregory.szorc@gmail.com>
parents:
24665
diff
changeset
|
616 return |
07200e3332a1
tags: extract .hgtags filenodes cache to a standalone file
Gregory Szorc <gregory.szorc@gmail.com>
parents:
24665
diff
changeset
|
617 |
07200e3332a1
tags: extract .hgtags filenodes cache to a standalone file
Gregory Szorc <gregory.szorc@gmail.com>
parents:
24665
diff
changeset
|
618 try: |
25498
559f24e3957d
tags: use try/except/finally
Matt Mackall <mpm@selenic.com>
parents:
24985
diff
changeset
|
619 f = repo.vfs.open(_fnodescachefile, 'ab') |
24914
07200e3332a1
tags: extract .hgtags filenodes cache to a standalone file
Gregory Szorc <gregory.szorc@gmail.com>
parents:
24665
diff
changeset
|
620 try: |
25498
559f24e3957d
tags: use try/except/finally
Matt Mackall <mpm@selenic.com>
parents:
24985
diff
changeset
|
621 # if the file has been truncated |
559f24e3957d
tags: use try/except/finally
Matt Mackall <mpm@selenic.com>
parents:
24985
diff
changeset
|
622 actualoffset = f.tell() |
559f24e3957d
tags: use try/except/finally
Matt Mackall <mpm@selenic.com>
parents:
24985
diff
changeset
|
623 if actualoffset < self._dirtyoffset: |
559f24e3957d
tags: use try/except/finally
Matt Mackall <mpm@selenic.com>
parents:
24985
diff
changeset
|
624 self._dirtyoffset = actualoffset |
559f24e3957d
tags: use try/except/finally
Matt Mackall <mpm@selenic.com>
parents:
24985
diff
changeset
|
625 data = self._raw[self._dirtyoffset:] |
559f24e3957d
tags: use try/except/finally
Matt Mackall <mpm@selenic.com>
parents:
24985
diff
changeset
|
626 f.seek(self._dirtyoffset) |
559f24e3957d
tags: use try/except/finally
Matt Mackall <mpm@selenic.com>
parents:
24985
diff
changeset
|
627 f.truncate() |
24914
07200e3332a1
tags: extract .hgtags filenodes cache to a standalone file
Gregory Szorc <gregory.szorc@gmail.com>
parents:
24665
diff
changeset
|
628 repo.ui.log('tagscache', |
25498
559f24e3957d
tags: use try/except/finally
Matt Mackall <mpm@selenic.com>
parents:
24985
diff
changeset
|
629 'writing %d bytes to %s\n' % ( |
559f24e3957d
tags: use try/except/finally
Matt Mackall <mpm@selenic.com>
parents:
24985
diff
changeset
|
630 len(data), _fnodescachefile)) |
559f24e3957d
tags: use try/except/finally
Matt Mackall <mpm@selenic.com>
parents:
24985
diff
changeset
|
631 f.write(data) |
559f24e3957d
tags: use try/except/finally
Matt Mackall <mpm@selenic.com>
parents:
24985
diff
changeset
|
632 self._dirtyoffset = None |
559f24e3957d
tags: use try/except/finally
Matt Mackall <mpm@selenic.com>
parents:
24985
diff
changeset
|
633 finally: |
559f24e3957d
tags: use try/except/finally
Matt Mackall <mpm@selenic.com>
parents:
24985
diff
changeset
|
634 f.close() |
26214
328739ea70c3
global: mass rewrite to use modern exception syntax
Gregory Szorc <gregory.szorc@gmail.com>
parents:
25902
diff
changeset
|
635 except (IOError, OSError) as inst: |
25498
559f24e3957d
tags: use try/except/finally
Matt Mackall <mpm@selenic.com>
parents:
24985
diff
changeset
|
636 repo.ui.log('tagscache', |
559f24e3957d
tags: use try/except/finally
Matt Mackall <mpm@selenic.com>
parents:
24985
diff
changeset
|
637 "couldn't write %s: %s\n" % ( |
559f24e3957d
tags: use try/except/finally
Matt Mackall <mpm@selenic.com>
parents:
24985
diff
changeset
|
638 _fnodescachefile, inst)) |
24914
07200e3332a1
tags: extract .hgtags filenodes cache to a standalone file
Gregory Szorc <gregory.szorc@gmail.com>
parents:
24665
diff
changeset
|
639 finally: |
07200e3332a1
tags: extract .hgtags filenodes cache to a standalone file
Gregory Szorc <gregory.szorc@gmail.com>
parents:
24665
diff
changeset
|
640 lock.release() |