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 /lib/git/index | |
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
Diffstat (limited to 'lib/git/index')
-rw-r--r-- | lib/git/index/base.py | 17 | ||||
-rw-r--r-- | lib/git/index/fun.py | 11 |
2 files changed, 18 insertions, 10 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): |