Skip to content

Commit

Permalink
format_note(): simplify API
Browse files Browse the repository at this point in the history
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>
  • Loading branch information
gitster committed Oct 18, 2012
1 parent e297cf5 commit 76141e2
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 15 deletions.
13 changes: 7 additions & 6 deletions notes.c
Expand Up @@ -1204,10 +1204,11 @@ void free_notes(struct notes_tree *t)
* If the given notes_tree is NULL, the internal/default notes_tree will be
* used instead.
*
* 'flags' is a bitwise combination of the flags for format_display_notes.
* (raw != 0) gives the %N userformat; otherwise, the note message is given
* for human consumption.
*/
static void format_note(struct notes_tree *t, const unsigned char *object_sha1,
struct strbuf *sb, const char *output_encoding, int flags)
struct strbuf *sb, const char *output_encoding, int raw)
{
static const char utf8[] = "utf-8";
const unsigned char *sha1;
Expand Down Expand Up @@ -1244,7 +1245,7 @@ static void format_note(struct notes_tree *t, const unsigned char *object_sha1,
if (msglen && msg[msglen - 1] == '\n')
msglen--;

if (flags & NOTES_SHOW_HEADER) {
if (!raw) {
const char *ref = t->ref;
if (!ref || !strcmp(ref, GIT_NOTES_DEFAULT_REF)) {
strbuf_addstr(sb, "\nNotes:\n");
Expand All @@ -1260,7 +1261,7 @@ static void format_note(struct notes_tree *t, const unsigned char *object_sha1,
for (msg_p = msg; msg_p < msg + msglen; msg_p += linelen + 1) {
linelen = strchrnul(msg_p, '\n') - msg_p;

if (flags & NOTES_INDENT)
if (!raw)
strbuf_addstr(sb, " ");
strbuf_add(sb, msg_p, linelen);
strbuf_addch(sb, '\n');
Expand All @@ -1270,13 +1271,13 @@ static void format_note(struct notes_tree *t, const unsigned char *object_sha1,
}

void format_display_notes(const unsigned char *object_sha1,
struct strbuf *sb, const char *output_encoding, int flags)
struct strbuf *sb, const char *output_encoding, int raw)
{
int i;
assert(display_notes_trees);
for (i = 0; display_notes_trees[i]; i++)
format_note(display_notes_trees[i], object_sha1, sb,
output_encoding, flags);
output_encoding, raw);
}

int copy_note(struct notes_tree *t,
Expand Down
6 changes: 1 addition & 5 deletions notes.h
Expand Up @@ -237,10 +237,6 @@ void prune_notes(struct notes_tree *t, int flags);
*/
void free_notes(struct notes_tree *t);

/* Flags controlling how notes are formatted */
#define NOTES_SHOW_HEADER 1
#define NOTES_INDENT 2

struct string_list;

struct display_notes_opt {
Expand Down Expand Up @@ -274,7 +270,7 @@ void init_display_notes(struct display_notes_opt *opt);
* You *must* call init_display_notes() before using this function.
*/
void format_display_notes(const unsigned char *object_sha1,
struct strbuf *sb, const char *output_encoding, int flags);
struct strbuf *sb, const char *output_encoding, int raw);

/*
* Load the notes tree from each ref listed in 'refs'. The output is
Expand Down
5 changes: 2 additions & 3 deletions pretty.c
Expand Up @@ -1035,7 +1035,7 @@ static size_t format_commit_one(struct strbuf *sb, const char *placeholder,
case 'N':
if (c->pretty_ctx->show_notes) {
format_display_notes(commit->object.sha1, sb,
get_log_output_encoding(), 0);
get_log_output_encoding(), 1);
return 1;
}
return 0;
Expand Down Expand Up @@ -1419,8 +1419,7 @@ void pretty_print_commit(const struct pretty_print_context *pp,
strbuf_addch(sb, '\n');

if (pp->show_notes)
format_display_notes(commit->object.sha1, sb, encoding,
NOTES_SHOW_HEADER | NOTES_INDENT);
format_display_notes(commit->object.sha1, sb, encoding, 0);

free(reencoded);
}
Expand Down
2 changes: 1 addition & 1 deletion revision.c
Expand Up @@ -2236,7 +2236,7 @@ static int commit_match(struct commit *commit, struct rev_info *opt)
if (!buf.len)
strbuf_addstr(&buf, commit->buffer);
format_display_notes(commit->object.sha1, &buf,
get_log_output_encoding(), 0);
get_log_output_encoding(), 1);
}

/* Find either in the commit object, or in the temporary */
Expand Down

0 comments on commit 76141e2

Please sign in to comment.