Skip to content

Commit c56fcc8

Browse files
jherlandgitster
authored andcommitted
Add flags to get_commit_notes() to control the format of the note string
This patch adds the following flags to get_commit_notes() for adjusting the format of the produced note string: - NOTES_SHOW_HEADER: Print "Notes:" line before the notes contents - NOTES_INDENT: Indent notes contents by 4 spaces Suggested-by: Johannes Schindelin <[email protected]> Signed-off-by: Johan Herland <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 3ed24b6 commit c56fcc8

File tree

3 files changed

+11
-5
lines changed

3 files changed

+11
-5
lines changed

notes.c

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,7 @@ static unsigned char *lookup_notes(const unsigned char *commit_sha1)
106106
}
107107

108108
void get_commit_notes(const struct commit *commit, struct strbuf *sb,
109-
const char *output_encoding)
109+
const char *output_encoding, int flags)
110110
{
111111
static const char utf8[] = "utf-8";
112112
unsigned char *sha1;
@@ -148,12 +148,14 @@ void get_commit_notes(const struct commit *commit, struct strbuf *sb,
148148
if (msglen && msg[msglen - 1] == '\n')
149149
msglen--;
150150

151-
strbuf_addstr(sb, "\nNotes:\n");
151+
if (flags & NOTES_SHOW_HEADER)
152+
strbuf_addstr(sb, "\nNotes:\n");
152153

153154
for (msg_p = msg; msg_p < msg + msglen; msg_p += linelen + 1) {
154155
linelen = strchrnul(msg_p, '\n') - msg_p;
155156

156-
strbuf_addstr(sb, " ");
157+
if (flags & NOTES_INDENT)
158+
strbuf_addstr(sb, " ");
157159
strbuf_add(sb, msg_p, linelen);
158160
strbuf_addch(sb, '\n');
159161
}

notes.h

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,10 @@
11
#ifndef NOTES_H
22
#define NOTES_H
33

4+
#define NOTES_SHOW_HEADER 1
5+
#define NOTES_INDENT 2
6+
47
void get_commit_notes(const struct commit *commit, struct strbuf *sb,
5-
const char *output_encoding);
8+
const char *output_encoding, int flags);
69

710
#endif

pretty.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -978,7 +978,8 @@ void pretty_print_commit(enum cmit_fmt fmt, const struct commit *commit,
978978
strbuf_addch(sb, '\n');
979979

980980
if (fmt != CMIT_FMT_ONELINE)
981-
get_commit_notes(commit, sb, encoding);
981+
get_commit_notes(commit, sb, encoding,
982+
NOTES_SHOW_HEADER | NOTES_INDENT);
982983

983984
free(reencoded);
984985
}

0 commit comments

Comments
 (0)