/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/_dirstate_helpers_pyx.pyx

  • Committer: Richard Wilbur
  • Date: 2016-02-04 19:07:28 UTC
  • mto: This revision was merged to the branch mainline in revision 6618.
  • Revision ID: richard.wilbur@gmail.com-20160204190728-p0zvfii6zase0fw7
Update COPYING.txt from the original http://www.gnu.org/licenses/gpl-2.0.txt  (Only differences were in whitespace.)  Thanks to Petr Stodulka for pointing out the discrepancy.

Show diffs side-by-side

added added

removed removed

Lines of Context:
19
19
This is the python implementation for DirState functions.
20
20
"""
21
21
 
22
 
from __future__ import absolute_import
23
 
 
24
22
import binascii
25
23
import bisect
26
24
import errno
28
26
import stat
29
27
import sys
30
28
 
31
 
from .. import cache_utf8, errors, osutils
32
 
from .dirstate import DirState, DirstateCorrupt
33
 
from ..osutils import parent_directories, pathjoin, splitpath
 
29
from bzrlib import cache_utf8, errors, osutils
 
30
from bzrlib.dirstate import DirState
 
31
from bzrlib.osutils import parent_directories, pathjoin, splitpath
34
32
 
35
33
 
36
34
# This is the Windows equivalent of ENOTDIR
42
40
cdef int ERROR_DIRECTORY
43
41
ERROR_DIRECTORY = 267
44
42
 
 
43
#python2.4 support, and other platform-dependent includes
45
44
cdef extern from "python-compat.h":
46
45
    unsigned long htonl(unsigned long)
47
46
 
121
120
    # void *memrchr(void *s, int c, size_t len)
122
121
 
123
122
# cimport all of the definitions we will need to access
124
 
from .._static_tuple_c cimport import_static_tuple_c, StaticTuple, \
 
123
from _static_tuple_c cimport import_static_tuple_c, StaticTuple, \
125
124
    StaticTuple_New, StaticTuple_SET_ITEM
126
125
 
127
126
import_static_tuple_c()
244
243
    return 0
245
244
 
246
245
 
247
 
def lt_by_dirs(path1, path2):
 
246
def cmp_by_dirs(path1, path2):
248
247
    """Compare two paths directory by directory.
249
248
 
250
249
    This is equivalent to doing::
251
250
 
252
 
       operator.lt(path1.split('/'), path2.split('/'))
 
251
       cmp(path1.split('/'), path2.split('/'))
253
252
 
254
253
    The idea is that you should compare path components separately. This
255
 
    differs from plain ``path1 < path2`` for paths like ``'a-b'`` and ``a/b``.
256
 
    "a-b" comes after "a" but would come before "a/b" lexically.
 
254
    differs from plain ``cmp(path1, path2)`` for paths like ``'a-b'`` and
 
255
    ``a/b``. "a-b" comes after "a" but would come before "a/b" lexically.
257
256
 
258
257
    :param path1: first path
259
258
    :param path2: second path
260
 
    :return: True if path1 comes first, otherwise False
 
259
    :return: negative number if ``path1`` comes first,
 
260
        0 if paths are equal,
 
261
        and positive number if ``path2`` sorts first
261
262
    """
262
263
    if not PyString_CheckExact(path1):
263
264
        raise TypeError("'path1' must be a plain string, not %s: %r"
265
266
    if not PyString_CheckExact(path2):
266
267
        raise TypeError("'path2' must be a plain string, not %s: %r"
267
268
                        % (type(path2), path2))
268
 
    return -1 == _cmp_by_dirs(PyString_AsString(path1),
269
 
                              PyString_Size(path1),
270
 
                              PyString_AsString(path2),
271
 
                              PyString_Size(path2))
272
 
 
273
 
 
274
 
def _lt_path_by_dirblock(path1, path2):
 
269
    return _cmp_by_dirs(PyString_AsString(path1),
 
270
                        PyString_Size(path1),
 
271
                        PyString_AsString(path2),
 
272
                        PyString_Size(path2))
 
273
 
 
274
 
 
275
def _cmp_path_by_dirblock(path1, path2):
275
276
    """Compare two paths based on what directory they are in.
276
277
 
277
278
    This generates a sort order, such that all children of a directory are
283
284
 
284
285
    :param path1: first path
285
286
    :param path2: the second path
286
 
    :return: True if path1 comes first, otherwise False.
 
287
    :return: negative number if ``path1`` comes first,
 
288
        0 if paths are equal
 
289
        and a positive number if ``path2`` sorts first
287
290
    """
288
291
    if not PyString_CheckExact(path1):
289
292
        raise TypeError("'path1' must be a plain string, not %s: %r"
291
294
    if not PyString_CheckExact(path2):
292
295
        raise TypeError("'path2' must be a plain string, not %s: %r"
293
296
                        % (type(path2), path2))
294
 
    # GZ 2017-06-09: This internal function really only needs lt as well.
295
 
    return (_cmp_path_by_dirblock_intern(PyString_AsString(path1),
296
 
                                         PyString_Size(path1),
297
 
                                         PyString_AsString(path2),
298
 
                                         PyString_Size(path2)) < 0)
 
297
    return _cmp_path_by_dirblock_intern(PyString_AsString(path1),
 
298
                                        PyString_Size(path1),
 
299
                                        PyString_AsString(path2),
 
300
                                        PyString_Size(path2))
299
301
 
300
302
 
301
303
cdef int _cmp_path_by_dirblock_intern(char *path1, int path1_len,
561
563
        self.cur_cstr = <char*>memchr(next, c'\0', self.end_cstr - next)
562
564
        if self.cur_cstr == NULL:
563
565
            extra_len = self.end_cstr - next
564
 
            raise DirstateCorrupt(self.state,
 
566
            raise errors.DirstateCorrupt(self.state,
565
567
                'failed to find trailing NULL (\\0).'
566
568
                ' Trailing garbage: %r'
567
569
                % safe_string_from_size(next, extra_len))
720
722
        # marker.
721
723
        trailing = self.get_next(&cur_size)
722
724
        if cur_size != 1 or trailing[0] != c'\n':
723
 
            raise DirstateCorrupt(self.state,
 
725
            raise errors.DirstateCorrupt(self.state,
724
726
                'Bad parse, we expected to end on \\n, not: %d %s: %s'
725
727
                % (cur_size, safe_string_from_size(trailing, cur_size),
726
728
                   ret))
767
769
            PyList_Append(current_block, entry)
768
770
            entry_count = entry_count + 1
769
771
        if entry_count != expected_entry_count:
770
 
            raise DirstateCorrupt(self.state,
 
772
            raise errors.DirstateCorrupt(self.state,
771
773
                    'We read the wrong number of entries.'
772
774
                    ' We expected to read %s, but read %s'
773
775
                    % (expected_entry_count, entry_count))
835
837
    return _pack_stat(stat_value)
836
838
 
837
839
 
838
 
cpdef update_entry(self, entry, abspath, stat_value):
 
840
def update_entry(self, entry, abspath, stat_value):
 
841
    """Update the entry based on what is actually on disk.
 
842
 
 
843
    This function only calculates the sha if it needs to - if the entry is
 
844
    uncachable, or clearly different to the first parent's entry, no sha
 
845
    is calculated, and None is returned.
 
846
 
 
847
    :param entry: This is the dirblock entry for the file in question.
 
848
    :param abspath: The path on disk for this file.
 
849
    :param stat_value: (optional) if we already have done a stat on the
 
850
        file, re-use it.
 
851
    :return: None, or The sha1 hexdigest of the file (40 bytes) or link
 
852
        target of a symlink.
 
853
    """
 
854
    return _update_entry(self, entry, abspath, stat_value)
 
855
 
 
856
 
 
857
cdef _update_entry(self, entry, abspath, stat_value):
839
858
    """Update the entry based on what is actually on disk.
840
859
 
841
860
    This function only calculates the sha if it needs to - if the entry is
1140
1159
            if self.target_index != 0:
1141
1160
                raise AssertionError("Unsupported target index %d" %
1142
1161
                                     self.target_index)
1143
 
            link_or_sha1 = update_entry(self.state, entry, path_info[4], path_info[3])
 
1162
            link_or_sha1 = _update_entry(self.state, entry, path_info[4], path_info[3])
1144
1163
            # The entry may have been modified by update_entry
1145
1164
            target_details = details_list[self.target_index]
1146
1165
            target_minikind = _minikind_from_string(target_details[0])
1179
1198
                # update the source details variable to be the real
1180
1199
                # location.
1181
1200
                if old_entry == (None, None):
1182
 
                    raise DirstateCorrupt(self.state._filename,
 
1201
                    raise errors.CorruptDirstate(self.state._filename,
1183
1202
                        "entry '%s/%s' is considered renamed from %r"
1184
1203
                        " but source does not exist\n"
1185
1204
                        "entry: %s" % (entry[0][0], entry[0][1], old_path, entry))
1326
1345
            parent_entry = self.state._get_entry(self.target_index,
1327
1346
                                                 path_utf8=entry[0][0])
1328
1347
            if parent_entry is None:
1329
 
                raise DirstateCorrupt(self.state,
 
1348
                raise errors.DirstateCorrupt(self.state,
1330
1349
                    "We could not find the parent entry in index %d"
1331
1350
                    " for the entry: %s"
1332
1351
                    % (self.target_index, entry[0]))