# HG changeset patch # User Stefano Tortarolo # Date 2008-05-29 20:21:29 # Node ID a2b13cac0922a7a952d1e786a6eaa1234bfd3e80 # Parent 8542fac26f63d425bb648dd848085036af19517b Active branches fix (issue1104) diff --git a/mercurial/commands.py b/mercurial/commands.py --- a/mercurial/commands.py +++ b/mercurial/commands.py @@ -371,30 +371,26 @@ def branches(ui, repo, active=False): 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. + A branch is considered active if it contains repository heads. Use the command 'hg update' to switch to an existing branch. """ - b = repo.branchtags() - heads = dict.fromkeys(repo.heads(), 1) - l = [((n in heads), repo.changelog.rev(n), n, t) for t, n in b.items()] - l.sort() - 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: - hexfunc = ui.debugflag and hex or short + hexfunc = ui.debugflag and hex or short + activebranches = [util.tolocal(repo.changectx(n).branch()) + for n in repo.heads()] + branches = [(tag in activebranches, repo.changelog.rev(node), tag) + for tag, node in repo.branchtags().items()] + branches.sort(reverse=True) + + for isactive, node, tag in branches: + if (not active) or isactive: if ui.quiet: - ui.write("%s\n" % t) + ui.write("%s\n" % tag) 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)) + rev = str(node).rjust(32 - util.locallen(tag)) + isinactive = ((not isactive) and " (inactive)") or '' + data = tag, rev, hexfunc(repo.lookup(node)), isinactive + ui.write("%s%s:%s%s\n" % data) def bundle(ui, repo, fname, dest=None, **opts): """create a changegroup file diff --git a/tests/test-branches b/tests/test-branches --- a/tests/test-branches +++ b/tests/test-branches @@ -31,6 +31,11 @@ hg add c hg branch c hg commit -d '5 0' -u test -m "Adding c branch" +echo 'd' >d +hg add d +hg branch d +hg commit -d '6 0' -u test -m "Adding d branch" + hg branches echo '-------' hg branches -a diff --git a/tests/test-branches.out b/tests/test-branches.out --- a/tests/test-branches.out +++ b/tests/test-branches.out @@ -5,12 +5,15 @@ created new head 0 files updated, 0 files merged, 1 files removed, 0 files unresolved created new head marked working directory as branch c -c 5:5ca481e59b8c +marked working directory as branch d +d 6:9c581c5ff105 +b 4:22df7444f7c1 a 1:dd6b440dd85a -b 4:22df7444f7c1 (inactive) +c 5:5ca481e59b8c (inactive) default 0:19709c5a4e75 (inactive) ------- -c 5:5ca481e59b8c +d 6:9c581c5ff105 +b 4:22df7444f7c1 a 1:dd6b440dd85a --- Branch a changeset: 1:dd6b440dd85a diff --git a/tests/test-convert-svn-branches.out b/tests/test-convert-svn-branches.out --- a/tests/test-convert-svn-branches.out +++ b/tests/test-convert-svn-branches.out @@ -123,8 +123,8 @@ o branch=old3 11 branch trunk@1 into ol |/ o branch= 0 init projA files: -old3 11: -default 10: +old3 11: +default 10: old 9: old2 8: tip