~abentley/bzrtools/bzrtools.dev

« back to all changes in this revision

Viewing changes to baz_import.py

  • Committer: Aaron Bentley
  • Date: 2006-06-27 14:36:32 UTC
  • Revision ID: abentley@panoramicfeedback.com-20060627143632-0f4114d7b0a8d7d9
Fix zap for checkouts of branches with no parents

Show diffs side-by-side

added added

removed removed

Lines of Context:
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
34
35
import bzrlib.ui
35
36
import bzrlib.ui.text
36
37
from bzrlib.workingtree import WorkingTree
423
424
            wt = WorkingTree.open(output_dir)
424
425
        except (NotBranchError, NoWorkingTree):
425
426
            wt = None
 
427
        if wt is None:
 
428
            old_basis = EmptyTree()
 
429
        else:
 
430
            old_basis = wt.basis_tree()
426
431
        try:
427
432
            for result in iter_import_version(output_dir, ancestors, tempdir,
428
433
                    pb=progress_bar,
440
445
                wt = None
441
446
            if wt is not None:
442
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)
443
450
                wt.revert([])
444
451
    
445
452
        finally:
721
728
    bzr_inv.sort()
722
729
    return bzr_inv
723
730
 
 
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.  <BZRTOOLS>"""
 
734
    takes_args = ['to_location', 'from_branch?', 'reuse_history*']
 
735
    takes_options = ['verbose', 'max-count']
724
736
 
725
 
def baz_import_branch(to_location, from_branch, fast, max_count, verbose, 
726
 
                      dry_run, reuse_history_list):
727
 
    to_location = os.path.realpath(str(to_location))
728
 
    if from_branch is not None:
729
 
        try:
730
 
            from_branch = pybaz.Version(from_branch)
731
 
        except pybaz.errors.NamespaceError:
732
 
            print "%s is not a valid Arch branch." % from_branch
733
 
            return 1
734
 
    if reuse_history_list is None:
735
 
        reuse_history_list = []
736
 
    import_version(to_location, from_branch, 
737
 
                   max_count=max_count, 
738
 
                   reuse_history_from=reuse_history_list)
 
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:
 
741
            try:
 
742
                from_branch = pybaz.Version(from_branch)
 
743
            except pybaz.errors.NamespaceError:
 
744
                print "%s is not a valid Arch branch." % from_branch
 
745
                return 1
 
746
        if reuse_history_list is None:
 
747
            reuse_history_list = []
 
748
        import_version(to_location, from_branch, 
 
749
                       max_count=max_count, 
 
750
                       reuse_history_from=reuse_history_list)
739
751
 
740
752
 
741
753
class NotInABranch(Exception):
744
756
        self.path = path
745
757
 
746
758
 
747
 
 
748
 
def baz_import(to_root_dir, from_archive, verbose=False, reuse_history_list=[],
749
 
               prefixes=None):
750
 
    if reuse_history_list is None:
751
 
        reuse_history_list = []
752
 
    to_root = str(os.path.realpath(to_root_dir))
753
 
    if not os.path.exists(to_root):
754
 
        os.mkdir(to_root)
755
 
    if prefixes is not None:
756
 
        prefixes = prefixes.split(':')
757
 
    import_archive(to_root, from_archive, verbose,
758
 
                   reuse_history_list, prefixes=prefixes)
 
759
class cmd_baz_import(Command):
 
760
    """Import an Arch or Baz archive into a bzr repository.  <BZRTOOLS>
 
761
 
 
762
    This command should be used on local archives (or mirrors) only.  It is
 
763
    quite slow on remote archives.
 
764
    
 
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.
 
770
 
 
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
 
776
    """
 
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")]
 
780
 
 
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):
 
787
            os.mkdir(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)
759
792
 
760
793
 
761
794
def import_archive(to_root, from_archive, verbose,