pythonlinuxbazaar

How do you use '_find_parent_ids_of_revisions' function from the bzrlib toolbox?


Okay so when I try to use this code calling it from the linux command line:

import bzrlib
from bzrlib.branch import Branch
from bzrlib import log
from bzrlib import repository
import sys


import argparse


parser = argparse.ArgumentParser()
parser.add_argument('-r', '--revnum', type=int, metavar='', required=True, help='Baseline revision number')
parser.add_argument('-d', '--directory',type=str, metavar='',required=True,help='Directory that repository in question is located')
args = parser.parse_args()

r1= args.revnum
d1= args.directory

print ''
print 'Directory containing repository: '+ (d1)
print ''
print ("Input revision number: %s" %(r1))
print ''

b = Branch.open (d1)

repository.Repository._find_parent_ids_of_revisions(revision_ids)

I get this error message no matter what I put in place of revison_ids.

must be called with Repository instance as first argument

I don't know how to utilize this bzrlib function and it should do exactly what I want it to do if I can get it to actually give me an output. I would appreciate any help! Thanks!


Solution

  • You shouldn't be using Repository._find_parent_ids_of_revisions - it will change between versions of the library.

    Instead, call either Repository.get_revision or Repository.get_parent_map to get the parents of a revision.

    You can open a Repository with the Repository.open call (which takes a path as argument), or if you already have a branch (as you do in this case), you can use the "repository" attribute on the "Branch" object, like so:

    b = Branch.open(d1)
    
    revid = b.dotted_revno_to_revision((r1, ))
    
    parent_ids = b.repository.get_revision(revid).parent_ids