Don't use "<unknown>" for placeholders and suppress printing of empty 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>
Michal Vitecek committed
Sep 25, 2007 at 16:38 UTC
55246aac6717e86c14f31391ac903ed810d1a9a0
6 files changed
+11
-16
builtin-rev-list.c
+2
-1
@@ -85,7 +85,8 @@ static void show_commit(struct commit *commit)
85
pretty_print_commit(revs.commit_format, commit, ~0,
86
&buf, &buflen,
87
revs.abbrev, NULL, NULL, revs.date_mode);
88
- printf("%s%c", buf, hdr_termination);
88
+ if (*buf)
89
+ printf("%s%c", buf, hdr_termination);
90
free(buf);
91
}
92
maybe_flush_or_die(stdout, "stdout");
commit.c
-3
@@ -917,9 +917,6 @@ long format_commit_message(const struct commit *commit, const void *format,
917
}
918
if (msg[i])
919
table[IBODY].value = xstrdup(msg + i);
920
- for (i = 0; i < ARRAY_SIZE(table); i++)
921
- if (!table[i].value)
922
- interp_set_entry(table, i, "<unknown>");
920
921
do {
922
char *buf = *buf_p;
interpolate.c
+5
-1
@@ -76,8 +76,12 @@ unsigned long interpolate(char *result, unsigned long reslen,
76
/* Check for valid interpolation. */
77
if (i < ninterps) {
78
value = interps[i].value;
79
- valuelen = strlen(value);
79
+ if (!value) {
80
+ src += namelen;
81
+ continue;
82
+ }
83
84
+ valuelen = strlen(value);
85
if (newlen + valuelen + 1 < reslen) {
86
/* Substitute. */
87
strncpy(dest, value, valuelen);
log-tree.c
+2
-1
@@ -298,7 +298,8 @@ void show_log(struct rev_info *opt, const char *sep)
298
if (opt->show_log_size)
299
printf("log size %i\n", len);
300
301
- printf("%s%s%s", msgbuf, extra, sep);
301
+ if (*msgbuf)
302
+ printf("%s%s%s", msgbuf, extra, sep);
303
free(msgbuf);
304
}
305
t/t6006-rev-list-format.sh
-8
@@ -79,9 +79,7 @@ EOF
79
80
test_format encoding %e <<'EOF'
81
commit 131a310eb913d107dd3c09a65d1651175898735d
82
-<unknown>
82
commit 86c75cfd708a0e5868dc876ed5b8bb66c80b4873
84
-<unknown>
83
EOF
84
85
test_format subject %s <<'EOF'
@@ -93,9 +91,7 @@ EOF
91
92
test_format body %b <<'EOF'
93
commit 131a310eb913d107dd3c09a65d1651175898735d
96
-<unknown>
94
commit 86c75cfd708a0e5868dc876ed5b8bb66c80b4873
98
-<unknown>
95
EOF
96
97
test_format colors %Credfoo%Cgreenbar%Cbluebaz%Cresetxyzzy <<'EOF'
@@ -121,9 +117,7 @@ test_format complex-encoding %e <<'EOF'
117
commit f58db70b055c5718631e5c61528b28b12090cdea
118
iso8859-1
119
commit 131a310eb913d107dd3c09a65d1651175898735d
124
-<unknown>
120
commit 86c75cfd708a0e5868dc876ed5b8bb66c80b4873
126
-<unknown>
121
EOF
122
123
test_format complex-subject %s <<'EOF'
@@ -142,9 +136,7 @@ and it will be encoded in iso8859-1. We should therefore
136
include an iso8859 character: ¡bueno!
137
138
commit 131a310eb913d107dd3c09a65d1651175898735d
145
-<unknown>
139
commit 86c75cfd708a0e5868dc876ed5b8bb66c80b4873
147
-<unknown>
140
EOF
141
142
test_done
t/t7500-commit.sh
+2
-2
@@ -81,7 +81,7 @@ test_expect_success 'explicit commit message should override template' '
81
git add foo &&
82
GIT_EDITOR=../t7500/add-content git commit --template "$TEMPLATE" \
83
-m "command line msg" &&
84
- commit_msg_is "command line msg<unknown>"
84
+ commit_msg_is "command line msg"
85
'
86
87
test_expect_success 'commit message from file should override template' '
@@ -90,7 +90,7 @@ test_expect_success 'commit message from file should override template' '
90
echo "standard input msg" |
91
GIT_EDITOR=../t7500/add-content git commit \
92
--template "$TEMPLATE" --file - &&
93
- commit_msg_is "standard input msg<unknown>"
93
+ commit_msg_is "standard input msg"
94
'
95
96
test_done