##// END OF EJS Templates
tags: validate nodes in _getfnodes() and update cache in case of unknown nodes...
Pulkit Goyal -
r47402:9a31f653 default
parent child Browse files
Show More
@@ -1,887 +1,916 b''
1 # tags.py - read tag info from local repository
1 # tags.py - read tag info from local repository
2 #
2 #
3 # Copyright 2009 Matt Mackall <mpm@selenic.com>
3 # Copyright 2009 Matt Mackall <mpm@selenic.com>
4 # Copyright 2009 Greg Ward <greg@gerg.ca>
4 # Copyright 2009 Greg Ward <greg@gerg.ca>
5 #
5 #
6 # This software may be used and distributed according to the terms of the
6 # This software may be used and distributed according to the terms of the
7 # GNU General Public License version 2 or any later version.
7 # GNU General Public License version 2 or any later version.
8
8
9 # Currently this module only deals with reading and caching tags.
9 # Currently this module only deals with reading and caching tags.
10 # Eventually, it could take care of updating (adding/removing/moving)
10 # Eventually, it could take care of updating (adding/removing/moving)
11 # tags too.
11 # tags too.
12
12
13 from __future__ import absolute_import
13 from __future__ import absolute_import
14
14
15 import errno
15 import errno
16 import io
16 import io
17
17
18 from .node import (
18 from .node import (
19 bin,
19 bin,
20 hex,
20 hex,
21 nullid,
21 nullid,
22 nullrev,
22 nullrev,
23 short,
23 short,
24 )
24 )
25 from .i18n import _
25 from .i18n import _
26 from . import (
26 from . import (
27 encoding,
27 encoding,
28 error,
28 error,
29 match as matchmod,
29 match as matchmod,
30 pycompat,
30 pycompat,
31 scmutil,
31 scmutil,
32 util,
32 util,
33 )
33 )
34 from .utils import stringutil
34 from .utils import stringutil
35
35
36 # Tags computation can be expensive and caches exist to make it fast in
36 # Tags computation can be expensive and caches exist to make it fast in
37 # the common case.
37 # the common case.
38 #
38 #
39 # The "hgtagsfnodes1" cache file caches the .hgtags filenode values for
39 # The "hgtagsfnodes1" cache file caches the .hgtags filenode values for
40 # each revision in the repository. The file is effectively an array of
40 # each revision in the repository. The file is effectively an array of
41 # fixed length records. Read the docs for "hgtagsfnodescache" for technical
41 # fixed length records. Read the docs for "hgtagsfnodescache" for technical
42 # details.
42 # details.
43 #
43 #
44 # The .hgtags filenode cache grows in proportion to the length of the
44 # The .hgtags filenode cache grows in proportion to the length of the
45 # changelog. The file is truncated when the # changelog is stripped.
45 # changelog. The file is truncated when the # changelog is stripped.
46 #
46 #
47 # The purpose of the filenode cache is to avoid the most expensive part
47 # The purpose of the filenode cache is to avoid the most expensive part
48 # of finding global tags, which is looking up the .hgtags filenode in the
48 # of finding global tags, which is looking up the .hgtags filenode in the
49 # manifest for each head. This can take dozens or over 100ms for
49 # manifest for each head. This can take dozens or over 100ms for
50 # repositories with very large manifests. Multiplied by dozens or even
50 # repositories with very large manifests. Multiplied by dozens or even
51 # hundreds of heads and there is a significant performance concern.
51 # hundreds of heads and there is a significant performance concern.
52 #
52 #
53 # There also exist a separate cache file for each repository filter.
53 # There also exist a separate cache file for each repository filter.
54 # These "tags-*" files store information about the history of tags.
54 # These "tags-*" files store information about the history of tags.
55 #
55 #
56 # The tags cache files consists of a cache validation line followed by
56 # The tags cache files consists of a cache validation line followed by
57 # a history of tags.
57 # a history of tags.
58 #
58 #
59 # The cache validation line has the format:
59 # The cache validation line has the format:
60 #
60 #
61 # <tiprev> <tipnode> [<filteredhash>]
61 # <tiprev> <tipnode> [<filteredhash>]
62 #
62 #
63 # <tiprev> is an integer revision and <tipnode> is a 40 character hex
63 # <tiprev> is an integer revision and <tipnode> is a 40 character hex
64 # node for that changeset. These redundantly identify the repository
64 # node for that changeset. These redundantly identify the repository
65 # tip from the time the cache was written. In addition, <filteredhash>,
65 # tip from the time the cache was written. In addition, <filteredhash>,
66 # if present, is a 40 character hex hash of the contents of the filtered
66 # if present, is a 40 character hex hash of the contents of the filtered
67 # revisions for this filter. If the set of filtered revs changes, the
67 # revisions for this filter. If the set of filtered revs changes, the
68 # hash will change and invalidate the cache.
68 # hash will change and invalidate the cache.
69 #
69 #
70 # The history part of the tags cache consists of lines of the form:
70 # The history part of the tags cache consists of lines of the form:
71 #
71 #
72 # <node> <tag>
72 # <node> <tag>
73 #
73 #
74 # (This format is identical to that of .hgtags files.)
74 # (This format is identical to that of .hgtags files.)
75 #
75 #
76 # <tag> is the tag name and <node> is the 40 character hex changeset
76 # <tag> is the tag name and <node> is the 40 character hex changeset
77 # the tag is associated with.
77 # the tag is associated with.
78 #
78 #
79 # Tags are written sorted by tag name.
79 # Tags are written sorted by tag name.
80 #
80 #
81 # Tags associated with multiple changesets have an entry for each changeset.
81 # Tags associated with multiple changesets have an entry for each changeset.
82 # The most recent changeset (in terms of revlog ordering for the head
82 # The most recent changeset (in terms of revlog ordering for the head
83 # setting it) for each tag is last.
83 # setting it) for each tag is last.
84
84
85
85
86 def fnoderevs(ui, repo, revs):
86 def fnoderevs(ui, repo, revs):
87 """return the list of '.hgtags' fnodes used in a set revisions
87 """return the list of '.hgtags' fnodes used in a set revisions
88
88
89 This is returned as list of unique fnodes. We use a list instead of a set
89 This is returned as list of unique fnodes. We use a list instead of a set
90 because order matters when it comes to tags."""
90 because order matters when it comes to tags."""
91 unfi = repo.unfiltered()
91 unfi = repo.unfiltered()
92 tonode = unfi.changelog.node
92 tonode = unfi.changelog.node
93 nodes = [tonode(r) for r in revs]
93 nodes = [tonode(r) for r in revs]
94 fnodes = _getfnodes(ui, repo, nodes)
94 fnodes = _getfnodes(ui, repo, nodes)
95 fnodes = _filterfnodes(fnodes, nodes)
95 fnodes = _filterfnodes(fnodes, nodes)
96 return fnodes
96 return fnodes
97
97
98
98
99 def _nulltonone(value):
99 def _nulltonone(value):
100 """convert nullid to None
100 """convert nullid to None
101
101
102 For tag value, nullid means "deleted". This small utility function helps
102 For tag value, nullid means "deleted". This small utility function helps
103 translating that to None."""
103 translating that to None."""
104 if value == nullid:
104 if value == nullid:
105 return None
105 return None
106 return value
106 return value
107
107
108
108
109 def difftags(ui, repo, oldfnodes, newfnodes):
109 def difftags(ui, repo, oldfnodes, newfnodes):
110 """list differences between tags expressed in two set of file-nodes
110 """list differences between tags expressed in two set of file-nodes
111
111
112 The list contains entries in the form: (tagname, oldvalue, new value).
112 The list contains entries in the form: (tagname, oldvalue, new value).
113 None is used to expressed missing value:
113 None is used to expressed missing value:
114 ('foo', None, 'abcd') is a new tag,
114 ('foo', None, 'abcd') is a new tag,
115 ('bar', 'ef01', None) is a deletion,
115 ('bar', 'ef01', None) is a deletion,
116 ('baz', 'abcd', 'ef01') is a tag movement.
116 ('baz', 'abcd', 'ef01') is a tag movement.
117 """
117 """
118 if oldfnodes == newfnodes:
118 if oldfnodes == newfnodes:
119 return []
119 return []
120 oldtags = _tagsfromfnodes(ui, repo, oldfnodes)
120 oldtags = _tagsfromfnodes(ui, repo, oldfnodes)
121 newtags = _tagsfromfnodes(ui, repo, newfnodes)
121 newtags = _tagsfromfnodes(ui, repo, newfnodes)
122
122
123 # list of (tag, old, new): None means missing
123 # list of (tag, old, new): None means missing
124 entries = []
124 entries = []
125 for tag, (new, __) in newtags.items():
125 for tag, (new, __) in newtags.items():
126 new = _nulltonone(new)
126 new = _nulltonone(new)
127 old, __ = oldtags.pop(tag, (None, None))
127 old, __ = oldtags.pop(tag, (None, None))
128 old = _nulltonone(old)
128 old = _nulltonone(old)
129 if old != new:
129 if old != new:
130 entries.append((tag, old, new))
130 entries.append((tag, old, new))
131 # handle deleted tags
131 # handle deleted tags
132 for tag, (old, __) in oldtags.items():
132 for tag, (old, __) in oldtags.items():
133 old = _nulltonone(old)
133 old = _nulltonone(old)
134 if old is not None:
134 if old is not None:
135 entries.append((tag, old, None))
135 entries.append((tag, old, None))
136 entries.sort()
136 entries.sort()
137 return entries
137 return entries
138
138
139
139
140 def writediff(fp, difflist):
140 def writediff(fp, difflist):
141 """write tags diff information to a file.
141 """write tags diff information to a file.
142
142
143 Data are stored with a line based format:
143 Data are stored with a line based format:
144
144
145 <action> <hex-node> <tag-name>\n
145 <action> <hex-node> <tag-name>\n
146
146
147 Action are defined as follow:
147 Action are defined as follow:
148 -R tag is removed,
148 -R tag is removed,
149 +A tag is added,
149 +A tag is added,
150 -M tag is moved (old value),
150 -M tag is moved (old value),
151 +M tag is moved (new value),
151 +M tag is moved (new value),
152
152
153 Example:
153 Example:
154
154
155 +A 875517b4806a848f942811a315a5bce30804ae85 t5
155 +A 875517b4806a848f942811a315a5bce30804ae85 t5
156
156
157 See documentation of difftags output for details about the input.
157 See documentation of difftags output for details about the input.
158 """
158 """
159 add = b'+A %s %s\n'
159 add = b'+A %s %s\n'
160 remove = b'-R %s %s\n'
160 remove = b'-R %s %s\n'
161 updateold = b'-M %s %s\n'
161 updateold = b'-M %s %s\n'
162 updatenew = b'+M %s %s\n'
162 updatenew = b'+M %s %s\n'
163 for tag, old, new in difflist:
163 for tag, old, new in difflist:
164 # translate to hex
164 # translate to hex
165 if old is not None:
165 if old is not None:
166 old = hex(old)
166 old = hex(old)
167 if new is not None:
167 if new is not None:
168 new = hex(new)
168 new = hex(new)
169 # write to file
169 # write to file
170 if old is None:
170 if old is None:
171 fp.write(add % (new, tag))
171 fp.write(add % (new, tag))
172 elif new is None:
172 elif new is None:
173 fp.write(remove % (old, tag))
173 fp.write(remove % (old, tag))
174 else:
174 else:
175 fp.write(updateold % (old, tag))
175 fp.write(updateold % (old, tag))
176 fp.write(updatenew % (new, tag))
176 fp.write(updatenew % (new, tag))
177
177
178
178
179 def findglobaltags(ui, repo):
179 def findglobaltags(ui, repo):
180 """Find global tags in a repo: return a tagsmap
180 """Find global tags in a repo: return a tagsmap
181
181
182 tagsmap: tag name to (node, hist) 2-tuples.
182 tagsmap: tag name to (node, hist) 2-tuples.
183
183
184 The tags cache is read and updated as a side-effect of calling.
184 The tags cache is read and updated as a side-effect of calling.
185 """
185 """
186 (heads, tagfnode, valid, cachetags, shouldwrite) = _readtagcache(ui, repo)
186 (heads, tagfnode, valid, cachetags, shouldwrite) = _readtagcache(ui, repo)
187 if cachetags is not None:
187 if cachetags is not None:
188 assert not shouldwrite
188 assert not shouldwrite
189 # XXX is this really 100% correct? are there oddball special
189 # XXX is this really 100% correct? are there oddball special
190 # cases where a global tag should outrank a local tag but won't,
190 # cases where a global tag should outrank a local tag but won't,
191 # because cachetags does not contain rank info?
191 # because cachetags does not contain rank info?
192 alltags = {}
192 alltags = {}
193 _updatetags(cachetags, alltags)
193 _updatetags(cachetags, alltags)
194 return alltags
194 return alltags
195
195
196 for head in reversed(heads): # oldest to newest
196 for head in reversed(heads): # oldest to newest
197 assert repo.changelog.index.has_node(
197 assert repo.changelog.index.has_node(
198 head
198 head
199 ), b"tag cache returned bogus head %s" % short(head)
199 ), b"tag cache returned bogus head %s" % short(head)
200 fnodes = _filterfnodes(tagfnode, reversed(heads))
200 fnodes = _filterfnodes(tagfnode, reversed(heads))
201 alltags = _tagsfromfnodes(ui, repo, fnodes)
201 alltags = _tagsfromfnodes(ui, repo, fnodes)
202
202
203 # and update the cache (if necessary)
203 # and update the cache (if necessary)
204 if shouldwrite:
204 if shouldwrite:
205 _writetagcache(ui, repo, valid, alltags)
205 _writetagcache(ui, repo, valid, alltags)
206 return alltags
206 return alltags
207
207
208
208
209 def _filterfnodes(tagfnode, nodes):
209 def _filterfnodes(tagfnode, nodes):
210 """return a list of unique fnodes
210 """return a list of unique fnodes
211
211
212 The order of this list matches the order of "nodes". Preserving this order
212 The order of this list matches the order of "nodes". Preserving this order
213 is important as reading tags in different order provides different
213 is important as reading tags in different order provides different
214 results."""
214 results."""
215 seen = set() # set of fnode
215 seen = set() # set of fnode
216 fnodes = []
216 fnodes = []
217 for no in nodes: # oldest to newest
217 for no in nodes: # oldest to newest
218 fnode = tagfnode.get(no)
218 fnode = tagfnode.get(no)
219 if fnode and fnode not in seen:
219 if fnode and fnode not in seen:
220 seen.add(fnode)
220 seen.add(fnode)
221 fnodes.append(fnode)
221 fnodes.append(fnode)
222 return fnodes
222 return fnodes
223
223
224
224
225 def _tagsfromfnodes(ui, repo, fnodes):
225 def _tagsfromfnodes(ui, repo, fnodes):
226 """return a tagsmap from a list of file-node
226 """return a tagsmap from a list of file-node
227
227
228 tagsmap: tag name to (node, hist) 2-tuples.
228 tagsmap: tag name to (node, hist) 2-tuples.
229
229
230 The order of the list matters."""
230 The order of the list matters."""
231 alltags = {}
231 alltags = {}
232 fctx = None
232 fctx = None
233 for fnode in fnodes:
233 for fnode in fnodes:
234 if fctx is None:
234 if fctx is None:
235 fctx = repo.filectx(b'.hgtags', fileid=fnode)
235 fctx = repo.filectx(b'.hgtags', fileid=fnode)
236 else:
236 else:
237 fctx = fctx.filectx(fnode)
237 fctx = fctx.filectx(fnode)
238 filetags = _readtags(ui, repo, fctx.data().splitlines(), fctx)
238 filetags = _readtags(ui, repo, fctx.data().splitlines(), fctx)
239 _updatetags(filetags, alltags)
239 _updatetags(filetags, alltags)
240 return alltags
240 return alltags
241
241
242
242
243 def readlocaltags(ui, repo, alltags, tagtypes):
243 def readlocaltags(ui, repo, alltags, tagtypes):
244 '''Read local tags in repo. Update alltags and tagtypes.'''
244 '''Read local tags in repo. Update alltags and tagtypes.'''
245 try:
245 try:
246 data = repo.vfs.read(b"localtags")
246 data = repo.vfs.read(b"localtags")
247 except IOError as inst:
247 except IOError as inst:
248 if inst.errno != errno.ENOENT:
248 if inst.errno != errno.ENOENT:
249 raise
249 raise
250 return
250 return
251
251
252 # localtags is in the local encoding; re-encode to UTF-8 on
252 # localtags is in the local encoding; re-encode to UTF-8 on
253 # input for consistency with the rest of this module.
253 # input for consistency with the rest of this module.
254 filetags = _readtags(
254 filetags = _readtags(
255 ui, repo, data.splitlines(), b"localtags", recode=encoding.fromlocal
255 ui, repo, data.splitlines(), b"localtags", recode=encoding.fromlocal
256 )
256 )
257
257
258 # remove tags pointing to invalid nodes
258 # remove tags pointing to invalid nodes
259 cl = repo.changelog
259 cl = repo.changelog
260 for t in list(filetags):
260 for t in list(filetags):
261 try:
261 try:
262 cl.rev(filetags[t][0])
262 cl.rev(filetags[t][0])
263 except (LookupError, ValueError):
263 except (LookupError, ValueError):
264 del filetags[t]
264 del filetags[t]
265
265
266 _updatetags(filetags, alltags, b'local', tagtypes)
266 _updatetags(filetags, alltags, b'local', tagtypes)
267
267
268
268
269 def _readtaghist(ui, repo, lines, fn, recode=None, calcnodelines=False):
269 def _readtaghist(ui, repo, lines, fn, recode=None, calcnodelines=False):
270 """Read tag definitions from a file (or any source of lines).
270 """Read tag definitions from a file (or any source of lines).
271
271
272 This function returns two sortdicts with similar information:
272 This function returns two sortdicts with similar information:
273
273
274 - the first dict, bintaghist, contains the tag information as expected by
274 - the first dict, bintaghist, contains the tag information as expected by
275 the _readtags function, i.e. a mapping from tag name to (node, hist):
275 the _readtags function, i.e. a mapping from tag name to (node, hist):
276 - node is the node id from the last line read for that name,
276 - node is the node id from the last line read for that name,
277 - hist is the list of node ids previously associated with it (in file
277 - hist is the list of node ids previously associated with it (in file
278 order). All node ids are binary, not hex.
278 order). All node ids are binary, not hex.
279
279
280 - the second dict, hextaglines, is a mapping from tag name to a list of
280 - the second dict, hextaglines, is a mapping from tag name to a list of
281 [hexnode, line number] pairs, ordered from the oldest to the newest node.
281 [hexnode, line number] pairs, ordered from the oldest to the newest node.
282
282
283 When calcnodelines is False the hextaglines dict is not calculated (an
283 When calcnodelines is False the hextaglines dict is not calculated (an
284 empty dict is returned). This is done to improve this function's
284 empty dict is returned). This is done to improve this function's
285 performance in cases where the line numbers are not needed.
285 performance in cases where the line numbers are not needed.
286 """
286 """
287
287
288 bintaghist = util.sortdict()
288 bintaghist = util.sortdict()
289 hextaglines = util.sortdict()
289 hextaglines = util.sortdict()
290 count = 0
290 count = 0
291
291
292 def dbg(msg):
292 def dbg(msg):
293 ui.debug(b"%s, line %d: %s\n" % (fn, count, msg))
293 ui.debug(b"%s, line %d: %s\n" % (fn, count, msg))
294
294
295 for nline, line in enumerate(lines):
295 for nline, line in enumerate(lines):
296 count += 1
296 count += 1
297 if not line:
297 if not line:
298 continue
298 continue
299 try:
299 try:
300 (nodehex, name) = line.split(b" ", 1)
300 (nodehex, name) = line.split(b" ", 1)
301 except ValueError:
301 except ValueError:
302 dbg(b"cannot parse entry")
302 dbg(b"cannot parse entry")
303 continue
303 continue
304 name = name.strip()
304 name = name.strip()
305 if recode:
305 if recode:
306 name = recode(name)
306 name = recode(name)
307 try:
307 try:
308 nodebin = bin(nodehex)
308 nodebin = bin(nodehex)
309 except TypeError:
309 except TypeError:
310 dbg(b"node '%s' is not well formed" % nodehex)
310 dbg(b"node '%s' is not well formed" % nodehex)
311 continue
311 continue
312
312
313 # update filetags
313 # update filetags
314 if calcnodelines:
314 if calcnodelines:
315 # map tag name to a list of line numbers
315 # map tag name to a list of line numbers
316 if name not in hextaglines:
316 if name not in hextaglines:
317 hextaglines[name] = []
317 hextaglines[name] = []
318 hextaglines[name].append([nodehex, nline])
318 hextaglines[name].append([nodehex, nline])
319 continue
319 continue
320 # map tag name to (node, hist)
320 # map tag name to (node, hist)
321 if name not in bintaghist:
321 if name not in bintaghist:
322 bintaghist[name] = []
322 bintaghist[name] = []
323 bintaghist[name].append(nodebin)
323 bintaghist[name].append(nodebin)
324 return bintaghist, hextaglines
324 return bintaghist, hextaglines
325
325
326
326
327 def _readtags(ui, repo, lines, fn, recode=None, calcnodelines=False):
327 def _readtags(ui, repo, lines, fn, recode=None, calcnodelines=False):
328 """Read tag definitions from a file (or any source of lines).
328 """Read tag definitions from a file (or any source of lines).
329
329
330 Returns a mapping from tag name to (node, hist).
330 Returns a mapping from tag name to (node, hist).
331
331
332 "node" is the node id from the last line read for that name. "hist"
332 "node" is the node id from the last line read for that name. "hist"
333 is the list of node ids previously associated with it (in file order).
333 is the list of node ids previously associated with it (in file order).
334 All node ids are binary, not hex.
334 All node ids are binary, not hex.
335 """
335 """
336 filetags, nodelines = _readtaghist(
336 filetags, nodelines = _readtaghist(
337 ui, repo, lines, fn, recode=recode, calcnodelines=calcnodelines
337 ui, repo, lines, fn, recode=recode, calcnodelines=calcnodelines
338 )
338 )
339 # util.sortdict().__setitem__ is much slower at replacing then inserting
339 # util.sortdict().__setitem__ is much slower at replacing then inserting
340 # new entries. The difference can matter if there are thousands of tags.
340 # new entries. The difference can matter if there are thousands of tags.
341 # Create a new sortdict to avoid the performance penalty.
341 # Create a new sortdict to avoid the performance penalty.
342 newtags = util.sortdict()
342 newtags = util.sortdict()
343 for tag, taghist in filetags.items():
343 for tag, taghist in filetags.items():
344 newtags[tag] = (taghist[-1], taghist[:-1])
344 newtags[tag] = (taghist[-1], taghist[:-1])
345 return newtags
345 return newtags
346
346
347
347
348 def _updatetags(filetags, alltags, tagtype=None, tagtypes=None):
348 def _updatetags(filetags, alltags, tagtype=None, tagtypes=None):
349 """Incorporate the tag info read from one file into dictionnaries
349 """Incorporate the tag info read from one file into dictionnaries
350
350
351 The first one, 'alltags', is a "tagmaps" (see 'findglobaltags' for details).
351 The first one, 'alltags', is a "tagmaps" (see 'findglobaltags' for details).
352
352
353 The second one, 'tagtypes', is optional and will be updated to track the
353 The second one, 'tagtypes', is optional and will be updated to track the
354 "tagtype" of entries in the tagmaps. When set, the 'tagtype' argument also
354 "tagtype" of entries in the tagmaps. When set, the 'tagtype' argument also
355 needs to be set."""
355 needs to be set."""
356 if tagtype is None:
356 if tagtype is None:
357 assert tagtypes is None
357 assert tagtypes is None
358
358
359 for name, nodehist in pycompat.iteritems(filetags):
359 for name, nodehist in pycompat.iteritems(filetags):
360 if name not in alltags:
360 if name not in alltags:
361 alltags[name] = nodehist
361 alltags[name] = nodehist
362 if tagtype is not None:
362 if tagtype is not None:
363 tagtypes[name] = tagtype
363 tagtypes[name] = tagtype
364 continue
364 continue
365
365
366 # we prefer alltags[name] if:
366 # we prefer alltags[name] if:
367 # it supersedes us OR
367 # it supersedes us OR
368 # mutual supersedes and it has a higher rank
368 # mutual supersedes and it has a higher rank
369 # otherwise we win because we're tip-most
369 # otherwise we win because we're tip-most
370 anode, ahist = nodehist
370 anode, ahist = nodehist
371 bnode, bhist = alltags[name]
371 bnode, bhist = alltags[name]
372 if (
372 if (
373 bnode != anode
373 bnode != anode
374 and anode in bhist
374 and anode in bhist
375 and (bnode not in ahist or len(bhist) > len(ahist))
375 and (bnode not in ahist or len(bhist) > len(ahist))
376 ):
376 ):
377 anode = bnode
377 anode = bnode
378 elif tagtype is not None:
378 elif tagtype is not None:
379 tagtypes[name] = tagtype
379 tagtypes[name] = tagtype
380 ahist.extend([n for n in bhist if n not in ahist])
380 ahist.extend([n for n in bhist if n not in ahist])
381 alltags[name] = anode, ahist
381 alltags[name] = anode, ahist
382
382
383
383
384 def _filename(repo):
384 def _filename(repo):
385 """name of a tagcache file for a given repo or repoview"""
385 """name of a tagcache file for a given repo or repoview"""
386 filename = b'tags2'
386 filename = b'tags2'
387 if repo.filtername:
387 if repo.filtername:
388 filename = b'%s-%s' % (filename, repo.filtername)
388 filename = b'%s-%s' % (filename, repo.filtername)
389 return filename
389 return filename
390
390
391
391
392 def _readtagcache(ui, repo):
392 def _readtagcache(ui, repo):
393 """Read the tag cache.
393 """Read the tag cache.
394
394
395 Returns a tuple (heads, fnodes, validinfo, cachetags, shouldwrite).
395 Returns a tuple (heads, fnodes, validinfo, cachetags, shouldwrite).
396
396
397 If the cache is completely up-to-date, "cachetags" is a dict of the
397 If the cache is completely up-to-date, "cachetags" is a dict of the
398 form returned by _readtags() and "heads", "fnodes", and "validinfo" are
398 form returned by _readtags() and "heads", "fnodes", and "validinfo" are
399 None and "shouldwrite" is False.
399 None and "shouldwrite" is False.
400
400
401 If the cache is not up to date, "cachetags" is None. "heads" is a list
401 If the cache is not up to date, "cachetags" is None. "heads" is a list
402 of all heads currently in the repository, ordered from tip to oldest.
402 of all heads currently in the repository, ordered from tip to oldest.
403 "validinfo" is a tuple describing cache validation info. This is used
403 "validinfo" is a tuple describing cache validation info. This is used
404 when writing the tags cache. "fnodes" is a mapping from head to .hgtags
404 when writing the tags cache. "fnodes" is a mapping from head to .hgtags
405 filenode. "shouldwrite" is True.
405 filenode. "shouldwrite" is True.
406
406
407 If the cache is not up to date, the caller is responsible for reading tag
407 If the cache is not up to date, the caller is responsible for reading tag
408 info from each returned head. (See findglobaltags().)
408 info from each returned head. (See findglobaltags().)
409 """
409 """
410 try:
410 try:
411 cachefile = repo.cachevfs(_filename(repo), b'r')
411 cachefile = repo.cachevfs(_filename(repo), b'r')
412 # force reading the file for static-http
412 # force reading the file for static-http
413 cachelines = iter(cachefile)
413 cachelines = iter(cachefile)
414 except IOError:
414 except IOError:
415 cachefile = None
415 cachefile = None
416
416
417 cacherev = None
417 cacherev = None
418 cachenode = None
418 cachenode = None
419 cachehash = None
419 cachehash = None
420 if cachefile:
420 if cachefile:
421 try:
421 try:
422 validline = next(cachelines)
422 validline = next(cachelines)
423 validline = validline.split()
423 validline = validline.split()
424 cacherev = int(validline[0])
424 cacherev = int(validline[0])
425 cachenode = bin(validline[1])
425 cachenode = bin(validline[1])
426 if len(validline) > 2:
426 if len(validline) > 2:
427 cachehash = bin(validline[2])
427 cachehash = bin(validline[2])
428 except Exception:
428 except Exception:
429 # corruption of the cache, just recompute it.
429 # corruption of the cache, just recompute it.
430 pass
430 pass
431
431
432 tipnode = repo.changelog.tip()
432 tipnode = repo.changelog.tip()
433 tiprev = len(repo.changelog) - 1
433 tiprev = len(repo.changelog) - 1
434
434
435 # Case 1 (common): tip is the same, so nothing has changed.
435 # Case 1 (common): tip is the same, so nothing has changed.
436 # (Unchanged tip trivially means no changesets have been added.
436 # (Unchanged tip trivially means no changesets have been added.
437 # But, thanks to localrepository.destroyed(), it also means none
437 # But, thanks to localrepository.destroyed(), it also means none
438 # have been destroyed by strip or rollback.)
438 # have been destroyed by strip or rollback.)
439 if (
439 if (
440 cacherev == tiprev
440 cacherev == tiprev
441 and cachenode == tipnode
441 and cachenode == tipnode
442 and cachehash == scmutil.filteredhash(repo, tiprev)
442 and cachehash == scmutil.filteredhash(repo, tiprev)
443 ):
443 ):
444 tags = _readtags(ui, repo, cachelines, cachefile.name)
444 tags = _readtags(ui, repo, cachelines, cachefile.name)
445 cachefile.close()
445 cachefile.close()
446 return (None, None, None, tags, False)
446 return (None, None, None, tags, False)
447 if cachefile:
447 if cachefile:
448 cachefile.close() # ignore rest of file
448 cachefile.close() # ignore rest of file
449
449
450 valid = (tiprev, tipnode, scmutil.filteredhash(repo, tiprev))
450 valid = (tiprev, tipnode, scmutil.filteredhash(repo, tiprev))
451
451
452 repoheads = repo.heads()
452 repoheads = repo.heads()
453 # Case 2 (uncommon): empty repo; get out quickly and don't bother
453 # Case 2 (uncommon): empty repo; get out quickly and don't bother
454 # writing an empty cache.
454 # writing an empty cache.
455 if repoheads == [nullid]:
455 if repoheads == [nullid]:
456 return ([], {}, valid, {}, False)
456 return ([], {}, valid, {}, False)
457
457
458 # Case 3 (uncommon): cache file missing or empty.
458 # Case 3 (uncommon): cache file missing or empty.
459
459
460 # Case 4 (uncommon): tip rev decreased. This should only happen
460 # Case 4 (uncommon): tip rev decreased. This should only happen
461 # when we're called from localrepository.destroyed(). Refresh the
461 # when we're called from localrepository.destroyed(). Refresh the
462 # cache so future invocations will not see disappeared heads in the
462 # cache so future invocations will not see disappeared heads in the
463 # cache.
463 # cache.
464
464
465 # Case 5 (common): tip has changed, so we've added/replaced heads.
465 # Case 5 (common): tip has changed, so we've added/replaced heads.
466
466
467 # As it happens, the code to handle cases 3, 4, 5 is the same.
467 # As it happens, the code to handle cases 3, 4, 5 is the same.
468
468
469 # N.B. in case 4 (nodes destroyed), "new head" really means "newly
469 # N.B. in case 4 (nodes destroyed), "new head" really means "newly
470 # exposed".
470 # exposed".
471 if not len(repo.file(b'.hgtags')):
471 if not len(repo.file(b'.hgtags')):
472 # No tags have ever been committed, so we can avoid a
472 # No tags have ever been committed, so we can avoid a
473 # potentially expensive search.
473 # potentially expensive search.
474 return ([], {}, valid, None, True)
474 return ([], {}, valid, None, True)
475
475
476 # Now we have to lookup the .hgtags filenode for every new head.
476 # Now we have to lookup the .hgtags filenode for every new head.
477 # This is the most expensive part of finding tags, so performance
477 # This is the most expensive part of finding tags, so performance
478 # depends primarily on the size of newheads. Worst case: no cache
478 # depends primarily on the size of newheads. Worst case: no cache
479 # file, so newheads == repoheads.
479 # file, so newheads == repoheads.
480 # Reversed order helps the cache ('repoheads' is in descending order)
480 # Reversed order helps the cache ('repoheads' is in descending order)
481 cachefnode = _getfnodes(ui, repo, reversed(repoheads))
481 cachefnode = _getfnodes(ui, repo, reversed(repoheads))
482
482
483 # Caller has to iterate over all heads, but can use the filenodes in
483 # Caller has to iterate over all heads, but can use the filenodes in
484 # cachefnode to get to each .hgtags revision quickly.
484 # cachefnode to get to each .hgtags revision quickly.
485 return (repoheads, cachefnode, valid, None, True)
485 return (repoheads, cachefnode, valid, None, True)
486
486
487
487
488 def _getfnodes(ui, repo, nodes):
488 def _getfnodes(ui, repo, nodes):
489 """return .hgtags fnodes for a list of changeset nodes
489 """return .hgtags fnodes for a list of changeset nodes
490
490
491 Return value is a {node: fnode} mapping. There will be no entry for nodes
491 Return value is a {node: fnode} mapping. There will be no entry for nodes
492 without a '.hgtags' file.
492 without a '.hgtags' file.
493 """
493 """
494 starttime = util.timer()
494 starttime = util.timer()
495 fnodescache = hgtagsfnodescache(repo.unfiltered())
495 fnodescache = hgtagsfnodescache(repo.unfiltered())
496 cachefnode = {}
496 cachefnode = {}
497 validated_fnodes = set()
498 unknown_entries = set()
497 for node in nodes:
499 for node in nodes:
498 fnode = fnodescache.getfnode(node)
500 fnode = fnodescache.getfnode(node)
501 flog = repo.file(b'.hgtags')
499 if fnode != nullid:
502 if fnode != nullid:
503 if fnode not in validated_fnodes:
504 if flog.hasnode(fnode):
505 validated_fnodes.add(fnode)
506 else:
507 unknown_entries.add(node)
500 cachefnode[node] = fnode
508 cachefnode[node] = fnode
501
509
510 if unknown_entries:
511 fixed_nodemap = fnodescache.refresh_invalid_nodes(unknown_entries)
512 for node, fnode in pycompat.iteritems(fixed_nodemap):
513 if fnode != nullid:
514 cachefnode[node] = fnode
515
502 fnodescache.write()
516 fnodescache.write()
503
517
504 duration = util.timer() - starttime
518 duration = util.timer() - starttime
505 ui.log(
519 ui.log(
506 b'tagscache',
520 b'tagscache',
507 b'%d/%d cache hits/lookups in %0.4f seconds\n',
521 b'%d/%d cache hits/lookups in %0.4f seconds\n',
508 fnodescache.hitcount,
522 fnodescache.hitcount,
509 fnodescache.lookupcount,
523 fnodescache.lookupcount,
510 duration,
524 duration,
511 )
525 )
512 return cachefnode
526 return cachefnode
513
527
514
528
515 def _writetagcache(ui, repo, valid, cachetags):
529 def _writetagcache(ui, repo, valid, cachetags):
516 filename = _filename(repo)
530 filename = _filename(repo)
517 try:
531 try:
518 cachefile = repo.cachevfs(filename, b'w', atomictemp=True)
532 cachefile = repo.cachevfs(filename, b'w', atomictemp=True)
519 except (OSError, IOError):
533 except (OSError, IOError):
520 return
534 return
521
535
522 ui.log(
536 ui.log(
523 b'tagscache',
537 b'tagscache',
524 b'writing .hg/cache/%s with %d tags\n',
538 b'writing .hg/cache/%s with %d tags\n',
525 filename,
539 filename,
526 len(cachetags),
540 len(cachetags),
527 )
541 )
528
542
529 if valid[2]:
543 if valid[2]:
530 cachefile.write(
544 cachefile.write(
531 b'%d %s %s\n' % (valid[0], hex(valid[1]), hex(valid[2]))
545 b'%d %s %s\n' % (valid[0], hex(valid[1]), hex(valid[2]))
532 )
546 )
533 else:
547 else:
534 cachefile.write(b'%d %s\n' % (valid[0], hex(valid[1])))
548 cachefile.write(b'%d %s\n' % (valid[0], hex(valid[1])))
535
549
536 # Tag names in the cache are in UTF-8 -- which is the whole reason
550 # Tag names in the cache are in UTF-8 -- which is the whole reason
537 # we keep them in UTF-8 throughout this module. If we converted
551 # we keep them in UTF-8 throughout this module. If we converted
538 # them local encoding on input, we would lose info writing them to
552 # them local encoding on input, we would lose info writing them to
539 # the cache.
553 # the cache.
540 for (name, (node, hist)) in sorted(pycompat.iteritems(cachetags)):
554 for (name, (node, hist)) in sorted(pycompat.iteritems(cachetags)):
541 for n in hist:
555 for n in hist:
542 cachefile.write(b"%s %s\n" % (hex(n), name))
556 cachefile.write(b"%s %s\n" % (hex(n), name))
543 cachefile.write(b"%s %s\n" % (hex(node), name))
557 cachefile.write(b"%s %s\n" % (hex(node), name))
544
558
545 try:
559 try:
546 cachefile.close()
560 cachefile.close()
547 except (OSError, IOError):
561 except (OSError, IOError):
548 pass
562 pass
549
563
550
564
551 def tag(repo, names, node, message, local, user, date, editor=False):
565 def tag(repo, names, node, message, local, user, date, editor=False):
552 """tag a revision with one or more symbolic names.
566 """tag a revision with one or more symbolic names.
553
567
554 names is a list of strings or, when adding a single tag, names may be a
568 names is a list of strings or, when adding a single tag, names may be a
555 string.
569 string.
556
570
557 if local is True, the tags are stored in a per-repository file.
571 if local is True, the tags are stored in a per-repository file.
558 otherwise, they are stored in the .hgtags file, and a new
572 otherwise, they are stored in the .hgtags file, and a new
559 changeset is committed with the change.
573 changeset is committed with the change.
560
574
561 keyword arguments:
575 keyword arguments:
562
576
563 local: whether to store tags in non-version-controlled file
577 local: whether to store tags in non-version-controlled file
564 (default False)
578 (default False)
565
579
566 message: commit message to use if committing
580 message: commit message to use if committing
567
581
568 user: name of user to use if committing
582 user: name of user to use if committing
569
583
570 date: date tuple to use if committing"""
584 date: date tuple to use if committing"""
571
585
572 if not local:
586 if not local:
573 m = matchmod.exact([b'.hgtags'])
587 m = matchmod.exact([b'.hgtags'])
574 st = repo.status(match=m, unknown=True, ignored=True)
588 st = repo.status(match=m, unknown=True, ignored=True)
575 if any(
589 if any(
576 (
590 (
577 st.modified,
591 st.modified,
578 st.added,
592 st.added,
579 st.removed,
593 st.removed,
580 st.deleted,
594 st.deleted,
581 st.unknown,
595 st.unknown,
582 st.ignored,
596 st.ignored,
583 )
597 )
584 ):
598 ):
585 raise error.Abort(
599 raise error.Abort(
586 _(b'working copy of .hgtags is changed'),
600 _(b'working copy of .hgtags is changed'),
587 hint=_(b'please commit .hgtags manually'),
601 hint=_(b'please commit .hgtags manually'),
588 )
602 )
589
603
590 with repo.wlock():
604 with repo.wlock():
591 repo.tags() # instantiate the cache
605 repo.tags() # instantiate the cache
592 _tag(repo, names, node, message, local, user, date, editor=editor)
606 _tag(repo, names, node, message, local, user, date, editor=editor)
593
607
594
608
595 def _tag(
609 def _tag(
596 repo, names, node, message, local, user, date, extra=None, editor=False
610 repo, names, node, message, local, user, date, extra=None, editor=False
597 ):
611 ):
598 if isinstance(names, bytes):
612 if isinstance(names, bytes):
599 names = (names,)
613 names = (names,)
600
614
601 branches = repo.branchmap()
615 branches = repo.branchmap()
602 for name in names:
616 for name in names:
603 repo.hook(b'pretag', throw=True, node=hex(node), tag=name, local=local)
617 repo.hook(b'pretag', throw=True, node=hex(node), tag=name, local=local)
604 if name in branches:
618 if name in branches:
605 repo.ui.warn(
619 repo.ui.warn(
606 _(b"warning: tag %s conflicts with existing branch name\n")
620 _(b"warning: tag %s conflicts with existing branch name\n")
607 % name
621 % name
608 )
622 )
609
623
610 def writetags(fp, names, munge, prevtags):
624 def writetags(fp, names, munge, prevtags):
611 fp.seek(0, io.SEEK_END)
625 fp.seek(0, io.SEEK_END)
612 if prevtags and not prevtags.endswith(b'\n'):
626 if prevtags and not prevtags.endswith(b'\n'):
613 fp.write(b'\n')
627 fp.write(b'\n')
614 for name in names:
628 for name in names:
615 if munge:
629 if munge:
616 m = munge(name)
630 m = munge(name)
617 else:
631 else:
618 m = name
632 m = name
619
633
620 if repo._tagscache.tagtypes and name in repo._tagscache.tagtypes:
634 if repo._tagscache.tagtypes and name in repo._tagscache.tagtypes:
621 old = repo.tags().get(name, nullid)
635 old = repo.tags().get(name, nullid)
622 fp.write(b'%s %s\n' % (hex(old), m))
636 fp.write(b'%s %s\n' % (hex(old), m))
623 fp.write(b'%s %s\n' % (hex(node), m))
637 fp.write(b'%s %s\n' % (hex(node), m))
624 fp.close()
638 fp.close()
625
639
626 prevtags = b''
640 prevtags = b''
627 if local:
641 if local:
628 try:
642 try:
629 fp = repo.vfs(b'localtags', b'r+')
643 fp = repo.vfs(b'localtags', b'r+')
630 except IOError:
644 except IOError:
631 fp = repo.vfs(b'localtags', b'a')
645 fp = repo.vfs(b'localtags', b'a')
632 else:
646 else:
633 prevtags = fp.read()
647 prevtags = fp.read()
634
648
635 # local tags are stored in the current charset
649 # local tags are stored in the current charset
636 writetags(fp, names, None, prevtags)
650 writetags(fp, names, None, prevtags)
637 for name in names:
651 for name in names:
638 repo.hook(b'tag', node=hex(node), tag=name, local=local)
652 repo.hook(b'tag', node=hex(node), tag=name, local=local)
639 return
653 return
640
654
641 try:
655 try:
642 fp = repo.wvfs(b'.hgtags', b'rb+')
656 fp = repo.wvfs(b'.hgtags', b'rb+')
643 except IOError as e:
657 except IOError as e:
644 if e.errno != errno.ENOENT:
658 if e.errno != errno.ENOENT:
645 raise
659 raise
646 fp = repo.wvfs(b'.hgtags', b'ab')
660 fp = repo.wvfs(b'.hgtags', b'ab')
647 else:
661 else:
648 prevtags = fp.read()
662 prevtags = fp.read()
649
663
650 # committed tags are stored in UTF-8
664 # committed tags are stored in UTF-8
651 writetags(fp, names, encoding.fromlocal, prevtags)
665 writetags(fp, names, encoding.fromlocal, prevtags)
652
666
653 fp.close()
667 fp.close()
654
668
655 repo.invalidatecaches()
669 repo.invalidatecaches()
656
670
657 if b'.hgtags' not in repo.dirstate:
671 if b'.hgtags' not in repo.dirstate:
658 repo[None].add([b'.hgtags'])
672 repo[None].add([b'.hgtags'])
659
673
660 m = matchmod.exact([b'.hgtags'])
674 m = matchmod.exact([b'.hgtags'])
661 tagnode = repo.commit(
675 tagnode = repo.commit(
662 message, user, date, extra=extra, match=m, editor=editor
676 message, user, date, extra=extra, match=m, editor=editor
663 )
677 )
664
678
665 for name in names:
679 for name in names:
666 repo.hook(b'tag', node=hex(node), tag=name, local=local)
680 repo.hook(b'tag', node=hex(node), tag=name, local=local)
667
681
668 return tagnode
682 return tagnode
669
683
670
684
671 _fnodescachefile = b'hgtagsfnodes1'
685 _fnodescachefile = b'hgtagsfnodes1'
672 _fnodesrecsize = 4 + 20 # changeset fragment + filenode
686 _fnodesrecsize = 4 + 20 # changeset fragment + filenode
673 _fnodesmissingrec = b'\xff' * 24
687 _fnodesmissingrec = b'\xff' * 24
674
688
675
689
676 class hgtagsfnodescache(object):
690 class hgtagsfnodescache(object):
677 """Persistent cache mapping revisions to .hgtags filenodes.
691 """Persistent cache mapping revisions to .hgtags filenodes.
678
692
679 The cache is an array of records. Each item in the array corresponds to
693 The cache is an array of records. Each item in the array corresponds to
680 a changelog revision. Values in the array contain the first 4 bytes of
694 a changelog revision. Values in the array contain the first 4 bytes of
681 the node hash and the 20 bytes .hgtags filenode for that revision.
695 the node hash and the 20 bytes .hgtags filenode for that revision.
682
696
683 The first 4 bytes are present as a form of verification. Repository
697 The first 4 bytes are present as a form of verification. Repository
684 stripping and rewriting may change the node at a numeric revision in the
698 stripping and rewriting may change the node at a numeric revision in the
685 changelog. The changeset fragment serves as a verifier to detect
699 changelog. The changeset fragment serves as a verifier to detect
686 rewriting. This logic is shared with the rev branch cache (see
700 rewriting. This logic is shared with the rev branch cache (see
687 branchmap.py).
701 branchmap.py).
688
702
689 The instance holds in memory the full cache content but entries are
703 The instance holds in memory the full cache content but entries are
690 only parsed on read.
704 only parsed on read.
691
705
692 Instances behave like lists. ``c[i]`` works where i is a rev or
706 Instances behave like lists. ``c[i]`` works where i is a rev or
693 changeset node. Missing indexes are populated automatically on access.
707 changeset node. Missing indexes are populated automatically on access.
694 """
708 """
695
709
696 def __init__(self, repo):
710 def __init__(self, repo):
697 assert repo.filtername is None
711 assert repo.filtername is None
698
712
699 self._repo = repo
713 self._repo = repo
700
714
701 # Only for reporting purposes.
715 # Only for reporting purposes.
702 self.lookupcount = 0
716 self.lookupcount = 0
703 self.hitcount = 0
717 self.hitcount = 0
704
718
705 try:
719 try:
706 data = repo.cachevfs.read(_fnodescachefile)
720 data = repo.cachevfs.read(_fnodescachefile)
707 except (OSError, IOError):
721 except (OSError, IOError):
708 data = b""
722 data = b""
709 self._raw = bytearray(data)
723 self._raw = bytearray(data)
710
724
711 # The end state of self._raw is an array that is of the exact length
725 # The end state of self._raw is an array that is of the exact length
712 # required to hold a record for every revision in the repository.
726 # required to hold a record for every revision in the repository.
713 # We truncate or extend the array as necessary. self._dirtyoffset is
727 # We truncate or extend the array as necessary. self._dirtyoffset is
714 # defined to be the start offset at which we need to write the output
728 # defined to be the start offset at which we need to write the output
715 # file. This offset is also adjusted when new entries are calculated
729 # file. This offset is also adjusted when new entries are calculated
716 # for array members.
730 # for array members.
717 cllen = len(repo.changelog)
731 cllen = len(repo.changelog)
718 wantedlen = cllen * _fnodesrecsize
732 wantedlen = cllen * _fnodesrecsize
719 rawlen = len(self._raw)
733 rawlen = len(self._raw)
720
734
721 self._dirtyoffset = None
735 self._dirtyoffset = None
722
736
723 rawlentokeep = min(
737 rawlentokeep = min(
724 wantedlen, (rawlen // _fnodesrecsize) * _fnodesrecsize
738 wantedlen, (rawlen // _fnodesrecsize) * _fnodesrecsize
725 )
739 )
726 if rawlen > rawlentokeep:
740 if rawlen > rawlentokeep:
727 # There's no easy way to truncate array instances. This seems
741 # There's no easy way to truncate array instances. This seems
728 # slightly less evil than copying a potentially large array slice.
742 # slightly less evil than copying a potentially large array slice.
729 for i in range(rawlen - rawlentokeep):
743 for i in range(rawlen - rawlentokeep):
730 self._raw.pop()
744 self._raw.pop()
731 rawlen = len(self._raw)
745 rawlen = len(self._raw)
732 self._dirtyoffset = rawlen
746 self._dirtyoffset = rawlen
733 if rawlen < wantedlen:
747 if rawlen < wantedlen:
734 if self._dirtyoffset is None:
748 if self._dirtyoffset is None:
735 self._dirtyoffset = rawlen
749 self._dirtyoffset = rawlen
736 # TODO: zero fill entire record, because it's invalid not missing?
750 # TODO: zero fill entire record, because it's invalid not missing?
737 self._raw.extend(b'\xff' * (wantedlen - rawlen))
751 self._raw.extend(b'\xff' * (wantedlen - rawlen))
738
752
739 def getfnode(self, node, computemissing=True):
753 def getfnode(self, node, computemissing=True):
740 """Obtain the filenode of the .hgtags file at a specified revision.
754 """Obtain the filenode of the .hgtags file at a specified revision.
741
755
742 If the value is in the cache, the entry will be validated and returned.
756 If the value is in the cache, the entry will be validated and returned.
743 Otherwise, the filenode will be computed and returned unless
757 Otherwise, the filenode will be computed and returned unless
744 "computemissing" is False. In that case, None will be returned if
758 "computemissing" is False. In that case, None will be returned if
745 the entry is missing or False if the entry is invalid without
759 the entry is missing or False if the entry is invalid without
746 any potentially expensive computation being performed.
760 any potentially expensive computation being performed.
747
761
748 If an .hgtags does not exist at the specified revision, nullid is
762 If an .hgtags does not exist at the specified revision, nullid is
749 returned.
763 returned.
750 """
764 """
751 if node == nullid:
765 if node == nullid:
752 return nullid
766 return nullid
753
767
754 ctx = self._repo[node]
768 ctx = self._repo[node]
755 rev = ctx.rev()
769 rev = ctx.rev()
756
770
757 self.lookupcount += 1
771 self.lookupcount += 1
758
772
759 offset = rev * _fnodesrecsize
773 offset = rev * _fnodesrecsize
760 record = b'%s' % self._raw[offset : offset + _fnodesrecsize]
774 record = b'%s' % self._raw[offset : offset + _fnodesrecsize]
761 properprefix = node[0:4]
775 properprefix = node[0:4]
762
776
763 # Validate and return existing entry.
777 # Validate and return existing entry.
764 if record != _fnodesmissingrec and len(record) == _fnodesrecsize:
778 if record != _fnodesmissingrec and len(record) == _fnodesrecsize:
765 fileprefix = record[0:4]
779 fileprefix = record[0:4]
766
780
767 if fileprefix == properprefix:
781 if fileprefix == properprefix:
768 self.hitcount += 1
782 self.hitcount += 1
769 return record[4:]
783 return record[4:]
770
784
771 # Fall through.
785 # Fall through.
772
786
773 # If we get here, the entry is either missing or invalid.
787 # If we get here, the entry is either missing or invalid.
774
788
775 if not computemissing:
789 if not computemissing:
776 if record != _fnodesmissingrec:
790 if record != _fnodesmissingrec:
777 return False
791 return False
778 return None
792 return None
779
793
780 fnode = self._computefnode(node)
794 fnode = self._computefnode(node)
781 self._writeentry(offset, properprefix, fnode)
795 self._writeentry(offset, properprefix, fnode)
782 return fnode
796 return fnode
783
797
784 def _computefnode(self, node):
798 def _computefnode(self, node):
785 """Finds the tag filenode for a node which is missing or invalid
799 """Finds the tag filenode for a node which is missing or invalid
786 in cache"""
800 in cache"""
787 ctx = self._repo[node]
801 ctx = self._repo[node]
788 rev = ctx.rev()
802 rev = ctx.rev()
789 fnode = None
803 fnode = None
790 cl = self._repo.changelog
804 cl = self._repo.changelog
791 p1rev, p2rev = cl._uncheckedparentrevs(rev)
805 p1rev, p2rev = cl._uncheckedparentrevs(rev)
792 p1node = cl.node(p1rev)
806 p1node = cl.node(p1rev)
793 p1fnode = self.getfnode(p1node, computemissing=False)
807 p1fnode = self.getfnode(p1node, computemissing=False)
794 if p2rev != nullrev:
808 if p2rev != nullrev:
795 # There is some no-merge changeset where p1 is null and p2 is set
809 # There is some no-merge changeset where p1 is null and p2 is set
796 # Processing them as merge is just slower, but still gives a good
810 # Processing them as merge is just slower, but still gives a good
797 # result.
811 # result.
798 p2node = cl.node(p1rev)
812 p2node = cl.node(p1rev)
799 p2fnode = self.getfnode(p2node, computemissing=False)
813 p2fnode = self.getfnode(p2node, computemissing=False)
800 if p1fnode != p2fnode:
814 if p1fnode != p2fnode:
801 # we cannot rely on readfast because we don't know against what
815 # we cannot rely on readfast because we don't know against what
802 # parent the readfast delta is computed
816 # parent the readfast delta is computed
803 p1fnode = None
817 p1fnode = None
804 if p1fnode:
818 if p1fnode:
805 mctx = ctx.manifestctx()
819 mctx = ctx.manifestctx()
806 fnode = mctx.readfast().get(b'.hgtags')
820 fnode = mctx.readfast().get(b'.hgtags')
807 if fnode is None:
821 if fnode is None:
808 fnode = p1fnode
822 fnode = p1fnode
809 if fnode is None:
823 if fnode is None:
810 # Populate missing entry.
824 # Populate missing entry.
811 try:
825 try:
812 fnode = ctx.filenode(b'.hgtags')
826 fnode = ctx.filenode(b'.hgtags')
813 except error.LookupError:
827 except error.LookupError:
814 # No .hgtags file on this revision.
828 # No .hgtags file on this revision.
815 fnode = nullid
829 fnode = nullid
816 return fnode
830 return fnode
817
831
818 def setfnode(self, node, fnode):
832 def setfnode(self, node, fnode):
819 """Set the .hgtags filenode for a given changeset."""
833 """Set the .hgtags filenode for a given changeset."""
820 assert len(fnode) == 20
834 assert len(fnode) == 20
821 ctx = self._repo[node]
835 ctx = self._repo[node]
822
836
823 # Do a lookup first to avoid writing if nothing has changed.
837 # Do a lookup first to avoid writing if nothing has changed.
824 if self.getfnode(ctx.node(), computemissing=False) == fnode:
838 if self.getfnode(ctx.node(), computemissing=False) == fnode:
825 return
839 return
826
840
827 self._writeentry(ctx.rev() * _fnodesrecsize, node[0:4], fnode)
841 self._writeentry(ctx.rev() * _fnodesrecsize, node[0:4], fnode)
828
842
843 def refresh_invalid_nodes(self, nodes):
844 """recomputes file nodes for a given set of nodes which has unknown
845 filenodes for them in the cache
846 Also updates the in-memory cache with the correct filenode.
847 Caller needs to take care about calling `.write()` so that updates are
848 persisted.
849 Returns a map {node: recomputed fnode}
850 """
851 fixed_nodemap = {}
852 for node in nodes:
853 fnode = self._computefnode(node)
854 fixed_nodemap[node] = fnode
855 self.setfnode(node, fnode)
856 return fixed_nodemap
857
829 def _writeentry(self, offset, prefix, fnode):
858 def _writeentry(self, offset, prefix, fnode):
830 # Slices on array instances only accept other array.
859 # Slices on array instances only accept other array.
831 entry = bytearray(prefix + fnode)
860 entry = bytearray(prefix + fnode)
832 self._raw[offset : offset + _fnodesrecsize] = entry
861 self._raw[offset : offset + _fnodesrecsize] = entry
833 # self._dirtyoffset could be None.
862 # self._dirtyoffset could be None.
834 self._dirtyoffset = min(self._dirtyoffset or 0, offset or 0)
863 self._dirtyoffset = min(self._dirtyoffset or 0, offset or 0)
835
864
836 def write(self):
865 def write(self):
837 """Perform all necessary writes to cache file.
866 """Perform all necessary writes to cache file.
838
867
839 This may no-op if no writes are needed or if a write lock could
868 This may no-op if no writes are needed or if a write lock could
840 not be obtained.
869 not be obtained.
841 """
870 """
842 if self._dirtyoffset is None:
871 if self._dirtyoffset is None:
843 return
872 return
844
873
845 data = self._raw[self._dirtyoffset :]
874 data = self._raw[self._dirtyoffset :]
846 if not data:
875 if not data:
847 return
876 return
848
877
849 repo = self._repo
878 repo = self._repo
850
879
851 try:
880 try:
852 lock = repo.lock(wait=False)
881 lock = repo.lock(wait=False)
853 except error.LockError:
882 except error.LockError:
854 repo.ui.log(
883 repo.ui.log(
855 b'tagscache',
884 b'tagscache',
856 b'not writing .hg/cache/%s because '
885 b'not writing .hg/cache/%s because '
857 b'lock cannot be acquired\n' % _fnodescachefile,
886 b'lock cannot be acquired\n' % _fnodescachefile,
858 )
887 )
859 return
888 return
860
889
861 try:
890 try:
862 f = repo.cachevfs.open(_fnodescachefile, b'ab')
891 f = repo.cachevfs.open(_fnodescachefile, b'ab')
863 try:
892 try:
864 # if the file has been truncated
893 # if the file has been truncated
865 actualoffset = f.tell()
894 actualoffset = f.tell()
866 if actualoffset < self._dirtyoffset:
895 if actualoffset < self._dirtyoffset:
867 self._dirtyoffset = actualoffset
896 self._dirtyoffset = actualoffset
868 data = self._raw[self._dirtyoffset :]
897 data = self._raw[self._dirtyoffset :]
869 f.seek(self._dirtyoffset)
898 f.seek(self._dirtyoffset)
870 f.truncate()
899 f.truncate()
871 repo.ui.log(
900 repo.ui.log(
872 b'tagscache',
901 b'tagscache',
873 b'writing %d bytes to cache/%s\n'
902 b'writing %d bytes to cache/%s\n'
874 % (len(data), _fnodescachefile),
903 % (len(data), _fnodescachefile),
875 )
904 )
876 f.write(data)
905 f.write(data)
877 self._dirtyoffset = None
906 self._dirtyoffset = None
878 finally:
907 finally:
879 f.close()
908 f.close()
880 except (IOError, OSError) as inst:
909 except (IOError, OSError) as inst:
881 repo.ui.log(
910 repo.ui.log(
882 b'tagscache',
911 b'tagscache',
883 b"couldn't write cache/%s: %s\n"
912 b"couldn't write cache/%s: %s\n"
884 % (_fnodescachefile, stringutil.forcebytestr(inst)),
913 % (_fnodescachefile, stringutil.forcebytestr(inst)),
885 )
914 )
886 finally:
915 finally:
887 lock.release()
916 lock.release()
@@ -1,935 +1,935 b''
1 setup
1 setup
2
2
3 $ cat >> $HGRCPATH << EOF
3 $ cat >> $HGRCPATH << EOF
4 > [extensions]
4 > [extensions]
5 > blackbox=
5 > blackbox=
6 > mock=$TESTDIR/mockblackbox.py
6 > mock=$TESTDIR/mockblackbox.py
7 > [blackbox]
7 > [blackbox]
8 > track = command, commandfinish, tagscache
8 > track = command, commandfinish, tagscache
9 > EOF
9 > EOF
10
10
11 Helper functions:
11 Helper functions:
12
12
13 $ cacheexists() {
13 $ cacheexists() {
14 > [ -f .hg/cache/tags2-visible ] && echo "tag cache exists" || echo "no tag cache"
14 > [ -f .hg/cache/tags2-visible ] && echo "tag cache exists" || echo "no tag cache"
15 > }
15 > }
16
16
17 $ fnodescacheexists() {
17 $ fnodescacheexists() {
18 > [ -f .hg/cache/hgtagsfnodes1 ] && echo "fnodes cache exists" || echo "no fnodes cache"
18 > [ -f .hg/cache/hgtagsfnodes1 ] && echo "fnodes cache exists" || echo "no fnodes cache"
19 > }
19 > }
20
20
21 $ dumptags() {
21 $ dumptags() {
22 > rev=$1
22 > rev=$1
23 > echo "rev $rev: .hgtags:"
23 > echo "rev $rev: .hgtags:"
24 > hg cat -r$rev .hgtags
24 > hg cat -r$rev .hgtags
25 > }
25 > }
26
26
27 # XXX need to test that the tag cache works when we strip an old head
27 # XXX need to test that the tag cache works when we strip an old head
28 # and add a new one rooted off non-tip: i.e. node and rev of tip are the
28 # and add a new one rooted off non-tip: i.e. node and rev of tip are the
29 # same, but stuff has changed behind tip.
29 # same, but stuff has changed behind tip.
30
30
31 Setup:
31 Setup:
32
32
33 $ hg init t
33 $ hg init t
34 $ cd t
34 $ cd t
35 $ cacheexists
35 $ cacheexists
36 no tag cache
36 no tag cache
37 $ fnodescacheexists
37 $ fnodescacheexists
38 no fnodes cache
38 no fnodes cache
39 $ hg id
39 $ hg id
40 000000000000 tip
40 000000000000 tip
41 $ cacheexists
41 $ cacheexists
42 no tag cache
42 no tag cache
43 $ fnodescacheexists
43 $ fnodescacheexists
44 no fnodes cache
44 no fnodes cache
45 $ echo a > a
45 $ echo a > a
46 $ hg add a
46 $ hg add a
47 $ hg commit -m "test"
47 $ hg commit -m "test"
48 $ hg co
48 $ hg co
49 0 files updated, 0 files merged, 0 files removed, 0 files unresolved
49 0 files updated, 0 files merged, 0 files removed, 0 files unresolved
50 $ hg identify
50 $ hg identify
51 acb14030fe0a tip
51 acb14030fe0a tip
52 $ hg identify -r 'wdir()'
52 $ hg identify -r 'wdir()'
53 acb14030fe0a tip
53 acb14030fe0a tip
54 $ cacheexists
54 $ cacheexists
55 tag cache exists
55 tag cache exists
56 No fnodes cache because .hgtags file doesn't exist
56 No fnodes cache because .hgtags file doesn't exist
57 (this is an implementation detail)
57 (this is an implementation detail)
58 $ fnodescacheexists
58 $ fnodescacheexists
59 no fnodes cache
59 no fnodes cache
60
60
61 Try corrupting the cache
61 Try corrupting the cache
62
62
63 $ printf 'a b' > .hg/cache/tags2-visible
63 $ printf 'a b' > .hg/cache/tags2-visible
64 $ hg identify
64 $ hg identify
65 acb14030fe0a tip
65 acb14030fe0a tip
66 $ cacheexists
66 $ cacheexists
67 tag cache exists
67 tag cache exists
68 $ fnodescacheexists
68 $ fnodescacheexists
69 no fnodes cache
69 no fnodes cache
70 $ hg identify
70 $ hg identify
71 acb14030fe0a tip
71 acb14030fe0a tip
72
72
73 Create local tag with long name:
73 Create local tag with long name:
74
74
75 $ T=`hg identify --debug --id`
75 $ T=`hg identify --debug --id`
76 $ hg tag -l "This is a local tag with a really long name!"
76 $ hg tag -l "This is a local tag with a really long name!"
77 $ hg tags
77 $ hg tags
78 tip 0:acb14030fe0a
78 tip 0:acb14030fe0a
79 This is a local tag with a really long name! 0:acb14030fe0a
79 This is a local tag with a really long name! 0:acb14030fe0a
80 $ rm .hg/localtags
80 $ rm .hg/localtags
81
81
82 Create a tag behind hg's back:
82 Create a tag behind hg's back:
83
83
84 $ echo "$T first" > .hgtags
84 $ echo "$T first" > .hgtags
85 $ cat .hgtags
85 $ cat .hgtags
86 acb14030fe0a21b60322c440ad2d20cf7685a376 first
86 acb14030fe0a21b60322c440ad2d20cf7685a376 first
87 $ hg add .hgtags
87 $ hg add .hgtags
88 $ hg commit -m "add tags"
88 $ hg commit -m "add tags"
89 $ hg tags
89 $ hg tags
90 tip 1:b9154636be93
90 tip 1:b9154636be93
91 first 0:acb14030fe0a
91 first 0:acb14030fe0a
92 $ hg identify
92 $ hg identify
93 b9154636be93 tip
93 b9154636be93 tip
94
94
95 We should have a fnodes cache now that we have a real tag
95 We should have a fnodes cache now that we have a real tag
96 The cache should have an empty entry for rev 0 and a valid entry for rev 1.
96 The cache should have an empty entry for rev 0 and a valid entry for rev 1.
97
97
98
98
99 $ fnodescacheexists
99 $ fnodescacheexists
100 fnodes cache exists
100 fnodes cache exists
101 $ f --size --hexdump .hg/cache/hgtagsfnodes1
101 $ f --size --hexdump .hg/cache/hgtagsfnodes1
102 .hg/cache/hgtagsfnodes1: size=48
102 .hg/cache/hgtagsfnodes1: size=48
103 0000: ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff |................|
103 0000: ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff |................|
104 0010: ff ff ff ff ff ff ff ff b9 15 46 36 26 b7 b4 a7 |..........F6&...|
104 0010: ff ff ff ff ff ff ff ff b9 15 46 36 26 b7 b4 a7 |..........F6&...|
105 0020: 73 e0 9e e3 c5 2f 51 0e 19 e0 5e 1f f9 66 d8 59 |s..../Q...^..f.Y|
105 0020: 73 e0 9e e3 c5 2f 51 0e 19 e0 5e 1f f9 66 d8 59 |s..../Q...^..f.Y|
106 $ hg debugtagscache
106 $ hg debugtagscache
107 0 acb14030fe0a21b60322c440ad2d20cf7685a376 missing
107 0 acb14030fe0a21b60322c440ad2d20cf7685a376 missing
108 1 b9154636be938d3d431e75a7c906504a079bfe07 26b7b4a773e09ee3c52f510e19e05e1ff966d859
108 1 b9154636be938d3d431e75a7c906504a079bfe07 26b7b4a773e09ee3c52f510e19e05e1ff966d859
109
109
110 Repeat with cold tag cache:
110 Repeat with cold tag cache:
111
111
112 $ rm -f .hg/cache/tags2-visible .hg/cache/hgtagsfnodes1
112 $ rm -f .hg/cache/tags2-visible .hg/cache/hgtagsfnodes1
113 $ hg identify
113 $ hg identify
114 b9154636be93 tip
114 b9154636be93 tip
115
115
116 $ fnodescacheexists
116 $ fnodescacheexists
117 fnodes cache exists
117 fnodes cache exists
118 $ f --size --hexdump .hg/cache/hgtagsfnodes1
118 $ f --size --hexdump .hg/cache/hgtagsfnodes1
119 .hg/cache/hgtagsfnodes1: size=48
119 .hg/cache/hgtagsfnodes1: size=48
120 0000: ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff |................|
120 0000: ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff |................|
121 0010: ff ff ff ff ff ff ff ff b9 15 46 36 26 b7 b4 a7 |..........F6&...|
121 0010: ff ff ff ff ff ff ff ff b9 15 46 36 26 b7 b4 a7 |..........F6&...|
122 0020: 73 e0 9e e3 c5 2f 51 0e 19 e0 5e 1f f9 66 d8 59 |s..../Q...^..f.Y|
122 0020: 73 e0 9e e3 c5 2f 51 0e 19 e0 5e 1f f9 66 d8 59 |s..../Q...^..f.Y|
123
123
124 And again, but now unable to write tag cache or lock file:
124 And again, but now unable to write tag cache or lock file:
125
125
126 #if unix-permissions no-fsmonitor
126 #if unix-permissions no-fsmonitor
127
127
128 $ rm -f .hg/cache/tags2-visible .hg/cache/hgtagsfnodes1
128 $ rm -f .hg/cache/tags2-visible .hg/cache/hgtagsfnodes1
129 $ chmod 555 .hg/cache
129 $ chmod 555 .hg/cache
130 $ hg identify
130 $ hg identify
131 b9154636be93 tip
131 b9154636be93 tip
132 $ chmod 755 .hg/cache
132 $ chmod 755 .hg/cache
133
133
134 (this block should be protected by no-fsmonitor, because "chmod 555 .hg"
134 (this block should be protected by no-fsmonitor, because "chmod 555 .hg"
135 makes watchman fail at accessing to files under .hg)
135 makes watchman fail at accessing to files under .hg)
136
136
137 $ chmod 555 .hg
137 $ chmod 555 .hg
138 $ hg identify
138 $ hg identify
139 b9154636be93 tip
139 b9154636be93 tip
140 $ chmod 755 .hg
140 $ chmod 755 .hg
141 #endif
141 #endif
142
142
143 Tag cache debug info written to blackbox log
143 Tag cache debug info written to blackbox log
144
144
145 $ rm -f .hg/cache/tags2-visible .hg/cache/hgtagsfnodes1
145 $ rm -f .hg/cache/tags2-visible .hg/cache/hgtagsfnodes1
146 $ hg identify
146 $ hg identify
147 b9154636be93 tip
147 b9154636be93 tip
148 $ hg blackbox -l 6
148 $ hg blackbox -l 6
149 1970/01/01 00:00:00 bob @b9154636be938d3d431e75a7c906504a079bfe07 (5000)> identify
149 1970/01/01 00:00:00 bob @b9154636be938d3d431e75a7c906504a079bfe07 (5000)> identify
150 1970/01/01 00:00:00 bob @b9154636be938d3d431e75a7c906504a079bfe07 (5000)> writing 48 bytes to cache/hgtagsfnodes1
150 1970/01/01 00:00:00 bob @b9154636be938d3d431e75a7c906504a079bfe07 (5000)> writing 48 bytes to cache/hgtagsfnodes1
151 1970/01/01 00:00:00 bob @b9154636be938d3d431e75a7c906504a079bfe07 (5000)> 0/2 cache hits/lookups in * seconds (glob)
151 1970/01/01 00:00:00 bob @b9154636be938d3d431e75a7c906504a079bfe07 (5000)> 0/2 cache hits/lookups in * seconds (glob)
152 1970/01/01 00:00:00 bob @b9154636be938d3d431e75a7c906504a079bfe07 (5000)> writing .hg/cache/tags2-visible with 1 tags
152 1970/01/01 00:00:00 bob @b9154636be938d3d431e75a7c906504a079bfe07 (5000)> writing .hg/cache/tags2-visible with 1 tags
153 1970/01/01 00:00:00 bob @b9154636be938d3d431e75a7c906504a079bfe07 (5000)> identify exited 0 after * seconds (glob)
153 1970/01/01 00:00:00 bob @b9154636be938d3d431e75a7c906504a079bfe07 (5000)> identify exited 0 after * seconds (glob)
154 1970/01/01 00:00:00 bob @b9154636be938d3d431e75a7c906504a079bfe07 (5000)> blackbox -l 6
154 1970/01/01 00:00:00 bob @b9154636be938d3d431e75a7c906504a079bfe07 (5000)> blackbox -l 6
155
155
156 Failure to acquire lock results in no write
156 Failure to acquire lock results in no write
157
157
158 $ rm -f .hg/cache/tags2-visible .hg/cache/hgtagsfnodes1
158 $ rm -f .hg/cache/tags2-visible .hg/cache/hgtagsfnodes1
159 $ echo 'foo:1' > .hg/store/lock
159 $ echo 'foo:1' > .hg/store/lock
160 $ hg identify
160 $ hg identify
161 b9154636be93 tip
161 b9154636be93 tip
162 $ hg blackbox -l 6
162 $ hg blackbox -l 6
163 1970/01/01 00:00:00 bob @b9154636be938d3d431e75a7c906504a079bfe07 (5000)> identify
163 1970/01/01 00:00:00 bob @b9154636be938d3d431e75a7c906504a079bfe07 (5000)> identify
164 1970/01/01 00:00:00 bob @b9154636be938d3d431e75a7c906504a079bfe07 (5000)> not writing .hg/cache/hgtagsfnodes1 because lock cannot be acquired
164 1970/01/01 00:00:00 bob @b9154636be938d3d431e75a7c906504a079bfe07 (5000)> not writing .hg/cache/hgtagsfnodes1 because lock cannot be acquired
165 1970/01/01 00:00:00 bob @b9154636be938d3d431e75a7c906504a079bfe07 (5000)> 0/2 cache hits/lookups in * seconds (glob)
165 1970/01/01 00:00:00 bob @b9154636be938d3d431e75a7c906504a079bfe07 (5000)> 0/2 cache hits/lookups in * seconds (glob)
166 1970/01/01 00:00:00 bob @b9154636be938d3d431e75a7c906504a079bfe07 (5000)> writing .hg/cache/tags2-visible with 1 tags
166 1970/01/01 00:00:00 bob @b9154636be938d3d431e75a7c906504a079bfe07 (5000)> writing .hg/cache/tags2-visible with 1 tags
167 1970/01/01 00:00:00 bob @b9154636be938d3d431e75a7c906504a079bfe07 (5000)> identify exited 0 after * seconds (glob)
167 1970/01/01 00:00:00 bob @b9154636be938d3d431e75a7c906504a079bfe07 (5000)> identify exited 0 after * seconds (glob)
168 1970/01/01 00:00:00 bob @b9154636be938d3d431e75a7c906504a079bfe07 (5000)> blackbox -l 6
168 1970/01/01 00:00:00 bob @b9154636be938d3d431e75a7c906504a079bfe07 (5000)> blackbox -l 6
169
169
170 $ fnodescacheexists
170 $ fnodescacheexists
171 no fnodes cache
171 no fnodes cache
172
172
173 $ rm .hg/store/lock
173 $ rm .hg/store/lock
174
174
175 $ rm -f .hg/cache/tags2-visible .hg/cache/hgtagsfnodes1
175 $ rm -f .hg/cache/tags2-visible .hg/cache/hgtagsfnodes1
176 $ hg identify
176 $ hg identify
177 b9154636be93 tip
177 b9154636be93 tip
178
178
179 Create a branch:
179 Create a branch:
180
180
181 $ echo bb > a
181 $ echo bb > a
182 $ hg status
182 $ hg status
183 M a
183 M a
184 $ hg identify
184 $ hg identify
185 b9154636be93+ tip
185 b9154636be93+ tip
186 $ hg co first
186 $ hg co first
187 0 files updated, 0 files merged, 1 files removed, 0 files unresolved
187 0 files updated, 0 files merged, 1 files removed, 0 files unresolved
188 $ hg id
188 $ hg id
189 acb14030fe0a+ first
189 acb14030fe0a+ first
190 $ hg id -r 'wdir()'
190 $ hg id -r 'wdir()'
191 acb14030fe0a+ first
191 acb14030fe0a+ first
192 $ hg -v id
192 $ hg -v id
193 acb14030fe0a+ first
193 acb14030fe0a+ first
194 $ hg status
194 $ hg status
195 M a
195 M a
196 $ echo 1 > b
196 $ echo 1 > b
197 $ hg add b
197 $ hg add b
198 $ hg commit -m "branch"
198 $ hg commit -m "branch"
199 created new head
199 created new head
200
200
201 Creating a new commit shouldn't append the .hgtags fnodes cache until
201 Creating a new commit shouldn't append the .hgtags fnodes cache until
202 tags info is accessed
202 tags info is accessed
203
203
204 $ f --size --hexdump .hg/cache/hgtagsfnodes1
204 $ f --size --hexdump .hg/cache/hgtagsfnodes1
205 .hg/cache/hgtagsfnodes1: size=48
205 .hg/cache/hgtagsfnodes1: size=48
206 0000: ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff |................|
206 0000: ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff |................|
207 0010: ff ff ff ff ff ff ff ff b9 15 46 36 26 b7 b4 a7 |..........F6&...|
207 0010: ff ff ff ff ff ff ff ff b9 15 46 36 26 b7 b4 a7 |..........F6&...|
208 0020: 73 e0 9e e3 c5 2f 51 0e 19 e0 5e 1f f9 66 d8 59 |s..../Q...^..f.Y|
208 0020: 73 e0 9e e3 c5 2f 51 0e 19 e0 5e 1f f9 66 d8 59 |s..../Q...^..f.Y|
209
209
210 $ hg id
210 $ hg id
211 c8edf04160c7 tip
211 c8edf04160c7 tip
212
212
213 First 4 bytes of record 3 are changeset fragment
213 First 4 bytes of record 3 are changeset fragment
214
214
215 $ f --size --hexdump .hg/cache/hgtagsfnodes1
215 $ f --size --hexdump .hg/cache/hgtagsfnodes1
216 .hg/cache/hgtagsfnodes1: size=72
216 .hg/cache/hgtagsfnodes1: size=72
217 0000: ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff |................|
217 0000: ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff |................|
218 0010: ff ff ff ff ff ff ff ff b9 15 46 36 26 b7 b4 a7 |..........F6&...|
218 0010: ff ff ff ff ff ff ff ff b9 15 46 36 26 b7 b4 a7 |..........F6&...|
219 0020: 73 e0 9e e3 c5 2f 51 0e 19 e0 5e 1f f9 66 d8 59 |s..../Q...^..f.Y|
219 0020: 73 e0 9e e3 c5 2f 51 0e 19 e0 5e 1f f9 66 d8 59 |s..../Q...^..f.Y|
220 0030: c8 ed f0 41 00 00 00 00 00 00 00 00 00 00 00 00 |...A............|
220 0030: c8 ed f0 41 00 00 00 00 00 00 00 00 00 00 00 00 |...A............|
221 0040: 00 00 00 00 00 00 00 00 |........|
221 0040: 00 00 00 00 00 00 00 00 |........|
222
222
223 Merge the two heads:
223 Merge the two heads:
224
224
225 $ hg merge 1
225 $ hg merge 1
226 1 files updated, 0 files merged, 0 files removed, 0 files unresolved
226 1 files updated, 0 files merged, 0 files removed, 0 files unresolved
227 (branch merge, don't forget to commit)
227 (branch merge, don't forget to commit)
228 $ hg blackbox -l3
228 $ hg blackbox -l3
229 1970/01/01 00:00:00 bob @c8edf04160c7f731e4589d66ab3ab3486a64ac28 (5000)> merge 1
229 1970/01/01 00:00:00 bob @c8edf04160c7f731e4589d66ab3ab3486a64ac28 (5000)> merge 1
230 1970/01/01 00:00:00 bob @c8edf04160c7f731e4589d66ab3ab3486a64ac28+b9154636be938d3d431e75a7c906504a079bfe07 (5000)> merge 1 exited 0 after * seconds (glob)
230 1970/01/01 00:00:00 bob @c8edf04160c7f731e4589d66ab3ab3486a64ac28+b9154636be938d3d431e75a7c906504a079bfe07 (5000)> merge 1 exited 0 after * seconds (glob)
231 1970/01/01 00:00:00 bob @c8edf04160c7f731e4589d66ab3ab3486a64ac28+b9154636be938d3d431e75a7c906504a079bfe07 (5000)> blackbox -l3
231 1970/01/01 00:00:00 bob @c8edf04160c7f731e4589d66ab3ab3486a64ac28+b9154636be938d3d431e75a7c906504a079bfe07 (5000)> blackbox -l3
232 $ hg id
232 $ hg id
233 c8edf04160c7+b9154636be93+ tip
233 c8edf04160c7+b9154636be93+ tip
234 $ hg status
234 $ hg status
235 M .hgtags
235 M .hgtags
236 $ hg commit -m "merge"
236 $ hg commit -m "merge"
237
237
238 Create a fake head, make sure tag not visible afterwards:
238 Create a fake head, make sure tag not visible afterwards:
239
239
240 $ cp .hgtags tags
240 $ cp .hgtags tags
241 $ hg tag last
241 $ hg tag last
242 $ hg rm .hgtags
242 $ hg rm .hgtags
243 $ hg commit -m "remove"
243 $ hg commit -m "remove"
244
244
245 $ mv tags .hgtags
245 $ mv tags .hgtags
246 $ hg add .hgtags
246 $ hg add .hgtags
247 $ hg commit -m "readd"
247 $ hg commit -m "readd"
248 $
248 $
249 $ hg tags
249 $ hg tags
250 tip 6:35ff301afafe
250 tip 6:35ff301afafe
251 first 0:acb14030fe0a
251 first 0:acb14030fe0a
252
252
253 Add invalid tags:
253 Add invalid tags:
254
254
255 $ echo "spam" >> .hgtags
255 $ echo "spam" >> .hgtags
256 $ echo >> .hgtags
256 $ echo >> .hgtags
257 $ echo "foo bar" >> .hgtags
257 $ echo "foo bar" >> .hgtags
258 $ echo "a5a5 invalid" >> .hg/localtags
258 $ echo "a5a5 invalid" >> .hg/localtags
259 $ cat .hgtags
259 $ cat .hgtags
260 acb14030fe0a21b60322c440ad2d20cf7685a376 first
260 acb14030fe0a21b60322c440ad2d20cf7685a376 first
261 spam
261 spam
262
262
263 foo bar
263 foo bar
264 $ hg commit -m "tags"
264 $ hg commit -m "tags"
265
265
266 Report tag parse error on other head:
266 Report tag parse error on other head:
267
267
268 $ hg up 3
268 $ hg up 3
269 1 files updated, 0 files merged, 0 files removed, 0 files unresolved
269 1 files updated, 0 files merged, 0 files removed, 0 files unresolved
270 $ echo 'x y' >> .hgtags
270 $ echo 'x y' >> .hgtags
271 $ hg commit -m "head"
271 $ hg commit -m "head"
272 created new head
272 created new head
273
273
274 $ hg tags --debug
274 $ hg tags --debug
275 .hgtags@75d9f02dfe28, line 2: cannot parse entry
275 .hgtags@75d9f02dfe28, line 2: cannot parse entry
276 .hgtags@75d9f02dfe28, line 4: node 'foo' is not well formed
276 .hgtags@75d9f02dfe28, line 4: node 'foo' is not well formed
277 .hgtags@c4be69a18c11, line 2: node 'x' is not well formed
277 .hgtags@c4be69a18c11, line 2: node 'x' is not well formed
278 tip 8:c4be69a18c11e8bc3a5fdbb576017c25f7d84663
278 tip 8:c4be69a18c11e8bc3a5fdbb576017c25f7d84663
279 first 0:acb14030fe0a21b60322c440ad2d20cf7685a376
279 first 0:acb14030fe0a21b60322c440ad2d20cf7685a376
280 $ hg tip
280 $ hg tip
281 changeset: 8:c4be69a18c11
281 changeset: 8:c4be69a18c11
282 tag: tip
282 tag: tip
283 parent: 3:ac5e980c4dc0
283 parent: 3:ac5e980c4dc0
284 user: test
284 user: test
285 date: Thu Jan 01 00:00:00 1970 +0000
285 date: Thu Jan 01 00:00:00 1970 +0000
286 summary: head
286 summary: head
287
287
288
288
289 Test tag precedence rules:
289 Test tag precedence rules:
290
290
291 $ cd ..
291 $ cd ..
292 $ hg init t2
292 $ hg init t2
293 $ cd t2
293 $ cd t2
294 $ echo foo > foo
294 $ echo foo > foo
295 $ hg add foo
295 $ hg add foo
296 $ hg ci -m 'add foo' # rev 0
296 $ hg ci -m 'add foo' # rev 0
297 $ hg tag bar # rev 1
297 $ hg tag bar # rev 1
298 $ echo >> foo
298 $ echo >> foo
299 $ hg ci -m 'change foo 1' # rev 2
299 $ hg ci -m 'change foo 1' # rev 2
300 $ hg up -C 1
300 $ hg up -C 1
301 1 files updated, 0 files merged, 0 files removed, 0 files unresolved
301 1 files updated, 0 files merged, 0 files removed, 0 files unresolved
302 $ hg tag -r 1 -f bar # rev 3
302 $ hg tag -r 1 -f bar # rev 3
303 $ hg up -C 1
303 $ hg up -C 1
304 1 files updated, 0 files merged, 0 files removed, 0 files unresolved
304 1 files updated, 0 files merged, 0 files removed, 0 files unresolved
305 $ echo >> foo
305 $ echo >> foo
306 $ hg ci -m 'change foo 2' # rev 4
306 $ hg ci -m 'change foo 2' # rev 4
307 created new head
307 created new head
308 $ hg tags
308 $ hg tags
309 tip 4:0c192d7d5e6b
309 tip 4:0c192d7d5e6b
310 bar 1:78391a272241
310 bar 1:78391a272241
311
311
312 Repeat in case of cache effects:
312 Repeat in case of cache effects:
313
313
314 $ hg tags
314 $ hg tags
315 tip 4:0c192d7d5e6b
315 tip 4:0c192d7d5e6b
316 bar 1:78391a272241
316 bar 1:78391a272241
317
317
318 Detailed dump of tag info:
318 Detailed dump of tag info:
319
319
320 $ hg heads -q # expect 4, 3, 2
320 $ hg heads -q # expect 4, 3, 2
321 4:0c192d7d5e6b
321 4:0c192d7d5e6b
322 3:6fa450212aeb
322 3:6fa450212aeb
323 2:7a94127795a3
323 2:7a94127795a3
324 $ dumptags 2
324 $ dumptags 2
325 rev 2: .hgtags:
325 rev 2: .hgtags:
326 bbd179dfa0a71671c253b3ae0aa1513b60d199fa bar
326 bbd179dfa0a71671c253b3ae0aa1513b60d199fa bar
327 $ dumptags 3
327 $ dumptags 3
328 rev 3: .hgtags:
328 rev 3: .hgtags:
329 bbd179dfa0a71671c253b3ae0aa1513b60d199fa bar
329 bbd179dfa0a71671c253b3ae0aa1513b60d199fa bar
330 bbd179dfa0a71671c253b3ae0aa1513b60d199fa bar
330 bbd179dfa0a71671c253b3ae0aa1513b60d199fa bar
331 78391a272241d70354aa14c874552cad6b51bb42 bar
331 78391a272241d70354aa14c874552cad6b51bb42 bar
332 $ dumptags 4
332 $ dumptags 4
333 rev 4: .hgtags:
333 rev 4: .hgtags:
334 bbd179dfa0a71671c253b3ae0aa1513b60d199fa bar
334 bbd179dfa0a71671c253b3ae0aa1513b60d199fa bar
335
335
336 Dump cache:
336 Dump cache:
337
337
338 $ cat .hg/cache/tags2-visible
338 $ cat .hg/cache/tags2-visible
339 4 0c192d7d5e6b78a714de54a2e9627952a877e25a
339 4 0c192d7d5e6b78a714de54a2e9627952a877e25a
340 bbd179dfa0a71671c253b3ae0aa1513b60d199fa bar
340 bbd179dfa0a71671c253b3ae0aa1513b60d199fa bar
341 bbd179dfa0a71671c253b3ae0aa1513b60d199fa bar
341 bbd179dfa0a71671c253b3ae0aa1513b60d199fa bar
342 78391a272241d70354aa14c874552cad6b51bb42 bar
342 78391a272241d70354aa14c874552cad6b51bb42 bar
343
343
344 $ f --size --hexdump .hg/cache/hgtagsfnodes1
344 $ f --size --hexdump .hg/cache/hgtagsfnodes1
345 .hg/cache/hgtagsfnodes1: size=120
345 .hg/cache/hgtagsfnodes1: size=120
346 0000: ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff |................|
346 0000: ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff |................|
347 0010: ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff |................|
347 0010: ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff |................|
348 0020: ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff |................|
348 0020: ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff |................|
349 0030: 7a 94 12 77 0c 04 f2 a8 af 31 de 17 fa b7 42 28 |z..w.....1....B(|
349 0030: 7a 94 12 77 0c 04 f2 a8 af 31 de 17 fa b7 42 28 |z..w.....1....B(|
350 0040: 78 ee 5a 2d ad bc 94 3d 6f a4 50 21 7d 3b 71 8c |x.Z-...=o.P!};q.|
350 0040: 78 ee 5a 2d ad bc 94 3d 6f a4 50 21 7d 3b 71 8c |x.Z-...=o.P!};q.|
351 0050: 96 4e f3 7b 89 e5 50 eb da fd 57 89 e7 6c e1 b0 |.N.{..P...W..l..|
351 0050: 96 4e f3 7b 89 e5 50 eb da fd 57 89 e7 6c e1 b0 |.N.{..P...W..l..|
352 0060: 0c 19 2d 7d 0c 04 f2 a8 af 31 de 17 fa b7 42 28 |..-}.....1....B(|
352 0060: 0c 19 2d 7d 0c 04 f2 a8 af 31 de 17 fa b7 42 28 |..-}.....1....B(|
353 0070: 78 ee 5a 2d ad bc 94 3d |x.Z-...=|
353 0070: 78 ee 5a 2d ad bc 94 3d |x.Z-...=|
354
354
355 Corrupt the .hgtags fnodes cache
355 Corrupt the .hgtags fnodes cache
356 Extra junk data at the end should get overwritten on next cache update
356 Extra junk data at the end should get overwritten on next cache update
357
357
358 $ echo extra >> .hg/cache/hgtagsfnodes1
358 $ echo extra >> .hg/cache/hgtagsfnodes1
359 $ echo dummy1 > foo
359 $ echo dummy1 > foo
360 $ hg commit -m throwaway1
360 $ hg commit -m throwaway1
361
361
362 $ hg tags
362 $ hg tags
363 tip 5:8dbfe60eff30
363 tip 5:8dbfe60eff30
364 bar 1:78391a272241
364 bar 1:78391a272241
365
365
366 $ hg blackbox -l 6
366 $ hg blackbox -l 6
367 1970/01/01 00:00:00 bob @8dbfe60eff306a54259cfe007db9e330e7ecf866 (5000)> tags
367 1970/01/01 00:00:00 bob @8dbfe60eff306a54259cfe007db9e330e7ecf866 (5000)> tags
368 1970/01/01 00:00:00 bob @8dbfe60eff306a54259cfe007db9e330e7ecf866 (5000)> writing 24 bytes to cache/hgtagsfnodes1
368 1970/01/01 00:00:00 bob @8dbfe60eff306a54259cfe007db9e330e7ecf866 (5000)> writing 24 bytes to cache/hgtagsfnodes1
369 1970/01/01 00:00:00 bob @8dbfe60eff306a54259cfe007db9e330e7ecf866 (5000)> 3/4 cache hits/lookups in * seconds (glob)
369 1970/01/01 00:00:00 bob @8dbfe60eff306a54259cfe007db9e330e7ecf866 (5000)> 3/4 cache hits/lookups in * seconds (glob)
370 1970/01/01 00:00:00 bob @8dbfe60eff306a54259cfe007db9e330e7ecf866 (5000)> writing .hg/cache/tags2-visible with 1 tags
370 1970/01/01 00:00:00 bob @8dbfe60eff306a54259cfe007db9e330e7ecf866 (5000)> writing .hg/cache/tags2-visible with 1 tags
371 1970/01/01 00:00:00 bob @8dbfe60eff306a54259cfe007db9e330e7ecf866 (5000)> tags exited 0 after * seconds (glob)
371 1970/01/01 00:00:00 bob @8dbfe60eff306a54259cfe007db9e330e7ecf866 (5000)> tags exited 0 after * seconds (glob)
372 1970/01/01 00:00:00 bob @8dbfe60eff306a54259cfe007db9e330e7ecf866 (5000)> blackbox -l 6
372 1970/01/01 00:00:00 bob @8dbfe60eff306a54259cfe007db9e330e7ecf866 (5000)> blackbox -l 6
373
373
374 On junk data + missing cache entries, hg also overwrites the junk.
374 On junk data + missing cache entries, hg also overwrites the junk.
375
375
376 $ rm -f .hg/cache/tags2-visible
376 $ rm -f .hg/cache/tags2-visible
377 >>> import os
377 >>> import os
378 >>> with open(".hg/cache/hgtagsfnodes1", "ab+") as fp:
378 >>> with open(".hg/cache/hgtagsfnodes1", "ab+") as fp:
379 ... fp.seek(-10, os.SEEK_END) and None
379 ... fp.seek(-10, os.SEEK_END) and None
380 ... fp.truncate() and None
380 ... fp.truncate() and None
381
381
382 $ hg debugtagscache | tail -2
382 $ hg debugtagscache | tail -2
383 4 0c192d7d5e6b78a714de54a2e9627952a877e25a 0c04f2a8af31de17fab7422878ee5a2dadbc943d
383 4 0c192d7d5e6b78a714de54a2e9627952a877e25a 0c04f2a8af31de17fab7422878ee5a2dadbc943d
384 5 8dbfe60eff306a54259cfe007db9e330e7ecf866 missing
384 5 8dbfe60eff306a54259cfe007db9e330e7ecf866 missing
385 $ hg tags
385 $ hg tags
386 tip 5:8dbfe60eff30
386 tip 5:8dbfe60eff30
387 bar 1:78391a272241
387 bar 1:78391a272241
388 $ hg debugtagscache | tail -2
388 $ hg debugtagscache | tail -2
389 4 0c192d7d5e6b78a714de54a2e9627952a877e25a 0c04f2a8af31de17fab7422878ee5a2dadbc943d
389 4 0c192d7d5e6b78a714de54a2e9627952a877e25a 0c04f2a8af31de17fab7422878ee5a2dadbc943d
390 5 8dbfe60eff306a54259cfe007db9e330e7ecf866 0c04f2a8af31de17fab7422878ee5a2dadbc943d
390 5 8dbfe60eff306a54259cfe007db9e330e7ecf866 0c04f2a8af31de17fab7422878ee5a2dadbc943d
391
391
392 If the 4 bytes of node hash for a record don't match an existing node, the entry
392 If the 4 bytes of node hash for a record don't match an existing node, the entry
393 is flagged as invalid.
393 is flagged as invalid.
394
394
395 >>> import os
395 >>> import os
396 >>> with open(".hg/cache/hgtagsfnodes1", "rb+") as fp:
396 >>> with open(".hg/cache/hgtagsfnodes1", "rb+") as fp:
397 ... fp.seek(-24, os.SEEK_END) and None
397 ... fp.seek(-24, os.SEEK_END) and None
398 ... fp.write(b'\xde\xad') and None
398 ... fp.write(b'\xde\xad') and None
399
399
400 $ f --size --hexdump .hg/cache/hgtagsfnodes1
400 $ f --size --hexdump .hg/cache/hgtagsfnodes1
401 .hg/cache/hgtagsfnodes1: size=144
401 .hg/cache/hgtagsfnodes1: size=144
402 0000: ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff |................|
402 0000: ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff |................|
403 0010: ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff |................|
403 0010: ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff |................|
404 0020: ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff |................|
404 0020: ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff |................|
405 0030: 7a 94 12 77 0c 04 f2 a8 af 31 de 17 fa b7 42 28 |z..w.....1....B(|
405 0030: 7a 94 12 77 0c 04 f2 a8 af 31 de 17 fa b7 42 28 |z..w.....1....B(|
406 0040: 78 ee 5a 2d ad bc 94 3d 6f a4 50 21 7d 3b 71 8c |x.Z-...=o.P!};q.|
406 0040: 78 ee 5a 2d ad bc 94 3d 6f a4 50 21 7d 3b 71 8c |x.Z-...=o.P!};q.|
407 0050: 96 4e f3 7b 89 e5 50 eb da fd 57 89 e7 6c e1 b0 |.N.{..P...W..l..|
407 0050: 96 4e f3 7b 89 e5 50 eb da fd 57 89 e7 6c e1 b0 |.N.{..P...W..l..|
408 0060: 0c 19 2d 7d 0c 04 f2 a8 af 31 de 17 fa b7 42 28 |..-}.....1....B(|
408 0060: 0c 19 2d 7d 0c 04 f2 a8 af 31 de 17 fa b7 42 28 |..-}.....1....B(|
409 0070: 78 ee 5a 2d ad bc 94 3d de ad e6 0e 0c 04 f2 a8 |x.Z-...=........|
409 0070: 78 ee 5a 2d ad bc 94 3d de ad e6 0e 0c 04 f2 a8 |x.Z-...=........|
410 0080: af 31 de 17 fa b7 42 28 78 ee 5a 2d ad bc 94 3d |.1....B(x.Z-...=|
410 0080: af 31 de 17 fa b7 42 28 78 ee 5a 2d ad bc 94 3d |.1....B(x.Z-...=|
411
411
412 $ hg debugtagscache | tail -2
412 $ hg debugtagscache | tail -2
413 4 0c192d7d5e6b78a714de54a2e9627952a877e25a 0c04f2a8af31de17fab7422878ee5a2dadbc943d
413 4 0c192d7d5e6b78a714de54a2e9627952a877e25a 0c04f2a8af31de17fab7422878ee5a2dadbc943d
414 5 8dbfe60eff306a54259cfe007db9e330e7ecf866 invalid
414 5 8dbfe60eff306a54259cfe007db9e330e7ecf866 invalid
415
415
416 $ hg tags
416 $ hg tags
417 tip 5:8dbfe60eff30
417 tip 5:8dbfe60eff30
418 bar 1:78391a272241
418 bar 1:78391a272241
419
419
420 BUG: If the filenode part of an entry in hgtagsfnodes is corrupt and
420 BUG: If the filenode part of an entry in hgtagsfnodes is corrupt and
421 tags2-visible is missing, `hg tags` aborts. Corrupting the leading 4 bytes of
421 tags2-visible is missing, `hg tags` aborts. Corrupting the leading 4 bytes of
422 node hash (as above) doesn't seem to trigger the issue. Also note that the
422 node hash (as above) doesn't seem to trigger the issue. Also note that the
423 debug command hides the corruption, both with and without tags2-visible.
423 debug command hides the corruption, both with and without tags2-visible.
424
424
425 $ mv .hg/cache/hgtagsfnodes1 .hg/cache/hgtagsfnodes1.bak
425 $ mv .hg/cache/hgtagsfnodes1 .hg/cache/hgtagsfnodes1.bak
426 $ hg debugupdatecaches
426 $ hg debugupdatecaches
427
427
428 >>> import os
428 >>> import os
429 >>> with open(".hg/cache/hgtagsfnodes1", "rb+") as fp:
429 >>> with open(".hg/cache/hgtagsfnodes1", "rb+") as fp:
430 ... fp.seek(-16, os.SEEK_END) and None
430 ... fp.seek(-16, os.SEEK_END) and None
431 ... fp.write(b'\xde\xad') and None
431 ... fp.write(b'\xde\xad') and None
432
432
433 $ f --size --hexdump .hg/cache/hgtagsfnodes1
433 $ f --size --hexdump .hg/cache/hgtagsfnodes1
434 .hg/cache/hgtagsfnodes1: size=144
434 .hg/cache/hgtagsfnodes1: size=144
435 0000: bb d1 79 df 00 00 00 00 00 00 00 00 00 00 00 00 |..y.............|
435 0000: bb d1 79 df 00 00 00 00 00 00 00 00 00 00 00 00 |..y.............|
436 0010: 00 00 00 00 00 00 00 00 78 39 1a 27 0c 04 f2 a8 |........x9.'....|
436 0010: 00 00 00 00 00 00 00 00 78 39 1a 27 0c 04 f2 a8 |........x9.'....|
437 0020: af 31 de 17 fa b7 42 28 78 ee 5a 2d ad bc 94 3d |.1....B(x.Z-...=|
437 0020: af 31 de 17 fa b7 42 28 78 ee 5a 2d ad bc 94 3d |.1....B(x.Z-...=|
438 0030: 7a 94 12 77 0c 04 f2 a8 af 31 de 17 fa b7 42 28 |z..w.....1....B(|
438 0030: 7a 94 12 77 0c 04 f2 a8 af 31 de 17 fa b7 42 28 |z..w.....1....B(|
439 0040: 78 ee 5a 2d ad bc 94 3d 6f a4 50 21 7d 3b 71 8c |x.Z-...=o.P!};q.|
439 0040: 78 ee 5a 2d ad bc 94 3d 6f a4 50 21 7d 3b 71 8c |x.Z-...=o.P!};q.|
440 0050: 96 4e f3 7b 89 e5 50 eb da fd 57 89 e7 6c e1 b0 |.N.{..P...W..l..|
440 0050: 96 4e f3 7b 89 e5 50 eb da fd 57 89 e7 6c e1 b0 |.N.{..P...W..l..|
441 0060: 0c 19 2d 7d 0c 04 f2 a8 af 31 de 17 fa b7 42 28 |..-}.....1....B(|
441 0060: 0c 19 2d 7d 0c 04 f2 a8 af 31 de 17 fa b7 42 28 |..-}.....1....B(|
442 0070: 78 ee 5a 2d ad bc 94 3d 8d bf e6 0e 0c 04 f2 a8 |x.Z-...=........|
442 0070: 78 ee 5a 2d ad bc 94 3d 8d bf e6 0e 0c 04 f2 a8 |x.Z-...=........|
443 0080: de ad de 17 fa b7 42 28 78 ee 5a 2d ad bc 94 3d |......B(x.Z-...=|
443 0080: de ad de 17 fa b7 42 28 78 ee 5a 2d ad bc 94 3d |......B(x.Z-...=|
444
444
445 $ hg debugtagscache | tail -2
445 $ hg debugtagscache | tail -2
446 4 0c192d7d5e6b78a714de54a2e9627952a877e25a 0c04f2a8af31de17fab7422878ee5a2dadbc943d
446 4 0c192d7d5e6b78a714de54a2e9627952a877e25a 0c04f2a8af31de17fab7422878ee5a2dadbc943d
447 5 8dbfe60eff306a54259cfe007db9e330e7ecf866 0c04f2a8deadde17fab7422878ee5a2dadbc943d (unknown node)
447 5 8dbfe60eff306a54259cfe007db9e330e7ecf866 0c04f2a8deadde17fab7422878ee5a2dadbc943d (unknown node)
448
448
449 $ rm -f .hg/cache/tags2-visible
449 $ rm -f .hg/cache/tags2-visible
450 $ hg debugtagscache | tail -2
450 $ hg debugtagscache | tail -2
451 4 0c192d7d5e6b78a714de54a2e9627952a877e25a 0c04f2a8af31de17fab7422878ee5a2dadbc943d
451 4 0c192d7d5e6b78a714de54a2e9627952a877e25a 0c04f2a8af31de17fab7422878ee5a2dadbc943d
452 5 8dbfe60eff306a54259cfe007db9e330e7ecf866 0c04f2a8deadde17fab7422878ee5a2dadbc943d (unknown node)
452 5 8dbfe60eff306a54259cfe007db9e330e7ecf866 0c04f2a8deadde17fab7422878ee5a2dadbc943d (unknown node)
453
453
454 $ hg tags
454 $ hg tags
455 abort: data/.hgtags.i@0c04f2a8deadde17fab7422878ee5a2dadbc943d: no match found
455 tip 5:8dbfe60eff30
456 [50]
456 bar 1:78391a272241
457
457
458 BUG: Unless this file is restored, the `hg tags` in the next unix-permissions
458 BUG: Unless this file is restored, the `hg tags` in the next unix-permissions
459 conditional will fail: "abort: data/.hgtags.i@0c04f2a8dead: no match found"
459 conditional will fail: "abort: data/.hgtags.i@0c04f2a8dead: no match found"
460
460
461 $ mv .hg/cache/hgtagsfnodes1.bak .hg/cache/hgtagsfnodes1
461 $ mv .hg/cache/hgtagsfnodes1.bak .hg/cache/hgtagsfnodes1
462
462
463 #if unix-permissions no-root
463 #if unix-permissions no-root
464 Errors writing to .hgtags fnodes cache are silently ignored
464 Errors writing to .hgtags fnodes cache are silently ignored
465
465
466 $ echo dummy2 > foo
466 $ echo dummy2 > foo
467 $ hg commit -m throwaway2
467 $ hg commit -m throwaway2
468
468
469 $ chmod a-w .hg/cache/hgtagsfnodes1
469 $ chmod a-w .hg/cache/hgtagsfnodes1
470 $ rm -f .hg/cache/tags2-visible
470 $ rm -f .hg/cache/tags2-visible
471
471
472 $ hg tags
472 $ hg tags
473 tip 6:b968051b5cf3
473 tip 6:b968051b5cf3
474 bar 1:78391a272241
474 bar 1:78391a272241
475
475
476 $ hg blackbox -l 6
476 $ hg blackbox -l 6
477 1970/01/01 00:00:00 bob @b968051b5cf3f624b771779c6d5f84f1d4c3fb5d (5000)> tags
477 1970/01/01 00:00:00 bob @b968051b5cf3f624b771779c6d5f84f1d4c3fb5d (5000)> tags
478 1970/01/01 00:00:00 bob @b968051b5cf3f624b771779c6d5f84f1d4c3fb5d (5000)> couldn't write cache/hgtagsfnodes1: [Errno *] * (glob)
478 1970/01/01 00:00:00 bob @b968051b5cf3f624b771779c6d5f84f1d4c3fb5d (5000)> couldn't write cache/hgtagsfnodes1: [Errno *] * (glob)
479 1970/01/01 00:00:00 bob @b968051b5cf3f624b771779c6d5f84f1d4c3fb5d (5000)> 2/4 cache hits/lookups in * seconds (glob)
479 1970/01/01 00:00:00 bob @b968051b5cf3f624b771779c6d5f84f1d4c3fb5d (5000)> 2/4 cache hits/lookups in * seconds (glob)
480 1970/01/01 00:00:00 bob @b968051b5cf3f624b771779c6d5f84f1d4c3fb5d (5000)> writing .hg/cache/tags2-visible with 1 tags
480 1970/01/01 00:00:00 bob @b968051b5cf3f624b771779c6d5f84f1d4c3fb5d (5000)> writing .hg/cache/tags2-visible with 1 tags
481 1970/01/01 00:00:00 bob @b968051b5cf3f624b771779c6d5f84f1d4c3fb5d (5000)> tags exited 0 after * seconds (glob)
481 1970/01/01 00:00:00 bob @b968051b5cf3f624b771779c6d5f84f1d4c3fb5d (5000)> tags exited 0 after * seconds (glob)
482 1970/01/01 00:00:00 bob @b968051b5cf3f624b771779c6d5f84f1d4c3fb5d (5000)> blackbox -l 6
482 1970/01/01 00:00:00 bob @b968051b5cf3f624b771779c6d5f84f1d4c3fb5d (5000)> blackbox -l 6
483
483
484 $ chmod a+w .hg/cache/hgtagsfnodes1
484 $ chmod a+w .hg/cache/hgtagsfnodes1
485
485
486 $ rm -f .hg/cache/tags2-visible
486 $ rm -f .hg/cache/tags2-visible
487 $ hg tags
487 $ hg tags
488 tip 6:b968051b5cf3
488 tip 6:b968051b5cf3
489 bar 1:78391a272241
489 bar 1:78391a272241
490
490
491 $ hg blackbox -l 6
491 $ hg blackbox -l 6
492 1970/01/01 00:00:00 bob @b968051b5cf3f624b771779c6d5f84f1d4c3fb5d (5000)> tags
492 1970/01/01 00:00:00 bob @b968051b5cf3f624b771779c6d5f84f1d4c3fb5d (5000)> tags
493 1970/01/01 00:00:00 bob @b968051b5cf3f624b771779c6d5f84f1d4c3fb5d (5000)> writing 24 bytes to cache/hgtagsfnodes1
493 1970/01/01 00:00:00 bob @b968051b5cf3f624b771779c6d5f84f1d4c3fb5d (5000)> writing 24 bytes to cache/hgtagsfnodes1
494 1970/01/01 00:00:00 bob @b968051b5cf3f624b771779c6d5f84f1d4c3fb5d (5000)> 2/4 cache hits/lookups in * seconds (glob)
494 1970/01/01 00:00:00 bob @b968051b5cf3f624b771779c6d5f84f1d4c3fb5d (5000)> 2/4 cache hits/lookups in * seconds (glob)
495 1970/01/01 00:00:00 bob @b968051b5cf3f624b771779c6d5f84f1d4c3fb5d (5000)> writing .hg/cache/tags2-visible with 1 tags
495 1970/01/01 00:00:00 bob @b968051b5cf3f624b771779c6d5f84f1d4c3fb5d (5000)> writing .hg/cache/tags2-visible with 1 tags
496 1970/01/01 00:00:00 bob @b968051b5cf3f624b771779c6d5f84f1d4c3fb5d (5000)> tags exited 0 after * seconds (glob)
496 1970/01/01 00:00:00 bob @b968051b5cf3f624b771779c6d5f84f1d4c3fb5d (5000)> tags exited 0 after * seconds (glob)
497 1970/01/01 00:00:00 bob @b968051b5cf3f624b771779c6d5f84f1d4c3fb5d (5000)> blackbox -l 6
497 1970/01/01 00:00:00 bob @b968051b5cf3f624b771779c6d5f84f1d4c3fb5d (5000)> blackbox -l 6
498
498
499 $ f --size .hg/cache/hgtagsfnodes1
499 $ f --size .hg/cache/hgtagsfnodes1
500 .hg/cache/hgtagsfnodes1: size=168
500 .hg/cache/hgtagsfnodes1: size=168
501
501
502 $ hg -q --config extensions.strip= strip -r 6 --no-backup
502 $ hg -q --config extensions.strip= strip -r 6 --no-backup
503 #endif
503 #endif
504
504
505 Stripping doesn't truncate the tags cache until new data is available
505 Stripping doesn't truncate the tags cache until new data is available
506
506
507 $ rm -f .hg/cache/hgtagsfnodes1 .hg/cache/tags2-visible
507 $ rm -f .hg/cache/hgtagsfnodes1 .hg/cache/tags2-visible
508 $ hg tags
508 $ hg tags
509 tip 5:8dbfe60eff30
509 tip 5:8dbfe60eff30
510 bar 1:78391a272241
510 bar 1:78391a272241
511
511
512 $ f --size .hg/cache/hgtagsfnodes1
512 $ f --size .hg/cache/hgtagsfnodes1
513 .hg/cache/hgtagsfnodes1: size=144
513 .hg/cache/hgtagsfnodes1: size=144
514
514
515 $ hg -q --config extensions.strip= strip -r 5 --no-backup
515 $ hg -q --config extensions.strip= strip -r 5 --no-backup
516 $ hg tags
516 $ hg tags
517 tip 4:0c192d7d5e6b
517 tip 4:0c192d7d5e6b
518 bar 1:78391a272241
518 bar 1:78391a272241
519
519
520 $ hg blackbox -l 5
520 $ hg blackbox -l 5
521 1970/01/01 00:00:00 bob @0c192d7d5e6b78a714de54a2e9627952a877e25a (5000)> writing 24 bytes to cache/hgtagsfnodes1
521 1970/01/01 00:00:00 bob @0c192d7d5e6b78a714de54a2e9627952a877e25a (5000)> writing 24 bytes to cache/hgtagsfnodes1
522 1970/01/01 00:00:00 bob @0c192d7d5e6b78a714de54a2e9627952a877e25a (5000)> 2/4 cache hits/lookups in * seconds (glob)
522 1970/01/01 00:00:00 bob @0c192d7d5e6b78a714de54a2e9627952a877e25a (5000)> 2/4 cache hits/lookups in * seconds (glob)
523 1970/01/01 00:00:00 bob @0c192d7d5e6b78a714de54a2e9627952a877e25a (5000)> writing .hg/cache/tags2-visible with 1 tags
523 1970/01/01 00:00:00 bob @0c192d7d5e6b78a714de54a2e9627952a877e25a (5000)> writing .hg/cache/tags2-visible with 1 tags
524 1970/01/01 00:00:00 bob @0c192d7d5e6b78a714de54a2e9627952a877e25a (5000)> tags exited 0 after * seconds (glob)
524 1970/01/01 00:00:00 bob @0c192d7d5e6b78a714de54a2e9627952a877e25a (5000)> tags exited 0 after * seconds (glob)
525 1970/01/01 00:00:00 bob @0c192d7d5e6b78a714de54a2e9627952a877e25a (5000)> blackbox -l 5
525 1970/01/01 00:00:00 bob @0c192d7d5e6b78a714de54a2e9627952a877e25a (5000)> blackbox -l 5
526
526
527 $ f --size .hg/cache/hgtagsfnodes1
527 $ f --size .hg/cache/hgtagsfnodes1
528 .hg/cache/hgtagsfnodes1: size=120
528 .hg/cache/hgtagsfnodes1: size=120
529
529
530 $ echo dummy > foo
530 $ echo dummy > foo
531 $ hg commit -m throwaway3
531 $ hg commit -m throwaway3
532
532
533 $ hg tags
533 $ hg tags
534 tip 5:035f65efb448
534 tip 5:035f65efb448
535 bar 1:78391a272241
535 bar 1:78391a272241
536
536
537 $ hg blackbox -l 6
537 $ hg blackbox -l 6
538 1970/01/01 00:00:00 bob @035f65efb448350f4772141702a81ab1df48c465 (5000)> tags
538 1970/01/01 00:00:00 bob @035f65efb448350f4772141702a81ab1df48c465 (5000)> tags
539 1970/01/01 00:00:00 bob @035f65efb448350f4772141702a81ab1df48c465 (5000)> writing 24 bytes to cache/hgtagsfnodes1
539 1970/01/01 00:00:00 bob @035f65efb448350f4772141702a81ab1df48c465 (5000)> writing 24 bytes to cache/hgtagsfnodes1
540 1970/01/01 00:00:00 bob @035f65efb448350f4772141702a81ab1df48c465 (5000)> 3/4 cache hits/lookups in * seconds (glob)
540 1970/01/01 00:00:00 bob @035f65efb448350f4772141702a81ab1df48c465 (5000)> 3/4 cache hits/lookups in * seconds (glob)
541 1970/01/01 00:00:00 bob @035f65efb448350f4772141702a81ab1df48c465 (5000)> writing .hg/cache/tags2-visible with 1 tags
541 1970/01/01 00:00:00 bob @035f65efb448350f4772141702a81ab1df48c465 (5000)> writing .hg/cache/tags2-visible with 1 tags
542 1970/01/01 00:00:00 bob @035f65efb448350f4772141702a81ab1df48c465 (5000)> tags exited 0 after * seconds (glob)
542 1970/01/01 00:00:00 bob @035f65efb448350f4772141702a81ab1df48c465 (5000)> tags exited 0 after * seconds (glob)
543 1970/01/01 00:00:00 bob @035f65efb448350f4772141702a81ab1df48c465 (5000)> blackbox -l 6
543 1970/01/01 00:00:00 bob @035f65efb448350f4772141702a81ab1df48c465 (5000)> blackbox -l 6
544 $ f --size .hg/cache/hgtagsfnodes1
544 $ f --size .hg/cache/hgtagsfnodes1
545 .hg/cache/hgtagsfnodes1: size=144
545 .hg/cache/hgtagsfnodes1: size=144
546
546
547 $ hg -q --config extensions.strip= strip -r 5 --no-backup
547 $ hg -q --config extensions.strip= strip -r 5 --no-backup
548
548
549 Test tag removal:
549 Test tag removal:
550
550
551 $ hg tag --remove bar # rev 5
551 $ hg tag --remove bar # rev 5
552 $ hg tip -vp
552 $ hg tip -vp
553 changeset: 5:5f6e8655b1c7
553 changeset: 5:5f6e8655b1c7
554 tag: tip
554 tag: tip
555 user: test
555 user: test
556 date: Thu Jan 01 00:00:00 1970 +0000
556 date: Thu Jan 01 00:00:00 1970 +0000
557 files: .hgtags
557 files: .hgtags
558 description:
558 description:
559 Removed tag bar
559 Removed tag bar
560
560
561
561
562 diff -r 0c192d7d5e6b -r 5f6e8655b1c7 .hgtags
562 diff -r 0c192d7d5e6b -r 5f6e8655b1c7 .hgtags
563 --- a/.hgtags Thu Jan 01 00:00:00 1970 +0000
563 --- a/.hgtags Thu Jan 01 00:00:00 1970 +0000
564 +++ b/.hgtags Thu Jan 01 00:00:00 1970 +0000
564 +++ b/.hgtags Thu Jan 01 00:00:00 1970 +0000
565 @@ -1,1 +1,3 @@
565 @@ -1,1 +1,3 @@
566 bbd179dfa0a71671c253b3ae0aa1513b60d199fa bar
566 bbd179dfa0a71671c253b3ae0aa1513b60d199fa bar
567 +78391a272241d70354aa14c874552cad6b51bb42 bar
567 +78391a272241d70354aa14c874552cad6b51bb42 bar
568 +0000000000000000000000000000000000000000 bar
568 +0000000000000000000000000000000000000000 bar
569
569
570 $ hg tags
570 $ hg tags
571 tip 5:5f6e8655b1c7
571 tip 5:5f6e8655b1c7
572 $ hg tags # again, try to expose cache bugs
572 $ hg tags # again, try to expose cache bugs
573 tip 5:5f6e8655b1c7
573 tip 5:5f6e8655b1c7
574
574
575 Remove nonexistent tag:
575 Remove nonexistent tag:
576
576
577 $ hg tag --remove foobar
577 $ hg tag --remove foobar
578 abort: tag 'foobar' does not exist
578 abort: tag 'foobar' does not exist
579 [10]
579 [10]
580 $ hg tip
580 $ hg tip
581 changeset: 5:5f6e8655b1c7
581 changeset: 5:5f6e8655b1c7
582 tag: tip
582 tag: tip
583 user: test
583 user: test
584 date: Thu Jan 01 00:00:00 1970 +0000
584 date: Thu Jan 01 00:00:00 1970 +0000
585 summary: Removed tag bar
585 summary: Removed tag bar
586
586
587
587
588 Undo a tag with rollback:
588 Undo a tag with rollback:
589
589
590 $ hg rollback # destroy rev 5 (restore bar)
590 $ hg rollback # destroy rev 5 (restore bar)
591 repository tip rolled back to revision 4 (undo commit)
591 repository tip rolled back to revision 4 (undo commit)
592 working directory now based on revision 4
592 working directory now based on revision 4
593 $ hg tags
593 $ hg tags
594 tip 4:0c192d7d5e6b
594 tip 4:0c192d7d5e6b
595 bar 1:78391a272241
595 bar 1:78391a272241
596 $ hg tags
596 $ hg tags
597 tip 4:0c192d7d5e6b
597 tip 4:0c192d7d5e6b
598 bar 1:78391a272241
598 bar 1:78391a272241
599
599
600 Test tag rank:
600 Test tag rank:
601
601
602 $ cd ..
602 $ cd ..
603 $ hg init t3
603 $ hg init t3
604 $ cd t3
604 $ cd t3
605 $ echo foo > foo
605 $ echo foo > foo
606 $ hg add foo
606 $ hg add foo
607 $ hg ci -m 'add foo' # rev 0
607 $ hg ci -m 'add foo' # rev 0
608 $ hg tag -f bar # rev 1 bar -> 0
608 $ hg tag -f bar # rev 1 bar -> 0
609 $ hg tag -f bar # rev 2 bar -> 1
609 $ hg tag -f bar # rev 2 bar -> 1
610 $ hg tag -fr 0 bar # rev 3 bar -> 0
610 $ hg tag -fr 0 bar # rev 3 bar -> 0
611 $ hg tag -fr 1 bar # rev 4 bar -> 1
611 $ hg tag -fr 1 bar # rev 4 bar -> 1
612 $ hg tag -fr 0 bar # rev 5 bar -> 0
612 $ hg tag -fr 0 bar # rev 5 bar -> 0
613 $ hg tags
613 $ hg tags
614 tip 5:85f05169d91d
614 tip 5:85f05169d91d
615 bar 0:bbd179dfa0a7
615 bar 0:bbd179dfa0a7
616 $ hg co 3
616 $ hg co 3
617 1 files updated, 0 files merged, 0 files removed, 0 files unresolved
617 1 files updated, 0 files merged, 0 files removed, 0 files unresolved
618 $ echo barbar > foo
618 $ echo barbar > foo
619 $ hg ci -m 'change foo' # rev 6
619 $ hg ci -m 'change foo' # rev 6
620 created new head
620 created new head
621 $ hg tags
621 $ hg tags
622 tip 6:735c3ca72986
622 tip 6:735c3ca72986
623 bar 0:bbd179dfa0a7
623 bar 0:bbd179dfa0a7
624
624
625 Don't allow moving tag without -f:
625 Don't allow moving tag without -f:
626
626
627 $ hg tag -r 3 bar
627 $ hg tag -r 3 bar
628 abort: tag 'bar' already exists (use -f to force)
628 abort: tag 'bar' already exists (use -f to force)
629 [10]
629 [10]
630 $ hg tags
630 $ hg tags
631 tip 6:735c3ca72986
631 tip 6:735c3ca72986
632 bar 0:bbd179dfa0a7
632 bar 0:bbd179dfa0a7
633
633
634 Strip 1: expose an old head:
634 Strip 1: expose an old head:
635
635
636 $ hg --config extensions.mq= strip 5
636 $ hg --config extensions.mq= strip 5
637 saved backup bundle to $TESTTMP/t3/.hg/strip-backup/*-backup.hg (glob)
637 saved backup bundle to $TESTTMP/t3/.hg/strip-backup/*-backup.hg (glob)
638 $ hg tags # partly stale cache
638 $ hg tags # partly stale cache
639 tip 5:735c3ca72986
639 tip 5:735c3ca72986
640 bar 1:78391a272241
640 bar 1:78391a272241
641 $ hg tags # up-to-date cache
641 $ hg tags # up-to-date cache
642 tip 5:735c3ca72986
642 tip 5:735c3ca72986
643 bar 1:78391a272241
643 bar 1:78391a272241
644
644
645 Strip 2: destroy whole branch, no old head exposed
645 Strip 2: destroy whole branch, no old head exposed
646
646
647 $ hg --config extensions.mq= strip 4
647 $ hg --config extensions.mq= strip 4
648 saved backup bundle to $TESTTMP/t3/.hg/strip-backup/*-backup.hg (glob)
648 saved backup bundle to $TESTTMP/t3/.hg/strip-backup/*-backup.hg (glob)
649 $ hg tags # partly stale
649 $ hg tags # partly stale
650 tip 4:735c3ca72986
650 tip 4:735c3ca72986
651 bar 0:bbd179dfa0a7
651 bar 0:bbd179dfa0a7
652 $ rm -f .hg/cache/tags2-visible
652 $ rm -f .hg/cache/tags2-visible
653 $ hg tags # cold cache
653 $ hg tags # cold cache
654 tip 4:735c3ca72986
654 tip 4:735c3ca72986
655 bar 0:bbd179dfa0a7
655 bar 0:bbd179dfa0a7
656
656
657 Test tag rank with 3 heads:
657 Test tag rank with 3 heads:
658
658
659 $ cd ..
659 $ cd ..
660 $ hg init t4
660 $ hg init t4
661 $ cd t4
661 $ cd t4
662 $ echo foo > foo
662 $ echo foo > foo
663 $ hg add
663 $ hg add
664 adding foo
664 adding foo
665 $ hg ci -m 'add foo' # rev 0
665 $ hg ci -m 'add foo' # rev 0
666 $ hg tag bar # rev 1 bar -> 0
666 $ hg tag bar # rev 1 bar -> 0
667 $ hg tag -f bar # rev 2 bar -> 1
667 $ hg tag -f bar # rev 2 bar -> 1
668 $ hg up -qC 0
668 $ hg up -qC 0
669 $ hg tag -fr 2 bar # rev 3 bar -> 2
669 $ hg tag -fr 2 bar # rev 3 bar -> 2
670 $ hg tags
670 $ hg tags
671 tip 3:197c21bbbf2c
671 tip 3:197c21bbbf2c
672 bar 2:6fa450212aeb
672 bar 2:6fa450212aeb
673 $ hg up -qC 0
673 $ hg up -qC 0
674 $ hg tag -m 'retag rev 0' -fr 0 bar # rev 4 bar -> 0, but bar stays at 2
674 $ hg tag -m 'retag rev 0' -fr 0 bar # rev 4 bar -> 0, but bar stays at 2
675
675
676 Bar should still point to rev 2:
676 Bar should still point to rev 2:
677
677
678 $ hg tags
678 $ hg tags
679 tip 4:3b4b14ed0202
679 tip 4:3b4b14ed0202
680 bar 2:6fa450212aeb
680 bar 2:6fa450212aeb
681
681
682 Test that removing global/local tags does not get confused when trying
682 Test that removing global/local tags does not get confused when trying
683 to remove a tag of type X which actually only exists as a type Y:
683 to remove a tag of type X which actually only exists as a type Y:
684
684
685 $ cd ..
685 $ cd ..
686 $ hg init t5
686 $ hg init t5
687 $ cd t5
687 $ cd t5
688 $ echo foo > foo
688 $ echo foo > foo
689 $ hg add
689 $ hg add
690 adding foo
690 adding foo
691 $ hg ci -m 'add foo' # rev 0
691 $ hg ci -m 'add foo' # rev 0
692
692
693 $ hg tag -r 0 -l localtag
693 $ hg tag -r 0 -l localtag
694 $ hg tag --remove localtag
694 $ hg tag --remove localtag
695 abort: tag 'localtag' is not a global tag
695 abort: tag 'localtag' is not a global tag
696 [10]
696 [10]
697 $
697 $
698 $ hg tag -r 0 globaltag
698 $ hg tag -r 0 globaltag
699 $ hg tag --remove -l globaltag
699 $ hg tag --remove -l globaltag
700 abort: tag 'globaltag' is not a local tag
700 abort: tag 'globaltag' is not a local tag
701 [10]
701 [10]
702 $ hg tags -v
702 $ hg tags -v
703 tip 1:a0b6fe111088
703 tip 1:a0b6fe111088
704 localtag 0:bbd179dfa0a7 local
704 localtag 0:bbd179dfa0a7 local
705 globaltag 0:bbd179dfa0a7
705 globaltag 0:bbd179dfa0a7
706
706
707 Templated output:
707 Templated output:
708
708
709 (immediate values)
709 (immediate values)
710
710
711 $ hg tags -T '{pad(tag, 9)} {rev}:{node} ({type})\n'
711 $ hg tags -T '{pad(tag, 9)} {rev}:{node} ({type})\n'
712 tip 1:a0b6fe111088c8c29567d3876cc466aa02927cae ()
712 tip 1:a0b6fe111088c8c29567d3876cc466aa02927cae ()
713 localtag 0:bbd179dfa0a71671c253b3ae0aa1513b60d199fa (local)
713 localtag 0:bbd179dfa0a71671c253b3ae0aa1513b60d199fa (local)
714 globaltag 0:bbd179dfa0a71671c253b3ae0aa1513b60d199fa ()
714 globaltag 0:bbd179dfa0a71671c253b3ae0aa1513b60d199fa ()
715
715
716 (ctx/revcache dependent)
716 (ctx/revcache dependent)
717
717
718 $ hg tags -T '{pad(tag, 9)} {rev} {file_adds}\n'
718 $ hg tags -T '{pad(tag, 9)} {rev} {file_adds}\n'
719 tip 1 .hgtags
719 tip 1 .hgtags
720 localtag 0 foo
720 localtag 0 foo
721 globaltag 0 foo
721 globaltag 0 foo
722
722
723 $ hg tags -T '{pad(tag, 9)} {rev}:{node|shortest}\n'
723 $ hg tags -T '{pad(tag, 9)} {rev}:{node|shortest}\n'
724 tip 1:a0b6
724 tip 1:a0b6
725 localtag 0:bbd1
725 localtag 0:bbd1
726 globaltag 0:bbd1
726 globaltag 0:bbd1
727
727
728 Test for issue3911
728 Test for issue3911
729
729
730 $ hg tag -r 0 -l localtag2
730 $ hg tag -r 0 -l localtag2
731 $ hg tag -l --remove localtag2
731 $ hg tag -l --remove localtag2
732 $ hg tags -v
732 $ hg tags -v
733 tip 1:a0b6fe111088
733 tip 1:a0b6fe111088
734 localtag 0:bbd179dfa0a7 local
734 localtag 0:bbd179dfa0a7 local
735 globaltag 0:bbd179dfa0a7
735 globaltag 0:bbd179dfa0a7
736
736
737 $ hg tag -r 1 -f localtag
737 $ hg tag -r 1 -f localtag
738 $ hg tags -v
738 $ hg tags -v
739 tip 2:5c70a037bb37
739 tip 2:5c70a037bb37
740 localtag 1:a0b6fe111088
740 localtag 1:a0b6fe111088
741 globaltag 0:bbd179dfa0a7
741 globaltag 0:bbd179dfa0a7
742
742
743 $ hg tags -v
743 $ hg tags -v
744 tip 2:5c70a037bb37
744 tip 2:5c70a037bb37
745 localtag 1:a0b6fe111088
745 localtag 1:a0b6fe111088
746 globaltag 0:bbd179dfa0a7
746 globaltag 0:bbd179dfa0a7
747
747
748 $ hg tag -r 1 localtag2
748 $ hg tag -r 1 localtag2
749 $ hg tags -v
749 $ hg tags -v
750 tip 3:bbfb8cd42be2
750 tip 3:bbfb8cd42be2
751 localtag2 1:a0b6fe111088
751 localtag2 1:a0b6fe111088
752 localtag 1:a0b6fe111088
752 localtag 1:a0b6fe111088
753 globaltag 0:bbd179dfa0a7
753 globaltag 0:bbd179dfa0a7
754
754
755 $ hg tags -v
755 $ hg tags -v
756 tip 3:bbfb8cd42be2
756 tip 3:bbfb8cd42be2
757 localtag2 1:a0b6fe111088
757 localtag2 1:a0b6fe111088
758 localtag 1:a0b6fe111088
758 localtag 1:a0b6fe111088
759 globaltag 0:bbd179dfa0a7
759 globaltag 0:bbd179dfa0a7
760
760
761 $ cd ..
761 $ cd ..
762
762
763 Create a repository with tags data to test .hgtags fnodes transfer
763 Create a repository with tags data to test .hgtags fnodes transfer
764
764
765 $ hg init tagsserver
765 $ hg init tagsserver
766 $ cd tagsserver
766 $ cd tagsserver
767 $ touch foo
767 $ touch foo
768 $ hg -q commit -A -m initial
768 $ hg -q commit -A -m initial
769 $ hg tag -m 'tag 0.1' 0.1
769 $ hg tag -m 'tag 0.1' 0.1
770 $ echo second > foo
770 $ echo second > foo
771 $ hg commit -m second
771 $ hg commit -m second
772 $ hg tag -m 'tag 0.2' 0.2
772 $ hg tag -m 'tag 0.2' 0.2
773 $ hg tags
773 $ hg tags
774 tip 3:40f0358cb314
774 tip 3:40f0358cb314
775 0.2 2:f63cc8fe54e4
775 0.2 2:f63cc8fe54e4
776 0.1 0:96ee1d7354c4
776 0.1 0:96ee1d7354c4
777 $ cd ..
777 $ cd ..
778
778
779 Cloning should pull down hgtags fnodes mappings and write the cache file
779 Cloning should pull down hgtags fnodes mappings and write the cache file
780
780
781 $ hg clone --pull tagsserver tagsclient
781 $ hg clone --pull tagsserver tagsclient
782 requesting all changes
782 requesting all changes
783 adding changesets
783 adding changesets
784 adding manifests
784 adding manifests
785 adding file changes
785 adding file changes
786 added 4 changesets with 4 changes to 2 files
786 added 4 changesets with 4 changes to 2 files
787 new changesets 96ee1d7354c4:40f0358cb314
787 new changesets 96ee1d7354c4:40f0358cb314
788 updating to branch default
788 updating to branch default
789 2 files updated, 0 files merged, 0 files removed, 0 files unresolved
789 2 files updated, 0 files merged, 0 files removed, 0 files unresolved
790
790
791 Missing tags2* files means the cache wasn't written through the normal mechanism.
791 Missing tags2* files means the cache wasn't written through the normal mechanism.
792
792
793 $ ls tagsclient/.hg/cache
793 $ ls tagsclient/.hg/cache
794 branch2-base
794 branch2-base
795 branch2-immutable
795 branch2-immutable
796 branch2-served
796 branch2-served
797 branch2-served.hidden
797 branch2-served.hidden
798 branch2-visible
798 branch2-visible
799 branch2-visible-hidden
799 branch2-visible-hidden
800 hgtagsfnodes1
800 hgtagsfnodes1
801 rbc-names-v1
801 rbc-names-v1
802 rbc-revs-v1
802 rbc-revs-v1
803 tags2
803 tags2
804 tags2-served
804 tags2-served
805
805
806 Cache should contain the head only, even though other nodes have tags data
806 Cache should contain the head only, even though other nodes have tags data
807
807
808 $ f --size --hexdump tagsclient/.hg/cache/hgtagsfnodes1
808 $ f --size --hexdump tagsclient/.hg/cache/hgtagsfnodes1
809 tagsclient/.hg/cache/hgtagsfnodes1: size=96
809 tagsclient/.hg/cache/hgtagsfnodes1: size=96
810 0000: 96 ee 1d 73 00 00 00 00 00 00 00 00 00 00 00 00 |...s............|
810 0000: 96 ee 1d 73 00 00 00 00 00 00 00 00 00 00 00 00 |...s............|
811 0010: 00 00 00 00 00 00 00 00 c4 da b0 c2 94 65 e1 c6 |.............e..|
811 0010: 00 00 00 00 00 00 00 00 c4 da b0 c2 94 65 e1 c6 |.............e..|
812 0020: 0d f7 f0 dd 32 04 ea 57 78 c8 97 97 79 fc d5 95 |....2..Wx...y...|
812 0020: 0d f7 f0 dd 32 04 ea 57 78 c8 97 97 79 fc d5 95 |....2..Wx...y...|
813 0030: f6 3c c8 fe 94 65 e1 c6 0d f7 f0 dd 32 04 ea 57 |.<...e......2..W|
813 0030: f6 3c c8 fe 94 65 e1 c6 0d f7 f0 dd 32 04 ea 57 |.<...e......2..W|
814 0040: 78 c8 97 97 79 fc d5 95 40 f0 35 8c 19 e0 a7 d3 |x...y...@.5.....|
814 0040: 78 c8 97 97 79 fc d5 95 40 f0 35 8c 19 e0 a7 d3 |x...y...@.5.....|
815 0050: 8a 5c 6a 82 4d cf fb a5 87 d0 2f a3 1e 4f 2f 8a |.\j.M...../..O/.|
815 0050: 8a 5c 6a 82 4d cf fb a5 87 d0 2f a3 1e 4f 2f 8a |.\j.M...../..O/.|
816
816
817 Running hg tags should produce tags2* file and not change cache
817 Running hg tags should produce tags2* file and not change cache
818
818
819 $ hg -R tagsclient tags
819 $ hg -R tagsclient tags
820 tip 3:40f0358cb314
820 tip 3:40f0358cb314
821 0.2 2:f63cc8fe54e4
821 0.2 2:f63cc8fe54e4
822 0.1 0:96ee1d7354c4
822 0.1 0:96ee1d7354c4
823
823
824 $ ls tagsclient/.hg/cache
824 $ ls tagsclient/.hg/cache
825 branch2-base
825 branch2-base
826 branch2-immutable
826 branch2-immutable
827 branch2-served
827 branch2-served
828 branch2-served.hidden
828 branch2-served.hidden
829 branch2-visible
829 branch2-visible
830 branch2-visible-hidden
830 branch2-visible-hidden
831 hgtagsfnodes1
831 hgtagsfnodes1
832 rbc-names-v1
832 rbc-names-v1
833 rbc-revs-v1
833 rbc-revs-v1
834 tags2
834 tags2
835 tags2-served
835 tags2-served
836 tags2-visible
836 tags2-visible
837
837
838 $ f --size --hexdump tagsclient/.hg/cache/hgtagsfnodes1
838 $ f --size --hexdump tagsclient/.hg/cache/hgtagsfnodes1
839 tagsclient/.hg/cache/hgtagsfnodes1: size=96
839 tagsclient/.hg/cache/hgtagsfnodes1: size=96
840 0000: 96 ee 1d 73 00 00 00 00 00 00 00 00 00 00 00 00 |...s............|
840 0000: 96 ee 1d 73 00 00 00 00 00 00 00 00 00 00 00 00 |...s............|
841 0010: 00 00 00 00 00 00 00 00 c4 da b0 c2 94 65 e1 c6 |.............e..|
841 0010: 00 00 00 00 00 00 00 00 c4 da b0 c2 94 65 e1 c6 |.............e..|
842 0020: 0d f7 f0 dd 32 04 ea 57 78 c8 97 97 79 fc d5 95 |....2..Wx...y...|
842 0020: 0d f7 f0 dd 32 04 ea 57 78 c8 97 97 79 fc d5 95 |....2..Wx...y...|
843 0030: f6 3c c8 fe 94 65 e1 c6 0d f7 f0 dd 32 04 ea 57 |.<...e......2..W|
843 0030: f6 3c c8 fe 94 65 e1 c6 0d f7 f0 dd 32 04 ea 57 |.<...e......2..W|
844 0040: 78 c8 97 97 79 fc d5 95 40 f0 35 8c 19 e0 a7 d3 |x...y...@.5.....|
844 0040: 78 c8 97 97 79 fc d5 95 40 f0 35 8c 19 e0 a7 d3 |x...y...@.5.....|
845 0050: 8a 5c 6a 82 4d cf fb a5 87 d0 2f a3 1e 4f 2f 8a |.\j.M...../..O/.|
845 0050: 8a 5c 6a 82 4d cf fb a5 87 d0 2f a3 1e 4f 2f 8a |.\j.M...../..O/.|
846
846
847 Check that the bundle includes cache data
847 Check that the bundle includes cache data
848
848
849 $ hg -R tagsclient bundle --all ./test-cache-in-bundle-all-rev.hg
849 $ hg -R tagsclient bundle --all ./test-cache-in-bundle-all-rev.hg
850 4 changesets found
850 4 changesets found
851 $ hg debugbundle ./test-cache-in-bundle-all-rev.hg
851 $ hg debugbundle ./test-cache-in-bundle-all-rev.hg
852 Stream params: {Compression: BZ}
852 Stream params: {Compression: BZ}
853 changegroup -- {nbchanges: 4, version: 02} (mandatory: True)
853 changegroup -- {nbchanges: 4, version: 02} (mandatory: True)
854 96ee1d7354c4ad7372047672c36a1f561e3a6a4c
854 96ee1d7354c4ad7372047672c36a1f561e3a6a4c
855 c4dab0c2fd337eb9191f80c3024830a4889a8f34
855 c4dab0c2fd337eb9191f80c3024830a4889a8f34
856 f63cc8fe54e4d326f8d692805d70e092f851ddb1
856 f63cc8fe54e4d326f8d692805d70e092f851ddb1
857 40f0358cb314c824a5929ee527308d90e023bc10
857 40f0358cb314c824a5929ee527308d90e023bc10
858 hgtagsfnodes -- {} (mandatory: True)
858 hgtagsfnodes -- {} (mandatory: True)
859 cache:rev-branch-cache -- {} (mandatory: False)
859 cache:rev-branch-cache -- {} (mandatory: False)
860
860
861 Check that local clone includes cache data
861 Check that local clone includes cache data
862
862
863 $ hg clone tagsclient tags-local-clone
863 $ hg clone tagsclient tags-local-clone
864 updating to branch default
864 updating to branch default
865 2 files updated, 0 files merged, 0 files removed, 0 files unresolved
865 2 files updated, 0 files merged, 0 files removed, 0 files unresolved
866 $ (cd tags-local-clone/.hg/cache/; ls -1 tag*)
866 $ (cd tags-local-clone/.hg/cache/; ls -1 tag*)
867 tags2
867 tags2
868 tags2-served
868 tags2-served
869 tags2-visible
869 tags2-visible
870
870
871 Avoid writing logs on trying to delete an already deleted tag
871 Avoid writing logs on trying to delete an already deleted tag
872 $ hg init issue5752
872 $ hg init issue5752
873 $ cd issue5752
873 $ cd issue5752
874 $ echo > a
874 $ echo > a
875 $ hg commit -Am 'add a'
875 $ hg commit -Am 'add a'
876 adding a
876 adding a
877 $ hg tag a
877 $ hg tag a
878 $ hg tags
878 $ hg tags
879 tip 1:bd7ee4f3939b
879 tip 1:bd7ee4f3939b
880 a 0:a8a82d372bb3
880 a 0:a8a82d372bb3
881 $ hg log
881 $ hg log
882 changeset: 1:bd7ee4f3939b
882 changeset: 1:bd7ee4f3939b
883 tag: tip
883 tag: tip
884 user: test
884 user: test
885 date: Thu Jan 01 00:00:00 1970 +0000
885 date: Thu Jan 01 00:00:00 1970 +0000
886 summary: Added tag a for changeset a8a82d372bb3
886 summary: Added tag a for changeset a8a82d372bb3
887
887
888 changeset: 0:a8a82d372bb3
888 changeset: 0:a8a82d372bb3
889 tag: a
889 tag: a
890 user: test
890 user: test
891 date: Thu Jan 01 00:00:00 1970 +0000
891 date: Thu Jan 01 00:00:00 1970 +0000
892 summary: add a
892 summary: add a
893
893
894 $ hg tag --remove a
894 $ hg tag --remove a
895 $ hg log
895 $ hg log
896 changeset: 2:e7feacc7ec9e
896 changeset: 2:e7feacc7ec9e
897 tag: tip
897 tag: tip
898 user: test
898 user: test
899 date: Thu Jan 01 00:00:00 1970 +0000
899 date: Thu Jan 01 00:00:00 1970 +0000
900 summary: Removed tag a
900 summary: Removed tag a
901
901
902 changeset: 1:bd7ee4f3939b
902 changeset: 1:bd7ee4f3939b
903 user: test
903 user: test
904 date: Thu Jan 01 00:00:00 1970 +0000
904 date: Thu Jan 01 00:00:00 1970 +0000
905 summary: Added tag a for changeset a8a82d372bb3
905 summary: Added tag a for changeset a8a82d372bb3
906
906
907 changeset: 0:a8a82d372bb3
907 changeset: 0:a8a82d372bb3
908 user: test
908 user: test
909 date: Thu Jan 01 00:00:00 1970 +0000
909 date: Thu Jan 01 00:00:00 1970 +0000
910 summary: add a
910 summary: add a
911
911
912 $ hg tag --remove a
912 $ hg tag --remove a
913 abort: tag 'a' is already removed
913 abort: tag 'a' is already removed
914 [10]
914 [10]
915 $ hg log
915 $ hg log
916 changeset: 2:e7feacc7ec9e
916 changeset: 2:e7feacc7ec9e
917 tag: tip
917 tag: tip
918 user: test
918 user: test
919 date: Thu Jan 01 00:00:00 1970 +0000
919 date: Thu Jan 01 00:00:00 1970 +0000
920 summary: Removed tag a
920 summary: Removed tag a
921
921
922 changeset: 1:bd7ee4f3939b
922 changeset: 1:bd7ee4f3939b
923 user: test
923 user: test
924 date: Thu Jan 01 00:00:00 1970 +0000
924 date: Thu Jan 01 00:00:00 1970 +0000
925 summary: Added tag a for changeset a8a82d372bb3
925 summary: Added tag a for changeset a8a82d372bb3
926
926
927 changeset: 0:a8a82d372bb3
927 changeset: 0:a8a82d372bb3
928 user: test
928 user: test
929 date: Thu Jan 01 00:00:00 1970 +0000
929 date: Thu Jan 01 00:00:00 1970 +0000
930 summary: add a
930 summary: add a
931
931
932 $ cat .hgtags
932 $ cat .hgtags
933 a8a82d372bb35b42ff736e74f07c23bcd99c371f a
933 a8a82d372bb35b42ff736e74f07c23bcd99c371f a
934 a8a82d372bb35b42ff736e74f07c23bcd99c371f a
934 a8a82d372bb35b42ff736e74f07c23bcd99c371f a
935 0000000000000000000000000000000000000000 a
935 0000000000000000000000000000000000000000 a
General Comments 0
You need to be logged in to leave comments. Login now