##// END OF EJS Templates
Refactor tags code to prepare for improving the algorithm
Matt Mackall -
r4210:caff9204 default
parent child Browse files
Show More
@@ -257,55 +257,56 b' class localrepository(repo.repository):'
257
257
258 def tags(self):
258 def tags(self):
259 '''return a mapping of tag to node'''
259 '''return a mapping of tag to node'''
260 if not self.tagscache:
260 if self.tagscache:
261 self.tagscache = {}
261 return self.tagscache
262
263 self.tagscache = {}
262
264
263 def parsetag(line, context):
265 def readtags(lines, fn):
264 if not line:
266 filetags = {}
265 return
267 count = 0
268
269 def warn(msg):
270 self.ui.warn(_("%s, line %s: %s\n") % (fn, count, msg))
271
272 for l in lines:
273 count += 1
274 if not l:
275 continue
266 s = l.split(" ", 1)
276 s = l.split(" ", 1)
267 if len(s) != 2:
277 if len(s) != 2:
268 self.ui.warn(_("%s: cannot parse entry\n") % context)
278 warn(_("cannot parse entry"))
269 return
279 continue
270 node, key = s
280 node, key = s
271 key = util.tolocal(key.strip()) # stored in UTF-8
281 key = util.tolocal(key.strip()) # stored in UTF-8
272 try:
282 try:
273 bin_n = bin(node)
283 bin_n = bin(node)
274 except TypeError:
284 except TypeError:
275 self.ui.warn(_("%s: node '%s' is not well formed\n") %
285 warn(_("node '%s' is not well formed") % node)
276 (context, node))
286 continue
277 return
278 if bin_n not in self.changelog.nodemap:
287 if bin_n not in self.changelog.nodemap:
279 self.ui.warn(_("%s: tag '%s' refers to unknown node\n") %
288 warn(_("tag '%s' refers to unknown node") % key)
280 (context, key))
289 continue
281 return
282 self.tagscache[key] = bin_n
290 self.tagscache[key] = bin_n
283
291
284 # read the tags file from each head, ending with the tip,
292 # read the tags file from each head, ending with the tip,
285 # and add each tag found to the map, with "newer" ones
293 # and add each tag found to the map, with "newer" ones
286 # taking precedence
294 # taking precedence
287 f = None
295 f = None
288 for rev, node, fnode in self._hgtagsnodes():
296 for rev, node, fnode in self._hgtagsnodes():
289 f = (f and f.filectx(fnode) or
297 f = (f and f.filectx(fnode) or
290 self.filectx('.hgtags', fileid=fnode))
298 self.filectx('.hgtags', fileid=fnode))
291 count = 0
299 readtags(f.data().splitlines(), f)
292 for l in f.data().splitlines():
293 count += 1
294 parsetag(l, _("%s, line %d") % (str(f), count))
295
300
296 try:
301 try:
297 f = self.opener("localtags")
302 data = util.fromlocal(self.opener("localtags").read())
298 count = 0
303 # localtags are stored in the local character set
299 for l in f:
304 # while the internal tag table is stored in UTF-8
300 # localtags are stored in the local character set
305 readtags(data.splitlines(), "localtags")
301 # while the internal tag table is stored in UTF-8
306 except IOError:
302 l = util.fromlocal(l)
307 pass
303 count += 1
304 parsetag(l, _("localtags, line %d") % count)
305 except IOError:
306 pass
307
308
308 self.tagscache['tip'] = self.changelog.tip()
309 self.tagscache['tip'] = self.changelog.tip()
309
310
310 return self.tagscache
311 return self.tagscache
311
312
General Comments 0
You need to be logged in to leave comments. Login now