Mercurial > public > mercurial-scm > hg
comparison mercurial/localrepo.py @ 9148:b7837f0ed9fe
localrepo: factor updatetags() out of readtags() (issue548).
author | Greg Ward <greg-hg@gerg.ca> |
---|---|
date | Thu, 16 Jul 2009 10:39:41 -0400 |
parents | 234a230cc33b |
children | abb7d4d43a5f |
comparison
equal
deleted
inserted
replaced
9147:234a230cc33b | 9148:b7837f0ed9fe |
---|---|
256 # mq and bookmarks add tags, but do not set the tagtype at all. | 256 # mq and bookmarks add tags, but do not set the tagtype at all. |
257 # Should each extension invent its own tag type? Should there | 257 # Should each extension invent its own tag type? Should there |
258 # be one tagtype for all such "virtual" tags? Or is the status | 258 # be one tagtype for all such "virtual" tags? Or is the status |
259 # quo fine? | 259 # quo fine? |
260 | 260 |
261 alltags = {} # map tag name to (node, hist) | 261 def readtags(lines, fn): |
262 tagtypes = {} | 262 '''Read tag definitions from a file (or any source of |
263 | 263 lines). Return a mapping from tag name to (node, hist): |
264 def readtags(lines, fn, tagtype): | 264 node is the node id from the last line read for that name, |
265 and hist is the list of node ids previously associated with | |
266 it (in file order). All node ids are binary, not hex.''' | |
267 | |
265 filetags = {} # map tag name to (node, hist) | 268 filetags = {} # map tag name to (node, hist) |
266 count = 0 | 269 count = 0 |
267 | 270 |
268 def warn(msg): | 271 def warn(msg): |
269 self.ui.warn(_("%s, line %s: %s\n") % (fn, count, msg)) | 272 self.ui.warn(_("%s, line %s: %s\n") % (fn, count, msg)) |
285 continue | 288 continue |
286 if nodebin not in self.changelog.nodemap: | 289 if nodebin not in self.changelog.nodemap: |
287 # silently ignore as pull -r might cause this | 290 # silently ignore as pull -r might cause this |
288 continue | 291 continue |
289 | 292 |
290 # update filetags: map tag name to (node, hist) where | 293 # update filetags |
291 # node is the node from the latest line read with | |
292 # 'name', and hist is the list of nodes previously | |
293 # associated with 'name' | |
294 hist = [] | 294 hist = [] |
295 if name in filetags: | 295 if name in filetags: |
296 n, hist = filetags[name] | 296 n, hist = filetags[name] |
297 hist.append(n) | 297 hist.append(n) |
298 filetags[name] = (nodebin, hist) | 298 filetags[name] = (nodebin, hist) |
299 return filetags | |
300 | |
301 alltags = {} # map tag name to (node, hist) | |
302 tagtypes = {} | |
303 | |
304 def updatetags(filetags, tagtype): | |
305 '''Incorporate the tag info read from one file into the two | |
306 dictionaries, alltags and tagtypes, that contain all tag | |
307 info (global across all heads plus local).''' | |
299 | 308 |
300 for name, nodehist in filetags.iteritems(): | 309 for name, nodehist in filetags.iteritems(): |
301 if name not in alltags: | 310 if name not in alltags: |
302 alltags[name] = nodehist | 311 alltags[name] = nodehist |
303 tagtypes[name] = tagtype | 312 tagtypes[name] = tagtype |
332 fctx = fctx.filectx(fnode) | 341 fctx = fctx.filectx(fnode) |
333 ctxs.append(fctx) | 342 ctxs.append(fctx) |
334 | 343 |
335 # read the tags file from each head, ending with the tip | 344 # read the tags file from each head, ending with the tip |
336 for fctx in reversed(ctxs): | 345 for fctx in reversed(ctxs): |
337 readtags(fctx.data().splitlines(), fctx, "global") | 346 filetags = readtags(fctx.data().splitlines(), fctx) |
347 updatetags(filetags, "global") | |
338 | 348 |
339 try: | 349 try: |
340 data = encoding.fromlocal(self.opener("localtags").read()) | 350 data = encoding.fromlocal(self.opener("localtags").read()) |
341 # localtags are stored in the local character set | 351 # localtags are stored in the local character set |
342 # while the internal tag table is stored in UTF-8 | 352 # while the internal tag table is stored in UTF-8 |
343 readtags(data.splitlines(), "localtags", "local") | 353 filetags = readtags(data.splitlines(), "localtags") |
354 updatetags(filetags, "local") | |
344 except IOError: | 355 except IOError: |
345 pass | 356 pass |
346 | 357 |
347 tags = {} | 358 tags = {} |
348 for (name, (node, hist)) in alltags.iteritems(): | 359 for (name, (node, hist)) in alltags.iteritems(): |