git.vger.kernel.org archive mirror
 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 2/3] parse-opt: migrate git-merge-base.
Date: Wed,  1 Oct 2008 08:05:05 +0200	[thread overview]
Message-ID: <1222841106-26148-2-git-send-email-madcoder@debian.org> (raw)
In-Reply-To: <1222841106-26148-1-git-send-email-madcoder@debian.org>

Signed-off-by: Pierre Habouzit <madcoder@debian.org>
---
 builtin-merge-base.c |   37 ++++++++++++++++---------------------
 1 files changed, 16 insertions(+), 21 deletions(-)

diff --git a/builtin-merge-base.c b/builtin-merge-base.c
index b08da51..03fc1c2 100644
--- a/builtin-merge-base.c
+++ b/builtin-merge-base.c
@@ -1,6 +1,7 @@
 #include "builtin.h"
 #include "cache.h"
 #include "commit.h"
+#include "parse-options.h"
 
 static int show_merge_base(struct commit **rev, int rev_nr, int show_all)
 {
@@ -21,8 +22,10 @@ static int show_merge_base(struct commit **rev, int rev_nr, int show_all)
 	return 0;
 }
 
-static const char merge_base_usage[] =
-"git merge-base [--all] <commit-id> <commit-id>...";
+static const char * const merge_base_usage[] = {
+	"git merge-base [--all] <commit-id> <commit-id>...",
+	NULL
+};
 
 static struct commit *get_commit_reference(const char *arg)
 {
@@ -44,25 +47,17 @@ int cmd_merge_base(int argc, const char **argv, const char *prefix)
 	int rev_nr = 0;
 	int show_all = 0;
 
-	git_config(git_default_config, NULL);
-
-	while (1 < argc && argv[1][0] == '-') {
-		const char *arg = argv[1];
-		if (!strcmp(arg, "-a") || !strcmp(arg, "--all"))
-			show_all = 1;
-		else
-			usage(merge_base_usage);
-		argc--; argv++;
-	}
-	if (argc < 3)
-		usage(merge_base_usage);
-
-	rev = xmalloc((argc - 1) * sizeof(*rev));
-
-	do {
-		rev[rev_nr++] = get_commit_reference(argv[1]);
-		argc--; argv++;
-	} while (argc > 1);
+	struct option options[] = {
+		OPT_BOOLEAN('a', "all", &show_all, "outputs all common ancestors"),
+		OPT_END()
+	};
 
+	git_config(git_default_config, NULL);
+	argc = parse_options(argc, argv, options, merge_base_usage, 0);
+	if (argc < 2)
+		usage_with_options(merge_base_usage, options);
+	rev = xmalloc(argc * sizeof(*rev));
+	while (argc-- > 0)
+		rev[rev_nr++] = get_commit_reference(*argv++);
 	return show_merge_base(rev, rev_nr, show_all);
 }
-- 
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             ` [PATCH 1/3] " Pierre Habouzit
2008-10-01  6:05               ` Pierre Habouzit [this message]
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-2-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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).