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>

Nguyễn Thái Ngọc Duy committed May 19, 2018 at 07:28 UTC 3cc0287b394bf802af68d4fdb8c18e16318df907
1 file changed +9 -3
sequencer.c
+9 -3
@@ -3362,6 +3362,8 @@ static int subject2item_cmp(const void *fndata,
3362 return key ? strcmp(a->subject, key) : strcmp(a->subject, b->subject);
3363 }
3364
3365 +define_commit_slab(commit_todo_item, struct todo_item *);
3366 +
3367 /*
3368 * Rearrange the todo list that has both "pick commit-id msg" and "pick
3369 * commit-id fixup!/squash! msg" in it so that the latter is put immediately
@@ -3378,6 +3380,7 @@ int rearrange_squash(void)
3380 struct hashmap subject2item;
3381 int res = 0, rearranged = 0, *next, *tail, i;
3382 char **subjects;
3383 + struct commit_todo_item commit_todo;
3384
3385 if (strbuf_read_file_or_whine(&todo_list.buf, todo_file) < 0)
3386 return -1;
@@ -3386,6 +3389,7 @@ int rearrange_squash(void)
3389 return -1;
3390 }
3391
3392 + init_commit_todo_item(&commit_todo);
3393 /*
3394 * The hashmap maps onelines to the respective todo list index.
3395 *
@@ -3416,10 +3420,11 @@ int rearrange_squash(void)
3420
3421 if (is_fixup(item->command)) {
3422 todo_list_release(&todo_list);
3423 + clear_commit_todo_item(&commit_todo);
3424 return error(_("the script was already rearranged."));
3425 }
3426
3422 - item->commit->util = item;
3427 + *commit_todo_item_at(&commit_todo, item->commit) = item;
3428
3429 parse_commit(item->commit);
3430 commit_buffer = get_commit_buffer(item->commit, NULL);
@@ -3446,9 +3451,9 @@ int rearrange_squash(void)
3451 else if (!strchr(p, ' ') &&
3452 (commit2 =
3453 lookup_commit_reference_by_name(p)) &&
3449 - commit2->util)
3454 + *commit_todo_item_at(&commit_todo, commit2))
3455 /* found by commit name */
3451 - i2 = (struct todo_item *)commit2->util
3456 + i2 = *commit_todo_item_at(&commit_todo, commit2)
3457 - todo_list.items;
3458 else {
3459 /* copy can be a prefix of the commit subject */
@@ -3527,5 +3532,6 @@ int rearrange_squash(void)
3532 hashmap_free(&subject2item, 1);
3533 todo_list_release(&todo_list);
3534
3535 + clear_commit_todo_item(&commit_todo);
3536 return res;
3537 }