/brz/remove-bazaar

To get this branch, use:
bzr branch http://gegoxaren.bato24.eu/bzr/brz/remove-bazaar

« back to all changes in this revision

Viewing changes to bzrlib/clean_tree.py

Merge 2.0 into 2.1 resolving conflicts

Show diffs side-by-side

added added

removed removed

Lines of Context:
15
15
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
16
16
 
17
17
 
 
18
import errno
18
19
import os
19
20
import shutil
 
21
import sys
20
22
 
21
 
from bzrlib.osutils import isdir
 
23
from bzrlib import bzrdir, errors
 
24
from bzrlib.osutils import has_symlinks, isdir
22
25
from bzrlib.trace import note
23
26
from bzrlib.workingtree import WorkingTree
24
27
 
51
54
    try:
52
55
        deletables = list(iter_deletables(tree, unknown=unknown,
53
56
            ignored=ignored, detritus=detritus))
 
57
        deletables = _filter_out_nested_bzrdirs(deletables)
54
58
        if len(deletables) == 0:
55
59
            note('Nothing to delete.')
56
60
            return 0
57
61
        if not no_prompt:
58
62
            for path, subp in deletables:
 
63
                # FIXME using print is very bad idea
 
64
                # clean_tree should accept to_file argument to write the output
59
65
                print subp
60
66
            val = raw_input('Are you sure you wish to delete these [y/N]?')
61
67
            if val.lower() not in ('y', 'yes'):
66
72
        tree.unlock()
67
73
 
68
74
 
 
75
def _filter_out_nested_bzrdirs(deletables):
 
76
    result = []
 
77
    for path, subp in deletables:
 
78
        # bzr won't recurse into unknowns/ignored directories by default
 
79
        # so we don't pay a penalty for checking subdirs of path for nested
 
80
        # bzrdir.
 
81
        # That said we won't detect the branch in the subdir of non-branch
 
82
        # directory and therefore delete it. (worth to FIXME?)
 
83
        if isdir(path):
 
84
            try:
 
85
                bzrdir.BzrDir.open(path)
 
86
            except errors.NotBranchError:
 
87
                result.append((path,subp))
 
88
            else:
 
89
                # TODO may be we need to notify user about skipped directories?
 
90
                pass
 
91
        else:
 
92
            result.append((path,subp))
 
93
    return result
 
94
 
 
95
 
69
96
def delete_items(deletables, dry_run=False):
70
97
    """Delete files in the deletables iterable"""
71
98
    has_deleted = False