sequencer.c: use commit-slab to associate todo items to commits

It's done so that commit->util can be removed. See more explanation in
the commit that removes commit->util.

Signed-off-by: Junio C Hamano <gitster@pobox.com>
This commit is contained in:
Nguyễn Thái Ngọc Duy 2018-05-19 07:28:23 +02:00 коммит произвёл Junio C Hamano
Родитель 8315bd20ea
Коммит 3cc0287b39
1 изменённых файлов: 9 добавлений и 3 удалений

Просмотреть файл

@ -3362,6 +3362,8 @@ static int subject2item_cmp(const void *fndata,
return key ? strcmp(a->subject, key) : strcmp(a->subject, b->subject); return key ? strcmp(a->subject, key) : strcmp(a->subject, b->subject);
} }
define_commit_slab(commit_todo_item, struct todo_item *);
/* /*
* Rearrange the todo list that has both "pick commit-id msg" and "pick * Rearrange the todo list that has both "pick commit-id msg" and "pick
* commit-id fixup!/squash! msg" in it so that the latter is put immediately * commit-id fixup!/squash! msg" in it so that the latter is put immediately
@ -3378,6 +3380,7 @@ int rearrange_squash(void)
struct hashmap subject2item; struct hashmap subject2item;
int res = 0, rearranged = 0, *next, *tail, i; int res = 0, rearranged = 0, *next, *tail, i;
char **subjects; char **subjects;
struct commit_todo_item commit_todo;
if (strbuf_read_file_or_whine(&todo_list.buf, todo_file) < 0) if (strbuf_read_file_or_whine(&todo_list.buf, todo_file) < 0)
return -1; return -1;
@ -3386,6 +3389,7 @@ int rearrange_squash(void)
return -1; return -1;
} }
init_commit_todo_item(&commit_todo);
/* /*
* The hashmap maps onelines to the respective todo list index. * The hashmap maps onelines to the respective todo list index.
* *
@ -3416,10 +3420,11 @@ int rearrange_squash(void)
if (is_fixup(item->command)) { if (is_fixup(item->command)) {
todo_list_release(&todo_list); todo_list_release(&todo_list);
clear_commit_todo_item(&commit_todo);
return error(_("the script was already rearranged.")); return error(_("the script was already rearranged."));
} }
item->commit->util = item; *commit_todo_item_at(&commit_todo, item->commit) = item;
parse_commit(item->commit); parse_commit(item->commit);
commit_buffer = get_commit_buffer(item->commit, NULL); commit_buffer = get_commit_buffer(item->commit, NULL);
@ -3446,9 +3451,9 @@ int rearrange_squash(void)
else if (!strchr(p, ' ') && else if (!strchr(p, ' ') &&
(commit2 = (commit2 =
lookup_commit_reference_by_name(p)) && lookup_commit_reference_by_name(p)) &&
commit2->util) *commit_todo_item_at(&commit_todo, commit2))
/* found by commit name */ /* found by commit name */
i2 = (struct todo_item *)commit2->util i2 = *commit_todo_item_at(&commit_todo, commit2)
- todo_list.items; - todo_list.items;
else { else {
/* copy can be a prefix of the commit subject */ /* copy can be a prefix of the commit subject */
@ -3527,5 +3532,6 @@ int rearrange_squash(void)
hashmap_free(&subject2item, 1); hashmap_free(&subject2item, 1);
todo_list_release(&todo_list); todo_list_release(&todo_list);
clear_commit_todo_item(&commit_todo);
return res; return res;
} }