comparison 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
comparison
equal deleted inserted replaced
4674:723e0ddb6ada 4676:0f6e2b37512d
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
2744 _('hg backout [OPTION]... [-r] REV')), 2757 _('hg backout [OPTION]... [-r] REV')),
2745 "branch": (branch, 2758 "branch": (branch,
2746 [('f', 'force', None, 2759 [('f', 'force', None,
2747 _('set branch name even if it shadows an existing branch'))], 2760 _('set branch name even if it shadows an existing branch'))],
2748 _('hg branch [NAME]')), 2761 _('hg branch [NAME]')),
2749 "branches": (branches, [], _('hg branches')), 2762 "branches": (branches,
2763 [('a', 'active', False,
2764 _("show only branches that have unmerged heads"))],
2765 _('hg branches [-a]')),
2750 "bundle": 2766 "bundle":
2751 (bundle, 2767 (bundle,
2752 [('f', 'force', None, 2768 [('f', 'force', None,
2753 _('run even when remote repository is unrelated')), 2769 _('run even when remote repository is unrelated')),
2754 ('r', 'rev', [], 2770 ('r', 'rev', [],