~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/plugins/weave_fmt/workingtree.py

  • Committer: Jelmer Vernooij
  • Date: 2011-08-30 09:29:03 UTC
  • mto: This revision was merged to the branch mainline in revision 6115.
  • Revision ID: jelmer@samba.org-20110830092903-981sb118z3ilvq7x
Move hashcache use to bzrlib.workingtree_3 and bzrlib.plugins.weave_fmt.workingtree.

Show diffs side-by-side

added added

removed removed

Lines of Context:
17
17
"""Weave-era working tree objects."""
18
18
 
19
19
from cStringIO import StringIO
 
20
import errno
20
21
 
21
22
from bzrlib import (
22
23
    conflicts as _mod_conflicts,
23
24
    errors,
 
25
    hashcache,
24
26
    inventory,
25
27
    osutils,
26
28
    revision as _mod_revision,
 
29
    trace,
27
30
    transform,
28
31
    xml5,
29
32
    )
143
146
     - uses the branch last-revision.
144
147
    """
145
148
 
146
 
    def __init__(self, *args, **kwargs):
147
 
        super(WorkingTree2, self).__init__(*args, **kwargs)
 
149
    def __init__(self, basedir, *args, **kwargs):
 
150
        super(WorkingTree2, self).__init__(basedir, *args, **kwargs)
 
151
 
 
152
        # update the whole cache up front and write to disk if anything changed;
 
153
        # in the future we might want to do this more selectively
 
154
        # two possible ways offer themselves : in self._unlock, write the cache
 
155
        # if needed, or, when the cache sees a change, append it to the hash
 
156
        # cache file, and have the parser take the most recent entry for a
 
157
        # given path only.
 
158
        wt_trans = self.bzrdir.get_workingtree_transport(None)
 
159
        cache_filename = wt_trans.local_abspath('stat-cache')
 
160
        self._hashcache = hashcache.HashCache(basedir, cache_filename,
 
161
            self.bzrdir._get_file_mode(),
 
162
            self._content_filter_stack_provider())
 
163
        hc = self._hashcache
 
164
        hc.read()
 
165
        # is this scan needed ? it makes things kinda slow.
 
166
        #hc.scan()
 
167
 
 
168
        if hc.needs_write:
 
169
            trace.mutter("write hc")
 
170
            hc.write()
 
171
 
148
172
        # WorkingTree2 has more of a constraint that self._inventory must
149
173
        # exist. Because this is an older format, we don't mind the overhead
150
174
        # caused by the extra computation here.
158
182
        """Return the references needed to perform a check of this tree."""
159
183
        return [('trees', self.last_revision())]
160
184
 
 
185
 
 
186
    @needs_read_lock
 
187
    def get_file_sha1(self, file_id, path=None, stat_value=None):
 
188
        if not path:
 
189
            path = self._inventory.id2path(file_id)
 
190
        return self._hashcache.get_sha1(path, stat_value)
 
191
 
161
192
    def lock_tree_write(self):
162
193
        """See WorkingTree.lock_tree_write().
163
194
 
175
206
            self.branch.unlock()
176
207
            raise
177
208
 
 
209
    def _write_hashcache_if_dirty(self):
 
210
        """Write out the hashcache if it is dirty."""
 
211
        if self._hashcache.needs_write:
 
212
            try:
 
213
                self._hashcache.write()
 
214
            except OSError, e:
 
215
                if e.errno not in (errno.EPERM, errno.EACCES):
 
216
                    raise
 
217
                # TODO: jam 20061219 Should this be a warning? A single line
 
218
                #       warning might be sufficient to let the user know what
 
219
                #       is going on.
 
220
                trace.mutter('Could not write hashcache for %s\nError: %s',
 
221
                              self._hashcache.cache_file_name(), e)
 
222
 
178
223
    def unlock(self):
179
224
        # we share control files:
180
225
        if self._control_files._lock_count == 3: