git@vger.kernel.org mailing list mirror (one of many)
 help / color / mirror / code / Atom feed
From: Linus Torvalds <torvalds@linux-foundation.org>
To: Junio C Hamano <gitster@pobox.com>
Cc: Paolo Bonzini <bonzini@gnu.org>,
	Miklos Vajna <vmiklos@frugalware.org>, Jeff King <peff@peff.net>,
	git@vger.kernel.org
Subject: Re: [RFH] two and half potential fixlets to the in-core index handling
Date: Sat, 23 Aug 2008 11:13:14 -0700 (PDT)	[thread overview]
Message-ID: <alpine.LFD.1.10.0808231104500.3363@nehalem.linux-foundation.org> (raw)
In-Reply-To: <7vbpzkypwz.fsf_-_@gitster.siamese.dyndns.org>



On Sat, 23 Aug 2008, Junio C Hamano wrote:
> 
> A hacky solution I have in the attached patch is to waste an xmalloc(1)
> and store it there when o->result is created, and also make
> read_from_index() pay attention to the cache_nr and the cache_changed
> bit. I think it is the safest and minimum fix.

Hmm. Wouldn't it be nicer to just add another bit to istate? We have the 
space already, since we already have a bitfield there, with just one bit 
used?

Something like this..

Untested. Of course.

			Linus

---
 cache.h        |    3 ++-
 read-cache.c   |    4 +++-
 unpack-trees.c |    1 +
 3 files changed, 6 insertions(+), 2 deletions(-)

diff --git a/cache.h b/cache.h
index 68ce6e6..6e41ec4 100644
--- a/cache.h
+++ b/cache.h
@@ -222,7 +222,8 @@ struct index_state {
 	struct cache_tree *cache_tree;
 	time_t timestamp;
 	void *alloc;
-	unsigned name_hash_initialized : 1;
+	unsigned name_hash_initialized : 1,
+		 initialized : 1;
 	struct hash_table name_hash;
 };
 
diff --git a/read-cache.c b/read-cache.c
index 2c03ec3..35fec46 100644
--- a/read-cache.c
+++ b/read-cache.c
@@ -1155,7 +1155,7 @@ int read_index_from(struct index_state *istate, const char *path)
 	size_t mmap_size;
 
 	errno = EBUSY;
-	if (istate->alloc)
+	if (istate->initialized)
 		return istate->cache_nr;
 
 	errno = ENOENT;
@@ -1195,6 +1195,7 @@ int read_index_from(struct index_state *istate, const char *path)
 	 * index size
 	 */
 	istate->alloc = xmalloc(estimate_cache_size(mmap_size, istate->cache_nr));
+	istate->initialized = 1;
 
 	src_offset = sizeof(*hdr);
 	dst_offset = 0;
@@ -1247,6 +1248,7 @@ int discard_index(struct index_state *istate)
 	cache_tree_free(&(istate->cache_tree));
 	free(istate->alloc);
 	istate->alloc = NULL;
+	istate->initialized = 0;
 
 	/* no need to throw away allocated active_cache */
 	return 0;
diff --git a/unpack-trees.c b/unpack-trees.c
index cba0aca..ef21c62 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;

  reply	other threads:[~2008-08-23 18:18 UTC|newest]

Thread overview: 22+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2008-08-22  6:36 [bug] git `next' does not do trivial merges Paolo Bonzini
2008-08-22 19:31 ` Jeff King
2008-08-23  6:08   ` Miklos Vajna
2008-08-23  8:14     ` [PATCH] Fix in-index merge Miklos Vajna
2008-08-23  8:17       ` [PATCH] builtin-merge: fail properly when we are in the middle of a conflicted merge Miklos Vajna
2008-08-23  9:01         ` Junio C Hamano
2008-08-23 10:57           ` Miklos Vajna
2008-08-23 19:55             ` Junio C Hamano
2008-08-23 19:56               ` [PATCH 1/2] merge: fix numerus bugs around "trivial merge" area Junio C Hamano
2008-08-24  1:58                 ` Junio C Hamano
2008-08-28 13:43                   ` [PATCH] builtin-merge: avoid run_command_v_opt() for recursive and subtree Miklos Vajna
2008-08-23 19:57               ` [PATCH 2/2] unpack_trees(): protect the handcrafted in-core index from read_cache() Junio C Hamano
2008-08-23  9:50         ` [PATCH] builtin-merge: fail properly when we are in the middle of a conflicted merge Junio C Hamano
2008-08-23  8:50       ` [PATCH] Fix in-index merge Junio C Hamano
2008-08-23 10:41         ` Miklos Vajna
2008-08-23  9:19       ` Paolo Bonzini
2008-08-23  9:55         ` Junio C Hamano
2008-08-23 10:00           ` Junio C Hamano
2008-08-23 10:41             ` [RFH] two and half potential fixlets to the in-core index handling Junio C Hamano
2008-08-23 18:13               ` Linus Torvalds [this message]
2008-08-23 19:14                 ` Junio C Hamano
2008-08-23 19:21                   ` Junio C Hamano

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: http://vger.kernel.org/majordomo-info.html

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=alpine.LFD.1.10.0808231104500.3363@nehalem.linux-foundation.org \
    --to=torvalds@linux-foundation.org \
    --cc=bonzini@gnu.org \
    --cc=git@vger.kernel.org \
    --cc=gitster@pobox.com \
    --cc=peff@peff.net \
    --cc=vmiklos@frugalware.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

	https://80x24.org/mirrors/git.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).