From 3714e7c8950681b440508244a1fcf5899a1b0966 Mon Sep 17 00:00:00 2001 From: Johannes Schindelin Date: Fri, 22 Dec 2006 22:15:59 +0100 Subject: 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 Signed-off-by: Junio C Hamano --- builtin-shortlog.c | 11 ++++++++--- t/t4201-shortlog.sh | 50 ++++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 58 insertions(+), 3 deletions(-) create mode 100644 t/t4201-shortlog.sh diff --git a/builtin-shortlog.c b/builtin-shortlog.c index 29343aefc8..2cdd528967 100644 --- a/builtin-shortlog.c +++ b/builtin-shortlog.c @@ -4,6 +4,7 @@ #include "diff.h" #include "path-list.h" #include "revision.h" +#include "utf8.h" static const char shortlog_usage[] = "git-shortlog [-n] [-s] [... ]"; @@ -323,9 +324,13 @@ int cmd_shortlog(int argc, const char **argv, const char *prefix) printf("%s: %d\n", list.items[i].path, onelines->nr); } else { printf("%s (%d):\n", list.items[i].path, onelines->nr); - for (j = onelines->nr - 1; j >= 0; j--) - printf(" %s\n", onelines->items[j].path); - printf("\n"); + for (j = onelines->nr - 1; j >= 0; j--) { + int col = print_wrapped_text(onelines->items[j].path, + 6, 9, 76); + if (col != 76) + putchar('\n'); + } + putchar('\n'); } onelines->strdup_paths = 1; diff --git a/t/t4201-shortlog.sh b/t/t4201-shortlog.sh new file mode 100644 index 0000000000..ab8a0888f6 --- /dev/null +++ b/t/t4201-shortlog.sh @@ -0,0 +1,50 @@ +#!/bin/sh +# +# Copyright (c) 2006 Johannes E. Schindelin +# + +test_description='git-shortlog +' + +. ./test-lib.sh + +echo 1 > a1 +git add a1 +tree=$(git write-tree) +commit=$((echo "Test"; echo) | git commit-tree $tree) +git update-ref HEAD $commit + +echo 2 > a1 +git commit -m "This is a very, very long first line for the commit message to see if it is wrapped correctly" a1 + +# test if the wrapping is still valid when replacing all i's by treble clefs. +echo 3 > a1 +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 + +# now fsck up the utf8 +git repo-config i18n.commitencoding non-utf-8 +echo 4 > a1 +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 + +echo 5 > a1 +git commit -m "a 12 34 56 78" a1 + +git shortlog HEAD > out + +cat > expect << EOF +A U Thor (5): + Test + This is a very, very long first line for the commit message to see if + it is wrapped correctly + Th๐„žs ๐„žs a very, very long f๐„žrst l๐„žne for the comm๐„žt message to see ๐„žf + ๐„žt ๐„žs wrapped correctly + Th๘„žs ๘„žs a very, very long f๘„žrst l๘„žne for the comm๘„žt + message to see ๘„žf ๘„žt ๘„žs wrapped correctly + a 12 34 + 56 78 + +EOF + +test_expect_success 'shortlog wrapping' 'diff -u expect out' + +test_done -- cgit v1.2.1 From 3d711d97a0db41633a5137e47358cf503b91b074 Mon Sep 17 00:00:00 2001 From: Junio C Hamano Date: Sun, 8 Apr 2007 01:28:00 -0700 Subject: shortlog -w: make wrap-line behaviour optional. Signed-off-by: Junio C Hamano --- builtin-shortlog.c | 70 ++++++++++++++++++++++++++++++++++++++++++++++++++--- t/t4201-shortlog.sh | 2 +- 2 files changed, 67 insertions(+), 5 deletions(-) diff --git a/builtin-shortlog.c b/builtin-shortlog.c index 2cdd528967..3f93498bb7 100644 --- a/builtin-shortlog.c +++ b/builtin-shortlog.c @@ -277,11 +277,64 @@ static void get_from_rev(struct rev_info *rev, struct path_list *list) } +static int parse_uint(char const **arg, int comma) +{ + unsigned long ul; + int ret; + char *endp; + + ul = strtoul(*arg, &endp, 10); + if (endp != *arg && *endp && *endp != comma) + return -1; + ret = (int) ul; + if (ret != ul) + return -1; + *arg = endp; + if (**arg) + (*arg)++; + return ret; +} + +static const char wrap_arg_usage[] = "-w[[,[,]]]"; +#define DEFAULT_WRAPLEN 76 +#define DEFAULT_INDENT1 6 +#define DEFAULT_INDENT2 9 + +static void parse_wrap_args(const char *arg, int *in1, int *in2, int *wrap) +{ + arg += 2; /* skip -w */ + + *wrap = parse_uint(&arg, ','); + if (*wrap < 0) + die(wrap_arg_usage); + *in1 = parse_uint(&arg, ','); + if (*in1 < 0) + die(wrap_arg_usage); + *in2 = parse_uint(&arg, '\0'); + if (*in2 < 0) + die(wrap_arg_usage); + + if (!*wrap) + *wrap = DEFAULT_WRAPLEN; + if (!*in1) + *in1 = DEFAULT_INDENT1; + if (!*in2) + *in2 = DEFAULT_INDENT2; + if (*wrap && + ((*in1 && *wrap <= *in1) || + (*in2 && *wrap <= *in2))) + die(wrap_arg_usage); +} + int cmd_shortlog(int argc, const char **argv, const char *prefix) { struct rev_info rev; struct path_list list = { NULL, 0, 0, 1 }; int i, j, sort_by_number = 0, summary = 0; + int wrap_lines = 0; + int wrap = DEFAULT_WRAPLEN; + int in1 = DEFAULT_INDENT1; + int in2 = DEFAULT_INDENT2; /* since -n is a shadowed rev argument, parse our args first */ while (argc > 1) { @@ -290,6 +343,10 @@ int cmd_shortlog(int argc, const char **argv, const char *prefix) else if (!strcmp(argv[1], "-s") || !strcmp(argv[1], "--summary")) summary = 1; + else if (!prefixcmp(argv[1], "-w")) { + wrap_lines = 1; + parse_wrap_args(argv[1], &in1, &in2, &wrap); + } else if (!strcmp(argv[1], "-h") || !strcmp(argv[1], "--help")) usage(shortlog_usage); else @@ -325,10 +382,15 @@ int cmd_shortlog(int argc, const char **argv, const char *prefix) } else { printf("%s (%d):\n", list.items[i].path, onelines->nr); for (j = onelines->nr - 1; j >= 0; j--) { - int col = print_wrapped_text(onelines->items[j].path, - 6, 9, 76); - if (col != 76) - putchar('\n'); + const char *msg = onelines->items[j].path; + + if (wrap_lines) { + int col = print_wrapped_text(msg, in1, in2, wrap); + if (col != wrap) + putchar('\n'); + } + else + printf(" %s\n", msg); } putchar('\n'); } diff --git a/t/t4201-shortlog.sh b/t/t4201-shortlog.sh index ab8a0888f6..321429c8fa 100644 --- a/t/t4201-shortlog.sh +++ b/t/t4201-shortlog.sh @@ -29,7 +29,7 @@ git commit -m "$(echo "This is a very, very long first line for the commit messa echo 5 > a1 git commit -m "a 12 34 56 78" a1 -git shortlog HEAD > out +git shortlog -w HEAD > out cat > expect << EOF A U Thor (5): -- cgit v1.2.1 From 238128d88885b5d0f5a3e28d392362a9b267a03f Mon Sep 17 00:00:00 2001 From: Alex Riesen Date: Fri, 13 Apr 2007 22:13:10 +0200 Subject: Fix t4201: accidental arithmetic expansion instead of embedded subshell. It actually breaks here (dash as /bin/sh): t4201-shortlog.sh: 27: Syntax error: Missing '))' FATAL: Unexpected exit with code 2 Signed-off-by: Alex Riesen Signed-off-by: Junio C Hamano --- t/t4201-shortlog.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/t/t4201-shortlog.sh b/t/t4201-shortlog.sh index 321429c8fa..c27e39cb6f 100644 --- a/t/t4201-shortlog.sh +++ b/t/t4201-shortlog.sh @@ -11,7 +11,7 @@ test_description='git-shortlog echo 1 > a1 git add a1 tree=$(git write-tree) -commit=$((echo "Test"; echo) | git commit-tree $tree) +commit=$( (echo "Test"; echo) | git commit-tree $tree ) git update-ref HEAD $commit echo 2 > a1 -- cgit v1.2.1 From 4848509a970e5c805a06fdba12c3377472308443 Mon Sep 17 00:00:00 2001 From: Alex Riesen Date: Fri, 13 Apr 2007 22:13:51 +0200 Subject: Fix permissions on test scripts Make every test executable. Remove exec-attribute from included shell files, they can't used standalone anyway. Signed-off-by: Alex Riesen Signed-off-by: Junio C Hamano --- t/diff-lib.sh | 0 t/lib-read-tree-m-3way.sh | 0 t/t4201-shortlog.sh | 0 t/t6023-merge-file.sh | 0 t/t6024-recursive-merge.sh | 0 t/t6025-merge-symlinks.sh | 0 t/test-lib.sh | 0 7 files changed, 0 insertions(+), 0 deletions(-) mode change 100755 => 100644 t/diff-lib.sh mode change 100755 => 100644 t/lib-read-tree-m-3way.sh mode change 100644 => 100755 t/t4201-shortlog.sh mode change 100644 => 100755 t/t6023-merge-file.sh mode change 100644 => 100755 t/t6024-recursive-merge.sh mode change 100644 => 100755 t/t6025-merge-symlinks.sh mode change 100755 => 100644 t/test-lib.sh diff --git a/t/diff-lib.sh b/t/diff-lib.sh old mode 100755 new mode 100644 diff --git a/t/lib-read-tree-m-3way.sh b/t/lib-read-tree-m-3way.sh old mode 100755 new mode 100644 diff --git a/t/t4201-shortlog.sh b/t/t4201-shortlog.sh old mode 100644 new mode 100755 diff --git a/t/t6023-merge-file.sh b/t/t6023-merge-file.sh old mode 100644 new mode 100755 diff --git a/t/t6024-recursive-merge.sh b/t/t6024-recursive-merge.sh old mode 100644 new mode 100755 diff --git a/t/t6025-merge-symlinks.sh b/t/t6025-merge-symlinks.sh old mode 100644 new mode 100755 diff --git a/t/test-lib.sh b/t/test-lib.sh old mode 100755 new mode 100644 -- cgit v1.2.1