Rev 6115: (jelmer) Move the use of hashcache to a new PreDirStateWorkingTree and case in file:///home/pqm/archives/thelove/bzr/%2Btrunk/
Canonical.com Patch Queue Manager
pqm at pqm.ubuntu.com
Thu Sep 1 02:11:38 UTC 2011
At file:///home/pqm/archives/thelove/bzr/%2Btrunk/
------------------------------------------------------------
revno: 6115 [merge]
revision-id: pqm at pqm.ubuntu.com-20110901021135-djsnex0953w58dux
parent: pqm at pqm.ubuntu.com-20110831235921-ra2k5rt3x4f6xeli
parent: jelmer at samba.org-20110830173229-k234j02cfvf7gshz
committer: Canonical.com Patch Queue Manager <pqm at pqm.ubuntu.com>
branch nick: +trunk
timestamp: Thu 2011-09-01 02:11:35 +0000
message:
(jelmer) Move the use of hashcache to a new PreDirStateWorkingTree and case
detection to InventoryWorkingTree. (Jelmer Vernooij)
modified:
bzrlib/plugins/weave_fmt/workingtree.py workingtree_2.py-20110303111903-b6uksp28mf3oo3vp-1
bzrlib/tests/test_import_tariff.py test_import_tariff.p-20100207155145-ff9infp7goncs7zh-1
bzrlib/workingtree.py workingtree.py-20050511021032-29b6ec0a681e02e3
bzrlib/workingtree_3.py workingtree_3.py-20110503234428-nwa1nw7zfdd0hrw8-1
=== modified file 'bzrlib/plugins/weave_fmt/workingtree.py'
--- a/bzrlib/plugins/weave_fmt/workingtree.py 2011-06-28 11:29:03 +0000
+++ b/bzrlib/plugins/weave_fmt/workingtree.py 2011-08-30 17:32:29 +0000
@@ -30,9 +30,11 @@
from bzrlib.decorators import needs_read_lock
from bzrlib.transport.local import LocalTransport
from bzrlib.workingtree import (
- InventoryWorkingTree,
WorkingTreeFormat,
)
+from bzrlib.workingtree_3 import (
+ PreDirStateWorkingTree,
+ )
def get_conflicted_stem(path):
@@ -135,7 +137,7 @@
return wt
-class WorkingTree2(InventoryWorkingTree):
+class WorkingTree2(PreDirStateWorkingTree):
"""This is the Format 2 working tree.
This was the first weave based working tree.
@@ -143,8 +145,8 @@
- uses the branch last-revision.
"""
- def __init__(self, *args, **kwargs):
- super(WorkingTree2, self).__init__(*args, **kwargs)
+ def __init__(self, basedir, *args, **kwargs):
+ super(WorkingTree2, self).__init__(basedir, *args, **kwargs)
# WorkingTree2 has more of a constraint that self._inventory must
# exist. Because this is an older format, we don't mind the overhead
# caused by the extra computation here.
@@ -158,6 +160,7 @@
"""Return the references needed to perform a check of this tree."""
return [('trees', self.last_revision())]
+
def lock_tree_write(self):
"""See WorkingTree.lock_tree_write().
=== modified file 'bzrlib/tests/test_import_tariff.py'
--- a/bzrlib/tests/test_import_tariff.py 2011-06-06 11:57:09 +0000
+++ b/bzrlib/tests/test_import_tariff.py 2011-08-30 09:30:27 +0000
@@ -167,6 +167,7 @@
'bzrlib.cmd_version_info',
'bzrlib.externalcommand',
'bzrlib.filters',
+ 'bzrlib.hashcache',
# foreign branch plugins import the foreign_vcs_registry from
# bzrlib.foreign so it can't be blacklisted
'bzrlib.gpg',
@@ -235,6 +236,7 @@
'bzrlib._dirstate_helpers_pyx',
'bzrlib.externalcommand',
'bzrlib.filters',
+ 'bzrlib.hashcache',
# foreign branch plugins import the foreign_vcs_registry from
# bzrlib.foreign so it can't be blacklisted
'bzrlib.gpg',
=== modified file 'bzrlib/workingtree.py'
--- a/bzrlib/workingtree.py 2011-08-04 13:30:30 +0000
+++ b/bzrlib/workingtree.py 2011-08-30 09:29:03 +0000
@@ -54,7 +54,6 @@
generate_ids,
globbing,
graph as _mod_graph,
- hashcache,
ignores,
inventory,
merge,
@@ -194,27 +193,6 @@
self.basedir = realpath(basedir)
self._control_files = _control_files
self._transport = self._control_files._transport
- # update the whole cache up front and write to disk if anything changed;
- # in the future we might want to do this more selectively
- # two possible ways offer themselves : in self._unlock, write the cache
- # if needed, or, when the cache sees a change, append it to the hash
- # cache file, and have the parser take the most recent entry for a
- # given path only.
- wt_trans = self.bzrdir.get_workingtree_transport(None)
- cache_filename = wt_trans.local_abspath('stat-cache')
- self._hashcache = hashcache.HashCache(basedir, cache_filename,
- self.bzrdir._get_file_mode(),
- self._content_filter_stack_provider())
- hc = self._hashcache
- hc.read()
- # is this scan needed ? it makes things kinda slow.
- #hc.scan()
-
- if hc.needs_write:
- mutter("write hc")
- hc.write()
-
- self._detect_case_handling()
self._rules_searcher = None
self.views = self._make_views()
@@ -238,17 +216,6 @@
"""
return self.bzrdir.is_control_filename(filename)
- def _detect_case_handling(self):
- wt_trans = self.bzrdir.get_workingtree_transport(None)
- try:
- wt_trans.stat(self._format.case_sensitive_filename)
- except errors.NoSuchFile:
- self.case_sensitive = True
- else:
- self.case_sensitive = False
-
- self._setup_directory_is_tree_reference()
-
branch = property(
fget=lambda self: self._branch,
doc="""The branch this WorkingTree is connected to.
@@ -1062,7 +1029,6 @@
stream.write(bytes)
finally:
stream.close()
- # TODO: update the hashcache here ?
def extras(self):
"""Yield all unversioned files in this WorkingTree.
@@ -1576,20 +1542,6 @@
last_rev = parent_trees[0][0]
return nb_conflicts
- def _write_hashcache_if_dirty(self):
- """Write out the hashcache if it is dirty."""
- if self._hashcache.needs_write:
- try:
- self._hashcache.write()
- except OSError, e:
- if e.errno not in (errno.EPERM, errno.EACCES):
- raise
- # TODO: jam 20061219 Should this be a warning? A single line
- # warning might be sufficient to let the user know what
- # is going on.
- mutter('Could not write hashcache for %s\nError: %s',
- self._hashcache.cache_file_name(), e)
-
def set_conflicts(self, arg):
raise errors.UnsupportedOperation(self.set_conflicts, self)
@@ -1827,6 +1779,8 @@
branch=branch, _control_files=_control_files, _internal=_internal,
_format=_format, _bzrdir=_bzrdir)
+ self._detect_case_handling()
+
if _inventory is None:
# This will be acquired on lock_read() or lock_write()
self._inventory_is_modified = False
@@ -1851,6 +1805,17 @@
self._inventory = inv
self._inventory_is_modified = dirty
+ def _detect_case_handling(self):
+ wt_trans = self.bzrdir.get_workingtree_transport(None)
+ try:
+ wt_trans.stat(self._format.case_sensitive_filename)
+ except errors.NoSuchFile:
+ self.case_sensitive = True
+ else:
+ self.case_sensitive = False
+
+ self._setup_directory_is_tree_reference()
+
def _serialize(self, inventory, out_file):
xml5.serializer_v5.write_inventory(self._inventory, out_file,
working=True)
@@ -2160,12 +2125,6 @@
mode=self.bzrdir._get_file_mode())
self._inventory_is_modified = False
- @needs_read_lock
- def get_file_sha1(self, file_id, path=None, stat_value=None):
- if not path:
- path = self._inventory.id2path(file_id)
- return self._hashcache.get_sha1(path, stat_value)
-
def get_file_mtime(self, file_id, path=None):
"""See Tree.get_file_mtime."""
if not path:
=== modified file 'bzrlib/workingtree_3.py'
--- a/bzrlib/workingtree_3.py 2011-06-28 11:29:03 +0000
+++ b/bzrlib/workingtree_3.py 2011-08-30 17:32:29 +0000
@@ -18,11 +18,15 @@
"""
+import errno
+
from bzrlib import (
bzrdir,
errors,
+ hashcache,
inventory,
revision as _mod_revision,
+ trace,
transform,
)
from bzrlib.decorators import (
@@ -36,7 +40,53 @@
WorkingTreeFormat,
)
-class WorkingTree3(InventoryWorkingTree):
+
+class PreDirStateWorkingTree(InventoryWorkingTree):
+
+ def __init__(self, basedir='.', *args, **kwargs):
+ super(PreDirStateWorkingTree, self).__init__(basedir, *args, **kwargs)
+ # update the whole cache up front and write to disk if anything changed;
+ # in the future we might want to do this more selectively
+ # two possible ways offer themselves : in self._unlock, write the cache
+ # if needed, or, when the cache sees a change, append it to the hash
+ # cache file, and have the parser take the most recent entry for a
+ # given path only.
+ wt_trans = self.bzrdir.get_workingtree_transport(None)
+ cache_filename = wt_trans.local_abspath('stat-cache')
+ self._hashcache = hashcache.HashCache(basedir, cache_filename,
+ self.bzrdir._get_file_mode(),
+ self._content_filter_stack_provider())
+ hc = self._hashcache
+ hc.read()
+ # is this scan needed ? it makes things kinda slow.
+ #hc.scan()
+
+ if hc.needs_write:
+ trace.mutter("write hc")
+ hc.write()
+
+ def _write_hashcache_if_dirty(self):
+ """Write out the hashcache if it is dirty."""
+ if self._hashcache.needs_write:
+ try:
+ self._hashcache.write()
+ except OSError, e:
+ if e.errno not in (errno.EPERM, errno.EACCES):
+ raise
+ # TODO: jam 20061219 Should this be a warning? A single line
+ # warning might be sufficient to let the user know what
+ # is going on.
+ trace.mutter('Could not write hashcache for %s\nError: %s',
+ self._hashcache.cache_file_name(), e)
+
+ @needs_read_lock
+ def get_file_sha1(self, file_id, path=None, stat_value=None):
+ if not path:
+ path = self._inventory.id2path(file_id)
+ return self._hashcache.get_sha1(path, stat_value)
+
+
+class WorkingTree3(PreDirStateWorkingTree):
"""This is the Format 3 working tree.
This differs from the base WorkingTree by:
More information about the bazaar-commits
mailing list