Skip to content

Commit

Permalink
Don't use "<unknown>" for placeholders and suppress printing of empty…
Browse files Browse the repository at this point in the history
… user formats.

This changes the interporate() to replace entries with NULL values
by the empty string, and uses it to interpolate missing fields in
custom format output used in git-log and friends.  It is most useful
to avoid <unknown> output from %b format for a commit log message
that lack any body text.

Signed-off-by: Junio C Hamano <gitster@pobox.com>
  • Loading branch information
Michal Vitecek authored and Junio C Hamano committed Sep 26, 2007
1 parent 5166810 commit 55246aa
Show file tree
Hide file tree
Showing 6 changed files with 11 additions and 16 deletions.
3 changes: 2 additions & 1 deletion builtin-rev-list.c
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,8 @@ static void show_commit(struct commit *commit)
pretty_print_commit(revs.commit_format, commit, ~0,
&buf, &buflen,
revs.abbrev, NULL, NULL, revs.date_mode);
printf("%s%c", buf, hdr_termination);
if (*buf)
printf("%s%c", buf, hdr_termination);
free(buf);
}
maybe_flush_or_die(stdout, "stdout");
Expand Down
3 changes: 0 additions & 3 deletions commit.c
Original file line number Diff line number Diff line change
Expand Up @@ -917,9 +917,6 @@ long format_commit_message(const struct commit *commit, const void *format,
}
if (msg[i])
table[IBODY].value = xstrdup(msg + i);
for (i = 0; i < ARRAY_SIZE(table); i++)
if (!table[i].value)
interp_set_entry(table, i, "<unknown>");

do {
char *buf = *buf_p;
Expand Down
6 changes: 5 additions & 1 deletion interpolate.c
Original file line number Diff line number Diff line change
Expand Up @@ -76,8 +76,12 @@ unsigned long interpolate(char *result, unsigned long reslen,
/* Check for valid interpolation. */
if (i < ninterps) {
value = interps[i].value;
valuelen = strlen(value);
if (!value) {
src += namelen;
continue;
}

valuelen = strlen(value);
if (newlen + valuelen + 1 < reslen) {
/* Substitute. */
strncpy(dest, value, valuelen);
Expand Down
3 changes: 2 additions & 1 deletion log-tree.c
Original file line number Diff line number Diff line change
Expand Up @@ -298,7 +298,8 @@ void show_log(struct rev_info *opt, const char *sep)
if (opt->show_log_size)
printf("log size %i\n", len);

printf("%s%s%s", msgbuf, extra, sep);
if (*msgbuf)
printf("%s%s%s", msgbuf, extra, sep);
free(msgbuf);
}

Expand Down
8 changes: 0 additions & 8 deletions t/t6006-rev-list-format.sh
Original file line number Diff line number Diff line change
Expand Up @@ -79,9 +79,7 @@ EOF

test_format encoding %e <<'EOF'
commit 131a310eb913d107dd3c09a65d1651175898735d
<unknown>
commit 86c75cfd708a0e5868dc876ed5b8bb66c80b4873
<unknown>
EOF

test_format subject %s <<'EOF'
Expand All @@ -93,9 +91,7 @@ EOF

test_format body %b <<'EOF'
commit 131a310eb913d107dd3c09a65d1651175898735d
<unknown>
commit 86c75cfd708a0e5868dc876ed5b8bb66c80b4873
<unknown>
EOF

test_format colors %Credfoo%Cgreenbar%Cbluebaz%Cresetxyzzy <<'EOF'
Expand All @@ -121,9 +117,7 @@ test_format complex-encoding %e <<'EOF'
commit f58db70b055c5718631e5c61528b28b12090cdea
iso8859-1
commit 131a310eb913d107dd3c09a65d1651175898735d
<unknown>
commit 86c75cfd708a0e5868dc876ed5b8bb66c80b4873
<unknown>
EOF

test_format complex-subject %s <<'EOF'
Expand All @@ -142,9 +136,7 @@ and it will be encoded in iso8859-1. We should therefore
include an iso8859 character: ¡bueno!
commit 131a310eb913d107dd3c09a65d1651175898735d
<unknown>
commit 86c75cfd708a0e5868dc876ed5b8bb66c80b4873
<unknown>
EOF

test_done
4 changes: 2 additions & 2 deletions t/t7500-commit.sh
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ test_expect_success 'explicit commit message should override template' '
git add foo &&
GIT_EDITOR=../t7500/add-content git commit --template "$TEMPLATE" \
-m "command line msg" &&
commit_msg_is "command line msg<unknown>"
commit_msg_is "command line msg"
'

test_expect_success 'commit message from file should override template' '
Expand All @@ -90,7 +90,7 @@ test_expect_success 'commit message from file should override template' '
echo "standard input msg" |
GIT_EDITOR=../t7500/add-content git commit \
--template "$TEMPLATE" --file - &&
commit_msg_is "standard input msg<unknown>"
commit_msg_is "standard input msg"
'

test_done

0 comments on commit 55246aa

Please sign in to comment.