comparison mercurial/tags.py @ 11352:b19067ee4507

tags: remove inactive debugging code. It was left in just in case things went wrong with the tag cache in Mercurial 1.4, so we could easily crank up the verbosity with a one-line change. There have been no problems in 1.4 or 1.5, so it should be safe to drop this now.
author Greg Ward <greg-hg@gerg.ca>
date Tue, 15 Jun 2010 16:10:32 -0400
parents 1cdc8b5e5729
children 2d754eae430c
comparison
equal deleted inserted replaced
11351:1cdc8b5e5729 11352:b19067ee4507
12 12
13 from node import nullid, bin, hex, short 13 from node import nullid, bin, hex, short
14 from i18n import _ 14 from i18n import _
15 import encoding 15 import encoding
16 import error 16 import error
17
18 def _debugalways(ui, *msg):
19 ui.write(*msg)
20
21 def _debugconditional(ui, *msg):
22 ui.debug(*msg)
23
24 def _debugnever(ui, *msg):
25 pass
26
27 _debug = _debugalways
28 _debug = _debugnever
29 17
30 def findglobaltags(ui, repo, alltags, tagtypes): 18 def findglobaltags(ui, repo, alltags, tagtypes):
31 '''Find global tags in repo by reading .hgtags from every head that 19 '''Find global tags in repo by reading .hgtags from every head that
32 has a distinct version of it, using a cache to avoid excess work. 20 has a distinct version of it, using a cache to avoid excess work.
33 Updates the dicts alltags, tagtypes in place: alltags maps tag name 21 Updates the dicts alltags, tagtypes in place: alltags maps tag name
45 # cases where a global tag should outrank a local tag but won't, 33 # cases where a global tag should outrank a local tag but won't,
46 # because cachetags does not contain rank info? 34 # because cachetags does not contain rank info?
47 _updatetags(cachetags, 'global', alltags, tagtypes) 35 _updatetags(cachetags, 'global', alltags, tagtypes)
48 return 36 return
49 37
50 _debug(ui, "reading tags from %d head(s): %s\n"
51 % (len(heads), map(short, reversed(heads))))
52 seen = set() # set of fnode 38 seen = set() # set of fnode
53 fctx = None 39 fctx = None
54 for head in reversed(heads): # oldest to newest 40 for head in reversed(heads): # oldest to newest
55 assert head in repo.changelog.nodemap, \ 41 assert head in repo.changelog.nodemap, \
56 "tag cache returned bogus head %s" % short(head) 42 "tag cache returned bogus head %s" % short(head)
169 155
170 try: 156 try:
171 cachefile = repo.opener('tags.cache', 'r') 157 cachefile = repo.opener('tags.cache', 'r')
172 # force reading the file for static-http 158 # force reading the file for static-http
173 cachelines = iter(cachefile) 159 cachelines = iter(cachefile)
174 _debug(ui, 'reading tag cache from %s\n' % cachefile.name)
175 except IOError: 160 except IOError:
176 cachefile = None 161 cachefile = None
177 162
178 # The cache file consists of lines like 163 # The cache file consists of lines like
179 # <headrev> <headnode> [<tagnode>] 164 # <headrev> <headnode> [<tagnode>]
208 # Case 1 (common): tip is the same, so nothing has changed. 193 # Case 1 (common): tip is the same, so nothing has changed.
209 # (Unchanged tip trivially means no changesets have been added. 194 # (Unchanged tip trivially means no changesets have been added.
210 # But, thanks to localrepository.destroyed(), it also means none 195 # But, thanks to localrepository.destroyed(), it also means none
211 # have been destroyed by strip or rollback.) 196 # have been destroyed by strip or rollback.)
212 if cacheheads and cacheheads[0] == tipnode and cacherevs[0] == tiprev: 197 if cacheheads and cacheheads[0] == tipnode and cacherevs[0] == tiprev:
213 _debug(ui, "tag cache: tip unchanged\n")
214 tags = _readtags(ui, repo, cachelines, cachefile.name) 198 tags = _readtags(ui, repo, cachelines, cachefile.name)
215 cachefile.close() 199 cachefile.close()
216 return (None, None, tags, False) 200 return (None, None, tags, False)
217 if cachefile: 201 if cachefile:
218 cachefile.close() # ignore rest of file 202 cachefile.close() # ignore rest of file
222 # writing an empty cache. 206 # writing an empty cache.
223 if repoheads == [nullid]: 207 if repoheads == [nullid]:
224 return ([], {}, {}, False) 208 return ([], {}, {}, False)
225 209
226 # Case 3 (uncommon): cache file missing or empty. 210 # Case 3 (uncommon): cache file missing or empty.
227 if not cacheheads:
228 _debug(ui, 'tag cache: cache file missing or empty\n')
229 211
230 # Case 4 (uncommon): tip rev decreased. This should only happen 212 # Case 4 (uncommon): tip rev decreased. This should only happen
231 # when we're called from localrepository.destroyed(). Refresh the 213 # when we're called from localrepository.destroyed(). Refresh the
232 # cache so future invocations will not see disappeared heads in the 214 # cache so future invocations will not see disappeared heads in the
233 # cache. 215 # cache.
234 elif cacheheads and tiprev < cacherevs[0]:
235 _debug(ui,
236 'tag cache: tip rev decremented (from %d to %d), '
237 'so we must be destroying nodes\n'
238 % (cacherevs[0], tiprev))
239 216
240 # Case 5 (common): tip has changed, so we've added/replaced heads. 217 # Case 5 (common): tip has changed, so we've added/replaced heads.
241 else: 218
242 _debug(ui, 219 # As it happens, the code to handle cases 3, 4, 5 is the same.
243 'tag cache: tip has changed (%d:%s); must find new heads\n'
244 % (tiprev, short(tipnode)))
245
246 # Luckily, the code to handle cases 3, 4, 5 is the same. So the
247 # above if/elif/else can disappear once we're confident this thing
248 # actually works and we don't need the debug output.
249 220
250 # N.B. in case 4 (nodes destroyed), "new head" really means "newly 221 # N.B. in case 4 (nodes destroyed), "new head" really means "newly
251 # exposed". 222 # exposed".
252 newheads = [head 223 newheads = [head
253 for head in repoheads 224 for head in repoheads
254 if head not in set(cacheheads)] 225 if head not in set(cacheheads)]
255 _debug(ui, 'tag cache: found %d head(s) not in cache: %s\n'
256 % (len(newheads), map(short, newheads)))
257 226
258 # Now we have to lookup the .hgtags filenode for every new head. 227 # Now we have to lookup the .hgtags filenode for every new head.
259 # This is the most expensive part of finding tags, so performance 228 # This is the most expensive part of finding tags, so performance
260 # depends primarily on the size of newheads. Worst case: no cache 229 # depends primarily on the size of newheads. Worst case: no cache
261 # file, so newheads == repoheads. 230 # file, so newheads == repoheads.
276 245
277 try: 246 try:
278 cachefile = repo.opener('tags.cache', 'w', atomictemp=True) 247 cachefile = repo.opener('tags.cache', 'w', atomictemp=True)
279 except (OSError, IOError): 248 except (OSError, IOError):
280 return 249 return
281 _debug(ui, 'writing cache file %s\n' % cachefile.name)
282 250
283 realheads = repo.heads() # for sanity checks below 251 realheads = repo.heads() # for sanity checks below
284 for head in heads: 252 for head in heads:
285 # temporary sanity checks; these can probably be removed 253 # temporary sanity checks; these can probably be removed
286 # once this code has been in crew for a few weeks 254 # once this code has been in crew for a few weeks