All of lore.kernel.org
 help / color / mirror / Atom feed
From: Pierre Habouzit <madcoder@debian.org>
To: spearce@spearce.org
Cc: git@vger.kernel.org, gitster@pobox.com,
	Pierre Habouzit <madcoder@debian.org>
Subject: [PATCH 1/3] parse-opt: migrate fmt-merge-msg.
Date: Wed,  1 Oct 2008 08:05:04 +0200	[thread overview]
Message-ID: <1222841106-26148-1-git-send-email-madcoder@debian.org> (raw)
In-Reply-To: <20080930224623.GQ21310@spearce.org>

Also fix an inefficient printf("%s", ...) where we can use write_in_full.

Signed-off-by: Pierre Habouzit <madcoder@debian.org>
---
 builtin-fmt-merge-msg.c |   52 +++++++++++++++++++++-------------------------
 1 files changed, 24 insertions(+), 28 deletions(-)

   > It may actually be a good idea to rebase this against master.
   >
   > Reading Junio's notes for sg/merge-options (the branch this conflict
   > is coming out of) it sounds like we'd want to revert that anyway.
   > Its been around since April and Junio was talking about it needing
   > to be in a 1.7.0 release.  Its not going to graduate anytime soon.

   Fair enough, here it is.


diff --git a/builtin-fmt-merge-msg.c b/builtin-fmt-merge-msg.c
index df02ba7..78c04bf 100644
--- a/builtin-fmt-merge-msg.c
+++ b/builtin-fmt-merge-msg.c
@@ -5,8 +5,10 @@
 #include "revision.h"
 #include "tag.h"
 
-static const char *fmt_merge_msg_usage =
-	"git fmt-merge-msg [--log] [--no-log] [--file <file>]";
+static const char * const fmt_merge_msg_usage[] = {
+	"git fmt-merge-msg [--log|--no-log] [--file <file>]",
+	NULL
+};
 
 static int merge_summary;
 
@@ -347,38 +349,32 @@ 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)
 {
+	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;
 	struct strbuf input, output;
 	int ret;
 
 	git_config(fmt_merge_msg_config, NULL);
-
-	while (argc > 1) {
-		if (!strcmp(argv[1], "--log") || !strcmp(argv[1], "--summary"))
-			merge_summary = 1;
-		else if (!strcmp(argv[1], "--no-log")
-				|| !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++;
+	argc = parse_options(argc, argv, options, fmt_merge_msg_usage, 0);
+	if (argc > 0)
+		usage_with_options(fmt_merge_msg_usage, options);
+
+	if (!inpath || strcmp(inpath, "-"))
+		in = stdin;
+	else {
+		fclose(in);
+		in = fopen(argv[2], "r");
+		if (!in)
+			die("cannot open %s", argv[2]);
 	}
 
-	if (argc > 1)
-		usage(fmt_merge_msg_usage);
-
 	strbuf_init(&input, 0);
 	if (strbuf_read(&input, fileno(in), 0) < 0)
 		die("could not read input file %s", strerror(errno));
@@ -387,6 +383,6 @@ int cmd_fmt_merge_msg(int argc, const char **argv, const char *prefix)
 	ret = fmt_merge_msg(merge_summary, &input, &output);
 	if (ret)
 		return ret;
-	printf("%s", output.buf);
+	write_in_full(STDOUT_FILENO, output.buf, output.len);
 	return 0;
 }
-- 
1.6.0.2.415.g9800c0.dirty

  reply	other threads:[~2008-10-01  6:06 UTC|newest]

Thread overview: 19+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2008-09-28  9:45 small warm-up: easy parse-opt migrations Pierre Habouzit
2008-09-28  9:45 ` [PATCH] parse-opt: migrate fmt-merge-msg Pierre Habouzit
2008-09-28  9:45   ` [PATCH] parse-opt: migrate git-merge-base Pierre Habouzit
2008-09-28  9:45     ` [PATCH] parse-opt: migrate builtin-merge-file Pierre Habouzit
2008-09-29 16:35   ` [PATCH] parse-opt: migrate fmt-merge-msg Shawn O. Pearce
2008-09-30  8:40     ` Pierre Habouzit
2008-09-30 19:10       ` Shawn O. Pearce
2008-09-30 21:16         ` Pierre Habouzit
2008-09-30 22:46           ` Shawn O. Pearce
2008-10-01  6:05             ` Pierre Habouzit [this message]
2008-10-01  6:05               ` [PATCH 2/3] parse-opt: migrate git-merge-base Pierre Habouzit
2008-10-01  6:05                 ` [PATCH 3/3] parse-opt: migrate builtin-merge-file Pierre Habouzit
2008-10-01 15:01                   ` Shawn O. Pearce
2008-10-01 14:56               ` [PATCH 1/3] parse-opt: migrate fmt-merge-msg Shawn O. Pearce
2008-10-02 11:51                 ` Pierre Habouzit
2008-10-02 12:59             ` [RESEND PATCH] " Pierre Habouzit
2008-10-02 12:59               ` [PATCH] parse-opt: migrate git-merge-base Pierre Habouzit
2008-10-02 12:59                 ` [RESEND PATCH] parse-opt: migrate builtin-merge-file Pierre Habouzit
2008-09-28 13:20 ` small warm-up: easy parse-opt migrations Sverre Rabbelier

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1222841106-26148-1-git-send-email-madcoder@debian.org \
    --to=madcoder@debian.org \
    --cc=git@vger.kernel.org \
    --cc=gitster@pobox.com \
    --cc=spearce@spearce.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.