/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

  • Committer: John Arbash Meinel
  • Date: 2010-08-04 07:14:54 UTC
  • mto: This revision was merged to the branch mainline in revision 5390.
  • Revision ID: john@arbash-meinel.com-20100804071454-bfhbwrqes7sabvay
Populate the offsets array.

This cuts down the number of bisections dramatically, basically by pre-caching
the first step. On real-world data it drops the steps from 587 to 156.
Or from 4.9/key to 1.3/key.
This drops the time to lookup from 23.7us to 20.3us.
Note that (k in dict) is 12.2us. I do wish we were just a bit closer to that.
However, with _LeafNode inherited from dict, I get 26us, so
maybe there is something in the interpreter that does a PyDict_CheckExact
call, and there isn't much we can do about it.

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