~abentley/bzrtools/bzrtools.dev

« back to all changes in this revision

Viewing changes to baz_import.py

  • Committer: Aaron Bentley
  • Date: 2005-10-24 00:08:03 UTC
  • mfrom: (147.4.5)
  • mto: (147.4.12)
  • mto: This revision was merged to the branch mainline in revision 324.
  • Revision ID: aaron.bentley@utoronto.ca-20051024000803-0e9b59dee42d0460
Merge lifeless

Show diffs side-by-side

added added

removed removed

Lines of Context:
342
342
            return
343
343
        if os.path.exists(output_dir):
344
344
            # Move the bzr control directory back, and update the working tree
345
 
            tmp_bzr_dir = os.path.join(tempdir, '.bzr')
346
 
            
347
 
            bzr_dir = os.path.join(output_dir, '.bzr')
348
 
            new_bzr_dir = os.path.join(tempdir, "rd", '.bzr')
349
 
 
350
 
            os.rename(bzr_dir, tmp_bzr_dir) # Move the original bzr out of the way
351
 
            os.rename(new_bzr_dir, bzr_dir)
352
 
            try:
 
345
            revdir = os.path.join(tempdir, "rd")
 
346
            if os.path.exists(revdir):
 
347
                # actual imports were done
 
348
                tmp_bzr_dir = os.path.join(tempdir, '.bzr')
 
349
                
 
350
                bzr_dir = os.path.join(output_dir, '.bzr')
 
351
                new_bzr_dir = os.path.join(tempdir, "rd", '.bzr')
 
352
    
 
353
                os.rename(bzr_dir, tmp_bzr_dir) # Move the original bzr out of the way
 
354
                os.rename(new_bzr_dir, bzr_dir)
 
355
                try:
 
356
                    bzrlib.merge.merge((output_dir, -1), (output_dir, None), # old_revno), 
 
357
                                       check_clean=False, this_dir=output_dir, 
 
358
                                       ignore_zero=True)
 
359
                except:
 
360
                    # If something failed, move back the original bzr directory
 
361
                    os.rename(bzr_dir, new_bzr_dir)
 
362
                    os.rename(tmp_bzr_dir, bzr_dir)
 
363
                    raise
 
364
            else:
 
365
                # no imports - perhaps just append_revisions
 
366
                # should not fail:
353
367
                bzrlib.merge.merge((output_dir, -1), (output_dir, None), # old_revno), 
354
368
                                   check_clean=False, this_dir=output_dir, 
355
369
                                   ignore_zero=True)
356
 
            except:
357
 
                # If something failed, move back the original bzr directory
358
 
                os.rename(bzr_dir, new_bzr_dir)
359
 
                os.rename(tmp_bzr_dir, bzr_dir)
360
 
                raise
361
370
        else:
362
371
            revdir = os.path.join(tempdir, "rd")
363
372
            os.rename(revdir, output_dir)
438
447
 
439
448
    for i in range(len(ancestors)):
440
449
        revision = ancestors[i]
 
450
        rev_id = revision_id(revision)
441
451
        direct_merges = []
442
452
        if verbose:
443
453
            version = str(revision.version)
448
458
            previous_version = version
449
459
        else:
450
460
            yield Progress("revisions", i, len(ancestors))
 
461
        if revdir is None and os.path.exists(output_dir):
 
462
            # check for imported revisions and if present just append immediately
 
463
            branch = Branch.open(output_dir)
 
464
            if branch.has_revision(rev_id):
 
465
                branch.append_revision(rev_id)
 
466
                continue
451
467
        if revdir is None:
452
468
            revdir = os.path.join(tempdir, "rd")
453
469
            try:
460
476
                print ("unable to access ancestor %s, making into a merge."
461
477
                       % missing_ancestor)
462
478
                continue
463
 
            # cached so we can delete the log
464
 
            log_date = log.date
465
 
            log_summary = log.summary
466
 
            log_description = log.description
467
 
            is_continuation = log.continuation_of is not None
468
 
            log_creator = log.creator
469
479
            if os.path.exists(output_dir):
470
480
                bzr_dir = os.path.join(output_dir, '.bzr')
471
481
                new_bzr_dir = os.path.join(tempdir, "rd", '.bzr')
473
483
                # we fail, we have corrupted the original .bzr directory.  Is
474
484
                # that a big problem, as we can just back out the last
475
485
                # revisions in .bzr/revision_history I don't really know
 
486
                # RBC20051024 - yes, it would be a problem as we could not then
 
487
                # apply the corrupted revision.
476
488
                shutil.copytree(bzr_dir, new_bzr_dir)
477
489
                # Now revdir should have a tree with the latest .bzr, and the
478
490
                # next revision of the baz tree
484
496
            new = os.path.join(tempdir, ".bzr")
485
497
            os.rename(old, new)
486
498
            baz_inv, log = apply_revision(tree, revision)
487
 
            log_date = log.date
488
 
            log_summary = log.summary
489
 
            log_description = log.description
490
 
            log_creator = log.creator
491
 
            is_continuation = log.continuation_of is not None
492
 
            direct_merges = get_direct_merges(revdir, revision)
493
499
            os.rename(new, old)
494
500
            branch = Branch.open(revdir)
 
501
        # cached so we can delete the log
 
502
        log_date = log.date
 
503
        log_summary = log.summary
 
504
        log_description = log.description
 
505
        is_continuation = log.continuation_of is not None
 
506
        log_creator = log.creator
 
507
        direct_merges = get_direct_merges(revdir, revision)
 
508
 
495
509
        timestamp = email.Utils.mktime_tz(log_date + (0,))
496
 
        rev_id = revision_id(revision)
497
510
        if log_summary is None:
498
511
            log_summary = ""
499
512
        # log_descriptions of None and "" are ignored.
577
590
    inv_iter = tree.iter_inventory_ids(source=True, both=True)
578
591
    inv_map = {}
579
592
    for arch_id, path in inv_iter:
580
 
        bzr_file_id = arch_id.replace('%', '%25').replace('/', '%2f')
 
593
        bzr_file_id = map_file_id(arch_id)
581
594
        inv_map[path] = bzr_file_id 
582
595
 
583
596
    bzr_inv = []
638
651
        printer("importing %s into %s" % (version, target))
639
652
        if not os.path.exists(os.path.dirname(target)):
640
653
            os.makedirs(os.path.dirname(target))
641
 
        import_version(target, version, printer)
 
654
        try:
 
655
            import_version(target, version, printer)
 
656
        except pybaz.errors.ExecProblem,e:
 
657
            if str(e).find('The requested revision cannot be built.') != -1:
 
658
                printer("Skipping version %s as it cannot be built due"
 
659
                        " to a missing parent archive." % version)
 
660
            else:
 
661
                raise
 
662
        except UserError, e:
 
663
            if str(e).find('already exists, and the last revision ') != -1:
 
664
                printer("Skipping version %s as it has had commits made"
 
665
                        " since it was converted to bzr." % version)
 
666
            else:
 
667
                raise
642
668
 
643
669
 
644
670
def map_namespace(a_version):
652
678
    if version == '0':
653
679
        return "%s/%s" % (category, branch)
654
680
    return "%s/%s/%s" % (category, version, branch)
 
681
 
 
682
def map_file_id(file_id):
 
683
    """Convert a baz file id to a bzr one."""
 
684
    return file_id.replace('%', '%25').replace('/', '%2f')