~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/_dirstate_helpers_py.py

  • Committer: Patch Queue Manager
  • Date: 2011-09-15 15:37:20 UTC
  • mfrom: (6140.1.3 trunk)
  • Revision ID: pqm@pqm.ubuntu.com-20110915153720-n17t6m5oh5bblqad
(vila) Open 2.5b2 for bugfixes (Vincent Ladeuil)

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
# Copyright (C) 2007 Canonical Ltd
 
1
# Copyright (C) 2007, 2008 Canonical Ltd
2
2
#
3
3
# This program is free software; you can redistribute it and/or modify
4
4
# it under the terms of the GNU General Public License as published by
12
12
#
13
13
# You should have received a copy of the GNU General Public License
14
14
# along with this program; if not, write to the Free Software
15
 
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 
15
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
16
16
 
17
17
"""Python implementations of Dirstate Helper functions."""
18
18
 
20
20
 
21
21
# We cannot import the dirstate module, because it loads this module
22
22
# All we really need is the IN_MEMORY_MODIFIED constant
 
23
from bzrlib import errors
23
24
from bzrlib.dirstate import DirState
24
25
 
25
26
 
26
 
def _bisect_path_left_py(paths, path):
 
27
def _bisect_path_left(paths, path):
27
28
    """Return the index where to insert path into paths.
28
29
 
29
30
    This uses the dirblock sorting. So all children in a directory come before
62
63
        mid = (lo + hi) // 2
63
64
        # Grab the dirname for the current dirblock
64
65
        cur = paths[mid]
65
 
        if _cmp_path_by_dirblock_py(cur, path) < 0:
 
66
        if _cmp_path_by_dirblock(cur, path) < 0:
66
67
            lo = mid + 1
67
68
        else:
68
69
            hi = mid
69
70
    return lo
70
71
 
71
72
 
72
 
def _bisect_path_right_py(paths, path):
 
73
def _bisect_path_right(paths, path):
73
74
    """Return the index where to insert path into paths.
74
75
 
75
76
    This uses a path-wise comparison so we get::
93
94
        mid = (lo+hi)//2
94
95
        # Grab the dirname for the current dirblock
95
96
        cur = paths[mid]
96
 
        if _cmp_path_by_dirblock_py(path, cur) < 0:
 
97
        if _cmp_path_by_dirblock(path, cur) < 0:
97
98
            hi = mid
98
99
        else:
99
100
            lo = mid + 1
100
101
    return lo
101
102
 
102
103
 
103
 
def bisect_dirblock_py(dirblocks, dirname, lo=0, hi=None, cache={}):
 
104
def bisect_dirblock(dirblocks, dirname, lo=0, hi=None, cache={}):
104
105
    """Return the index where to insert dirname into the dirblocks.
105
106
 
106
107
    The return value idx is such that all directories blocks in dirblock[:idx]
131
132
    return lo
132
133
 
133
134
 
134
 
def cmp_by_dirs_py(path1, path2):
 
135
def cmp_by_dirs(path1, path2):
135
136
    """Compare two paths directory by directory.
136
137
 
137
138
    This is equivalent to doing::
157
158
    return cmp(path1.split('/'), path2.split('/'))
158
159
 
159
160
 
160
 
def _cmp_path_by_dirblock_py(path1, path2):
 
161
def _cmp_path_by_dirblock(path1, path2):
161
162
    """Compare two paths based on what directory they are in.
162
163
 
163
164
    This generates a sort order, such that all children of a directory are
183
184
    return cmp(key1, key2)
184
185
 
185
186
 
186
 
def _read_dirblocks_py(state):
 
187
def _read_dirblocks(state):
187
188
    """Read in the dirblocks for the given DirState object.
188
189
 
189
190
    This is tightly bound to the DirState internal representation. It should be
201
202
    # Remove the last blank entry
202
203
    trailing = fields.pop()
203
204
    if trailing != '':
204
 
        raise AssertionError("dirstate line %r has trailing garbage: %r" 
205
 
            % (trailing,))
 
205
        raise errors.DirstateCorrupt(state,
 
206
            'trailing garbage: %r' % (trailing,))
206
207
    # consider turning fields into a tuple.
207
208
 
208
209
    # skip the first field which is the trailing null from the header.
220
221
    field_count = len(fields)
221
222
    # this checks our adjustment, and also catches file too short.
222
223
    if field_count - cur != expected_field_count:
223
 
        raise AssertionError(
 
224
        raise errors.DirstateCorrupt(state,
224
225
            'field count incorrect %s != %s, entry_size=%s, '\
225
226
            'num_entries=%s fields=%r' % (
226
227
            field_count - cur, expected_field_count, entry_size,
288
289
    # To convert from format 3 => format 2
289
290
    # state._dirblocks = sorted(state._dirblocks)
290
291
    state._dirblock_state = DirState.IN_MEMORY_UNMODIFIED
291