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

  • Committer: Martin
  • Date: 2010-05-25 17:27:52 UTC
  • mfrom: (5254 +trunk)
  • mto: This revision was merged to the branch mainline in revision 5257.
  • Revision ID: gzlist@googlemail.com-20100525172752-amm089xcikv968sw
Merge bzr.dev to unite with similar changes already made

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
# Copyright (C) 2007, 2008 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
119
119
    # void *memrchr(void *s, int c, size_t len)
120
120
 
121
121
 
122
 
cdef void* _my_memrchr(void *s, int c, size_t n):
 
122
cdef void* _my_memrchr(void *s, int c, size_t n): # cannot_raise
123
123
    # memrchr seems to be a GNU extension, so we have to implement it ourselves
124
124
    cdef char *pos
125
125
    cdef char *start
156
156
        return None
157
157
    return <char*>found - <char*>_s
158
158
 
 
159
 
159
160
cdef object safe_string_from_size(char *s, Py_ssize_t size):
160
161
    if size < 0:
161
 
        # XXX: On 64-bit machines the <int> cast causes a C compiler warning.
162
162
        raise AssertionError(
163
 
            'tried to create a string with an invalid size: %d @0x%x'
164
 
            % (size, <int>s))
 
163
            'tried to create a string with an invalid size: %d'
 
164
            % (size))
165
165
    return PyString_FromStringAndSize(s, size)
166
166
 
167
167
 
168
 
cdef int _is_aligned(void *ptr):
 
168
cdef int _is_aligned(void *ptr): # cannot_raise
169
169
    """Is this pointer aligned to an integer size offset?
170
170
 
171
171
    :return: 1 if this pointer is aligned, 0 otherwise.
173
173
    return ((<intptr_t>ptr) & ((sizeof(int))-1)) == 0
174
174
 
175
175
 
176
 
cdef int _cmp_by_dirs(char *path1, int size1, char *path2, int size2):
 
176
cdef int _cmp_by_dirs(char *path1, int size1, char *path2, int size2): # cannot_raise
177
177
    cdef unsigned char *cur1
178
178
    cdef unsigned char *cur2
179
179
    cdef unsigned char *end1
295
295
 
296
296
 
297
297
cdef int _cmp_path_by_dirblock_intern(char *path1, int path1_len,
298
 
                                      char *path2, int path2_len):
 
298
                                      char *path2, int path2_len): # cannot_raise
299
299
    """Compare two paths by what directory they are in.
300
300
 
301
301
    see ``_cmp_path_by_dirblock`` for details.
768
768
    state._dirblock_state = DirState.IN_MEMORY_UNMODIFIED
769
769
 
770
770
 
771
 
cdef int minikind_from_mode(int mode):
 
771
cdef int minikind_from_mode(int mode): # cannot_raise
772
772
    # in order of frequency:
773
773
    if S_ISREG(mode):
774
774
        return c"f"
915
915
    return link_or_sha1
916
916
 
917
917
 
918
 
cdef char _minikind_from_string(object string):
 
918
# TODO: Do we want to worry about exceptions here?
 
919
cdef char _minikind_from_string(object string) except? -1:
919
920
    """Convert a python string to a char."""
920
921
    return PyString_AsString(string)[0]
921
922
 
953
954
    raise KeyError(PyString_FromStringAndSize(_minikind, 1))
954
955
 
955
956
 
956
 
cdef int _versioned_minikind(char minikind):
 
957
cdef int _versioned_minikind(char minikind): # cannot_raise
957
958
    """Return non-zero if minikind is in fltd"""
958
959
    return (minikind == c'f' or
959
960
            minikind == c'd' or
1202
1203
                        content_change = 0
1203
1204
                    target_exec = False
1204
1205
                else:
1205
 
                    raise Exception, "unknown kind %s" % path_info[2]
 
1206
                    if path is None:
 
1207
                        path = self.pathjoin(old_dirname, old_basename)
 
1208
                    raise errors.BadFileKindError(path, path_info[2])
1206
1209
            if source_minikind == c'd':
1207
1210
                if path is None:
1208
1211
                    old_path = path = self.pathjoin(old_dirname, old_basename)
1216
1219
            else:
1217
1220
                try:
1218
1221
                    source_parent_id = self.old_dirname_to_file_id[old_dirname]
1219
 
                except KeyError:
 
1222
                except KeyError, _:
1220
1223
                    source_parent_entry = self.state._get_entry(self.source_index,
1221
1224
                                                           path_utf8=old_dirname)
1222
1225
                    source_parent_id = source_parent_entry[0][2]
1233
1236
            else:
1234
1237
                try:
1235
1238
                    target_parent_id = self.new_dirname_to_file_id[new_dirname]
1236
 
                except KeyError:
 
1239
                except KeyError, _:
1237
1240
                    # TODO: We don't always need to do the lookup, because the
1238
1241
                    #       parent entry will be the same as the source entry.
1239
1242
                    target_parent_entry = self.state._get_entry(self.target_index,
1371
1374
    def iter_changes(self):
1372
1375
        return self
1373
1376
 
1374
 
    cdef void _gather_result_for_consistency(self, result):
 
1377
    cdef int _gather_result_for_consistency(self, result) except -1:
1375
1378
        """Check a result we will yield to make sure we are consistent later.
1376
1379
        
1377
1380
        This gathers result's parents into a set to output later.
1379
1382
        :param result: A result tuple.
1380
1383
        """
1381
1384
        if not self.partial or not result[0]:
1382
 
            return
 
1385
            return 0
1383
1386
        self.seen_ids.add(result[0])
1384
1387
        new_path = result[1][1]
1385
1388
        if new_path:
1389
1392
            # Add the root directory which parent_directories does not
1390
1393
            # provide.
1391
1394
            self.search_specific_file_parents.add('')
 
1395
        return 0
1392
1396
 
1393
 
    cdef void _update_current_block(self):
 
1397
    cdef int _update_current_block(self) except -1:
1394
1398
        if (self.block_index < len(self.state._dirblocks) and
1395
1399
            osutils.is_inside(self.current_root, self.state._dirblocks[self.block_index][0])):
1396
1400
            self.current_block = self.state._dirblocks[self.block_index]
1399
1403
        else:
1400
1404
            self.current_block = None
1401
1405
            self.current_block_list = None
 
1406
        return 0
1402
1407
 
1403
1408
    def __next__(self):
1404
1409
        # Simple thunk to allow tail recursion without pyrex confusion
1473
1478
            # interface doesn't require it.
1474
1479
            try:
1475
1480
                self.current_root = self.search_specific_files.pop()
1476
 
            except KeyError:
 
1481
            except KeyError, _:
1477
1482
                raise StopIteration()
1478
1483
            self.searched_specific_files.add(self.current_root)
1479
1484
            # process the entries for this containing directory: the rest will be
1562
1567
                        #            and e.winerror == ERROR_DIRECTORY
1563
1568
                        try:
1564
1569
                            e_winerror = e.winerror
1565
 
                        except AttributeError:
 
1570
                        except AttributeError, _:
1566
1571
                            e_winerror = None
1567
1572
                        win_errors = (ERROR_DIRECTORY, ERROR_PATH_NOT_FOUND)
1568
1573
                        if (e.errno in win_errors or e_winerror in win_errors):
1651
1656
                    try:
1652
1657
                        self.current_dir_info = self.dir_iterator.next()
1653
1658
                        self.current_dir_list = self.current_dir_info[1]
1654
 
                    except StopIteration:
 
1659
                    except StopIteration, _:
1655
1660
                        self.current_dir_info = None
1656
1661
                else: #(dircmp > 0)
1657
1662
                    # We have a dirblock entry for this location, but there
1798
1803
                                and stat.S_IEXEC & current_path_info[3].st_mode)
1799
1804
                            try:
1800
1805
                                relpath_unicode = self.utf8_decode(current_path_info[0])[0]
1801
 
                            except UnicodeDecodeError:
 
1806
                            except UnicodeDecodeError, _:
1802
1807
                                raise errors.BadFilenameEncoding(
1803
1808
                                    current_path_info[0], osutils._fs_enc)
1804
1809
                            if changed is not None:
1846
1851
                try:
1847
1852
                    self.current_dir_info = self.dir_iterator.next()
1848
1853
                    self.current_dir_list = self.current_dir_info[1]
1849
 
                except StopIteration:
 
1854
                except StopIteration, _:
1850
1855
                    self.current_dir_info = None
1851
1856
 
1852
1857
    cdef object _next_consistent_entries(self):