comparison mercurial/localrepo.py @ 9475:c295a82a020b

localrepo: fix bugs in branchheads and add docstring - The call to reverse() reversed the list in place in the global branchmap. - The nodesbetween function doesn't preserve ordering.
author Sune Foldager <cryo@cyanite.org>
date Wed, 23 Sep 2009 15:51:36 +0200
parents 1444a42f6052
children a0e69510018b f3569d95c2ab
comparison
equal deleted inserted replaced
9474:6ea653272c09 9475:c295a82a020b
1181 # sort the output in rev descending order 1181 # sort the output in rev descending order
1182 heads = [(-self.changelog.rev(h), h) for h in heads] 1182 heads = [(-self.changelog.rev(h), h) for h in heads]
1183 return [n for (r, n) in sorted(heads)] 1183 return [n for (r, n) in sorted(heads)]
1184 1184
1185 def branchheads(self, branch=None, start=None, closed=False): 1185 def branchheads(self, branch=None, start=None, closed=False):
1186 '''return a (possibly filtered) list of heads for the given branch
1187
1188 Heads are returned in topological order, from newest to oldest.
1189 If branch is None, use the dirstate branch.
1190 If start is not None, return only heads reachable from start.
1191 If closed is True, return heads that are marked as closed as well.
1192 '''
1186 if branch is None: 1193 if branch is None:
1187 branch = self[None].branch() 1194 branch = self[None].branch()
1188 branches = self.branchmap() 1195 branches = self.branchmap()
1189 if branch not in branches: 1196 if branch not in branches:
1190 return [] 1197 return []
1191 bheads = branches[branch]
1192 # the cache returns heads ordered lowest to highest 1198 # the cache returns heads ordered lowest to highest
1193 bheads.reverse() 1199 bheads = list(reversed(branches[branch]))
1194 if start is not None: 1200 if start is not None:
1195 # filter out the heads that cannot be reached from startrev 1201 # filter out the heads that cannot be reached from startrev
1196 bheads = self.changelog.nodesbetween([start], bheads)[2] 1202 fbheads = set(self.changelog.nodesbetween([start], bheads)[2])
1203 bheads = [h for h in bheads if h in fbheads]
1197 if not closed: 1204 if not closed:
1198 bheads = [h for h in bheads if 1205 bheads = [h for h in bheads if
1199 ('close' not in self.changelog.read(h)[5])] 1206 ('close' not in self.changelog.read(h)[5])]
1200 return bheads 1207 return bheads
1201 1208