31
31
from bzrlib.option import _global_option, Option
32
32
from bzrlib.merge import merge_inner
33
33
from bzrlib.revision import NULL_REVISION
34
from bzrlib.tree import EmptyTree
35
36
import bzrlib.ui.text
36
37
from bzrlib.workingtree import WorkingTree
284
def get_remaining_revisions(output_dir, version, encoding,
285
reuse_history_from=[]):
281
def get_remaining_revisions(output_dir, version, reuse_history_from=[]):
286
282
last_patch = None
288
284
output_exists = os.path.exists(output_dir)
290
286
# We are starting from an existing directory, figure out what
291
287
# the current version is
292
288
branch = Branch.open(output_dir)
293
last_patch, last_encoding = get_last_revision(branch)
294
assert encoding == last_encoding
289
last_patch = get_last_revision(branch)
295
290
if last_patch is None:
296
291
if branch.last_revision() != None:
297
292
raise NotPreviousImport(branch.base)
316
311
map_namespace(ancestor.version))
318
313
source = Branch.open(possible_source)
319
rev_id = revision_id(ancestor, encoding)
314
rev_id = revision_id(ancestor)
320
315
if rev_id in source.revision_history():
321
316
do_branch(source, output_dir, rev_id)
322
317
last_patch = ancestor
360
def import_version(output_dir, version, encoding, fast=False,
355
def import_version(output_dir, version, fast=False,
361
356
verbose=False, dry_run=False, max_count=None,
362
357
reuse_history_from=[], standalone=True):
375
370
>>> bzrlib.ui.ui_factory = bzrlib.ui.text.TextUIFactory(
376
371
... bar_type=bzrlib.progress.DotsProgressBar)
378
>>> import_version('/', version, None, dry_run=True)
373
>>> import_version('/', version, dry_run=True)
379
374
Traceback (most recent call last):
380
375
NotPreviousImport: / is not the location of a previous import.
381
>>> import_version(result_path, version, None, dry_run=True)
376
>>> import_version(result_path, version, dry_run=True)
382
377
Traceback (most recent call last):
383
378
UserError: The version test@example.com/test--test--0.1 does not exist.
384
379
>>> version = pybaz.Version("test@example.com/test--test--0")
385
>>> import_version(result_path, version, None, dry_run=True) #doctest: +ELLIPSIS
380
>>> import_version(result_path, version, dry_run=True) #doctest: +ELLIPSIS
386
381
importing test@example.com/test--test--0 into ...
388
383
revisions: ..........................................
389
384
Dry run, not modifying output_dir
391
>>> import_version(result_path, version, None) #doctest: +ELLIPSIS
386
>>> import_version(result_path, version) #doctest: +ELLIPSIS
392
387
importing test@example.com/test--test--0 into ...
394
389
revisions: .....................................................................
397
>>> import_version(result_path, version, None) #doctest: +ELLIPSIS
392
>>> import_version(result_path, version) #doctest: +ELLIPSIS
398
393
Tree is up-to-date with test@example.com/test--test--0--patch-2
399
394
>>> commit_more_test_revisions()
400
>>> import_version(result_path, version, None) #doctest: +ELLIPSIS
395
>>> import_version(result_path, version) #doctest: +ELLIPSIS
401
396
importing test@example.com/test--test--0 into ...
402
397
revisions: ....................................................
418
412
progress_bar.note('Version %s has no revisions.' % version)
420
414
if len(ancestors) == 0:
421
last_revision, last_encoding = \
422
get_last_revision(Branch.open(output_dir))
415
last_revision = get_last_revision(Branch.open(output_dir))
423
416
progress_bar.note('Tree is up-to-date with %s' % last_revision)
431
424
wt = WorkingTree.open(output_dir)
432
425
except (NotBranchError, NoWorkingTree):
428
old_basis = EmptyTree()
430
old_basis = wt.basis_tree()
435
432
for result in iter_import_version(output_dir, ancestors, tempdir,
436
pb=progress_bar, encoding=encoding, fast=fast,
437
verbose=verbose, dry_run=dry_run, max_count=max_count,
438
standalone=standalone):
434
fast=fast, verbose=verbose, dry_run=dry_run,
435
max_count=max_count, standalone=standalone):
439
436
show_progress(progress_bar, result)
441
438
progress_bar.note('Dry run, not modifying output_dir')
449
446
if wt is not None:
450
447
wt.set_last_revision(wt.branch.last_revision())
451
wt.set_root_id(BAZ_IMPORT_ROOT)
448
merge_inner(wt.branch, wt.basis_tree(), old_basis,
449
ignore_zero=True, this_tree=wt)
482
480
:param arch_revision: The Arch revision to generate an ID for.
484
>>> revision_id(pybaz.Revision("you@example.com/cat--br--0--base-0"), None)
482
>>> revision_id(pybaz.Revision("you@example.com/cat--br--0--base-0"))
485
483
'Arch-1:you@example.com%cat--br--0--base-0'
486
>>> revision_id(pybaz.Revision("you@example.com/cat--br--0--base-0"), 'utf-8')
487
'Arch-1-utf-8:you@example.com%cat--br--0--base-0'
492
encoding = '-' + encoding
493
return "Arch-1%s:%s" % (encoding, str(arch_revision).replace('/', '%'))
485
return "Arch-1:%s" % str(arch_revision).replace('/', '%')
495
487
class NotArchRevision(Exception):
496
488
def __init__(self, revision_id):
506
498
>>> str(arch_revision("Arch-1:jrandom@example.com%test--test--0--base-5"))
507
499
Traceback (most recent call last):
508
500
NotArchRevision: The revision id Arch-1:jrandom@example.com%test--test--0--base-5 does not look like it came from Arch.
509
>>> str(arch_revision("Arch-1:jrandom@example.com%test--test--0--patch-5")[0])
510
'jrandom@example.com/test--test--0--patch-5'
511
>>> str(arch_revision("Arch-1:jrandom@example.com%test--test--0--patch-5")[0])
512
'jrandom@example.com/test--test--0--patch-5'
513
>>> str(arch_revision("Arch-1:jrandom@example.com%test--test--0--patch-5")[1])
515
>>> str(arch_revision("Arch-1-utf-8:jrandom@example.com%test--test--0--patch-5")[1])
501
>>> str(arch_revision("Arch-1:jrandom@example.com%test--test--0--patch-5"))
502
'jrandom@example.com/test--test--0--patch-5'
518
504
if revision_id is None:
520
if revision_id[:7] not in ('Arch-1:', 'Arch-1-'):
506
if revision_id[:7] != 'Arch-1:':
521
507
raise NotArchRevision(revision_id)
524
encoding, arch_name = revision_id[6:].split(':', 1)
525
arch_name = arch_name.replace('%', '/')
529
encoding = encoding[1:]
530
return pybaz.Revision(arch_name), encoding
510
return pybaz.Revision(revision_id[7:].replace('%', '/'))
531
511
except pybaz.errors.NamespaceError, e:
532
512
raise NotArchRevision(revision_id)
552
532
if revision_id is None:
553
533
revision_id = source.last_revision()
554
534
wt = create_checkout(source, to_location, NULL_REVISION)
557
wt.set_last_revision(revision_id)
559
if revision_id not in (NULL_REVISION, None):
560
basis = wt.basis_tree()
563
wt._write_inventory(basis.inventory)
535
wt.set_last_revision(revision_id)
536
wt._write_inventory(wt.basis_tree().inventory)
571
def iter_import_version(output_dir, ancestors, tempdir, pb, encoding,
572
fast=False, verbose=False, dry_run=False,
573
max_count=None, standalone=False):
540
def iter_import_version(output_dir, ancestors, tempdir, pb, fast=False,
541
verbose=False, dry_run=False, max_count=None,
575
log_encoding = 'ascii'
576
if encoding is not None:
577
log_encoding = encoding
579
545
# Uncomment this for testing, it basically just has baz2bzr only update
580
546
# 5 patches at a time
667
633
if missing_ancestor:
668
634
# if we want it to be in revision-history, do that here.
669
target_tree.set_parent_ids(
670
[revision_id(missing_ancestor, encoding)],
671
allow_leftmost_as_ghost=True)
635
target_tree.add_pending_merge(revision_id(missing_ancestor))
672
636
missing_ancestor = None
673
637
for merged_rev in direct_merges:
674
target_tree.add_pending_merge(revision_id(merged_rev,
676
target_tree.set_root_id(BAZ_IMPORT_ROOT)
638
target_tree.add_pending_merge(revision_id(merged_rev))
678
639
target_tree.set_inventory(baz_inv)
679
640
commitobj = Commit(reporter=ImportCommitReporter())
680
641
commitobj.commit(working_tree=target_tree,
681
message=log_message.decode(log_encoding, 'replace'),
682
verbose=False, committer=log_creator, timestamp=timestamp,
683
timezone=0, rev_id=rev_id, revprops={})
642
message=log_message.decode('ascii', 'replace'),
643
verbose=False, committer=log_creator,
644
timestamp=timestamp, timezone=0, rev_id=rev_id,
685
647
target_tree.unlock()
770
732
def baz_import_branch(to_location, from_branch, fast, max_count, verbose,
771
encoding, dry_run, reuse_history_list):
733
dry_run, reuse_history_list):
772
734
to_location = os.path.realpath(str(to_location))
773
735
if from_branch is not None:
779
741
if reuse_history_list is None:
780
742
reuse_history_list = []
781
import_version(to_location, from_branch, encoding, max_count=max_count,
743
import_version(to_location, from_branch,
782
745
reuse_history_from=reuse_history_list)
792
def baz_import(to_root_dir, from_archive, encoding, verbose=False,
793
reuse_history_list=[], prefixes=None):
755
def baz_import(to_root_dir, from_archive, verbose=False, reuse_history_list=[],
794
757
if reuse_history_list is None:
795
758
reuse_history_list = []
796
759
to_root = str(os.path.realpath(to_root_dir))
798
761
os.mkdir(to_root)
799
762
if prefixes is not None:
800
763
prefixes = prefixes.split(':')
801
import_archive(to_root, from_archive, verbose, encoding,
764
import_archive(to_root, from_archive, verbose,
802
765
reuse_history_list, prefixes=prefixes)
805
768
def import_archive(to_root, from_archive, verbose,
806
encoding, reuse_history_from=[], standalone=False,
769
reuse_history_from=[], standalone=False,
808
771
def selected(version):
809
772
if prefixes is None:
835
798
if not os.path.exists(os.path.dirname(target)):
836
799
os.makedirs(os.path.dirname(target))
838
import_version(target, version, encoding,
801
import_version(target, version,
839
802
reuse_history_from=reuse_history_from,
840
803
standalone=standalone)
841
804
except pybaz.errors.ExecProblem,e: