예제 #1
0
파일: mailmap.c 프로젝트: 00027jang27/git
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);
}
예제 #2
0
파일: notes.c 프로젝트: julesbowden/git
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;
}
예제 #3
0
파일: string-list.c 프로젝트: 777/test-proj
struct string_list_item *string_list_insert(struct string_list *list, const char *string)
{
	return string_list_insert_at_index(list, -1, string);
}
예제 #4
0
struct string_list_item *string_list_insert(const char *string, struct string_list *list)
{
	return string_list_insert_at_index(-1, string, list);
}