git.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Will Palmer <wmpalmer@gmail.com>
To: git@vger.kernel.org
Cc: wmpalmer@gmail.com, gitster@pobox.com, peff@peff.net,
	raa.lkml@gmail.com, jrnieder@gmail.com
Subject: [PATCH v3 4/5] pretty: add infrastructure to allow format aliases
Date: Fri, 30 Apr 2010 20:35:27 +0100	[thread overview]
Message-ID: <1272656128-2002-5-git-send-email-wmpalmer@gmail.com> (raw)
In-Reply-To: <1272656128-2002-1-git-send-email-wmpalmer@gmail.com>

here we modify the find_commit_format function to make it recursively
dereference aliases when they are specified. At this point, there are
no aliases specified and there is no way to specify an alias, but the
support is there for any which are added.

Signed-off-by: Will Palmer <wmpalmer@gmail.com>
---
 pretty.c |   23 ++++++++++++++++++++---
 1 files changed, 20 insertions(+), 3 deletions(-)

diff --git a/pretty.c b/pretty.c
index 55d5721..3d1c4a9 100644
--- a/pretty.c
+++ b/pretty.c
@@ -15,6 +15,8 @@ static struct cmt_fmt_map {
 	const char *name;
 	enum cmit_fmt format;
 	int is_tformat;
+	int is_alias;
+	const char *user_format;
 } *commit_formats = NULL;
 static size_t commit_formats_len = 0;
 static struct cmt_fmt_map *find_commit_format(const char *sought);
@@ -46,14 +48,15 @@ static void setup_commit_formats(void)
 	       sizeof(*builtin_formats)*ARRAY_SIZE(builtin_formats));
 }
 
-static struct cmt_fmt_map *find_commit_format(const char *sought)
+static struct cmt_fmt_map *find_commit_format_recursive(const char *sought,
+							int num_redirections)
 {
 	struct cmt_fmt_map *found = NULL;
 	size_t found_match_len;
 	int i;
 
-	if (!commit_formats)
-		setup_commit_formats();
+	if (num_redirections >= commit_formats_len)
+		return NULL;
 
 	for (i = 0; i < commit_formats_len; i++) {
 		size_t match_len;
@@ -67,9 +70,23 @@ static struct cmt_fmt_map *find_commit_format(const char *sought)
 			found_match_len = match_len;
 		}
 	}
+
+	if (found && found->is_alias) {
+		found = find_commit_format_recursive(found->user_format,
+						     num_redirections+1);
+	}
+
 	return found;
 }
 
+static struct cmt_fmt_map *find_commit_format(const char *sought)
+{
+	if (!commit_formats)
+		setup_commit_formats();
+
+	return find_commit_format_recursive(sought, 0);
+}
+
 void get_commit_format(const char *arg, struct rev_info *rev)
 {
 	struct cmt_fmt_map *commit_format;
-- 
1.7.1.rc1.13.gbb0a0a.dirty

  parent reply	other threads:[~2010-04-30 19:38 UTC|newest]

Thread overview: 21+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2010-04-30 19:35 [PATCH v3 0/5] pretty: format aliases Will Palmer
2010-04-30 19:35 ` [PATCH v3 1/5] pretty: add conditional %C?colorname placeholders Will Palmer
2010-05-02  3:12   ` Junio C Hamano
2010-05-02  9:31     ` Will Palmer
2010-04-30 19:35 ` [PATCH v3 2/5] pretty: make %H/%h/etc respect --abbrev[-commit] Will Palmer
2010-05-02  3:13   ` Junio C Hamano
2010-05-02  4:45     ` Jeff King
2010-05-02  5:33       ` Junio C Hamano
2010-05-02  5:40         ` Jeff King
2010-05-02  7:52         ` Will Palmer
2010-05-02  8:50     ` Will Palmer
2010-05-02  9:11       ` Junio C Hamano
2010-05-02  9:17         ` Jonathan Nieder
2010-04-30 19:35 ` [PATCH v3 3/5] pretty: make it easier to add new formats Will Palmer
2010-04-30 19:35 ` Will Palmer [this message]
2010-05-02  3:13   ` [PATCH v3 4/5] pretty: add infrastructure to allow format aliases Junio C Hamano
2010-05-02  9:01     ` Will Palmer
2010-04-30 19:35 ` [PATCH v3 5/5] pretty: add aliases for pretty formats Will Palmer
2010-05-02  3:13   ` Junio C Hamano
2010-05-02  4:47   ` Jeff King
2010-05-02  3:12 ` [PATCH v3 0/5] pretty: format aliases 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=1272656128-2002-5-git-send-email-wmpalmer@gmail.com \
    --to=wmpalmer@gmail.com \
    --cc=git@vger.kernel.org \
    --cc=gitster@pobox.com \
    --cc=jrnieder@gmail.com \
    --cc=peff@peff.net \
    --cc=raa.lkml@gmail.com \
    /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).