~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/workingtree_4.py

  • Committer: Vincent Ladeuil
  • Date: 2008-01-29 08:40:53 UTC
  • mto: (3206.1.1 trunk)
  • mto: This revision was merged to the branch mainline in revision 3207.
  • Revision ID: v.ladeuil+lp@free.fr-20080129084053-sunwf549ox6zczqr
Fix two more leaked log files.

* bzrlib/tests/test_http.py:
(TestHttpProxyWhiteBox.tearDown): Call the base class tearDown.

Show diffs side-by-side

added added

removed removed

Lines of Context:
151
151
        self._dirstate = None
152
152
        self._inventory = None
153
153
        #-------------
 
154
        self._setup_directory_is_tree_reference()
 
155
        self._detect_case_handling()
154
156
 
155
157
    @needs_tree_write_lock
156
158
    def _add(self, files, ids, kinds):
492
494
 
493
495
            Note: The caller is expected to take a read-lock before calling this.
494
496
            """
 
497
            self._must_be_locked()
495
498
            if not path:
496
499
                path = self.id2path(file_id)
497
500
            mode = os.lstat(self.abspath(path)).st_mode
1255
1258
        """See WorkingTreeFormat.get_format_description()."""
1256
1259
        return "Working tree format 4"
1257
1260
 
1258
 
    def initialize(self, a_bzrdir, revision_id=None, from_branch=None):
 
1261
    def initialize(self, a_bzrdir, revision_id=None, from_branch=None,
 
1262
                   accelerator_tree=None):
1259
1263
        """See WorkingTreeFormat.initialize().
1260
1264
 
1261
1265
        :param revision_id: allows creating a working tree at a different
1262
1266
        revision than the branch is at.
 
1267
        :param accelerator_tree: A tree which can be used for retrieving file
 
1268
            contents more quickly than the revision tree, i.e. a workingtree.
 
1269
            The revision tree will be used for cases where accelerator_tree's
 
1270
            content is different.
1263
1271
 
1264
1272
        These trees get an initial random root id, if their repository supports
1265
1273
        rich root data, TREE_ROOT otherwise.
1296
1304
                else:
1297
1305
                    wt._set_root_id(ROOT_ID)
1298
1306
                wt.flush()
1299
 
            wt.set_last_revision(revision_id)
 
1307
            basis = None
 
1308
            # frequently, we will get here due to branching.  The accelerator
 
1309
            # tree will be the tree from the branch, so the desired basis
 
1310
            # tree will often be a parent of the accelerator tree.
 
1311
            if accelerator_tree is not None:
 
1312
                try:
 
1313
                    basis = accelerator_tree.revision_tree(revision_id)
 
1314
                except errors.NoSuchRevision:
 
1315
                    pass
 
1316
            if basis is None:
 
1317
                basis = branch.repository.revision_tree(revision_id)
 
1318
            if revision_id == NULL_REVISION:
 
1319
                parents_list = []
 
1320
            else:
 
1321
                parents_list = [(revision_id, basis)]
 
1322
            basis.lock_read()
 
1323
            wt.set_parent_trees(parents_list, allow_leftmost_as_ghost=True)
1300
1324
            wt.flush()
1301
 
            basis = wt.basis_tree()
1302
 
            basis.lock_read()
1303
1325
            # if the basis has a root id we have to use that; otherwise we use
1304
1326
            # a new random one
1305
1327
            basis_root_id = basis.get_root_id()
1306
1328
            if basis_root_id is not None:
1307
1329
                wt._set_root_id(basis_root_id)
1308
1330
                wt.flush()
1309
 
            transform.build_tree(basis, wt)
 
1331
            transform.build_tree(basis, wt, accelerator_tree)
1310
1332
            basis.unlock()
1311
1333
        finally:
1312
1334
            control_files.unlock()
1379
1401
    def get_root_id(self):
1380
1402
        return self.path2id('')
1381
1403
 
 
1404
    def id2path(self, file_id):
 
1405
        "Convert a file-id to a path."
 
1406
        entry = self._get_entry(file_id=file_id)
 
1407
        if entry == (None, None):
 
1408
            raise errors.NoSuchId(tree=self, file_id=file_id)
 
1409
        path_utf8 = osutils.pathjoin(entry[0][0], entry[0][1])
 
1410
        return path_utf8.decode('utf8')
 
1411
 
1382
1412
    def _get_parent_index(self):
1383
1413
        """Return the index in the dirstate referenced by this tree."""
1384
1414
        return self._dirstate.get_parent_ids().index(self._revision_id) + 1
1506
1536
        return StringIO(self.get_file_text(file_id))
1507
1537
 
1508
1538
    def get_file_lines(self, file_id):
1509
 
        ie = self.inventory[file_id]
1510
 
        return self._get_weave(file_id).get_lines(ie.revision)
 
1539
        entry = self._get_entry(file_id=file_id)[1]
 
1540
        if entry == None:
 
1541
            raise errors.NoSuchId(tree=self, file_id=file_id)
 
1542
        return self._get_weave(file_id).get_lines(entry[1][4])
1511
1543
 
1512
1544
    def get_file_size(self, file_id):
1513
1545
        return self.inventory[file_id].text_size
1565
1597
        return bool(self.path2id(filename))
1566
1598
 
1567
1599
    def kind(self, file_id):
1568
 
        return self.inventory[file_id].kind
 
1600
        entry = self._get_entry(file_id=file_id)[1]
 
1601
        if entry == None:
 
1602
            raise errors.NoSuchId(tree=self, file_id=file_id)
 
1603
        return dirstate.DirState._minikind_to_kind[entry[1][0]]
1569
1604
 
1570
1605
    def path_content_summary(self, path):
1571
1606
        """See Tree.path_content_summary."""
1721
1756
        # NB: show_status depends on being able to pass in non-versioned files
1722
1757
        # and report them as unknown
1723
1758
        # TODO: handle extra trees in the dirstate.
1724
 
        # TODO: handle comparisons as an empty tree as a different special
1725
 
        # case? mbp 20070226
1726
 
        if (extra_trees or (self.source._revision_id == NULL_REVISION)
1727
 
            or specific_files == []):
 
1759
        if (extra_trees or specific_files == []):
1728
1760
            # we can't fast-path these cases (yet)
1729
1761
            for f in super(InterDirStateTree, self)._iter_changes(
1730
1762
                include_unchanged, specific_files, pb, extra_trees,
1732
1764
                yield f
1733
1765
            return
1734
1766
        parent_ids = self.target.get_parent_ids()
1735
 
        assert (self.source._revision_id in parent_ids), \
 
1767
        assert (self.source._revision_id in parent_ids
 
1768
                or self.source._revision_id == NULL_REVISION), \
1736
1769
                "revision {%s} is not stored in {%s}, but %s " \
1737
1770
                "can only be used for trees stored in the dirstate" \
1738
1771
                % (self.source._revision_id, self.target, self._iter_changes)
1745
1778
                "Failure: source._revision_id: %s not in target.parent_ids(%s)" % (
1746
1779
                self.source._revision_id, parent_ids)
1747
1780
            source_index = 1 + parent_ids.index(self.source._revision_id)
1748
 
            indices = (source_index,target_index)
 
1781
            indices = (source_index, target_index)
1749
1782
        # -- make all specific_files utf8 --
1750
1783
        if specific_files:
1751
1784
            specific_files_utf8 = set()