Skip to content

Commit

Permalink
Fix author ident cache being keyed by email only
Browse files Browse the repository at this point in the history
This addresses the issue where an author name change "wins" and tig
shows it for all historical commits by same email under old names

Addresses jonas#526 , jonas/tig/jonas#424
  • Loading branch information
Mina Naguib committed Nov 28, 2016
1 parent c3ffa59 commit 065fd45
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 4 deletions.
1 change: 1 addition & 0 deletions include/tig/util.h
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@ struct time {
};

struct ident {
const char *key;
const char *name;
const char *email;
};
Expand Down
14 changes: 10 additions & 4 deletions src/parse.c
Original file line number Diff line number Diff line change
Expand Up @@ -267,25 +267,31 @@ get_path(const char *path)
return entry->path;
}

DEFINE_STRING_MAP(author_cache, const struct ident *, email, 32)
DEFINE_STRING_MAP(author_cache, const struct ident *, key, 32)

/* Small author cache to reduce memory consumption. No entries
* are ever freed. */
struct ident *
get_author(const char *name, const char *email)
{
struct ident *ident = string_map_get(&author_cache, email);
char key[SIZEOF_STR + SIZEOF_STR];
struct ident *ident;

string_format(key, "%s%s", email, name);

ident = string_map_get(&author_cache, key);
if (ident)
return ident;

ident = calloc(1, sizeof(*ident));
if (!ident)
return NULL;
ident->key = strdup(key);
ident->name = strdup(name);
ident->email = strdup(email);
if (!ident->name || !ident->email ||
!string_map_put(&author_cache, email, ident)) {
if (!ident->key || !ident->name || !ident->email ||
!string_map_put(&author_cache, key, ident)) {
free((void *) ident->key);
free((void *) ident->name);
free((void *) ident->email);
free(ident);
Expand Down

0 comments on commit 065fd45

Please sign in to comment.