~abentley/bzrtools/bzrtools.dev

« back to all changes in this revision

Viewing changes to baz_import.py

  • Committer: Aaron Bentley
  • Date: 2006-10-25 13:35:12 UTC
  • Revision ID: abentley@panoramicfeedback.com-20061025133512-09660b1b3104b054
Update version number to 0.13.0

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, encoding, 
285
 
                            reuse_history_from=[]):
 
284
def get_remaining_revisions(output_dir, version, reuse_history_from=[]):
286
285
    last_patch = None
287
286
    old_revno = None
288
287
    output_exists = os.path.exists(output_dir)
290
289
        # We are starting from an existing directory, figure out what
291
290
        # the current version is
292
291
        branch = Branch.open(output_dir)
293
 
        last_patch, last_encoding = get_last_revision(branch)
294
 
        assert encoding == last_encoding
 
292
        last_patch = get_last_revision(branch)
295
293
        if last_patch is None:
296
294
            if branch.last_revision() != None:
297
295
                raise NotPreviousImport(branch.base)
316
314
                        map_namespace(ancestor.version))
317
315
                    try:
318
316
                        source = Branch.open(possible_source)
319
 
                        rev_id = revision_id(ancestor, encoding)
 
317
                        rev_id = revision_id(ancestor)
320
318
                        if rev_id in source.revision_history():
321
319
                            do_branch(source, output_dir, rev_id)
322
320
                            last_patch = ancestor
357
355
###        self.
358
356
 
359
357
 
360
 
def import_version(output_dir, version, encoding, fast=False,
 
358
def import_version(output_dir, version, fast=False,
361
359
                   verbose=False, dry_run=False, max_count=None,
362
360
                   reuse_history_from=[], standalone=True):
363
361
    """
375
373
    >>> bzrlib.ui.ui_factory = bzrlib.ui.text.TextUIFactory(
376
374
    ...     bar_type=bzrlib.progress.DotsProgressBar)
377
375
 
378
 
    >>> import_version('/', version, None, dry_run=True)
 
376
    >>> import_version('/', version, dry_run=True)
379
377
    Traceback (most recent call last):
380
378
    NotPreviousImport: / is not the location of a previous import.
381
 
    >>> import_version(result_path, version, None, dry_run=True)
 
379
    >>> import_version(result_path, version, dry_run=True)
382
380
    Traceback (most recent call last):
383
381
    UserError: The version test@example.com/test--test--0.1 does not exist.
384
382
    >>> version = pybaz.Version("test@example.com/test--test--0")
385
 
    >>> import_version(result_path, version, None, dry_run=True) #doctest: +ELLIPSIS
 
383
    >>> import_version(result_path, version, dry_run=True) #doctest: +ELLIPSIS
386
384
    importing test@example.com/test--test--0 into ...
387
385
    ...
388
386
    revisions: ..........................................
389
387
    Dry run, not modifying output_dir
390
388
    Cleaning up
391
 
    >>> import_version(result_path, version, None) #doctest: +ELLIPSIS
 
389
    >>> import_version(result_path, version) #doctest: +ELLIPSIS
392
390
    importing test@example.com/test--test--0 into ...
393
391
    ...
394
392
    revisions: .....................................................................
395
393
    Cleaning up
396
394
    Import complete.
397
 
    >>> import_version(result_path, version, None) #doctest: +ELLIPSIS
 
395
    >>> import_version(result_path, version) #doctest: +ELLIPSIS
398
396
    Tree is up-to-date with test@example.com/test--test--0--patch-2
399
397
    >>> commit_more_test_revisions()
400
 
    >>> import_version(result_path, version, None) #doctest: +ELLIPSIS
 
398
    >>> import_version(result_path, version) #doctest: +ELLIPSIS
401
399
    importing test@example.com/test--test--0 into ...
402
400
    revisions: ....................................................
403
401
    Cleaning up
410
408
    try:
411
409
        try:
412
410
            ancestors, old_revno = get_remaining_revisions(output_dir, version,
413
 
                                                           encoding,
414
411
                                                           reuse_history_from)
415
412
        except NotBranchError, e:
416
413
            raise NotPreviousImport(e.path)
418
415
            progress_bar.note('Version %s has no revisions.' % version)
419
416
            return
420
417
        if len(ancestors) == 0:
421
 
            last_revision, last_encoding = \
422
 
                get_last_revision(Branch.open(output_dir))
 
418
            last_revision = get_last_revision(Branch.open(output_dir))
423
419
            progress_bar.note('Tree is up-to-date with %s' % last_revision)
424
420
            return
425
421
 
433
429
            wt = None
434
430
        try:
435
431
            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):
 
432
                    pb=progress_bar,
 
433
                    fast=fast, verbose=verbose, dry_run=dry_run,
 
434
                    max_count=max_count, standalone=standalone):
439
435
                show_progress(progress_bar, result)
440
436
            if dry_run:
441
437
                progress_bar.note('Dry run, not modifying output_dir')
473
469
                           % path)
474
470
 
475
471
 
476
 
def revision_id(arch_revision, encoding):
 
472
def revision_id(arch_revision):
477
473
    """
478
474
    Generate a Bzr revision id from an Arch revision id.  'x' in the id
479
475
    designates a revision imported with an experimental algorithm.  A number
481
477
 
482
478
    :param arch_revision: The Arch revision to generate an ID for.
483
479
 
484
 
    >>> revision_id(pybaz.Revision("you@example.com/cat--br--0--base-0"), None)
 
480
    >>> revision_id(pybaz.Revision("you@example.com/cat--br--0--base-0"))
485
481
    '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'
488
482
    """
489
 
    if encoding is None:
490
 
        encoding = ''
491
 
    else:
492
 
        encoding = '-' + encoding
493
 
    return "Arch-1%s:%s" % (encoding, str(arch_revision).replace('/', '%'))
 
483
    return "Arch-1:%s" % str(arch_revision).replace('/', '%')
494
484
 
495
485
class NotArchRevision(Exception):
496
486
    def __init__(self, revision_id):
506
496
    >>> str(arch_revision("Arch-1:jrandom@example.com%test--test--0--base-5"))
507
497
    Traceback (most recent call last):
508
498
    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])
514
 
    'None'
515
 
    >>> str(arch_revision("Arch-1-utf-8:jrandom@example.com%test--test--0--patch-5")[1])
516
 
    'utf-8'
 
499
    >>> str(arch_revision("Arch-1:jrandom@example.com%test--test--0--patch-5"))
 
500
    'jrandom@example.com/test--test--0--patch-5'
517
501
    """
518
502
    if revision_id is None:
519
 
        return None, None
520
 
    if revision_id[:7] not in ('Arch-1:', 'Arch-1-'):
 
503
        return None
 
504
    if revision_id[:7] != 'Arch-1:':
521
505
        raise NotArchRevision(revision_id)
522
506
    else:
523
507
        try:
524
 
            encoding, arch_name = revision_id[6:].split(':', 1)
525
 
            arch_name = arch_name.replace('%', '/')
526
 
            if encoding == '':
527
 
                encoding = None
528
 
            else:
529
 
                encoding = encoding[1:]
530
 
            return pybaz.Revision(arch_name), encoding
 
508
            return pybaz.Revision(revision_id[7:].replace('%', '/'))
531
509
        except pybaz.errors.NamespaceError, e:
532
510
            raise NotArchRevision(revision_id)
533
511
 
558
536
    return wt
559
537
 
560
538
 
561
 
def iter_import_version(output_dir, ancestors, tempdir, pb, encoding, 
562
 
                        fast=False, verbose=False, dry_run=False,
563
 
                        max_count=None, standalone=False):
 
539
def iter_import_version(output_dir, ancestors, tempdir, pb, fast=False,
 
540
                        verbose=False, dry_run=False, max_count=None,
 
541
                        standalone=False):
564
542
    revdir = None
565
 
    log_encoding = 'ascii'
566
 
    if encoding is not None:
567
 
        log_encoding = encoding
568
543
 
569
544
    # Uncomment this for testing, it basically just has baz2bzr only update
570
545
    # 5 patches at a time
599
574
 
600
575
    for i in range(len(ancestors)):
601
576
        revision = ancestors[i]
602
 
        rev_id = revision_id(revision, encoding)
 
577
        rev_id = revision_id(revision)
603
578
        direct_merges = []
604
579
        if verbose:
605
580
            version = str(revision.version)
656
631
        try:
657
632
            if missing_ancestor:
658
633
                # if we want it to be in revision-history, do that here.
659
 
                target_tree.set_parent_ids(
660
 
                    [revision_id(missing_ancestor, encoding)],
661
 
                    allow_leftmost_as_ghost=True)
 
634
                target_tree.set_parent_ids([revision_id(missing_ancestor)],
 
635
                                           allow_leftmost_as_ghost=True)
662
636
                missing_ancestor = None
663
637
            for merged_rev in direct_merges:
664
 
                target_tree.add_pending_merge(revision_id(merged_rev, 
665
 
                                                          encoding))
 
638
                target_tree.add_pending_merge(revision_id(merged_rev))
666
639
            target_tree.set_root_id(BAZ_IMPORT_ROOT)
667
640
            target_tree.set_inventory(baz_inv)
668
641
            commitobj = Commit(reporter=ImportCommitReporter())
669
642
            commitobj.commit(working_tree=target_tree,
670
 
                message=log_message.decode(log_encoding, 'replace'),
671
 
                verbose=False, committer=log_creator, timestamp=timestamp,
672
 
                timezone=0, rev_id=rev_id, revprops={})
 
643
                             message=log_message.decode('ascii', 'replace'), 
 
644
                             verbose=False, committer=log_creator,
 
645
                             timestamp=timestamp, timezone=0, rev_id=rev_id,
 
646
                             revprops={})
673
647
        finally:
674
648
            target_tree.unlock()
675
649
            branch.unlock()
757
731
 
758
732
 
759
733
def baz_import_branch(to_location, from_branch, fast, max_count, verbose, 
760
 
                      encoding, dry_run, reuse_history_list):
 
734
                      dry_run, reuse_history_list):
761
735
    to_location = os.path.realpath(str(to_location))
762
736
    if from_branch is not None:
763
737
        try:
767
741
            return 1
768
742
    if reuse_history_list is None:
769
743
        reuse_history_list = []
770
 
    import_version(to_location, from_branch, encoding, max_count=max_count, 
 
744
    import_version(to_location, from_branch, 
 
745
                   max_count=max_count, 
771
746
                   reuse_history_from=reuse_history_list)
772
747
 
773
748
 
778
753
 
779
754
 
780
755
 
781
 
def baz_import(to_root_dir, from_archive, encoding, verbose=False, 
782
 
               reuse_history_list=[], prefixes=None):
 
756
def baz_import(to_root_dir, from_archive, verbose=False, reuse_history_list=[],
 
757
               prefixes=None):
783
758
    if reuse_history_list is None:
784
759
        reuse_history_list = []
785
760
    to_root = str(os.path.realpath(to_root_dir))
787
762
        os.mkdir(to_root)
788
763
    if prefixes is not None:
789
764
        prefixes = prefixes.split(':')
790
 
    import_archive(to_root, from_archive, verbose, encoding,
 
765
    import_archive(to_root, from_archive, verbose,
791
766
                   reuse_history_list, prefixes=prefixes)
792
767
 
793
768
 
794
769
def import_archive(to_root, from_archive, verbose,
795
 
                   encoding, reuse_history_from=[], standalone=False,
 
770
                   reuse_history_from=[], standalone=False,
796
771
                   prefixes=None):
797
772
    def selected(version):
798
773
        if prefixes is None:
824
799
            if not os.path.exists(os.path.dirname(target)):
825
800
                os.makedirs(os.path.dirname(target))
826
801
            try:
827
 
                import_version(target, version, encoding,
 
802
                import_version(target, version,
828
803
                               reuse_history_from=reuse_history_from, 
829
804
                               standalone=standalone)
830
805
            except pybaz.errors.ExecProblem,e: