/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: Vincent Ladeuil
  • Date: 2010-03-01 09:02:18 UTC
  • mto: (5064.1.1 integration)
  • mto: This revision was merged to the branch mainline in revision 5065.
  • Revision ID: v.ladeuil+lp@free.fr-20100301090218-pq3ib5y07dx3wbp6
Delete spurious spaces.

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)
1103
1094
        tree_transport = self.bzrdir.root_transport.clone(sub_path)
1104
1095
        if tree_transport.base != branch_transport.base:
1105
1096
            tree_bzrdir = format.initialize_on_transport(tree_transport)
1106
 
            branch.BranchReferenceFormat().initialize(tree_bzrdir,
1107
 
                target_branch=new_branch)
 
1097
            branch.BranchReferenceFormat().initialize(tree_bzrdir, new_branch)
1108
1098
        else:
1109
1099
            tree_bzrdir = branch_bzrdir
1110
1100
        wt = tree_bzrdir.create_workingtree(_mod_revision.NULL_REVISION)
1148
1138
        This does not include files that have been deleted in this
1149
1139
        tree. Skips the control directory.
1150
1140
 
1151
 
        :param include_root: if True, return an entry for the root
 
1141
        :param include_root: if True, do not return an entry for the root
1152
1142
        :param from_dir: start from this directory or None for the root
1153
1143
        :param recursive: whether to recurse into subdirectories or not
1154
1144
        """
1805
1795
            raise errors.ObjectNotLocked(self)
1806
1796
 
1807
1797
    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
 
        """
 
1798
        """See Branch.lock_read, and WorkingTree.unlock."""
1814
1799
        if not self.is_locked():
1815
1800
            self._reset_data()
1816
1801
        self.branch.lock_read()
1817
1802
        try:
1818
 
            self._control_files.lock_read()
1819
 
            return LogicalLockResult(self.unlock)
 
1803
            return self._control_files.lock_read()
1820
1804
        except:
1821
1805
            self.branch.unlock()
1822
1806
            raise
1823
1807
 
1824
1808
    def lock_tree_write(self):
1825
 
        """See MutableTree.lock_tree_write, and WorkingTree.unlock.
1826
 
 
1827
 
        :return: A bzrlib.lock.LogicalLockResult.
1828
 
        """
 
1809
        """See MutableTree.lock_tree_write, and WorkingTree.unlock."""
1829
1810
        if not self.is_locked():
1830
1811
            self._reset_data()
1831
1812
        self.branch.lock_read()
1832
1813
        try:
1833
 
            self._control_files.lock_write()
1834
 
            return LogicalLockResult(self.unlock)
 
1814
            return self._control_files.lock_write()
1835
1815
        except:
1836
1816
            self.branch.unlock()
1837
1817
            raise
1838
1818
 
1839
1819
    def lock_write(self):
1840
 
        """See MutableTree.lock_write, and WorkingTree.unlock.
1841
 
 
1842
 
        :return: A bzrlib.lock.LogicalLockResult.
1843
 
        """
 
1820
        """See MutableTree.lock_write, and WorkingTree.unlock."""
1844
1821
        if not self.is_locked():
1845
1822
            self._reset_data()
1846
1823
        self.branch.lock_write()
1847
1824
        try:
1848
 
            self._control_files.lock_write()
1849
 
            return LogicalLockResult(self.unlock)
 
1825
            return self._control_files.lock_write()
1850
1826
        except:
1851
1827
            self.branch.unlock()
1852
1828
            raise
1977
1953
        def recurse_directory_to_add_files(directory):
1978
1954
            # Recurse directory and add all files
1979
1955
            # so we can check if they have changed.
1980
 
            for parent_info, file_infos in self.walkdirs(directory):
 
1956
            for parent_info, file_infos in\
 
1957
                self.walkdirs(directory):
1981
1958
                for relpath, basename, kind, lstat, fileid, kind in file_infos:
1982
1959
                    # Is it versioned or ignored?
1983
1960
                    if self.path2id(relpath) or self.is_ignored(relpath):
2018
1995
                            # ... but not ignored
2019
1996
                            has_changed_files = True
2020
1997
                            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.
 
1998
                    elif content_change and (kind[1] is not None):
 
1999
                        # Versioned and changed, but not deleted
2025
2000
                        has_changed_files = True
2026
2001
                        break
2027
2002
 
2282
2257
            last_rev = _mod_revision.NULL_REVISION
2283
2258
        if revision is None:
2284
2259
            revision = self.branch.last_revision()
 
2260
        else:
 
2261
            if revision not in self.branch.revision_history():
 
2262
                raise errors.NoSuchRevision(self.branch, revision)
2285
2263
 
2286
2264
        old_tip = old_tip or _mod_revision.NULL_REVISION
2287
2265
 
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