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

Yuya Nishihara yuya at tcha.org
Wed Dec 26 07:44:15 EST 2018


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.


More information about the Mercurial-devel mailing list