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

  • Committer: Jelmer Vernooij
  • Date: 2017-05-21 12:41:27 UTC
  • mto: This revision was merged to the branch mainline in revision 6623.
  • Revision ID: jelmer@jelmer.uk-20170521124127-iv8etg0vwymyai6y
s/bzr/brz/ in apport config.

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