From: Shawn Bohrer <shawn.bohrer@gmail.com>
To: git@vger.kernel.org
Cc: peff@peff.net, gitster@pobox.com, madcoder@debian.org,
Shawn Bohrer <shawn.bohrer@gmail.com>
Subject: [PATCH 2/2] git shortlog: Modify to use parse_options
Date: Tue, 17 Jun 2008 22:03:56 -0500 [thread overview]
Message-ID: <1213758236-979-3-git-send-email-shawn.bohrer@gmail.com> (raw)
In-Reply-To: <1213758236-979-2-git-send-email-shawn.bohrer@gmail.com>
Signed-off-by: Shawn Bohrer <shawn.bohrer@gmail.com>
---
builtin-shortlog.c | 54 +++++++++++++++++++++++++++------------------------
1 files changed, 29 insertions(+), 25 deletions(-)
diff --git a/builtin-shortlog.c b/builtin-shortlog.c
index e6a2865..b1087b5 100644
--- a/builtin-shortlog.c
+++ b/builtin-shortlog.c
@@ -7,9 +7,12 @@
#include "utf8.h"
#include "mailmap.h"
#include "shortlog.h"
+#include "parse-options.h"
-static const char shortlog_usage[] =
-"git-shortlog [-n] [-s] [-e] [-w] [<commit-id>... ]";
+static const char *const shortlog_usage[] = {
+ "git-shortlog [-n] [-s] [-e] [-w] [<commit-id>... ]",
+ NULL
+};
static int compare_by_number(const void *a1, const void *a2)
{
@@ -189,8 +192,6 @@ static const char wrap_arg_usage[] = "-w[<width>[,<indent1>[,<indent2>]]]";
static void parse_wrap_args(const char *arg, int *in1, int *in2, int *wrap)
{
- arg += 2; /* skip -w */
-
*wrap = parse_uint(&arg, ',');
if (*wrap < 0)
die(wrap_arg_usage);
@@ -230,35 +231,38 @@ int cmd_shortlog(int argc, const char **argv, const char *prefix)
struct shortlog log;
struct rev_info rev;
int nongit;
+ const char * wrap_options = NULL;
+ struct option options[] = {
+ OPT_BOOLEAN('n', "numbered", &log.sort_by_number,
+ "sort by number"),
+ OPT_BOOLEAN('s', "summary", &log.summary,
+ "only provide commit count summary"),
+ OPT_BOOLEAN('e', "email", &log.email,
+ "show email address of author"),
+ { OPTION_STRING, 'w', NULL, &wrap_options,
+ "[<width>[,<indent1>[,<indent2>]]]", "linewrap the output",
+ PARSE_OPT_OPTARG, NULL, (intptr_t)"-w" },
+ OPT_END()
+ };
prefix = setup_git_directory_gently(&nongit);
shortlog_init(&log);
- /* since -n is a shadowed rev argument, parse our args first */
- while (argc > 1) {
- if (!strcmp(argv[1], "-n") || !strcmp(argv[1], "--numbered"))
- log.sort_by_number = 1;
- else if (!strcmp(argv[1], "-s") ||
- !strcmp(argv[1], "--summary"))
- log.summary = 1;
- else if (!strcmp(argv[1], "-e") ||
- !strcmp(argv[1], "--email"))
- log.email = 1;
- else if (!prefixcmp(argv[1], "-w")) {
- log.wrap_lines = 1;
- parse_wrap_args(argv[1], &log.in1, &log.in2, &log.wrap);
- }
- else if (!strcmp(argv[1], "-h") || !strcmp(argv[1], "--help"))
- usage(shortlog_usage);
- else
- break;
- argv++;
- argc--;
+ argc = parse_options(argc, argv, options, shortlog_usage,
+ PARSE_OPT_NO_ERROR_ON_UNKNOWN);
+
+ if (wrap_options)
+ {
+ if (!prefixcmp(wrap_options, "-w"))
+ wrap_options += 2; /* skip -w */
+ log.wrap_lines = 1;
+ parse_wrap_args(wrap_options, &log.in1, &log.in2, &log.wrap);
}
+
init_revisions(&rev, prefix);
argc = setup_revisions(argc, argv, &rev, NULL);
if (argc > 1)
- die ("unrecognized argument: %s", argv[1]);
+ usage_with_options(shortlog_usage, options);
/* assume HEAD if from a tty */
if (!nongit && !rev.pending.nr && isatty(0))
--
1.5.4.3
next prev parent reply other threads:[~2008-06-18 3:05 UTC|newest]
Thread overview: 17+ messages / expand[flat|nested] mbox.gz Atom feed top
2008-06-18 3:03 [RFC] convert shortlog to use parse_options Shawn Bohrer
2008-06-18 3:03 ` [PATCH 1/2] parse_options: Add flag to prevent errors for further processing Shawn Bohrer
2008-06-18 3:03 ` Shawn Bohrer [this message]
2008-06-18 3:21 ` Junio C Hamano
2008-06-18 3:30 ` Jeff King
2008-06-18 3:34 ` Jeff King
2008-06-18 5:13 ` Junio C Hamano
2008-06-18 16:50 ` Johannes Schindelin
2008-06-18 18:52 ` Junio C Hamano
2008-06-19 14:25 ` Shawn Bohrer
2008-06-22 19:07 ` Johannes Schindelin
2008-06-23 19:55 ` Junio C Hamano
2008-06-23 19:59 ` Jeff King
2008-06-23 20:17 ` Junio C Hamano
2008-06-23 20:24 ` Johannes Schindelin
2008-06-22 17:07 ` Pierre Habouzit
2008-06-23 1:45 ` Junio C Hamano
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=1213758236-979-3-git-send-email-shawn.bohrer@gmail.com \
--to=shawn.bohrer@gmail.com \
--cc=git@vger.kernel.org \
--cc=gitster@pobox.com \
--cc=madcoder@debian.org \
--cc=peff@peff.net \
/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).