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
This commit is contained in:
Junio C Hamano 2007-04-16 16:53:29 -07:00
commit aa36985161
8 changed files with 120 additions and 3 deletions

View file

@ -4,6 +4,7 @@
#include "diff.h" #include "diff.h"
#include "path-list.h" #include "path-list.h"
#include "revision.h" #include "revision.h"
#include "utf8.h"
static const char shortlog_usage[] = static const char shortlog_usage[] =
"git-shortlog [-n] [-s] [<commit-id>... ]"; "git-shortlog [-n] [-s] [<commit-id>... ]";
@ -276,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[<width>[,<indent1>[,<indent2>]]]";
#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) int cmd_shortlog(int argc, const char **argv, const char *prefix)
{ {
struct rev_info rev; struct rev_info rev;
struct path_list list = { NULL, 0, 0, 1 }; struct path_list list = { NULL, 0, 0, 1 };
int i, j, sort_by_number = 0, summary = 0; 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 */ /* since -n is a shadowed rev argument, parse our args first */
while (argc > 1) { while (argc > 1) {
@ -289,6 +343,10 @@ int cmd_shortlog(int argc, const char **argv, const char *prefix)
else if (!strcmp(argv[1], "-s") || else if (!strcmp(argv[1], "-s") ||
!strcmp(argv[1], "--summary")) !strcmp(argv[1], "--summary"))
summary = 1; 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")) else if (!strcmp(argv[1], "-h") || !strcmp(argv[1], "--help"))
usage(shortlog_usage); usage(shortlog_usage);
else else
@ -323,9 +381,18 @@ int cmd_shortlog(int argc, const char **argv, const char *prefix)
printf("%s: %d\n", list.items[i].path, onelines->nr); printf("%s: %d\n", list.items[i].path, onelines->nr);
} else { } else {
printf("%s (%d):\n", list.items[i].path, onelines->nr); printf("%s (%d):\n", list.items[i].path, onelines->nr);
for (j = onelines->nr - 1; j >= 0; j--) for (j = onelines->nr - 1; j >= 0; j--) {
printf(" %s\n", onelines->items[j].path); const char *msg = onelines->items[j].path;
printf("\n");
if (wrap_lines) {
int col = print_wrapped_text(msg, in1, in2, wrap);
if (col != wrap)
putchar('\n');
}
else
printf(" %s\n", msg);
}
putchar('\n');
} }
onelines->strdup_paths = 1; onelines->strdup_paths = 1;

0
t/diff-lib.sh Executable file → Normal file
View file

0
t/lib-read-tree-m-3way.sh Executable file → Normal file
View file

50
t/t4201-shortlog.sh Executable file
View file

@ -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 -w 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ð<68>„žs ð<>„žs a very, very long fð<66>„žrst lð<6C>„žne for the commð<6D>„žt message to see ð<>„žf
ð<>„žt ð<>„žs wrapped correctly
Thø<68>„žs ø<>„žs a very, very long fø<66>„žrst lø<6C>„žne for the commø<6D>„ž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

0
t/t6023-merge-file.sh Normal file → Executable file
View file

0
t/t6024-recursive-merge.sh Normal file → Executable file
View file

0
t/t6025-merge-symlinks.sh Normal file → Executable file
View file

0
t/test-lib.sh Executable file → Normal file
View file