const char *find_descendant_ref(const char *dirname, const struct string_list *extras, const struct string_list *skip) { int pos; if (!extras) return NULL; /* * Look at the place where dirname would be inserted into * extras. If there is an entry at that position that starts * with dirname (remember, dirname includes the trailing * slash) and is not in skip, then we have a conflict. */ for (pos = string_list_find_insert_index(extras, dirname, 0); pos < extras->nr; pos++) { const char *extra_refname = extras->items[pos].string; if (!starts_with(extra_refname, dirname)) break; if (!skip || !string_list_has_string(skip, extra_refname)) return extra_refname; } return NULL; }
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); }
/* * Look for an entry in map that match string[0:len]; string[len] * does not have to be NUL (but it could be). */ static struct string_list_item *lookup_prefix(struct string_list *map, const char *string, size_t len) { int i = string_list_find_insert_index(map, string, 1); if (i < 0) { /* exact match */ i = -1 - i; if (!string[len]) return &map->items[i]; /* * that map entry matches exactly to the string, including * the cruft at the end beyond "len". That is not a match * with string[0:len] that we are looking for. */ } else if (!string[len]) { /* * asked with the whole string, and got nothing. No * matching entry can exist in the map. */ return NULL; } /* * i is at the exact match to an overlong key, or location the * overlong key would be inserted, which must come after the * real location of the key if one exists. */ while (0 <= --i && i < map->nr) { int cmp = strncasecmp(map->items[i].string, string, len); if (cmp < 0) /* * "i" points at a key definitely below the prefix; * the map does not have string[0:len] in it. */ break; else if (!cmp && !map->items[i].string[len]) /* found it */ return &map->items[i]; /* * otherwise, the string at "i" may be string[0:len] * followed by a string that sorts later than string[len:]; * keep trying. */ } return NULL; }
static int string_list_add_note_lines(struct string_list *sort_uniq_list, const unsigned char *sha1) { char *data; unsigned long len; enum object_type t; struct strbuf buf = STRBUF_INIT; struct strbuf **lines = NULL; int i, list_index; if (is_null_sha1(sha1)) return 0; /* read_sha1_file NUL-terminates */ data = read_sha1_file(sha1, &t, &len); if (t != OBJ_BLOB || !data || !len) { free(data); return t != OBJ_BLOB || !data; } strbuf_attach(&buf, data, len, len + 1); lines = strbuf_split(&buf, '\n'); for (i = 0; lines[i]; i++) { if (lines[i]->buf[lines[i]->len - 1] == '\n') strbuf_setlen(lines[i], lines[i]->len - 1); if (!lines[i]->len) continue; /* skip empty lines */ list_index = string_list_find_insert_index(sort_uniq_list, lines[i]->buf, 0); if (list_index < 0) continue; /* skip duplicate lines */ string_list_insert_at_index(sort_uniq_list, list_index, lines[i]->buf); } strbuf_list_free(lines); strbuf_release(&buf); return 0; }