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

[PATCH RFC 5/5] cache: Use ce_norm_sha1().

From
Henrik Grubbström (Grubba) <grubba@grubba.org>
Date
Apr 16, 2010, 16:10 UTC
Message-ID
<c68d98b384086925da0194e560ae01d83a29f80c.1271432034.git.grubba@grubba.org>
In-Reply-To
<cover.1271432034.git.grubba@grubba.org>

When the conversion filter for a file is changed, the file may get listed as modified even though the user has not made any changes to it. This patch makes the index ignore such changes. It also makes git-diff compare with the normalized content rather than the original content.

Signed-off-by: Henrik Grubbström <grubba@grubba.org>
---
 diff-lib.c   |    9 ++++++---
 read-cache.c |    2 +-
 2 files changed, 7 insertions(+), 4 deletions(-)
diff --git a/diff-lib.c b/diff-lib.c
index c9f6e05..ae6118d 100644
--- a/diff-lib.c
+++ b/diff-lib.c
@@ -95,6 +95,7 @@ int run_diff_files(struct rev_info *revs, unsigned int option)
 		struct cache_entry *ce = active_cache[i];
 		int changed;
 		unsigned dirty_submodule = 0;
+		const unsigned char *norm_sha1;
 
 		if (DIFF_OPT_TST(&revs->diffopt, QUICK) &&
 			DIFF_OPT_TST(&revs->diffopt, HAS_CHANGES))
@@ -147,7 +148,8 @@ int run_diff_files(struct rev_info *revs, unsigned int option)
 				if (2 <= stage) {
 					int mode = nce->ce_mode;
 					num_compare_stages++;
-					hashcpy(dpath->parent[stage-2].sha1, nce->sha1);
+					hashcpy(dpath->parent[stage-2].sha1,
+						ce_norm_sha1(nce));
 					dpath->parent[stage-2].mode = ce_mode_from_stat(nce, mode);
 					dpath->parent[stage-2].status =
 						DIFF_STATUS_MODIFIED;
@@ -195,7 +197,7 @@ int run_diff_files(struct rev_info *revs, unsigned int option)
 			if (silent_on_removed)
 				continue;
 			diff_addremove(&revs->diffopt, '-', ce->ce_mode,
-				       ce->sha1, ce->name, 0);
+				       ce_norm_sha1(ce), ce->name, 0);
 			continue;
 		}
 		changed = match_stat_with_submodule(&revs->diffopt, ce, &st,
@@ -207,8 +209,9 @@ int run_diff_files(struct rev_info *revs, unsigned int option)
 		}
 		oldmode = ce->ce_mode;
 		newmode = ce_mode_from_stat(ce, st.st_mode);
+		norm_sha1 = ce_norm_sha1(ce);
 		diff_change(&revs->diffopt, oldmode, newmode,
-			    ce->sha1, (changed ? null_sha1 : ce->sha1),
+			    norm_sha1, (changed ? null_sha1 : norm_sha1),
 			    ce->name, 0, dirty_submodule);
 
 	}
diff --git a/read-cache.c b/read-cache.c
index 002160e..b631de9 100644
--- a/read-cache.c
+++ b/read-cache.c
@@ -94,7 +94,7 @@ static int ce_compare_data(struct cache_entry *ce, struct stat *st)
 	if (fd >= 0) {
 		unsigned char sha1[20];
 		if (!index_fd(sha1, fd, st, 0, OBJ_BLOB, ce->name))
-			match = hashcmp(sha1, ce->sha1);
+			match = hashcmp(sha1, ce_norm_sha1(ce));
 		/* index_fd() closed the file descriptor already */
 	}
 	return match;
-- 
1.7.0.4.369.g81e89
Previous: Henrik Grubbström (Grubba)Next: Junio C Hamano
Message 6 of 18 in “Patches to avoid reporting conversion changes.”
  1. 0/5 Patches to avoid reporting conversion changes.Henrik Grubbström (Grubba), Apr 16, 2010
  2. 1/5 sha1_file: Added index_blob().Henrik Grubbström (Grubba), Apr 16, 2010
  3. 2/5 cache: Added ce_norm_sha1() and related cache_entry fields.Henrik Grubbström (Grubba), Apr 16, 2010
  4. 3/5 cache: Added index extension "NORM".Henrik Grubbström (Grubba), Apr 16, 2010
  5. 4/5 reachable: Made the gc aware of the ce_norm_sha1.Henrik Grubbström (Grubba), Apr 16, 2010
  6. 5/5 cache: Use ce_norm_sha1().Henrik Grubbström (Grubba), Apr 16, 2010
  7. Junio C HamanoApr 20, 2010
  8. Henrik GrubbströmApr 20, 2010
  9. Junio C HamanoApr 20, 2010
  10. Henrik GrubbströmApr 25, 2010
  11. Jari AaltoApr 16, 2010
  12. Randal L. SchwartzApr 16, 2010
  13. Jari AaltoApr 17, 2010
  14. Randal L. SchwartzApr 17, 2010
  15. Sverre RabbelierApr 17, 2010
  16. Jakub NarebskiApr 17, 2010
  17. Sverre RabbelierApr 17, 2010
  18. Randal L. SchwartzApr 17, 2010

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.