pythonlinuxbazaar

What Bzr function can I use to return the Branch location if given the repository and revision # / revision ID?


If you have a repository and you open it up from your command line with the bzr qlog there is a section for each revision number that returns branch: trunk or branch: xyz

If you use the bzr log in the command line there is a section for each revision number that returns branch nick: trunk or branch nick: xyz or branch nick: yougettheidea

The nick is short for nickname as I have discovered from actually reading into the log python script.

My thought is that since there is some code that is pulling out the location of the branch for each revision and displaying it in the log then I should be able to use that directly to just return the branch location by itself. So the code would run and return to me trunk or xyz.

I would like to write this code using python and the bzrlib toolbox.

Lastly I found this within the log.py code directly from bzr.

branch_nick = revision.rev.properties.get('branch-nick', None) if branch_nick is not None: lines.append('branch nick: %s' % (branch_nick,))

However, when I try to use revision.rev.properties.get('branch-nick', None) it gives me an error message saying the rev has no attribute to revision module. Also I would not know what to put in place for None.


Solution

  • So the best way that I found to do this is by running this code. It will return the 'branch nickname'

    `from bzrlib.branch import Branch
    r1= "revision number such as 1024"
    d1= "directory containing repository"
    b = Branch.open (d1)
    c = b.dotted_revno_to_revision_id((r1,), _cache_reverse=False)
    f = b.repository.get_revision(c).properties.get('branch-nick')`
    
    `print f`