~abentley/bzrtools/bzrtools.dev

« back to all changes in this revision

Viewing changes to upstream_import.py

  • Committer: Aaron Bentley
  • Date: 2011-02-01 23:25:27 UTC
  • mfrom: (749.1.1 2.3)
  • Revision ID: aaron@aaronbentley.com-20110201232527-8yjkmelpj1udx4w7
Merged 2.3 into bzrtools.dev.

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)
 
15
                            file_kind, splitpath)
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_directory(path):
 
120
def top_path(path):
121
121
    """Return the top directory given in a path."""
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
 
122
    components = splitpath(path)
 
123
    if len(components) > 0:
 
124
        return components[0]
 
125
    else:
 
126
        return ''
129
127
 
130
128
 
131
129
def common_directory(names):
132
130
    """Determine a single directory prefix from a list of names"""
133
131
    possible_prefix = None
134
132
    for name in names:
135
 
        name_top = top_directory(name)
 
133
        name_top = top_path(name)
136
134
        if name_top == '':
137
135
            return None
138
136
        if possible_prefix is None:
165
163
            yield member.name
166
164
 
167
165
 
 
166
def should_ignore(relative_path):
 
167
    return top_path(relative_path) == '.bzr'
 
168
 
 
169
 
168
170
def import_tar(tree, tar_input):
169
171
    """Replace the contents of a working directory with tarfile contents.
170
172
    The tarfile may be a gzipped stream.  File ids will be updated.
205
207
            relative_path = relative_path.rstrip('/')
206
208
        if relative_path == '':
207
209
            continue
 
210
        if should_ignore(relative_path):
 
211
            continue
208
212
        add_implied_parents(implied_parents, relative_path)
209
213
        trans_id = tt.trans_id_tree_path(relative_path)
210
214
        added.add(relative_path.rstrip('/'))