wt-status: Split header generation into three functions
Reorganize header generation so that all header text related to each block is in one place. This adds a function, but makes it easier to see what is generated in each case. It also allows for easy tweaking of individual headers. Signed-off-by: Junio C Hamano <gitster@pobox.com>
This commit is contained in:
parent
ec3a4ba519
commit
bb914b14c9
34
wt-status.c
34
wt-status.c
@ -22,12 +22,6 @@ static char wt_status_colors[][COLOR_MAXLEN] = {
|
|||||||
"\033[31m", /* WT_STATUS_NOBRANCH: red */
|
"\033[31m", /* WT_STATUS_NOBRANCH: red */
|
||||||
};
|
};
|
||||||
|
|
||||||
static const char use_add_msg[] =
|
|
||||||
"use \"git add <file>...\" to update what will be committed";
|
|
||||||
static const char use_add_rm_msg[] =
|
|
||||||
"use \"git add/rm <file>...\" to update what will be committed";
|
|
||||||
static const char use_add_to_include_msg[] =
|
|
||||||
"use \"git add <file>...\" to include in what will be committed";
|
|
||||||
enum untracked_status_type show_untracked_files = SHOW_NORMAL_UNTRACKED_FILES;
|
enum untracked_status_type show_untracked_files = SHOW_NORMAL_UNTRACKED_FILES;
|
||||||
|
|
||||||
static int parse_status_slot(const char *var, int offset)
|
static int parse_status_slot(const char *var, int offset)
|
||||||
@ -76,12 +70,23 @@ static void wt_status_print_cached_header(struct wt_status *s)
|
|||||||
color_fprintf_ln(s->fp, c, "#");
|
color_fprintf_ln(s->fp, c, "#");
|
||||||
}
|
}
|
||||||
|
|
||||||
static void wt_status_print_header(struct wt_status *s,
|
static void wt_status_print_dirty_header(struct wt_status *s,
|
||||||
const char *main, const char *sub)
|
int has_deleted)
|
||||||
{
|
{
|
||||||
const char *c = color(WT_STATUS_HEADER);
|
const char *c = color(WT_STATUS_HEADER);
|
||||||
color_fprintf_ln(s->fp, c, "# %s:", main);
|
color_fprintf_ln(s->fp, c, "# Changed but not updated:");
|
||||||
color_fprintf_ln(s->fp, c, "# (%s)", sub);
|
if (!has_deleted)
|
||||||
|
color_fprintf_ln(s->fp, c, "# (use \"git add <file>...\" to update what will be committed)");
|
||||||
|
else
|
||||||
|
color_fprintf_ln(s->fp, c, "# (use \"git add/rm <file>...\" to update what will be committed)");
|
||||||
|
color_fprintf_ln(s->fp, c, "#");
|
||||||
|
}
|
||||||
|
|
||||||
|
static void wt_status_print_untracked_header(struct wt_status *s)
|
||||||
|
{
|
||||||
|
const char *c = color(WT_STATUS_HEADER);
|
||||||
|
color_fprintf_ln(s->fp, c, "# Untracked files:");
|
||||||
|
color_fprintf_ln(s->fp, c, "# (use \"git add <file>...\" to include in what will be committed)");
|
||||||
color_fprintf_ln(s->fp, c, "#");
|
color_fprintf_ln(s->fp, c, "#");
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -166,14 +171,14 @@ static void wt_status_print_changed_cb(struct diff_queue_struct *q,
|
|||||||
struct wt_status *s = data;
|
struct wt_status *s = data;
|
||||||
int i;
|
int i;
|
||||||
if (q->nr) {
|
if (q->nr) {
|
||||||
const char *msg = use_add_msg;
|
int has_deleted = 0;
|
||||||
s->workdir_dirty = 1;
|
s->workdir_dirty = 1;
|
||||||
for (i = 0; i < q->nr; i++)
|
for (i = 0; i < q->nr; i++)
|
||||||
if (q->queue[i]->status == DIFF_STATUS_DELETED) {
|
if (q->queue[i]->status == DIFF_STATUS_DELETED) {
|
||||||
msg = use_add_rm_msg;
|
has_deleted = 1;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
wt_status_print_header(s, "Changed but not updated", msg);
|
wt_status_print_dirty_header(s, has_deleted);
|
||||||
}
|
}
|
||||||
for (i = 0; i < q->nr; i++)
|
for (i = 0; i < q->nr; i++)
|
||||||
wt_status_print_filepair(s, WT_STATUS_CHANGED, q->queue[i]);
|
wt_status_print_filepair(s, WT_STATUS_CHANGED, q->queue[i]);
|
||||||
@ -291,8 +296,7 @@ static void wt_status_print_untracked(struct wt_status *s)
|
|||||||
}
|
}
|
||||||
if (!shown_header) {
|
if (!shown_header) {
|
||||||
s->workdir_untracked = 1;
|
s->workdir_untracked = 1;
|
||||||
wt_status_print_header(s, "Untracked files",
|
wt_status_print_untracked_header(s);
|
||||||
use_add_to_include_msg);
|
|
||||||
shown_header = 1;
|
shown_header = 1;
|
||||||
}
|
}
|
||||||
color_fprintf(s->fp, color(WT_STATUS_HEADER), "#\t");
|
color_fprintf(s->fp, color(WT_STATUS_HEADER), "#\t");
|
||||||
|
Loading…
Reference in New Issue
Block a user