Skip to content

Commit 5c3894c

Browse files
peffgitster
authored andcommitted
shortlog: match both "Author:" and "author" on stdin
The original git-shortlog could read both the normal "git log" output as well as "git log --format=raw". However, when it was converted to C by b8ec592 (Build in shortlog, 2006-10-22), the trailing colon became mandatory, and we no longer matched the raw output. Given the amount of intervening time without any bug reports, it's probable that nobody cares. But it's relatively easy to fix, and the end result is hopefully more readable than the original. Note that this no longer matches "author: ", which we did before, but that has never been a format generated by git. Signed-off-by: Jeff King <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 7548842 commit 5c3894c

File tree

2 files changed

+10
-3
lines changed

2 files changed

+10
-3
lines changed

builtin/shortlog.c

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -94,16 +94,17 @@ static void read_from_stdin(struct shortlog *log)
9494
char author[1024], oneline[1024];
9595

9696
while (fgets(author, sizeof(author), stdin) != NULL) {
97-
if (!(author[0] == 'A' || author[0] == 'a') ||
98-
!starts_with(author + 1, "uthor: "))
97+
const char *v;
98+
if (!skip_prefix(author, "Author: ", &v) &&
99+
!skip_prefix(author, "author ", &v))
99100
continue;
100101
while (fgets(oneline, sizeof(oneline), stdin) &&
101102
oneline[0] != '\n')
102103
; /* discard headers */
103104
while (fgets(oneline, sizeof(oneline), stdin) &&
104105
oneline[0] == '\n')
105106
; /* discard blanks */
106-
insert_one_record(log, author + 8, oneline);
107+
insert_one_record(log, v, oneline);
107108
}
108109
}
109110

t/t4201-shortlog.sh

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -120,6 +120,12 @@ test_expect_success !MINGW 'shortlog from non-git directory' '
120120
test_cmp expect out
121121
'
122122

123+
test_expect_success !MINGW 'shortlog can read --format=raw output' '
124+
git log --format=raw HEAD >log &&
125+
GIT_DIR=non-existing git shortlog -w <log >out &&
126+
test_cmp expect out
127+
'
128+
123129
test_expect_success 'shortlog should add newline when input line matches wraplen' '
124130
cat >expect <<\EOF &&
125131
A U Thor (2):

0 commit comments

Comments
 (0)