~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/_dirstate_helpers_pyx.pyx

  • Committer: Martin von Gagern
  • Date: 2011-09-19 08:49:15 UTC
  • mto: This revision was merged to the branch mainline in revision 6148.
  • Revision ID: martin.vgagern@gmx.net-20110919084915-vbumflqq3xqm1vez
Avoid using deprecated api in the unit tests for bzrlib.missing.

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
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()
121
126
 
122
127
cdef void* _my_memrchr(void *s, int c, size_t n): # cannot_raise
123
128
    # memrchr seems to be a GNU extension, so we have to implement it ourselves
610
615
        :param new_block: This is to let the caller know that it needs to
611
616
            create a new directory block to store the next entry.
612
617
        """
613
 
        cdef object path_name_file_id_key
 
618
        cdef StaticTuple path_name_file_id_key
 
619
        cdef StaticTuple tmp
614
620
        cdef char *entry_size_cstr
615
621
        cdef unsigned long int entry_size
616
622
        cdef char* executable_cstr
650
656
        # Build up the key that will be used.
651
657
        # By using <object>(void *) Pyrex will automatically handle the
652
658
        # 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
 
                                )
 
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
657
673
 
658
674
        # Parse all of the per-tree information. current has the information in
659
675
        # the same location as parent trees. The only difference is that 'info'
677
693
            executable_cstr = self.get_next(&cur_size)
678
694
            is_executable = (executable_cstr[0] == c'y')
679
695
            info = self.get_next_str()
680
 
            PyList_Append(trees, (
 
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(
681
710
                minikind,     # minikind
682
711
                fingerprint,  # fingerprint
683
712
                entry_size,   # size
837
866
    # _st mode of the compiled stat objects.
838
867
    cdef int minikind, saved_minikind
839
868
    cdef void * details
 
869
    cdef int worth_saving
840
870
    minikind = minikind_from_mode(stat_value.st_mode)
841
871
    if 0 == minikind:
842
872
        return None
871
901
    # If we have gotten this far, that means that we need to actually
872
902
    # process this entry.
873
903
    link_or_sha1 = None
 
904
    worth_saving = 1
874
905
    if minikind == c'f':
875
906
        executable = self._is_executable(stat_value.st_mode,
876
907
                                         saved_executable)
887
918
            entry[1][0] = ('f', link_or_sha1, stat_value.st_size,
888
919
                           executable, packed_stat)
889
920
        else:
890
 
            entry[1][0] = ('f', '', stat_value.st_size,
891
 
                           executable, DirState.NULLSTAT)
 
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
892
929
    elif minikind == c'd':
893
 
        link_or_sha1 = None
894
930
        entry[1][0] = ('d', '', 0, False, packed_stat)
895
931
        if saved_minikind != c'd':
896
932
            # This changed from something into a directory. Make sure we
900
936
                self._get_block_entry_index(entry[0][0], entry[0][1], 0)
901
937
            self._ensure_block(block_index, entry_index,
902
938
                               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
903
943
    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
904
950
        link_or_sha1 = self._read_link(abspath, saved_link_or_sha1)
905
951
        if self._cutoff_time is None:
906
952
            self._sha_cutoff_time()
911
957
        else:
912
958
            entry[1][0] = ('l', '', stat_value.st_size,
913
959
                           False, DirState.NULLSTAT)
914
 
    self._dirblock_state = DirState.IN_MEMORY_MODIFIED
 
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])
915
964
    return link_or_sha1
916
965
 
917
966
 
1219
1268
            else:
1220
1269
                try:
1221
1270
                    source_parent_id = self.old_dirname_to_file_id[old_dirname]
1222
 
                except KeyError:
 
1271
                except KeyError, _:
1223
1272
                    source_parent_entry = self.state._get_entry(self.source_index,
1224
1273
                                                           path_utf8=old_dirname)
1225
1274
                    source_parent_id = source_parent_entry[0][2]
1236
1285
            else:
1237
1286
                try:
1238
1287
                    target_parent_id = self.new_dirname_to_file_id[new_dirname]
1239
 
                except KeyError:
 
1288
                except KeyError, _:
1240
1289
                    # TODO: We don't always need to do the lookup, because the
1241
1290
                    #       parent entry will be the same as the source entry.
1242
1291
                    target_parent_entry = self.state._get_entry(self.target_index,
1478
1527
            # interface doesn't require it.
1479
1528
            try:
1480
1529
                self.current_root = self.search_specific_files.pop()
1481
 
            except KeyError:
 
1530
            except KeyError, _:
1482
1531
                raise StopIteration()
1483
1532
            self.searched_specific_files.add(self.current_root)
1484
1533
            # process the entries for this containing directory: the rest will be
1567
1616
                        #            and e.winerror == ERROR_DIRECTORY
1568
1617
                        try:
1569
1618
                            e_winerror = e.winerror
1570
 
                        except AttributeError:
 
1619
                        except AttributeError, _:
1571
1620
                            e_winerror = None
1572
1621
                        win_errors = (ERROR_DIRECTORY, ERROR_PATH_NOT_FOUND)
1573
1622
                        if (e.errno in win_errors or e_winerror in win_errors):
1656
1705
                    try:
1657
1706
                        self.current_dir_info = self.dir_iterator.next()
1658
1707
                        self.current_dir_list = self.current_dir_info[1]
1659
 
                    except StopIteration:
 
1708
                    except StopIteration, _:
1660
1709
                        self.current_dir_info = None
1661
1710
                else: #(dircmp > 0)
1662
1711
                    # We have a dirblock entry for this location, but there
1744
1793
                advance_entry = -1
1745
1794
                advance_path = -1
1746
1795
                result = None
 
1796
                changed = None
1747
1797
                path_handled = 0
1748
1798
                if current_entry is None:
1749
1799
                    # unversioned -  the check for path_handled when the path
1803
1853
                                and stat.S_IEXEC & current_path_info[3].st_mode)
1804
1854
                            try:
1805
1855
                                relpath_unicode = self.utf8_decode(current_path_info[0])[0]
1806
 
                            except UnicodeDecodeError:
 
1856
                            except UnicodeDecodeError, _:
1807
1857
                                raise errors.BadFilenameEncoding(
1808
1858
                                    current_path_info[0], osutils._fs_enc)
1809
1859
                            if changed is not None:
1851
1901
                try:
1852
1902
                    self.current_dir_info = self.dir_iterator.next()
1853
1903
                    self.current_dir_list = self.current_dir_info[1]
1854
 
                except StopIteration:
 
1904
                except StopIteration, _:
1855
1905
                    self.current_dir_info = None
1856
1906
 
1857
1907
    cdef object _next_consistent_entries(self):