~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/workingtree_3.py

  • Committer: Tarmac
  • Author(s): Vincent Ladeuil
  • Date: 2017-01-30 14:42:05 UTC
  • mfrom: (6620.1.1 trunk)
  • Revision ID: tarmac-20170130144205-r8fh2xpmiuxyozpv
Merge  2.7 into trunk including fix for bug #1657238 [r=vila]

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
 
 
23
import errno
 
24
 
21
25
from bzrlib import (
22
26
    bzrdir,
23
27
    errors,
 
28
    hashcache,
24
29
    inventory,
25
30
    revision as _mod_revision,
 
31
    trace,
26
32
    transform,
27
33
    )
28
34
from bzrlib.decorators import (
30
36
    )
31
37
from bzrlib.lockable_files import LockableFiles
32
38
from bzrlib.lockdir import LockDir
 
39
from bzrlib.mutabletree import MutableTree
33
40
from bzrlib.transport.local import LocalTransport
34
41
from bzrlib.workingtree import (
35
42
    InventoryWorkingTree,
36
 
    WorkingTreeFormat,
 
43
    WorkingTreeFormatMetaDir,
37
44
    )
38
45
 
39
 
class WorkingTree3(InventoryWorkingTree):
 
46
 
 
47
class PreDirStateWorkingTree(InventoryWorkingTree):
 
48
 
 
49
    def __init__(self, basedir='.', *args, **kwargs):
 
50
        super(PreDirStateWorkingTree, self).__init__(basedir, *args, **kwargs)
 
51
        # update the whole cache up front and write to disk if anything changed;
 
52
        # in the future we might want to do this more selectively
 
53
        # two possible ways offer themselves : in self._unlock, write the cache
 
54
        # if needed, or, when the cache sees a change, append it to the hash
 
55
        # cache file, and have the parser take the most recent entry for a
 
56
        # given path only.
 
57
        wt_trans = self.bzrdir.get_workingtree_transport(None)
 
58
        cache_filename = wt_trans.local_abspath('stat-cache')
 
59
        self._hashcache = hashcache.HashCache(basedir, cache_filename,
 
60
            self.bzrdir._get_file_mode(),
 
61
            self._content_filter_stack_provider())
 
62
        hc = self._hashcache
 
63
        hc.read()
 
64
        # is this scan needed ? it makes things kinda slow.
 
65
        #hc.scan()
 
66
 
 
67
        if hc.needs_write:
 
68
            trace.mutter("write hc")
 
69
            hc.write()
 
70
 
 
71
    def _write_hashcache_if_dirty(self):
 
72
        """Write out the hashcache if it is dirty."""
 
73
        if self._hashcache.needs_write:
 
74
            try:
 
75
                self._hashcache.write()
 
76
            except OSError, e:
 
77
                if e.errno not in (errno.EPERM, errno.EACCES):
 
78
                    raise
 
79
                # TODO: jam 20061219 Should this be a warning? A single line
 
80
                #       warning might be sufficient to let the user know what
 
81
                #       is going on.
 
82
                trace.mutter('Could not write hashcache for %s\nError: %s',
 
83
                              self._hashcache.cache_file_name(), e)
 
84
 
 
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)
 
90
 
 
91
 
 
92
class WorkingTree3(PreDirStateWorkingTree):
40
93
    """This is the Format 3 working tree.
41
94
 
42
95
    This differs from the base WorkingTree by:
86
139
            self.branch.unlock()
87
140
 
88
141
 
89
 
class WorkingTreeFormat3(WorkingTreeFormat):
 
142
class WorkingTreeFormat3(WorkingTreeFormatMetaDir):
90
143
    """The second working tree format updated to record a format marker.
91
144
 
92
145
    This format:
93
146
        - exists within a metadir controlling .bzr
94
147
        - includes an explicit version marker for the workingtree control
95
 
          files, separate from the BzrDir format
 
148
          files, separate from the ControlDir format
96
149
        - modifies the hash cache format
97
150
        - is new in bzr 0.8
98
151
        - uses a LockDir to guard access for writes.
104
157
 
105
158
    supports_versioned_directories = True
106
159
 
107
 
    def get_format_string(self):
 
160
    @classmethod
 
161
    def get_format_string(cls):
108
162
        """See WorkingTreeFormat.get_format_string()."""
109
163
        return "Bazaar-NG Working Tree format 3"
110
164
 
142
196
        control_files = self._open_control_files(a_bzrdir)
143
197
        control_files.create_lock()
144
198
        control_files.lock_write()
145
 
        transport.put_bytes('format', self.get_format_string(),
 
199
        transport.put_bytes('format', self.as_string(),
146
200
            mode=a_bzrdir._get_file_mode())
147
201
        if from_branch is not None:
148
202
            branch = from_branch
167
221
        try:
168
222
            basis_tree = branch.repository.revision_tree(revision_id)
169
223
            # only set an explicit root id if there is one to set.
170
 
            if basis_tree.inventory.root is not None:
 
224
            if basis_tree.get_root_id() is not None:
171
225
                wt.set_root_id(basis_tree.get_root_id())
172
226
            if revision_id == _mod_revision.NULL_REVISION:
173
227
                wt.set_parent_trees([])
174
228
            else:
175
229
                wt.set_parent_trees([(revision_id, basis_tree)])
176
230
            transform.build_tree(basis_tree, wt)
 
231
            for hook in MutableTree.hooks['post_build_tree']:
 
232
                hook(wt)
177
233
        finally:
178
234
            # Unlock in this order so that the unlock-triggers-flush in
179
235
            # WorkingTree is given a chance to fire.
209
265
                                _format=self,
210
266
                                _bzrdir=a_bzrdir,
211
267
                                _control_files=control_files)
212
 
 
213
 
    def __str__(self):
214
 
        return self.get_format_string()