]> git.ipfire.org Git - thirdparty/git.git/commitdiff
Close object store closer to spawning child processes
authorJohannes Schindelin <johannes.schindelin@gmx.de>
Thu, 9 Sep 2021 09:47:08 +0000 (09:47 +0000)
committerJunio C Hamano <gitster@pobox.com>
Thu, 9 Sep 2021 19:56:11 +0000 (12:56 -0700)
In many cases where we spawned child processes that _may_ trigger a
repack, we explicitly closed the object store first (so that the
`repack` process can delete the `.pack` files, which would otherwise not
be possible on Windows since files cannot be deleted as long as they as
still in use).

Wherever possible, we now use the new `close_object_store` bit of the
`run_command()` API, to delay closing the object store even further.
This makes the code easier to maintain because it is now more obvious
that we only release those file handles because of those child
processes.

Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
builtin/gc.c
builtin/pull.c
builtin/receive-pack.c

index f05d2f0a1ac9cd5637237d7da987452523a8ced3..ddee9f8324f22a4fae7f2440c510e8d6685d2b9f 100644 (file)
@@ -663,8 +663,8 @@ int cmd_gc(int argc, const char **argv, const char *prefix)
        gc_before_repack();
 
        if (!repository_format_precious_objects) {
-               close_object_store(the_repository->objects);
-               if (run_command_v_opt(repack.v, RUN_GIT_CMD))
+               if (run_command_v_opt(repack.v,
+                                     RUN_GIT_CMD | RUN_CLOSE_OBJECT_STORE))
                        die(FAILED_RUN, repack.v[0]);
 
                if (prune_expire) {
@@ -848,7 +848,7 @@ static int run_write_commit_graph(struct maintenance_run_opts *opts)
 {
        struct child_process child = CHILD_PROCESS_INIT;
 
-       child.git_cmd = 1;
+       child.git_cmd = child.close_object_store = 1;
        strvec_pushl(&child.args, "commit-graph", "write",
                     "--split", "--reachable", NULL);
 
@@ -864,7 +864,6 @@ static int maintenance_task_commit_graph(struct maintenance_run_opts *opts)
        if (!the_repository->settings.core_commit_graph)
                return 0;
 
-       close_object_store(the_repository->objects);
        if (run_write_commit_graph(opts)) {
                error(_("failed to write commit-graph"));
                return 1;
@@ -913,7 +912,7 @@ static int maintenance_task_gc(struct maintenance_run_opts *opts)
 {
        struct child_process child = CHILD_PROCESS_INIT;
 
-       child.git_cmd = 1;
+       child.git_cmd = child.close_object_store = 1;
        strvec_push(&child.args, "gc");
 
        if (opts->auto_flag)
@@ -923,7 +922,6 @@ static int maintenance_task_gc(struct maintenance_run_opts *opts)
        else
                strvec_push(&child.args, "--no-quiet");
 
-       close_object_store(the_repository->objects);
        return run_command(&child);
 }
 
@@ -1097,14 +1095,12 @@ static int multi_pack_index_expire(struct maintenance_run_opts *opts)
 {
        struct child_process child = CHILD_PROCESS_INIT;
 
-       child.git_cmd = 1;
+       child.git_cmd = child.close_object_store = 1;
        strvec_pushl(&child.args, "multi-pack-index", "expire", NULL);
 
        if (opts->quiet)
                strvec_push(&child.args, "--no-progress");
 
-       close_object_store(the_repository->objects);
-
        if (run_command(&child))
                return error(_("'git multi-pack-index expire' failed"));
 
@@ -1155,7 +1151,7 @@ static int multi_pack_index_repack(struct maintenance_run_opts *opts)
 {
        struct child_process child = CHILD_PROCESS_INIT;
 
-       child.git_cmd = 1;
+       child.git_cmd = child.close_object_store = 1;
        strvec_pushl(&child.args, "multi-pack-index", "repack", NULL);
 
        if (opts->quiet)
@@ -1164,8 +1160,6 @@ static int multi_pack_index_repack(struct maintenance_run_opts *opts)
        strvec_pushf(&child.args, "--batch-size=%"PRIuMAX,
                                  (uintmax_t)get_auto_pack_size());
 
-       close_object_store(the_repository->objects);
-
        if (run_command(&child))
                return error(_("'git multi-pack-index repack' failed"));
 
index d9f0156d96917c0b1b0ac29c2f527369c433b4da..751372041c2bdadfdbc0c4c283eaf5dd9720ea7c 100644 (file)
@@ -578,7 +578,7 @@ static int run_fetch(const char *repo, const char **refspecs)
                strvec_pushv(&args, refspecs);
        } else if (*refspecs)
                BUG("refspecs without repo?");
-       ret = run_command_v_opt(args.v, RUN_GIT_CMD);
+       ret = run_command_v_opt(args.v, RUN_GIT_CMD | RUN_CLOSE_OBJECT_STORE);
        strvec_clear(&args);
        return ret;
 }
@@ -999,7 +999,6 @@ int cmd_pull(int argc, const char **argv, const char *prefix)
                        oidclr(&rebase_fork_point);
        }
 
-       close_object_store(the_repository->objects);
        if (run_fetch(repo, refspecs))
                return 1;
 
index 2d1f97e1ca7b5346d9cae3239165d6824df309af..9d5e0e3d11cc87a9f5b1b9874edf89e1f524c1a9 100644 (file)
@@ -2580,10 +2580,9 @@ int cmd_receive_pack(int argc, const char **argv, const char *prefix)
                        proc.no_stdin = 1;
                        proc.stdout_to_stderr = 1;
                        proc.err = use_sideband ? -1 : 0;
-                       proc.git_cmd = 1;
+                       proc.git_cmd = proc.close_object_store = 1;
                        proc.argv = argv_gc_auto;
 
-                       close_object_store(the_repository->objects);
                        if (!start_command(&proc)) {
                                if (use_sideband)
                                        copy_to_sideband(proc.err, -1, NULL);