mercurial/commands.py
changeset 41064 4506f801e492
parent 41051 bad05a6afdc8
child 41121 5967995c32bb
--- 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))