Re: [PATCH v1 1/6] Allow --porcelain[=<n>] in status and commit commands
- From
Johannes Schindelin <johannes.schindelin@gmx.de>
- Date
- Jul 20, 2016, 15:08 UTC
- Message-ID
- <alpine.DEB.2.20.1607201600050.14111@virtualbox>
- In-Reply-To
- <1468966258-11191-2-git-send-email-jeffhost@microsoft.com>
Hi Jeff,
On Tue, 19 Jul 2016, Jeff Hostetler wrote:
Show 8 quoted lines
> Update the --porcelain argument to take an optional > version number. This will allow us to define new > porcelain formats in the future. > > This default to 1 and represents the existing porcelain > format. > > Signed-off-by: Jeff Hostetler <jeffhost@microsoft.com>
Very nice introductory patch.
Show 22 quoted lines
> diff --git a/builtin/commit.c b/builtin/commit.c
> index 1f6dbcd..892d7f7 100644
> --- a/builtin/commit.c
> +++ b/builtin/commit.c
> @@ -142,14 +142,24 @@ static int show_ignored_in_status, have_option_m;
> static const char *only_include_assumed;
> static struct strbuf message = STRBUF_INIT;
>
> -static enum status_format {
> - STATUS_FORMAT_NONE = 0,
> - STATUS_FORMAT_LONG,
> - STATUS_FORMAT_SHORT,
> - STATUS_FORMAT_PORCELAIN,
> +static enum wt_status_format status_format = STATUS_FORMAT_UNSPECIFIED;
>
> - STATUS_FORMAT_UNSPECIFIED
> -} status_format = STATUS_FORMAT_UNSPECIFIED;
> +static int opt_parse_porcelain(const struct option *opt, const char *arg, int unset)
> +{
> + enum wt_status_format *value = (enum wt_status_format *)opt->value;
> + if (unset) {
> + *value = STATUS_FORMAT_UNSPECIFIED;In Git's source code, we skip the curly braces for one-liners.
Show 8 quoted lines
> + } else if (arg) {
> + int n = strtol(arg, NULL, 10);
> + if (n == 1)
> + *value = STATUS_FORMAT_PORCELAIN;
> + else
> + die("unsupported porcelain version");
> + } else {
> + *value = STATUS_FORMAT_PORCELAIN;This could be folded into the previous conditional:
}
else {
int n = arg ? strtol(arg, NULL, 10) : 1;
...Having said this, ...
Show 10 quoted lines
> @@ -1336,9 +1347,9 @@ int cmd_status(int argc, const char **argv, const char *prefix)
> N_("show status concisely"), STATUS_FORMAT_SHORT),
> OPT_BOOL('b', "branch", &s.show_branch,
> N_("show branch information")),
> - OPT_SET_INT(0, "porcelain", &status_format,
> - N_("machine-readable output"),
> - STATUS_FORMAT_PORCELAIN),
> + { OPTION_CALLBACK, 0, "porcelain", &status_format,
> + N_("version"), N_("machine-readable output"),
> + PARSE_OPT_OPTARG, opt_parse_porcelain },How about using a COUNTUP here instead? We could then set the status format afterwards, like this:
if (porcelain == 0)
status_format = STATUS_FORMAT_UNSPECIFIED;
else {
status_format = STATUS_FORMAT_PORCELAIN;
if (porcelain > 1)
warning("No porcelain v%d; falling back to v1",
porcelain);
}The rest of the patch looks good to me!
Ciao, Johannes