##// 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,28 +257,36 b' class localrepository(repo.repository):'
257 257
258 258 def tags(self):
259 259 '''return a mapping of tag to node'''
260 if not self.tagscache:
260 if self.tagscache:
261 return self.tagscache
262
261 263 self.tagscache = {}
262 264
263 def parsetag(line, context):
264 if not line:
265 return
265 def readtags(lines, fn):
266 filetags = {}
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 276 s = l.split(" ", 1)
267 277 if len(s) != 2:
268 self.ui.warn(_("%s: cannot parse entry\n") % context)
269 return
278 warn(_("cannot parse entry"))
279 continue
270 280 node, key = s
271 281 key = util.tolocal(key.strip()) # stored in UTF-8
272 282 try:
273 283 bin_n = bin(node)
274 284 except TypeError:
275 self.ui.warn(_("%s: node '%s' is not well formed\n") %
276 (context, node))
277 return
285 warn(_("node '%s' is not well formed") % node)
286 continue
278 287 if bin_n not in self.changelog.nodemap:
279 self.ui.warn(_("%s: tag '%s' refers to unknown node\n") %
280 (context, key))
281 return
288 warn(_("tag '%s' refers to unknown node") % key)
289 continue
282 290 self.tagscache[key] = bin_n
283 291
284 292 # read the tags file from each head, ending with the tip,
@@ -288,20 +296,13 b' class localrepository(repo.repository):'
288 296 for rev, node, fnode in self._hgtagsnodes():
289 297 f = (f and f.filectx(fnode) or
290 298 self.filectx('.hgtags', fileid=fnode))
291 count = 0
292 for l in f.data().splitlines():
293 count += 1
294 parsetag(l, _("%s, line %d") % (str(f), count))
299 readtags(f.data().splitlines(), f)
295 300
296 301 try:
297 f = self.opener("localtags")
298 count = 0
299 for l in f:
302 data = util.fromlocal(self.opener("localtags").read())
300 303 # localtags are stored in the local character set
301 304 # while the internal tag table is stored in UTF-8
302 l = util.fromlocal(l)
303 count += 1
304 parsetag(l, _("localtags, line %d") % count)
305 readtags(data.splitlines(), "localtags")
305 306 except IOError:
306 307 pass
307 308
General Comments 0
You need to be logged in to leave comments. Login now