~abentley/bzrtools/bzrtools.dev

« back to all changes in this revision

Viewing changes to baz_import.py

  • Committer: Robert Collins
  • Date: 2005-09-28 06:11:50 UTC
  • mto: (147.2.6) (364.1.3 bzrtools)
  • mto: This revision was merged to the branch mainline in revision 324.
  • Revision ID: robertc@robertcollins.net-20050928061150-2920dac61286de9f
update to latest bzr api

Show diffs side-by-side

added added

removed removed

Lines of Context:
229
229
    if os.path.exists(output_dir):
230
230
        # We are starting from an existing directory, figure out what
231
231
        # the current version is
232
 
        branch = find_branch(output_dir, find_root=False)
 
232
        branch = Branch.open(output_dir)
233
233
        last_patch = get_last_revision(branch)
234
234
        if version is None:
235
235
            version = last_patch.version
252
252
        # Strip off all of the ancestors which are already present
253
253
        # And get a directory starting with the latest ancestor
254
254
        latest_ancestor = ancestors[i]
255
 
        old_revno = find_branch(output_dir, find_root=False).revno()
 
255
        old_revno = Branch.open(output_dir).revno()
256
256
        ancestors = ancestors[i+1:]
257
257
    return ancestors, old_revno
258
258
 
296
296
    except NotBranchError, e:
297
297
        raise UserError("%s exists, but is not a bzr branch." % output_dir)
298
298
    if len(ancestors) == 0:
299
 
        last_revision = get_last_revision(find_branch(output_dir, find_root=False))
 
299
        last_revision = get_last_revision(Branch.open(output_dir))
300
300
        print 'Tree is up-to-date with %s' % last_revision
301
301
        return
302
302
 
457
457
                shutil.copytree(bzr_dir, new_bzr_dir)
458
458
                # Now revdir should have a tree with the latest .bzr, and the
459
459
                # next revision of the baz tree
460
 
                branch = find_branch(revdir, find_root=False)
 
460
                branch = Branch.open(revdir)
461
461
            else:
462
462
                branch = Branch.initialize(revdir)
463
463
        else:
470
470
            log_creator = log.creator
471
471
            direct_merges = get_direct_merges(revdir, revision)
472
472
            os.rename(new, old)
473
 
            branch = find_branch(revdir, find_root=False)
 
473
            branch = Branch.open(revdir)
474
474
        timestamp = email.Utils.mktime_tz(log_date + (0,))
475
475
        rev_id = revision_id(revision)
476
476
        branch.lock_write()
538
538
        raise UserError("Cannot convert %s because %s is a %s" % (revision,e.path, e.kind) )
539
539
 
540
540
 
541
 
 
542
 
 
543
541
class BadFileKind(Exception):
544
542
    """The file kind is not permitted in bzr inventories"""
545
543
    def __init__(self, tree_root, path, kind):
549
547
        Exception.__init__(self, "File %s is of forbidden type %s" %
550
548
                           (os.path.join(tree_root, path), kind))
551
549
 
 
550
 
552
551
def bzr_inventory_data(tree):
553
552
    inv_iter = tree.iter_inventory_ids(source=True, both=True)
554
553
    inv_map = {}
572
571
    return bzr_inv
573
572
 
574
573
 
575
 
class NotInABranch(Exception):
576
 
    def __init__(self, path):
577
 
        Exception.__init__(self, "%s is not in a branch." % path)
578
 
        self.path = path
579
 
 
580
 
 
581
 
def find_branch(path):
582
 
    """
583
 
    >>> find_branch('/')
584
 
    Traceback (most recent call last):
585
 
    NotInABranch: / is not in a branch.
586
 
    >>> sb = bzrlib.ScratchBranch()
587
 
    >>> isinstance(find_branch(sb.base), Branch)
588
 
    True
589
 
    """
590
 
    try:
591
 
        return Branch.open(path)
592
 
    except BzrError, e:
593
 
        if e.args[0].endswith("' is not in a branch"):
594
 
            raise NotInABranch(path)
595
 
 
596
 
 
597
574
class cmd_baz_import_branch(Command):
598
575
    """Import an Arch or Baz branch into a bzr branch"""
599
576
    takes_args = ['to_location', 'from_branch?']
613
590
                return 1
614
591
        import_version(to_location, from_branch, self.printer)
615
592
 
 
593
 
616
594
class cmd_baz_import(Command):
617
595
    """Import an Arch or Baz archive into bzr branches."""
618
596
    takes_args = ['to_root_dir', 'from_archive']
627
605
            os.mkdir(to_root)
628
606
        import_archive(to_root, from_archive, verbose, self.printer)
629
607
 
 
608
 
630
609
def import_archive(to_root, from_archive, verbose, printer):
631
610
    for version in pybaz.Archive(str(from_archive)).iter_versions():
632
611
        target = os.path.join(to_root, map_namespace(version))
635
614
            os.makedirs(os.path.dirname(target))
636
615
        import_version(target, version, printer)
637
616
 
 
617
 
638
618
def map_namespace(a_version):
639
619
    a_version = pybaz.Version("%s" % a_version)
640
620
    parser = NameParser(a_version)