format_note(): simplify API
We either stuff the notes message without modification for %N userformat, or format it for human consumption. Using two bits is an overkill that does not benefit anybody. Signed-off-by: Junio C Hamano <gitster@pobox.com>
Junio C Hamano committed
Oct 17, 2012 at 21:41 UTC
76141e2e6280101362c3c5ddb22699b6f0458100
4 files changed
+11
-15
notes.c
+7
-6
@@ -1204,10 +1204,11 @@ void free_notes(struct notes_tree *t)
1204
* If the given notes_tree is NULL, the internal/default notes_tree will be
1205
* used instead.
1206
*
1207
- * 'flags' is a bitwise combination of the flags for format_display_notes.
1207
+ * (raw != 0) gives the %N userformat; otherwise, the note message is given
1208
+ * for human consumption.
1209
*/
1210
static void format_note(struct notes_tree *t, const unsigned char *object_sha1,
1210
- struct strbuf *sb, const char *output_encoding, int flags)
1211
+ struct strbuf *sb, const char *output_encoding, int raw)
1212
{
1213
static const char utf8[] = "utf-8";
1214
const unsigned char *sha1;
@@ -1244,7 +1245,7 @@ static void format_note(struct notes_tree *t, const unsigned char *object_sha1,
1245
if (msglen && msg[msglen - 1] == '\n')
1246
msglen--;
1247
1247
- if (flags & NOTES_SHOW_HEADER) {
1248
+ if (!raw) {
1249
const char *ref = t->ref;
1250
if (!ref || !strcmp(ref, GIT_NOTES_DEFAULT_REF)) {
1251
strbuf_addstr(sb, "\nNotes:\n");
@@ -1260,7 +1261,7 @@ static void format_note(struct notes_tree *t, const unsigned char *object_sha1,
1261
for (msg_p = msg; msg_p < msg + msglen; msg_p += linelen + 1) {
1262
linelen = strchrnul(msg_p, '\n') - msg_p;
1263
1263
- if (flags & NOTES_INDENT)
1264
+ if (!raw)
1265
strbuf_addstr(sb, " ");
1266
strbuf_add(sb, msg_p, linelen);
1267
strbuf_addch(sb, '\n');
@@ -1270,13 +1271,13 @@ static void format_note(struct notes_tree *t, const unsigned char *object_sha1,
1271
}
1272
1273
void format_display_notes(const unsigned char *object_sha1,
1273
- struct strbuf *sb, const char *output_encoding, int flags)
1274
+ struct strbuf *sb, const char *output_encoding, int raw)
1275
{
1276
int i;
1277
assert(display_notes_trees);
1278
for (i = 0; display_notes_trees[i]; i++)
1279
format_note(display_notes_trees[i], object_sha1, sb,
1279
- output_encoding, flags);
1280
+ output_encoding, raw);
1281
}
1282
1283
int copy_note(struct notes_tree *t,
notes.h
+1
-5
@@ -237,10 +237,6 @@ void prune_notes(struct notes_tree *t, int flags);
237
*/
238
void free_notes(struct notes_tree *t);
239
240
-/* Flags controlling how notes are formatted */
241
-#define NOTES_SHOW_HEADER 1
242
-#define NOTES_INDENT 2
243
-
240
struct string_list;
241
242
struct display_notes_opt {
@@ -274,7 +270,7 @@ void init_display_notes(struct display_notes_opt *opt);
270
* You *must* call init_display_notes() before using this function.
271
*/
272
void format_display_notes(const unsigned char *object_sha1,
277
- struct strbuf *sb, const char *output_encoding, int flags);
273
+ struct strbuf *sb, const char *output_encoding, int raw);
274
275
/*
276
* Load the notes tree from each ref listed in 'refs'. The output is
pretty.c
+2
-3
@@ -1035,7 +1035,7 @@ static size_t format_commit_one(struct strbuf *sb, const char *placeholder,
1035
case 'N':
1036
if (c->pretty_ctx->show_notes) {
1037
format_display_notes(commit->object.sha1, sb,
1038
- get_log_output_encoding(), 0);
1038
+ get_log_output_encoding(), 1);
1039
return 1;
1040
}
1041
return 0;
@@ -1419,8 +1419,7 @@ void pretty_print_commit(const struct pretty_print_context *pp,
1419
strbuf_addch(sb, '\n');
1420
1421
if (pp->show_notes)
1422
- format_display_notes(commit->object.sha1, sb, encoding,
1423
- NOTES_SHOW_HEADER | NOTES_INDENT);
1422
+ format_display_notes(commit->object.sha1, sb, encoding, 0);
1423
1424
free(reencoded);
1425
}
revision.c
+1
-1
@@ -2236,7 +2236,7 @@ static int commit_match(struct commit *commit, struct rev_info *opt)
2236
if (!buf.len)
2237
strbuf_addstr(&buf, commit->buffer);
2238
format_display_notes(commit->object.sha1, &buf,
2239
- get_log_output_encoding(), 0);
2239
+ get_log_output_encoding(), 1);
2240
}
2241
2242
/* Find either in the commit object, or in the temporary */