From c4f49fb232acb2c02761a82acc12c4040699685d Mon Sep 17 00:00:00 2001 From: Sebastian Thiel Date: Tue, 22 Jun 2010 12:03:37 +0200 Subject: index.write_tree: now uses MemoryDB, making tree handling more efficient as IO will only be done when required. A possible disadvantage though is that time is spent on compressing the trees, although only the raw data and their shas would theoretically be needed. On the other hand, compressing their data uses less memory. An optimal implementation would just sha the data, check for existance, and compress it to write it to the database right away. This would mean more specialized code though, introducing redundancy. If IStreams would know whether they contain compressed or uncompressed data, and if there was a method to get a sha from data, this would work nicely in the existing framework though --- lib/git/ext/gitdb | 2 +- lib/git/index/base.py | 10 +++++++--- 2 files changed, 8 insertions(+), 4 deletions(-) (limited to 'lib/git') diff --git a/lib/git/ext/gitdb b/lib/git/ext/gitdb index 92ca2e4a..9b53ab02 160000 --- a/lib/git/ext/gitdb +++ b/lib/git/ext/gitdb @@ -1 +1 @@ -Subproject commit 92ca2e4ad606fbec7c934ad9e467a1b51fddcc92 +Subproject commit 9b53ab02cb44571e6167a125a5296b7c3395563f diff --git a/lib/git/index/base.py b/lib/git/index/base.py index 48b2d766..06437702 100644 --- a/lib/git/index/base.py +++ b/lib/git/index/base.py @@ -66,6 +66,7 @@ from fun import ( ) from gitdb.base import IStream +from gitdb.db import MemoryDB __all__ = ( 'IndexFile', 'CheckoutError' ) @@ -502,10 +503,13 @@ class IndexFile(LazyMixin, diff.Diffable, Serializable): if not self.entries: raise ValueError("Cannot write empty index") - # TODO: use memory db, this helps to prevent IO if the resulting tree - # already exists + mdb = MemoryDB() entries = self._entries_sorted() - binsha, tree_items = write_tree_from_cache(entries, self.repo.odb, slice(0, len(entries))) + binsha, tree_items = write_tree_from_cache(entries, mdb, slice(0, len(entries))) + + # copy changed trees only + mdb.stream_copy(mdb.sha_iter(), self.repo.odb) + # note: additional deserialization could be saved if write_tree_from_cache # would return sorted tree entries -- cgit v1.2.3