Skip to content

Commit 786a961

Browse files
committed
Merge branch 'jk/refresh-porcelain-output' into maint
* jk/refresh-porcelain-output: refresh_index: make porcelain output more specific refresh_index: rename format variables read-cache: let refresh_cache_ent pass up changed flags
2 parents 2ce0edc + 73b7eae commit 786a961

File tree

1 file changed

+32
-10
lines changed

1 file changed

+32
-10
lines changed

read-cache.c

Lines changed: 32 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1001,7 +1001,8 @@ int add_index_entry(struct index_state *istate, struct cache_entry *ce, int opti
10011001
*/
10021002
static struct cache_entry *refresh_cache_ent(struct index_state *istate,
10031003
struct cache_entry *ce,
1004-
unsigned int options, int *err)
1004+
unsigned int options, int *err,
1005+
int *changed_ret)
10051006
{
10061007
struct stat st;
10071008
struct cache_entry *updated;
@@ -1033,6 +1034,8 @@ static struct cache_entry *refresh_cache_ent(struct index_state *istate,
10331034
}
10341035

10351036
changed = ie_match_stat(istate, ce, &st, options);
1037+
if (changed_ret)
1038+
*changed_ret = changed;
10361039
if (!changed) {
10371040
/*
10381041
* The path is unchanged. If we were told to ignore
@@ -1102,14 +1105,21 @@ int refresh_index(struct index_state *istate, unsigned int flags, const char **p
11021105
int first = 1;
11031106
int in_porcelain = (flags & REFRESH_IN_PORCELAIN);
11041107
unsigned int options = really ? CE_MATCH_IGNORE_VALID : 0;
1105-
const char *needs_update_fmt;
1106-
const char *needs_merge_fmt;
1107-
1108-
needs_update_fmt = (in_porcelain ? "M\t%s\n" : "%s: needs update\n");
1109-
needs_merge_fmt = (in_porcelain ? "U\t%s\n" : "%s: needs merge\n");
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");
11101119
for (i = 0; i < istate->cache_nr; i++) {
11111120
struct cache_entry *ce, *new;
11121121
int cache_errno = 0;
1122+
int changed = 0;
11131123

11141124
ce = istate->cache[i];
11151125
if (ignore_submodules && S_ISGITLINK(ce->ce_mode))
@@ -1122,18 +1132,20 @@ int refresh_index(struct index_state *istate, unsigned int flags, const char **p
11221132
i--;
11231133
if (allow_unmerged)
11241134
continue;
1125-
show_file(needs_merge_fmt, ce->name, in_porcelain, &first, header_msg);
1135+
show_file(unmerged_fmt, ce->name, in_porcelain, &first, header_msg);
11261136
has_errors = 1;
11271137
continue;
11281138
}
11291139

11301140
if (pathspec && !match_pathspec(pathspec, ce->name, strlen(ce->name), 0, seen))
11311141
continue;
11321142

1133-
new = refresh_cache_ent(istate, ce, options, &cache_errno);
1143+
new = refresh_cache_ent(istate, ce, options, &cache_errno, &changed);
11341144
if (new == ce)
11351145
continue;
11361146
if (!new) {
1147+
const char *fmt;
1148+
11371149
if (not_new && cache_errno == ENOENT)
11381150
continue;
11391151
if (really && cache_errno == EINVAL) {
@@ -1145,7 +1157,17 @@ int refresh_index(struct index_state *istate, unsigned int flags, const char **p
11451157
}
11461158
if (quiet)
11471159
continue;
1148-
show_file(needs_update_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);
11491171
has_errors = 1;
11501172
continue;
11511173
}
@@ -1157,7 +1179,7 @@ int refresh_index(struct index_state *istate, unsigned int flags, const char **p
11571179

11581180
static struct cache_entry *refresh_cache_entry(struct cache_entry *ce, int really)
11591181
{
1160-
return refresh_cache_ent(&the_index, ce, really, NULL);
1182+
return refresh_cache_ent(&the_index, ce, really, NULL, NULL);
11611183
}
11621184

11631185
static int verify_hdr(struct cache_header *hdr, unsigned long size)

0 commit comments

Comments
 (0)