comparison mercurial/commands.py @ 22703:bd6e95cb82b4

branches: port to generic templater
author Yuya Nishihara <yuya@tcha.org>
date Thu, 02 Oct 2014 22:59:56 +0900
parents 08a4e70ed183
children 386339ffe421
comparison
equal deleted inserted replaced
22702:08a4e70ed183 22703:bd6e95cb82b4
1071 finally: 1071 finally:
1072 wlock.release() 1072 wlock.release()
1073 1073
1074 @command('branches', 1074 @command('branches',
1075 [('a', 'active', False, _('show only branches that have unmerged heads')), 1075 [('a', 'active', False, _('show only branches that have unmerged heads')),
1076 ('c', 'closed', False, _('show normal and closed branches'))], 1076 ('c', 'closed', False, _('show normal and closed branches')),
1077 ] + formatteropts,
1077 _('[-ac]')) 1078 _('[-ac]'))
1078 def branches(ui, repo, active=False, closed=False): 1079 def branches(ui, repo, active=False, closed=False, **opts):
1079 """list repository named branches 1080 """list repository named branches
1080 1081
1081 List the repository's named branches, indicating which ones are 1082 List the repository's named branches, indicating which ones are
1082 inactive. If -c/--closed is specified, also list branches which have 1083 inactive. If -c/--closed is specified, also list branches which have
1083 been marked closed (see :hg:`commit --close-branch`). 1084 been marked closed (see :hg:`commit --close-branch`).
1088 Use the command :hg:`update` to switch to an existing branch. 1089 Use the command :hg:`update` to switch to an existing branch.
1089 1090
1090 Returns 0. 1091 Returns 0.
1091 """ 1092 """
1092 1093
1093 hexfunc = ui.debugflag and hex or short 1094 fm = ui.formatter('branches', opts)
1095 hexfunc = fm.hexfunc
1094 1096
1095 allheads = set(repo.heads()) 1097 allheads = set(repo.heads())
1096 branches = [] 1098 branches = []
1097 for tag, heads, tip, isclosed in repo.branchmap().iterbranches(): 1099 for tag, heads, tip, isclosed in repo.branchmap().iterbranches():
1098 isactive = not isclosed and bool(set(heads) & allheads) 1100 isactive = not isclosed and bool(set(heads) & allheads)
1114 else: 1116 else:
1115 label = 'branches.inactive' 1117 label = 'branches.inactive'
1116 notice = _(' (inactive)') 1118 notice = _(' (inactive)')
1117 if tag == repo.dirstate.branch(): 1119 if tag == repo.dirstate.branch():
1118 label = 'branches.current' 1120 label = 'branches.current'
1121
1122 fm.startitem()
1123 fm.write('branch', '%s', tag, label=label)
1119 rev = ctx.rev() 1124 rev = ctx.rev()
1120 padsize = max(31 - len(str(rev)) - encoding.colwidth(tag), 0) 1125 padsize = max(31 - len(str(rev)) - encoding.colwidth(tag), 0)
1121 fmt = ' ' * padsize + '%d:%s' 1126 fmt = ' ' * padsize + '%d:%s'
1122 rev = ui.label(fmt % (rev, hexfunc(ctx.node())), 1127 if not ui.quiet:
1123 'log.changeset changeset.%s' % ctx.phasestr()) 1128 fm.plain(' ')
1124 labeledtag = ui.label(tag, label) 1129 fm.condwrite(not ui.quiet, 'rev node', fmt, rev, hexfunc(ctx.node()),
1125 if ui.quiet: 1130 label='log.changeset changeset.%s' % ctx.phasestr())
1126 ui.write("%s\n" % labeledtag) 1131 if not ui.quiet:
1127 else: 1132 fm.plain(notice)
1128 ui.write("%s %s%s\n" % (labeledtag, rev, notice)) 1133 fm.plain('\n')
1134 fm.end()
1129 1135
1130 @command('bundle', 1136 @command('bundle',
1131 [('f', 'force', None, _('run even when the destination is unrelated')), 1137 [('f', 'force', None, _('run even when the destination is unrelated')),
1132 ('r', 'rev', [], _('a changeset intended to be added to the destination'), 1138 ('r', 'rev', [], _('a changeset intended to be added to the destination'),
1133 _('REV')), 1139 _('REV')),