refresh_index: make porcelain output more specific

If you have a deleted file and a porcelain refreshes the cache, we print: Unstaged changes after reset: M file This is technically correct, in that the file is modified, but it's friendlier to the user if we further differentiate the case of a deleted file (especially because this output looks a lot like "diff --name-status", which would also make the distinction). Similarly, we can distinguish typechanges ("T") and intent-to-add files ("A"), both of which appear as just "M" in the current output. The plumbing output for all cases remains "needs update" for historical compatibility. Signed-off-by: Jeff King <peff@peff.net> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Jeff King committed Nov 18, 2011 at 06:13 UTC 73b7eae60c18036eab21a84e42bfa8b5297fe679
1 file changed +21 -2
read-cache.c
+21 -2
@@ -1106,13 +1106,20 @@ int refresh_index(struct index_state *istate, unsigned int flags, const char **p
1106 int in_porcelain = (flags & REFRESH_IN_PORCELAIN);
1107 unsigned int options = really ? CE_MATCH_IGNORE_VALID : 0;
1108 const char *modified_fmt;
1109 + const char *deleted_fmt;
1110 + const char *typechange_fmt;
1111 + const char *added_fmt;
1112 const char *unmerged_fmt;
1113
1114 modified_fmt = (in_porcelain ? "M\t%s\n" : "%s: needs update\n");
1115 + deleted_fmt = (in_porcelain ? "D\t%s\n" : "%s: needs update\n");
1116 + typechange_fmt = (in_porcelain ? "T\t%s\n" : "%s needs update\n");
1117 + added_fmt = (in_porcelain ? "A\t%s\n" : "%s needs update\n");
1118 unmerged_fmt = (in_porcelain ? "U\t%s\n" : "%s: needs merge\n");
1119 for (i = 0; i < istate->cache_nr; i++) {
1120 struct cache_entry *ce, *new;
1121 int cache_errno = 0;
1122 + int changed = 0;
1123
1124 ce = istate->cache[i];
1125 if (ignore_submodules && S_ISGITLINK(ce->ce_mode))
@@ -1133,10 +1140,12 @@ int refresh_index(struct index_state *istate, unsigned int flags, const char **p
1140 if (pathspec && !match_pathspec(pathspec, ce->name, strlen(ce->name), 0, seen))
1141 continue;
1142
1136 - new = refresh_cache_ent(istate, ce, options, &cache_errno, NULL);
1143 + new = refresh_cache_ent(istate, ce, options, &cache_errno, &changed);
1144 if (new == ce)
1145 continue;
1146 if (!new) {
1147 + const char *fmt;
1148 +
1149 if (not_new && cache_errno == ENOENT)
1150 continue;
1151 if (really && cache_errno == EINVAL) {
@@ -1148,7 +1157,17 @@ int refresh_index(struct index_state *istate, unsigned int flags, const char **p
1157 }
1158 if (quiet)
1159 continue;
1151 - show_file(modified_fmt, ce->name, in_porcelain, &first, header_msg);
1160 +
1161 + if (cache_errno == ENOENT)
1162 + fmt = deleted_fmt;
1163 + else if (ce->ce_flags & CE_INTENT_TO_ADD)
1164 + fmt = added_fmt; /* must be before other checks */
1165 + else if (changed & TYPE_CHANGED)
1166 + fmt = typechange_fmt;
1167 + else
1168 + fmt = modified_fmt;
1169 + show_file(fmt,
1170 + ce->name, in_porcelain, &first, header_msg);
1171 has_errors = 1;
1172 continue;
1173 }