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

login
register
mail settings
Submitter phabricator
Date Dec. 25, 2018, 1:49 p.m.
Message ID <5010dbe852ee14229ca0b8d183bdab59@localhost.localdomain>
Download mbox | patch
Permalink /patch/37349/
State Not Applicable
Headers show

Comments

phabricator - Dec. 25, 2018, 1:49 p.m.
navaneeth.suresh updated this revision to Diff 12978.

REPOSITORY
  rHG Mercurial

CHANGES SINCE LAST UPDATE
  https://phab.mercurial-scm.org/D5477?vs=12969&id=12978

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

AFFECTED FILES
  mercurial/commands.py
  tests/test-branches.t

CHANGE DETAILS




To: navaneeth.suresh, #hg-reviewers
Cc: pulkit, yuja, mercurial-devel
Yuya Nishihara - Dec. 26, 2018, 12:44 p.m.
Looks mostly good.

Can you update the commit message to conform to our style?
https://www.mercurial-scm.org/wiki/ContributingChanges#Submission_checklist

You'll see some lint errors if you run `test-check-*`. And you'll probably
need to update `test-completion.t`.

>      opts = pycompat.byteskwargs(opts)
> +    revs = opts.get('rev')
> +    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
> @@ -1165,6 +1172,8 @@
>      allheads = set(repo.heads())
>      branches = []
>      for tag, heads, tip, isclosed in repo.branchmap().iterbranches():
> +        if revs and tag not in selectedbranches:
> +            continue

I prefer initializing `selectedbranches` to `None`, and check if it `is None`
here. It makes sure that `selectedbranches` never be an undefined name, and
avoid weird behavior when `revs` resolved to an empty set.
phabricator - Dec. 26, 2018, 1:02 p.m.
yuja added a comment.


  Looks mostly good.
  
  Can you update the commit message to conform to our style?
  https://www.mercurial-scm.org/wiki/ContributingChanges#Submission_checklist
  
  You'll see some lint errors if you run `test-check-*`. And you'll probably
  need to update `test-completion.t`.
  
  >   opts = pycompat.byteskwargs(opts)
  > 
  > +    revs = opts.get('rev')
  >  +    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
  > 
  > @@ -1165,6 +1172,8 @@
  > 
  >   allheads = set(repo.heads())
  >   branches = []
  >   for tag, heads, tip, isclosed in repo.branchmap().iterbranches():
  > 
  > +        if revs and tag not in selectedbranches:
  >  +            continue
  
  I prefer initializing `selectedbranches` to `None`, and check if it `is None`
  here. It makes sure that `selectedbranches` never be an undefined name, and
  avoid weird behavior when `revs` resolved to an empty set.

REPOSITORY
  rHG Mercurial

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

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

Patch

diff --git a/tests/test-branches.t b/tests/test-branches.t
--- a/tests/test-branches.t
+++ b/tests/test-branches.t
@@ -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
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'))
     ] + formatteropts,
     _('[-c]'),
     helpcategory=command.CATEGORY_CHANGE_ORGANIZATION,
@@ -1158,6 +1159,12 @@ 
     """
 
     opts = pycompat.byteskwargs(opts)
+    revs = opts.get('rev')
+    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
@@ -1165,6 +1172,8 @@ 
     allheads = set(repo.heads())
     branches = []
     for tag, heads, tip, isclosed in repo.branchmap().iterbranches():
+        if revs and tag not in selectedbranches:
+            continue
         isactive = False
         if not isclosed:
             openheads = set(repo.branchmap().iteropen(heads))