parse-opt: migrate fmt-merge-msg.
Also fix an inefficient printf("%s", ...) where we can use write_in_full. Signed-off-by: Pierre Habouzit <madcoder@debian.org> Signed-off-by: Shawn O. Pearce <spearce@spearce.org>
This commit is contained in:
parent
52e8370bc7
commit
c8ef0383ac
@ -5,8 +5,10 @@
|
|||||||
#include "revision.h"
|
#include "revision.h"
|
||||||
#include "tag.h"
|
#include "tag.h"
|
||||||
|
|
||||||
static const char *fmt_merge_msg_usage =
|
static const char * const fmt_merge_msg_usage[] = {
|
||||||
"git fmt-merge-msg [--log] [--no-log] [--file <file>]";
|
"git fmt-merge-msg [--log|--no-log] [--file <file>]",
|
||||||
|
NULL
|
||||||
|
};
|
||||||
|
|
||||||
static int merge_summary;
|
static int merge_summary;
|
||||||
|
|
||||||
@ -347,38 +349,29 @@ int fmt_merge_msg(int merge_summary, struct strbuf *in, struct strbuf *out) {
|
|||||||
|
|
||||||
int cmd_fmt_merge_msg(int argc, const char **argv, const char *prefix)
|
int cmd_fmt_merge_msg(int argc, const char **argv, const char *prefix)
|
||||||
{
|
{
|
||||||
|
const char *inpath = NULL;
|
||||||
|
struct option options[] = {
|
||||||
|
OPT_BOOLEAN(0, "log", &merge_summary, "populate log with the shortlog"),
|
||||||
|
OPT_BOOLEAN(0, "summary", &merge_summary, "alias for --log"),
|
||||||
|
OPT_STRING('F', "file", &inpath, "file", "file to read from"),
|
||||||
|
OPT_END()
|
||||||
|
};
|
||||||
|
|
||||||
FILE *in = stdin;
|
FILE *in = stdin;
|
||||||
struct strbuf input, output;
|
struct strbuf input, output;
|
||||||
int ret;
|
int ret;
|
||||||
|
|
||||||
git_config(fmt_merge_msg_config, NULL);
|
git_config(fmt_merge_msg_config, NULL);
|
||||||
|
argc = parse_options(argc, argv, options, fmt_merge_msg_usage, 0);
|
||||||
|
if (argc > 0)
|
||||||
|
usage_with_options(fmt_merge_msg_usage, options);
|
||||||
|
|
||||||
while (argc > 1) {
|
if (inpath && strcmp(inpath, "-")) {
|
||||||
if (!strcmp(argv[1], "--log") || !strcmp(argv[1], "--summary"))
|
in = fopen(inpath, "r");
|
||||||
merge_summary = 1;
|
if (!in)
|
||||||
else if (!strcmp(argv[1], "--no-log")
|
die("cannot open %s", inpath);
|
||||||
|| !strcmp(argv[1], "--no-summary"))
|
|
||||||
merge_summary = 0;
|
|
||||||
else if (!strcmp(argv[1], "-F") || !strcmp(argv[1], "--file")) {
|
|
||||||
if (argc < 3)
|
|
||||||
die ("Which file?");
|
|
||||||
if (!strcmp(argv[2], "-"))
|
|
||||||
in = stdin;
|
|
||||||
else {
|
|
||||||
fclose(in);
|
|
||||||
in = fopen(argv[2], "r");
|
|
||||||
if (!in)
|
|
||||||
die("cannot open %s", argv[2]);
|
|
||||||
}
|
|
||||||
argc--; argv++;
|
|
||||||
} else
|
|
||||||
break;
|
|
||||||
argc--; argv++;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (argc > 1)
|
|
||||||
usage(fmt_merge_msg_usage);
|
|
||||||
|
|
||||||
strbuf_init(&input, 0);
|
strbuf_init(&input, 0);
|
||||||
if (strbuf_read(&input, fileno(in), 0) < 0)
|
if (strbuf_read(&input, fileno(in), 0) < 0)
|
||||||
die("could not read input file %s", strerror(errno));
|
die("could not read input file %s", strerror(errno));
|
||||||
@ -387,6 +380,6 @@ int cmd_fmt_merge_msg(int argc, const char **argv, const char *prefix)
|
|||||||
ret = fmt_merge_msg(merge_summary, &input, &output);
|
ret = fmt_merge_msg(merge_summary, &input, &output);
|
||||||
if (ret)
|
if (ret)
|
||||||
return ret;
|
return ret;
|
||||||
printf("%s", output.buf);
|
write_in_full(STDOUT_FILENO, output.buf, output.len);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user