~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/workingtree_4.py

(jameinel) Fix bug #397739,
 resolve 'lp:foo' locally as long as we have a launchpad-login to use
 bzr+ssh. (John A Meinel)

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,
569
570
    def lock_read(self):
570
571
        """See Branch.lock_read, and WorkingTree.unlock.
571
572
 
572
 
        :return: An object with an unlock method which will release the lock
573
 
            obtained.
 
573
        :return: A bzrlib.lock.LogicalLockResult.
574
574
        """
575
575
        self.branch.lock_read()
576
576
        try:
590
590
        except:
591
591
            self.branch.unlock()
592
592
            raise
593
 
        return self
 
593
        return LogicalLockResult(self.unlock)
594
594
 
595
595
    def _lock_self_write(self):
596
596
        """This should be called after the branch is locked."""
611
611
        except:
612
612
            self.branch.unlock()
613
613
            raise
614
 
        return self
 
614
        return LogicalLockResult(self.unlock)
615
615
 
616
616
    def lock_tree_write(self):
617
617
        """See MutableTree.lock_tree_write, and WorkingTree.unlock.
618
618
 
619
 
        :return: An object with an unlock method which will release the lock
620
 
            obtained.
 
619
        :return: A bzrlib.lock.LogicalLockResult.
621
620
        """
622
621
        self.branch.lock_read()
623
622
        return self._lock_self_write()
625
624
    def lock_write(self):
626
625
        """See MutableTree.lock_write, and WorkingTree.unlock.
627
626
 
628
 
        :return: An object with an unlock method which will release the lock
629
 
            obtained.
 
627
        :return: A bzrlib.lock.LogicalLockResult.
630
628
        """
631
629
        self.branch.lock_write()
632
630
        return self._lock_self_write()
1249
1247
        # have to change the legacy inventory too.
1250
1248
        if self._inventory is not None:
1251
1249
            for file_id in file_ids:
1252
 
                self._inventory.remove_recursive_id(file_id)
 
1250
                if self._inventory.has_id(file_id):
 
1251
                    self._inventory.remove_recursive_id(file_id)
1253
1252
 
1254
1253
    @needs_tree_write_lock
1255
1254
    def rename_one(self, from_rel, to_rel, after=False):
1294
1293
            self._inventory = inv
1295
1294
        self.flush()
1296
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
 
1297
1317
 
1298
1318
class ContentFilterAwareSHA1Provider(dirstate.SHA1Provider):
1299
1319
 
1331
1351
    def _file_content_summary(self, path, stat_result):
1332
1352
        # This is to support the somewhat obsolete path_content_summary method
1333
1353
        # with content filtering: see
1334
 
        # <https://bugs.edge.launchpad.net/bzr/+bug/415508>.
 
1354
        # <https://bugs.launchpad.net/bzr/+bug/415508>.
1335
1355
        #
1336
1356
        # If the dirstate cache is up to date and knows the hash and size,
1337
1357
        # return that.
1386
1406
 
1387
1407
class DirStateWorkingTreeFormat(WorkingTreeFormat3):
1388
1408
 
 
1409
    missing_parent_conflicts = True
 
1410
 
1389
1411
    def initialize(self, a_bzrdir, revision_id=None, from_branch=None,
1390
1412
                   accelerator_tree=None, hardlink=False):
1391
1413
        """See WorkingTreeFormat.initialize().
1739
1761
                elif kind == 'directory':
1740
1762
                    parent_ies[(dirname + '/' + name).strip('/')] = inv_entry
1741
1763
                elif kind == 'symlink':
1742
 
                    inv_entry.executable = False
1743
 
                    inv_entry.text_size = None
1744
1764
                    inv_entry.symlink_target = utf8_decode(fingerprint)[0]
1745
1765
                elif kind == 'tree-reference':
1746
1766
                    inv_entry.reference_revision = fingerprint or None
1870
1890
    def is_executable(self, file_id, path=None):
1871
1891
        ie = self.inventory[file_id]
1872
1892
        if ie.kind != "file":
1873
 
            return None
 
1893
            return False
1874
1894
        return ie.executable
1875
1895
 
1876
1896
    def is_locked(self):
1896
1916
    def lock_read(self):
1897
1917
        """Lock the tree for a set of operations.
1898
1918
 
1899
 
        :return: An object with an unlock method which will release the lock
1900
 
            obtained.
 
1919
        :return: A bzrlib.lock.LogicalLockResult.
1901
1920
        """
1902
1921
        if not self._locked:
1903
1922
            self._repository.lock_read()
1905
1924
                self._dirstate.lock_read()
1906
1925
                self._dirstate_locked = True
1907
1926
        self._locked += 1
1908
 
        return self
 
1927
        return LogicalLockResult(self.unlock)
1909
1928
 
1910
1929
    def _must_be_locked(self):
1911
1930
        if not self._locked: