ref-filter: abstract ref format into its own struct

The ref-filter module provides routines for formatting a ref
for output. The fundamental interface for the format is a
"const char *" containing the format, and any additional
options need to be passed to each invocation of
show_ref_array_item.

Instead, let's make a ref_format struct that holds the
format, along with any associated format options. That will
make some enhancements easier in the future:

  1. new formatting options can be added without disrupting
     existing callers

  2. some state can be carried in the struct rather than as
     global variables

For now this just has the text format itself along with the
quote_style option, but we'll add more fields in future patches.

Signed-off-by: Jeff King <peff@peff.net>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
This commit is contained in:
Jeff King
2017-07-13 11:01:18 -04:00
committed by Junio C Hamano
parent 51331aad69
commit 4a68e36d7d
6 changed files with 70 additions and 52 deletions

View File

@ -32,11 +32,11 @@ int cmd_verify_tag(int argc, const char **argv, const char *prefix)
{
int i = 1, verbose = 0, had_error = 0;
unsigned flags = 0;
char *fmt_pretty = NULL;
struct ref_format format = REF_FORMAT_INIT;
const struct option verify_tag_options[] = {
OPT__VERBOSE(&verbose, N_("print tag contents")),
OPT_BIT(0, "raw", &flags, N_("print raw gpg status output"), GPG_VERIFY_RAW),
OPT_STRING( 0 , "format", &fmt_pretty, N_("format"), N_("format to use for the output")),
OPT_STRING(0, "format", &format.format, N_("format"), N_("format to use for the output")),
OPT_END()
};
@ -50,8 +50,8 @@ int cmd_verify_tag(int argc, const char **argv, const char *prefix)
if (verbose)
flags |= GPG_VERIFY_VERBOSE;
if (fmt_pretty) {
if (verify_ref_format(fmt_pretty))
if (format.format) {
if (verify_ref_format(&format))
usage_with_options(verify_tag_usage,
verify_tag_options);
flags |= GPG_VERIFY_OMIT_STATUS;
@ -70,8 +70,8 @@ int cmd_verify_tag(int argc, const char **argv, const char *prefix)
continue;
}
if (fmt_pretty)
pretty_print_ref(name, sha1, fmt_pretty);
if (format.format)
pretty_print_ref(name, sha1, &format);
}
return had_error;
}