Skip to content

Commit dda8f4b

Browse files
committed
Merge branch 'uk/maint-shortlog-encoding' into maint
* uk/maint-shortlog-encoding: t4201: use ISO8859-1 rather than ISO-8859-1 shortlog: respect commit encoding
2 parents c8b1d76 + 3994e8a commit dda8f4b

File tree

2 files changed

+39
-9
lines changed

2 files changed

+39
-9
lines changed

builtin-shortlog.c

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -139,8 +139,12 @@ static void read_from_stdin(struct shortlog *log)
139139
void shortlog_add_commit(struct shortlog *log, struct commit *commit)
140140
{
141141
const char *author = NULL, *buffer;
142+
struct strbuf buf = STRBUF_INIT;
143+
struct strbuf ufbuf = STRBUF_INIT;
142144

143-
buffer = commit->buffer;
145+
pretty_print_commit(CMIT_FMT_RAW, commit, &buf,
146+
0, NULL, NULL, DATE_NORMAL, 0);
147+
buffer = buf.buf;
144148
while (*buffer && *buffer != '\n') {
145149
const char *eol = strchr(buffer, '\n');
146150

@@ -157,17 +161,15 @@ void shortlog_add_commit(struct shortlog *log, struct commit *commit)
157161
die("Missing author: %s",
158162
sha1_to_hex(commit->object.sha1));
159163
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,
163165
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) {
169168
buffer++;
169+
}
170170
insert_one_record(log, author, !*buffer ? "<none>" : buffer);
171+
strbuf_release(&ufbuf);
172+
strbuf_release(&buf);
171173
}
172174

173175
static void get_from_rev(struct rev_info *rev, struct shortlog *log)

t/t4201-shortlog.sh

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,4 +52,32 @@ GIT_DIR=non-existing git shortlog -w < log > out
5252

5353
test_expect_success 'shortlog from non-git directory' 'test_cmp expect out'
5454

55+
iconvfromutf8toiso88591() {
56+
printf "%s" "$*" | iconv -f UTF-8 -t ISO8859-1
57+
}
58+
59+
DSCHO="Jöhännës \"Dschö\" Schindëlin"
60+
DSCHOE="$DSCHO <[email protected]>"
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 "ISO8859-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+
5583
test_done

0 commit comments

Comments
 (0)