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