builtin-commit: refactor short-status code into wt-status.c
Currently, builtin-commit.c contains most code producing the short-status output, whereas wt-status.c contains most of the code for the long format. Refactor so that most of the long and short format producing code resides in wt-status.c and is named analogously. Signed-off-by: Michael J Gruber <git@drmicha.warpmail.net> Signed-off-by: Junio C Hamano <gitster@pobox.com>
This commit is contained in:
committed by
Junio C Hamano
parent
14ed05ddd6
commit
84dbe7b867
89
wt-status.c
89
wt-status.c
@ -592,3 +592,92 @@ void wt_status_print(struct wt_status *s)
|
||||
printf("nothing to commit (working directory clean)\n");
|
||||
}
|
||||
}
|
||||
|
||||
static void wt_shortstatus_unmerged(int null_termination, struct string_list_item *it,
|
||||
struct wt_status *s)
|
||||
{
|
||||
struct wt_status_change_data *d = it->util;
|
||||
const char *how = "??";
|
||||
|
||||
switch (d->stagemask) {
|
||||
case 1: how = "DD"; break; /* both deleted */
|
||||
case 2: how = "AU"; break; /* added by us */
|
||||
case 3: how = "UD"; break; /* deleted by them */
|
||||
case 4: how = "UA"; break; /* added by them */
|
||||
case 5: how = "DU"; break; /* deleted by us */
|
||||
case 6: how = "AA"; break; /* both added */
|
||||
case 7: how = "UU"; break; /* both modified */
|
||||
}
|
||||
printf("%s ", how);
|
||||
if (null_termination) {
|
||||
fprintf(stdout, "%s%c", it->string, 0);
|
||||
} else {
|
||||
struct strbuf onebuf = STRBUF_INIT;
|
||||
const char *one;
|
||||
one = quote_path(it->string, -1, &onebuf, s->prefix);
|
||||
printf("%s\n", one);
|
||||
strbuf_release(&onebuf);
|
||||
}
|
||||
}
|
||||
|
||||
static void wt_shortstatus_status(int null_termination, struct string_list_item *it,
|
||||
struct wt_status *s)
|
||||
{
|
||||
struct wt_status_change_data *d = it->util;
|
||||
|
||||
printf("%c%c ",
|
||||
!d->index_status ? ' ' : d->index_status,
|
||||
!d->worktree_status ? ' ' : d->worktree_status);
|
||||
if (null_termination) {
|
||||
fprintf(stdout, "%s%c", it->string, 0);
|
||||
if (d->head_path)
|
||||
fprintf(stdout, "%s%c", d->head_path, 0);
|
||||
} else {
|
||||
struct strbuf onebuf = STRBUF_INIT;
|
||||
const char *one;
|
||||
if (d->head_path) {
|
||||
one = quote_path(d->head_path, -1, &onebuf, s->prefix);
|
||||
printf("%s -> ", one);
|
||||
strbuf_release(&onebuf);
|
||||
}
|
||||
one = quote_path(it->string, -1, &onebuf, s->prefix);
|
||||
printf("%s\n", one);
|
||||
strbuf_release(&onebuf);
|
||||
}
|
||||
}
|
||||
|
||||
static void wt_shortstatus_untracked(int null_termination, struct string_list_item *it,
|
||||
struct wt_status *s)
|
||||
{
|
||||
if (null_termination) {
|
||||
fprintf(stdout, "?? %s%c", it->string, 0);
|
||||
} else {
|
||||
struct strbuf onebuf = STRBUF_INIT;
|
||||
const char *one;
|
||||
one = quote_path(it->string, -1, &onebuf, s->prefix);
|
||||
printf("?? %s\n", one);
|
||||
strbuf_release(&onebuf);
|
||||
}
|
||||
}
|
||||
|
||||
void wt_shortstatus_print(struct wt_status *s, int null_termination)
|
||||
{
|
||||
int i;
|
||||
for (i = 0; i < s->change.nr; i++) {
|
||||
struct wt_status_change_data *d;
|
||||
struct string_list_item *it;
|
||||
|
||||
it = &(s->change.items[i]);
|
||||
d = it->util;
|
||||
if (d->stagemask)
|
||||
wt_shortstatus_unmerged(null_termination, it, s);
|
||||
else
|
||||
wt_shortstatus_status(null_termination, it, s);
|
||||
}
|
||||
for (i = 0; i < s->untracked.nr; i++) {
|
||||
struct string_list_item *it;
|
||||
|
||||
it = &(s->untracked.items[i]);
|
||||
wt_shortstatus_untracked(null_termination, it, s);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user