~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/_dirstate_helpers_py.py

  • Committer: Canonical.com Patch Queue Manager
  • Date: 2008-03-16 14:01:20 UTC
  • mfrom: (3280.2.5 integration)
  • Revision ID: pqm@pqm.ubuntu.com-20080316140120-i3yq8yr1l66m11h7
Start 1.4 development

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
# Copyright (C) 2007, 2008 Canonical Ltd
 
1
# Copyright (C) 2007 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
 
15
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  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
24
23
from bzrlib.dirstate import DirState
25
24
 
26
25
 
27
 
def _bisect_path_left(paths, path):
 
26
def _bisect_path_left_py(paths, path):
28
27
    """Return the index where to insert path into paths.
29
28
 
30
29
    This uses the dirblock sorting. So all children in a directory come before
63
62
        mid = (lo + hi) // 2
64
63
        # Grab the dirname for the current dirblock
65
64
        cur = paths[mid]
66
 
        if _cmp_path_by_dirblock(cur, path) < 0:
 
65
        if _cmp_path_by_dirblock_py(cur, path) < 0:
67
66
            lo = mid + 1
68
67
        else:
69
68
            hi = mid
70
69
    return lo
71
70
 
72
71
 
73
 
def _bisect_path_right(paths, path):
 
72
def _bisect_path_right_py(paths, path):
74
73
    """Return the index where to insert path into paths.
75
74
 
76
75
    This uses a path-wise comparison so we get::
94
93
        mid = (lo+hi)//2
95
94
        # Grab the dirname for the current dirblock
96
95
        cur = paths[mid]
97
 
        if _cmp_path_by_dirblock(path, cur) < 0:
 
96
        if _cmp_path_by_dirblock_py(path, cur) < 0:
98
97
            hi = mid
99
98
        else:
100
99
            lo = mid + 1
101
100
    return lo
102
101
 
103
102
 
104
 
def bisect_dirblock(dirblocks, dirname, lo=0, hi=None, cache={}):
 
103
def bisect_dirblock_py(dirblocks, dirname, lo=0, hi=None, cache={}):
105
104
    """Return the index where to insert dirname into the dirblocks.
106
105
 
107
106
    The return value idx is such that all directories blocks in dirblock[:idx]
132
131
    return lo
133
132
 
134
133
 
135
 
def cmp_by_dirs(path1, path2):
 
134
def cmp_by_dirs_py(path1, path2):
136
135
    """Compare two paths directory by directory.
137
136
 
138
137
    This is equivalent to doing::
158
157
    return cmp(path1.split('/'), path2.split('/'))
159
158
 
160
159
 
161
 
def _cmp_path_by_dirblock(path1, path2):
 
160
def _cmp_path_by_dirblock_py(path1, path2):
162
161
    """Compare two paths based on what directory they are in.
163
162
 
164
163
    This generates a sort order, such that all children of a directory are
184
183
    return cmp(key1, key2)
185
184
 
186
185
 
187
 
def _read_dirblocks(state):
 
186
def _read_dirblocks_py(state):
188
187
    """Read in the dirblocks for the given DirState object.
189
188
 
190
189
    This is tightly bound to the DirState internal representation. It should be
201
200
    fields = text.split('\0')
202
201
    # Remove the last blank entry
203
202
    trailing = fields.pop()
204
 
    if trailing != '':
205
 
        raise errors.DirstateCorrupt(state,
206
 
            'trailing garbage: %r' % (trailing,))
 
203
    assert trailing == ''
207
204
    # consider turning fields into a tuple.
208
205
 
209
206
    # skip the first field which is the trailing null from the header.
220
217
    expected_field_count = entry_size * state._num_entries
221
218
    field_count = len(fields)
222
219
    # this checks our adjustment, and also catches file too short.
223
 
    if field_count - cur != expected_field_count:
224
 
        raise errors.DirstateCorrupt(state,
225
 
            'field count incorrect %s != %s, entry_size=%s, '\
226
 
            'num_entries=%s fields=%r' % (
 
220
    assert field_count - cur == expected_field_count, \
 
221
        'field count incorrect %s != %s, entry_size=%s, '\
 
222
        'num_entries=%s fields=%r' % (
227
223
            field_count - cur, expected_field_count, entry_size,
228
 
            state._num_entries, fields))
 
224
            state._num_entries, fields)
229
225
 
230
226
    if num_present_parents == 1:
231
227
        # Bind external functions to local names
273
269
                     ),
274
270
                     ])
275
271
            trailing = next()
276
 
            if trailing != '\n':
277
 
                raise ValueError("trailing garbage in dirstate: %r" % trailing)
 
272
            assert trailing == '\n'
278
273
            # append the entry to the current block
279
274
            append_entry(entry)
280
275
        state._split_root_dirblock_into_contents()
289
284
    # To convert from format 3 => format 2
290
285
    # state._dirblocks = sorted(state._dirblocks)
291
286
    state._dirblock_state = DirState.IN_MEMORY_UNMODIFIED
 
287