/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 breezy/_dirstate_helpers_pyx.pyx

  • Committer: Jelmer Vernooij
  • Date: 2017-06-10 01:35:53 UTC
  • mto: (6670.4.8 move-bzr)
  • mto: This revision was merged to the branch mainline in revision 6681.
  • Revision ID: jelmer@jelmer.uk-20170610013553-560y7mn3su4pp763
Fix remaining tests.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
# Copyright (C) 2007, 2008, 2010 Canonical Ltd
 
1
# Copyright (C) 2007-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
19
19
This is the python implementation for DirState functions.
20
20
"""
21
21
 
 
22
from __future__ import absolute_import
 
23
 
22
24
import binascii
23
25
import bisect
24
26
import errno
26
28
import stat
27
29
import sys
28
30
 
29
 
from bzrlib import cache_utf8, errors, osutils
30
 
from bzrlib.dirstate import DirState
31
 
from bzrlib.osutils import parent_directories, pathjoin, splitpath
 
31
from . import cache_utf8, errors, osutils
 
32
from .dirstate import DirState
 
33
from .osutils import parent_directories, pathjoin, splitpath
32
34
 
33
35
 
34
36
# This is the Windows equivalent of ENOTDIR
40
42
cdef int ERROR_DIRECTORY
41
43
ERROR_DIRECTORY = 267
42
44
 
43
 
#python2.4 support, and other platform-dependent includes
44
45
cdef extern from "python-compat.h":
45
46
    unsigned long htonl(unsigned long)
46
47
 
97
98
    object PyTuple_GetItem_void_object "PyTuple_GET_ITEM" (void* tpl, int index)
98
99
    object PyTuple_GET_ITEM(object tpl, Py_ssize_t index)
99
100
 
 
101
    unsigned long PyInt_AsUnsignedLongMask(object number) except? -1
100
102
 
101
103
    char *PyString_AsString(object p)
102
104
    char *PyString_AsString_obj "PyString_AsString" (PyObject *string)
118
120
    # ??? memrchr is a GNU extension :(
119
121
    # void *memrchr(void *s, int c, size_t len)
120
122
 
 
123
# cimport all of the definitions we will need to access
 
124
from ._static_tuple_c cimport import_static_tuple_c, StaticTuple, \
 
125
    StaticTuple_New, StaticTuple_SET_ITEM
 
126
 
 
127
import_static_tuple_c()
121
128
 
122
129
cdef void* _my_memrchr(void *s, int c, size_t n): # cannot_raise
123
130
    # memrchr seems to be a GNU extension, so we have to implement it ourselves
610
617
        :param new_block: This is to let the caller know that it needs to
611
618
            create a new directory block to store the next entry.
612
619
        """
613
 
        cdef object path_name_file_id_key
 
620
        cdef StaticTuple path_name_file_id_key
 
621
        cdef StaticTuple tmp
614
622
        cdef char *entry_size_cstr
615
623
        cdef unsigned long int entry_size
616
624
        cdef char* executable_cstr
650
658
        # Build up the key that will be used.
651
659
        # By using <object>(void *) Pyrex will automatically handle the
652
660
        # Py_INCREF that we need.
653
 
        path_name_file_id_key = (<object>p_current_dirname[0],
654
 
                                 self.get_next_str(),
655
 
                                 self.get_next_str(),
656
 
                                )
 
661
        cur_dirname = <object>p_current_dirname[0]
 
662
        # Use StaticTuple_New to pre-allocate, rather than creating a regular
 
663
        # tuple and passing it to the StaticTuple constructor.
 
664
        # path_name_file_id_key = StaticTuple(<object>p_current_dirname[0],
 
665
        #                          self.get_next_str(),
 
666
        #                          self.get_next_str(),
 
667
        #                         )
 
668
        tmp = StaticTuple_New(3)
 
669
        Py_INCREF(cur_dirname); StaticTuple_SET_ITEM(tmp, 0, cur_dirname)
 
670
        cur_basename = self.get_next_str()
 
671
        cur_file_id = self.get_next_str()
 
672
        Py_INCREF(cur_basename); StaticTuple_SET_ITEM(tmp, 1, cur_basename)
 
673
        Py_INCREF(cur_file_id); StaticTuple_SET_ITEM(tmp, 2, cur_file_id)
 
674
        path_name_file_id_key = tmp
657
675
 
658
676
        # Parse all of the per-tree information. current has the information in
659
677
        # the same location as parent trees. The only difference is that 'info'
677
695
            executable_cstr = self.get_next(&cur_size)
678
696
            is_executable = (executable_cstr[0] == c'y')
679
697
            info = self.get_next_str()
680
 
            PyList_Append(trees, (
 
698
            # TODO: If we want to use StaticTuple_New here we need to be pretty
 
699
            #       careful. We are relying on a bit of Pyrex
 
700
            #       automatic-conversion from 'int' to PyInt, and that doesn't
 
701
            #       play well with the StaticTuple_SET_ITEM macro.
 
702
            #       Timing doesn't (yet) show a worthwile improvement in speed
 
703
            #       versus complexity and maintainability.
 
704
            # tmp = StaticTuple_New(5)
 
705
            # Py_INCREF(minikind); StaticTuple_SET_ITEM(tmp, 0, minikind)
 
706
            # Py_INCREF(fingerprint); StaticTuple_SET_ITEM(tmp, 1, fingerprint)
 
707
            # Py_INCREF(entry_size); StaticTuple_SET_ITEM(tmp, 2, entry_size)
 
708
            # Py_INCREF(is_executable); StaticTuple_SET_ITEM(tmp, 3, is_executable)
 
709
            # Py_INCREF(info); StaticTuple_SET_ITEM(tmp, 4, info)
 
710
            # PyList_Append(trees, tmp)
 
711
            PyList_Append(trees, StaticTuple(
681
712
                minikind,     # minikind
682
713
                fingerprint,  # fingerprint
683
714
                entry_size,   # size
782
813
_encode = binascii.b2a_base64
783
814
 
784
815
 
785
 
from struct import pack
786
816
cdef _pack_stat(stat_value):
787
817
    """return a string representing the stat value's key fields.
788
818
 
792
822
    cdef char result[6*4] # 6 long ints
793
823
    cdef int *aliased
794
824
    aliased = <int *>result
795
 
    aliased[0] = htonl(stat_value.st_size)
796
 
    aliased[1] = htonl(int(stat_value.st_mtime))
797
 
    aliased[2] = htonl(int(stat_value.st_ctime))
798
 
    aliased[3] = htonl(stat_value.st_dev)
799
 
    aliased[4] = htonl(stat_value.st_ino & 0xFFFFFFFF)
800
 
    aliased[5] = htonl(stat_value.st_mode)
 
825
    aliased[0] = htonl(PyInt_AsUnsignedLongMask(stat_value.st_size))
 
826
    # mtime and ctime will often be floats but get converted to PyInt within
 
827
    aliased[1] = htonl(PyInt_AsUnsignedLongMask(stat_value.st_mtime))
 
828
    aliased[2] = htonl(PyInt_AsUnsignedLongMask(stat_value.st_ctime))
 
829
    aliased[3] = htonl(PyInt_AsUnsignedLongMask(stat_value.st_dev))
 
830
    aliased[4] = htonl(PyInt_AsUnsignedLongMask(stat_value.st_ino))
 
831
    aliased[5] = htonl(PyInt_AsUnsignedLongMask(stat_value.st_mode))
801
832
    packed = PyString_FromStringAndSize(result, 6*4)
802
833
    return _encode(packed)[:-1]
803
834
 
804
835
 
 
836
def pack_stat(stat_value):
 
837
    """Convert stat value into a packed representation quickly with pyrex"""
 
838
    return _pack_stat(stat_value)
 
839
 
 
840
 
805
841
def update_entry(self, entry, abspath, stat_value):
806
842
    """Update the entry based on what is actually on disk.
807
843
 
837
873
    # _st mode of the compiled stat objects.
838
874
    cdef int minikind, saved_minikind
839
875
    cdef void * details
 
876
    cdef int worth_saving
840
877
    minikind = minikind_from_mode(stat_value.st_mode)
841
878
    if 0 == minikind:
842
879
        return None
871
908
    # If we have gotten this far, that means that we need to actually
872
909
    # process this entry.
873
910
    link_or_sha1 = None
 
911
    worth_saving = 1
874
912
    if minikind == c'f':
875
913
        executable = self._is_executable(stat_value.st_mode,
876
914
                                         saved_executable)
887
925
            entry[1][0] = ('f', link_or_sha1, stat_value.st_size,
888
926
                           executable, packed_stat)
889
927
        else:
890
 
            entry[1][0] = ('f', '', stat_value.st_size,
891
 
                           executable, DirState.NULLSTAT)
 
928
            # This file is not worth caching the sha1. Either it is too new, or
 
929
            # it is newly added. Regardless, the only things we are changing
 
930
            # are derived from the stat, and so are not worth caching. So we do
 
931
            # *not* set the IN_MEMORY_MODIFIED flag. (But we'll save the
 
932
            # updated values if there is *other* data worth saving.)
 
933
            entry[1][0] = ('f', '', stat_value.st_size, executable,
 
934
                           DirState.NULLSTAT)
 
935
            worth_saving = 0
892
936
    elif minikind == c'd':
893
 
        link_or_sha1 = None
894
937
        entry[1][0] = ('d', '', 0, False, packed_stat)
895
938
        if saved_minikind != c'd':
896
939
            # This changed from something into a directory. Make sure we
900
943
                self._get_block_entry_index(entry[0][0], entry[0][1], 0)
901
944
            self._ensure_block(block_index, entry_index,
902
945
                               pathjoin(entry[0][0], entry[0][1]))
 
946
        else:
 
947
            # Any changes are derived trivially from the stat object, not worth
 
948
            # re-writing a dirstate for just this
 
949
            worth_saving = 0
903
950
    elif minikind == c'l':
 
951
        if saved_minikind == c'l':
 
952
            # If the object hasn't changed kind, it isn't worth saving the
 
953
            # dirstate just for a symlink. The default is 'fast symlinks' which
 
954
            # save the target in the inode entry, rather than separately. So to
 
955
            # stat, we've already read everything off disk.
 
956
            worth_saving = 0
904
957
        link_or_sha1 = self._read_link(abspath, saved_link_or_sha1)
905
958
        if self._cutoff_time is None:
906
959
            self._sha_cutoff_time()
911
964
        else:
912
965
            entry[1][0] = ('l', '', stat_value.st_size,
913
966
                           False, DirState.NULLSTAT)
914
 
    self._dirblock_state = DirState.IN_MEMORY_MODIFIED
 
967
    if worth_saving:
 
968
        # Note, even though _mark_modified will only set
 
969
        # IN_MEMORY_HASH_MODIFIED, it still isn't worth 
 
970
        self._mark_modified([entry])
915
971
    return link_or_sha1
916
972
 
917
973
 
1219
1275
            else:
1220
1276
                try:
1221
1277
                    source_parent_id = self.old_dirname_to_file_id[old_dirname]
1222
 
                except KeyError:
 
1278
                except KeyError, _:
1223
1279
                    source_parent_entry = self.state._get_entry(self.source_index,
1224
1280
                                                           path_utf8=old_dirname)
1225
1281
                    source_parent_id = source_parent_entry[0][2]
1236
1292
            else:
1237
1293
                try:
1238
1294
                    target_parent_id = self.new_dirname_to_file_id[new_dirname]
1239
 
                except KeyError:
 
1295
                except KeyError, _:
1240
1296
                    # TODO: We don't always need to do the lookup, because the
1241
1297
                    #       parent entry will be the same as the source entry.
1242
1298
                    target_parent_entry = self.state._get_entry(self.target_index,
1478
1534
            # interface doesn't require it.
1479
1535
            try:
1480
1536
                self.current_root = self.search_specific_files.pop()
1481
 
            except KeyError:
 
1537
            except KeyError, _:
1482
1538
                raise StopIteration()
1483
1539
            self.searched_specific_files.add(self.current_root)
1484
1540
            # process the entries for this containing directory: the rest will be
1567
1623
                        #            and e.winerror == ERROR_DIRECTORY
1568
1624
                        try:
1569
1625
                            e_winerror = e.winerror
1570
 
                        except AttributeError:
 
1626
                        except AttributeError, _:
1571
1627
                            e_winerror = None
1572
1628
                        win_errors = (ERROR_DIRECTORY, ERROR_PATH_NOT_FOUND)
1573
1629
                        if (e.errno in win_errors or e_winerror in win_errors):
1656
1712
                    try:
1657
1713
                        self.current_dir_info = self.dir_iterator.next()
1658
1714
                        self.current_dir_list = self.current_dir_info[1]
1659
 
                    except StopIteration:
 
1715
                    except StopIteration, _:
1660
1716
                        self.current_dir_info = None
1661
1717
                else: #(dircmp > 0)
1662
1718
                    # We have a dirblock entry for this location, but there
1744
1800
                advance_entry = -1
1745
1801
                advance_path = -1
1746
1802
                result = None
 
1803
                changed = None
1747
1804
                path_handled = 0
1748
1805
                if current_entry is None:
1749
1806
                    # unversioned -  the check for path_handled when the path
1803
1860
                                and stat.S_IEXEC & current_path_info[3].st_mode)
1804
1861
                            try:
1805
1862
                                relpath_unicode = self.utf8_decode(current_path_info[0])[0]
1806
 
                            except UnicodeDecodeError:
 
1863
                            except UnicodeDecodeError, _:
1807
1864
                                raise errors.BadFilenameEncoding(
1808
1865
                                    current_path_info[0], osutils._fs_enc)
1809
1866
                            if changed is not None:
1851
1908
                try:
1852
1909
                    self.current_dir_info = self.dir_iterator.next()
1853
1910
                    self.current_dir_list = self.current_dir_info[1]
1854
 
                except StopIteration:
 
1911
                except StopIteration, _:
1855
1912
                    self.current_dir_info = None
1856
1913
 
1857
1914
    cdef object _next_consistent_entries(self):