~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 10:37:58 UTC
  • mto: This revision was merged to the branch mainline in revision 6427.
  • Revision ID: martin.packman@canonical.com-20120105103758-wzftnmsip5iv9n2g
Revert addition of get_message_encoding function

Show diffs side-by-side

added added

removed removed

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