Skip to content

Commit 3714e7c

Browse files
dschoJunio C Hamano
authored andcommitted
Use print_wrapped_text() in shortlog
Some oneline descriptions are just too long. In shortlog, it looks much nicer when they are wrapped. Since print_wrapped_text() is UTF-8 aware, it also works with those descriptions. [jc: with minimum fixes] Signed-off-by: Johannes Schindelin <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 8ff21b1 commit 3714e7c

File tree

2 files changed

+58
-3
lines changed

2 files changed

+58
-3
lines changed

builtin-shortlog.c

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
#include "diff.h"
55
#include "path-list.h"
66
#include "revision.h"
7+
#include "utf8.h"
78

89
static const char shortlog_usage[] =
910
"git-shortlog [-n] [-s] [<commit-id>... ]";
@@ -323,9 +324,13 @@ int cmd_shortlog(int argc, const char **argv, const char *prefix)
323324
printf("%s: %d\n", list.items[i].path, onelines->nr);
324325
} else {
325326
printf("%s (%d):\n", list.items[i].path, onelines->nr);
326-
for (j = onelines->nr - 1; j >= 0; j--)
327-
printf(" %s\n", onelines->items[j].path);
328-
printf("\n");
327+
for (j = onelines->nr - 1; j >= 0; j--) {
328+
int col = print_wrapped_text(onelines->items[j].path,
329+
6, 9, 76);
330+
if (col != 76)
331+
putchar('\n');
332+
}
333+
putchar('\n');
329334
}
330335

331336
onelines->strdup_paths = 1;

t/t4201-shortlog.sh

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
#!/bin/sh
2+
#
3+
# Copyright (c) 2006 Johannes E. Schindelin
4+
#
5+
6+
test_description='git-shortlog
7+
'
8+
9+
. ./test-lib.sh
10+
11+
echo 1 > a1
12+
git add a1
13+
tree=$(git write-tree)
14+
commit=$((echo "Test"; echo) | git commit-tree $tree)
15+
git update-ref HEAD $commit
16+
17+
echo 2 > a1
18+
git commit -m "This is a very, very long first line for the commit message to see if it is wrapped correctly" a1
19+
20+
# test if the wrapping is still valid when replacing all i's by treble clefs.
21+
echo 3 > a1
22+
git commit -m "$(echo "This is a very, very long first line for the commit message to see if it is wrapped correctly" | sed "s/i/1234/g" | tr 1234 '\360\235\204\236')" a1
23+
24+
# now fsck up the utf8
25+
git repo-config i18n.commitencoding non-utf-8
26+
echo 4 > a1
27+
git commit -m "$(echo "This is a very, very long first line for the commit message to see if it is wrapped correctly" | sed "s/i/1234/g" | tr 1234 '\370\235\204\236')" a1
28+
29+
echo 5 > a1
30+
git commit -m "a 12 34 56 78" a1
31+
32+
git shortlog HEAD > out
33+
34+
cat > expect << EOF
35+
A U Thor (5):
36+
Test
37+
This is a very, very long first line for the commit message to see if
38+
it is wrapped correctly
39+
Th𝄞s 𝄞s a very, very long f𝄞rst l𝄞ne for the comm𝄞t message to see 𝄞f
40+
𝄞t 𝄞s wrapped correctly
41+
Thø„žs ø„žs a very, very long fø„žrst lø„žne for the commø„žt
42+
message to see ø„žf ø„žt ø„žs wrapped correctly
43+
a 12 34
44+
56 78
45+
46+
EOF
47+
48+
test_expect_success 'shortlog wrapping' 'diff -u expect out'
49+
50+
test_done

0 commit comments

Comments
 (0)