comparison mercurial/commands.py @ 41064:4506f801e492

branches: add -r option to show branch name(s) of a given rev (issue5948) Differential Revision: https://phab.mercurial-scm.org/D5486
author Navaneeth Suresh <navaneeths1998@gmail.com>
date Mon, 24 Dec 2018 17:04:37 +0530
parents bad05a6afdc8
children 5967995c32bb
comparison
equal deleted inserted replaced
41063:6603de284b0a 41064:4506f801e492
1130 1130
1131 @command('branches', 1131 @command('branches',
1132 [('a', 'active', False, 1132 [('a', 'active', False,
1133 _('show only branches that have unmerged heads (DEPRECATED)')), 1133 _('show only branches that have unmerged heads (DEPRECATED)')),
1134 ('c', 'closed', False, _('show normal and closed branches')), 1134 ('c', 'closed', False, _('show normal and closed branches')),
1135 ('r', 'rev', [], _('show branch name(s) of the given rev'))
1135 ] + formatteropts, 1136 ] + formatteropts,
1136 _('[-c]'), 1137 _('[-c]'),
1137 helpcategory=command.CATEGORY_CHANGE_ORGANIZATION, 1138 helpcategory=command.CATEGORY_CHANGE_ORGANIZATION,
1138 intents={INTENT_READONLY}) 1139 intents={INTENT_READONLY})
1139 def branches(ui, repo, active=False, closed=False, **opts): 1140 def branches(ui, repo, active=False, closed=False, **opts):
1159 1160
1160 Returns 0. 1161 Returns 0.
1161 """ 1162 """
1162 1163
1163 opts = pycompat.byteskwargs(opts) 1164 opts = pycompat.byteskwargs(opts)
1165 revs = opts.get('rev')
1166 selectedbranches = None
1167 if revs:
1168 revs = scmutil.revrange(repo, revs)
1169 getbi = repo.revbranchcache().branchinfo
1170 selectedbranches = {getbi(r)[0] for r in revs}
1171
1164 ui.pager('branches') 1172 ui.pager('branches')
1165 fm = ui.formatter('branches', opts) 1173 fm = ui.formatter('branches', opts)
1166 hexfunc = fm.hexfunc 1174 hexfunc = fm.hexfunc
1167 1175
1168 allheads = set(repo.heads()) 1176 allheads = set(repo.heads())
1169 branches = [] 1177 branches = []
1170 for tag, heads, tip, isclosed in repo.branchmap().iterbranches(): 1178 for tag, heads, tip, isclosed in repo.branchmap().iterbranches():
1179 if selectedbranches is not None and tag not in selectedbranches:
1180 continue
1171 isactive = False 1181 isactive = False
1172 if not isclosed: 1182 if not isclosed:
1173 openheads = set(repo.branchmap().iteropen(heads)) 1183 openheads = set(repo.branchmap().iteropen(heads))
1174 isactive = bool(openheads & allheads) 1184 isactive = bool(openheads & allheads)
1175 branches.append((tag, repo[tip], isactive, not isclosed)) 1185 branches.append((tag, repo[tip], isactive, not isclosed))