~garyvdm/bzr/lsprof-threads

« back to all changes in this revision

Viewing changes to bzrlib/clean_tree.py

  • Committer: Canonical.com Patch Queue Manager
  • Date: 2010-05-05 14:44:53 UTC
  • mfrom: (5195.4.7 clean-tree-bzrdir)
  • Revision ID: pqm@pqm.ubuntu.com-20100505144453-4ewd3ms50q5m9tgw
(garyvdm for bialix) bzr clean-tree should not delete nested bzrdirs.

Show diffs side-by-side

added added

removed removed

Lines of Context:
18
18
import os
19
19
import shutil
20
20
 
 
21
from bzrlib import bzrdir, errors
21
22
from bzrlib.osutils import isdir
22
23
from bzrlib.trace import note
23
24
from bzrlib.workingtree import WorkingTree
51
52
    try:
52
53
        deletables = list(iter_deletables(tree, unknown=unknown,
53
54
            ignored=ignored, detritus=detritus))
 
55
        deletables = _filter_out_nested_bzrdirs(deletables)
54
56
        if len(deletables) == 0:
55
57
            note('Nothing to delete.')
56
58
            return 0
57
59
        if not no_prompt:
58
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
59
63
                print subp
60
64
            val = raw_input('Are you sure you wish to delete these [y/N]?')
61
65
            if val.lower() not in ('y', 'yes'):
66
70
        tree.unlock()
67
71
 
68
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
 
69
94
def delete_items(deletables, dry_run=False):
70
95
    """Delete files in the deletables iterable"""
71
96
    has_deleted = False