@matheusbsbs / matheus-bagliano / commits / 7595e2ee6e
Fork 0

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>

Junio C Hamano committed Nov 25, 2006 at 00:07 UTC 7595e2ee6ef9b35ebc8dc45543723e1d89765ce3
2 files changed +24 -2
builtin-shortlog.c
+22 -2
@@ -9,6 +9,8 @@
9 static const char shortlog_usage[] =
10 "git-shortlog [-n] [-s] [<commit-id>... ]";
11
12 +static char *common_repo_prefix;
13 +
14 static int compare_by_number(const void *a1, const void *a2)
15 {
16 const struct path_list_item *i1 = a1, *i2 = a2;
@@ -35,8 +37,26 @@ static int read_mailmap(const char *filename)
37 char *end_of_name, *left_bracket, *right_bracket;
38 char *name, *email;
39 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 + }
58 continue;
59 + }
60 if ((left_bracket = strchr(buffer, '<')) == NULL)
61 continue;
62 if ((right_bracket = strchr(left_bracket + 1, '>')) == NULL)
@@ -87,7 +107,7 @@ static void insert_author_oneline(struct path_list *list,
107 const char *author, int authorlen,
108 const char *oneline, int onelinelen)
109 {
90 - const char *dot3 = "/pub/scm/linux/kernel/git/";
110 + const char *dot3 = common_repo_prefix;
111 char *buffer, *p;
112 struct path_list_item *item;
113 struct path_list *onelines;
contrib/mailmap.linux
+2
@@ -3,6 +3,8 @@
3 # So have an email->real name table to translate the
4 # (hopefully few) missing names
5 #
6 +# repo-abbrev: /pub/scm/linux/kernel/git/
7 +#
8 Adrian Bunk <bunk@stusta.de>
9 Andreas Herrmann <aherrman@de.ibm.com>
10 Andrew Morton <akpm@osdl.org>