Skip to content

Commit 0139c58

Browse files
avargitster
authored andcommitted
revisions API users: add "goto cleanup" for release_revisions()
Add a release_revisions() to various users of "struct rev_info" which requires a minor refactoring to a "goto cleanup" pattern to use that function. Signed-off-by: Ævar Arnfjörð Bjarmason <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 5e48017 commit 0139c58

File tree

6 files changed

+55
-24
lines changed

6 files changed

+55
-24
lines changed

builtin/diff-files.c

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -77,8 +77,12 @@ int cmd_diff_files(int argc, const char **argv, const char *prefix)
7777

7878
if (read_cache_preload(&rev.diffopt.pathspec) < 0) {
7979
perror("read_cache_preload");
80-
return -1;
80+
result = -1;
81+
goto cleanup;
8182
}
83+
cleanup:
8284
result = run_diff_files(&rev, options);
83-
return diff_result_code(&rev.diffopt, result);
85+
result = diff_result_code(&rev.diffopt, result);
86+
release_revisions(&rev);
87+
return result;
8488
}

builtin/rev-list.c

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -500,6 +500,7 @@ int cmd_rev_list(int argc, const char **argv, const char *prefix)
500500
int use_bitmap_index = 0;
501501
int filter_provided_objects = 0;
502502
const char *show_progress = NULL;
503+
int ret = 0;
503504

504505
if (argc == 2 && !strcmp(argv[1], "-h"))
505506
usage(rev_list_usage);
@@ -583,7 +584,7 @@ int cmd_rev_list(int argc, const char **argv, const char *prefix)
583584
}
584585
if (!strcmp(arg, "--test-bitmap")) {
585586
test_bitmap_walk(&revs);
586-
return 0;
587+
goto cleanup;
587588
}
588589
if (skip_prefix(arg, "--progress=", &arg)) {
589590
show_progress = arg;
@@ -672,11 +673,11 @@ int cmd_rev_list(int argc, const char **argv, const char *prefix)
672673

673674
if (use_bitmap_index) {
674675
if (!try_bitmap_count(&revs, filter_provided_objects))
675-
return 0;
676+
goto cleanup;
676677
if (!try_bitmap_disk_usage(&revs, filter_provided_objects))
677-
return 0;
678+
goto cleanup;
678679
if (!try_bitmap_traversal(&revs, filter_provided_objects))
679-
return 0;
680+
goto cleanup;
680681
}
681682

682683
if (prepare_revision_walk(&revs))
@@ -696,8 +697,10 @@ int cmd_rev_list(int argc, const char **argv, const char *prefix)
696697

697698
find_bisection(&revs.commits, &reaches, &all, bisect_flags);
698699

699-
if (bisect_show_vars)
700-
return show_bisect_vars(&info, reaches, all);
700+
if (bisect_show_vars) {
701+
ret = show_bisect_vars(&info, reaches, all);
702+
goto cleanup;
703+
}
701704
}
702705

703706
if (filter_provided_objects) {
@@ -752,5 +755,7 @@ int cmd_rev_list(int argc, const char **argv, const char *prefix)
752755
if (show_disk_usage)
753756
printf("%"PRIuMAX"\n", (uintmax_t)total_disk_usage);
754757

755-
return 0;
758+
cleanup:
759+
release_revisions(&revs);
760+
return ret;
756761
}

builtin/stash.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -917,6 +917,7 @@ static int show_stash(int argc, const char **argv, const char *prefix)
917917
cleanup:
918918
strvec_clear(&stash_args);
919919
free_stash_info(&info);
920+
release_revisions(&rev);
920921
if (do_usage)
921922
usage_with_options(git_stash_show_usage, options);
922923
return ret;

builtin/submodule--helper.c

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1232,6 +1232,7 @@ static int compute_summary_module_list(struct object_id *head_oid,
12321232
struct strvec diff_args = STRVEC_INIT;
12331233
struct rev_info rev;
12341234
struct module_cb_list list = MODULE_CB_LIST_INIT;
1235+
int ret = 0;
12351236

12361237
strvec_push(&diff_args, get_diff_cmd(diff_cmd));
12371238
if (info->cached)
@@ -1257,21 +1258,24 @@ static int compute_summary_module_list(struct object_id *head_oid,
12571258
setup_work_tree();
12581259
if (read_cache_preload(&rev.diffopt.pathspec) < 0) {
12591260
perror("read_cache_preload");
1260-
return -1;
1261+
ret = -1;
1262+
goto cleanup;
12611263
}
12621264
} else if (read_cache() < 0) {
12631265
perror("read_cache");
1264-
return -1;
1266+
ret = -1;
1267+
goto cleanup;
12651268
}
12661269

12671270
if (diff_cmd == DIFF_INDEX)
12681271
run_diff_index(&rev, info->cached);
12691272
else
12701273
run_diff_files(&rev, 0);
12711274
prepare_submodule_summary(info, &list);
1275+
cleanup:
12721276
strvec_clear(&diff_args);
12731277
release_revisions(&rev);
1274-
return 0;
1278+
return ret;
12751279
}
12761280

12771281
static int module_summary(int argc, const char **argv, const char *prefix)

sequencer.c

Lines changed: 16 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -5354,6 +5354,7 @@ int sequencer_make_script(struct repository *r, struct strbuf *out, int argc,
53545354
int rebase_merges = flags & TODO_LIST_REBASE_MERGES;
53555355
int reapply_cherry_picks = flags & TODO_LIST_REAPPLY_CHERRY_PICKS;
53565356
int skipped_commit = 0;
5357+
int ret = 0;
53575358

53585359
repo_init_revisions(r, &revs, NULL);
53595360
revs.verbose_header = 1;
@@ -5377,14 +5378,20 @@ int sequencer_make_script(struct repository *r, struct strbuf *out, int argc,
53775378
pp.fmt = revs.commit_format;
53785379
pp.output_encoding = get_log_output_encoding();
53795380

5380-
if (setup_revisions(argc, argv, &revs, NULL) > 1)
5381-
return error(_("make_script: unhandled options"));
5381+
if (setup_revisions(argc, argv, &revs, NULL) > 1) {
5382+
ret = error(_("make_script: unhandled options"));
5383+
goto cleanup;
5384+
}
53825385

5383-
if (prepare_revision_walk(&revs) < 0)
5384-
return error(_("make_script: error preparing revisions"));
5386+
if (prepare_revision_walk(&revs) < 0) {
5387+
ret = error(_("make_script: error preparing revisions"));
5388+
goto cleanup;
5389+
}
53855390

5386-
if (rebase_merges)
5387-
return make_script_with_merges(&pp, &revs, out, flags);
5391+
if (rebase_merges) {
5392+
ret = make_script_with_merges(&pp, &revs, out, flags);
5393+
goto cleanup;
5394+
}
53885395

53895396
while ((commit = get_revision(&revs))) {
53905397
int is_empty = is_original_commit_empty(commit);
@@ -5408,7 +5415,9 @@ int sequencer_make_script(struct repository *r, struct strbuf *out, int argc,
54085415
if (skipped_commit)
54095416
advise_if_enabled(ADVICE_SKIPPED_CHERRY_PICKS,
54105417
_("use --reapply-cherry-picks to include skipped commits"));
5411-
return 0;
5418+
cleanup:
5419+
release_revisions(&revs);
5420+
return ret;
54125421
}
54135422

54145423
/*

t/helper/test-fast-rebase.c

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,7 @@ int cmd__fast_rebase(int argc, const char **argv)
9999
struct merge_result result;
100100
struct strbuf reflog_msg = STRBUF_INIT;
101101
struct strbuf branch_name = STRBUF_INIT;
102+
int ret = 0;
102103

103104
/*
104105
* test-tool stuff doesn't set up the git directory by default; need to
@@ -137,13 +138,17 @@ int cmd__fast_rebase(int argc, const char **argv)
137138
revs.topo_order = 1;
138139
strvec_pushl(&rev_walk_args, "", argv[4], "--not", argv[3], NULL);
139140

140-
if (setup_revisions(rev_walk_args.nr, rev_walk_args.v, &revs, NULL) > 1)
141-
return error(_("unhandled options"));
141+
if (setup_revisions(rev_walk_args.nr, rev_walk_args.v, &revs, NULL) > 1) {
142+
ret = error(_("unhandled options"));
143+
goto cleanup;
144+
}
142145

143146
strvec_clear(&rev_walk_args);
144147

145-
if (prepare_revision_walk(&revs) < 0)
146-
return error(_("error preparing revisions"));
148+
if (prepare_revision_walk(&revs) < 0) {
149+
ret = error(_("error preparing revisions"));
150+
goto cleanup;
151+
}
147152

148153
init_merge_options(&merge_opt, the_repository);
149154
memset(&result, 0, sizeof(result));
@@ -220,7 +225,10 @@ int cmd__fast_rebase(int argc, const char **argv)
220225
COMMIT_LOCK | SKIP_IF_UNCHANGED))
221226
die(_("unable to write %s"), get_index_file());
222227

228+
ret = (result.clean == 0);
229+
cleanup:
223230
strbuf_release(&reflog_msg);
224231
strbuf_release(&branch_name);
225-
return (result.clean == 0);
232+
release_revisions(&revs);
233+
return ret;
226234
}

0 commit comments

Comments
 (0)