Skip to content

Commit 73b7eae

Browse files
peffgitster
authored andcommitted
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 <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 4bd4e73 commit 73b7eae

File tree

1 file changed

+21
-2
lines changed

1 file changed

+21
-2
lines changed

read-cache.c

Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1106,13 +1106,20 @@ int refresh_index(struct index_state *istate, unsigned int flags, const char **p
11061106
int in_porcelain = (flags & REFRESH_IN_PORCELAIN);
11071107
unsigned int options = really ? CE_MATCH_IGNORE_VALID : 0;
11081108
const char *modified_fmt;
1109+
const char *deleted_fmt;
1110+
const char *typechange_fmt;
1111+
const char *added_fmt;
11091112
const char *unmerged_fmt;
11101113

11111114
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");
11121118
unmerged_fmt = (in_porcelain ? "U\t%s\n" : "%s: needs merge\n");
11131119
for (i = 0; i < istate->cache_nr; i++) {
11141120
struct cache_entry *ce, *new;
11151121
int cache_errno = 0;
1122+
int changed = 0;
11161123

11171124
ce = istate->cache[i];
11181125
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
11331140
if (pathspec && !match_pathspec(pathspec, ce->name, strlen(ce->name), 0, seen))
11341141
continue;
11351142

1136-
new = refresh_cache_ent(istate, ce, options, &cache_errno, NULL);
1143+
new = refresh_cache_ent(istate, ce, options, &cache_errno, &changed);
11371144
if (new == ce)
11381145
continue;
11391146
if (!new) {
1147+
const char *fmt;
1148+
11401149
if (not_new && cache_errno == ENOENT)
11411150
continue;
11421151
if (really && cache_errno == EINVAL) {
@@ -1148,7 +1157,17 @@ int refresh_index(struct index_state *istate, unsigned int flags, const char **p
11481157
}
11491158
if (quiet)
11501159
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);
11521171
has_errors = 1;
11531172
continue;
11541173
}

0 commit comments

Comments
 (0)