0

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.

2 Answers2

1

The branch nick does not necessarily refer to anything that exists on disk. You can manually set the branch nick with the bzr nick command, or it may be the last part of the path of the branch name on the machine where the revision was created.

revision is an object returned by Repository.get_revision, not the bzrlib.revision module.

jelmer
  • 2,405
  • 14
  • 27
  • So how could I go about getting the branch location as an output of any given function? By the way jelmer I really appreciate your answers you have helped me out quite alot. – newtopython Jun 18 '20 at 17:16
  • 1
    Unfortunately Bazaar doesn't store that information. The only thing you can do is store the information when you're creating the commit /or/ searching known locations for branches and checking if one of them matches. – jelmer Jun 19 '20 at 03:04
  • I actually found out how to return the information. I will add it as an answer. But again I do appreciate the help. Bazaar is brand new to me. – newtopython Jun 19 '20 at 13:31
0

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`
  • 1
    That will contain the branch *nick* at the time the commit was created. This only works if: 1) the branch nick hasn't been changed 2) the branch hasn't deleted or moved 3) you created the branch, and not somebody else 4) the branch is directly under the repository – jelmer Jun 19 '20 at 21:15