Mercurial > public > mercurial-scm > hg-stable
diff mercurial/commands.py @ 4676:0f6e2b37512d
Merge with Eric Hopper
author | Matt Mackall <mpm@selenic.com> |
---|---|
date | Thu, 21 Jun 2007 18:05:14 -0500 |
parents | d8442fc0da8d 6858a7477a5e |
children | 51ec5e069505 |
line wrap: on
line diff
--- a/mercurial/commands.py Thu Jun 21 18:02:03 2007 -0500 +++ b/mercurial/commands.py Thu Jun 21 18:05:14 2007 -0500 @@ -237,21 +237,34 @@ else: ui.write("%s\n" % util.tolocal(repo.dirstate.branch())) -def branches(ui, repo): +def branches(ui, repo, active=False): """list repository named branches - List the repository's named branches. + List the repository's named branches, indicating which ones are + inactive. If active is specified, only show active branches. + + A branch is considered active if it contains unmerged heads. """ b = repo.branchtags() - l = [(-repo.changelog.rev(n), n, t) for t, n in b.items()] + heads = dict.fromkeys(repo.heads(), 1) + l = [((n in heads), repo.changelog.rev(n), n, t) for t, n in b.items()] l.sort() - for r, n, t in l: - hexfunc = ui.debugflag and hex or short - if ui.quiet: - ui.write("%s\n" % t) + l.reverse() + for ishead, r, n, t in l: + if active and not ishead: + # If we're only displaying active branches, abort the loop on + # encountering the first inactive head + break else: - spaces = " " * (30 - util.locallen(t)) - ui.write("%s%s %s:%s\n" % (t, spaces, -r, hexfunc(n))) + hexfunc = ui.debugflag and hex or short + if ui.quiet: + ui.write("%s\n" % t) + else: + spaces = " " * (30 - util.locallen(t)) + # The code only gets here if inactive branches are being + # displayed or the branch is active. + isinactive = ((not ishead) and " (inactive)") or '' + ui.write("%s%s %s:%s%s\n" % (t, spaces, r, hexfunc(n), isinactive)) def bundle(ui, repo, fname, dest=None, **opts): """create a changegroup file @@ -2746,7 +2759,10 @@ [('f', 'force', None, _('set branch name even if it shadows an existing branch'))], _('hg branch [NAME]')), - "branches": (branches, [], _('hg branches')), + "branches": (branches, + [('a', 'active', False, + _("show only branches that have unmerged heads"))], + _('hg branches [-a]')), "bundle": (bundle, [('f', 'force', None,