~abentley/bzrtools/bzrtools.dev

« back to all changes in this revision

Viewing changes to upstream_import.py

  • Committer: Aaron Bentley
  • Date: 2006-05-18 15:48:22 UTC
  • Revision ID: abentley@panoramicfeedback.com-20060518154822-7faf0c05951fb95b
Got import working decently

Show diffs side-by-side

added added

removed removed

Lines of Context:
8
8
 
9
9
from bzrlib.bzrdir import BzrDir
10
10
from bzrlib.delta import compare_trees
11
 
from bzrlib.errors import NoSuchFile, BzrCommandError
12
 
from bzrlib.osutils import pathjoin, isdir
 
11
from bzrlib.errors import NoSuchFile, BzrCommandError, NotBranchError
 
12
from bzrlib.osutils import pathjoin, isdir, file_iterator
13
13
from bzrlib.tests import TestCaseInTempDir
14
14
from bzrlib.transform import TreeTransform
15
15
from bzrlib.workingtree import WorkingTree
61
61
        added.append(relative_path)
62
62
        path = tree.abspath(relative_path)
63
63
        if member.isreg():
64
 
            tt.create_file([tar_file.extractfile(member).read()], trans_id)
 
64
            tt.create_file(file_iterator(tar_file.extractfile(member)), 
 
65
                           trans_id)
65
66
        elif member.isdir():
66
67
            if isdir(path):
67
68
                tt.cancel_deletion(trans_id)
82
83
            tree.add(path)
83
84
 
84
85
 
85
 
def do_import(source):
 
86
def do_import(source, tree_directory=None):
86
87
    """Implementation of import command.  Intended for UI only"""
87
 
    tree = WorkingTree.open_containing('.')[0]
 
88
    if tree_directory is not None:
 
89
        try:
 
90
            tree = WorkingTree.open(tree_directory)
 
91
        except NotBranchError:
 
92
            if not os.path.exists(tree_directory):
 
93
                os.mkdir(tree_directory)
 
94
            branch = BzrDir.create_branch_convenience(tree_directory)
 
95
            tree = branch.bzrdir.open_workingtree()
 
96
    else:
 
97
        tree = WorkingTree.open_containing('.')[0]
88
98
    tree.lock_write()
89
99
    try:
90
100
        if compare_trees(tree, tree.basis_tree()).has_changed():