status: refactor null_termination option
This option is passed separately to the wt_status printing functions, whereas every other formatting option is contained in the wt_status struct itself. Let's do the same here, so we can avoid passing it around through the call stack. Signed-off-by: Jeff King <peff@peff.net>
This commit is contained in:
parent
036dbbfb2d
commit
3207a3a291
@ -109,7 +109,6 @@ static int show_ignored_in_status;
|
|||||||
static const char *only_include_assumed;
|
static const char *only_include_assumed;
|
||||||
static struct strbuf message = STRBUF_INIT;
|
static struct strbuf message = STRBUF_INIT;
|
||||||
|
|
||||||
static int null_termination;
|
|
||||||
static enum {
|
static enum {
|
||||||
STATUS_FORMAT_LONG,
|
STATUS_FORMAT_LONG,
|
||||||
STATUS_FORMAT_SHORT,
|
STATUS_FORMAT_SHORT,
|
||||||
@ -460,10 +459,10 @@ static int run_status(FILE *fp, const char *index_file, const char *prefix, int
|
|||||||
|
|
||||||
switch (status_format) {
|
switch (status_format) {
|
||||||
case STATUS_FORMAT_SHORT:
|
case STATUS_FORMAT_SHORT:
|
||||||
wt_shortstatus_print(s, null_termination, status_show_branch);
|
wt_shortstatus_print(s, status_show_branch);
|
||||||
break;
|
break;
|
||||||
case STATUS_FORMAT_PORCELAIN:
|
case STATUS_FORMAT_PORCELAIN:
|
||||||
wt_porcelain_print(s, null_termination);
|
wt_porcelain_print(s);
|
||||||
break;
|
break;
|
||||||
case STATUS_FORMAT_LONG:
|
case STATUS_FORMAT_LONG:
|
||||||
wt_status_print(s);
|
wt_status_print(s);
|
||||||
@ -1082,7 +1081,7 @@ static int parse_and_validate_options(int argc, const char *argv[],
|
|||||||
if (all && argc > 0)
|
if (all && argc > 0)
|
||||||
die(_("Paths with -a does not make sense."));
|
die(_("Paths with -a does not make sense."));
|
||||||
|
|
||||||
if (null_termination && status_format == STATUS_FORMAT_LONG)
|
if (s->null_termination && status_format == STATUS_FORMAT_LONG)
|
||||||
status_format = STATUS_FORMAT_PORCELAIN;
|
status_format = STATUS_FORMAT_PORCELAIN;
|
||||||
if (status_format != STATUS_FORMAT_LONG)
|
if (status_format != STATUS_FORMAT_LONG)
|
||||||
dry_run = 1;
|
dry_run = 1;
|
||||||
@ -1181,7 +1180,7 @@ int cmd_status(int argc, const char **argv, const char *prefix)
|
|||||||
OPT_SET_INT(0, "porcelain", &status_format,
|
OPT_SET_INT(0, "porcelain", &status_format,
|
||||||
"machine-readable output",
|
"machine-readable output",
|
||||||
STATUS_FORMAT_PORCELAIN),
|
STATUS_FORMAT_PORCELAIN),
|
||||||
OPT_BOOLEAN('z', "null", &null_termination,
|
OPT_BOOLEAN('z', "null", &s.null_termination,
|
||||||
"terminate entries with NUL"),
|
"terminate entries with NUL"),
|
||||||
{ OPTION_STRING, 'u', "untracked-files", &untracked_files_arg,
|
{ OPTION_STRING, 'u', "untracked-files", &untracked_files_arg,
|
||||||
"mode",
|
"mode",
|
||||||
@ -1206,7 +1205,7 @@ int cmd_status(int argc, const char **argv, const char *prefix)
|
|||||||
builtin_status_options,
|
builtin_status_options,
|
||||||
builtin_status_usage, 0);
|
builtin_status_usage, 0);
|
||||||
|
|
||||||
if (null_termination && status_format == STATUS_FORMAT_LONG)
|
if (s.null_termination && status_format == STATUS_FORMAT_LONG)
|
||||||
status_format = STATUS_FORMAT_PORCELAIN;
|
status_format = STATUS_FORMAT_PORCELAIN;
|
||||||
|
|
||||||
handle_untracked_files_arg(&s);
|
handle_untracked_files_arg(&s);
|
||||||
@ -1231,10 +1230,10 @@ int cmd_status(int argc, const char **argv, const char *prefix)
|
|||||||
|
|
||||||
switch (status_format) {
|
switch (status_format) {
|
||||||
case STATUS_FORMAT_SHORT:
|
case STATUS_FORMAT_SHORT:
|
||||||
wt_shortstatus_print(&s, null_termination, status_show_branch);
|
wt_shortstatus_print(&s, status_show_branch);
|
||||||
break;
|
break;
|
||||||
case STATUS_FORMAT_PORCELAIN:
|
case STATUS_FORMAT_PORCELAIN:
|
||||||
wt_porcelain_print(&s, null_termination);
|
wt_porcelain_print(&s);
|
||||||
break;
|
break;
|
||||||
case STATUS_FORMAT_LONG:
|
case STATUS_FORMAT_LONG:
|
||||||
s.verbose = verbose;
|
s.verbose = verbose;
|
||||||
@ -1406,7 +1405,7 @@ int cmd_commit(int argc, const char **argv, const char *prefix)
|
|||||||
OPT_BOOLEAN(0, "branch", &status_show_branch, "show branch information"),
|
OPT_BOOLEAN(0, "branch", &status_show_branch, "show branch information"),
|
||||||
OPT_SET_INT(0, "porcelain", &status_format,
|
OPT_SET_INT(0, "porcelain", &status_format,
|
||||||
"machine-readable output", STATUS_FORMAT_PORCELAIN),
|
"machine-readable output", STATUS_FORMAT_PORCELAIN),
|
||||||
OPT_BOOLEAN('z', "null", &null_termination,
|
OPT_BOOLEAN('z', "null", &s.null_termination,
|
||||||
"terminate entries with NUL"),
|
"terminate entries with NUL"),
|
||||||
OPT_BOOLEAN(0, "amend", &amend, "amend previous commit"),
|
OPT_BOOLEAN(0, "amend", &amend, "amend previous commit"),
|
||||||
OPT_BOOLEAN(0, "no-post-rewrite", &no_post_rewrite, "bypass post-rewrite hook"),
|
OPT_BOOLEAN(0, "no-post-rewrite", &no_post_rewrite, "bypass post-rewrite hook"),
|
||||||
|
26
wt-status.c
26
wt-status.c
@ -777,7 +777,7 @@ void wt_status_print(struct wt_status *s)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static void wt_shortstatus_unmerged(int null_termination, struct string_list_item *it,
|
static void wt_shortstatus_unmerged(struct string_list_item *it,
|
||||||
struct wt_status *s)
|
struct wt_status *s)
|
||||||
{
|
{
|
||||||
struct wt_status_change_data *d = it->util;
|
struct wt_status_change_data *d = it->util;
|
||||||
@ -793,7 +793,7 @@ static void wt_shortstatus_unmerged(int null_termination, struct string_list_ite
|
|||||||
case 7: how = "UU"; break; /* both modified */
|
case 7: how = "UU"; break; /* both modified */
|
||||||
}
|
}
|
||||||
color_fprintf(s->fp, color(WT_STATUS_UNMERGED, s), "%s", how);
|
color_fprintf(s->fp, color(WT_STATUS_UNMERGED, s), "%s", how);
|
||||||
if (null_termination) {
|
if (s->null_termination) {
|
||||||
fprintf(stdout, " %s%c", it->string, 0);
|
fprintf(stdout, " %s%c", it->string, 0);
|
||||||
} else {
|
} else {
|
||||||
struct strbuf onebuf = STRBUF_INIT;
|
struct strbuf onebuf = STRBUF_INIT;
|
||||||
@ -804,7 +804,7 @@ static void wt_shortstatus_unmerged(int null_termination, struct string_list_ite
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static void wt_shortstatus_status(int null_termination, struct string_list_item *it,
|
static void wt_shortstatus_status(struct string_list_item *it,
|
||||||
struct wt_status *s)
|
struct wt_status *s)
|
||||||
{
|
{
|
||||||
struct wt_status_change_data *d = it->util;
|
struct wt_status_change_data *d = it->util;
|
||||||
@ -818,7 +818,7 @@ static void wt_shortstatus_status(int null_termination, struct string_list_item
|
|||||||
else
|
else
|
||||||
putchar(' ');
|
putchar(' ');
|
||||||
putchar(' ');
|
putchar(' ');
|
||||||
if (null_termination) {
|
if (s->null_termination) {
|
||||||
fprintf(stdout, "%s%c", it->string, 0);
|
fprintf(stdout, "%s%c", it->string, 0);
|
||||||
if (d->head_path)
|
if (d->head_path)
|
||||||
fprintf(stdout, "%s%c", d->head_path, 0);
|
fprintf(stdout, "%s%c", d->head_path, 0);
|
||||||
@ -846,10 +846,10 @@ static void wt_shortstatus_status(int null_termination, struct string_list_item
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static void wt_shortstatus_other(int null_termination, struct string_list_item *it,
|
static void wt_shortstatus_other(struct string_list_item *it,
|
||||||
struct wt_status *s, const char *sign)
|
struct wt_status *s, const char *sign)
|
||||||
{
|
{
|
||||||
if (null_termination) {
|
if (s->null_termination) {
|
||||||
fprintf(stdout, "%s %s%c", sign, it->string, 0);
|
fprintf(stdout, "%s %s%c", sign, it->string, 0);
|
||||||
} else {
|
} else {
|
||||||
struct strbuf onebuf = STRBUF_INIT;
|
struct strbuf onebuf = STRBUF_INIT;
|
||||||
@ -917,7 +917,7 @@ static void wt_shortstatus_print_tracking(struct wt_status *s)
|
|||||||
color_fprintf_ln(s->fp, header_color, "]");
|
color_fprintf_ln(s->fp, header_color, "]");
|
||||||
}
|
}
|
||||||
|
|
||||||
void wt_shortstatus_print(struct wt_status *s, int null_termination, int show_branch)
|
void wt_shortstatus_print(struct wt_status *s, int show_branch)
|
||||||
{
|
{
|
||||||
int i;
|
int i;
|
||||||
|
|
||||||
@ -931,28 +931,28 @@ void wt_shortstatus_print(struct wt_status *s, int null_termination, int show_br
|
|||||||
it = &(s->change.items[i]);
|
it = &(s->change.items[i]);
|
||||||
d = it->util;
|
d = it->util;
|
||||||
if (d->stagemask)
|
if (d->stagemask)
|
||||||
wt_shortstatus_unmerged(null_termination, it, s);
|
wt_shortstatus_unmerged(it, s);
|
||||||
else
|
else
|
||||||
wt_shortstatus_status(null_termination, it, s);
|
wt_shortstatus_status(it, s);
|
||||||
}
|
}
|
||||||
for (i = 0; i < s->untracked.nr; i++) {
|
for (i = 0; i < s->untracked.nr; i++) {
|
||||||
struct string_list_item *it;
|
struct string_list_item *it;
|
||||||
|
|
||||||
it = &(s->untracked.items[i]);
|
it = &(s->untracked.items[i]);
|
||||||
wt_shortstatus_other(null_termination, it, s, "??");
|
wt_shortstatus_other(it, s, "??");
|
||||||
}
|
}
|
||||||
for (i = 0; i < s->ignored.nr; i++) {
|
for (i = 0; i < s->ignored.nr; i++) {
|
||||||
struct string_list_item *it;
|
struct string_list_item *it;
|
||||||
|
|
||||||
it = &(s->ignored.items[i]);
|
it = &(s->ignored.items[i]);
|
||||||
wt_shortstatus_other(null_termination, it, s, "!!");
|
wt_shortstatus_other(it, s, "!!");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void wt_porcelain_print(struct wt_status *s, int null_termination)
|
void wt_porcelain_print(struct wt_status *s)
|
||||||
{
|
{
|
||||||
s->use_color = 0;
|
s->use_color = 0;
|
||||||
s->relative_paths = 0;
|
s->relative_paths = 0;
|
||||||
s->prefix = NULL;
|
s->prefix = NULL;
|
||||||
wt_shortstatus_print(s, null_termination, 0);
|
wt_shortstatus_print(s, 0);
|
||||||
}
|
}
|
||||||
|
@ -56,6 +56,7 @@ struct wt_status {
|
|||||||
enum untracked_status_type show_untracked_files;
|
enum untracked_status_type show_untracked_files;
|
||||||
const char *ignore_submodule_arg;
|
const char *ignore_submodule_arg;
|
||||||
char color_palette[WT_STATUS_MAXSLOT][COLOR_MAXLEN];
|
char color_palette[WT_STATUS_MAXSLOT][COLOR_MAXLEN];
|
||||||
|
int null_termination;
|
||||||
|
|
||||||
/* These are computed during processing of the individual sections */
|
/* These are computed during processing of the individual sections */
|
||||||
int commitable;
|
int commitable;
|
||||||
@ -72,8 +73,8 @@ void wt_status_prepare(struct wt_status *s);
|
|||||||
void wt_status_print(struct wt_status *s);
|
void wt_status_print(struct wt_status *s);
|
||||||
void wt_status_collect(struct wt_status *s);
|
void wt_status_collect(struct wt_status *s);
|
||||||
|
|
||||||
void wt_shortstatus_print(struct wt_status *s, int null_termination, int show_branch);
|
void wt_shortstatus_print(struct wt_status *s, int show_branch);
|
||||||
void wt_porcelain_print(struct wt_status *s, int null_termination);
|
void wt_porcelain_print(struct wt_status *s);
|
||||||
|
|
||||||
void status_printf_ln(struct wt_status *s, const char *color, const char *fmt, ...)
|
void status_printf_ln(struct wt_status *s, const char *color, const char *fmt, ...)
|
||||||
;
|
;
|
||||||
|
Loading…
Reference in New Issue
Block a user