/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 breezy/bzr/workingtree_3.py

  • Committer: Jelmer Vernooij
  • Date: 2017-06-08 23:30:31 UTC
  • mto: This revision was merged to the branch mainline in revision 6690.
  • Revision ID: jelmer@jelmer.uk-20170608233031-3qavls2o7a1pqllj
Update imports.

Show diffs side-by-side

added added

removed removed

Lines of Context:
18
18
 
19
19
"""
20
20
 
 
21
from __future__ import absolute_import
 
22
 
21
23
import errno
22
24
 
23
25
from . import (
28
30
from .. import (
29
31
    errors,
30
32
    hashcache,
31
 
    osutils,
32
33
    revision as _mod_revision,
33
34
    trace,
34
35
    transform,
35
36
    )
 
37
from ..decorators import (
 
38
    needs_read_lock,
 
39
    )
36
40
from ..lockable_files import LockableFiles
37
41
from ..lockdir import LockDir
38
42
from ..mutabletree import MutableTree
53
57
        # if needed, or, when the cache sees a change, append it to the hash
54
58
        # cache file, and have the parser take the most recent entry for a
55
59
        # given path only.
56
 
        wt_trans = self.controldir.get_workingtree_transport(None)
 
60
        wt_trans = self.bzrdir.get_workingtree_transport(None)
57
61
        cache_filename = wt_trans.local_abspath('stat-cache')
58
62
        self._hashcache = hashcache.HashCache(basedir, cache_filename,
59
 
                                              self.controldir._get_file_mode(),
60
 
                                              self._content_filter_stack_provider())
 
63
            self.bzrdir._get_file_mode(),
 
64
            self._content_filter_stack_provider())
61
65
        hc = self._hashcache
62
66
        hc.read()
63
67
        # is this scan needed ? it makes things kinda slow.
64
 
        # hc.scan()
 
68
        #hc.scan()
65
69
 
66
70
        if hc.needs_write:
67
71
            trace.mutter("write hc")
79
83
                #       warning might be sufficient to let the user know what
80
84
                #       is going on.
81
85
                trace.mutter('Could not write hashcache for %s\nError: %s',
82
 
                             self._hashcache.cache_file_name(),
83
 
                             osutils.safe_unicode(e.args[1]))
 
86
                              self._hashcache.cache_file_name(), e)
84
87
 
85
 
    def get_file_sha1(self, path, stat_value=None):
86
 
        with self.lock_read():
87
 
            # To make sure NoSuchFile gets raised..
88
 
            if not self.is_versioned(path):
89
 
                raise errors.NoSuchFile(path)
90
 
            return self._hashcache.get_sha1(path, stat_value)
 
88
    @needs_read_lock
 
89
    def get_file_sha1(self, file_id, path=None, stat_value=None):
 
90
        if not path:
 
91
            path = self._inventory.id2path(file_id)
 
92
        return self._hashcache.get_sha1(path, stat_value)
91
93
 
92
94
 
93
95
class WorkingTree3(PreDirStateWorkingTree):
100
102
    This is new in bzr 0.8
101
103
    """
102
104
 
 
105
    @needs_read_lock
103
106
    def _last_revision(self):
104
107
        """See Mutable.last_revision."""
105
 
        with self.lock_read():
106
 
            try:
107
 
                return self._transport.get_bytes('last-revision')
108
 
            except errors.NoSuchFile:
109
 
                return _mod_revision.NULL_REVISION
 
108
        try:
 
109
            return self._transport.get_bytes('last-revision')
 
110
        except errors.NoSuchFile:
 
111
            return _mod_revision.NULL_REVISION
110
112
 
111
113
    def _change_last_revision(self, revision_id):
112
114
        """See WorkingTree._change_last_revision."""
118
120
            return False
119
121
        else:
120
122
            self._transport.put_bytes('last-revision', revision_id,
121
 
                                      mode=self.controldir._get_file_mode())
 
123
                mode=self.bzrdir._get_file_mode())
122
124
            return True
123
125
 
124
126
    def _get_check_refs(self):
127
129
 
128
130
    def unlock(self):
129
131
        if self._control_files._lock_count == 1:
130
 
            # do non-implementation specific cleanup
 
132
           # do non-implementation specific cleanup
131
133
            self._cleanup()
132
134
            # _inventory_is_modified is always False during a read lock.
133
135
            if self._inventory_is_modified:
161
163
    @classmethod
162
164
    def get_format_string(cls):
163
165
        """See WorkingTreeFormat.get_format_string()."""
164
 
        return b"Bazaar-NG Working Tree format 3"
 
166
        return "Bazaar-NG Working Tree format 3"
165
167
 
166
168
    def get_format_description(self):
167
169
        """See WorkingTreeFormat.get_format_description()."""
169
171
 
170
172
    _tree_class = WorkingTree3
171
173
 
172
 
    def __get_matchingcontroldir(self):
 
174
    def __get_matchingbzrdir(self):
173
175
        return bzrdir.BzrDirMetaFormat1()
174
176
 
175
 
    _matchingcontroldir = property(__get_matchingcontroldir)
 
177
    _matchingbzrdir = property(__get_matchingbzrdir)
176
178
 
177
 
    def _open_control_files(self, a_controldir):
178
 
        transport = a_controldir.get_workingtree_transport(None)
 
179
    def _open_control_files(self, a_bzrdir):
 
180
        transport = a_bzrdir.get_workingtree_transport(None)
179
181
        return LockableFiles(transport, 'lock', LockDir)
180
182
 
181
 
    def initialize(self, a_controldir, revision_id=None, from_branch=None,
 
183
    def initialize(self, a_bzrdir, revision_id=None, from_branch=None,
182
184
                   accelerator_tree=None, hardlink=False):
183
185
        """See WorkingTreeFormat.initialize().
184
186
 
191
193
        :param hardlink: If true, hard-link files from accelerator_tree,
192
194
            where possible.
193
195
        """
194
 
        if not isinstance(a_controldir.transport, LocalTransport):
195
 
            raise errors.NotLocalUrl(a_controldir.transport.base)
196
 
        transport = a_controldir.get_workingtree_transport(self)
197
 
        control_files = self._open_control_files(a_controldir)
 
196
        if not isinstance(a_bzrdir.transport, LocalTransport):
 
197
            raise errors.NotLocalUrl(a_bzrdir.transport.base)
 
198
        transport = a_bzrdir.get_workingtree_transport(self)
 
199
        control_files = self._open_control_files(a_bzrdir)
198
200
        control_files.create_lock()
199
201
        control_files.lock_write()
200
202
        transport.put_bytes('format', self.as_string(),
201
 
                            mode=a_controldir._get_file_mode())
 
203
            mode=a_bzrdir._get_file_mode())
202
204
        if from_branch is not None:
203
205
            branch = from_branch
204
206
        else:
205
 
            branch = a_controldir.open_branch()
 
207
            branch = a_bzrdir.open_branch()
206
208
        if revision_id is None:
207
209
            revision_id = _mod_revision.ensure_null(branch.last_revision())
208
210
        # WorkingTree3 can handle an inventory which has a unique root id.
211
213
        # are maintaining compatibility with older clients.
212
214
        # inv = Inventory(root_id=gen_root_id())
213
215
        inv = self._initial_inventory()
214
 
        wt = self._tree_class(a_controldir.root_transport.local_abspath('.'),
215
 
                              branch,
216
 
                              inv,
217
 
                              _internal=True,
218
 
                              _format=self,
219
 
                              _controldir=a_controldir,
220
 
                              _control_files=control_files)
 
216
        wt = self._tree_class(a_bzrdir.root_transport.local_abspath('.'),
 
217
                         branch,
 
218
                         inv,
 
219
                         _internal=True,
 
220
                         _format=self,
 
221
                         _bzrdir=a_bzrdir,
 
222
                         _control_files=control_files)
221
223
        wt.lock_tree_write()
222
224
        try:
223
225
            basis_tree = branch.repository.revision_tree(revision_id)
224
226
            # only set an explicit root id if there is one to set.
225
 
            if basis_tree.path2id('') is not None:
226
 
                wt.set_root_id(basis_tree.path2id(''))
 
227
            if basis_tree.get_root_id() is not None:
 
228
                wt.set_root_id(basis_tree.get_root_id())
227
229
            if revision_id == _mod_revision.NULL_REVISION:
228
230
                wt.set_parent_trees([])
229
231
            else:
241
243
    def _initial_inventory(self):
242
244
        return inventory.Inventory()
243
245
 
244
 
    def open(self, a_controldir, _found=False):
245
 
        """Return the WorkingTree object for a_controldir
 
246
    def open(self, a_bzrdir, _found=False):
 
247
        """Return the WorkingTree object for a_bzrdir
246
248
 
247
249
        _found is a private parameter, do not use it. It is used to indicate
248
250
               if format probing has already been done.
250
252
        if not _found:
251
253
            # we are being called directly and must probe.
252
254
            raise NotImplementedError
253
 
        if not isinstance(a_controldir.transport, LocalTransport):
254
 
            raise errors.NotLocalUrl(a_controldir.transport.base)
255
 
        wt = self._open(a_controldir, self._open_control_files(a_controldir))
 
255
        if not isinstance(a_bzrdir.transport, LocalTransport):
 
256
            raise errors.NotLocalUrl(a_bzrdir.transport.base)
 
257
        wt = self._open(a_bzrdir, self._open_control_files(a_bzrdir))
256
258
        return wt
257
259
 
258
 
    def _open(self, a_controldir, control_files):
 
260
    def _open(self, a_bzrdir, control_files):
259
261
        """Open the tree itself.
260
262
 
261
 
        :param a_controldir: the dir for the tree.
 
263
        :param a_bzrdir: the dir for the tree.
262
264
        :param control_files: the control files for the tree.
263
265
        """
264
 
        return self._tree_class(a_controldir.root_transport.local_abspath('.'),
 
266
        return self._tree_class(a_bzrdir.root_transport.local_abspath('.'),
265
267
                                _internal=True,
266
268
                                _format=self,
267
 
                                _controldir=a_controldir,
 
269
                                _bzrdir=a_bzrdir,
268
270
                                _control_files=control_files)