diff mercurial/commands.py @ 41067: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
line wrap: on
line diff
--- 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))