[Pkg-bazaar-commits] ./bzr/unstable r438: - Avoid calling Inventory.iter_entries() when finding modified
Martin Pool
mbp at sourcefrog.net
Fri Apr 10 08:19:45 UTC 2009
------------------------------------------------------------
revno: 438
committer: Martin Pool <mbp at sourcefrog.net>
timestamp: Tue 2005-05-10 16:54:12 +1000
message:
- Avoid calling Inventory.iter_entries() when finding modified
files. Just calculate path for files known to be changed.
- update_cache optionally takes inventory to avoid reading it twice.
modified:
bzrlib/commands.py
bzrlib/statcache.py
-------------- next part --------------
=== modified file 'bzrlib/commands.py'
--- a/bzrlib/commands.py 2005-05-10 06:48:34 +0000
+++ b/bzrlib/commands.py 2005-05-10 06:54:12 +0000
@@ -485,17 +485,23 @@
def run(self):
import statcache
b = Branch('.')
- sc = statcache.update_cache(b)
+ inv = b.read_working_inventory()
+ sc = statcache.update_cache(b, inv)
basis = b.basis_tree()
basis_inv = basis.inventory
- for path, ie in basis_inv.iter_entries():
- if ie.kind != 'file':
- continue
- cacheentry = sc.get(ie.file_id)
- if not cacheentry:
- # deleted
- continue
+
+ # We used to do this through iter_entries(), but that's slow
+ # when most of the files are unmodified, as is usually the
+ # case. So instead we iterate by inventory entry, and only
+ # calculate paths as necessary.
+
+ for file_id in basis_inv:
+ cacheentry = sc.get(file_id)
+ if not cacheentry: # deleted
+ continue
+ ie = basis_inv[file_id]
if cacheentry[statcache.SC_SHA1] != ie.text_sha1:
+ path = inv.id2path(file_id)
print path
=== modified file 'bzrlib/statcache.py'
--- a/bzrlib/statcache.py 2005-05-10 06:48:34 +0000
+++ b/bzrlib/statcache.py 2005-05-10 06:54:12 +0000
@@ -127,7 +127,7 @@
-def update_cache(branch, flush=False):
+def update_cache(branch, inv=None, flush=False):
"""Update and return the cache for the branch.
The returned cache may contain entries that have not been written
@@ -141,11 +141,13 @@
# We don't directly know the inum of the files of course but we do
# know where they were last sighted, so we can sort by that.
+ assert isinstance(flush, bool)
if flush:
cache = {}
else:
cache = load_cache(branch)
- inv = branch.read_working_inventory()
+ if inv == None:
+ inv = branch.read_working_inventory()
return _update_cache_from_list(branch, cache, _files_from_inventory(inv))
More information about the Pkg-bazaar-commits
mailing list