286
290
# We are starting from an existing directory, figure out what
287
291
# the current version is
288
292
branch = Branch.open(output_dir)
289
last_patch = get_last_revision(branch)
293
last_patch, last_encoding = get_last_revision(branch)
294
assert encoding == last_encoding
290
295
if last_patch is None:
291
296
if branch.last_revision() != None:
292
297
raise NotPreviousImport(branch.base)
311
316
map_namespace(ancestor.version))
313
318
source = Branch.open(possible_source)
314
rev_id = revision_id(ancestor)
319
rev_id = revision_id(ancestor, encoding)
315
320
if rev_id in source.revision_history():
316
321
do_branch(source, output_dir, rev_id)
317
322
last_patch = ancestor
355
def import_version(output_dir, version, fast=False,
360
def import_version(output_dir, version, encoding, fast=False,
356
361
verbose=False, dry_run=False, max_count=None,
357
362
reuse_history_from=[], standalone=True):
370
375
>>> bzrlib.ui.ui_factory = bzrlib.ui.text.TextUIFactory(
371
376
... bar_type=bzrlib.progress.DotsProgressBar)
373
>>> import_version('/', version, dry_run=True)
378
>>> import_version('/', version, None, dry_run=True)
374
379
Traceback (most recent call last):
375
380
NotPreviousImport: / is not the location of a previous import.
376
>>> import_version(result_path, version, dry_run=True)
381
>>> import_version(result_path, version, None, dry_run=True)
377
382
Traceback (most recent call last):
378
383
UserError: The version test@example.com/test--test--0.1 does not exist.
379
384
>>> version = pybaz.Version("test@example.com/test--test--0")
380
>>> import_version(result_path, version, dry_run=True) #doctest: +ELLIPSIS
385
>>> import_version(result_path, version, None, dry_run=True) #doctest: +ELLIPSIS
381
386
importing test@example.com/test--test--0 into ...
383
388
revisions: ..........................................
384
389
Dry run, not modifying output_dir
386
>>> import_version(result_path, version) #doctest: +ELLIPSIS
391
>>> import_version(result_path, version, None) #doctest: +ELLIPSIS
387
392
importing test@example.com/test--test--0 into ...
389
394
revisions: .....................................................................
392
>>> import_version(result_path, version) #doctest: +ELLIPSIS
397
>>> import_version(result_path, version, None) #doctest: +ELLIPSIS
393
398
Tree is up-to-date with test@example.com/test--test--0--patch-2
394
399
>>> commit_more_test_revisions()
395
>>> import_version(result_path, version) #doctest: +ELLIPSIS
400
>>> import_version(result_path, version, None) #doctest: +ELLIPSIS
396
401
importing test@example.com/test--test--0 into ...
397
402
revisions: ....................................................
424
431
wt = WorkingTree.open(output_dir)
425
432
except (NotBranchError, NoWorkingTree):
428
old_basis = EmptyTree()
430
old_basis = wt.basis_tree()
432
435
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
pb=progress_bar, encoding=encoding, fast=fast,
437
verbose=verbose, dry_run=dry_run, max_count=max_count,
438
standalone=standalone):
436
439
show_progress(progress_bar, result)
438
441
progress_bar.note('Dry run, not modifying output_dir')
480
482
:param arch_revision: The Arch revision to generate an ID for.
482
>>> revision_id(pybaz.Revision("you@example.com/cat--br--0--base-0"))
484
>>> revision_id(pybaz.Revision("you@example.com/cat--br--0--base-0"), None)
483
485
'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'
485
return "Arch-1:%s" % str(arch_revision).replace('/', '%')
492
encoding = '-' + encoding
493
return "Arch-1%s:%s" % (encoding, str(arch_revision).replace('/', '%'))
487
495
class NotArchRevision(Exception):
488
496
def __init__(self, revision_id):
498
506
>>> str(arch_revision("Arch-1:jrandom@example.com%test--test--0--base-5"))
499
507
Traceback (most recent call last):
500
508
NotArchRevision: The revision id Arch-1:jrandom@example.com%test--test--0--base-5 does not look like it came from Arch.
501
>>> str(arch_revision("Arch-1:jrandom@example.com%test--test--0--patch-5"))
502
'jrandom@example.com/test--test--0--patch-5'
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])
504
518
if revision_id is None:
506
if revision_id[:7] != 'Arch-1:':
520
if revision_id[:7] not in ('Arch-1:', 'Arch-1-'):
507
521
raise NotArchRevision(revision_id)
510
return pybaz.Revision(revision_id[7:].replace('%', '/'))
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
511
531
except pybaz.errors.NamespaceError, e:
512
532
raise NotArchRevision(revision_id)
532
552
if revision_id is None:
533
553
revision_id = source.last_revision()
534
554
wt = create_checkout(source, to_location, NULL_REVISION)
535
wt.set_last_revision(revision_id)
536
wt._write_inventory(wt.basis_tree().inventory)
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)
540
def iter_import_version(output_dir, ancestors, tempdir, pb, fast=False,
541
verbose=False, dry_run=False, max_count=None,
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):
575
log_encoding = 'ascii'
576
if encoding is not None:
577
log_encoding = encoding
545
579
# Uncomment this for testing, it basically just has baz2bzr only update
546
580
# 5 patches at a time
633
667
if missing_ancestor:
634
668
# if we want it to be in revision-history, do that here.
635
target_tree.add_pending_merge(revision_id(missing_ancestor))
669
target_tree.set_parent_ids(
670
[revision_id(missing_ancestor, encoding)],
671
allow_leftmost_as_ghost=True)
636
672
missing_ancestor = None
637
673
for merged_rev in direct_merges:
638
target_tree.add_pending_merge(revision_id(merged_rev))
674
target_tree.add_pending_merge(revision_id(merged_rev,
676
target_tree.set_root_id(BAZ_IMPORT_ROOT)
639
678
target_tree.set_inventory(baz_inv)
640
679
commitobj = Commit(reporter=ImportCommitReporter())
641
680
commitobj.commit(working_tree=target_tree,
642
message=log_message.decode('ascii', 'replace'),
643
verbose=False, committer=log_creator,
644
timestamp=timestamp, timezone=0, rev_id=rev_id,
681
message=log_message.decode(log_encoding, 'replace'),
682
verbose=False, committer=log_creator, timestamp=timestamp,
683
timezone=0, rev_id=rev_id, revprops={})
647
685
target_tree.unlock()
731
_global_option('max-count', type = int)
732
class cmd_baz_import_branch(Command):
733
"""Import an Arch or Baz branch into a bzr branch."""
734
takes_args = ['to_location', 'from_branch?', 'reuse_history*']
735
takes_options = ['verbose', 'max-count']
737
def run(self, to_location, from_branch=None, fast=False, max_count=None,
738
verbose=False, dry_run=False, reuse_history_list=[]):
739
to_location = os.path.realpath(str(to_location))
740
if from_branch is not None:
742
from_branch = pybaz.Version(from_branch)
743
except pybaz.errors.NamespaceError:
744
print "%s is not a valid Arch branch." % from_branch
746
if reuse_history_list is None:
747
reuse_history_list = []
748
import_version(to_location, from_branch,
750
reuse_history_from=reuse_history_list)
770
def baz_import_branch(to_location, from_branch, fast, max_count, verbose,
771
encoding, dry_run, reuse_history_list):
772
to_location = os.path.realpath(str(to_location))
773
if from_branch is not None:
775
from_branch = pybaz.Version(from_branch)
776
except pybaz.errors.NamespaceError:
777
print "%s is not a valid Arch branch." % from_branch
779
if reuse_history_list is None:
780
reuse_history_list = []
781
import_version(to_location, from_branch, encoding, max_count=max_count,
782
reuse_history_from=reuse_history_list)
753
785
class NotInABranch(Exception):
759
class cmd_baz_import(Command):
760
"""Import an Arch or Baz archive into a bzr repository.
762
This command should be used on local archives (or mirrors) only. It is
763
quite slow on remote archives.
765
reuse_history allows you to specify any previous imports you
766
have done of different archives, which this archive has branches
767
tagged from. This will dramatically reduce the time to convert
768
the archive as it will not have to convert the history already
769
converted in that other branch.
771
If you specify prefixes, only branches whose names start with that prefix
772
will be imported. Skipped branches will be listed, so you can import any
773
branches you missed by accident. Here's an example of doing a partial
774
import from thelove@canonical.com:
775
bzr baz-import thelove thelove@canonical.com --prefixes dists:talloc-except
777
takes_args = ['to_root_dir', 'from_archive', 'reuse_history*']
778
takes_options = ['verbose', Option('prefixes', type=str,
779
help="Prefixes of branches to import, colon-separated")]
781
def run(self, to_root_dir, from_archive, verbose=False,
782
reuse_history_list=[], prefixes=None):
783
if reuse_history_list is None:
784
reuse_history_list = []
785
to_root = str(os.path.realpath(to_root_dir))
786
if not os.path.exists(to_root):
788
if prefixes is not None:
789
prefixes = prefixes.split(':')
790
import_archive(to_root, from_archive, verbose,
791
reuse_history_list, prefixes=prefixes)
792
def baz_import(to_root_dir, from_archive, encoding, verbose=False,
793
reuse_history_list=[], prefixes=None):
794
if reuse_history_list is None:
795
reuse_history_list = []
796
to_root = str(os.path.realpath(to_root_dir))
797
if not os.path.exists(to_root):
799
if prefixes is not None:
800
prefixes = prefixes.split(':')
801
import_archive(to_root, from_archive, verbose, encoding,
802
reuse_history_list, prefixes=prefixes)
794
805
def import_archive(to_root, from_archive, verbose,
795
reuse_history_from=[], standalone=False,
806
encoding, reuse_history_from=[], standalone=False,
797
808
def selected(version):
798
809
if prefixes is None:
824
835
if not os.path.exists(os.path.dirname(target)):
825
836
os.makedirs(os.path.dirname(target))
827
import_version(target, version,
838
import_version(target, version, encoding,
828
839
reuse_history_from=reuse_history_from,
829
840
standalone=standalone)
830
841
except pybaz.errors.ExecProblem,e: