~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/_dirstate_helpers_pyx.pyx

(vila) Fix bzrlib.tests.test_gpg.TestVerify.test_verify_revoked_signature
 with recent versions of gpg. (Vincent Ladeuil)

Show diffs side-by-side

added added

removed removed

Lines of Context:
97
97
    object PyTuple_GetItem_void_object "PyTuple_GET_ITEM" (void* tpl, int index)
98
98
    object PyTuple_GET_ITEM(object tpl, Py_ssize_t index)
99
99
 
 
100
    unsigned long PyInt_AsUnsignedLongMask(object number) except? -1
100
101
 
101
102
    char *PyString_AsString(object p)
102
103
    char *PyString_AsString_obj "PyString_AsString" (PyObject *string)
811
812
_encode = binascii.b2a_base64
812
813
 
813
814
 
814
 
from struct import pack
815
815
cdef _pack_stat(stat_value):
816
816
    """return a string representing the stat value's key fields.
817
817
 
821
821
    cdef char result[6*4] # 6 long ints
822
822
    cdef int *aliased
823
823
    aliased = <int *>result
824
 
    aliased[0] = htonl(stat_value.st_size)
825
 
    aliased[1] = htonl(int(stat_value.st_mtime))
826
 
    aliased[2] = htonl(int(stat_value.st_ctime))
827
 
    aliased[3] = htonl(stat_value.st_dev)
828
 
    aliased[4] = htonl(stat_value.st_ino & 0xFFFFFFFF)
829
 
    aliased[5] = htonl(stat_value.st_mode)
 
824
    aliased[0] = htonl(PyInt_AsUnsignedLongMask(stat_value.st_size))
 
825
    # mtime and ctime will often be floats but get converted to PyInt within
 
826
    aliased[1] = htonl(PyInt_AsUnsignedLongMask(stat_value.st_mtime))
 
827
    aliased[2] = htonl(PyInt_AsUnsignedLongMask(stat_value.st_ctime))
 
828
    aliased[3] = htonl(PyInt_AsUnsignedLongMask(stat_value.st_dev))
 
829
    aliased[4] = htonl(PyInt_AsUnsignedLongMask(stat_value.st_ino))
 
830
    aliased[5] = htonl(PyInt_AsUnsignedLongMask(stat_value.st_mode))
830
831
    packed = PyString_FromStringAndSize(result, 6*4)
831
832
    return _encode(packed)[:-1]
832
833
 
833
834
 
 
835
def pack_stat(stat_value):
 
836
    """Convert stat value into a packed representation quickly with pyrex"""
 
837
    return _pack_stat(stat_value)
 
838
 
 
839
 
834
840
def update_entry(self, entry, abspath, stat_value):
835
841
    """Update the entry based on what is actually on disk.
836
842
 
866
872
    # _st mode of the compiled stat objects.
867
873
    cdef int minikind, saved_minikind
868
874
    cdef void * details
 
875
    cdef int worth_saving
869
876
    minikind = minikind_from_mode(stat_value.st_mode)
870
877
    if 0 == minikind:
871
878
        return None
900
907
    # If we have gotten this far, that means that we need to actually
901
908
    # process this entry.
902
909
    link_or_sha1 = None
 
910
    worth_saving = 1
903
911
    if minikind == c'f':
904
912
        executable = self._is_executable(stat_value.st_mode,
905
913
                                         saved_executable)
916
924
            entry[1][0] = ('f', link_or_sha1, stat_value.st_size,
917
925
                           executable, packed_stat)
918
926
        else:
919
 
            entry[1][0] = ('f', '', stat_value.st_size,
920
 
                           executable, DirState.NULLSTAT)
 
927
            # This file is not worth caching the sha1. Either it is too new, or
 
928
            # it is newly added. Regardless, the only things we are changing
 
929
            # are derived from the stat, and so are not worth caching. So we do
 
930
            # *not* set the IN_MEMORY_MODIFIED flag. (But we'll save the
 
931
            # updated values if there is *other* data worth saving.)
 
932
            entry[1][0] = ('f', '', stat_value.st_size, executable,
 
933
                           DirState.NULLSTAT)
 
934
            worth_saving = 0
921
935
    elif minikind == c'd':
922
 
        link_or_sha1 = None
923
936
        entry[1][0] = ('d', '', 0, False, packed_stat)
924
937
        if saved_minikind != c'd':
925
938
            # This changed from something into a directory. Make sure we
929
942
                self._get_block_entry_index(entry[0][0], entry[0][1], 0)
930
943
            self._ensure_block(block_index, entry_index,
931
944
                               pathjoin(entry[0][0], entry[0][1]))
 
945
        else:
 
946
            # Any changes are derived trivially from the stat object, not worth
 
947
            # re-writing a dirstate for just this
 
948
            worth_saving = 0
932
949
    elif minikind == c'l':
 
950
        if saved_minikind == c'l':
 
951
            # If the object hasn't changed kind, it isn't worth saving the
 
952
            # dirstate just for a symlink. The default is 'fast symlinks' which
 
953
            # save the target in the inode entry, rather than separately. So to
 
954
            # stat, we've already read everything off disk.
 
955
            worth_saving = 0
933
956
        link_or_sha1 = self._read_link(abspath, saved_link_or_sha1)
934
957
        if self._cutoff_time is None:
935
958
            self._sha_cutoff_time()
940
963
        else:
941
964
            entry[1][0] = ('l', '', stat_value.st_size,
942
965
                           False, DirState.NULLSTAT)
943
 
    self._dirblock_state = DirState.IN_MEMORY_MODIFIED
 
966
    if worth_saving:
 
967
        # Note, even though _mark_modified will only set
 
968
        # IN_MEMORY_HASH_MODIFIED, it still isn't worth 
 
969
        self._mark_modified([entry])
944
970
    return link_or_sha1
945
971
 
946
972
 
1773
1799
                advance_entry = -1
1774
1800
                advance_path = -1
1775
1801
                result = None
 
1802
                changed = None
1776
1803
                path_handled = 0
1777
1804
                if current_entry is None:
1778
1805
                    # unversioned -  the check for path_handled when the path