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>
Anders Melchiorsen committed
Sep 8, 2008 at 00:05 UTC
bb914b14c9d2c1c630512291fe4ca276e69b6e00
1 file changed
+19
-15
wt-status.c
+19
-15
@@ -22,12 +22,6 @@ static char wt_status_colors[][COLOR_MAXLEN] = {
22
"\033[31m", /* WT_STATUS_NOBRANCH: red */
23
};
24
25
-static const char use_add_msg[] =
26
-"use \"git add <file>...\" to update what will be committed";
27
-static const char use_add_rm_msg[] =
28
-"use \"git add/rm <file>...\" to update what will be committed";
29
-static const char use_add_to_include_msg[] =
30
-"use \"git add <file>...\" to include in what will be committed";
25
enum untracked_status_type show_untracked_files = SHOW_NORMAL_UNTRACKED_FILES;
26
27
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)
70
color_fprintf_ln(s->fp, c, "#");
71
}
72
79
-static void wt_status_print_header(struct wt_status *s,
80
- const char *main, const char *sub)
73
+static void wt_status_print_dirty_header(struct wt_status *s,
74
+ int has_deleted)
75
{
76
const char *c = color(WT_STATUS_HEADER);
83
- color_fprintf_ln(s->fp, c, "# %s:", main);
84
- color_fprintf_ln(s->fp, c, "# (%s)", sub);
77
+ color_fprintf_ln(s->fp, c, "# Changed but not updated:");
78
+ if (!has_deleted)
79
+ color_fprintf_ln(s->fp, c, "# (use \"git add <file>...\" to update what will be committed)");
80
+ else
81
+ color_fprintf_ln(s->fp, c, "# (use \"git add/rm <file>...\" to update what will be committed)");
82
+ color_fprintf_ln(s->fp, c, "#");
83
+}
84
+
85
+static void wt_status_print_untracked_header(struct wt_status *s)
86
+{
87
+ const char *c = color(WT_STATUS_HEADER);
88
+ color_fprintf_ln(s->fp, c, "# Untracked files:");
89
+ color_fprintf_ln(s->fp, c, "# (use \"git add <file>...\" to include in what will be committed)");
90
color_fprintf_ln(s->fp, c, "#");
91
}
92
@@ -166,14 +171,14 @@ static void wt_status_print_changed_cb(struct diff_queue_struct *q,
171
struct wt_status *s = data;
172
int i;
173
if (q->nr) {
169
- const char *msg = use_add_msg;
174
+ int has_deleted = 0;
175
s->workdir_dirty = 1;
176
for (i = 0; i < q->nr; i++)
177
if (q->queue[i]->status == DIFF_STATUS_DELETED) {
173
- msg = use_add_rm_msg;
178
+ has_deleted = 1;
179
break;
180
}
176
- wt_status_print_header(s, "Changed but not updated", msg);
181
+ wt_status_print_dirty_header(s, has_deleted);
182
}
183
for (i = 0; i < q->nr; i++)
184
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)
296
}
297
if (!shown_header) {
298
s->workdir_untracked = 1;
294
- wt_status_print_header(s, "Untracked files",
295
- use_add_to_include_msg);
299
+ wt_status_print_untracked_header(s);
300
shown_header = 1;
301
}
302
color_fprintf(s->fp, color(WT_STATUS_HEADER), "#\t");