]> git.ipfire.org Git - thirdparty/git.git/commitdiff
remerge-diff: clean up temporary objdir at a central place
authorJunio C Hamano <gitster@pobox.com>
Fri, 9 Aug 2024 22:31:35 +0000 (15:31 -0700)
committerJunio C Hamano <gitster@pobox.com>
Fri, 9 Aug 2024 22:42:40 +0000 (15:42 -0700)
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 <gitster@pobox.com>
12 files changed:
builtin/describe.c
builtin/diff-files.c
builtin/diff-index.c
builtin/diff-tree.c
builtin/diff.c
builtin/log.c
builtin/stash.c
builtin/submodule--helper.c
diff-no-index.c
diff.c
diff.h
wt-status.c

index d6c77a714f46194faca18739d0118294bc233f81..a1457d59e80892b01aed5b1b732a023f4ed5b277 100644 (file)
@@ -687,7 +687,7 @@ int cmd_describe(int argc, const char **argv, const char *prefix)
                                BUG("malformed internal diff-index command line");
                        run_diff_index(&revs, 0);
 
-                       if (!diff_result_code(&revs.diffopt))
+                       if (!diff_result_code(&revs))
                                suffix = NULL;
                        else
                                suffix = dirty;
index 018011f29ea26be24b567e9af380699dd7d893a3..dd0b76e7d5646094f763e43ab446887b8abcdda0 100644 (file)
@@ -82,7 +82,7 @@ int cmd_diff_files(int argc, const char **argv, const char *prefix)
        if (repo_read_index_preload(the_repository, &rev.diffopt.pathspec, 0) < 0)
                die_errno("repo_read_index_preload");
        run_diff_files(&rev, options);
-       result = diff_result_code(&rev.diffopt);
+       result = diff_result_code(&rev);
        release_revisions(&rev);
        return result;
 }
index 3e05260ac0e0401188163aeaf4c4d1aea0ba56d1..560c099524f9959024fdb151a6554509226218e3 100644 (file)
@@ -71,7 +71,7 @@ int cmd_diff_index(int argc, const char **argv, const char *prefix)
                return -1;
        }
        run_diff_index(&rev, option);
-       result = diff_result_code(&rev.diffopt);
+       result = diff_result_code(&rev);
        release_revisions(&rev);
        return result;
 }
index af51cd29c6f8eca2a82a613de0cbf89a7e5a437b..995225ef5f0424956b544463479b226b71b1411d 100644 (file)
@@ -232,10 +232,5 @@ int cmd_diff_tree(int argc, const char **argv, const char *prefix)
                diff_free(&opt->diffopt);
        }
 
-       if (opt->remerge_diff) {
-               tmp_objdir_destroy(opt->remerge_objdir);
-               opt->remerge_objdir = NULL;
-       }
-
-       return diff_result_code(&opt->diffopt);
+       return diff_result_code(opt);
 }
index 6e196e0c7d2d055df1557ffd256d87a737053324..a5834704aa3821ccd2c40442e7552de3b49e295d 100644 (file)
@@ -605,7 +605,7 @@ int cmd_diff(int argc, const char **argv, const char *prefix)
                builtin_diff_combined(&rev, argc, argv,
                                      ent.objects, ent.nr,
                                      first_non_parent);
-       result = diff_result_code(&rev.diffopt);
+       result = diff_result_code(&rev);
        if (1 < rev.diffopt.skip_stat_unmatch)
                refresh_index_quietly();
        release_revisions(&rev);
index 227823a16e3abde8f592f232b5c62060b2dd5e7c..b1a8fa73b1a76fa62a55415f3ca1260cd5a3a0eb 100644 (file)
@@ -493,6 +493,7 @@ static int cmd_log_walk_no_free(struct rev_info *rev)
        struct commit *commit;
        int saved_nrl = 0;
        int saved_dcctc = 0;
+       int result;
 
        if (rev->early_output)
                setup_early_output();
@@ -533,16 +534,12 @@ static int cmd_log_walk_no_free(struct rev_info *rev)
        rev->diffopt.degraded_cc_to_c = saved_dcctc;
        rev->diffopt.needed_rename_limit = saved_nrl;
 
-       if (rev->remerge_diff) {
-               tmp_objdir_destroy(rev->remerge_objdir);
-               rev->remerge_objdir = NULL;
-       }
-
+       result = diff_result_code(rev);
        if (rev->diffopt.output_format & DIFF_FORMAT_CHECKDIFF &&
            rev->diffopt.flags.check_failed) {
-               return 02;
+               result = 02;
        }
-       return diff_result_code(&rev->diffopt);
+       return result;
 }
 
 static int cmd_log_walk(struct rev_info *rev)
index 7fb355bff0a628d1d7a1a08646175ac33d8fe9d7..6dc70a6be2a7d76a73f2f05bf0a53f5b88509854 100644 (file)
@@ -972,7 +972,7 @@ static int show_stash(int argc, const char **argv, const char *prefix)
        }
        log_tree_diff_flush(&rev);
 
-       ret = diff_result_code(&rev.diffopt);
+       ret = diff_result_code(&rev);
 cleanup:
        strvec_clear(&stash_args);
        free_stash_info(&info);
@@ -1116,13 +1116,13 @@ static int check_changes_tracked_files(const struct pathspec *ps)
        diff_setup_done(&rev.diffopt);
 
        run_diff_index(&rev, DIFF_INDEX_CACHED);
-       if (diff_result_code(&rev.diffopt)) {
+       if (diff_result_code(&rev)) {
                ret = 1;
                goto done;
        }
 
        run_diff_files(&rev, 0);
-       if (diff_result_code(&rev.diffopt)) {
+       if (diff_result_code(&rev)) {
                ret = 1;
                goto done;
        }
index cc0db6336c310d0e065f65e75b4589258eafe77b..96d28899072155ebf523434f8e15f8e77f88d9e0 100644 (file)
@@ -675,7 +675,7 @@ static void status_submodule(const char *path, const struct object_id *ce_oid,
        setup_revisions(diff_files_args.nr, diff_files_args.v, &rev, &opt);
        run_diff_files(&rev, 0);
 
-       if (!diff_result_code(&rev.diffopt)) {
+       if (!diff_result_code(&rev)) {
                print_status(flags, ' ', path, ce_oid,
                             displaypath);
        } else if (!(flags & OPT_CACHED)) {
index 3a8965672c5e90093c08a9fde12981b922ae8a76..c5fb06e6d1a90d60de54ed5a31573fd4998c4623 100644 (file)
@@ -362,7 +362,7 @@ int diff_no_index(struct rev_info *revs,
         * The return code for --no-index imitates diff(1):
         * 0 = no changes, 1 = changes, else error
         */
-       ret = diff_result_code(&revs->diffopt);
+       ret = diff_result_code(revs);
 
 out:
        for (i = 0; i < ARRAY_SIZE(to_free); i++)
diff --git a/diff.c b/diff.c
index ccfa1fca0d05fa0148a53e05497efaf21cc4d916..970ea47710e457bb1fe23255f565349f4245fc32 100644 (file)
--- a/diff.c
+++ b/diff.c
@@ -9,6 +9,7 @@
 #include "environment.h"
 #include "gettext.h"
 #include "tempfile.h"
+#include "revision.h"
 #include "quote.h"
 #include "diff.h"
 #include "diffcore.h"
@@ -26,6 +27,7 @@
 #include "merge-ll.h"
 #include "string-list.h"
 #include "strvec.h"
+#include "tmp-objdir.h"
 #include "graph.h"
 #include "oid-array.h"
 #include "packfile.h"
@@ -7012,10 +7014,16 @@ void diffcore_std(struct diff_options *options)
        options->found_follow = 0;
 }
 
-int diff_result_code(struct diff_options *opt)
+int diff_result_code(struct rev_info *revs)
 {
+       struct diff_options *opt = &revs->diffopt;
        int result = 0;
 
+       if (revs->remerge_diff) {
+               tmp_objdir_destroy(revs->remerge_objdir);
+               revs->remerge_objdir = NULL;
+       }
+
        diff_warn_rename_limit("diff.renameLimit",
                               opt->needed_rename_limit,
                               opt->degraded_cc_to_c);
diff --git a/diff.h b/diff.h
index 66bd8aeb2936fbe9d6610f7dc1202e31e1450ebb..1966ba6bb7e6af2a48824afb4dd8d81cc6db227f 100644 (file)
--- a/diff.h
+++ b/diff.h
@@ -648,7 +648,7 @@ int do_diff_cache(const struct object_id *, struct diff_options *);
 int diff_flush_patch_id(struct diff_options *, struct object_id *, int);
 void flush_one_hunk(struct object_id *result, git_hash_ctx *ctx);
 
-int diff_result_code(struct diff_options *);
+int diff_result_code(struct rev_info *);
 
 int diff_no_index(struct rev_info *,
                  int implicit_no_index, int, const char **);
index 9e8c08003b990c44ca17dc1e778bf572eb694786..d1c3f3dc4d433a9a724f8a6f1d12bdc07f5c7bc6 100644 (file)
@@ -2582,7 +2582,7 @@ int has_unstaged_changes(struct repository *r, int ignore_submodules)
        rev_info.diffopt.flags.quick = 1;
        diff_setup_done(&rev_info.diffopt);
        run_diff_files(&rev_info, 0);
-       result = diff_result_code(&rev_info.diffopt);
+       result = diff_result_code(&rev_info);
        release_revisions(&rev_info);
        return result;
 }
@@ -2616,7 +2616,7 @@ int has_uncommitted_changes(struct repository *r,
 
        diff_setup_done(&rev_info.diffopt);
        run_diff_index(&rev_info, DIFF_INDEX_CACHED);
-       result = diff_result_code(&rev_info.diffopt);
+       result = diff_result_code(&rev_info);
        release_revisions(&rev_info);
        return result;
 }