~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/_dirstate_helpers_c.pyx

Review feedback.

Show diffs side-by-side

added added

removed removed

Lines of Context:
26
26
import stat
27
27
 
28
28
from bzrlib import cache_utf8, errors, osutils
29
 
from bzrlib.dirstate import DirState, pack_stat
 
29
from bzrlib.dirstate import DirState
30
30
from bzrlib.osutils import pathjoin, splitpath
31
31
 
32
32
 
60
60
cdef extern from "stdlib.h":
61
61
    unsigned long int strtoul(char *nptr, char **endptr, int base)
62
62
 
63
 
cdef extern from "stdio.h":
64
 
    void printf(char *format, ...)
65
63
 
66
64
cdef extern from 'sys/stat.h':
67
65
    int S_ISDIR(int mode)
776
774
    return 0
777
775
 
778
776
 
779
 
#cdef object _encode
780
777
_encode = binascii.b2a_base64
781
778
 
 
779
 
782
780
from struct import pack
783
781
cdef _pack_stat(stat_value):
784
782
    """return a string representing the stat value's key fields.
815
813
cdef _update_entry(self, entry, abspath, stat_value):
816
814
    """Update the entry based on what is actually on disk.
817
815
 
 
816
    :param self: The dirstate object this is operating on.
818
817
    :param entry: This is the dirblock entry for the file in question.
819
818
    :param abspath: The path on disk for this file.
820
 
    :param stat_value: (optional) if we already have done a stat on the
821
 
        file, re-use it.
 
819
    :param stat_value: The stat value done on the path.
822
820
    :return: The sha1 hexdigest of the file (40 bytes) or link target of a
823
821
            symlink.
824
822
    """
825
 
    # TODO - require pyrex 0.8, then use a pyd file to define access to the _st
826
 
    # mode of the compiled stat objects.
 
823
    # TODO - require pyrex 0.9.8, then use a pyd file to define access to the
 
824
    # _st mode of the compiled stat objects.
827
825
    cdef int minikind, saved_minikind
828
826
    cdef void * details
829
 
    # pyrex 0.9.7 would allow cdef list details_list, and direct access rather
830
 
    # than PyList_GetItem_void_void below
831
827
    minikind = minikind_from_mode(stat_value.st_mode)
832
828
    if 0 == minikind:
833
829
        return None
883
879
            block_index, entry_index, dir_present, file_present = \
884
880
                self._get_block_entry_index(entry[0][0], entry[0][1], 0)
885
881
            self._ensure_block(block_index, entry_index,
886
 
                               osutils.pathjoin(entry[0][0], entry[0][1]))
 
882
                               pathjoin(entry[0][0], entry[0][1]))
887
883
    elif minikind == c'l':
888
884
        link_or_sha1 = self._read_link(abspath, saved_link_or_sha1)
889
885
        if self._cutoff_time is None:
977
973
    cdef int path_index
978
974
    cdef object root_dir_info
979
975
    cdef object bisect_left
 
976
    cdef object pathjoin
980
977
 
981
978
    def __init__(self, include_unchanged, use_filesystem_for_exec,
982
979
        search_specific_files, state, source_index, target_index,
1023
1020
        self.path_index = 0
1024
1021
        self.root_dir_info = None
1025
1022
        self.bisect_left = bisect.bisect_left
 
1023
        self.pathjoin = osutils.pathjoin
1026
1024
 
1027
1025
    cdef _process_entry(self, entry, path_info):
1028
1026
        """Compare an entry and real disk to generate delta information.
1084
1082
                # as well.
1085
1083
                old_path = source_details[1]
1086
1084
                old_dirname, old_basename = os.path.split(old_path)
1087
 
                path = pathjoin(entry[0][0], entry[0][1])
 
1085
                path = self.pathjoin(entry[0][0], entry[0][1])
1088
1086
                old_entry = self.state._get_entry(self.source_index,
1089
1087
                                             path_utf8=old_path)
1090
1088
                # update the source details variable to be the real
1106
1104
                target_kind = path_info[2]
1107
1105
                if target_kind == 'directory':
1108
1106
                    if path is None:
1109
 
                        old_path = path = pathjoin(old_dirname, old_basename)
 
1107
                        old_path = path = self.pathjoin(old_dirname, old_basename)
1110
1108
                    file_id = entry[0][2]
1111
1109
                    self.new_dirname_to_file_id[path] = file_id
1112
1110
                    if source_minikind != c'd':
1145
1143
                    raise Exception, "unknown kind %s" % path_info[2]
1146
1144
            if source_minikind == c'd':
1147
1145
                if path is None:
1148
 
                    old_path = path = pathjoin(old_dirname, old_basename)
 
1146
                    old_path = path = self.pathjoin(old_dirname, old_basename)
1149
1147
                if file_id is None:
1150
1148
                    file_id = entry[0][2]
1151
1149
                self.old_dirname_to_file_id[old_path] = file_id
1196
1194
                or source_exec != target_exec
1197
1195
                ):
1198
1196
                if old_path is None:
1199
 
                    path = pathjoin(old_dirname, old_basename)
 
1197
                    path = self.pathjoin(old_dirname, old_basename)
1200
1198
                    old_path = path
1201
1199
                    old_path_u = self.utf8_decode(old_path)[0]
1202
1200
                    path_u = old_path_u
1219
1217
                return self.uninteresting
1220
1218
        elif source_minikind == c'a' and _versioned_minikind(target_minikind):
1221
1219
            # looks like a new file
1222
 
            path = pathjoin(entry[0][0], entry[0][1])
 
1220
            path = self.pathjoin(entry[0][0], entry[0][1])
1223
1221
            # parent id is the entry for the path in the target tree
1224
1222
            # TODO: these are the same for an entire directory: cache em.
1225
1223
            parent_id = self.state._get_entry(self.target_index,
1259
1257
            # if its still on disk, *and* theres no other entry at this
1260
1258
            # path [we dont know this in this routine at the moment -
1261
1259
            # perhaps we should change this - then it would be an unknown.
1262
 
            old_path = pathjoin(entry[0][0], entry[0][1])
 
1260
            old_path = self.pathjoin(entry[0][0], entry[0][1])
1263
1261
            # parent id is the entry for the path in the target tree
1264
1262
            parent_id = self.state._get_entry(self.source_index, path_utf8=entry[0][0])[0][2]
1265
1263
            if parent_id == entry[0][2]: