branches: add -r option to show branch name(s) of a given rev (
issue5948)
Differential Revision: https://phab.mercurial-scm.org/D5486
--- a/mercurial/commands.py Mon Dec 10 20:06:58 2018 +0000
+++ b/mercurial/commands.py Mon Dec 24 17:04:37 2018 +0530
@@ -1132,6 +1132,7 @@
[('a', 'active', False,
_('show only branches that have unmerged heads (DEPRECATED)')),
('c', 'closed', False, _('show normal and closed branches')),
+ ('r', 'rev', [], _('show branch name(s) of the given rev'))
] + formatteropts,
_('[-c]'),
helpcategory=command.CATEGORY_CHANGE_ORGANIZATION,
@@ -1161,6 +1162,13 @@
"""
opts = pycompat.byteskwargs(opts)
+ revs = opts.get('rev')
+ selectedbranches = None
+ if revs:
+ revs = scmutil.revrange(repo, revs)
+ getbi = repo.revbranchcache().branchinfo
+ selectedbranches = {getbi(r)[0] for r in revs}
+
ui.pager('branches')
fm = ui.formatter('branches', opts)
hexfunc = fm.hexfunc
@@ -1168,6 +1176,8 @@
allheads = set(repo.heads())
branches = []
for tag, heads, tip, isclosed in repo.branchmap().iterbranches():
+ if selectedbranches is not None and tag not in selectedbranches:
+ continue
isactive = False
if not isclosed:
openheads = set(repo.branchmap().iteropen(heads))
--- a/tests/test-branches.t Mon Dec 10 20:06:58 2018 +0000
+++ b/tests/test-branches.t Mon Dec 24 17:04:37 2018 +0530
@@ -157,6 +157,18 @@
summary: Adding b branch
+---- going to test branch listing by rev
+ $ hg branches -r0
+ default 0:19709c5a4e75 (inactive)
+ $ hg branches -qr0
+ default
+--- now more than one rev
+ $ hg branches -r2:5
+ b 4:aee39cd168d0
+ a 5:d8cbc61dbaa6 (inactive)
+ $ hg branches -qr2:5
+ b
+ a
---- going to test branch closing
$ hg branches
--- a/tests/test-completion.t Mon Dec 10 20:06:58 2018 +0000
+++ b/tests/test-completion.t Mon Dec 24 17:04:37 2018 +0530
@@ -238,7 +238,7 @@
bisect: reset, good, bad, skip, extend, command, noupdate
bookmarks: force, rev, delete, rename, inactive, list, template
branch: force, clean, rev
- branches: active, closed, template
+ branches: active, closed, rev, template
bundle: force, rev, branch, base, all, type, ssh, remotecmd, insecure
cat: output, rev, decode, include, exclude, template
clone: noupdate, updaterev, rev, branch, pull, uncompressed, stream, ssh, remotecmd, insecure