~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/_dirstate_helpers_pyx.pyx

  • Committer: Martin Pool
  • Date: 2010-08-18 07:25:22 UTC
  • mto: This revision was merged to the branch mainline in revision 5383.
  • Revision ID: mbp@sourcefrog.net-20100818072522-uk3gsazoia3l3s0a
Start adding 'what's new in 2.3'

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
# Copyright (C) 2007-2010 Canonical Ltd
 
1
# Copyright (C) 2007, 2008, 2010 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
118
118
    # ??? memrchr is a GNU extension :(
119
119
    # void *memrchr(void *s, int c, size_t len)
120
120
 
121
 
# cimport all of the definitions we will need to access
122
 
from _static_tuple_c cimport import_static_tuple_c, StaticTuple, \
123
 
    StaticTuple_New, StaticTuple_SET_ITEM
124
 
 
125
 
import_static_tuple_c()
126
121
 
127
122
cdef void* _my_memrchr(void *s, int c, size_t n): # cannot_raise
128
123
    # memrchr seems to be a GNU extension, so we have to implement it ourselves
615
610
        :param new_block: This is to let the caller know that it needs to
616
611
            create a new directory block to store the next entry.
617
612
        """
618
 
        cdef StaticTuple path_name_file_id_key
619
 
        cdef StaticTuple tmp
 
613
        cdef object path_name_file_id_key
620
614
        cdef char *entry_size_cstr
621
615
        cdef unsigned long int entry_size
622
616
        cdef char* executable_cstr
656
650
        # Build up the key that will be used.
657
651
        # By using <object>(void *) Pyrex will automatically handle the
658
652
        # Py_INCREF that we need.
659
 
        cur_dirname = <object>p_current_dirname[0]
660
 
        # Use StaticTuple_New to pre-allocate, rather than creating a regular
661
 
        # tuple and passing it to the StaticTuple constructor.
662
 
        # path_name_file_id_key = StaticTuple(<object>p_current_dirname[0],
663
 
        #                          self.get_next_str(),
664
 
        #                          self.get_next_str(),
665
 
        #                         )
666
 
        tmp = StaticTuple_New(3)
667
 
        Py_INCREF(cur_dirname); StaticTuple_SET_ITEM(tmp, 0, cur_dirname)
668
 
        cur_basename = self.get_next_str()
669
 
        cur_file_id = self.get_next_str()
670
 
        Py_INCREF(cur_basename); StaticTuple_SET_ITEM(tmp, 1, cur_basename)
671
 
        Py_INCREF(cur_file_id); StaticTuple_SET_ITEM(tmp, 2, cur_file_id)
672
 
        path_name_file_id_key = tmp
 
653
        path_name_file_id_key = (<object>p_current_dirname[0],
 
654
                                 self.get_next_str(),
 
655
                                 self.get_next_str(),
 
656
                                )
673
657
 
674
658
        # Parse all of the per-tree information. current has the information in
675
659
        # the same location as parent trees. The only difference is that 'info'
693
677
            executable_cstr = self.get_next(&cur_size)
694
678
            is_executable = (executable_cstr[0] == c'y')
695
679
            info = self.get_next_str()
696
 
            # TODO: If we want to use StaticTuple_New here we need to be pretty
697
 
            #       careful. We are relying on a bit of Pyrex
698
 
            #       automatic-conversion from 'int' to PyInt, and that doesn't
699
 
            #       play well with the StaticTuple_SET_ITEM macro.
700
 
            #       Timing doesn't (yet) show a worthwile improvement in speed
701
 
            #       versus complexity and maintainability.
702
 
            # tmp = StaticTuple_New(5)
703
 
            # Py_INCREF(minikind); StaticTuple_SET_ITEM(tmp, 0, minikind)
704
 
            # Py_INCREF(fingerprint); StaticTuple_SET_ITEM(tmp, 1, fingerprint)
705
 
            # Py_INCREF(entry_size); StaticTuple_SET_ITEM(tmp, 2, entry_size)
706
 
            # Py_INCREF(is_executable); StaticTuple_SET_ITEM(tmp, 3, is_executable)
707
 
            # Py_INCREF(info); StaticTuple_SET_ITEM(tmp, 4, info)
708
 
            # PyList_Append(trees, tmp)
709
 
            PyList_Append(trees, StaticTuple(
 
680
            PyList_Append(trees, (
710
681
                minikind,     # minikind
711
682
                fingerprint,  # fingerprint
712
683
                entry_size,   # size
866
837
    # _st mode of the compiled stat objects.
867
838
    cdef int minikind, saved_minikind
868
839
    cdef void * details
869
 
    cdef int worth_saving
870
840
    minikind = minikind_from_mode(stat_value.st_mode)
871
841
    if 0 == minikind:
872
842
        return None
901
871
    # If we have gotten this far, that means that we need to actually
902
872
    # process this entry.
903
873
    link_or_sha1 = None
904
 
    worth_saving = 1
905
874
    if minikind == c'f':
906
875
        executable = self._is_executable(stat_value.st_mode,
907
876
                                         saved_executable)
918
887
            entry[1][0] = ('f', link_or_sha1, stat_value.st_size,
919
888
                           executable, packed_stat)
920
889
        else:
921
 
            # This file is not worth caching the sha1. Either it is too new, or
922
 
            # it is newly added. Regardless, the only things we are changing
923
 
            # are derived from the stat, and so are not worth caching. So we do
924
 
            # *not* set the IN_MEMORY_MODIFIED flag. (But we'll save the
925
 
            # updated values if there is *other* data worth saving.)
926
 
            entry[1][0] = ('f', '', stat_value.st_size, executable,
927
 
                           DirState.NULLSTAT)
928
 
            worth_saving = 0
 
890
            entry[1][0] = ('f', '', stat_value.st_size,
 
891
                           executable, DirState.NULLSTAT)
929
892
    elif minikind == c'd':
 
893
        link_or_sha1 = None
930
894
        entry[1][0] = ('d', '', 0, False, packed_stat)
931
895
        if saved_minikind != c'd':
932
896
            # This changed from something into a directory. Make sure we
936
900
                self._get_block_entry_index(entry[0][0], entry[0][1], 0)
937
901
            self._ensure_block(block_index, entry_index,
938
902
                               pathjoin(entry[0][0], entry[0][1]))
939
 
        else:
940
 
            # Any changes are derived trivially from the stat object, not worth
941
 
            # re-writing a dirstate for just this
942
 
            worth_saving = 0
943
903
    elif minikind == c'l':
944
 
        if saved_minikind == c'l':
945
 
            # If the object hasn't changed kind, it isn't worth saving the
946
 
            # dirstate just for a symlink. The default is 'fast symlinks' which
947
 
            # save the target in the inode entry, rather than separately. So to
948
 
            # stat, we've already read everything off disk.
949
 
            worth_saving = 0
950
904
        link_or_sha1 = self._read_link(abspath, saved_link_or_sha1)
951
905
        if self._cutoff_time is None:
952
906
            self._sha_cutoff_time()
957
911
        else:
958
912
            entry[1][0] = ('l', '', stat_value.st_size,
959
913
                           False, DirState.NULLSTAT)
960
 
    if worth_saving:
961
 
        # Note, even though _mark_modified will only set
962
 
        # IN_MEMORY_HASH_MODIFIED, it still isn't worth 
963
 
        self._mark_modified([entry])
 
914
    self._dirblock_state = DirState.IN_MEMORY_MODIFIED
964
915
    return link_or_sha1
965
916
 
966
917