git.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Junio C Hamano <gitster@pobox.com>
To: git@vger.kernel.org
Subject: [PATCH 1/4] read-tree A B: do not corrupt cache-tree
Date: Mon, 20 Apr 2009 03:58:17 -0700	[thread overview]
Message-ID: <1240225100-29960-2-git-send-email-gitster@pobox.com> (raw)
In-Reply-To: <1240225100-29960-1-git-send-email-gitster@pobox.com>

An earlier commit aab3b9a (read-tree A B C: do not create a bogus index
and do not segfault, 2009-03-12) resurrected the support for an obscure
(but useful) feature to read and overlay more than one tree into the index
without the -m (merge) option.  But the fix was not enough.

Exercising this feature exposes a longstanding bug in the code that primes
the cache-tree in the index from the tree that was read.  The intention
was that when we know that the index must exactly match the tree we just
read, we prime the entire cache-tree with it.

However, the logic to detect that case incorrectly triggered if you read
two trees without -m.  This resulted in a corrupted cache-tree, and
write-tree would have produced an incorrect tree object out of such an
index.

Signed-off-by: Junio C Hamano <gitster@pobox.com>
---
 * Meant for maint.

 builtin-read-tree.c |    6 ++----
 1 files changed, 2 insertions(+), 4 deletions(-)

diff --git a/builtin-read-tree.c b/builtin-read-tree.c
index 38fef34..e4e0e71 100644
--- a/builtin-read-tree.c
+++ b/builtin-read-tree.c
@@ -211,7 +211,6 @@ int cmd_read_tree(int argc, const char **argv, const char *unused_prefix)
 		case 3:
 		default:
 			opts.fn = threeway_merge;
-			cache_tree_free(&active_cache_tree);
 			break;
 		}
 
@@ -221,6 +220,7 @@ int cmd_read_tree(int argc, const char **argv, const char *unused_prefix)
 			opts.head_idx = 1;
 	}
 
+	cache_tree_free(&active_cache_tree);
 	for (i = 0; i < nr_trees; i++) {
 		struct tree *tree = trees[i];
 		parse_tree(tree);
@@ -235,10 +235,8 @@ int cmd_read_tree(int argc, const char **argv, const char *unused_prefix)
 	 * valid cache-tree because the index must match exactly
 	 * what came from the tree.
 	 */
-	if (nr_trees && !opts.prefix && (!opts.merge || (stage == 2))) {
-		cache_tree_free(&active_cache_tree);
+	if (nr_trees == 1 && !opts.prefix)
 		prime_cache_tree();
-	}
 
 	if (write_cache(newfd, active_cache, active_nr) ||
 	    commit_locked_index(&lock_file))
-- 
1.6.3.rc1.18.g66996

  reply	other threads:[~2009-04-20 11:00 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2009-04-20 10:58 [PATCH 0/4] Revisiting cache-tree Junio C Hamano
2009-04-20 10:58 ` Junio C Hamano [this message]
2009-04-20 10:58   ` [PATCH 2/4] Move prime_cache_tree() to cache-tree.c Junio C Hamano
2009-04-20 10:58     ` [PATCH 3/4] read-tree -m A B: prime cache-tree from the switched-to tree Junio C Hamano
2009-04-20 10:58       ` [PATCH 4/4] checkout branch: prime cache-tree fully Junio C Hamano
2009-04-20 13:08 ` [PATCH 0/4] Revisiting cache-tree Alex Riesen

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

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

  git send-email \
    --in-reply-to=1240225100-29960-2-git-send-email-gitster@pobox.com \
    --to=gitster@pobox.com \
    --cc=git@vger.kernel.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.
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 NNTP newsgroup(s).