~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/workingtree_3.py

  • Committer: Canonical.com Patch Queue Manager
  • Date: 2011-08-17 18:13:57 UTC
  • mfrom: (5268.7.29 transport-segments)
  • Revision ID: pqm@pqm.ubuntu.com-20110817181357-y5q5eth1hk8bl3om
(jelmer) Allow specifying the colocated branch to use in the branch URL,
 and retrieving the branch name using ControlDir._get_selected_branch.
 (Jelmer Vernooij)

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
 
 
25
21
from bzrlib import (
26
22
    bzrdir,
27
23
    errors,
28
 
    hashcache,
29
24
    inventory,
30
25
    revision as _mod_revision,
31
 
    trace,
32
26
    transform,
33
27
    )
34
28
from bzrlib.decorators import (
36
30
    )
37
31
from bzrlib.lockable_files import LockableFiles
38
32
from bzrlib.lockdir import LockDir
39
 
from bzrlib.mutabletree import MutableTree
40
33
from bzrlib.transport.local import LocalTransport
41
34
from bzrlib.workingtree import (
42
35
    InventoryWorkingTree,
43
 
    WorkingTreeFormatMetaDir,
 
36
    WorkingTreeFormat,
44
37
    )
45
38
 
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):
 
39
class WorkingTree3(InventoryWorkingTree):
93
40
    """This is the Format 3 working tree.
94
41
 
95
42
    This differs from the base WorkingTree by:
139
86
            self.branch.unlock()
140
87
 
141
88
 
142
 
class WorkingTreeFormat3(WorkingTreeFormatMetaDir):
 
89
class WorkingTreeFormat3(WorkingTreeFormat):
143
90
    """The second working tree format updated to record a format marker.
144
91
 
145
92
    This format:
146
93
        - exists within a metadir controlling .bzr
147
94
        - includes an explicit version marker for the workingtree control
148
 
          files, separate from the ControlDir format
 
95
          files, separate from the BzrDir format
149
96
        - modifies the hash cache format
150
97
        - is new in bzr 0.8
151
98
        - uses a LockDir to guard access for writes.
157
104
 
158
105
    supports_versioned_directories = True
159
106
 
160
 
    @classmethod
161
 
    def get_format_string(cls):
 
107
    def get_format_string(self):
162
108
        """See WorkingTreeFormat.get_format_string()."""
163
109
        return "Bazaar-NG Working Tree format 3"
164
110
 
196
142
        control_files = self._open_control_files(a_bzrdir)
197
143
        control_files.create_lock()
198
144
        control_files.lock_write()
199
 
        transport.put_bytes('format', self.as_string(),
 
145
        transport.put_bytes('format', self.get_format_string(),
200
146
            mode=a_bzrdir._get_file_mode())
201
147
        if from_branch is not None:
202
148
            branch = from_branch
221
167
        try:
222
168
            basis_tree = branch.repository.revision_tree(revision_id)
223
169
            # only set an explicit root id if there is one to set.
224
 
            if basis_tree.get_root_id() is not None:
 
170
            if basis_tree.inventory.root is not None:
225
171
                wt.set_root_id(basis_tree.get_root_id())
226
172
            if revision_id == _mod_revision.NULL_REVISION:
227
173
                wt.set_parent_trees([])
228
174
            else:
229
175
                wt.set_parent_trees([(revision_id, basis_tree)])
230
176
            transform.build_tree(basis_tree, wt)
231
 
            for hook in MutableTree.hooks['post_build_tree']:
232
 
                hook(wt)
233
177
        finally:
234
178
            # Unlock in this order so that the unlock-triggers-flush in
235
179
            # WorkingTree is given a chance to fire.
265
209
                                _format=self,
266
210
                                _bzrdir=a_bzrdir,
267
211
                                _control_files=control_files)
 
212
 
 
213
    def __str__(self):
 
214
        return self.get_format_string()