~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/_dirstate_helpers_pyx.pyx

  • Committer: Jelmer Vernooij
  • Date: 2011-05-01 21:02:50 UTC
  • mto: This revision was merged to the branch mainline in revision 5842.
  • Revision ID: jelmer@samba.org-20110501210250-24jq6hrxxc9psvzf
Actually use branch format 5 in branch format 5 test.

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':
904
944
        link_or_sha1 = self._read_link(abspath, saved_link_or_sha1)
905
945
        if self._cutoff_time is None:
911
951
        else:
912
952
            entry[1][0] = ('l', '', stat_value.st_size,
913
953
                           False, DirState.NULLSTAT)
914
 
    self._dirblock_state = DirState.IN_MEMORY_MODIFIED
 
954
    if worth_saving:
 
955
        self._dirblock_state = DirState.IN_MEMORY_MODIFIED
915
956
    return link_or_sha1
916
957
 
917
958
 
1219
1260
            else:
1220
1261
                try:
1221
1262
                    source_parent_id = self.old_dirname_to_file_id[old_dirname]
1222
 
                except KeyError:
 
1263
                except KeyError, _:
1223
1264
                    source_parent_entry = self.state._get_entry(self.source_index,
1224
1265
                                                           path_utf8=old_dirname)
1225
1266
                    source_parent_id = source_parent_entry[0][2]
1236
1277
            else:
1237
1278
                try:
1238
1279
                    target_parent_id = self.new_dirname_to_file_id[new_dirname]
1239
 
                except KeyError:
 
1280
                except KeyError, _:
1240
1281
                    # TODO: We don't always need to do the lookup, because the
1241
1282
                    #       parent entry will be the same as the source entry.
1242
1283
                    target_parent_entry = self.state._get_entry(self.target_index,
1478
1519
            # interface doesn't require it.
1479
1520
            try:
1480
1521
                self.current_root = self.search_specific_files.pop()
1481
 
            except KeyError:
 
1522
            except KeyError, _:
1482
1523
                raise StopIteration()
1483
1524
            self.searched_specific_files.add(self.current_root)
1484
1525
            # process the entries for this containing directory: the rest will be
1567
1608
                        #            and e.winerror == ERROR_DIRECTORY
1568
1609
                        try:
1569
1610
                            e_winerror = e.winerror
1570
 
                        except AttributeError:
 
1611
                        except AttributeError, _:
1571
1612
                            e_winerror = None
1572
1613
                        win_errors = (ERROR_DIRECTORY, ERROR_PATH_NOT_FOUND)
1573
1614
                        if (e.errno in win_errors or e_winerror in win_errors):
1656
1697
                    try:
1657
1698
                        self.current_dir_info = self.dir_iterator.next()
1658
1699
                        self.current_dir_list = self.current_dir_info[1]
1659
 
                    except StopIteration:
 
1700
                    except StopIteration, _:
1660
1701
                        self.current_dir_info = None
1661
1702
                else: #(dircmp > 0)
1662
1703
                    # We have a dirblock entry for this location, but there
1803
1844
                                and stat.S_IEXEC & current_path_info[3].st_mode)
1804
1845
                            try:
1805
1846
                                relpath_unicode = self.utf8_decode(current_path_info[0])[0]
1806
 
                            except UnicodeDecodeError:
 
1847
                            except UnicodeDecodeError, _:
1807
1848
                                raise errors.BadFilenameEncoding(
1808
1849
                                    current_path_info[0], osutils._fs_enc)
1809
1850
                            if changed is not None:
1851
1892
                try:
1852
1893
                    self.current_dir_info = self.dir_iterator.next()
1853
1894
                    self.current_dir_list = self.current_dir_info[1]
1854
 
                except StopIteration:
 
1895
                except StopIteration, _:
1855
1896
                    self.current_dir_info = None
1856
1897
 
1857
1898
    cdef object _next_consistent_entries(self):