355
def import_version(output_dir, version, fast=False,
356
def import_version(output_dir, version, printer, fancy=True, fast=False,
356
357
verbose=False, dry_run=False, max_count=None,
357
358
reuse_history_from=[], standalone=True):
359
360
>>> q = test_environ()
361
Progress bars output to stderr, but doctest does not capture that.
363
>>> old_stderr = sys.stderr
364
>>> sys.stderr = sys.stdout
366
361
>>> result_path = os.path.join(q, "result")
367
362
>>> commit_test_revisions()
368
363
>>> version = pybaz.Version("test@example.com/test--test--0.1")
369
>>> old_ui = bzrlib.ui.ui_factory
370
>>> bzrlib.ui.ui_factory = bzrlib.ui.text.TextUIFactory(
371
... bar_type=bzrlib.progress.DotsProgressBar)
373
>>> import_version('/', version, dry_run=True)
364
>>> def printer(message): print message
365
>>> import_version('/', version, printer, fancy=False, dry_run=True)
374
366
Traceback (most recent call last):
375
367
NotPreviousImport: / is not the location of a previous import.
376
>>> import_version(result_path, version, dry_run=True)
368
>>> import_version(result_path, version, printer, fancy=False, dry_run=True)
377
369
Traceback (most recent call last):
378
370
UserError: The version test@example.com/test--test--0.1 does not exist.
379
371
>>> version = pybaz.Version("test@example.com/test--test--0")
380
>>> import_version(result_path, version, dry_run=True) #doctest: +ELLIPSIS
381
importing test@example.com/test--test--0 into ...
383
revisions: ..........................................
372
>>> import_version(result_path, version, printer, fancy=False, dry_run=True)
384
375
Dry run, not modifying output_dir
386
>>> import_version(result_path, version) #doctest: +ELLIPSIS
387
importing test@example.com/test--test--0 into ...
389
revisions: .....................................................................
377
>>> import_version(result_path, version, printer, fancy=False)
392
>>> import_version(result_path, version) #doctest: +ELLIPSIS
382
>>> import_version(result_path, version, printer, fancy=False)
393
383
Tree is up-to-date with test@example.com/test--test--0--patch-2
394
384
>>> commit_more_test_revisions()
395
>>> import_version(result_path, version) #doctest: +ELLIPSIS
396
importing test@example.com/test--test--0 into ...
397
revisions: ....................................................
385
>>> import_version(result_path, version, printer, fancy=False)
400
>>> bzrlib.ui.ui_factory = old_ui
401
>>> sys.stderr = old_stderr
402
390
>>> teardown_environ(q)
404
progress_bar = bzrlib.ui.ui_factory.nested_progress_bar()
393
ancestors, old_revno = get_remaining_revisions(output_dir, version,
395
except NotBranchError, e:
396
raise NotPreviousImport(e.path)
397
if old_revno is None and len(ancestors) == 0:
398
print 'Version %s has no revisions.' % version
400
if len(ancestors) == 0:
401
last_revision = get_last_revision(Branch.open(output_dir))
402
print 'Tree is up-to-date with %s' % last_revision
405
progress_bar = bzrlib.ui.ui_factory.progress_bar()
406
tempdir = tempfile.mkdtemp(prefix="baz2bzr-",
407
dir=os.path.dirname(output_dir))
409
wt = WorkingTree.open(output_dir)
410
except (NotBranchError, NoWorkingTree):
413
old_basis = EmptyTree()
415
old_basis = wt.basis_tree()
407
ancestors, old_revno = get_remaining_revisions(output_dir, version,
409
except NotBranchError, e:
410
raise NotPreviousImport(e.path)
411
if old_revno is None and len(ancestors) == 0:
412
progress_bar.note('Version %s has no revisions.' % version)
414
if len(ancestors) == 0:
415
last_revision = get_last_revision(Branch.open(output_dir))
416
progress_bar.note('Tree is up-to-date with %s' % last_revision)
419
progress_bar.note("importing %s into %s" % (version, output_dir))
421
tempdir = tempfile.mkdtemp(prefix="baz2bzr-",
422
dir=os.path.dirname(output_dir))
420
for result in iter_import_version(output_dir, ancestors, tempdir,
421
progress_bar, fast=fast, verbose=verbose, dry_run=dry_run,
422
max_count=max_count, standalone=standalone):
424
show_progress(progress_bar, result)
426
sys.stdout.write('.')
431
sys.stdout.write('\n')
434
print 'Dry run, not modifying output_dir'
437
# Update the working tree of the branch
424
439
wt = WorkingTree.open(output_dir)
425
except (NotBranchError, NoWorkingTree):
440
except NoWorkingTree:
428
old_basis = EmptyTree()
430
old_basis = wt.basis_tree()
432
for result in iter_import_version(output_dir, ancestors, tempdir,
434
fast=fast, verbose=verbose, dry_run=dry_run,
435
max_count=max_count, standalone=standalone):
436
show_progress(progress_bar, result)
438
progress_bar.note('Dry run, not modifying output_dir')
441
# Update the working tree of the branch
443
wt = WorkingTree.open(output_dir)
444
except NoWorkingTree:
447
wt.set_last_revision(wt.branch.last_revision())
448
merge_inner(wt.branch, wt.basis_tree(), old_basis,
449
ignore_zero=True, this_tree=wt)
454
progress_bar.note('Cleaning up')
455
shutil.rmtree(tempdir)
456
progress_bar.note("Import complete.")
443
wt.set_last_revision(wt.branch.last_revision())
444
merge_inner(wt.branch, wt.basis_tree(), old_basis,
445
ignore_zero=True, this_tree=wt)
458
progress_bar.finished()
449
printer('Cleaning up')
450
shutil.rmtree(tempdir)
451
printer("Import complete.")
460
453
class UserError(BzrCommandError):
461
454
def __init__(self, message):
812
812
create_shared_repository(to_root)
813
813
except NoRepositoryPresent:
814
814
raise BzrCommandError("Can't create repository at existing branch.")
815
versions = list(pybaz.Archive(str(from_archive)).iter_versions())
816
progress_bar = bzrlib.ui.ui_factory.nested_progress_bar()
818
for num, version in enumerate(versions):
819
progress_bar.update("Branch", num, len(versions))
820
if not selected(version):
821
print "Skipping %s" % version
823
target = os.path.join(to_root, map_namespace(version))
824
if not os.path.exists(os.path.dirname(target)):
825
os.makedirs(os.path.dirname(target))
827
import_version(target, version,
828
reuse_history_from=reuse_history_from,
829
standalone=standalone)
830
except pybaz.errors.ExecProblem,e:
831
if str(e).find('The requested revision cannot be built.') != -1:
833
"Skipping version %s as it cannot be built due"
815
for version in pybaz.Archive(str(from_archive)).iter_versions():
816
if not selected(version):
817
print "Skipping %s" % version
819
target = os.path.join(to_root, map_namespace(version))
820
printer("importing %s into %s" % (version, target))
821
if not os.path.exists(os.path.dirname(target)):
822
os.makedirs(os.path.dirname(target))
824
import_version(target, version, printer,
825
reuse_history_from=reuse_history_from,
826
standalone=standalone)
827
except pybaz.errors.ExecProblem,e:
828
if str(e).find('The requested revision cannot be built.') != -1:
829
printer("Skipping version %s as it cannot be built due"
834
830
" to a missing parent archive." % version)
838
if str(e).find('already exists, and the last revision ') != -1:
840
"Skipping version %s as it has had commits made"
834
if str(e).find('already exists, and the last revision ') != -1:
835
printer("Skipping version %s as it has had commits made"
841
836
" since it was converted to bzr." % version)
845
progress_bar.finished()
848
841
def map_namespace(a_version):