~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/workingtree_3.py

  • Committer: Martin Packman
  • Date: 2012-01-05 09:50:04 UTC
  • mfrom: (6424 +trunk)
  • mto: This revision was merged to the branch mainline in revision 6426.
  • Revision ID: martin.packman@canonical.com-20120105095004-mia9xb7y0efmto0v
Merge bzr.dev to resolve conflicts in bzrlib.builtins

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 (
33
39
from bzrlib.transport.local import LocalTransport
34
40
from bzrlib.workingtree import (
35
41
    InventoryWorkingTree,
36
 
    WorkingTreeFormat,
 
42
    WorkingTreeFormatMetaDir,
37
43
    )
38
44
 
39
 
class WorkingTree3(InventoryWorkingTree):
 
45
 
 
46
class PreDirStateWorkingTree(InventoryWorkingTree):
 
47
 
 
48
    def __init__(self, basedir='.', *args, **kwargs):
 
49
        super(PreDirStateWorkingTree, self).__init__(basedir, *args, **kwargs)
 
50
        # update the whole cache up front and write to disk if anything changed;
 
51
        # in the future we might want to do this more selectively
 
52
        # two possible ways offer themselves : in self._unlock, write the cache
 
53
        # if needed, or, when the cache sees a change, append it to the hash
 
54
        # cache file, and have the parser take the most recent entry for a
 
55
        # given path only.
 
56
        wt_trans = self.bzrdir.get_workingtree_transport(None)
 
57
        cache_filename = wt_trans.local_abspath('stat-cache')
 
58
        self._hashcache = hashcache.HashCache(basedir, cache_filename,
 
59
            self.bzrdir._get_file_mode(),
 
60
            self._content_filter_stack_provider())
 
61
        hc = self._hashcache
 
62
        hc.read()
 
63
        # is this scan needed ? it makes things kinda slow.
 
64
        #hc.scan()
 
65
 
 
66
        if hc.needs_write:
 
67
            trace.mutter("write hc")
 
68
            hc.write()
 
69
 
 
70
    def _write_hashcache_if_dirty(self):
 
71
        """Write out the hashcache if it is dirty."""
 
72
        if self._hashcache.needs_write:
 
73
            try:
 
74
                self._hashcache.write()
 
75
            except OSError, e:
 
76
                if e.errno not in (errno.EPERM, errno.EACCES):
 
77
                    raise
 
78
                # TODO: jam 20061219 Should this be a warning? A single line
 
79
                #       warning might be sufficient to let the user know what
 
80
                #       is going on.
 
81
                trace.mutter('Could not write hashcache for %s\nError: %s',
 
82
                              self._hashcache.cache_file_name(), e)
 
83
 
 
84
    @needs_read_lock
 
85
    def get_file_sha1(self, file_id, path=None, stat_value=None):
 
86
        if not path:
 
87
            path = self._inventory.id2path(file_id)
 
88
        return self._hashcache.get_sha1(path, stat_value)
 
89
 
 
90
 
 
91
class WorkingTree3(PreDirStateWorkingTree):
40
92
    """This is the Format 3 working tree.
41
93
 
42
94
    This differs from the base WorkingTree by:
86
138
            self.branch.unlock()
87
139
 
88
140
 
89
 
class WorkingTreeFormat3(WorkingTreeFormat):
 
141
class WorkingTreeFormat3(WorkingTreeFormatMetaDir):
90
142
    """The second working tree format updated to record a format marker.
91
143
 
92
144
    This format:
93
145
        - exists within a metadir controlling .bzr
94
146
        - includes an explicit version marker for the workingtree control
95
 
          files, separate from the BzrDir format
 
147
          files, separate from the ControlDir format
96
148
        - modifies the hash cache format
97
149
        - is new in bzr 0.8
98
150
        - uses a LockDir to guard access for writes.
104
156
 
105
157
    supports_versioned_directories = True
106
158
 
107
 
    def get_format_string(self):
 
159
    @classmethod
 
160
    def get_format_string(cls):
108
161
        """See WorkingTreeFormat.get_format_string()."""
109
162
        return "Bazaar-NG Working Tree format 3"
110
163
 
142
195
        control_files = self._open_control_files(a_bzrdir)
143
196
        control_files.create_lock()
144
197
        control_files.lock_write()
145
 
        transport.put_bytes('format', self.get_format_string(),
 
198
        transport.put_bytes('format', self.as_string(),
146
199
            mode=a_bzrdir._get_file_mode())
147
200
        if from_branch is not None:
148
201
            branch = from_branch
209
262
                                _format=self,
210
263
                                _bzrdir=a_bzrdir,
211
264
                                _control_files=control_files)
212
 
 
213
 
    def __str__(self):
214
 
        return self.get_format_string()