From mboxrd@z Thu Jan 1 00:00:00 1970 From: Eric Wong Subject: [PATCH 6/6] commit: allow --pretty= args to be abbreviated Date: Mon, 08 May 2006 22:06:49 -0700 Message-ID: <11471512123998-git-send-email-normalperson@yhbt.net> References: <11471512123005-git-send-email-normalperson@yhbt.net> Reply-To: Eric Wong Cc: Eric Wong X-From: git-owner@vger.kernel.org Tue May 09 08:23:20 2006 Return-path: Envelope-to: gcvg-git@gmane.org Received: from vger.kernel.org ([209.132.176.167]) by ciao.gmane.org with esmtp (Exim 4.43) id 1FdLcl-0008Bq-Gw for gcvg-git@gmane.org; Tue, 09 May 2006 08:23:12 +0200 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751424AbWEIGWv (ORCPT ); Tue, 9 May 2006 02:22:51 -0400 Received: (majordomo@vger.kernel.org) by vger.kernel.org id S1751429AbWEIGWv (ORCPT ); Tue, 9 May 2006 02:22:51 -0400 Received: from hand.yhbt.net ([66.150.188.102]:8927 "EHLO hand.yhbt.net") by vger.kernel.org with ESMTP id S1751427AbWEIGWo (ORCPT ); Tue, 9 May 2006 02:22:44 -0400 Received: from localhost.localdomain (localhost [127.0.0.1]) by hand.yhbt.net (Postfix) with ESMTP id BAA2B2DC035; Mon, 8 May 2006 23:22:43 -0700 (PDT) To: git@vger.kernel.org X-Mailer: git-send-email 1.3.2.ge3d7 In-Reply-To: <11471512123005-git-send-email-normalperson@yhbt.net> Sender: git-owner@vger.kernel.org Precedence: bulk X-Mailing-List: git@vger.kernel.org Archived-At: Signed-off-by: Eric Wong --- 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