Skip to content

Commit aa36985

Browse files
author
Junio C Hamano
committed
Merge branch 'js/wrap-log'
* js/wrap-log: Fix permissions on test scripts Fix t4201: accidental arithmetic expansion shortlog -w: make wrap-line behaviour optional. Use print_wrapped_text() in shortlog
2 parents f06a6a4 + 4848509 commit aa36985

File tree

8 files changed

+120
-3
lines changed

8 files changed

+120
-3
lines changed

builtin-shortlog.c

Lines changed: 70 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>... ]";
@@ -276,11 +277,64 @@ static void get_from_rev(struct rev_info *rev, struct path_list *list)
276277

277278
}
278279

280+
static int parse_uint(char const **arg, int comma)
281+
{
282+
unsigned long ul;
283+
int ret;
284+
char *endp;
285+
286+
ul = strtoul(*arg, &endp, 10);
287+
if (endp != *arg && *endp && *endp != comma)
288+
return -1;
289+
ret = (int) ul;
290+
if (ret != ul)
291+
return -1;
292+
*arg = endp;
293+
if (**arg)
294+
(*arg)++;
295+
return ret;
296+
}
297+
298+
static const char wrap_arg_usage[] = "-w[<width>[,<indent1>[,<indent2>]]]";
299+
#define DEFAULT_WRAPLEN 76
300+
#define DEFAULT_INDENT1 6
301+
#define DEFAULT_INDENT2 9
302+
303+
static void parse_wrap_args(const char *arg, int *in1, int *in2, int *wrap)
304+
{
305+
arg += 2; /* skip -w */
306+
307+
*wrap = parse_uint(&arg, ',');
308+
if (*wrap < 0)
309+
die(wrap_arg_usage);
310+
*in1 = parse_uint(&arg, ',');
311+
if (*in1 < 0)
312+
die(wrap_arg_usage);
313+
*in2 = parse_uint(&arg, '\0');
314+
if (*in2 < 0)
315+
die(wrap_arg_usage);
316+
317+
if (!*wrap)
318+
*wrap = DEFAULT_WRAPLEN;
319+
if (!*in1)
320+
*in1 = DEFAULT_INDENT1;
321+
if (!*in2)
322+
*in2 = DEFAULT_INDENT2;
323+
if (*wrap &&
324+
((*in1 && *wrap <= *in1) ||
325+
(*in2 && *wrap <= *in2)))
326+
die(wrap_arg_usage);
327+
}
328+
279329
int cmd_shortlog(int argc, const char **argv, const char *prefix)
280330
{
281331
struct rev_info rev;
282332
struct path_list list = { NULL, 0, 0, 1 };
283333
int i, j, sort_by_number = 0, summary = 0;
334+
int wrap_lines = 0;
335+
int wrap = DEFAULT_WRAPLEN;
336+
int in1 = DEFAULT_INDENT1;
337+
int in2 = DEFAULT_INDENT2;
284338

285339
/* since -n is a shadowed rev argument, parse our args first */
286340
while (argc > 1) {
@@ -289,6 +343,10 @@ int cmd_shortlog(int argc, const char **argv, const char *prefix)
289343
else if (!strcmp(argv[1], "-s") ||
290344
!strcmp(argv[1], "--summary"))
291345
summary = 1;
346+
else if (!prefixcmp(argv[1], "-w")) {
347+
wrap_lines = 1;
348+
parse_wrap_args(argv[1], &in1, &in2, &wrap);
349+
}
292350
else if (!strcmp(argv[1], "-h") || !strcmp(argv[1], "--help"))
293351
usage(shortlog_usage);
294352
else
@@ -323,9 +381,18 @@ int cmd_shortlog(int argc, const char **argv, const char *prefix)
323381
printf("%s: %d\n", list.items[i].path, onelines->nr);
324382
} else {
325383
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");
384+
for (j = onelines->nr - 1; j >= 0; j--) {
385+
const char *msg = onelines->items[j].path;
386+
387+
if (wrap_lines) {
388+
int col = print_wrapped_text(msg, in1, in2, wrap);
389+
if (col != wrap)
390+
putchar('\n');
391+
}
392+
else
393+
printf(" %s\n", msg);
394+
}
395+
putchar('\n');
329396
}
330397

331398
onelines->strdup_paths = 1;

t/diff-lib.sh

100755100644
File mode changed.

t/lib-read-tree-m-3way.sh

100755100644
File mode changed.

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 -w 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

t/t6023-merge-file.sh

100644100755
File mode changed.

t/t6024-recursive-merge.sh

100644100755
File mode changed.

t/t6025-merge-symlinks.sh

100644100755
File mode changed.

t/test-lib.sh

100755100644
File mode changed.

0 commit comments

Comments
 (0)