git/list[1] front-page[2] threads[3] people[4] search[5] about
 

[PATCH 1/2] diff-lib: simplify do_diff_cache()

From
Junio C Hamano <gitster@pobox.com>
Date
Jul 19, 2011, 18:13 UTC
Message-ID
<1311099186-16482-2-git-send-email-gitster@pobox.com>
In-Reply-To
<1311099186-16482-1-git-send-email-gitster@pobox.com>

Since 34110cd (Make 'unpack_trees()' have a separate source and destination index, 2008-03-06), we can run unpack_trees() without munging the index at all, but do_diff_cache() tried ever so carefully to work around the old behaviour of the function.

We can just tell unpack_trees() not to touch the original index and there is no need to clean-up whatever the previous round has done.

Signed-off-by: Junio C Hamano <gitster@pobox.com>
---
 diff-lib.c |   26 +-------------------------
 1 files changed, 1 insertions(+), 25 deletions(-)
diff --git a/diff-lib.c b/diff-lib.c
index fd61acb..b5bb58d 100644
--- a/diff-lib.c
+++ b/diff-lib.c
@@ -480,33 +480,9 @@ int do_diff_cache(const unsigned char *tree_sha1, struct diff_options *opt)
 {
 	struct tree *tree;
 	struct rev_info revs;
-	int i;
-	struct cache_entry **dst;
-	struct cache_entry *last = NULL;
 	struct unpack_trees_options opts;
 	struct tree_desc t;
 
-	/*
-	 * This is used by git-blame to run diff-cache internally;
-	 * it potentially needs to repeatedly run this, so we will
-	 * start by removing the higher order entries the last round
-	 * left behind.
-	 */
-	dst = active_cache;
-	for (i = 0; i < active_nr; i++) {
-		struct cache_entry *ce = active_cache[i];
-		if (ce_stage(ce)) {
-			if (last && !strcmp(ce->name, last->name))
-				continue;
-			cache_tree_invalidate_path(active_cache_tree,
-						   ce->name);
-			last = ce;
-			ce->ce_flags |= CE_REMOVE;
-		}
-		*dst++ = ce;
-	}
-	active_nr = dst - active_cache;
-
 	init_revisions(&revs, NULL);
 	init_pathspec(&revs.prune_data, opt->pathspec.raw);
 	tree = parse_tree_indirect(tree_sha1);
@@ -521,7 +497,7 @@ int do_diff_cache(const unsigned char *tree_sha1, struct diff_options *opt)
 	opts.fn = oneway_diff;
 	opts.unpack_data = &revs;
 	opts.src_index = &the_index;
-	opts.dst_index = &the_index;
+	opts.dst_index = NULL;
 
 	init_tree_desc(&t, tree->buffer, tree->size);
 	if (unpack_trees(1, &t, &opts))
-- 
1.7.6.178.g55272
Previous: Junio C HamanoNext: Jeff King
Message 6 of 9 in “reproducible unexpected behavior for 'git reset'”
  1. John NowakJul 10, 2011
  2. Junio C HamanoJul 11, 2011
  3. Junio C HamanoJul 11, 2011
  4. Junio C HamanoJul 14, 2011
  5. 0/2 refactoring diff-indexJunio C Hamano, Jul 19, 2011
  6. 1/2 diff-lib: simplify do_diff_cache()Junio C Hamano, Jul 19, 2011
  7. Jeff KingJul 19, 2011
  8. Junio C HamanoJul 19, 2011
  9. 2/2 diff-lib: refactor run_diff_index() and do_diff_cache()Junio C Hamano, Jul 19, 2011

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.