diff options
author | Junio C Hamano <gitster@pobox.com> | 2023-08-24 19:32:33 +0300 |
---|---|---|
committer | Junio C Hamano <gitster@pobox.com> | 2023-08-24 19:32:33 +0300 |
commit | e9608bbc351f0264e7d2a1e88fc00127242c3a73 (patch) | |
tree | 415d1314377c6050eb6e17e7f4dc4b7da927cfba /sequencer.c | |
parent | f5f23a430f25fa956a87a9426791f4ee9055a5bf (diff) | |
parent | 82dc42cbd1c4576c2fd879996d9e73a86434769a (diff) |
Merge branch 'ob/sequencer-rearrange-cleanup'
Code clean-up.
* ob/sequencer-rearrange-cleanup:
sequencer: simplify allocation of result array in todo_list_rearrange_squash()
Diffstat (limited to 'sequencer.c')
-rw-r--r-- | sequencer.c | 9 |
1 files changed, 5 insertions, 4 deletions
diff --git a/sequencer.c b/sequencer.c index 5e0c15a16b..fcf5a7eba0 100644 --- a/sequencer.c +++ b/sequencer.c @@ -6245,7 +6245,7 @@ static int skip_fixupish(const char *subject, const char **p) { int todo_list_rearrange_squash(struct todo_list *todo_list) { struct hashmap subject2item; - int rearranged = 0, *next, *tail, i, nr = 0, alloc = 0; + int rearranged = 0, *next, *tail, i, nr = 0; char **subjects; struct commit_todo_item commit_todo; struct todo_item *items = NULL; @@ -6357,6 +6357,8 @@ int todo_list_rearrange_squash(struct todo_list *todo_list) } if (rearranged) { + ALLOC_ARRAY(items, todo_list->nr); + for (i = 0; i < todo_list->nr; i++) { enum todo_command command = todo_list->items[i].command; int cur = i; @@ -6369,16 +6371,15 @@ int todo_list_rearrange_squash(struct todo_list *todo_list) continue; while (cur >= 0) { - ALLOC_GROW(items, nr + 1, alloc); items[nr++] = todo_list->items[cur]; cur = next[cur]; } } + assert(nr == todo_list->nr); + todo_list->alloc = nr; FREE_AND_NULL(todo_list->items); todo_list->items = items; - todo_list->nr = nr; - todo_list->alloc = alloc; } free(next); |