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')
347
bzr_dir = os.path.join(output_dir, '.bzr')
348
new_bzr_dir = os.path.join(tempdir, "rd", '.bzr')
350
os.rename(bzr_dir, tmp_bzr_dir) # Move the original bzr out of the way
351
os.rename(new_bzr_dir, bzr_dir)
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')
350
bzr_dir = os.path.join(output_dir, '.bzr')
351
new_bzr_dir = os.path.join(tempdir, "rd", '.bzr')
353
os.rename(bzr_dir, tmp_bzr_dir) # Move the original bzr out of the way
354
os.rename(new_bzr_dir, bzr_dir)
356
bzrlib.merge.merge((output_dir, -1), (output_dir, None), # old_revno),
357
check_clean=False, this_dir=output_dir,
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)
365
# no imports - perhaps just append_revisions
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)
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)
362
371
revdir = os.path.join(tempdir, "rd")
363
372
os.rename(revdir, output_dir)
448
458
previous_version = version
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)
451
467
if revdir is None:
452
468
revdir = os.path.join(tempdir, "rd")
460
476
print ("unable to access ancestor %s, making into a merge."
461
477
% missing_ancestor)
463
# cached so we can delete the log
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)
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
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)
495
509
timestamp = email.Utils.mktime_tz(log_date + (0,))
496
rev_id = revision_id(revision)
497
510
if log_summary is None:
499
512
# log_descriptions of None and "" are ignored.
577
590
inv_iter = tree.iter_inventory_ids(source=True, both=True)
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
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)
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)
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)
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)
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')