~abentley/bzrtools/bzrtools.dev

« back to all changes in this revision

Viewing changes to baz_import.py

  • Committer: Aaron Bentley
  • Date: 2006-11-21 23:26:35 UTC
  • Revision ID: abentley@panoramicfeedback.com-20061121232635-z2b0g5rv73im3cdc
Add encoding parameter everywhere

Show diffs side-by-side

added added

removed removed

Lines of Context:
281
281
    finally:
282
282
        br_from.unlock()
283
283
 
284
 
def get_remaining_revisions(output_dir, version, reuse_history_from=[]):
 
284
def get_remaining_revisions(output_dir, version, encoding, 
 
285
                            reuse_history_from=[]):
285
286
    last_patch = None
286
287
    old_revno = None
287
288
    output_exists = os.path.exists(output_dir)
314
315
                        map_namespace(ancestor.version))
315
316
                    try:
316
317
                        source = Branch.open(possible_source)
317
 
                        rev_id = revision_id(ancestor)
 
318
                        rev_id = revision_id(ancestor, encoding)
318
319
                        if rev_id in source.revision_history():
319
320
                            do_branch(source, output_dir, rev_id)
320
321
                            last_patch = ancestor
355
356
###        self.
356
357
 
357
358
 
358
 
def import_version(output_dir, version, fast=False,
 
359
def import_version(output_dir, version, encoding, fast=False,
359
360
                   verbose=False, dry_run=False, max_count=None,
360
361
                   reuse_history_from=[], standalone=True):
361
362
    """
373
374
    >>> bzrlib.ui.ui_factory = bzrlib.ui.text.TextUIFactory(
374
375
    ...     bar_type=bzrlib.progress.DotsProgressBar)
375
376
 
376
 
    >>> import_version('/', version, dry_run=True)
 
377
    >>> import_version('/', version, None, dry_run=True)
377
378
    Traceback (most recent call last):
378
379
    NotPreviousImport: / is not the location of a previous import.
379
 
    >>> import_version(result_path, version, dry_run=True)
 
380
    >>> import_version(result_path, version, None, dry_run=True)
380
381
    Traceback (most recent call last):
381
382
    UserError: The version test@example.com/test--test--0.1 does not exist.
382
383
    >>> version = pybaz.Version("test@example.com/test--test--0")
383
 
    >>> import_version(result_path, version, dry_run=True) #doctest: +ELLIPSIS
 
384
    >>> import_version(result_path, version, None, dry_run=True) #doctest: +ELLIPSIS
384
385
    importing test@example.com/test--test--0 into ...
385
386
    ...
386
387
    revisions: ..........................................
387
388
    Dry run, not modifying output_dir
388
389
    Cleaning up
389
 
    >>> import_version(result_path, version) #doctest: +ELLIPSIS
 
390
    >>> import_version(result_path, version, None) #doctest: +ELLIPSIS
390
391
    importing test@example.com/test--test--0 into ...
391
392
    ...
392
393
    revisions: .....................................................................
393
394
    Cleaning up
394
395
    Import complete.
395
 
    >>> import_version(result_path, version) #doctest: +ELLIPSIS
 
396
    >>> import_version(result_path, version, None) #doctest: +ELLIPSIS
396
397
    Tree is up-to-date with test@example.com/test--test--0--patch-2
397
398
    >>> commit_more_test_revisions()
398
 
    >>> import_version(result_path, version) #doctest: +ELLIPSIS
 
399
    >>> import_version(result_path, version, None) #doctest: +ELLIPSIS
399
400
    importing test@example.com/test--test--0 into ...
400
401
    revisions: ....................................................
401
402
    Cleaning up
408
409
    try:
409
410
        try:
410
411
            ancestors, old_revno = get_remaining_revisions(output_dir, version,
 
412
                                                           encoding,
411
413
                                                           reuse_history_from)
412
414
        except NotBranchError, e:
413
415
            raise NotPreviousImport(e.path)
429
431
            wt = None
430
432
        try:
431
433
            for result in iter_import_version(output_dir, ancestors, tempdir,
432
 
                    pb=progress_bar,
433
 
                    fast=fast, verbose=verbose, dry_run=dry_run,
434
 
                    max_count=max_count, standalone=standalone):
 
434
                    pb=progress_bar, encoding=encoding, fast=fast, 
 
435
                    verbose=verbose, dry_run=dry_run, max_count=max_count,
 
436
                    standalone=standalone):
435
437
                show_progress(progress_bar, result)
436
438
            if dry_run:
437
439
                progress_bar.note('Dry run, not modifying output_dir')
469
471
                           % path)
470
472
 
471
473
 
472
 
def revision_id(arch_revision):
 
474
def revision_id(arch_revision, encoding):
473
475
    """
474
476
    Generate a Bzr revision id from an Arch revision id.  'x' in the id
475
477
    designates a revision imported with an experimental algorithm.  A number
477
479
 
478
480
    :param arch_revision: The Arch revision to generate an ID for.
479
481
 
480
 
    >>> revision_id(pybaz.Revision("you@example.com/cat--br--0--base-0"))
 
482
    >>> revision_id(pybaz.Revision("you@example.com/cat--br--0--base-0"), None)
481
483
    'Arch-1:you@example.com%cat--br--0--base-0'
 
484
    >>> revision_id(pybaz.Revision("you@example.com/cat--br--0--base-0"), 'utf-8')
 
485
    'Arch-1-utf-8:you@example.com%cat--br--0--base-0'
482
486
    """
483
 
    return "Arch-1:%s" % str(arch_revision).replace('/', '%')
 
487
    if encoding is None:
 
488
        encoding = ''
 
489
    else:
 
490
        encoding = '-' + encoding
 
491
    return "Arch-1%s:%s" % (encoding, str(arch_revision).replace('/', '%'))
484
492
 
485
493
class NotArchRevision(Exception):
486
494
    def __init__(self, revision_id):
536
544
    return wt
537
545
 
538
546
 
539
 
def iter_import_version(output_dir, ancestors, tempdir, pb, fast=False,
540
 
                        verbose=False, dry_run=False, max_count=None,
541
 
                        standalone=False):
 
547
def iter_import_version(output_dir, ancestors, tempdir, pb, encoding, 
 
548
                        fast=False, verbose=False, dry_run=False,
 
549
                        max_count=None, standalone=False):
542
550
    revdir = None
543
551
 
544
552
    # Uncomment this for testing, it basically just has baz2bzr only update
574
582
 
575
583
    for i in range(len(ancestors)):
576
584
        revision = ancestors[i]
577
 
        rev_id = revision_id(revision)
 
585
        rev_id = revision_id(revision, encoding)
578
586
        direct_merges = []
579
587
        if verbose:
580
588
            version = str(revision.version)
631
639
        try:
632
640
            if missing_ancestor:
633
641
                # if we want it to be in revision-history, do that here.
634
 
                target_tree.set_parent_ids([revision_id(missing_ancestor)],
635
 
                                           allow_leftmost_as_ghost=True)
 
642
                target_tree.set_parent_ids(
 
643
                    [revision_id(missing_ancestor, encoding)],
 
644
                    allow_leftmost_as_ghost=True)
636
645
                missing_ancestor = None
637
646
            for merged_rev in direct_merges:
638
 
                target_tree.add_pending_merge(revision_id(merged_rev))
 
647
                target_tree.add_pending_merge(revision_id(merged_rev, 
 
648
                                                          encoding))
639
649
            target_tree.set_root_id(BAZ_IMPORT_ROOT)
640
650
            target_tree.set_inventory(baz_inv)
641
651
            commitobj = Commit(reporter=ImportCommitReporter())
731
741
 
732
742
 
733
743
def baz_import_branch(to_location, from_branch, fast, max_count, verbose, 
734
 
                      dry_run, reuse_history_list):
 
744
                      encoding, dry_run, reuse_history_list):
735
745
    to_location = os.path.realpath(str(to_location))
736
746
    if from_branch is not None:
737
747
        try:
741
751
            return 1
742
752
    if reuse_history_list is None:
743
753
        reuse_history_list = []
744
 
    import_version(to_location, from_branch, 
745
 
                   max_count=max_count, 
 
754
    import_version(to_location, from_branch, encoding, max_count=max_count, 
746
755
                   reuse_history_from=reuse_history_list)
747
756
 
748
757
 
753
762
 
754
763
 
755
764
 
756
 
def baz_import(to_root_dir, from_archive, verbose=False, reuse_history_list=[],
757
 
               prefixes=None):
 
765
def baz_import(to_root_dir, from_archive, encoding, verbose=False, 
 
766
               reuse_history_list=[], prefixes=None):
758
767
    if reuse_history_list is None:
759
768
        reuse_history_list = []
760
769
    to_root = str(os.path.realpath(to_root_dir))
762
771
        os.mkdir(to_root)
763
772
    if prefixes is not None:
764
773
        prefixes = prefixes.split(':')
765
 
    import_archive(to_root, from_archive, verbose,
 
774
    import_archive(to_root, from_archive, verbose, encoding,
766
775
                   reuse_history_list, prefixes=prefixes)
767
776
 
768
777
 
769
778
def import_archive(to_root, from_archive, verbose,
770
 
                   reuse_history_from=[], standalone=False,
 
779
                   encoding, reuse_history_from=[], standalone=False,
771
780
                   prefixes=None):
772
781
    def selected(version):
773
782
        if prefixes is None:
799
808
            if not os.path.exists(os.path.dirname(target)):
800
809
                os.makedirs(os.path.dirname(target))
801
810
            try:
802
 
                import_version(target, version,
 
811
                import_version(target, version, encoding,
803
812
                               reuse_history_from=reuse_history_from, 
804
813
                               standalone=standalone)
805
814
            except pybaz.errors.ExecProblem,e: