Mercurial > public > mercurial-scm > hg-stable
comparison mercurial/localrepo.py @ 4210:caff92047e87
Refactor tags code to prepare for improving the algorithm
author | Matt Mackall <mpm@selenic.com> |
---|---|
date | Wed, 14 Mar 2007 16:40:47 -0500 |
parents | 0b48e3985765 |
children | e29f2db5ab18 |
comparison
equal
deleted
inserted
replaced
4180:f80cf8b7bbd9 | 4210:caff92047e87 |
---|---|
255 self.commit(['.hgtags'], message, user, date) | 255 self.commit(['.hgtags'], message, user, date) |
256 self.hook('tag', node=hex(node), tag=name, local=local) | 256 self.hook('tag', node=hex(node), tag=name, local=local) |
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 | 262 |
263 def parsetag(line, context): | 263 self.tagscache = {} |
264 if not line: | 264 |
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 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(): | 300 |
293 count += 1 | 301 try: |
294 parsetag(l, _("%s, line %d") % (str(f), count)) | 302 data = util.fromlocal(self.opener("localtags").read()) |
295 | 303 # localtags are stored in the local character set |
296 try: | 304 # while the internal tag table is stored in UTF-8 |
297 f = self.opener("localtags") | 305 readtags(data.splitlines(), "localtags") |
298 count = 0 | 306 except IOError: |
299 for l in f: | 307 pass |
300 # localtags are stored in the local character set | 308 |
301 # while the internal tag table is stored in UTF-8 | 309 self.tagscache['tip'] = self.changelog.tip() |
302 l = util.fromlocal(l) | |
303 count += 1 | |
304 parsetag(l, _("localtags, line %d") % count) | |
305 except IOError: | |
306 pass | |
307 | |
308 self.tagscache['tip'] = self.changelog.tip() | |
309 | 310 |
310 return self.tagscache | 311 return self.tagscache |
311 | 312 |
312 def _hgtagsnodes(self): | 313 def _hgtagsnodes(self): |
313 heads = self.heads() | 314 heads = self.heads() |