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

[PATCH 4/4] refresh_index: notice typechanges in output

From
Jeff King <peff@peff.net>
Date
Nov 14, 2011, 22:56 UTC
Message-ID
<20111114225651.GD3993@sigill.intra.peff.net>
In-Reply-To
<20111114225056.GA27370@sigill.intra.peff.net>

If a file changes type and a porcelain updates the index, we will print "M file". Instead, let's be more specific and print "T file", which matches actual diff and status output.

The plumbing version remains "needs update" for historical compatibility.

Signed-off-by: Jeff King <peff@peff.net>
---
The "changed" flag comes from refresh_cache_ent, which in turn gets it
from ie_modified_stat. The one hesitation I have is that intent-to-add
entries get the TYPE_CHANGED flag set, which means they will get a "T"
output. Whereas I actually think "M" is a little more sensible.

For "git reset", I'm not sure if it matters, since resetting the index will always drop such an entry anyway. But you can see it with:

  git add -N file
  git add --refresh -v other
 read-cache.c |    6 +++++-
 1 files changed, 5 insertions(+), 1 deletions(-)
diff --git a/read-cache.c b/read-cache.c
index 83fb19c..0e17add 100644
--- a/read-cache.c
+++ b/read-cache.c
@@ -1107,14 +1107,17 @@ int refresh_index(struct index_state *istate, unsigned int flags, const char **p
 	unsigned int options = really ? CE_MATCH_IGNORE_VALID : 0;
 	const char *modified_fmt;
 	const char *deleted_fmt;
+	const char *typechange_fmt;
 	const char *unmerged_fmt;
 
 	modified_fmt = (in_porcelain ? "M\t%s\n" : "%s: needs update\n");
 	deleted_fmt = (in_porcelain ? "D\t%s\n" : "%s: needs update\n");
+	typechange_fmt = (in_porcelain ? "T\t%s\n" : "%s needs update\n");
 	unmerged_fmt = (in_porcelain ? "U\t%s\n" : "%s: needs merge\n");
 	for (i = 0; i < istate->cache_nr; i++) {
 		struct cache_entry *ce, *new;
 		int cache_errno = 0;
+		int changed = 0;
 
 		ce = istate->cache[i];
 		if (ignore_submodules && S_ISGITLINK(ce->ce_mode))
@@ -1135,7 +1138,7 @@ int refresh_index(struct index_state *istate, unsigned int flags, const char **p
 		if (pathspec && !match_pathspec(pathspec, ce->name, strlen(ce->name), 0, seen))
 			continue;
 
-		new = refresh_cache_ent(istate, ce, options, &cache_errno, NULL);
+		new = refresh_cache_ent(istate, ce, options, &cache_errno, &changed);
 		if (new == ce)
 			continue;
 		if (!new) {
@@ -1151,6 +1154,7 @@ int refresh_index(struct index_state *istate, unsigned int flags, const char **p
 			if (quiet)
 				continue;
 			show_file((cache_errno == ENOENT ? deleted_fmt :
+				   changed & TYPE_CHANGED ? typechange_fmt :
 				   modified_fmt),
 				  ce->name, in_porcelain, &first, header_msg);
 			has_errors = 1;
-- 
1.7.7.3.8.g38efa
Previous: Jeff KingNext: Junio C Hamano
Message 11 of 18 in “reset reports file as modified when it's in fact deleted”
  1. Carlos Martín NietoNov 7, 2011
  2. Jeff KingNov 7, 2011
  3. Carlos Martín NietoNov 11, 2011
  4. Junio C HamanoNov 11, 2011
  5. Jeff KingNov 11, 2011
  6. Junio C HamanoNov 12, 2011
  7. Jeff KingNov 14, 2011
  8. 1/4 refresh_index: rename format variablesJeff King, Nov 14, 2011
  9. 2/4 refresh_index: mark deletions in porcelain outputJeff King, Nov 14, 2011
  10. 3/4 read-cache: let refresh_cache_ent pass up changed flagsJeff King, Nov 14, 2011
  11. 4/4 refresh_index: notice typechanges in outputJeff King, Nov 14, 2011
  12. Junio C HamanoNov 15, 2011
  13. Jeff KingNov 15, 2011
  14. Jeff KingNov 18, 2011
  15. 1/3 read-cache: let refresh_cache_ent pass up changed flagsJeff King, Nov 18, 2011
  16. 2/3 refresh_index: rename format variablesJeff King, Nov 18, 2011
  17. 3/3 refresh_index: make porcelain output more specificJeff King, Nov 18, 2011
  18. Junio C HamanoNov 18, 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.