git/list[1] front-page[2] threads[3] people[4] search[5] about
 

[PATCH v3 4/5] pretty: add infrastructure to allow format aliases

From
Will Palmer <wmpalmer@gmail.com>
Date
Apr 30, 2010, 19:35 UTC
Message-ID
<1272656128-2002-5-git-send-email-wmpalmer@gmail.com>
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
Previous: Will PalmerNext: Junio C Hamano
Message 15 of 21 in “pretty: format aliases”
  1. 0/5 pretty: format aliasesWill Palmer, Apr 30, 2010
  2. 1/5 pretty: add conditional %C?colorname placeholdersWill Palmer, Apr 30, 2010
  3. Junio C HamanoMay 2, 2010
  4. Will PalmerMay 2, 2010
  5. 2/5 pretty: make %H/%h/etc respect --abbrev[-commit]Will Palmer, Apr 30, 2010
  6. Junio C HamanoMay 2, 2010
  7. Jeff KingMay 2, 2010
  8. Junio C HamanoMay 2, 2010
  9. Jeff KingMay 2, 2010
  10. Will PalmerMay 2, 2010
  11. Will PalmerMay 2, 2010
  12. Junio C HamanoMay 2, 2010
  13. Jonathan NiederMay 2, 2010
  14. 3/5 pretty: make it easier to add new formatsWill Palmer, Apr 30, 2010
  15. 4/5 pretty: add infrastructure to allow format aliasesWill Palmer, Apr 30, 2010
  16. Junio C HamanoMay 2, 2010
  17. Will PalmerMay 2, 2010
  18. 5/5 pretty: add aliases for pretty formatsWill Palmer, Apr 30, 2010
  19. Junio C HamanoMay 2, 2010
  20. Jeff KingMay 2, 2010
  21. Junio C HamanoMay 2, 2010

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.