/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_3.py

  • Committer: Richard Wilbur
  • Date: 2016-02-04 19:07:28 UTC
  • mto: This revision was merged to the branch mainline in revision 6618.
  • Revision ID: richard.wilbur@gmail.com-20160204190728-p0zvfii6zase0fw7
Update COPYING.txt from the original http://www.gnu.org/licenses/gpl-2.0.txt  (Only differences were in whitespace.)  Thanks to Petr Stodulka for pointing out the discrepancy.

Show diffs side-by-side

added added

removed removed

Lines of Context:
22
22
 
23
23
import errno
24
24
 
25
 
from . import (
 
25
from bzrlib import (
26
26
    bzrdir,
27
 
    inventory,
28
 
    )
29
 
 
30
 
from .. import (
31
27
    errors,
32
28
    hashcache,
 
29
    inventory,
33
30
    revision as _mod_revision,
34
31
    trace,
35
32
    transform,
36
33
    )
37
 
from ..lockable_files import LockableFiles
38
 
from ..lockdir import LockDir
39
 
from ..mutabletree import MutableTree
40
 
from ..transport.local import LocalTransport
41
 
from .workingtree import (
 
34
from bzrlib.decorators import (
 
35
    needs_read_lock,
 
36
    )
 
37
from bzrlib.lockable_files import LockableFiles
 
38
from bzrlib.lockdir import LockDir
 
39
from bzrlib.mutabletree import MutableTree
 
40
from bzrlib.transport.local import LocalTransport
 
41
from bzrlib.workingtree import (
42
42
    InventoryWorkingTree,
43
43
    WorkingTreeFormatMetaDir,
44
44
    )
54
54
        # if needed, or, when the cache sees a change, append it to the hash
55
55
        # cache file, and have the parser take the most recent entry for a
56
56
        # given path only.
57
 
        wt_trans = self.controldir.get_workingtree_transport(None)
 
57
        wt_trans = self.bzrdir.get_workingtree_transport(None)
58
58
        cache_filename = wt_trans.local_abspath('stat-cache')
59
59
        self._hashcache = hashcache.HashCache(basedir, cache_filename,
60
 
            self.controldir._get_file_mode(),
 
60
            self.bzrdir._get_file_mode(),
61
61
            self._content_filter_stack_provider())
62
62
        hc = self._hashcache
63
63
        hc.read()
73
73
        if self._hashcache.needs_write:
74
74
            try:
75
75
                self._hashcache.write()
76
 
            except OSError as e:
 
76
            except OSError, e:
77
77
                if e.errno not in (errno.EPERM, errno.EACCES):
78
78
                    raise
79
79
                # TODO: jam 20061219 Should this be a warning? A single line
82
82
                trace.mutter('Could not write hashcache for %s\nError: %s',
83
83
                              self._hashcache.cache_file_name(), e)
84
84
 
85
 
    def get_file_sha1(self, path, file_id=None, stat_value=None):
86
 
        with self.lock_read():
87
 
            # To make sure NoSuchFile gets raised..
88
 
            if self.path2id(path) is None:
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):
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('.'),
 
213
        wt = self._tree_class(a_bzrdir.root_transport.local_abspath('.'),
215
214
                         branch,
216
215
                         inv,
217
216
                         _internal=True,
218
217
                         _format=self,
219
 
                         _controldir=a_controldir,
 
218
                         _bzrdir=a_bzrdir,
220
219
                         _control_files=control_files)
221
220
        wt.lock_tree_write()
222
221
        try:
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)