From: Eric Wong <normalperson@yhbt.net>
To: git@vger.kernel.org
Cc: Eric Wong <normalperson@yhbt.net>
Subject: [PATCH 6/6] commit: allow --pretty= args to be abbreviated
Date: Mon, 08 May 2006 22:06:49 -0700 [thread overview]
Message-ID: <11471512123998-git-send-email-normalperson@yhbt.net> (raw)
In-Reply-To: <11471512123005-git-send-email-normalperson@yhbt.net>
Signed-off-by: Eric Wong <normalperson@yhbt.net>
---
commit.c | 42 +++++++++++++++++++++++++++++-------------
1 files changed, 29 insertions(+), 13 deletions(-)
0a3aed7c25eca808b29f2318d5e4c087e03b9bfb
diff --git a/commit.c b/commit.c
index a056b25..055064a 100644
--- a/commit.c
+++ b/commit.c
@@ -22,23 +22,39 @@ struct sort_node
const char *commit_type = "commit";
+struct cmt_fmt_map {
+ const char *n;
+ enum cmit_fmt v;
+} cmt_fmts[] = {
+ { "raw", CMIT_FMT_RAW },
+ { "medium", CMIT_FMT_MEDIUM },
+ { "short", CMIT_FMT_SHORT },
+ { "full", CMIT_FMT_FULL },
+ { "fuller", CMIT_FMT_FULLER },
+ { "oneline", CMIT_FMT_ONELINE },
+};
+
enum cmit_fmt get_commit_format(const char *arg)
{
+ int i, found = -1;
if (!*arg)
return CMIT_FMT_DEFAULT;
- if (!strcmp(arg, "raw"))
- return CMIT_FMT_RAW;
- if (!strcmp(arg, "medium"))
- return CMIT_FMT_MEDIUM;
- if (!strcmp(arg, "short"))
- return CMIT_FMT_SHORT;
- if (!strcmp(arg, "full"))
- return CMIT_FMT_FULL;
- if (!strcmp(arg, "fuller"))
- return CMIT_FMT_FULLER;
- if (!strcmp(arg, "oneline"))
- return CMIT_FMT_ONELINE;
- die("invalid --pretty format");
+ for (i = 0; i < ARRAY_SIZE(cmt_fmts); i++) {
+ if (!strcmp(arg, cmt_fmts[i].n))
+ return cmt_fmts[i].v;
+ }
+
+ /* look for abbreviations */
+ for (i = 0; i < ARRAY_SIZE(cmt_fmts); i++) {
+ if (strstr(cmt_fmts[i].n, arg)) {
+ if (found >= 0)
+ die("invalid --pretty format: %s", arg);
+ found = i;
+ }
+ }
+ if (found >= 0)
+ return cmt_fmts[found].v;
+ die("invalid --pretty format: %s", arg);
}
static struct commit *check_commit(struct object *obj,
--
1.3.2.g0a3ae
next prev parent reply other threads:[~2006-05-09 6:23 UTC|newest]
Thread overview: 22+ messages / expand[flat|nested] mbox.gz Atom feed top
2006-05-09 5:06 [PATCH/RFC] gitopt - command-line parsing enhancements Eric Wong
2006-05-09 5:06 ` [PATCH 1/6] gitopt: a new command-line option parser for git Eric Wong
2006-05-09 5:06 ` [PATCH 2/6] update-index: convert to using gitopt Eric Wong
2006-05-09 5:06 ` [PATCH 3/6] ls-tree: convert to gitopt Eric Wong
2006-05-09 5:06 ` [PATCH 4/6] ls-files: convert to using gitopt Eric Wong
2006-05-09 5:06 ` [PATCH 5/6] gitopt: convert setup_revisions(), and diff_opt_parse() Eric Wong
2006-05-09 5:06 ` Eric Wong [this message]
2006-05-09 7:16 ` Eric Wong
2006-05-11 20:19 ` Eric Wong
2006-05-09 9:08 ` [PATCH 1/6] gitopt: a new command-line option parser for git Timo Hirvonen
2006-05-09 12:58 ` Junio C Hamano
2006-05-09 19:39 ` Eric Wong
2006-05-09 19:18 ` Eric Wong
2006-05-09 20:10 ` Timo Hirvonen
2006-05-09 20:35 ` Junio C Hamano
2006-05-09 21:08 ` Timo Hirvonen
2006-05-09 21:11 ` Junio C Hamano
2006-05-09 21:31 ` Timo Hirvonen
2006-05-09 8:35 ` [PATCH/RFC] gitopt - command-line parsing enhancements Junio C Hamano
2006-05-09 19:48 ` Eric Wong
2006-05-09 20:28 ` Junio C Hamano
2006-05-09 21:14 ` Eric Wong
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=11471512123998-git-send-email-normalperson@yhbt.net \
--to=normalperson@yhbt.net \
--cc=git@vger.kernel.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).