Skip to content

Commit 7595e2e

Browse files
author
Junio C Hamano
committed
git-shortlog: make common repository prefix configurable with .mailmap
The code had "/pub/scm/linux/kernel/git/" hardcoded which was too specific to the kernel project. With this, a line in the .mailmap file: # repo-abbrev: /pub/scm/linux/kernel/git/ can be used to cause the substring to be abbreviated to /.../ on the title line of the commit message. Signed-off-by: Junio C Hamano <junkio@cox.net>
1 parent c95044d commit 7595e2e

File tree

2 files changed

+24
-2
lines changed

2 files changed

+24
-2
lines changed

builtin-shortlog.c

Lines changed: 22 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@
99
static const char shortlog_usage[] =
1010
"git-shortlog [-n] [-s] [<commit-id>... ]";
1111

12+
static char *common_repo_prefix;
13+
1214
static int compare_by_number(const void *a1, const void *a2)
1315
{
1416
const struct path_list_item *i1 = a1, *i2 = a2;
@@ -35,8 +37,26 @@ static int read_mailmap(const char *filename)
3537
char *end_of_name, *left_bracket, *right_bracket;
3638
char *name, *email;
3739
int i;
38-
if (buffer[0] == '#')
40+
if (buffer[0] == '#') {
41+
static const char abbrev[] = "# repo-abbrev:";
42+
int abblen = sizeof(abbrev) - 1;
43+
int len = strlen(buffer);
44+
45+
if (len && buffer[len - 1] == '\n')
46+
buffer[--len] = 0;
47+
if (!strncmp(buffer, abbrev, abblen)) {
48+
char *cp;
49+
50+
if (common_repo_prefix)
51+
free(common_repo_prefix);
52+
common_repo_prefix = xmalloc(len);
53+
54+
for (cp = buffer + abblen; isspace(*cp); cp++)
55+
; /* nothing */
56+
strcpy(common_repo_prefix, cp);
57+
}
3958
continue;
59+
}
4060
if ((left_bracket = strchr(buffer, '<')) == NULL)
4161
continue;
4262
if ((right_bracket = strchr(left_bracket + 1, '>')) == NULL)
@@ -87,7 +107,7 @@ static void insert_author_oneline(struct path_list *list,
87107
const char *author, int authorlen,
88108
const char *oneline, int onelinelen)
89109
{
90-
const char *dot3 = "/pub/scm/linux/kernel/git/";
110+
const char *dot3 = common_repo_prefix;
91111
char *buffer, *p;
92112
struct path_list_item *item;
93113
struct path_list *onelines;

contrib/mailmap.linux

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@
33
# So have an email->real name table to translate the
44
# (hopefully few) missing names
55
#
6+
# repo-abbrev: /pub/scm/linux/kernel/git/
7+
#
68
Adrian Bunk <bunk@stusta.de>
79
Andreas Herrmann <aherrman@de.ibm.com>
810
Andrew Morton <akpm@osdl.org>

0 commit comments

Comments
 (0)