diff options
author | Junio C Hamano <gitster@pobox.com> | 2008-08-23 12:57:30 -0700 |
---|---|---|
committer | Junio C Hamano <gitster@pobox.com> | 2008-08-23 18:09:27 -0700 |
commit | 913e0e99b6a6e63af6a062622a1f94bd78fd8052 (patch) | |
tree | f7fb7fd1cb378c2db864e09c14a27ed1ab512f34 /unpack-trees.c | |
parent | 893d340f2c735dc85b9360556ccd46cc0bf27fc0 (diff) | |
download | git-913e0e99b6a6e63af6a062622a1f94bd78fd8052.tar.gz |
unpack_trees(): protect the handcrafted in-core index from read_cache()
unpack_trees() rebuilds the in-core index from scratch by allocating a new
structure and finishing it off by copying the built one to the final
index.
The resulting in-core index is Ok for most use, but read_cache() does not
recognize it as such. The function is meant to be no-op if you already
have loaded the index, until you call discard_cache().
This change the way read_cache() detects an already initialized in-core
index, by introducing an extra bit, and marks the handcrafted in-core
index as initialized, to avoid this problem.
A better fix in the longer term would be to change the read_cache() API so
that it will always discard and re-read from the on-disk index to avoid
confusion. But there are higher level API that have relied on the current
semantics, and they and their users all need to get converted, which is
outside the scope of 'maint' track.
An example of such a higher level API is write_cache_as_tree(), which is
used by git-write-tree as well as later Porcelains like git-merge, revert
and cherry-pick. In the longer term, we should remove read_cache() from
there and add one to cmd_write_tree(); other callers expect that the
in-core index they prepared is what gets written as a tree so no other
change is necessary for this particular codepath.
The original version of this patch marked the index by pointing an
otherwise wasted malloc'ed memory with o->result.alloc, but this version
uses Linus's idea to use a new "initialized" bit, which is conceptually
much cleaner.
Signed-off-by: Junio C Hamano <gitster@pobox.com>
Diffstat (limited to 'unpack-trees.c')
-rw-r--r-- | unpack-trees.c | 1 |
1 files changed, 1 insertions, 0 deletions
diff --git a/unpack-trees.c b/unpack-trees.c index cba0aca062..ef21c62195 100644 --- a/unpack-trees.c +++ b/unpack-trees.c @@ -376,6 +376,7 @@ int unpack_trees(unsigned len, struct tree_desc *t, struct unpack_trees_options state.refresh_cache = 1; memset(&o->result, 0, sizeof(o->result)); + o->result.initialized = 1; if (o->src_index) o->result.timestamp = o->src_index->timestamp; o->merge_size = len; |