~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/_dirstate_helpers_pyx.pyx

  • Committer: Martin Pool
  • Date: 2010-04-01 04:41:18 UTC
  • mto: This revision was merged to the branch mainline in revision 5128.
  • Revision ID: mbp@sourcefrog.net-20100401044118-shyctqc02ob08ngz
ignore .testrepository

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
# Copyright (C) 2007-2010 Canonical Ltd
 
1
# Copyright (C) 2007, 2008, 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()
126
121
 
127
122
cdef void* _my_memrchr(void *s, int c, size_t n): # cannot_raise
128
123
    # memrchr seems to be a GNU extension, so we have to implement it ourselves
615
610
        :param new_block: This is to let the caller know that it needs to
616
611
            create a new directory block to store the next entry.
617
612
        """
618
 
        cdef StaticTuple path_name_file_id_key
619
 
        cdef StaticTuple tmp
 
613
        cdef object path_name_file_id_key
620
614
        cdef char *entry_size_cstr
621
615
        cdef unsigned long int entry_size
622
616
        cdef char* executable_cstr
656
650
        # Build up the key that will be used.
657
651
        # By using <object>(void *) Pyrex will automatically handle the
658
652
        # Py_INCREF that we need.
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
 
653
        path_name_file_id_key = (<object>p_current_dirname[0],
 
654
                                 self.get_next_str(),
 
655
                                 self.get_next_str(),
 
656
                                )
673
657
 
674
658
        # Parse all of the per-tree information. current has the information in
675
659
        # the same location as parent trees. The only difference is that 'info'
693
677
            executable_cstr = self.get_next(&cur_size)
694
678
            is_executable = (executable_cstr[0] == c'y')
695
679
            info = self.get_next_str()
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(
 
680
            PyList_Append(trees, (
710
681
                minikind,     # minikind
711
682
                fingerprint,  # fingerprint
712
683
                entry_size,   # size
1248
1219
            else:
1249
1220
                try:
1250
1221
                    source_parent_id = self.old_dirname_to_file_id[old_dirname]
1251
 
                except KeyError, _:
 
1222
                except KeyError:
1252
1223
                    source_parent_entry = self.state._get_entry(self.source_index,
1253
1224
                                                           path_utf8=old_dirname)
1254
1225
                    source_parent_id = source_parent_entry[0][2]
1265
1236
            else:
1266
1237
                try:
1267
1238
                    target_parent_id = self.new_dirname_to_file_id[new_dirname]
1268
 
                except KeyError, _:
 
1239
                except KeyError:
1269
1240
                    # TODO: We don't always need to do the lookup, because the
1270
1241
                    #       parent entry will be the same as the source entry.
1271
1242
                    target_parent_entry = self.state._get_entry(self.target_index,
1507
1478
            # interface doesn't require it.
1508
1479
            try:
1509
1480
                self.current_root = self.search_specific_files.pop()
1510
 
            except KeyError, _:
 
1481
            except KeyError:
1511
1482
                raise StopIteration()
1512
1483
            self.searched_specific_files.add(self.current_root)
1513
1484
            # process the entries for this containing directory: the rest will be
1596
1567
                        #            and e.winerror == ERROR_DIRECTORY
1597
1568
                        try:
1598
1569
                            e_winerror = e.winerror
1599
 
                        except AttributeError, _:
 
1570
                        except AttributeError:
1600
1571
                            e_winerror = None
1601
1572
                        win_errors = (ERROR_DIRECTORY, ERROR_PATH_NOT_FOUND)
1602
1573
                        if (e.errno in win_errors or e_winerror in win_errors):
1685
1656
                    try:
1686
1657
                        self.current_dir_info = self.dir_iterator.next()
1687
1658
                        self.current_dir_list = self.current_dir_info[1]
1688
 
                    except StopIteration, _:
 
1659
                    except StopIteration:
1689
1660
                        self.current_dir_info = None
1690
1661
                else: #(dircmp > 0)
1691
1662
                    # We have a dirblock entry for this location, but there
1832
1803
                                and stat.S_IEXEC & current_path_info[3].st_mode)
1833
1804
                            try:
1834
1805
                                relpath_unicode = self.utf8_decode(current_path_info[0])[0]
1835
 
                            except UnicodeDecodeError, _:
 
1806
                            except UnicodeDecodeError:
1836
1807
                                raise errors.BadFilenameEncoding(
1837
1808
                                    current_path_info[0], osutils._fs_enc)
1838
1809
                            if changed is not None:
1880
1851
                try:
1881
1852
                    self.current_dir_info = self.dir_iterator.next()
1882
1853
                    self.current_dir_list = self.current_dir_info[1]
1883
 
                except StopIteration, _:
 
1854
                except StopIteration:
1884
1855
                    self.current_dir_info = None
1885
1856
 
1886
1857
    cdef object _next_consistent_entries(self):