~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/_dirstate_helpers_py.py

  • Committer: Ian Clatworthy
  • Date: 2009-09-09 11:43:10 UTC
  • mto: (4634.37.2 prepare-2.0)
  • mto: This revision was merged to the branch mainline in revision 4689.
  • Revision ID: ian.clatworthy@canonical.com-20090909114310-glw7tv76i5gnx9pt
put rules back in Makefile supporting plain-style docs

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::
144
145
 
145
146
    :param path1: first path
146
147
    :param path2: second path
147
 
    :return: positive number if ``path1`` comes first,
 
148
    :return: negative number if ``path1`` comes first,
148
149
        0 if paths are equal,
149
 
        and negative number if ``path2`` sorts first
 
150
        and positive number if ``path2`` sorts first
150
151
    """
151
152
    if not isinstance(path1, str):
152
153
        raise TypeError("'path1' must be a plain string, not %s: %r"
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
166
167
 
167
168
    :param path1: first path
168
169
    :param path2: the second path
169
 
    :return: positive number if ``path1`` comes first,
 
170
    :return: negative number if ``path1`` comes first,
170
171
        0 if paths are equal
171
 
        and a negative number if ``path2`` sorts first
 
172
        and a positive number if ``path2`` sorts first
172
173
    """
173
174
    if not isinstance(path1, str):
174
175
        raise TypeError("'path1' must be a plain string, not %s: %r"
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
200
201
    fields = text.split('\0')
201
202
    # Remove the last blank entry
202
203
    trailing = fields.pop()
203
 
    assert trailing == ''
 
204
    if trailing != '':
 
205
        raise errors.DirstateCorrupt(state,
 
206
            'trailing garbage: %r' % (trailing,))
204
207
    # consider turning fields into a tuple.
205
208
 
206
209
    # skip the first field which is the trailing null from the header.
217
220
    expected_field_count = entry_size * state._num_entries
218
221
    field_count = len(fields)
219
222
    # this checks our adjustment, and also catches file too short.
220
 
    assert field_count - cur == expected_field_count, \
221
 
        'field count incorrect %s != %s, entry_size=%s, '\
222
 
        'num_entries=%s fields=%r' % (
 
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' % (
223
227
            field_count - cur, expected_field_count, entry_size,
224
 
            state._num_entries, fields)
 
228
            state._num_entries, fields))
225
229
 
226
230
    if num_present_parents == 1:
227
231
        # Bind external functions to local names
269
273
                     ),
270
274
                     ])
271
275
            trailing = next()
272
 
            assert trailing == '\n'
 
276
            if trailing != '\n':
 
277
                raise ValueError("trailing garbage in dirstate: %r" % trailing)
273
278
            # append the entry to the current block
274
279
            append_entry(entry)
275
280
        state._split_root_dirblock_into_contents()
284
289
    # To convert from format 3 => format 2
285
290
    # state._dirblocks = sorted(state._dirblocks)
286
291
    state._dirblock_state = DirState.IN_MEMORY_UNMODIFIED
287