/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

  • 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) 2005, 2006, 2007, 2008, 2009 Canonical Ltd
 
1
# Copyright (C) 2007-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
53
53
from bzrlib.decorators import needs_read_lock, needs_write_lock
54
54
from bzrlib.filters import filtered_input_file, internal_size_sha_file_byname
55
55
from bzrlib.inventory import Inventory, ROOT_ID, entry_factory
56
 
import bzrlib.mutabletree
 
56
from bzrlib.lock import LogicalLockResult
57
57
from bzrlib.mutabletree import needs_tree_write_lock
58
58
from bzrlib.osutils import (
59
59
    file_kind,
568
568
            return _mod_revision.NULL_REVISION
569
569
 
570
570
    def lock_read(self):
571
 
        """See Branch.lock_read, and WorkingTree.unlock."""
 
571
        """See Branch.lock_read, and WorkingTree.unlock.
 
572
 
 
573
        :return: A bzrlib.lock.LogicalLockResult.
 
574
        """
572
575
        self.branch.lock_read()
573
576
        try:
574
577
            self._control_files.lock_read()
587
590
        except:
588
591
            self.branch.unlock()
589
592
            raise
 
593
        return LogicalLockResult(self.unlock)
590
594
 
591
595
    def _lock_self_write(self):
592
596
        """This should be called after the branch is locked."""
607
611
        except:
608
612
            self.branch.unlock()
609
613
            raise
 
614
        return LogicalLockResult(self.unlock)
610
615
 
611
616
    def lock_tree_write(self):
612
 
        """See MutableTree.lock_tree_write, and WorkingTree.unlock."""
 
617
        """See MutableTree.lock_tree_write, and WorkingTree.unlock.
 
618
 
 
619
        :return: A bzrlib.lock.LogicalLockResult.
 
620
        """
613
621
        self.branch.lock_read()
614
 
        self._lock_self_write()
 
622
        return self._lock_self_write()
615
623
 
616
624
    def lock_write(self):
617
 
        """See MutableTree.lock_write, and WorkingTree.unlock."""
 
625
        """See MutableTree.lock_write, and WorkingTree.unlock.
 
626
 
 
627
        :return: A bzrlib.lock.LogicalLockResult.
 
628
        """
618
629
        self.branch.lock_write()
619
 
        self._lock_self_write()
 
630
        return self._lock_self_write()
620
631
 
621
632
    @needs_tree_write_lock
622
633
    def move(self, from_paths, to_dir, after=False):
1267
1278
        if self._dirty:
1268
1279
            raise AssertionError("attempting to write an inventory when the "
1269
1280
                "dirstate is dirty will lose pending changes")
1270
 
        self.current_dirstate().set_state_from_inventory(inv)
1271
 
        self._make_dirty(reset_inventory=False)
1272
 
        if self._inventory is not None:
 
1281
        had_inventory = self._inventory is not None
 
1282
        # Setting self._inventory = None forces the dirstate to regenerate the
 
1283
        # working inventory. We do this because self.inventory may be inv, or
 
1284
        # may have been modified, and either case would prevent a clean delta
 
1285
        # being created.
 
1286
        self._inventory = None
 
1287
        # generate a delta,
 
1288
        delta = inv._make_delta(self.inventory)
 
1289
        # and apply it.
 
1290
        self.apply_inventory_delta(delta)
 
1291
        if had_inventory:
1273
1292
            self._inventory = inv
1274
1293
        self.flush()
1275
1294
 
1310
1329
    def _file_content_summary(self, path, stat_result):
1311
1330
        # This is to support the somewhat obsolete path_content_summary method
1312
1331
        # with content filtering: see
1313
 
        # <https://bugs.edge.launchpad.net/bzr/+bug/415508>.
 
1332
        # <https://bugs.launchpad.net/bzr/+bug/415508>.
1314
1333
        #
1315
1334
        # If the dirstate cache is up to date and knows the hash and size,
1316
1335
        # return that.
1364
1383
 
1365
1384
 
1366
1385
class DirStateWorkingTreeFormat(WorkingTreeFormat3):
 
1386
 
1367
1387
    def initialize(self, a_bzrdir, revision_id=None, from_branch=None,
1368
1388
                   accelerator_tree=None, hardlink=False):
1369
1389
        """See WorkingTreeFormat.initialize().
1439
1459
                if basis_root_id is not None:
1440
1460
                    wt._set_root_id(basis_root_id)
1441
1461
                    wt.flush()
1442
 
                # If content filtering is supported, do not use the accelerator
1443
 
                # tree - the cost of transforming the content both ways and
1444
 
                # checking for changed content can outweight the gains it gives.
1445
 
                # Note: do NOT move this logic up higher - using the basis from
1446
 
                # the accelerator tree is still desirable because that can save
1447
 
                # a minute or more of processing on large trees!
1448
 
                # The original tree may not have the same content filters
1449
 
                # applied so we can't safely build the inventory delta from
1450
 
                # the source tree.
1451
1462
                if wt.supports_content_filtering():
1452
 
                    if hardlink:
1453
 
                        # see https://bugs.edge.launchpad.net/bzr/+bug/408193
1454
 
                        trace.warning("hardlinking working copy files is not currently "
1455
 
                            "supported in %r" % (wt,))
1456
 
                    accelerator_tree = None
 
1463
                    # The original tree may not have the same content filters
 
1464
                    # applied so we can't safely build the inventory delta from
 
1465
                    # the source tree.
1457
1466
                    delta_from_tree = False
1458
1467
                else:
1459
1468
                    delta_from_tree = True
1758
1767
            return None
1759
1768
        parent_index = self._get_parent_index()
1760
1769
        last_changed_revision = entry[1][parent_index][4]
1761
 
        return self._repository.get_revision(last_changed_revision).timestamp
 
1770
        try:
 
1771
            rev = self._repository.get_revision(last_changed_revision)
 
1772
        except errors.NoSuchRevision:
 
1773
            raise errors.FileTimestampUnavailable(self.id2path(file_id))
 
1774
        return rev.timestamp
1762
1775
 
1763
1776
    def get_file_sha1(self, file_id, path=None, stat_value=None):
1764
1777
        entry = self._get_entry(file_id=file_id, path=path)
1831
1844
        entry = self._get_entry(file_id=file_id)[1]
1832
1845
        if entry is None:
1833
1846
            raise errors.NoSuchId(tree=self, file_id=file_id)
1834
 
        return dirstate.DirState._minikind_to_kind[entry[1][0]]
 
1847
        parent_index = self._get_parent_index()
 
1848
        return dirstate.DirState._minikind_to_kind[entry[parent_index][0]]
1835
1849
 
1836
1850
    def stored_kind(self, file_id):
1837
1851
        """See Tree.stored_kind"""
1857
1871
            return None
1858
1872
        return ie.executable
1859
1873
 
 
1874
    def is_locked(self):
 
1875
        return self._locked
 
1876
 
1860
1877
    def list_files(self, include_root=False, from_dir=None, recursive=True):
1861
1878
        # We use a standard implementation, because DirStateRevisionTree is
1862
1879
        # dealing with one of the parents of the current state
1875
1892
            yield path, 'V', entry.kind, entry.file_id, entry
1876
1893
 
1877
1894
    def lock_read(self):
1878
 
        """Lock the tree for a set of operations."""
 
1895
        """Lock the tree for a set of operations.
 
1896
 
 
1897
        :return: A bzrlib.lock.LogicalLockResult.
 
1898
        """
1879
1899
        if not self._locked:
1880
1900
            self._repository.lock_read()
1881
1901
            if self._dirstate._lock_token is None:
1882
1902
                self._dirstate.lock_read()
1883
1903
                self._dirstate_locked = True
1884
1904
        self._locked += 1
 
1905
        return LogicalLockResult(self.unlock)
1885
1906
 
1886
1907
    def _must_be_locked(self):
1887
1908
        if not self._locked:
1977
1998
        return result
1978
1999
 
1979
2000
    @classmethod
1980
 
    def make_source_parent_tree_compiled_dirstate(klass, test_case, source, target):
 
2001
    def make_source_parent_tree_compiled_dirstate(klass, test_case, source,
 
2002
                                                  target):
1981
2003
        from bzrlib.tests.test__dirstate_helpers import \
1982
 
            CompiledDirstateHelpersFeature
1983
 
        if not CompiledDirstateHelpersFeature.available():
1984
 
            from bzrlib.tests import UnavailableFeature
1985
 
            raise UnavailableFeature(CompiledDirstateHelpersFeature)
 
2004
            compiled_dirstate_helpers_feature
 
2005
        test_case.requireFeature(compiled_dirstate_helpers_feature)
1986
2006
        from bzrlib._dirstate_helpers_pyx import ProcessEntryC
1987
2007
        result = klass.make_source_parent_tree(source, target)
1988
2008
        result[1]._iter_changes = ProcessEntryC
2019
2039
            output. An unversioned file is defined as one with (False, False)
2020
2040
            for the versioned pair.
2021
2041
        """
2022
 
        # NB: show_status depends on being able to pass in non-versioned files
2023
 
        # and report them as unknown
2024
2042
        # TODO: handle extra trees in the dirstate.
2025
2043
        if (extra_trees or specific_files == []):
2026
2044
            # we can't fast-path these cases (yet)