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 <johannes.schindelin@gmx.de> Signed-off-by: Johan Herland <johan@herland.net> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Johan Herland committed
Oct 9, 2009 at 12:22 UTC
c56fcc89b951f3e8c9240ea02676b2eef5417da6
3 files changed
+11
-5
notes.c
+5
-3
@@ -106,7 +106,7 @@ static unsigned char *lookup_notes(const unsigned char *commit_sha1)
106
}
107
108
void get_commit_notes(const struct commit *commit, struct strbuf *sb,
109
- const char *output_encoding)
109
+ const char *output_encoding, int flags)
110
{
111
static const char utf8[] = "utf-8";
112
unsigned char *sha1;
@@ -148,12 +148,14 @@ void get_commit_notes(const struct commit *commit, struct strbuf *sb,
148
if (msglen && msg[msglen - 1] == '\n')
149
msglen--;
150
151
- strbuf_addstr(sb, "\nNotes:\n");
151
+ if (flags & NOTES_SHOW_HEADER)
152
+ strbuf_addstr(sb, "\nNotes:\n");
153
154
for (msg_p = msg; msg_p < msg + msglen; msg_p += linelen + 1) {
155
linelen = strchrnul(msg_p, '\n') - msg_p;
156
156
- strbuf_addstr(sb, " ");
157
+ if (flags & NOTES_INDENT)
158
+ strbuf_addstr(sb, " ");
159
strbuf_add(sb, msg_p, linelen);
160
strbuf_addch(sb, '\n');
161
}
notes.h
+4
-1
@@ -1,7 +1,10 @@
1
#ifndef NOTES_H
2
#define NOTES_H
3
4
+#define NOTES_SHOW_HEADER 1
5
+#define NOTES_INDENT 2
6
+
7
void get_commit_notes(const struct commit *commit, struct strbuf *sb,
5
- const char *output_encoding);
8
+ const char *output_encoding, int flags);
9
10
#endif
pretty.c
+2
-1
@@ -978,7 +978,8 @@ void pretty_print_commit(enum cmit_fmt fmt, const struct commit *commit,
978
strbuf_addch(sb, '\n');
979
980
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);
983
984
free(reencoded);
985
}