~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/workingtree.py

  • Committer: Canonical.com Patch Queue Manager
  • Date: 2010-04-08 06:17:41 UTC
  • mfrom: (4797.33.16 apport)
  • Revision ID: pqm@pqm.ubuntu.com-20100408061741-m7vl6z97vu33riv7
(robertc) Make sure ExecutablePath and InterpreterPath are set in
        Apport. (Martin Pool, James Westby, lp:528114)

Show diffs side-by-side

added added

removed removed

Lines of Context:
29
29
WorkingTree.open(dir).
30
30
"""
31
31
 
 
32
# TODO: Give the workingtree sole responsibility for the working inventory;
 
33
# remove the variable and references to it from the branch.  This may require
 
34
# updating the commit code so as to update the inventory within the working
 
35
# copy, and making sure there's only one WorkingTree for any directory on disk.
 
36
# At the moment they may alias the inventory and have old copies of it in
 
37
# memory.  (Now done? -- mbp 20060309)
32
38
 
33
39
from cStringIO import StringIO
34
40
import os
61
67
    revisiontree,
62
68
    trace,
63
69
    transform,
64
 
    transport,
65
70
    ui,
66
71
    views,
67
72
    xml5,
68
73
    xml7,
69
74
    )
 
75
import bzrlib.branch
 
76
from bzrlib.transport import get_transport
70
77
from bzrlib.workingtree_4 import (
71
78
    WorkingTreeFormat4,
72
79
    WorkingTreeFormat5,
76
83
 
77
84
from bzrlib import symbol_versioning
78
85
from bzrlib.decorators import needs_read_lock, needs_write_lock
79
 
from bzrlib.lock import LogicalLockResult
80
86
from bzrlib.lockable_files import LockableFiles
81
87
from bzrlib.lockdir import LockDir
82
88
import bzrlib.mutabletree
95
101
from bzrlib.filters import filtered_input_file
96
102
from bzrlib.trace import mutter, note
97
103
from bzrlib.transport.local import LocalTransport
 
104
from bzrlib.progress import ProgressPhase
98
105
from bzrlib.revision import CURRENT_REVISION
99
106
from bzrlib.rio import RioReader, rio_file, Stanza
100
107
from bzrlib.symbol_versioning import (
167
174
        return ''
168
175
 
169
176
 
170
 
class WorkingTree(bzrlib.mutabletree.MutableTree,
171
 
    bzrdir.ControlComponent):
 
177
class WorkingTree(bzrlib.mutabletree.MutableTree):
172
178
    """Working copy tree.
173
179
 
174
180
    The inventory is held in the `Branch` working-inventory, and the
176
182
 
177
183
    It is possible for a `WorkingTree` to have a filename which is
178
184
    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
185
    """
183
186
 
184
187
    # override this to set the strategy for storing views
250
253
        self._rules_searcher = None
251
254
        self.views = self._make_views()
252
255
 
253
 
    @property
254
 
    def user_transport(self):
255
 
        return self.bzrdir.user_transport
256
 
 
257
 
    @property
258
 
    def control_transport(self):
259
 
        return self._transport
260
 
 
261
256
    def _detect_case_handling(self):
262
257
        wt_trans = self.bzrdir.get_workingtree_transport(None)
263
258
        try:
371
366
                return True, None
372
367
            else:
373
368
                return True, tree
374
 
        t = transport.get_transport(location)
375
 
        iterator = bzrdir.BzrDir.find_bzrdirs(t, evaluate=evaluate,
 
369
        transport = get_transport(location)
 
370
        iterator = bzrdir.BzrDir.find_bzrdirs(transport, evaluate=evaluate,
376
371
                                              list_current=list_current)
377
 
        return [tr for tr in iterator if tr is not None]
 
372
        return [t for t in iterator if t is not None]
378
373
 
379
374
    # should be deprecated - this is slow and in any case treating them as a
380
375
    # container is (we now know) bad style -- mbp 20070302
465
460
        return (file_obj, stat_value)
466
461
 
467
462
    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()
 
463
        return self.get_file(file_id, path=path, filtered=filtered).read()
473
464
 
474
465
    def get_file_byname(self, filename, filtered=True):
475
466
        path = self.abspath(filename)
529
520
 
530
521
        # Now we have the parents of this content
531
522
        annotator = self.branch.repository.texts.get_annotator()
532
 
        text = self.get_file_text(file_id)
 
523
        text = self.get_file(file_id).read()
533
524
        this_key =(file_id, default_revision)
534
525
        annotator.add_special_text(this_key, file_parent_keys, text)
535
526
        annotations = [(key[-1], line)
1805
1796
            raise errors.ObjectNotLocked(self)
1806
1797
 
1807
1798
    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
 
        """
 
1799
        """See Branch.lock_read, and WorkingTree.unlock."""
1814
1800
        if not self.is_locked():
1815
1801
            self._reset_data()
1816
1802
        self.branch.lock_read()
1817
1803
        try:
1818
 
            self._control_files.lock_read()
1819
 
            return LogicalLockResult(self.unlock)
 
1804
            return self._control_files.lock_read()
1820
1805
        except:
1821
1806
            self.branch.unlock()
1822
1807
            raise
1823
1808
 
1824
1809
    def lock_tree_write(self):
1825
 
        """See MutableTree.lock_tree_write, and WorkingTree.unlock.
1826
 
 
1827
 
        :return: A bzrlib.lock.LogicalLockResult.
1828
 
        """
 
1810
        """See MutableTree.lock_tree_write, and WorkingTree.unlock."""
1829
1811
        if not self.is_locked():
1830
1812
            self._reset_data()
1831
1813
        self.branch.lock_read()
1832
1814
        try:
1833
 
            self._control_files.lock_write()
1834
 
            return LogicalLockResult(self.unlock)
 
1815
            return self._control_files.lock_write()
1835
1816
        except:
1836
1817
            self.branch.unlock()
1837
1818
            raise
1838
1819
 
1839
1820
    def lock_write(self):
1840
 
        """See MutableTree.lock_write, and WorkingTree.unlock.
1841
 
 
1842
 
        :return: A bzrlib.lock.LogicalLockResult.
1843
 
        """
 
1821
        """See MutableTree.lock_write, and WorkingTree.unlock."""
1844
1822
        if not self.is_locked():
1845
1823
            self._reset_data()
1846
1824
        self.branch.lock_write()
1847
1825
        try:
1848
 
            self._control_files.lock_write()
1849
 
            return LogicalLockResult(self.unlock)
 
1826
            return self._control_files.lock_write()
1850
1827
        except:
1851
1828
            self.branch.unlock()
1852
1829
            raise
1977
1954
        def recurse_directory_to_add_files(directory):
1978
1955
            # Recurse directory and add all files
1979
1956
            # so we can check if they have changed.
1980
 
            for parent_info, file_infos in self.walkdirs(directory):
 
1957
            for parent_info, file_infos in\
 
1958
                self.walkdirs(directory):
1981
1959
                for relpath, basename, kind, lstat, fileid, kind in file_infos:
1982
1960
                    # Is it versioned or ignored?
1983
1961
                    if self.path2id(relpath) or self.is_ignored(relpath):
2018
1996
                            # ... but not ignored
2019
1997
                            has_changed_files = True
2020
1998
                            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.
 
1999
                    elif content_change and (kind[1] is not None):
 
2000
                        # Versioned and changed, but not deleted
2025
2001
                        has_changed_files = True
2026
2002
                        break
2027
2003
 
2282
2258
            last_rev = _mod_revision.NULL_REVISION
2283
2259
        if revision is None:
2284
2260
            revision = self.branch.last_revision()
 
2261
        else:
 
2262
            if revision not in self.branch.revision_history():
 
2263
                raise errors.NoSuchRevision(self.branch, revision)
2285
2264
 
2286
2265
        old_tip = old_tip or _mod_revision.NULL_REVISION
2287
2266
 
2658
2637
 
2659
2638
        In Format2 WorkingTrees we have a single lock for the branch and tree
2660
2639
        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
2640
        """
2665
2641
        self.branch.lock_write()
2666
2642
        try:
2667
 
            self._control_files.lock_write()
2668
 
            return self
 
2643
            return self._control_files.lock_write()
2669
2644
        except:
2670
2645
            self.branch.unlock()
2671
2646
            raise