~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/workingtree.py

  • Committer: Gary van der Merwe
  • Date: 2010-08-02 19:56:52 UTC
  • mfrom: (5050.3.18 2.2)
  • mto: (5050.3.19 2.2)
  • mto: This revision was merged to the branch mainline in revision 5371.
  • Revision ID: garyvdm@gmail.com-20100802195652-o1ppjemhwrr98i61
MergeĀ lp:bzr/2.2.

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)
38
32
 
39
33
from cStringIO import StringIO
40
34
import os
67
61
    revisiontree,
68
62
    trace,
69
63
    transform,
 
64
    transport,
70
65
    ui,
71
66
    views,
72
67
    xml5,
73
68
    xml7,
74
69
    )
75
 
import bzrlib.branch
76
 
from bzrlib.transport import get_transport
77
70
from bzrlib.workingtree_4 import (
78
71
    WorkingTreeFormat4,
79
72
    WorkingTreeFormat5,
83
76
 
84
77
from bzrlib import symbol_versioning
85
78
from bzrlib.decorators import needs_read_lock, needs_write_lock
 
79
from bzrlib.lock import LogicalLockResult
86
80
from bzrlib.lockable_files import LockableFiles
87
81
from bzrlib.lockdir import LockDir
88
82
import bzrlib.mutabletree
101
95
from bzrlib.filters import filtered_input_file
102
96
from bzrlib.trace import mutter, note
103
97
from bzrlib.transport.local import LocalTransport
104
 
from bzrlib.progress import ProgressPhase
105
98
from bzrlib.revision import CURRENT_REVISION
106
99
from bzrlib.rio import RioReader, rio_file, Stanza
107
100
from bzrlib.symbol_versioning import (
174
167
        return ''
175
168
 
176
169
 
177
 
class WorkingTree(bzrlib.mutabletree.MutableTree):
 
170
class WorkingTree(bzrlib.mutabletree.MutableTree,
 
171
    bzrdir.ControlComponent):
178
172
    """Working copy tree.
179
173
 
180
174
    The inventory is held in the `Branch` working-inventory, and the
182
176
 
183
177
    It is possible for a `WorkingTree` to have a filename which is
184
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).
185
182
    """
186
183
 
187
184
    # override this to set the strategy for storing views
253
250
        self._rules_searcher = None
254
251
        self.views = self._make_views()
255
252
 
 
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
 
256
261
    def _detect_case_handling(self):
257
262
        wt_trans = self.bzrdir.get_workingtree_transport(None)
258
263
        try:
366
371
                return True, None
367
372
            else:
368
373
                return True, tree
369
 
        transport = get_transport(location)
370
 
        iterator = bzrdir.BzrDir.find_bzrdirs(transport, evaluate=evaluate,
 
374
        t = transport.get_transport(location)
 
375
        iterator = bzrdir.BzrDir.find_bzrdirs(t, evaluate=evaluate,
371
376
                                              list_current=list_current)
372
 
        return [t for t in iterator if t is not None]
 
377
        return [tr for tr in iterator if tr is not None]
373
378
 
374
379
    # should be deprecated - this is slow and in any case treating them as a
375
380
    # container is (we now know) bad style -- mbp 20070302
460
465
        return (file_obj, stat_value)
461
466
 
462
467
    def get_file_text(self, file_id, path=None, filtered=True):
463
 
        return self.get_file(file_id, path=path, filtered=filtered).read()
 
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()
464
473
 
465
474
    def get_file_byname(self, filename, filtered=True):
466
475
        path = self.abspath(filename)
520
529
 
521
530
        # Now we have the parents of this content
522
531
        annotator = self.branch.repository.texts.get_annotator()
523
 
        text = self.get_file(file_id).read()
 
532
        text = self.get_file_text(file_id)
524
533
        this_key =(file_id, default_revision)
525
534
        annotator.add_special_text(this_key, file_parent_keys, text)
526
535
        annotations = [(key[-1], line)
1094
1103
        tree_transport = self.bzrdir.root_transport.clone(sub_path)
1095
1104
        if tree_transport.base != branch_transport.base:
1096
1105
            tree_bzrdir = format.initialize_on_transport(tree_transport)
1097
 
            branch.BranchReferenceFormat().initialize(tree_bzrdir, new_branch)
 
1106
            branch.BranchReferenceFormat().initialize(tree_bzrdir,
 
1107
                target_branch=new_branch)
1098
1108
        else:
1099
1109
            tree_bzrdir = branch_bzrdir
1100
1110
        wt = tree_bzrdir.create_workingtree(_mod_revision.NULL_REVISION)
1138
1148
        This does not include files that have been deleted in this
1139
1149
        tree. Skips the control directory.
1140
1150
 
1141
 
        :param include_root: if True, do not return an entry for the root
 
1151
        :param include_root: if True, return an entry for the root
1142
1152
        :param from_dir: start from this directory or None for the root
1143
1153
        :param recursive: whether to recurse into subdirectories or not
1144
1154
        """
1795
1805
            raise errors.ObjectNotLocked(self)
1796
1806
 
1797
1807
    def lock_read(self):
1798
 
        """See Branch.lock_read, and WorkingTree.unlock."""
 
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
1814
        if not self.is_locked():
1800
1815
            self._reset_data()
1801
1816
        self.branch.lock_read()
1802
1817
        try:
1803
 
            return self._control_files.lock_read()
 
1818
            self._control_files.lock_read()
 
1819
            return LogicalLockResult(self.unlock)
1804
1820
        except:
1805
1821
            self.branch.unlock()
1806
1822
            raise
1807
1823
 
1808
1824
    def lock_tree_write(self):
1809
 
        """See MutableTree.lock_tree_write, and WorkingTree.unlock."""
 
1825
        """See MutableTree.lock_tree_write, and WorkingTree.unlock.
 
1826
 
 
1827
        :return: A bzrlib.lock.LogicalLockResult.
 
1828
        """
1810
1829
        if not self.is_locked():
1811
1830
            self._reset_data()
1812
1831
        self.branch.lock_read()
1813
1832
        try:
1814
 
            return self._control_files.lock_write()
 
1833
            self._control_files.lock_write()
 
1834
            return LogicalLockResult(self.unlock)
1815
1835
        except:
1816
1836
            self.branch.unlock()
1817
1837
            raise
1818
1838
 
1819
1839
    def lock_write(self):
1820
 
        """See MutableTree.lock_write, and WorkingTree.unlock."""
 
1840
        """See MutableTree.lock_write, and WorkingTree.unlock.
 
1841
 
 
1842
        :return: A bzrlib.lock.LogicalLockResult.
 
1843
        """
1821
1844
        if not self.is_locked():
1822
1845
            self._reset_data()
1823
1846
        self.branch.lock_write()
1824
1847
        try:
1825
 
            return self._control_files.lock_write()
 
1848
            self._control_files.lock_write()
 
1849
            return LogicalLockResult(self.unlock)
1826
1850
        except:
1827
1851
            self.branch.unlock()
1828
1852
            raise
1953
1977
        def recurse_directory_to_add_files(directory):
1954
1978
            # Recurse directory and add all files
1955
1979
            # so we can check if they have changed.
1956
 
            for parent_info, file_infos in\
1957
 
                self.walkdirs(directory):
 
1980
            for parent_info, file_infos in self.walkdirs(directory):
1958
1981
                for relpath, basename, kind, lstat, fileid, kind in file_infos:
1959
1982
                    # Is it versioned or ignored?
1960
1983
                    if self.path2id(relpath) or self.is_ignored(relpath):
1995
2018
                            # ... but not ignored
1996
2019
                            has_changed_files = True
1997
2020
                            break
1998
 
                    elif content_change and (kind[1] is not None):
1999
 
                        # Versioned and changed, but not deleted
 
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.
2000
2025
                        has_changed_files = True
2001
2026
                        break
2002
2027
 
2257
2282
            last_rev = _mod_revision.NULL_REVISION
2258
2283
        if revision is None:
2259
2284
            revision = self.branch.last_revision()
2260
 
        else:
2261
 
            if revision not in self.branch.revision_history():
2262
 
                raise errors.NoSuchRevision(self.branch, revision)
2263
2285
 
2264
2286
        old_tip = old_tip or _mod_revision.NULL_REVISION
2265
2287
 
2636
2658
 
2637
2659
        In Format2 WorkingTrees we have a single lock for the branch and tree
2638
2660
        so lock_tree_write() degrades to lock_write().
 
2661
 
 
2662
        :return: An object with an unlock method which will release the lock
 
2663
            obtained.
2639
2664
        """
2640
2665
        self.branch.lock_write()
2641
2666
        try:
2642
 
            return self._control_files.lock_write()
 
2667
            self._control_files.lock_write()
 
2668
            return self
2643
2669
        except:
2644
2670
            self.branch.unlock()
2645
2671
            raise