threads / rfc / 27184

RFC patch, 2 partsnotes/pretty: allow callers to set the notes format from struct rev_info

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

## tl;dr

6 messages between Apr 26, 2011 and Apr 27, 2011. Diffs are folded; open one to read it.

replies: 5people: 3as markdown or json

Michael J Gruber· Apr 26, 2011, 08:54 UTC · lore

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(-)
Show changes to 5 files +6 −5

builtin/log.c, notes.h, pretty.c, revision.c, revision.h

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
Michael J Gruber· Apr 26, 2011, 08:54 UTC · re: Michael J Gruber · lore

[PATCH/RFC 2/2] format-patch: show notes as message after the ---

When requesting notes with "--notes", "format-patch" produces notes within the commit message which "am" misunderstands as being part of the message.

Change this so that notes are displayed after an additional "---". Any "am" (old or new) will ignore that, so that it is a safe place for additional comments:

Log message "---" notes "---" diffstat patch

(The first "---" appears only when there is a note, of course.)

Later on (say with "--format-notes") the output format can be changed easily to accomodate a future "am" which knows how to create notes from such patches.

Signed-off-by: Michael J Gruber <git@drmicha.warpmail.net>
---
Reducing the output format to one "---" only is not only complicated (the notes
separator is generated in a quite different place from the patch separator)
but also unnecessary (am reads the patch anyways) and not even preferable (to
give a clear separation of the parts).
---
 builtin/log.c |    4 +++-
 notes.c       |    2 ++
 notes.h       |    3 +++
 3 files changed, 8 insertions(+), 1 deletions(-)
Show changes to 3 files +8 −1

builtin/log.c, notes.c, notes.h

diff --git a/builtin/log.c b/builtin/log.c
index 5e71caa..67aed94 100644
--- a/builtin/log.c
+++ b/builtin/log.c
@@ -1159,8 +1159,10 @@ int cmd_format_patch(int argc, const char **argv, const char *prefix)
 	if (!DIFF_OPT_TST(&rev.diffopt, TEXT) && !no_binary_diff)
 		DIFF_OPT_SET(&rev.diffopt, BINARY);
 
-	if (rev.show_notes)
+	if (rev.show_notes) {
 		init_display_notes(&rev.notes_opt);
+		rev.show_notes = NOTES_DASH;
+	}
 
 	if (!use_stdout)
 		output_directory = set_outdir(prefix, output_directory);
diff --git a/notes.c b/notes.c
index a013c1b..b8b737e 100644
--- a/notes.c
+++ b/notes.c
@@ -1233,6 +1233,8 @@ void format_note(struct notes_tree *t, const unsigned char *object_sha1,
 	if (msglen && msg[msglen - 1] == '\n')
 		msglen--;
 
+	if (flags & NOTES_DASH)
+		strbuf_addstr(sb, "---\n");
 	if (flags & NOTES_SHOW_HEADER) {
 		const char *ref = t->ref;
 		if (!ref || !strcmp(ref, GIT_NOTES_DEFAULT_REF)) {
diff --git a/notes.h b/notes.h
index 81d16e3..17150d5 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_DASH 4
 #define NOTES_DEFAULT (NOTES_SHOW_HEADER | NOTES_INDENT)
 
 /*
@@ -284,6 +285,8 @@ void init_display_notes(struct display_notes_opt *opt);
  *
  * - NOTES_INDENT: indent the notes by 4 places
  *
+ * - NOTES_DASH: prepend a "---" line
+ *
  * You *must* call init_display_notes() before using this function.
  */
 void format_display_notes(const unsigned char *object_sha1,
-- 
1.7.5.270.gafca7
Johan Herland· Apr 26, 2011, 09:28 UTC · re: Michael J Gruber · lore

Re: [PATCH/RFC 2/2] format-patch: show notes as message after the ---

On Tuesday 26 April 2011, Michael J Gruber wrote:
Show 22 quoted lines
> When requesting notes with "--notes", "format-patch" produces notes
> within the commit message which "am" misunderstands as being part of
> the message.
>
> Change this so that notes are displayed after an additional "---".
> Any "am" (old or new) will ignore that, so that it is a safe place
> for additional comments:
>
> Log message
> "---"
> notes
> "---"
> diffstat
> patch
>
> (The first "---" appears only when there is a note, of course.)
>
> Later on (say with "--format-notes") the output format can be changed
> easily to accomodate a future "am" which knows how to create notes
> from such patches.
>
> Signed-off-by: Michael J Gruber <git@drmicha.warpmail.net>
Acked-by: Johan Herland <johan@herland.net>
(goes for 1/2 as well)
/me likes :)
...Johan
-- 
Johan Herland, <johan@herland.net>
www.herland.net
Michael J Gruber· Apr 26, 2011, 09:44 UTC · re: Johan Herland · lore

Re: [PATCH/RFC 2/2] format-patch: show notes as message after the ---

Johan Herland venit, vidit, dixit 26.04.2011 11:28:
Show 30 quoted lines
> On Tuesday 26 April 2011, Michael J Gruber wrote:
>> When requesting notes with "--notes", "format-patch" produces notes
>> within the commit message which "am" misunderstands as being part of
>> the message.
>>
>> Change this so that notes are displayed after an additional "---".
>> Any "am" (old or new) will ignore that, so that it is a safe place
>> for additional comments:
>>
>> Log message
>> "---"
>> notes
>> "---"
>> diffstat
>> patch
>>
>> (The first "---" appears only when there is a note, of course.)
>>
>> Later on (say with "--format-notes") the output format can be changed
>> easily to accomodate a future "am" which knows how to create notes
>> from such patches.
>>
>> Signed-off-by: Michael J Gruber <git@drmicha.warpmail.net>
> 
> Acked-by: Johan Herland <johan@herland.net>
> 
> (goes for 1/2 as well)
> 
> 
> /me likes :)
Thanks :)
BTW: Just before hitting "send-mail", I thought of quoting the "---" in
my commit message where I describe the format. I wonder what would have
happened else when am-ing that message...
Michael
Junio C Hamano· Apr 26, 2011, 17:39 UTC · re: Michael J Gruber · lore

Re: [PATCH/RFC 2/2] format-patch: show notes as message after the ---

Michael J Gruber <git@drmicha.warpmail.net> writes:
Show 28 quoted lines
> When requesting notes with "--notes", "format-patch" produces notes
> within the commit message which "am" misunderstands as being part of the
> message.
>
> Change this so that notes are displayed after an additional "---". Any
> "am" (old or new) will ignore that, so that it is a safe place for
> additional comments:
>
> Log message
> "---"
> notes
> "---"
> diffstat
> patch
>
> (The first "---" appears only when there is a note, of course.)
>
> Later on (say with "--format-notes") the output format can be changed
> easily to accomodate a future "am" which knows how to create notes from
> such patches.
>
> Signed-off-by: Michael J Gruber <git@drmicha.warpmail.net>
> ---
> Reducing the output format to one "---" only is not only complicated (the notes
> separator is generated in a quite different place from the patch separator)
> but also unnecessary (am reads the patch anyways) and not even preferable (to
> give a clear separation of the parts).
> ---

If you show more than one note, separating them with "---" in between would be a good idea so that reader can tell where each note ends, but I'd rather not to see the "---" after the last note. Put just a blank line here instead.

Michael J Gruber· Apr 27, 2011, 06:37 UTC · re: Junio C Hamano · lore

Re: [PATCH/RFC 2/2] format-patch: show notes as message after the ---

Junio C Hamano venit, vidit, dixit 26.04.2011 19:39:
Show 33 quoted lines
> Michael J Gruber <git@drmicha.warpmail.net> writes:
> 
>> When requesting notes with "--notes", "format-patch" produces notes
>> within the commit message which "am" misunderstands as being part of the
>> message.
>>
>> Change this so that notes are displayed after an additional "---". Any
>> "am" (old or new) will ignore that, so that it is a safe place for
>> additional comments:
>>
>> Log message
>> "---"
>> notes
>> "---"
>> diffstat
>> patch
>>
>> (The first "---" appears only when there is a note, of course.)
>>
>> Later on (say with "--format-notes") the output format can be changed
>> easily to accomodate a future "am" which knows how to create notes from
>> such patches.
>>
>> Signed-off-by: Michael J Gruber <git@drmicha.warpmail.net>
>> ---
>> Reducing the output format to one "---" only is not only complicated (the notes
>> separator is generated in a quite different place from the patch separator)
>> but also unnecessary (am reads the patch anyways) and not even preferable (to
>> give a clear separation of the parts).
>> ---
> 
> If you show more than one note, separating them with "---" in between
> would be a good idea so that reader can tell where each note ends, but I'd
It does that already. More precisely, each note is preceded by a "---\n".
> rather not to see the "---" after the last note.  Put just a blank line
> here instead.

Well, in the note which you snipped, I tried to explain that that is complicated (the note code would need to set a flag "dash_output" which the log-tree code would need to look at) and may not even be preferable, because the "---" gives a clear separation between the note and the diffstat. I'll check whether there's an easy way (and provide a test).

Michael

← back to recent threads