Skip to content

Commit 3235ef3

Browse files
committed
Merge branch 'rs/commit-stack'
Code clean-up, unifying various hand-rolled "list of commit objects" and use the commit_stack API. * rs/commit-stack: commit-reach: use commit_stack commit-graph: use commit_stack commit: add commit_stack_grow() shallow: use commit_stack pack-bitmap-write: use commit_stack commit: add commit_stack_init() test-reach: use commit_stack remote: use commit_stack for src_commits remote: use commit_stack for sent_tips remote: use commit_stack for local_commits name-rev: use commit_stack midx: use commit_stack log: use commit_stack revision: export commit_stack
2 parents 0320bcd + 0e44595 commit 3235ef3

File tree

13 files changed

+184
-247
lines changed

13 files changed

+184
-247
lines changed

builtin/log.c

Lines changed: 15 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1896,11 +1896,11 @@ int cmd_format_patch(int argc,
18961896
{
18971897
struct format_config cfg;
18981898
struct commit *commit;
1899-
struct commit **list = NULL;
1899+
struct commit_stack list = COMMIT_STACK_INIT;
19001900
struct rev_info rev;
19011901
char *to_free = NULL;
19021902
struct setup_revision_opt s_r_opt;
1903-
size_t nr = 0, total, i;
1903+
size_t total, i;
19041904
int use_stdout = 0;
19051905
int start_number = -1;
19061906
int just_numbers = 0;
@@ -2283,14 +2283,12 @@ int cmd_format_patch(int argc,
22832283
if (ignore_if_in_upstream && has_commit_patch_id(commit, &ids))
22842284
continue;
22852285

2286-
nr++;
2287-
REALLOC_ARRAY(list, nr);
2288-
list[nr - 1] = commit;
2286+
commit_stack_push(&list, commit);
22892287
}
2290-
if (nr == 0)
2288+
if (!list.nr)
22912289
/* nothing to do */
22922290
goto done;
2293-
total = nr;
2291+
total = list.nr;
22942292
if (cover_letter == -1) {
22952293
if (cfg.config_cover_letter == COVER_AUTO)
22962294
cover_letter = (total > 1);
@@ -2308,7 +2306,7 @@ int cmd_format_patch(int argc,
23082306
if (!cover_letter && total != 1)
23092307
die(_("--interdiff requires --cover-letter or single patch"));
23102308
rev.idiff_oid1 = &idiff_prev.oid[idiff_prev.nr - 1];
2311-
rev.idiff_oid2 = get_commit_tree_oid(list[0]);
2309+
rev.idiff_oid2 = get_commit_tree_oid(list.items[0]);
23122310
rev.idiff_title = diff_title(&idiff_title, reroll_count,
23132311
_("Interdiff:"),
23142312
_("Interdiff against v%d:"));
@@ -2324,7 +2322,7 @@ int cmd_format_patch(int argc,
23242322
die(_("--range-diff requires --cover-letter or single patch"));
23252323

23262324
infer_range_diff_ranges(&rdiff1, &rdiff2, rdiff_prev,
2327-
origin, list[0]);
2325+
origin, list.items[0]);
23282326
rev.rdiff1 = rdiff1.buf;
23292327
rev.rdiff2 = rdiff2.buf;
23302328
rev.creation_factor = creation_factor;
@@ -2360,11 +2358,11 @@ int cmd_format_patch(int argc,
23602358
}
23612359

23622360
memset(&bases, 0, sizeof(bases));
2363-
base = get_base_commit(&cfg, list, nr);
2361+
base = get_base_commit(&cfg, list.items, list.nr);
23642362
if (base) {
23652363
reset_revision_walk();
23662364
clear_object_flags(the_repository, UNINTERESTING);
2367-
prepare_bases(&bases, base, list, nr);
2365+
prepare_bases(&bases, base, list.items, list.nr);
23682366
}
23692367

23702368
if (in_reply_to || cfg.thread || cover_letter) {
@@ -2381,7 +2379,8 @@ int cmd_format_patch(int argc,
23812379
if (cfg.thread)
23822380
gen_message_id(&rev, "cover");
23832381
make_cover_letter(&rev, !!output_directory,
2384-
origin, nr, list, description_file, branch_name, quiet, &cfg);
2382+
origin, list.nr, list.items,
2383+
description_file, branch_name, quiet, &cfg);
23852384
print_bases(&bases, rev.diffopt.file);
23862385
print_signature(signature, rev.diffopt.file);
23872386
total++;
@@ -2395,12 +2394,12 @@ int cmd_format_patch(int argc,
23952394
if (show_progress)
23962395
progress = start_delayed_progress(the_repository,
23972396
_("Generating patches"), total);
2398-
for (i = 0; i < nr; i++) {
2399-
size_t idx = nr - i - 1;
2397+
while (list.nr) {
2398+
size_t idx = list.nr - 1;
24002399
int shown;
24012400

24022401
display_progress(progress, total - idx);
2403-
commit = list[idx];
2402+
commit = commit_stack_pop(&list);
24042403
rev.nr = total - idx + (start_number - 1);
24052404

24062405
/* Make the second and subsequent mails replies to the first */
@@ -2469,7 +2468,7 @@ int cmd_format_patch(int argc,
24692468
}
24702469
}
24712470
stop_progress(&progress);
2472-
free(list);
2471+
commit_stack_clear(&list);
24732472
if (ignore_if_in_upstream)
24742473
free_patch_ids(&ids);
24752474

builtin/name-rev.c

Lines changed: 6 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -180,8 +180,7 @@ static void name_rev(struct commit *start_commit,
180180
{
181181
struct prio_queue queue;
182182
struct commit *commit;
183-
struct commit **parents_to_queue = NULL;
184-
size_t parents_to_queue_nr, parents_to_queue_alloc = 0;
183+
struct commit_stack parents_to_queue = COMMIT_STACK_INIT;
185184
struct rev_name *start_name;
186185

187186
repo_parse_commit(the_repository, start_commit);
@@ -206,7 +205,7 @@ static void name_rev(struct commit *start_commit,
206205
struct commit_list *parents;
207206
int parent_number = 1;
208207

209-
parents_to_queue_nr = 0;
208+
parents_to_queue.nr = 0;
210209

211210
for (parents = commit->parents;
212211
parents;
@@ -238,22 +237,18 @@ static void name_rev(struct commit *start_commit,
238237
string_pool);
239238
else
240239
parent_name->tip_name = name->tip_name;
241-
ALLOC_GROW(parents_to_queue,
242-
parents_to_queue_nr + 1,
243-
parents_to_queue_alloc);
244-
parents_to_queue[parents_to_queue_nr] = parent;
245-
parents_to_queue_nr++;
240+
commit_stack_push(&parents_to_queue, parent);
246241
}
247242
}
248243

249244
/* The first parent must come out first from the prio_queue */
250-
while (parents_to_queue_nr)
245+
while (parents_to_queue.nr)
251246
prio_queue_put(&queue,
252-
parents_to_queue[--parents_to_queue_nr]);
247+
commit_stack_pop(&parents_to_queue));
253248
}
254249

255250
clear_prio_queue(&queue);
256-
free(parents_to_queue);
251+
commit_stack_clear(&parents_to_queue);
257252
}
258253

259254
static int subpath_matches(const char *path, const char *filter)

0 commit comments

Comments
 (0)