~abentley/bzrtools/bzrtools.dev

« back to all changes in this revision

Viewing changes to upstream_import.py

  • Committer: Aaron Bentley
  • Date: 2009-04-10 21:09:41 UTC
  • Revision ID: aaron@aaronbentley.com-20090410210941-xaysnjs7kum6v7tv
Fix import with Python 2.6

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: