comparison mercurial/localrepo.py @ 8954:e67e5b60e55f

Branch heads should not include "heads" that are ancestors of other heads. For example, given 1 (branch a) -> 2 (branch b) -> 3 (branch a) I expect "hg heads a" to show only 3. Discovered by running hg heads HEAD on the mutt repo, where older clients committed default on top of HEAD.
author Brendan Cully <brendan@kublai.com>
date Mon, 29 Jun 2009 00:54:23 -0700
parents 3df8dbf706b0
children 4a1187d3cb00
comparison
equal deleted inserted replaced
8953:e1d119f450f0 8954:e67e5b60e55f
452 f.rename() 452 f.rename()
453 except (IOError, OSError): 453 except (IOError, OSError):
454 pass 454 pass
455 455
456 def _updatebranchcache(self, partial, start, end): 456 def _updatebranchcache(self, partial, start, end):
457 # collect new branch entries
458 newbranches = {}
457 for r in xrange(start, end): 459 for r in xrange(start, end):
458 c = self[r] 460 c = self[r]
459 b = c.branch() 461 newbranches.setdefault(c.branch(), []).append(c.node())
460 bheads = partial.setdefault(b, []) 462 # if older branchheads are reachable from new ones, they aren't
461 bheads.append(c.node()) 463 # really branchheads. Note checking parents is insufficient:
462 for p in c.parents(): 464 # 1 (branch a) -> 2 (branch b) -> 3 (branch a)
463 pn = p.node() 465 for branch, newnodes in newbranches.iteritems():
464 if pn in bheads: 466 bheads = partial.setdefault(branch, [])
465 bheads.remove(pn) 467 bheads.extend(newnodes)
468 if len(bheads) < 2:
469 continue
470 newbheads = []
471 # starting from tip means fewer passes over reachable
472 while newnodes:
473 latest = newnodes.pop()
474 if latest not in bheads:
475 continue
476 reachable = self.changelog.reachable(latest, bheads[0])
477 bheads = [b for b in bheads if b not in reachable]
478 newbheads.insert(0, latest)
479 bheads.extend(newbheads)
480 partial[branch] = bheads
466 481
467 def lookup(self, key): 482 def lookup(self, key):
468 if isinstance(key, int): 483 if isinstance(key, int):
469 return self.changelog.node(key) 484 return self.changelog.node(key)
470 elif key == '.': 485 elif key == '.':