Skip to content

Commit 3cc0287

Browse files
pcloudsgitster
authored andcommitted
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 <[email protected]>
1 parent 8315bd2 commit 3cc0287

File tree

1 file changed

+9
-3
lines changed

1 file changed

+9
-3
lines changed

sequencer.c

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3362,6 +3362,8 @@ static int subject2item_cmp(const void *fndata,
33623362
return key ? strcmp(a->subject, key) : strcmp(a->subject, b->subject);
33633363
}
33643364

3365+
define_commit_slab(commit_todo_item, struct todo_item *);
3366+
33653367
/*
33663368
* Rearrange the todo list that has both "pick commit-id msg" and "pick
33673369
* commit-id fixup!/squash! msg" in it so that the latter is put immediately
@@ -3378,6 +3380,7 @@ int rearrange_squash(void)
33783380
struct hashmap subject2item;
33793381
int res = 0, rearranged = 0, *next, *tail, i;
33803382
char **subjects;
3383+
struct commit_todo_item commit_todo;
33813384

33823385
if (strbuf_read_file_or_whine(&todo_list.buf, todo_file) < 0)
33833386
return -1;
@@ -3386,6 +3389,7 @@ int rearrange_squash(void)
33863389
return -1;
33873390
}
33883391

3392+
init_commit_todo_item(&commit_todo);
33893393
/*
33903394
* The hashmap maps onelines to the respective todo list index.
33913395
*
@@ -3416,10 +3420,11 @@ int rearrange_squash(void)
34163420

34173421
if (is_fixup(item->command)) {
34183422
todo_list_release(&todo_list);
3423+
clear_commit_todo_item(&commit_todo);
34193424
return error(_("the script was already rearranged."));
34203425
}
34213426

3422-
item->commit->util = item;
3427+
*commit_todo_item_at(&commit_todo, item->commit) = item;
34233428

34243429
parse_commit(item->commit);
34253430
commit_buffer = get_commit_buffer(item->commit, NULL);
@@ -3446,9 +3451,9 @@ int rearrange_squash(void)
34463451
else if (!strchr(p, ' ') &&
34473452
(commit2 =
34483453
lookup_commit_reference_by_name(p)) &&
3449-
commit2->util)
3454+
*commit_todo_item_at(&commit_todo, commit2))
34503455
/* found by commit name */
3451-
i2 = (struct todo_item *)commit2->util
3456+
i2 = *commit_todo_item_at(&commit_todo, commit2)
34523457
- todo_list.items;
34533458
else {
34543459
/* copy can be a prefix of the commit subject */
@@ -3527,5 +3532,6 @@ int rearrange_squash(void)
35273532
hashmap_free(&subject2item, 1);
35283533
todo_list_release(&todo_list);
35293534

3535+
clear_commit_todo_item(&commit_todo);
35303536
return res;
35313537
}

0 commit comments

Comments
 (0)