/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 breezy/clean_tree.py

  • Committer: Breezy landing bot
  • Author(s): Colin Watson
  • Date: 2020-11-16 21:47:08 UTC
  • mfrom: (7521.1.1 remove-lp-workaround)
  • Revision ID: breezy.the.bot@gmail.com-20201116214708-jos209mgxi41oy15
Remove breezy.git workaround for bazaar.launchpad.net.

Merged from https://code.launchpad.net/~cjwatson/brz/remove-lp-workaround/+merge/393710

Show diffs side-by-side

added added

removed removed

Lines of Context:
14
14
# along with this program; if not, write to the Free Software
15
15
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
16
16
 
17
 
from __future__ import absolute_import
18
 
 
19
17
import errno
20
18
import os
21
19
import shutil
22
20
 
23
 
from bzrlib import (
 
21
from . import (
24
22
    controldir,
25
23
    errors,
26
24
    ui,
27
25
    )
28
 
from bzrlib.osutils import isdir
29
 
from bzrlib.trace import note
30
 
from bzrlib.workingtree import WorkingTree
31
 
from bzrlib.i18n import gettext
 
26
from .osutils import isdir
 
27
from .trace import note
 
28
from .workingtree import WorkingTree
 
29
from .i18n import gettext
 
30
 
32
31
 
33
32
def is_detritus(subp):
34
33
    """Return True if the supplied path is detritus, False otherwise"""
54
53
               dry_run=False, no_prompt=False):
55
54
    """Remove files in the specified classes from the tree"""
56
55
    tree = WorkingTree.open_containing(directory)[0]
57
 
    tree.lock_read()
58
 
    try:
 
56
    with tree.lock_read():
59
57
        deletables = list(iter_deletables(tree, unknown=unknown,
60
 
            ignored=ignored, detritus=detritus))
61
 
        deletables = _filter_out_nested_bzrdirs(deletables)
 
58
                                          ignored=ignored, detritus=detritus))
 
59
        deletables = _filter_out_nested_controldirs(deletables)
62
60
        if len(deletables) == 0:
63
61
            note(gettext('Nothing to delete.'))
64
62
            return 0
70
68
                ui.ui_factory.note(gettext('Canceled'))
71
69
                return 0
72
70
        delete_items(deletables, dry_run=dry_run)
73
 
    finally:
74
 
        tree.unlock()
75
 
 
76
 
 
77
 
def _filter_out_nested_bzrdirs(deletables):
 
71
 
 
72
 
 
73
def _filter_out_nested_controldirs(deletables):
78
74
    result = []
79
75
    for path, subp in deletables:
80
76
        # bzr won't recurse into unknowns/ignored directories by default
81
77
        # so we don't pay a penalty for checking subdirs of path for nested
82
 
        # bzrdir.
 
78
        # control dir.
83
79
        # That said we won't detect the branch in the subdir of non-branch
84
80
        # directory and therefore delete it. (worth to FIXME?)
85
81
        if isdir(path):
86
82
            try:
87
83
                controldir.ControlDir.open(path)
88
84
            except errors.NotBranchError:
89
 
                result.append((path,subp))
 
85
                result.append((path, subp))
90
86
            else:
91
87
                # TODO may be we need to notify user about skipped directories?
92
88
                pass
93
89
        else:
94
 
            result.append((path,subp))
 
90
            result.append((path, subp))
95
91
    return result
96
92
 
97
93
 
117
113
                try:
118
114
                    os.unlink(path)
119
115
                    note('  ' + subp)
120
 
                except OSError, e:
 
116
                except OSError as e:
121
117
                    # We handle only permission error here
122
118
                    if e.errno != errno.EACCES:
123
119
                        raise e
124
120
                    ui.ui_factory.show_warning(gettext(
125
121
                        'unable to remove "{0}": {1}.').format(
126
 
                                                    path, e.strerror))
 
122
                        path, e.strerror))
127
123
        else:
128
124
            note('  ' + subp)
129
125
    if not has_deleted: