void clear_mailmap(struct string_list *map) { debug_mm("mailmap: clearing %d entries...\n", map->nr); map->strdup_strings = 1; string_list_clear_func(map, free_mailmap_entry); debug_mm("mailmap: cleared\n"); }
static void add_mapping(struct string_list *map, char *new_name, char *new_email, char *old_name, char *old_email) { struct mailmap_entry *me; int index; char *p; if (old_email) for (p = old_email; *p; p++) *p = tolower(*p); if (new_email) for (p = new_email; *p; p++) *p = tolower(*p); if (old_email == NULL) { old_email = new_email; new_email = NULL; } if ((index = string_list_find_insert_index(map, old_email, 1)) < 0) { /* mailmap entry exists, invert index value */ index = -1 - index; } else { /* create mailmap entry */ struct string_list_item *item = string_list_insert_at_index(map, index, old_email); item->util = xcalloc(1, sizeof(struct mailmap_entry)); ((struct mailmap_entry *)item->util)->namemap.strdup_strings = 1; } me = (struct mailmap_entry *)map->items[index].util; if (old_name == NULL) { debug_mm("mailmap: adding (simple) entry for %s at index %d\n", old_email, index); /* Replace current name and new email for simple entry */ if (new_name) { free(me->name); me->name = xstrdup(new_name); } if (new_email) { free(me->email); me->email = xstrdup(new_email); } } else { struct mailmap_info *mi = xcalloc(1, sizeof(struct mailmap_info)); debug_mm("mailmap: adding (complex) entry for %s at index %d\n", old_email, index); if (new_name) mi->name = xstrdup(new_name); if (new_email) mi->email = xstrdup(new_email); string_list_insert(&me->namemap, old_name)->util = mi; } debug_mm("mailmap: '%s' <%s> -> '%s' <%s>\n", old_name, old_email, new_name, new_email); }
static void free_mailmap_entry(void *p, const char *s) { struct mailmap_entry *me = (struct mailmap_entry *)p; debug_mm("mailmap: removing entries for <%s>, with %d sub-entries\n", s, me->namemap.nr); debug_mm("mailmap: - simple: '%s' <%s>\n", me->name, me->email); free(me->name); free(me->email); me->namemap.strdup_strings = 1; string_list_clear_func(&me->namemap, free_mailmap_info); }
static void add_mapping(struct string_list *map, char *new_name, char *new_email, char *old_name, char *old_email) { struct mailmap_entry *me; struct string_list_item *item; if (old_email == NULL) { old_email = new_email; new_email = NULL; } item = string_list_insert(map, old_email); if (item->util) { me = (struct mailmap_entry *)item->util; } else { me = xcalloc(1, sizeof(struct mailmap_entry)); me->namemap.strdup_strings = 1; me->namemap.cmp = namemap_cmp; item->util = me; } if (old_name == NULL) { debug_mm("mailmap: adding (simple) entry for '%s'\n", old_email); /* Replace current name and new email for simple entry */ if (new_name) { free(me->name); me->name = xstrdup(new_name); } if (new_email) { free(me->email); me->email = xstrdup(new_email); } } else { struct mailmap_info *mi = xcalloc(1, sizeof(struct mailmap_info)); debug_mm("mailmap: adding (complex) entry for '%s'\n", old_email); if (new_name) mi->name = xstrdup(new_name); if (new_email) mi->email = xstrdup(new_email); string_list_insert(&me->namemap, old_name)->util = mi; } debug_mm("mailmap: '%s' <%s> -> '%s' <%s>\n", debug_str(old_name), old_email, debug_str(new_name), debug_str(new_email)); }
int map_user(struct string_list *map, const char **email, size_t *emaillen, const char **name, size_t *namelen) { struct string_list_item *item; struct mailmap_entry *me; debug_mm("map_user: map '%.*s' <%.*s>\n", (int)*namelen, debug_str(*name), (int)*emaillen, debug_str(*email)); item = lookup_prefix(map, *email, *emaillen); if (item != NULL) { me = (struct mailmap_entry *)item->util; if (me->namemap.nr) { /* * The item has multiple items, so we'll look up on * name too. If the name is not found, we choose the * simple entry. */ struct string_list_item *subitem; subitem = lookup_prefix(&me->namemap, *name, *namelen); if (subitem) item = subitem; } } if (item != NULL) { struct mailmap_info *mi = (struct mailmap_info *)item->util; if (mi->name == NULL && mi->email == NULL) { debug_mm("map_user: -- (no simple mapping)\n"); return 0; } if (mi->email) { *email = mi->email; *emaillen = strlen(*email); } if (mi->name) { *name = mi->name; *namelen = strlen(*name); } debug_mm("map_user: to '%.*s' <%.*s>\n", (int)*namelen, debug_str(*name), (int)*emaillen, debug_str(*email)); return 1; } debug_mm("map_user: --\n"); return 0; }
static void free_mailmap_info(void *p, const char *s) { struct mailmap_info *mi = (struct mailmap_info *)p; debug_mm("mailmap: -- complex: '%s' -> '%s' <%s>\n", s, mi->name, mi->email); free(mi->name); free(mi->email); }