~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/_dirstate_helpers_pyx.pyx

  • Committer: Vincent Ladeuil
  • Date: 2010-04-12 16:54:35 UTC
  • mto: (5148.1.1 integration)
  • mto: This revision was merged to the branch mainline in revision 5151.
  • Revision ID: v.ladeuil+lp@free.fr-20100412165435-gzdnwuybj9rvddiz
Fix bug #519319 by defaulting to a warning for dirty trees.

* bzrlib/mutabletree.py:
(MutableTree.warn_if_changed_or_out_of_date): Factor out the
checks done by send, push and dpush.

* bzrlib/send.py:
(send): Use warn_if_changed_or_out_of_date().

* bzrlib/foreign.py:
(cmd_dpush.run): Use warn_if_changed_or_out_of_date().

* bzrlib/builtins.py:
(cmd_push.run): Use warn_if_changed_or_out_of_date().

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
866
837
    # _st mode of the compiled stat objects.
867
838
    cdef int minikind, saved_minikind
868
839
    cdef void * details
869
 
    cdef int worth_saving
870
840
    minikind = minikind_from_mode(stat_value.st_mode)
871
841
    if 0 == minikind:
872
842
        return None
901
871
    # If we have gotten this far, that means that we need to actually
902
872
    # process this entry.
903
873
    link_or_sha1 = None
904
 
    worth_saving = 1
905
874
    if minikind == c'f':
906
875
        executable = self._is_executable(stat_value.st_mode,
907
876
                                         saved_executable)
918
887
            entry[1][0] = ('f', link_or_sha1, stat_value.st_size,
919
888
                           executable, packed_stat)
920
889
        else:
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
 
890
            entry[1][0] = ('f', '', stat_value.st_size,
 
891
                           executable, DirState.NULLSTAT)
929
892
    elif minikind == c'd':
 
893
        link_or_sha1 = None
930
894
        entry[1][0] = ('d', '', 0, False, packed_stat)
931
895
        if saved_minikind != c'd':
932
896
            # This changed from something into a directory. Make sure we
936
900
                self._get_block_entry_index(entry[0][0], entry[0][1], 0)
937
901
            self._ensure_block(block_index, entry_index,
938
902
                               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
943
903
    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
950
904
        link_or_sha1 = self._read_link(abspath, saved_link_or_sha1)
951
905
        if self._cutoff_time is None:
952
906
            self._sha_cutoff_time()
957
911
        else:
958
912
            entry[1][0] = ('l', '', stat_value.st_size,
959
913
                           False, DirState.NULLSTAT)
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])
 
914
    self._dirblock_state = DirState.IN_MEMORY_MODIFIED
964
915
    return link_or_sha1
965
916
 
966
917
 
1268
1219
            else:
1269
1220
                try:
1270
1221
                    source_parent_id = self.old_dirname_to_file_id[old_dirname]
1271
 
                except KeyError, _:
 
1222
                except KeyError:
1272
1223
                    source_parent_entry = self.state._get_entry(self.source_index,
1273
1224
                                                           path_utf8=old_dirname)
1274
1225
                    source_parent_id = source_parent_entry[0][2]
1285
1236
            else:
1286
1237
                try:
1287
1238
                    target_parent_id = self.new_dirname_to_file_id[new_dirname]
1288
 
                except KeyError, _:
 
1239
                except KeyError:
1289
1240
                    # TODO: We don't always need to do the lookup, because the
1290
1241
                    #       parent entry will be the same as the source entry.
1291
1242
                    target_parent_entry = self.state._get_entry(self.target_index,
1527
1478
            # interface doesn't require it.
1528
1479
            try:
1529
1480
                self.current_root = self.search_specific_files.pop()
1530
 
            except KeyError, _:
 
1481
            except KeyError:
1531
1482
                raise StopIteration()
1532
1483
            self.searched_specific_files.add(self.current_root)
1533
1484
            # process the entries for this containing directory: the rest will be
1616
1567
                        #            and e.winerror == ERROR_DIRECTORY
1617
1568
                        try:
1618
1569
                            e_winerror = e.winerror
1619
 
                        except AttributeError, _:
 
1570
                        except AttributeError:
1620
1571
                            e_winerror = None
1621
1572
                        win_errors = (ERROR_DIRECTORY, ERROR_PATH_NOT_FOUND)
1622
1573
                        if (e.errno in win_errors or e_winerror in win_errors):
1705
1656
                    try:
1706
1657
                        self.current_dir_info = self.dir_iterator.next()
1707
1658
                        self.current_dir_list = self.current_dir_info[1]
1708
 
                    except StopIteration, _:
 
1659
                    except StopIteration:
1709
1660
                        self.current_dir_info = None
1710
1661
                else: #(dircmp > 0)
1711
1662
                    # We have a dirblock entry for this location, but there
1793
1744
                advance_entry = -1
1794
1745
                advance_path = -1
1795
1746
                result = None
1796
 
                changed = None
1797
1747
                path_handled = 0
1798
1748
                if current_entry is None:
1799
1749
                    # unversioned -  the check for path_handled when the path
1853
1803
                                and stat.S_IEXEC & current_path_info[3].st_mode)
1854
1804
                            try:
1855
1805
                                relpath_unicode = self.utf8_decode(current_path_info[0])[0]
1856
 
                            except UnicodeDecodeError, _:
 
1806
                            except UnicodeDecodeError:
1857
1807
                                raise errors.BadFilenameEncoding(
1858
1808
                                    current_path_info[0], osutils._fs_enc)
1859
1809
                            if changed is not None:
1901
1851
                try:
1902
1852
                    self.current_dir_info = self.dir_iterator.next()
1903
1853
                    self.current_dir_list = self.current_dir_info[1]
1904
 
                except StopIteration, _:
 
1854
                except StopIteration:
1905
1855
                    self.current_dir_info = None
1906
1856
 
1907
1857
    cdef object _next_consistent_entries(self):