shortlog: respect commit encoding
Don't take the author name information without re-encoding from the raw commit object buffer. Signed-off-by: Uwe Kleine-König <u.kleine-koenig@pengutronix.de> Cc: Jiri Kosina <jkosina@suse.cz> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Uwe Kleine-König committed
Nov 25, 2009 at 20:33 UTC
79f7ca063d6b74e9d7f3db90c85dfa4a162128e4
2 files changed
+39
-9
builtin-shortlog.c
+11
-9
@@ -139,8 +139,12 @@ static void read_from_stdin(struct shortlog *log)
139
void shortlog_add_commit(struct shortlog *log, struct commit *commit)
140
{
141
const char *author = NULL, *buffer;
142
+ struct strbuf buf = STRBUF_INIT;
143
+ struct strbuf ufbuf = STRBUF_INIT;
144
143
- buffer = commit->buffer;
145
+ pretty_print_commit(CMIT_FMT_RAW, commit, &buf,
146
+ 0, NULL, NULL, DATE_NORMAL, 0);
147
+ buffer = buf.buf;
148
while (*buffer && *buffer != '\n') {
149
const char *eol = strchr(buffer, '\n');
150
@@ -157,17 +161,15 @@ void shortlog_add_commit(struct shortlog *log, struct commit *commit)
161
die("Missing author: %s",
162
sha1_to_hex(commit->object.sha1));
163
if (log->user_format) {
160
- struct strbuf buf = STRBUF_INIT;
161
-
162
- pretty_print_commit(CMIT_FMT_USERFORMAT, commit, &buf,
164
+ pretty_print_commit(CMIT_FMT_USERFORMAT, commit, &ufbuf,
165
DEFAULT_ABBREV, "", "", DATE_NORMAL, 0);
164
- insert_one_record(log, author, buf.buf);
165
- strbuf_release(&buf);
166
- return;
167
- }
168
- if (*buffer)
166
+ buffer = ufbuf.buf;
167
+ } else if (*buffer) {
168
buffer++;
169
+ }
170
insert_one_record(log, author, !*buffer ? "<none>" : buffer);
171
+ strbuf_release(&ufbuf);
172
+ strbuf_release(&buf);
173
}
174
175
static void get_from_rev(struct rev_info *rev, struct shortlog *log)
t/t4201-shortlog.sh
+28
@@ -52,4 +52,32 @@ GIT_DIR=non-existing git shortlog -w < log > out
52
53
test_expect_success 'shortlog from non-git directory' 'test_cmp expect out'
54
55
+iconvfromutf8toiso88591() {
56
+ printf "%s" "$*" | iconv -f UTF-8 -t ISO-8859-1
57
+}
58
+
59
+DSCHO="Jöhännës \"Dschö\" Schindëlin"
60
+DSCHOE="$DSCHO <Johannes.Schindelin@gmx.de>"
61
+MSG1="set a1 to 2 and some non-ASCII chars: Äßø"
62
+MSG2="set a1 to 3 and some non-ASCII chars: áæï"
63
+cat > expect << EOF
64
+$DSCHO (2):
65
+ $MSG1
66
+ $MSG2
67
+
68
+EOF
69
+
70
+test_expect_success 'shortlog encoding' '
71
+ git reset --hard "$commit" &&
72
+ git config --unset i18n.commitencoding &&
73
+ echo 2 > a1 &&
74
+ git commit --quiet -m "$MSG1" --author="$DSCHOE" a1 &&
75
+ git config i18n.commitencoding "ISO-8859-1" &&
76
+ echo 3 > a1 &&
77
+ git commit --quiet -m "$(iconvfromutf8toiso88591 "$MSG2")" \
78
+ --author="$(iconvfromutf8toiso88591 "$DSCHOE")" a1 &&
79
+ git config --unset i18n.commitencoding &&
80
+ git shortlog HEAD~2.. > out &&
81
+test_cmp expect out'
82
+
83
test_done