/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: Canonical.com Patch Queue Manager
  • Date: 2011-02-09 10:44:18 UTC
  • mfrom: (5652.1.3 thread-with-exception)
  • Revision ID: pqm@pqm.ubuntu.com-20110209104418-n3058l06ehubtl9a
(vila) Moves CatchingExceptionThread out of the bzrlib.tests hierarchy.
 (Vincent Ladeuil)

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
# Copyright (C) 2007-2010 Canonical Ltd
 
1
# Copyright (C) 2007-2011 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
from bzrlib.lock import LogicalLockResult
56
57
from bzrlib.mutabletree import needs_tree_write_lock
57
58
from bzrlib.osutils import (
58
59
    file_kind,
567
568
            return _mod_revision.NULL_REVISION
568
569
 
569
570
    def lock_read(self):
570
 
        """See Branch.lock_read, and WorkingTree.unlock."""
 
571
        """See Branch.lock_read, and WorkingTree.unlock.
 
572
 
 
573
        :return: A bzrlib.lock.LogicalLockResult.
 
574
        """
571
575
        self.branch.lock_read()
572
576
        try:
573
577
            self._control_files.lock_read()
586
590
        except:
587
591
            self.branch.unlock()
588
592
            raise
 
593
        return LogicalLockResult(self.unlock)
589
594
 
590
595
    def _lock_self_write(self):
591
596
        """This should be called after the branch is locked."""
606
611
        except:
607
612
            self.branch.unlock()
608
613
            raise
 
614
        return LogicalLockResult(self.unlock)
609
615
 
610
616
    def lock_tree_write(self):
611
 
        """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
        """
612
621
        self.branch.lock_read()
613
 
        self._lock_self_write()
 
622
        return self._lock_self_write()
614
623
 
615
624
    def lock_write(self):
616
 
        """See MutableTree.lock_write, and WorkingTree.unlock."""
 
625
        """See MutableTree.lock_write, and WorkingTree.unlock.
 
626
 
 
627
        :return: A bzrlib.lock.LogicalLockResult.
 
628
        """
617
629
        self.branch.lock_write()
618
 
        self._lock_self_write()
 
630
        return self._lock_self_write()
619
631
 
620
632
    @needs_tree_write_lock
621
633
    def move(self, from_paths, to_dir, after=False):
1235
1247
        # have to change the legacy inventory too.
1236
1248
        if self._inventory is not None:
1237
1249
            for file_id in file_ids:
1238
 
                self._inventory.remove_recursive_id(file_id)
 
1250
                if self._inventory.has_id(file_id):
 
1251
                    self._inventory.remove_recursive_id(file_id)
1239
1252
 
1240
1253
    @needs_tree_write_lock
1241
1254
    def rename_one(self, from_rel, to_rel, after=False):
1280
1293
            self._inventory = inv
1281
1294
        self.flush()
1282
1295
 
 
1296
    @needs_tree_write_lock
 
1297
    def reset_state(self, revision_ids=None):
 
1298
        """Reset the state of the working tree.
 
1299
 
 
1300
        This does a hard-reset to a last-known-good state. This is a way to
 
1301
        fix if something got corrupted (like the .bzr/checkout/dirstate file)
 
1302
        """
 
1303
        if revision_ids is None:
 
1304
            revision_ids = self.get_parent_ids()
 
1305
        if not revision_ids:
 
1306
            base_tree = self.branch.repository.revision_tree(
 
1307
                _mod_revision.NULL_REVISION)
 
1308
            trees = []
 
1309
        else:
 
1310
            trees = zip(revision_ids,
 
1311
                        self.branch.repository.revision_trees(revision_ids))
 
1312
            base_tree = trees[0][1]
 
1313
        state = self.current_dirstate()
 
1314
        # We don't support ghosts yet
 
1315
        state.set_state_from_scratch(base_tree.inventory, trees, [])
 
1316
 
1283
1317
 
1284
1318
class ContentFilterAwareSHA1Provider(dirstate.SHA1Provider):
1285
1319
 
1317
1351
    def _file_content_summary(self, path, stat_result):
1318
1352
        # This is to support the somewhat obsolete path_content_summary method
1319
1353
        # with content filtering: see
1320
 
        # <https://bugs.edge.launchpad.net/bzr/+bug/415508>.
 
1354
        # <https://bugs.launchpad.net/bzr/+bug/415508>.
1321
1355
        #
1322
1356
        # If the dirstate cache is up to date and knows the hash and size,
1323
1357
        # return that.
1725
1759
                elif kind == 'directory':
1726
1760
                    parent_ies[(dirname + '/' + name).strip('/')] = inv_entry
1727
1761
                elif kind == 'symlink':
1728
 
                    inv_entry.executable = False
1729
 
                    inv_entry.text_size = None
1730
1762
                    inv_entry.symlink_target = utf8_decode(fingerprint)[0]
1731
1763
                elif kind == 'tree-reference':
1732
1764
                    inv_entry.reference_revision = fingerprint or None
1856
1888
    def is_executable(self, file_id, path=None):
1857
1889
        ie = self.inventory[file_id]
1858
1890
        if ie.kind != "file":
1859
 
            return None
 
1891
            return False
1860
1892
        return ie.executable
1861
1893
 
 
1894
    def is_locked(self):
 
1895
        return self._locked
 
1896
 
1862
1897
    def list_files(self, include_root=False, from_dir=None, recursive=True):
1863
1898
        # We use a standard implementation, because DirStateRevisionTree is
1864
1899
        # dealing with one of the parents of the current state
1877
1912
            yield path, 'V', entry.kind, entry.file_id, entry
1878
1913
 
1879
1914
    def lock_read(self):
1880
 
        """Lock the tree for a set of operations."""
 
1915
        """Lock the tree for a set of operations.
 
1916
 
 
1917
        :return: A bzrlib.lock.LogicalLockResult.
 
1918
        """
1881
1919
        if not self._locked:
1882
1920
            self._repository.lock_read()
1883
1921
            if self._dirstate._lock_token is None:
1884
1922
                self._dirstate.lock_read()
1885
1923
                self._dirstate_locked = True
1886
1924
        self._locked += 1
 
1925
        return LogicalLockResult(self.unlock)
1887
1926
 
1888
1927
    def _must_be_locked(self):
1889
1928
        if not self._locked: