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

  • Committer: Canonical.com Patch Queue Manager
  • Date: 2008-09-26 05:47:03 UTC
  • mfrom: (3696.5.4 integration)
  • Revision ID: pqm@pqm.ubuntu.com-20080926054703-nxn5f1h7z7gvur96
(robertc) Improve the handling of the sha1 cache by updating it
        during commit and avoiding some of the sha generation during
        iter_changes. (Robert Collins)

Show diffs side-by-side

added added

removed removed

Lines of Context:
802
802
def update_entry(self, entry, abspath, stat_value):
803
803
    """Update the entry based on what is actually on disk.
804
804
 
 
805
    This function only calculates the sha if it needs to - if the entry is
 
806
    uncachable, or clearly different to the first parent's entry, no sha
 
807
    is calculated, and None is returned.
 
808
 
805
809
    :param entry: This is the dirblock entry for the file in question.
806
810
    :param abspath: The path on disk for this file.
807
811
    :param stat_value: (optional) if we already have done a stat on the
808
812
        file, re-use it.
809
 
    :return: The sha1 hexdigest of the file (40 bytes) or link target of a
810
 
            symlink.
 
813
    :return: None, or The sha1 hexdigest of the file (40 bytes) or link
 
814
        target of a symlink.
811
815
    """
812
816
    return _update_entry(self, entry, abspath, stat_value)
813
817
 
815
819
cdef _update_entry(self, entry, abspath, stat_value):
816
820
    """Update the entry based on what is actually on disk.
817
821
 
 
822
    This function only calculates the sha if it needs to - if the entry is
 
823
    uncachable, or clearly different to the first parent's entry, no sha
 
824
    is calculated, and None is returned.
 
825
 
818
826
    :param self: The dirstate object this is operating on.
819
827
    :param entry: This is the dirblock entry for the file in question.
820
828
    :param abspath: The path on disk for this file.
821
829
    :param stat_value: The stat value done on the path.
822
 
    :return: The sha1 hexdigest of the file (40 bytes) or link target of a
823
 
            symlink.
 
830
    :return: None, or The sha1 hexdigest of the file (40 bytes) or link
 
831
        target of a symlink.
824
832
    """
825
833
    # TODO - require pyrex 0.9.8, then use a pyd file to define access to the
826
834
    # _st mode of the compiled stat objects.
859
867
    # process this entry.
860
868
    link_or_sha1 = None
861
869
    if minikind == c'f':
862
 
        link_or_sha1 = self._sha1_file(abspath)
863
870
        executable = self._is_executable(stat_value.st_mode,
864
871
                                         saved_executable)
865
872
        if self._cutoff_time is None:
866
873
            self._sha_cutoff_time()
867
874
        if (stat_value.st_mtime < self._cutoff_time
868
 
            and stat_value.st_ctime < self._cutoff_time):
 
875
            and stat_value.st_ctime < self._cutoff_time
 
876
            and len(entry[1]) > 1
 
877
            and entry[1][1][0] != 'a'):
 
878
                # Could check for size changes for further optimised
 
879
                # avoidance of sha1's. However the most prominent case of
 
880
                # over-shaing is during initial add, which this catches.
 
881
            link_or_sha1 = self._sha1_file(abspath)
869
882
            entry[1][0] = ('f', link_or_sha1, stat_value.st_size,
870
883
                           executable, packed_stat)
871
884
        else:
976
989
    cdef object root_dir_info
977
990
    cdef object bisect_left
978
991
    cdef object pathjoin
 
992
    cdef object fstat
 
993
    cdef object sha_file
979
994
 
980
995
    def __init__(self, include_unchanged, use_filesystem_for_exec,
981
996
        search_specific_files, state, source_index, target_index,
1023
1038
        self.root_dir_info = None
1024
1039
        self.bisect_left = bisect.bisect_left
1025
1040
        self.pathjoin = osutils.pathjoin
 
1041
        self.fstat = os.fstat
 
1042
        self.sha_file = osutils.sha_file
1026
1043
 
1027
1044
    cdef _process_entry(self, entry, path_info):
1028
1045
        """Compare an entry and real disk to generate delta information.
1119
1136
                    if source_minikind != c'f':
1120
1137
                        content_change = 1
1121
1138
                    else:
1122
 
                        # We could check the size, but we already have the
1123
 
                        # sha1 hash.
1124
 
                        content_change = (link_or_sha1 != source_details[1])
 
1139
                        # If the size is the same, check the sha:
 
1140
                        if target_details[2] == source_details[2]:
 
1141
                            if link_or_sha1 is None:
 
1142
                                # Stat cache miss:
 
1143
                                file_obj = file(path_info[4], 'rb')
 
1144
                                try:
 
1145
                                    # XXX: TODO: Use lower level file IO rather
 
1146
                                    # than python objects for sha-misses.
 
1147
                                    statvalue = self.fstat(file_obj.fileno())
 
1148
                                    link_or_sha1 = self.sha_file(file_obj)
 
1149
                                finally:
 
1150
                                    file_obj.close()
 
1151
                                self.state._observed_sha1(entry, link_or_sha1,
 
1152
                                    statvalue)
 
1153
                            content_change = (link_or_sha1 != source_details[1])
 
1154
                        else:
 
1155
                            # Size changed, so must be different
 
1156
                            content_change = 1
1125
1157
                    # Target details is updated at update_entry time
1126
1158
                    if self.use_filesystem_for_exec:
1127
1159
                        # We don't need S_ISREG here, because we are sure