~abentley/bzrtools/bzrtools.dev

« back to all changes in this revision

Viewing changes to upstream_import.py

  • Committer: Benoît Pierre
  • Date: 2008-11-16 17:50:52 UTC
  • mto: This revision was merged to the branch mainline in revision 683.
  • Revision ID: benoit.pierre@gmail.com-20081116175052-8ldrpprvpfq3wscm
Check if STDOUT is a TTY in has_ansi_colors: return False if not.

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: