/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/workingtree_4.py

Merge bzr.dev.

Show diffs side-by-side

added added

removed removed

Lines of Context:
49
49
    errors,
50
50
    generate_ids,
51
51
    globbing,
52
 
    hashcache,
53
52
    ignores,
54
53
    merge,
55
54
    osutils,
132
131
        """
133
132
        self._format = _format
134
133
        self.bzrdir = _bzrdir
135
 
        from bzrlib.trace import note, mutter
136
134
        assert isinstance(basedir, basestring), \
137
135
            "base directory %r is not a string" % basedir
138
136
        basedir = safe_unicode(basedir)
160
158
        state = self.current_dirstate()
161
159
        for f, file_id, kind in zip(files, ids, kinds):
162
160
            f = f.strip('/')
163
 
            assert '//' not in f
164
 
            assert '..' not in f
165
161
            if self.path2id(f):
166
162
                # special case tree root handling.
167
163
                if f == '' and self.path2id(f) == ROOT_ID:
272
268
        self._dirstate = dirstate.DirState.on_file(local_path)
273
269
        return self._dirstate
274
270
 
275
 
    def _directory_is_tree_reference(self, relpath):
276
 
        # as a special case, if a directory contains control files then 
277
 
        # it's a tree reference, except that the root of the tree is not
278
 
        return relpath and osutils.isdir(self.abspath(relpath) + u"/.bzr")
279
 
        # TODO: We could ask all the control formats whether they
280
 
        # recognize this directory, but at the moment there's no cheap api
281
 
        # to do that.  Since we probably can only nest bzr checkouts and
282
 
        # they always use this name it's ok for now.  -- mbp 20060306
283
 
        #
284
 
        # FIXME: There is an unhandled case here of a subdirectory
285
 
        # containing .bzr but not a branch; that will probably blow up
286
 
        # when you try to commit it.  It might happen if there is a
287
 
        # checkout in a subdirectory.  This can be avoided by not adding
288
 
        # it.  mbp 20070306
289
 
 
290
271
    def filter_unversioned_files(self, paths):
291
272
        """Filter out paths that are versioned.
292
273
 
470
451
 
471
452
    def has_id(self, file_id):
472
453
        state = self.current_dirstate()
473
 
        file_id = osutils.safe_file_id(file_id)
474
454
        row, parents = self._get_entry(file_id=file_id)
475
455
        if row is None:
476
456
            return False
480
460
    @needs_read_lock
481
461
    def id2path(self, file_id):
482
462
        "Convert a file-id to a path."
483
 
        file_id = osutils.safe_file_id(file_id)
484
463
        state = self.current_dirstate()
485
464
        entry = self._get_entry(file_id=file_id)
486
465
        if entry == (None, None):
494
473
 
495
474
            Note: The caller is expected to take a read-lock before calling this.
496
475
            """
497
 
            file_id = osutils.safe_file_id(file_id)
498
476
            entry = self._get_entry(file_id=file_id, path=path)
499
477
            if entry == (None, None):
500
478
                return False
506
484
            Note: The caller is expected to take a read-lock before calling this.
507
485
            """
508
486
            if not path:
509
 
                file_id = osutils.safe_file_id(file_id)
510
487
                path = self.id2path(file_id)
511
488
            mode = os.lstat(self.abspath(path)).st_mode
512
489
            return bool(stat.S_ISREG(mode) and stat.S_IEXEC & mode)
947
924
            if not all_versioned:
948
925
                raise errors.PathsNotVersionedError(paths)
949
926
        # -- remove redundancy in supplied paths to prevent over-scanning --
950
 
        search_paths = set()
951
 
        for path in paths:
952
 
            other_paths = paths.difference(set([path]))
953
 
            if not osutils.is_inside_any(other_paths, path):
954
 
                # this is a top level path, we must check it.
955
 
                search_paths.add(path)
 
927
        search_paths = osutils.minimum_path_selection(paths)
956
928
        # sketch: 
957
929
        # for all search_indexs in each path at or under each element of
958
930
        # search_paths, if the detail is relocated: add the id, and add the
1026
998
 
1027
999
        WorkingTree4 supplies revision_trees for any basis tree.
1028
1000
        """
1029
 
        revision_id = osutils.safe_revision_id(revision_id)
1030
1001
        dirstate = self.current_dirstate()
1031
1002
        parent_ids = dirstate.get_parent_ids()
1032
1003
        if revision_id not in parent_ids:
1039
1010
    @needs_tree_write_lock
1040
1011
    def set_last_revision(self, new_revision):
1041
1012
        """Change the last revision in the working tree."""
1042
 
        new_revision = osutils.safe_revision_id(new_revision)
1043
1013
        parents = self.get_parent_ids()
1044
1014
        if new_revision in (NULL_REVISION, None):
1045
1015
            assert len(parents) < 2, (
1063
1033
        :param revision_ids: The revision_ids to set as the parent ids of this
1064
1034
            working tree. Any of these may be ghosts.
1065
1035
        """
1066
 
        revision_ids = [osutils.safe_revision_id(r) for r in revision_ids]
1067
1036
        trees = []
1068
1037
        for revision_id in revision_ids:
1069
1038
            try:
1095
1064
        # convert absent trees to the null tree, which we convert back to
1096
1065
        # missing on access.
1097
1066
        for rev_id, tree in parents_list:
1098
 
            rev_id = osutils.safe_revision_id(rev_id)
1099
1067
            _mod_revision.check_not_reserved_id(rev_id)
1100
1068
            if tree is not None:
1101
1069
                real_trees.append((rev_id, tree))
1113
1081
        if state._dirblock_state == dirstate.DirState.IN_MEMORY_MODIFIED:
1114
1082
            self._make_dirty(reset_inventory=True)
1115
1083
 
 
1084
    def _sha_from_stat(self, path, stat_result):
 
1085
        """Get a sha digest from the tree's stat cache.
 
1086
 
 
1087
        The default implementation assumes no stat cache is present.
 
1088
 
 
1089
        :param path: The path.
 
1090
        :param stat_result: The stat result being looked up.
 
1091
        """
 
1092
        state = self.current_dirstate()
 
1093
        # XXX: should we make the path be passed in as utf8 ?
 
1094
        entry = state._get_entry(0, path_utf8=cache_utf8.encode(path))
 
1095
        tree_details = entry[1][0]
 
1096
        packed_stat = dirstate.pack_stat(stat_result)
 
1097
        if tree_details[4] == packed_stat:
 
1098
            return tree_details[1]
 
1099
        else:
 
1100
            return None
 
1101
 
1116
1102
    @needs_read_lock
1117
1103
    def supports_tree_reference(self):
1118
1104
        return self._repo_supports_tree_reference
1158
1144
            return
1159
1145
        state = self.current_dirstate()
1160
1146
        state._read_dirblocks_if_needed()
1161
 
        ids_to_unversion = set()
1162
 
        for file_id in file_ids:
1163
 
            ids_to_unversion.add(osutils.safe_file_id(file_id))
 
1147
        ids_to_unversion = set(file_ids)
1164
1148
        paths_to_unversion = set()
1165
1149
        # sketch:
1166
1150
        # check if the root is to be unversioned, if so, assert for now.
1273
1257
        These trees get an initial random root id, if their repository supports
1274
1258
        rich root data, TREE_ROOT otherwise.
1275
1259
        """
1276
 
        revision_id = osutils.safe_revision_id(revision_id)
1277
1260
        if not isinstance(a_bzrdir.transport, LocalTransport):
1278
1261
            raise errors.NotLocalUrl(a_bzrdir.transport.base)
1279
1262
        transport = a_bzrdir.get_workingtree_transport(self)
1345
1328
 
1346
1329
    def __init__(self, dirstate, revision_id, repository):
1347
1330
        self._dirstate = dirstate
1348
 
        self._revision_id = osutils.safe_revision_id(revision_id)
 
1331
        self._revision_id = revision_id
1349
1332
        self._repository = repository
1350
1333
        self._inventory = None
1351
1334
        self._locked = 0
1403
1386
        """
1404
1387
        if file_id is None and path is None:
1405
1388
            raise errors.BzrError('must supply file_id or path')
1406
 
        file_id = osutils.safe_file_id(file_id)
1407
1389
        if path is not None:
1408
1390
            path = path.encode('utf8')
1409
1391
        parent_index = self._get_parent_index()
1575
1557
    def kind(self, file_id):
1576
1558
        return self.inventory[file_id].kind
1577
1559
 
 
1560
    def path_content_summary(self, path):
 
1561
        """See Tree.path_content_summary."""
 
1562
        id = self.inventory.path2id(path)
 
1563
        if id is None:
 
1564
            return ('missing', None, None, None)
 
1565
        entry = self._inventory[id]
 
1566
        kind = entry.kind
 
1567
        if kind == 'file':
 
1568
            return (kind, entry.text_size, entry.executable, entry.text_sha1)
 
1569
        elif kind == 'symlink':
 
1570
            return (kind, None, None, entry.symlink_target)
 
1571
        else:
 
1572
            return (kind, None, None, None)
 
1573
 
1578
1574
    def is_executable(self, file_id, path=None):
1579
1575
        ie = self.inventory[file_id]
1580
1576
        if ie.kind != "file":
1717
1713
        # TODO: handle extra trees in the dirstate.
1718
1714
        # TODO: handle comparisons as an empty tree as a different special
1719
1715
        # case? mbp 20070226
1720
 
        if extra_trees or (self.source._revision_id == NULL_REVISION):
 
1716
        if (extra_trees or (self.source._revision_id == NULL_REVISION)
 
1717
            or specific_files == []):
1721
1718
            # we can't fast-path these cases (yet)
1722
1719
            for f in super(InterDirStateTree, self)._iter_changes(
1723
1720
                include_unchanged, specific_files, pb, extra_trees,