~abentley/bzrtools/bzrtools.dev

« back to all changes in this revision

Viewing changes to upstream_import.py

  • Committer: Aaron Bentley
  • Date: 2007-12-22 02:01:03 UTC
  • Revision ID: aaron.bentley@utoronto.ca-20071222020103-ggjszok7n974e1l2
Update branches, multi-pull to new APIs, create trees

Show diffs side-by-side

added added

removed removed

Lines of Context:
12
12
from bzrlib.bzrdir import BzrDir
13
13
from bzrlib.errors import NoSuchFile, BzrCommandError, NotBranchError
14
14
from bzrlib.osutils import (pathjoin, isdir, file_iterator, basename,
15
 
                            file_kind, splitpath)
 
15
                            file_kind)
16
16
from bzrlib.trace import warning
17
17
from bzrlib.transform import TreeTransform, resolve_conflicts, cook_conflicts
18
18
from bzrlib.workingtree import WorkingTree
117
117
            return False
118
118
 
119
119
 
120
 
def top_path(path):
 
120
def top_directory(path):
121
121
    """Return the top directory given in a path."""
122
 
    components = splitpath(path)
123
 
    if len(components) > 0:
124
 
        return components[0]
125
 
    else:
126
 
        return ''
 
122
    dirname = os.path.dirname(path)
 
123
    last_dirname = dirname
 
124
    while True:
 
125
        dirname = os.path.dirname(dirname)
 
126
        if dirname == '' or dirname == last_dirname:
 
127
            return last_dirname
 
128
        last_dirname = dirname
127
129
 
128
130
 
129
131
def common_directory(names):
130
132
    """Determine a single directory prefix from a list of names"""
131
133
    possible_prefix = None
132
134
    for name in names:
133
 
        name_top = top_path(name)
 
135
        name_top = top_directory(name)
134
136
        if name_top == '':
135
137
            return None
136
138
        if possible_prefix is None:
163
165
            yield member.name
164
166
 
165
167
 
166
 
def should_ignore(relative_path):
167
 
    return top_path(relative_path) == '.bzr'
168
 
 
169
 
 
170
168
def import_tar(tree, tar_input):
171
169
    """Replace the contents of a working directory with tarfile contents.
172
170
    The tarfile may be a gzipped stream.  File ids will be updated.
207
205
            relative_path = relative_path.rstrip('/')
208
206
        if relative_path == '':
209
207
            continue
210
 
        if should_ignore(relative_path):
211
 
            continue
212
208
        add_implied_parents(implied_parents, relative_path)
213
209
        trans_id = tt.trans_id_tree_path(relative_path)
214
210
        added.add(relative_path.rstrip('/'))