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

yuja (Yuya Nishihara) phabricator at mercurial-scm.org
Tue Dec 25 07:17:05 EST 2018


yuja added a comment.


  >   > ctx points to the tipmost branch head. so `rev not in revs` doesn't mean any
  >   >  of the `revs` do not belong to the branch.
  >   
  >   Is there any possibility of workaround within this iteration itself @yuja? I can do outside the current loop by creating a branches list and map it by iterating over scmutil.revrange() as suggested by you. But, that won't fetch all details. Just changeset and corresponding branch. We need to keep the same output format, right?
  
  Well, I meant you can build a set of branches to select.
  
    selectedbranches = {repo[r].branch() for r in revs}
    for tag, ... in repo.branchmap().iterbranches():
        if tag not in selectedbranches:
            continue
        ...
  
  This is the simplest implementation. Since `repo[r].branch()` isn't a cheap
  operation, it's probably better to query a revbranchcache.
  
    getbi = repo.revbranchcache().branchinfo
    selectedbranches = {getbi(r)[0] for r in revs}
  
  There will be more optimization ideas (e.g. look up branchmap directly if
  `len(revs) == 1`, but they won't be required to implement a minimal working
  patch.

REPOSITORY
  rHG Mercurial

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

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


More information about the Mercurial-devel mailing list