diff options
author | Sebastian Thiel <byronimo@gmail.com> | 2010-06-23 15:48:57 +0200 |
---|---|---|
committer | Sebastian Thiel <byronimo@gmail.com> | 2010-06-23 15:48:57 +0200 |
commit | 1e2265a23ecec4e4d9ad60d788462e7f124f1bb7 (patch) | |
tree | 67c56788c74b87e8720562556168f57b439a6ab1 | |
parent | aea0243840a46021e6f77c759c960a06151d91c9 (diff) | |
download | gitpython-1e2265a23ecec4e4d9ad60d788462e7f124f1bb7.tar.gz |
fixed critical bug in traverse_trees_recursive, implemented IndexFile.new including simple test, it may be simple as the methods it uses are throroughly tested
-rw-r--r-- | lib/git/index/base.py | 17 | ||||
-rw-r--r-- | lib/git/index/fun.py | 11 | ||||
-rw-r--r-- | lib/git/objects/fun.py | 2 | ||||
-rw-r--r-- | test/git/test_fun.py | 9 | ||||
-rw-r--r-- | test/git/test_index.py | 9 |
5 files changed, 31 insertions, 17 deletions
diff --git a/lib/git/index/base.py b/lib/git/index/base.py index f1be00e0..af45171b 100644 --- a/lib/git/index/base.py +++ b/lib/git/index/base.py @@ -59,14 +59,16 @@ from git.utils import ( ) from fun import ( + entry_key, write_cache, read_cache, - write_tree_from_cache, - entry_key + aggressive_tree_merge, + write_tree_from_cache ) from gitdb.base import IStream from gitdb.db import MemoryDB +from itertools import izip __all__ = ( 'IndexFile', 'CheckoutError' ) @@ -253,10 +255,15 @@ class IndexFile(LazyMixin, diff.Diffable, Serializable): New IndexFile instance. Its path will be undefined. If you intend to write such a merged Index, supply an alternate file_path to its 'write' method.""" - base_entries = aggressive_tree_merge(repo.odb, tree_sha) + base_entries = aggressive_tree_merge(repo.odb, [str(t) for t in tree_sha]) - inst = cls(self.repo) - raise NotImplementedError("convert to entries") + inst = cls(repo) + # convert to entries dict + entries = dict(izip(((e.path, e.stage) for e in base_entries), + (IndexEntry.from_base(e) for e in base_entries))) + + inst.entries = entries + return inst @classmethod diff --git a/lib/git/index/fun.py b/lib/git/index/fun.py index b04d018f..23a6d8f9 100644 --- a/lib/git/index/fun.py +++ b/lib/git/index/fun.py @@ -78,15 +78,16 @@ def write_cache(entries, stream, extension_data=None, ShaStreamCls=IndexFileSHA1 def read_entry(stream): """Return: One entry of the given stream""" beginoffset = stream.tell() - ctime = unpack(">8s", stream.read(8))[0] - mtime = unpack(">8s", stream.read(8))[0] + read = stream.read + ctime = unpack(">8s", read(8))[0] + mtime = unpack(">8s", read(8))[0] (dev, ino, mode, uid, gid, size, sha, flags) = \ - unpack(">LLLLLL20sH", stream.read(20 + 4 * 6 + 2)) + unpack(">LLLLLL20sH", read(20 + 4 * 6 + 2)) path_size = flags & CE_NAMEMASK - path = stream.read(path_size) + path = read(path_size) real_size = ((stream.tell() - beginoffset + 8) & ~7) - data = stream.read((beginoffset + real_size) - stream.tell()) + data = read((beginoffset + real_size) - stream.tell()) return IndexEntry((mode, sha, flags, path, ctime, mtime, dev, ino, uid, gid, size)) def read_header(stream): diff --git a/lib/git/objects/fun.py b/lib/git/objects/fun.py index d21a7dad..c2e7358f 100644 --- a/lib/git/objects/fun.py +++ b/lib/git/objects/fun.py @@ -148,7 +148,7 @@ def traverse_trees_recursive(odb, tree_shas, path_prefix): # if we are a directory, enter recursion if is_dir: - out.extend(traverse_trees_recursive(odb, [ei[0] for ei in entries if ei], path_prefix+name+'/')) + out.extend(traverse_trees_recursive(odb, [((ei and ei[0]) or None) for ei in entries], path_prefix+name+'/')) else: out_append(tuple(_to_full_path(e, path_prefix) for e in entries)) # END handle recursion diff --git a/test/git/test_fun.py b/test/git/test_fun.py index ce610014..b2b94415 100644 --- a/test/git/test_fun.py +++ b/test/git/test_fun.py @@ -60,6 +60,9 @@ class TestFun(TestBase): M = tree("44a601a068f4f543f73fd9c49e264c931b1e1652") trees = [B.sha, H.sha, M.sha] self._assert_index_entries(aggressive_tree_merge(odb, trees), trees) + + # too many trees + self.failUnlessRaises(ValueError, aggressive_tree_merge, odb, trees*2) def mktree(self, odb, entries): """create a tree from the given tree entries and safe it to the database""" @@ -164,14 +167,10 @@ class TestFun(TestBase): # as one is deleted, there are only 2 entries assert_entries(aggressive_tree_merge(odb, trees), 2, True) # END handle ours, theirs - - - - def _assert_tree_entries(self, entries, num_trees): - assert len(entries[0]) == num_trees for entry in entries: + assert len(entry) == num_trees paths = set(e[2] for e in entry if e) # only one path per set of entries diff --git a/test/git/test_index.py b/test/git/test_index.py index ae754430..35580135 100644 --- a/test/git/test_index.py +++ b/test/git/test_index.py @@ -594,6 +594,13 @@ class TestIndex(TestBase): # END for each commit def test_index_new(self): - self.fail("todo index new") + B = self.rorepo.tree("6d9b1f4f9fa8c9f030e3207e7deacc5d5f8bba4e") + H = self.rorepo.tree("25dca42bac17d511b7e2ebdd9d1d679e7626db5f") + M = self.rorepo.tree("e746f96bcc29238b79118123028ca170adc4ff0f") + + for args in ((B,), (B,H), (B,H,M)): + index = IndexFile.new(self.rorepo, *args) + assert isinstance(index, IndexFile) + # END for each arg tuple |