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

[PATCH/RFC 1/2] notes/pretty: allow callers to set the notes format from struct rev_info

From
Michael J Gruber <git@drmicha.warpmail.net>
Date
Apr 26, 2011, 08:54 UTC
Message-ID
<cb2af8d1ef663a68ea96dbb916dcfa0aee71abcb.1303808057.git.git@drmicha.warpmail.net>

The notes display format is customisable, but this possibility is hidden from callers which go through struct rev_info's show_notes member and the pretty-machinery.

Change the show_notes member to an int which determines the format, and set it to NOTES_DEFAULT (which is NOTES_SHOW_HEADER | NOTES_INDENT) where we set it to 1 before. This allows callers to choose a different form.

The only form which cannot be chosen that way is "bare" (no indent, no header) because "0" means "do not show notes" for this code path. But current callers which need that (e.g. "%N" processing) call the notes formatters directly instead. And for future callers which need to request "bare" through rev_info's show_notes we can always introduce another notes format flag NOTES_BARE when we need it.

No functional change with this commit.
Signed-off-by: Michael J Gruber <git@drmicha.warpmail.net>
---
 builtin/log.c |    2 +-
 notes.h       |    1 +
 pretty.c      |    2 +-
 revision.c    |    4 ++--
 revision.h    |    2 +-
 5 files changed, 6 insertions(+), 5 deletions(-)
diff --git a/builtin/log.c b/builtin/log.c
index 9db43ed..5e71caa 100644
--- a/builtin/log.c
+++ b/builtin/log.c
@@ -81,7 +81,7 @@ static void cmd_log_init(int argc, const char **argv, const char *prefix,
 	userformat_find_requirements(NULL, &w);
 
 	if (!rev->show_notes_given && (!rev->pretty_given || w.notes))
-		rev->show_notes = 1;
+		rev->show_notes = NOTES_DEFAULT;
 	if (rev->show_notes)
 		init_display_notes(&rev->notes_opt);
 
diff --git a/notes.h b/notes.h
index 83bd6e0..81d16e3 100644
--- a/notes.h
+++ b/notes.h
@@ -238,6 +238,7 @@ void free_notes(struct notes_tree *t);
 /* Flags controlling how notes are formatted */
 #define NOTES_SHOW_HEADER 1
 #define NOTES_INDENT 2
+#define NOTES_DEFAULT (NOTES_SHOW_HEADER | NOTES_INDENT)
 
 /*
  * Fill the given strbuf with the notes associated with the given object.
diff --git a/pretty.c b/pretty.c
index e1d8a8f..dc371a4 100644
--- a/pretty.c
+++ b/pretty.c
@@ -1271,7 +1271,7 @@ void pretty_print_commit(enum cmit_fmt fmt, const struct commit *commit,
 
 	if (context->show_notes)
 		format_display_notes(commit->object.sha1, sb, encoding,
-				     NOTES_SHOW_HEADER | NOTES_INDENT);
+				     context->show_notes);
 
 	free(reencoded);
 }
diff --git a/revision.c b/revision.c
index 0f38364..f24ffb8 100644
--- a/revision.c
+++ b/revision.c
@@ -1366,11 +1366,11 @@ static int handle_revision_opt(struct rev_info *revs, int argc, const char **arg
 		revs->pretty_given = 1;
 		get_commit_format(arg+9, revs);
 	} else if (!strcmp(arg, "--show-notes")) {
-		revs->show_notes = 1;
+		revs->show_notes = NOTES_DEFAULT;
 		revs->show_notes_given = 1;
 	} else if (!prefixcmp(arg, "--show-notes=")) {
 		struct strbuf buf = STRBUF_INIT;
-		revs->show_notes = 1;
+		revs->show_notes = NOTES_DEFAULT;
 		revs->show_notes_given = 1;
 		if (!revs->notes_opt.extra_notes_refs)
 			revs->notes_opt.extra_notes_refs = xcalloc(1, sizeof(struct string_list));
diff --git a/revision.h b/revision.h
index 9fd8f30..e50eb49 100644
--- a/revision.h
+++ b/revision.h
@@ -84,9 +84,9 @@ struct rev_info {
 			always_show_header:1;
 
 	/* Format info */
+	unsigned int	show_notes;
 	unsigned int	shown_one:1,
 			show_merge:1,
-			show_notes:1,
 			show_notes_given:1,
 			pretty_given:1,
 			abbrev_commit:1,
-- 
1.7.5.270.gafca7
Next: Michael J Gruber
Message 1 of 6 in “notes/pretty: allow callers to set the notes format from struct rev_info”
  1. 1/2 notes/pretty: allow callers to set the notes format from struct rev_infoMichael J Gruber, Apr 26, 2011
  2. 2/2 format-patch: show notes as message after the ---Michael J Gruber, Apr 26, 2011
  3. Johan HerlandApr 26, 2011
  4. Michael J GruberApr 26, 2011
  5. Junio C HamanoApr 26, 2011
  6. Michael J GruberApr 27, 2011

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.