~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/clean_tree.py

  • Committer: Aaron Bentley
  • Date: 2010-05-10 11:34:20 UTC
  • mfrom: (5218 +trunk)
  • mto: This revision was merged to the branch mainline in revision 5221.
  • Revision ID: aaron@aaronbentley.com-20100510113420-toh2d5yioobb5uq1
Merged bzr.dev into transform-commit-full.

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