Skip to content

Commit 4460e05

Browse files
committed
remerge-diff: clean up temporary objdir at a central place
After running a diff between two things, or a series of diffs while walking the history, the diff computation is concluded by a call to diff_result_code() to extract the exit status of the diff machinery. The function can work on "struct diffopt", but all the callers historically and currently pass "struct diffopt" that is embedded in the "struct rev_info" that is used to hold the remerge_diff bit and the remerge_objdir variable that points at the temporary object directory in use. Redefine diff_result_code() to take the whole "struct rev_info" to give it an access to these members related to remerge-diff, so that it can get rid of the temporary object directory for any and all callers that used the feature. We can lose the equivalent code to do so from the code paths for individual commands, diff-tree, diff, and log. Signed-off-by: Junio C Hamano <[email protected]>
1 parent 245cac5 commit 4460e05

File tree

12 files changed

+26
-26
lines changed

12 files changed

+26
-26
lines changed

builtin/describe.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -687,7 +687,7 @@ int cmd_describe(int argc, const char **argv, const char *prefix)
687687
BUG("malformed internal diff-index command line");
688688
run_diff_index(&revs, 0);
689689

690-
if (!diff_result_code(&revs.diffopt))
690+
if (!diff_result_code(&revs))
691691
suffix = NULL;
692692
else
693693
suffix = dirty;

builtin/diff-files.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ int cmd_diff_files(int argc, const char **argv, const char *prefix)
8282
if (repo_read_index_preload(the_repository, &rev.diffopt.pathspec, 0) < 0)
8383
die_errno("repo_read_index_preload");
8484
run_diff_files(&rev, options);
85-
result = diff_result_code(&rev.diffopt);
85+
result = diff_result_code(&rev);
8686
release_revisions(&rev);
8787
return result;
8888
}

builtin/diff-index.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ int cmd_diff_index(int argc, const char **argv, const char *prefix)
7171
return -1;
7272
}
7373
run_diff_index(&rev, option);
74-
result = diff_result_code(&rev.diffopt);
74+
result = diff_result_code(&rev);
7575
release_revisions(&rev);
7676
return result;
7777
}

builtin/diff-tree.c

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -232,10 +232,5 @@ int cmd_diff_tree(int argc, const char **argv, const char *prefix)
232232
diff_free(&opt->diffopt);
233233
}
234234

235-
if (opt->remerge_diff) {
236-
tmp_objdir_destroy(opt->remerge_objdir);
237-
opt->remerge_objdir = NULL;
238-
}
239-
240-
return diff_result_code(&opt->diffopt);
235+
return diff_result_code(opt);
241236
}

builtin/diff.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -605,7 +605,7 @@ int cmd_diff(int argc, const char **argv, const char *prefix)
605605
builtin_diff_combined(&rev, argc, argv,
606606
ent.objects, ent.nr,
607607
first_non_parent);
608-
result = diff_result_code(&rev.diffopt);
608+
result = diff_result_code(&rev);
609609
if (1 < rev.diffopt.skip_stat_unmatch)
610610
refresh_index_quietly();
611611
release_revisions(&rev);

builtin/log.c

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -493,6 +493,7 @@ static int cmd_log_walk_no_free(struct rev_info *rev)
493493
struct commit *commit;
494494
int saved_nrl = 0;
495495
int saved_dcctc = 0;
496+
int result;
496497

497498
if (rev->early_output)
498499
setup_early_output();
@@ -533,16 +534,12 @@ static int cmd_log_walk_no_free(struct rev_info *rev)
533534
rev->diffopt.degraded_cc_to_c = saved_dcctc;
534535
rev->diffopt.needed_rename_limit = saved_nrl;
535536

536-
if (rev->remerge_diff) {
537-
tmp_objdir_destroy(rev->remerge_objdir);
538-
rev->remerge_objdir = NULL;
539-
}
540-
537+
result = diff_result_code(rev);
541538
if (rev->diffopt.output_format & DIFF_FORMAT_CHECKDIFF &&
542539
rev->diffopt.flags.check_failed) {
543-
return 02;
540+
result = 02;
544541
}
545-
return diff_result_code(&rev->diffopt);
542+
return result;
546543
}
547544

548545
static int cmd_log_walk(struct rev_info *rev)

builtin/stash.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -972,7 +972,7 @@ static int show_stash(int argc, const char **argv, const char *prefix)
972972
}
973973
log_tree_diff_flush(&rev);
974974

975-
ret = diff_result_code(&rev.diffopt);
975+
ret = diff_result_code(&rev);
976976
cleanup:
977977
strvec_clear(&stash_args);
978978
free_stash_info(&info);
@@ -1116,13 +1116,13 @@ static int check_changes_tracked_files(const struct pathspec *ps)
11161116
diff_setup_done(&rev.diffopt);
11171117

11181118
run_diff_index(&rev, DIFF_INDEX_CACHED);
1119-
if (diff_result_code(&rev.diffopt)) {
1119+
if (diff_result_code(&rev)) {
11201120
ret = 1;
11211121
goto done;
11221122
}
11231123

11241124
run_diff_files(&rev, 0);
1125-
if (diff_result_code(&rev.diffopt)) {
1125+
if (diff_result_code(&rev)) {
11261126
ret = 1;
11271127
goto done;
11281128
}

builtin/submodule--helper.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -675,7 +675,7 @@ static void status_submodule(const char *path, const struct object_id *ce_oid,
675675
setup_revisions(diff_files_args.nr, diff_files_args.v, &rev, &opt);
676676
run_diff_files(&rev, 0);
677677

678-
if (!diff_result_code(&rev.diffopt)) {
678+
if (!diff_result_code(&rev)) {
679679
print_status(flags, ' ', path, ce_oid,
680680
displaypath);
681681
} else if (!(flags & OPT_CACHED)) {

diff-no-index.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -362,7 +362,7 @@ int diff_no_index(struct rev_info *revs,
362362
* The return code for --no-index imitates diff(1):
363363
* 0 = no changes, 1 = changes, else error
364364
*/
365-
ret = diff_result_code(&revs->diffopt);
365+
ret = diff_result_code(revs);
366366

367367
out:
368368
for (i = 0; i < ARRAY_SIZE(to_free); i++)

diff.c

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
#include "environment.h"
1010
#include "gettext.h"
1111
#include "tempfile.h"
12+
#include "revision.h"
1213
#include "quote.h"
1314
#include "diff.h"
1415
#include "diffcore.h"
@@ -26,6 +27,7 @@
2627
#include "merge-ll.h"
2728
#include "string-list.h"
2829
#include "strvec.h"
30+
#include "tmp-objdir.h"
2931
#include "graph.h"
3032
#include "oid-array.h"
3133
#include "packfile.h"
@@ -7012,10 +7014,16 @@ void diffcore_std(struct diff_options *options)
70127014
options->found_follow = 0;
70137015
}
70147016

7015-
int diff_result_code(struct diff_options *opt)
7017+
int diff_result_code(struct rev_info *revs)
70167018
{
7019+
struct diff_options *opt = &revs->diffopt;
70177020
int result = 0;
70187021

7022+
if (revs->remerge_diff) {
7023+
tmp_objdir_destroy(revs->remerge_objdir);
7024+
revs->remerge_objdir = NULL;
7025+
}
7026+
70197027
diff_warn_rename_limit("diff.renameLimit",
70207028
opt->needed_rename_limit,
70217029
opt->degraded_cc_to_c);

0 commit comments

Comments
 (0)