From e40b5f075bdb9d6c2992a0a1cf05f7f6f4f101a3 Mon Sep 17 00:00:00 2001 From: Sebastian Thiel Date: Wed, 25 Nov 2009 15:14:10 +0100 Subject: index.write_tree: fixed bug that would cause the written tree not to contain any of our changes entries as it would in fact write a possibly cached tree stored in our extension data.It was solved by simply ignoring that extension data when writing the index for tree creation. A test was added for this as well --- lib/git/index.py | 20 +++++++++++++++++++- 1 file changed, 19 insertions(+), 1 deletion(-) (limited to 'lib/git/index.py') diff --git a/lib/git/index.py b/lib/git/index.py index 54bb0209..61307bb8 100644 --- a/lib/git/index.py +++ b/lib/git/index.py @@ -191,7 +191,7 @@ class IndexEntry(BaseIndexEntry): Instance of type BaseIndexEntry """ time = struct.pack(">LL", 0, 0) - return IndexEntry((base.mode, base.sha, base.stage, base.path, time, time, 1, 1, 1, 1, 0)) + return IndexEntry((base.mode, base.sha, base.stage, base.path, time, time, 0, 0, 0, 0, 0)) @classmethod def from_blob(cls, blob): @@ -352,6 +352,10 @@ class IndexFile(LazyMixin, diff.Diffable): # the footer contains extension data and a sha on the content so far # Keep the extension footer,and verify we have a sha in the end + # Extension data format is: + # 4 bytes ID + # 4 bytes length of chunk + # repeated 0 - N times self._extension_data = stream.read(~0) assert len(self._extension_data) > 19, "Index Footer was not at least a sha on content as it was only %i bytes in size" % len(self._extension_data) @@ -733,9 +737,23 @@ class IndexFile(LazyMixin, diff.Diffable): index_path = self._index_path() tmp_index_mover = _TemporaryFileSwap(index_path) + # IMPORTANT: If we have TREE extension data, it will actually + # ignore the index and write the stored tree instead. Hence we + # temporarily forget about it, and in fact I don't know what git + # uses it for + stored_ext_data = None + if self._extension_data and self._extension_data[:4] == 'TREE': + stored_ext_data = self._extension_data + self._extension_data = '' + # END extension data special handling + self.write(index_path) tree_sha = self.repo.git.write_tree(missing_ok=missing_ok) + if stored_ext_data: + self._extension_data = stored_ext_data + # END reset stored exstension data + return Tree(self.repo, tree_sha, 0, '') def _process_diff_args(self, args): -- cgit v1.2.1