D5477: branches: Added -r option to show branch name(s) of a given rev (Issue5948)

navaneeth.suresh (Navaneeth Suresh) phabricator at mercurial-scm.org
Mon Dec 24 11:35:33 UTC 2018


navaneeth.suresh created this revision.
Herald added a subscriber: mercurial-devel.
Herald added a reviewer: hg-reviewers.

REPOSITORY
  rHG Mercurial

REVISION DETAIL
  https://phab.mercurial-scm.org/D5477

AFFECTED FILES
  mercurial/commands.py

CHANGE DETAILS

diff --git a/mercurial/commands.py b/mercurial/commands.py
--- a/mercurial/commands.py
+++ b/mercurial/commands.py
@@ -1129,6 +1129,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(s)'))
     ] + formatteropts,
     _('[-c]'),
     helpcategory=command.CATEGORY_CHANGE_ORGANIZATION,
@@ -1158,6 +1159,10 @@
     """
 
     opts = pycompat.byteskwargs(opts)
+    revs = opts.get('rev')
+    if revs:
+        revs = scmutil.revrange(repo, revs)
+
     ui.pager('branches')
     fm = ui.formatter('branches', opts)
     hexfunc = fm.hexfunc
@@ -1192,8 +1197,11 @@
             label = 'branches.current'
 
         fm.startitem()
+        rev = ctx.rev()
+        if opts.get('rev') and rev not in revs:
+            continue
+
         fm.write('branch', '%s', tag, label=label)
-        rev = ctx.rev()
         padsize = max(31 - len("%d" % rev) - encoding.colwidth(tag), 0)
         fmt = ' ' * padsize + ' %d:%s'
         fm.condwrite(not ui.quiet, 'rev node', fmt, rev, hexfunc(ctx.node()),



To: navaneeth.suresh, #hg-reviewers
Cc: mercurial-devel


More information about the Mercurial-devel mailing list