Mercurial > hg > mercurial-crew-with-dirclash
comparison mercurial/commands.py @ 4675:6858a7477a5e
Change branches to sort 'active' branches first, and add an option to show only active branches.
author | Eric Hopper <hopper@omnifarious.org> |
---|---|
date | Thu, 21 Jun 2007 10:40:09 -0700 |
parents | c7a81e3ae80f |
children | 0f6e2b37512d |
comparison
equal
deleted
inserted
replaced
4667:c7a81e3ae80f | 4675:6858a7477a5e |
---|---|
235 repo.dirstate.setbranch(util.fromlocal(label)) | 235 repo.dirstate.setbranch(util.fromlocal(label)) |
236 ui.status(_('marked working directory as branch %s\n') % label) | 236 ui.status(_('marked working directory as branch %s\n') % label) |
237 else: | 237 else: |
238 ui.write("%s\n" % util.tolocal(repo.dirstate.branch())) | 238 ui.write("%s\n" % util.tolocal(repo.dirstate.branch())) |
239 | 239 |
240 def branches(ui, repo): | 240 def branches(ui, repo, active=False): |
241 """list repository named branches | 241 """list repository named branches |
242 | 242 |
243 List the repository's named branches. | 243 List the repository's named branches, indicating which ones are |
244 inactive. If active is specified, only show active branches. | |
245 | |
246 A branch is considered active if it contains unmerged heads. | |
244 """ | 247 """ |
245 b = repo.branchtags() | 248 b = repo.branchtags() |
246 l = [(-repo.changelog.rev(n), n, t) for t, n in b.items()] | 249 heads = dict.fromkeys(repo.heads(), 1) |
250 l = [((n in heads), repo.changelog.rev(n), n, t) for t, n in b.items()] | |
247 l.sort() | 251 l.sort() |
248 for r, n, t in l: | 252 l.reverse() |
249 hexfunc = ui.debugflag and hex or short | 253 for ishead, r, n, t in l: |
250 if ui.quiet: | 254 if active and not ishead: |
251 ui.write("%s\n" % t) | 255 # If we're only displaying active branches, abort the loop on |
256 # encountering the first inactive head | |
257 break | |
252 else: | 258 else: |
253 spaces = " " * (30 - util.locallen(t)) | 259 hexfunc = ui.debugflag and hex or short |
254 ui.write("%s%s %s:%s\n" % (t, spaces, -r, hexfunc(n))) | 260 if ui.quiet: |
261 ui.write("%s\n" % t) | |
262 else: | |
263 spaces = " " * (30 - util.locallen(t)) | |
264 # The code only gets here if inactive branches are being | |
265 # displayed or the branch is active. | |
266 isinactive = ((not ishead) and " (inactive)") or '' | |
267 ui.write("%s%s %s:%s%s\n" % (t, spaces, r, hexfunc(n), isinactive)) | |
255 | 268 |
256 def bundle(ui, repo, fname, dest=None, **opts): | 269 def bundle(ui, repo, fname, dest=None, **opts): |
257 """create a changegroup file | 270 """create a changegroup file |
258 | 271 |
259 Generate a compressed changegroup file collecting changesets not | 272 Generate a compressed changegroup file collecting changesets not |
2736 _('hg backout [OPTION]... [-r] REV')), | 2749 _('hg backout [OPTION]... [-r] REV')), |
2737 "branch": (branch, | 2750 "branch": (branch, |
2738 [('f', 'force', None, | 2751 [('f', 'force', None, |
2739 _('set branch name even if it shadows an existing branch'))], | 2752 _('set branch name even if it shadows an existing branch'))], |
2740 _('hg branch [NAME]')), | 2753 _('hg branch [NAME]')), |
2741 "branches": (branches, [], _('hg branches')), | 2754 "branches": (branches, |
2755 [('a', 'active', False, | |
2756 _("show only branches that have unmerged heads"))], | |
2757 _('hg branches [-a]')), | |
2742 "bundle": | 2758 "bundle": |
2743 (bundle, | 2759 (bundle, |
2744 [('f', 'force', None, | 2760 [('f', 'force', None, |
2745 _('run even when remote repository is unrelated')), | 2761 _('run even when remote repository is unrelated')), |
2746 ('r', 'rev', [], | 2762 ('r', 'rev', [], |