@matheusbsbs / matheus-bagliano / commits / f95673849c
Fork 0

Apply mailmap in git-blame output.

This makes git-blame to use the same mailmap used by git-shortlog. Signed-off-by: Junio C Hamano <junkio@cox.net>

Junio C Hamano committed Apr 27, 2007 at 00:42 UTC f95673849c99baf3b10756e944d6ebe22394a2c0
1 file changed +39 -3
builtin-blame.c
+39 -3
@@ -16,14 +16,17 @@
16 #include "quote.h"
17 #include "xdiff-interface.h"
18 #include "cache-tree.h"
19 +#include "path-list.h"
20 +#include "mailmap.h"
21
22 static char blame_usage[] =
21 -"git-blame [-c] [-b] [-l] [--root] [-t] [-f] [-n] [-s] [-p] [-L n,m] [-S <revs-file>] [-M] [-C] [-C] [--contents <filename>] [--incremental] [commit] [--] file\n"
23 +"git-blame [-c] [-b] [-l] [--root] [-x] [-t] [-f] [-n] [-s] [-p] [-L n,m] [-S <revs-file>] [-M] [-C] [-C] [--contents <filename>] [--incremental] [commit] [--] file\n"
24 " -c Use the same output mode as git-annotate (Default: off)\n"
25 " -b Show blank SHA-1 for boundary commits (Default: off)\n"
26 " -l Show long commit SHA1 (Default: off)\n"
27 " --root Do not treat root commits as boundaries (Default: off)\n"
28 " -t Show raw timestamp (Default: off)\n"
29 +" -x Do not use .mailmap file\n"
30 " -f, --show-name Show original filename (Default: auto)\n"
31 " -n, --show-number Show original linenumber (Default: off)\n"
32 " -s Suppress author name and timestamp (Default: off)\n"
@@ -43,6 +46,8 @@ static int show_root;
46 static int blank_boundary;
47 static int incremental;
48 static int cmd_is_annotate;
49 +static int no_mailmap;
50 +static struct path_list mailmap;
51
52 #ifndef DEBUG
53 #define DEBUG 0
@@ -1265,8 +1270,8 @@ static void get_ac_line(const char *inbuf, const char *what,
1270 int bufsz, char *person, const char **mail,
1271 unsigned long *time, const char **tz)
1272 {
1268 - int len;
1269 - char *tmp, *endp;
1273 + int len, tzlen, maillen;
1274 + char *tmp, *endp, *timepos;
1275
1276 tmp = strstr(inbuf, what);
1277 if (!tmp)
@@ -1292,17 +1297,42 @@ static void get_ac_line(const char *inbuf, const char *what,
1297 while (*tmp != ' ')
1298 tmp--;
1299 *tz = tmp+1;
1300 + tzlen = (person+len)-(tmp+1);
1301
1302 *tmp = 0;
1303 while (*tmp != ' ')
1304 tmp--;
1305 *time = strtoul(tmp, NULL, 10);
1306 + timepos = tmp;
1307
1308 *tmp = 0;
1309 while (*tmp != ' ')
1310 tmp--;
1311 *mail = tmp + 1;
1312 *tmp = 0;
1313 + maillen = timepos - tmp;
1314 +
1315 + if (!mailmap.nr)
1316 + return;
1317 +
1318 + /*
1319 + * mailmap expansion may make the name longer.
1320 + * make room by pushing stuff down.
1321 + */
1322 + tmp = person + bufsz - (tzlen + 1);
1323 + memmove(tmp, *tz, tzlen);
1324 + tmp[tzlen] = 0;
1325 + *tz = tmp;
1326 +
1327 + tmp = tmp - (maillen + 1);
1328 + memmove(tmp, *mail, maillen);
1329 + tmp[maillen] = 0;
1330 + *mail = tmp;
1331 +
1332 + /*
1333 + * Now, convert e-mail using mailmap
1334 + */
1335 + map_email(&mailmap, tmp + 1, person, tmp-person-1);
1336 }
1337
1338 static void get_commit_info(struct commit *commit,
@@ -2143,6 +2173,9 @@ int cmd_blame(int argc, const char **argv, const char *prefix)
2173 else if (!strcmp("-p", arg) ||
2174 !strcmp("--porcelain", arg))
2175 output_option |= OUTPUT_PORCELAIN;
2176 + else if (!strcmp("-x", arg) ||
2177 + !strcmp("--no-mailmap", arg))
2178 + no_mailmap = 1;
2179 else if (!strcmp("--", arg)) {
2180 seen_dashdash = 1;
2181 i++;
@@ -2342,6 +2375,9 @@ int cmd_blame(int argc, const char **argv, const char *prefix)
2375 die("reading graft file %s failed: %s",
2376 revs_file, strerror(errno));
2377
2378 + if (!no_mailmap && !access(".mailmap", R_OK))
2379 + read_mailmap(&mailmap, ".mailmap", NULL);
2380 +
2381 assign_blame(&sb, &revs, opt);
2382
2383 if (incremental)