~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/workingtree_4.py

Upgraded to the latest bzr.dev

Show diffs side-by-side

added added

removed removed

Lines of Context:
99
99
# This is the Windows equivalent of ENOTDIR
100
100
# It is defined in pywin32.winerror, but we don't want a strong dependency for
101
101
# just an error code.
 
102
ERROR_PATH_NOT_FOUND = 3
102
103
ERROR_DIRECTORY = 267
103
104
 
104
105
 
563
564
                # set our support for tree references from the repository in
564
565
                # use.
565
566
                self._repo_supports_tree_reference = getattr(
566
 
                    self.branch.repository._format, "support_tree_reference",
 
567
                    self.branch.repository._format, "supports_tree_reference",
567
568
                    False)
568
569
            except:
569
570
                self._control_files.unlock()
583
584
                # set our support for tree references from the repository in
584
585
                # use.
585
586
                self._repo_supports_tree_reference = getattr(
586
 
                    self.branch.repository._format, "support_tree_reference",
 
587
                    self.branch.repository._format, "supports_tree_reference",
587
588
                    False)
588
589
            except:
589
590
                self._control_files.unlock()
809
810
                                     size=cur_details[2],
810
811
                                     to_block=to_block,
811
812
                                     to_key=to_key,
812
 
                                     to_path_utf8=to_rel_utf8)
 
813
                                     to_path_utf8=to_path_utf8)
813
814
                            if minikind == 'd':
814
815
                                # We need to move all the children of this
815
816
                                # entry
1202
1203
            for file_id in file_ids:
1203
1204
                self._inventory.remove_recursive_id(file_id)
1204
1205
 
 
1206
    @needs_read_lock
 
1207
    def _validate(self):
 
1208
        self._dirstate._validate()
 
1209
 
1205
1210
    @needs_tree_write_lock
1206
1211
    def _write_inventory(self, inv):
1207
1212
        """Write inventory as the current inventory."""
1225
1230
        - uses a LockDir to guard access to it.
1226
1231
    """
1227
1232
 
 
1233
    upgrade_recommended = False
 
1234
 
1228
1235
    def get_format_string(self):
1229
1236
        """See WorkingTreeFormat.get_format_string()."""
1230
1237
        return "Bazaar Working Tree Format 4 (bzr 0.15)\n"
1239
1246
        :param revision_id: allows creating a working tree at a different
1240
1247
        revision than the branch is at.
1241
1248
 
1242
 
        These trees get an initial random root id.
 
1249
        These trees get an initial random root id, if their repository supports
 
1250
        rich root data, TREE_ROOT otherwise.
1243
1251
        """
1244
1252
        revision_id = osutils.safe_revision_id(revision_id)
1245
1253
        if not isinstance(a_bzrdir.transport, LocalTransport):
1256
1264
        # write out new dirstate (must exist when we create the tree)
1257
1265
        state = dirstate.DirState.initialize(local_path)
1258
1266
        state.unlock()
 
1267
        del state
1259
1268
        wt = WorkingTree4(a_bzrdir.root_transport.local_abspath('.'),
1260
1269
                         branch,
1261
1270
                         _format=self,
1263
1272
                         _control_files=control_files)
1264
1273
        wt._new_tree()
1265
1274
        wt.lock_tree_write()
1266
 
        state._validate()
 
1275
        wt.current_dirstate()._validate()
1267
1276
        try:
1268
1277
            if revision_id in (None, NULL_REVISION):
1269
 
                wt._set_root_id(generate_ids.gen_root_id())
 
1278
                if branch.repository.supports_rich_root():
 
1279
                    wt._set_root_id(generate_ids.gen_root_id())
 
1280
                else:
 
1281
                    wt._set_root_id(ROOT_ID)
1270
1282
                wt.flush()
1271
1283
                wt.current_dirstate()._validate()
1272
1284
            wt.set_last_revision(revision_id)
2075
2087
                    # python 2.5 has e.errno == EINVAL,
2076
2088
                    #            and e.winerror == ERROR_DIRECTORY
2077
2089
                    e_winerror = getattr(e, 'winerror', None)
 
2090
                    win_errors = (ERROR_DIRECTORY, ERROR_PATH_NOT_FOUND)
2078
2091
                    # there may be directories in the inventory even though
2079
2092
                    # this path is not a file on disk: so mark it as end of
2080
2093
                    # iterator
2081
2094
                    if e.errno in (errno.ENOENT, errno.ENOTDIR, errno.EINVAL):
2082
2095
                        current_dir_info = None
2083
2096
                    elif (sys.platform == 'win32'
2084
 
                          and ERROR_DIRECTORY in (e.errno, e_winerror)):
 
2097
                          and (e.errno in win_errors
 
2098
                               or e_winerror in win_errors)):
2085
2099
                        current_dir_info = None
2086
2100
                    else:
2087
2101
                        raise
2107
2121
                        # this has two possibilities:
2108
2122
                        # A) it is versioned but empty, so there is no block for it
2109
2123
                        # B) it is not versioned.
2110
 
                        # in either case it was processed by the containing directories walk:
2111
 
                        # if it is root/foo, when we walked root we emitted it,
2112
 
                        # or if we ere given root/foo to walk specifically, we
2113
 
                        # emitted it when checking the walk-root entries
2114
 
                        # advance the iterator and loop - we dont need to emit it.
 
2124
 
 
2125
                        # if (A) then we need to recurse into it to check for
 
2126
                        # new unknown files or directories.
 
2127
                        # if (B) then we should ignore it, because we don't
 
2128
                        # recurse into unknown directories.
 
2129
                        if want_unversioned:
 
2130
                            path_index = 0
 
2131
                            while path_index < len(current_dir_info[1]):
 
2132
                                    current_path_info = current_dir_info[1][path_index]
 
2133
                                    if current_path_info[2] == 'directory':
 
2134
                                        if self.target._directory_is_tree_reference(
 
2135
                                            current_path_info[0].decode('utf8')):
 
2136
                                            current_path_info = current_path_info[:2] + \
 
2137
                                                ('tree-reference',) + current_path_info[3:]
 
2138
                                    new_executable = bool(
 
2139
                                        stat.S_ISREG(current_path_info[3].st_mode)
 
2140
                                        and stat.S_IEXEC & current_path_info[3].st_mode)
 
2141
                                    yield (None,
 
2142
                                        (None, utf8_decode_or_none(current_path_info[0])),
 
2143
                                        True,
 
2144
                                        (False, False),
 
2145
                                        (None, None),
 
2146
                                        (None, utf8_decode_or_none(current_path_info[1])),
 
2147
                                        (None, current_path_info[2]),
 
2148
                                        (None, new_executable))
 
2149
                                    # dont descend into this unversioned path if it is
 
2150
                                    # a dir
 
2151
                                    if current_path_info[2] in ('directory',
 
2152
                                                                'tree-reference'):
 
2153
                                        del current_dir_info[1][path_index]
 
2154
                                        path_index -= 1
 
2155
                                    path_index += 1
 
2156
 
 
2157
                        # This dir info has been handled, go to the next
2115
2158
                        try:
2116
2159
                            current_dir_info = dir_iterator.next()
2117
2160
                        except StopIteration:
2280
2323
                                new_executable = bool(
2281
2324
                                    stat.S_ISREG(current_path_info[3].st_mode)
2282
2325
                                    and stat.S_IEXEC & current_path_info[3].st_mode)
2283
 
                                if want_unversioned:
2284
 
                                    yield (None,
2285
 
                                        (None, utf8_decode_or_none(current_path_info[0])),
2286
 
                                        True,
2287
 
                                        (False, False),
2288
 
                                        (None, None),
2289
 
                                        (None, utf8_decode_or_none(current_path_info[1])),
2290
 
                                        (None, current_path_info[2]),
2291
 
                                        (None, new_executable))
 
2326
                                yield (None,
 
2327
                                    (None, utf8_decode_or_none(current_path_info[0])),
 
2328
                                    True,
 
2329
                                    (False, False),
 
2330
                                    (None, None),
 
2331
                                    (None, utf8_decode_or_none(current_path_info[1])),
 
2332
                                    (None, current_path_info[2]),
 
2333
                                    (None, new_executable))
2292
2334
                            # dont descend into this unversioned path if it is
2293
2335
                            # a dir
2294
2336
                            if current_path_info[2] in ('directory'):