~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/workingtree_4.py

  • Committer: Robert Collins
  • Date: 2008-09-23 06:21:45 UTC
  • mto: (3696.5.2 iter-changes.less-sha1)
  • mto: This revision was merged to the branch mainline in revision 3741.
  • Revision ID: robertc@robertcollins.net-20080923062145-bi6lcbxwgfhcm8j9
Sha files for the stat cache more lazily rather than on first-examination, allowing less overall sha calculations to occur.

Show diffs side-by-side

added added

removed removed

Lines of Context:
412
412
        link_or_sha1 = state.update_entry(entry, file_abspath,
413
413
                                          stat_value=stat_value)
414
414
        if entry[1][0][0] == 'f':
415
 
            return link_or_sha1
 
415
            if link_or_sha1 is None:
 
416
                file_obj, statvalue = self.get_file_with_stat(file_id, path)
 
417
                try:
 
418
                    sha1 = osutils.sha_file(file_obj)
 
419
                finally:
 
420
                    file_obj.close()
 
421
                self._observed_sha1(file_id, path, (sha1, statvalue))
 
422
                return sha1
 
423
            else:
 
424
                return link_or_sha1
416
425
        return None
417
426
 
418
427
    def _get_inventory(self):
1845
1854
        utf8_decode = cache_utf8._utf8_decode
1846
1855
        _minikind_to_kind = dirstate.DirState._minikind_to_kind
1847
1856
        cmp_by_dirs = dirstate.cmp_by_dirs
 
1857
        fstat = os.fstat
 
1858
        sha_file = osutils.sha_file
1848
1859
        # NB: show_status depends on being able to pass in non-versioned files
1849
1860
        # and report them as unknown
1850
1861
        # TODO: handle extra trees in the dirstate.
2078
2089
                        if source_minikind != 'f':
2079
2090
                            content_change = True
2080
2091
                        else:
2081
 
                            # We could check the size, but we already have the
2082
 
                            # sha1 hash.
2083
 
                            content_change = (link_or_sha1 != source_details[1])
 
2092
                            # If the size is the same, check the sha:
 
2093
                            if target_details[2] == source_details[2]:
 
2094
                                if link_or_sha1 is None:
 
2095
                                    # Stat cache miss:
 
2096
                                    file_obj = file(path_info[4], 'rb')
 
2097
                                    try:
 
2098
                                        statvalue = fstat(file_obj.fileno())
 
2099
                                        link_or_sha1 = sha_file(file_obj)
 
2100
                                    finally:
 
2101
                                        file_obj.close()
 
2102
                                    state._observed_sha1(entry, link_or_sha1,
 
2103
                                        statvalue)
 
2104
                                content_change = (link_or_sha1 != source_details[1])
 
2105
                            else:
 
2106
                                # Size changed, so must be different
 
2107
                                content_change = True
2084
2108
                        # Target details is updated at update_entry time
2085
2109
                        if use_filesystem_for_exec:
2086
2110
                            # We don't need S_ISREG here, because we are sure