23
23
from bzrlib.dirstate import DirState
26
def bisect_path_left_py(paths, path):
26
def _bisect_path_left_py(paths, path):
27
27
"""Return the index where to insert path into paths.
29
29
This uses the dirblock sorting. So all children in a directory come before
62
62
mid = (lo + hi) // 2
63
63
# Grab the dirname for the current dirblock
65
if cmp_path_by_dirblock_py(cur, path) < 0:
65
if _cmp_path_by_dirblock_py(cur, path) < 0:
72
def bisect_path_right_py(paths, path):
72
def _bisect_path_right_py(paths, path):
73
73
"""Return the index where to insert path into paths.
75
75
This uses a path-wise comparison so we get::
134
def cmp_by_dirs_py(path1, path2):
135
"""Compare two paths directory by directory.
137
This is equivalent to doing::
139
cmp(path1.split('/'), path2.split('/'))
141
The idea is that you should compare path components separately. This
142
differs from plain ``cmp(path1, path2)`` for paths like ``'a-b'`` and
143
``a/b``. "a-b" comes after "a" but would come before "a/b" lexically.
145
:param path1: first path
146
:param path2: second path
147
:return: positive number if ``path1`` comes first,
148
0 if paths are equal,
149
and negative number if ``path2`` sorts first
151
return cmp(path1.split('/'), path2.split('/'))
154
def _cmp_path_by_dirblock_py(path1, path2):
155
"""Compare two paths based on what directory they are in.
157
This generates a sort order, such that all children of a directory are
158
sorted together, and grandchildren are in the same order as the
159
children appear. But all grandchildren come after all children.
161
:param path1: first path
162
:param path2: the second path
163
:return: positive number if ``path1`` comes first,
165
and a negative number if ``path2`` sorts first
167
dirname1, basename1 = os.path.split(path1)
168
key1 = (dirname1.split('/'), basename1)
169
dirname2, basename2 = os.path.split(path2)
170
key2 = (dirname2.split('/'), basename2)
171
return cmp(key1, key2)
134
174
def _read_dirblocks_py(state):
135
175
"""Read in the dirblocks for the given DirState object.
233
273
# state._dirblocks = sorted(state._dirblocks)
234
274
state._dirblock_state = DirState.IN_MEMORY_UNMODIFIED
237
def cmp_by_dirs_py(path1, path2):
238
"""Compare two paths directory by directory.
240
This is equivalent to doing::
242
cmp(path1.split('/'), path2.split('/'))
244
The idea is that you should compare path components separately. This
245
differs from plain ``cmp(path1, path2)`` for paths like ``'a-b'`` and
246
``a/b``. "a-b" comes after "a" but would come before "a/b" lexically.
248
:param path1: first path
249
:param path2: second path
250
:return: positive number if ``path1`` comes first,
251
0 if paths are equal,
252
and negative number if ``path2`` sorts first
254
return cmp(path1.split('/'), path2.split('/'))
257
def cmp_path_by_dirblock_py(path1, path2):
258
"""Compare two paths based on what directory they are in.
260
This generates a sort order, such that all children of a directory are
261
sorted together, and grandchildren are in the same order as the
262
children appear. But all grandchildren come after all children.
264
:param path1: first path
265
:param path2: the second path
266
:return: positive number if ``path1`` comes first,
268
and a negative number if ``path2`` sorts first
270
dirname1, basename1 = os.path.split(path1)
271
key1 = (dirname1.split('/'), basename1)
272
dirname2, basename2 = os.path.split(path2)
273
key2 = (dirname2.split('/'), basename2)
274
return cmp(key1, key2)