##// END OF EJS Templates
add a -r/--rev option to heads to show only heads descendant from rev
Benoit Boissinot -
r1550:ccb9b62d default
parent child Browse files
Show More
@@ -1286,11 +1286,14 b' def heads(ui, repo, **opts):'
1286 1286 changesets. They are where development generally takes place and
1287 1287 are the usual targets for update and merge operations.
1288 1288 """
1289 heads = repo.changelog.heads()
1289 if opts['rev']:
1290 heads = repo.heads(repo.lookup(rev))
1291 else:
1292 heads = repo.heads()
1290 1293 br = None
1291 1294 if opts['branches']:
1292 br = repo.branchlookup(heads)
1293 for n in repo.changelog.heads():
1295 br = repo.branchlookup(list(heads))
1296 for n in heads:
1294 1297 show_changeset(ui, repo, changenode=n, brinfo=br)
1295 1298
1296 1299 def identify(ui, repo):
@@ -2237,8 +2240,9 b' table = {'
2237 2240 "hg grep [OPTION]... PATTERN [FILE]..."),
2238 2241 "heads":
2239 2242 (heads,
2240 [('b', 'branches', None, _('find branch info'))],
2241 _('hg heads [-b]')),
2243 [('b', 'branches', None, _('find branch info')),
2244 ('r', 'rev', None, _('show only heads descendants from rev'))],
2245 _('hg heads [-b] [-r <rev>]')),
2242 2246 "help": (help_, [], _('hg help [COMMAND]')),
2243 2247 "identify|id": (identify, [], _('hg identify')),
2244 2248 "import|patch":
@@ -613,8 +613,12 b' class localrepository:'
613 613 self.dirstate.update([dest], "a")
614 614 self.dirstate.copy(source, dest)
615 615
616 def heads(self):
617 return self.changelog.heads()
616 def heads(self, start=nullid):
617 heads = self.changelog.heads(start)
618 # sort the output in rev descending order
619 heads = [(-self.changelog.rev(h), h) for h in heads]
620 heads.sort()
621 return [n for (r, n) in heads]
618 622
619 623 # branchlookup returns a dict giving a list of branches for
620 624 # each head. A branch is defined as the tag of a node or
@@ -409,25 +409,23 b' class revlog:'
409 409 assert heads
410 410 return (orderedout, roots, heads)
411 411
412 def heads(self, stop=None):
413 """return the list of all nodes that have no children"""
414 p = {}
415 h = []
416 stoprev = 0
417 if stop and stop in self.nodemap:
418 stoprev = self.rev(stop)
412 def heads(self, start=nullid):
413 """return the list of all nodes that have no children
414 if start is specified, only heads that are children of
415 start will be returned"""
416 reachable = {start: 1}
417 heads = {start: 1}
418 startrev = self.rev(start)
419 419
420 for r in range(self.count() - 1, -1, -1):
420 for r in xrange(startrev + 1, self.count()):
421 421 n = self.node(r)
422 if n not in p:
423 h.append(n)
424 if n == stop:
425 break
426 if r < stoprev:
427 break
428 422 for pn in self.parents(n):
429 p[pn] = 1
430 return h
423 if pn in reachable:
424 reachable[n] = 1
425 heads[n] = 1
426 if pn in heads:
427 del heads[pn]
428 return heads.keys()
431 429
432 430 def children(self, node):
433 431 """find the children of a given node"""
General Comments 0
You need to be logged in to leave comments. Login now