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

  • Committer: Robert Collins
  • Date: 2010-05-06 11:08:10 UTC
  • mto: This revision was merged to the branch mainline in revision 5223.
  • Revision ID: robertc@robertcollins.net-20100506110810-h3j07fh5gmw54s25
Cleaner matcher matching revised unlocking protocol.

Show diffs side-by-side

added added

removed removed

Lines of Context:
61
61
    revisiontree,
62
62
    trace,
63
63
    transform,
64
 
    transport,
65
64
    ui,
66
65
    views,
67
66
    xml5,
68
67
    xml7,
69
68
    )
 
69
import bzrlib.branch
 
70
from bzrlib.transport import get_transport
70
71
from bzrlib.workingtree_4 import (
71
72
    WorkingTreeFormat4,
72
73
    WorkingTreeFormat5,
76
77
 
77
78
from bzrlib import symbol_versioning
78
79
from bzrlib.decorators import needs_read_lock, needs_write_lock
79
 
from bzrlib.lock import LogicalLockResult
80
80
from bzrlib.lockable_files import LockableFiles
81
81
from bzrlib.lockdir import LockDir
82
82
import bzrlib.mutabletree
176
176
 
177
177
    It is possible for a `WorkingTree` to have a filename which is
178
178
    not listed in the Inventory and vice versa.
179
 
 
180
 
    :ivar basedir: The root of the tree on disk. This is a unicode path object
181
 
        (as opposed to a URL).
182
179
    """
183
180
 
184
181
    # override this to set the strategy for storing views
371
368
                return True, None
372
369
            else:
373
370
                return True, tree
374
 
        t = transport.get_transport(location)
375
 
        iterator = bzrdir.BzrDir.find_bzrdirs(t, evaluate=evaluate,
 
371
        transport = get_transport(location)
 
372
        iterator = bzrdir.BzrDir.find_bzrdirs(transport, evaluate=evaluate,
376
373
                                              list_current=list_current)
377
 
        return [tr for tr in iterator if tr is not None]
 
374
        return [t for t in iterator if t is not None]
378
375
 
379
376
    # should be deprecated - this is slow and in any case treating them as a
380
377
    # container is (we now know) bad style -- mbp 20070302
465
462
        return (file_obj, stat_value)
466
463
 
467
464
    def get_file_text(self, file_id, path=None, filtered=True):
468
 
        my_file = self.get_file(file_id, path=path, filtered=filtered)
469
 
        try:
470
 
            return my_file.read()
471
 
        finally:
472
 
            my_file.close()
 
465
        return self.get_file(file_id, path=path, filtered=filtered).read()
473
466
 
474
467
    def get_file_byname(self, filename, filtered=True):
475
468
        path = self.abspath(filename)
529
522
 
530
523
        # Now we have the parents of this content
531
524
        annotator = self.branch.repository.texts.get_annotator()
532
 
        text = self.get_file_text(file_id)
 
525
        text = self.get_file(file_id).read()
533
526
        this_key =(file_id, default_revision)
534
527
        annotator.add_special_text(this_key, file_parent_keys, text)
535
528
        annotations = [(key[-1], line)
1805
1798
            raise errors.ObjectNotLocked(self)
1806
1799
 
1807
1800
    def lock_read(self):
1808
 
        """Lock the tree for reading.
1809
 
 
1810
 
        This also locks the branch, and can be unlocked via self.unlock().
1811
 
 
1812
 
        :return: A bzrlib.lock.LogicalLockResult.
1813
 
        """
 
1801
        """See Branch.lock_read, and WorkingTree.unlock."""
1814
1802
        if not self.is_locked():
1815
1803
            self._reset_data()
1816
1804
        self.branch.lock_read()
1817
1805
        try:
1818
 
            self._control_files.lock_read()
1819
 
            return LogicalLockResult(self.unlock)
 
1806
            return self._control_files.lock_read()
1820
1807
        except:
1821
1808
            self.branch.unlock()
1822
1809
            raise
1823
1810
 
1824
1811
    def lock_tree_write(self):
1825
 
        """See MutableTree.lock_tree_write, and WorkingTree.unlock.
1826
 
 
1827
 
        :return: A bzrlib.lock.LogicalLockResult.
1828
 
        """
 
1812
        """See MutableTree.lock_tree_write, and WorkingTree.unlock."""
1829
1813
        if not self.is_locked():
1830
1814
            self._reset_data()
1831
1815
        self.branch.lock_read()
1832
1816
        try:
1833
 
            self._control_files.lock_write()
1834
 
            return LogicalLockResult(self.unlock)
 
1817
            return self._control_files.lock_write()
1835
1818
        except:
1836
1819
            self.branch.unlock()
1837
1820
            raise
1838
1821
 
1839
1822
    def lock_write(self):
1840
 
        """See MutableTree.lock_write, and WorkingTree.unlock.
1841
 
 
1842
 
        :return: A bzrlib.lock.LogicalLockResult.
1843
 
        """
 
1823
        """See MutableTree.lock_write, and WorkingTree.unlock."""
1844
1824
        if not self.is_locked():
1845
1825
            self._reset_data()
1846
1826
        self.branch.lock_write()
1847
1827
        try:
1848
 
            self._control_files.lock_write()
1849
 
            return LogicalLockResult(self.unlock)
 
1828
            return self._control_files.lock_write()
1850
1829
        except:
1851
1830
            self.branch.unlock()
1852
1831
            raise
1977
1956
        def recurse_directory_to_add_files(directory):
1978
1957
            # Recurse directory and add all files
1979
1958
            # so we can check if they have changed.
1980
 
            for parent_info, file_infos in self.walkdirs(directory):
 
1959
            for parent_info, file_infos in\
 
1960
                self.walkdirs(directory):
1981
1961
                for relpath, basename, kind, lstat, fileid, kind in file_infos:
1982
1962
                    # Is it versioned or ignored?
1983
1963
                    if self.path2id(relpath) or self.is_ignored(relpath):
2018
1998
                            # ... but not ignored
2019
1999
                            has_changed_files = True
2020
2000
                            break
2021
 
                    elif (content_change and (kind[1] is not None) and
2022
 
                            osutils.is_inside_any(files, path[1])):
2023
 
                        # Versioned and changed, but not deleted, and still
2024
 
                        # in one of the dirs to be deleted.
 
2001
                    elif content_change and (kind[1] is not None):
 
2002
                        # Versioned and changed, but not deleted
2025
2003
                        has_changed_files = True
2026
2004
                        break
2027
2005
 
2658
2636
 
2659
2637
        In Format2 WorkingTrees we have a single lock for the branch and tree
2660
2638
        so lock_tree_write() degrades to lock_write().
2661
 
 
2662
 
        :return: An object with an unlock method which will release the lock
2663
 
            obtained.
2664
2639
        """
2665
2640
        self.branch.lock_write()
2666
2641
        try:
2667
 
            self._control_files.lock_write()
2668
 
            return self
 
2642
            return self._control_files.lock_write()
2669
2643
        except:
2670
2644
            self.branch.unlock()
2671
2645
            raise