From: Junio C Hamano Date: Mon, 21 Jan 2013 01:06:52 +0000 (-0800) Subject: Merge branch 'ap/log-mailmap' X-Git-Tag: v1.8.2-rc0~112 X-Git-Url: http://git.osdn.net/view?a=commitdiff_plain;h=577f63e781d2f9b9a6862389b6e9d2ca2467afa2;p=git-core%2Fgit.git Merge branch 'ap/log-mailmap' Teach commands in the "log" family to optionally pay attention to the mailmap. * ap/log-mailmap: log --use-mailmap: optimize for cases without --author/--committer search log: add log.mailmap configuration option log: grep author/committer using mailmap test: add test for --use-mailmap option log: add --use-mailmap option pretty: use mailmap to display username and email mailmap: add mailmap structure to rev_info and pp mailmap: simplify map_user() interface mailmap: remove email copy and length limitation Use split_ident_line to parse author and committer string-list: allow case-insensitive string list --- 577f63e781d2f9b9a6862389b6e9d2ca2467afa2 diff --cc commit.h index 0f469e507,7f8f9878d..c16c8a753 --- a/commit.h +++ b/commit.h @@@ -89,7 -89,7 +89,8 @@@ struct pretty_print_context char *notes_message; struct reflog_walk_info *reflog_info; const char *output_encoding; + struct string_list *mailmap; + int color; }; struct userformat_want { diff --cc log-tree.c index f8487f8a8,92254fd49..5dc45c481 --- a/log-tree.c +++ b/log-tree.c @@@ -681,7 -671,7 +681,8 @@@ void show_log(struct rev_info *opt ctx.preserve_subject = opt->preserve_subject; ctx.reflog_info = opt->reflog_info; ctx.fmt = opt->commit_format; + ctx.mailmap = opt->mailmap; + ctx.color = opt->diffopt.use_color; pretty_print_commit(&ctx, commit, &msgbuf); if (opt->add_signoff) diff --cc mailmap.c index b16542feb,743dbdae2..2a7b36628 --- a/mailmap.c +++ b/mailmap.c @@@ -187,62 -171,13 +187,63 @@@ static int read_mailmap_file(struct str return 0; } +static void read_mailmap_buf(struct string_list *map, + const char *buf, unsigned long len, + char **repo_abbrev) +{ + while (len) { + const char *end = strchrnul(buf, '\n'); + unsigned long linelen = end - buf + 1; + char *line = xmemdupz(buf, linelen); + + read_mailmap_line(map, line, repo_abbrev); + + free(line); + buf += linelen; + len -= linelen; + } +} + +static int read_mailmap_blob(struct string_list *map, + const char *name, + char **repo_abbrev) +{ + unsigned char sha1[20]; + char *buf; + unsigned long size; + enum object_type type; + + if (!name) + return 0; + if (get_sha1(name, sha1) < 0) + return 0; + + buf = read_sha1_file(sha1, &type, &size); + if (!buf) + return error("unable to read mailmap object at %s", name); + if (type != OBJ_BLOB) + return error("mailmap is not a blob: %s", name); + + read_mailmap_buf(map, buf, size, repo_abbrev); + + free(buf); + return 0; +} + int read_mailmap(struct string_list *map, char **repo_abbrev) { + int err = 0; + map->strdup_strings = 1; + map->cmp = strcasecmp; - /* each failure returns 1, so >1 means both calls failed */ - return read_single_mailmap(map, ".mailmap", repo_abbrev) + - read_single_mailmap(map, git_mailmap_file, repo_abbrev) > 1; + + if (!git_mailmap_blob && is_bare_repository()) + git_mailmap_blob = "HEAD:.mailmap"; + + err |= read_mailmap_file(map, ".mailmap", repo_abbrev); + err |= read_mailmap_blob(map, git_mailmap_blob, repo_abbrev); + err |= read_mailmap_file(map, git_mailmap_file, repo_abbrev); + return err; } void clear_mailmap(struct string_list *map)