Skip to content

Commit c4f49fb

Browse files
committed
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
1 parent d2d9197 commit c4f49fb

File tree

3 files changed

+14
-5
lines changed

3 files changed

+14
-5
lines changed

lib/git/ext/gitdb

Submodule gitdb updated from 92ca2e4 to 9b53ab0

lib/git/index/base.py

+7-3
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,7 @@
6666
)
6767

6868
from gitdb.base import IStream
69+
from gitdb.db import MemoryDB
6970

7071
__all__ = ( 'IndexFile', 'CheckoutError' )
7172

@@ -502,10 +503,13 @@ def write_tree(self):
502503
if not self.entries:
503504
raise ValueError("Cannot write empty index")
504505

505-
# TODO: use memory db, this helps to prevent IO if the resulting tree
506-
# already exists
506+
mdb = MemoryDB()
507507
entries = self._entries_sorted()
508-
binsha, tree_items = write_tree_from_cache(entries, self.repo.odb, slice(0, len(entries)))
508+
binsha, tree_items = write_tree_from_cache(entries, mdb, slice(0, len(entries)))
509+
510+
# copy changed trees only
511+
mdb.stream_copy(mdb.sha_iter(), self.repo.odb)
512+
509513

510514
# note: additional deserialization could be saved if write_tree_from_cache
511515
# would return sorted tree entries

test/git/test_index.py

+6-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@
66

77
from test.testlib import *
88
from git import *
9-
from git.index.util import TemporaryFileSwap
109
import inspect
1110
import os
1211
import sys
@@ -580,7 +579,13 @@ def write_tree(index):
580579
# END git cmd write tree
581580

582581
# write all trees and compare them
582+
# its important to have a few submodules in there too
583+
max_count = 100
584+
count = 0
583585
for commit in rw_repo.head.commit.traverse():
586+
if count >= max_count:
587+
break
588+
count += 1
584589
index = rw_repo.index.reset(commit)
585590
orig_tree = commit.tree
586591
new_git_tree = write_tree(index)

0 commit comments

Comments
 (0)