0

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!

  • Functions/methods starting with an underscore are usually not meant for public use. The error indicates that ``_find_parent_ids_of_revisions`` must be called on an *instance* of ``repository.Repository``, not the class itself, though. – MisterMiyagi Jun 11 '20 at 18:30
  • Thank you for the feedback! What would an example of an "instance" of repository.Repository look like? – newtopython Jun 11 '20 at 19:44
  • Well, usually ``repository.Repository()``. I'm not familiar with the library, so I can't say whether it expects any arguments (it probably does). – MisterMiyagi Jun 11 '20 at 19:49

1 Answers1

0

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
jelmer
  • 2,405
  • 14
  • 27
  • So that worked, but now I am having the same problem regarding getting the dotted revision numbers of the parent_ids. I don't think I really understand the error message that I keep getting about things must be called on an _instance_ of Branch or repository etc. Here is the most recent code I tried. `dotted_revno = b.revision_id_to_dotted_revno((parent_ids),).dotted_revno print dotted_revno` `I get the error `unhashable type: 'list'` – newtopython Jun 12 '20 at 13:43
  • revision_id_to_dotted_revno takes a single parent id, not multiple. For example, you can pass it parent_ids[0] – jelmer Jun 12 '20 at 15:55