~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/_dirstate_helpers_pyx.pyx

  • Committer: Canonical.com Patch Queue Manager
  • Date: 2010-09-01 08:02:42 UTC
  • mfrom: (5390.3.3 faster-revert-593560)
  • Revision ID: pqm@pqm.ubuntu.com-20100901080242-esg62ody4frwmy66
(spiv) Avoid repeatedly calling self.target.all_file_ids() in
 InterTree.iter_changes. (Andrew Bennetts)

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
101
100
 
102
101
    char *PyString_AsString(object p)
103
102
    char *PyString_AsString_obj "PyString_AsString" (PyObject *string)
812
811
_encode = binascii.b2a_base64
813
812
 
814
813
 
 
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(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))
 
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)
831
830
    packed = PyString_FromStringAndSize(result, 6*4)
832
831
    return _encode(packed)[:-1]
833
832
 
834
833
 
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
 
 
840
834
def update_entry(self, entry, abspath, stat_value):
841
835
    """Update the entry based on what is actually on disk.
842
836
 
872
866
    # _st mode of the compiled stat objects.
873
867
    cdef int minikind, saved_minikind
874
868
    cdef void * details
875
 
    cdef int worth_saving
876
869
    minikind = minikind_from_mode(stat_value.st_mode)
877
870
    if 0 == minikind:
878
871
        return None
907
900
    # If we have gotten this far, that means that we need to actually
908
901
    # process this entry.
909
902
    link_or_sha1 = None
910
 
    worth_saving = 1
911
903
    if minikind == c'f':
912
904
        executable = self._is_executable(stat_value.st_mode,
913
905
                                         saved_executable)
924
916
            entry[1][0] = ('f', link_or_sha1, stat_value.st_size,
925
917
                           executable, packed_stat)
926
918
        else:
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
 
919
            entry[1][0] = ('f', '', stat_value.st_size,
 
920
                           executable, DirState.NULLSTAT)
935
921
    elif minikind == c'd':
 
922
        link_or_sha1 = None
936
923
        entry[1][0] = ('d', '', 0, False, packed_stat)
937
924
        if saved_minikind != c'd':
938
925
            # This changed from something into a directory. Make sure we
942
929
                self._get_block_entry_index(entry[0][0], entry[0][1], 0)
943
930
            self._ensure_block(block_index, entry_index,
944
931
                               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
949
932
    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
956
933
        link_or_sha1 = self._read_link(abspath, saved_link_or_sha1)
957
934
        if self._cutoff_time is None:
958
935
            self._sha_cutoff_time()
963
940
        else:
964
941
            entry[1][0] = ('l', '', stat_value.st_size,
965
942
                           False, DirState.NULLSTAT)
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])
 
943
    self._dirblock_state = DirState.IN_MEMORY_MODIFIED
970
944
    return link_or_sha1
971
945
 
972
946
 
1799
1773
                advance_entry = -1
1800
1774
                advance_path = -1
1801
1775
                result = None
1802
 
                changed = None
1803
1776
                path_handled = 0
1804
1777
                if current_entry is None:
1805
1778
                    # unversioned -  the check for path_handled when the path