Skip to content

Commit a192006

Browse files
dschoGit for Windows Build Agent
authored and
Git for Windows Build Agent
committed
Merge branch 'close-graph-everywhere'
This topic branch is a backport of gitgitgadget#208, which avoids a lock contention in `git gc --auto` where the `git gc` process holds a read lock to the `commit-graph` file (if `core.commitgraph=true`) and the spawned `git commit-graph write` (if `gc.writecommitgraph=true`) tries to overwrite it. Signed-off-by: Johannes Schindelin <[email protected]>
2 parents 88f160c + a14ad65 commit a192006

14 files changed

+21
-18
lines changed

builtin/am.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1803,7 +1803,7 @@ static void am_run(struct am_state *state, int resume)
18031803
*/
18041804
if (!state->rebasing) {
18051805
am_destroy(state);
1806-
close_all_packs(the_repository->objects);
1806+
close_object_store(the_repository->objects);
18071807
run_command_v_opt(argv_gc_auto, RUN_GIT_CMD);
18081808
}
18091809
}

builtin/clone.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1247,7 +1247,7 @@ int cmd_clone(int argc, const char **argv, const char *prefix)
12471247
transport_disconnect(transport);
12481248

12491249
if (option_dissociate) {
1250-
close_all_packs(the_repository->objects);
1250+
close_object_store(the_repository->objects);
12511251
dissociate_from_references();
12521252
}
12531253

builtin/fetch.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1672,7 +1672,7 @@ int cmd_fetch(int argc, const char **argv, const char *prefix)
16721672

16731673
string_list_clear(&list, 0);
16741674

1675-
close_all_packs(the_repository->objects);
1675+
close_object_store(the_repository->objects);
16761676

16771677
argv_array_pushl(&argv_gc_auto, "gc", "--auto", NULL);
16781678
if (verbosity < 0)

builtin/gc.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -653,7 +653,7 @@ int cmd_gc(int argc, const char **argv, const char *prefix)
653653
gc_before_repack();
654654

655655
if (!repository_format_precious_objects) {
656-
close_all_packs(the_repository->objects);
656+
close_object_store(the_repository->objects);
657657
if (run_command_v_opt(repack.argv, RUN_GIT_CMD))
658658
die(FAILED_RUN, repack.argv[0]);
659659

@@ -681,7 +681,7 @@ int cmd_gc(int argc, const char **argv, const char *prefix)
681681
report_garbage = report_pack_garbage;
682682
reprepare_packed_git(the_repository);
683683
if (pack_garbage.nr > 0) {
684-
close_all_packs(the_repository->objects);
684+
close_object_store(the_repository->objects);
685685
clean_pack_garbage();
686686
}
687687

builtin/merge.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -457,7 +457,7 @@ static void finish(struct commit *head_commit,
457457
* We ignore errors in 'gc --auto', since the
458458
* user should see them.
459459
*/
460-
close_all_packs(the_repository->objects);
460+
close_object_store(the_repository->objects);
461461
run_command_v_opt(argv_gc_auto, RUN_GIT_CMD);
462462
}
463463
}

builtin/rebase.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -741,7 +741,7 @@ static int finish_rebase(struct rebase_options *opts)
741741

742742
delete_ref(NULL, "REBASE_HEAD", NULL, REF_NO_DEREF);
743743
apply_autostash(opts);
744-
close_all_packs(the_repository->objects);
744+
close_object_store(the_repository->objects);
745745
/*
746746
* We ignore errors in 'gc --auto', since the
747747
* user should see them.

builtin/receive-pack.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2043,7 +2043,7 @@ int cmd_receive_pack(int argc, const char **argv, const char *prefix)
20432043
proc.git_cmd = 1;
20442044
proc.argv = argv_gc_auto;
20452045

2046-
close_all_packs(the_repository->objects);
2046+
close_object_store(the_repository->objects);
20472047
if (!start_command(&proc)) {
20482048
if (use_sideband)
20492049
copy_to_sideband(proc.err, -1, NULL);

builtin/repack.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -422,7 +422,7 @@ int cmd_repack(int argc, const char **argv, const char *prefix)
422422
if (!names.nr && !po_args.quiet)
423423
printf_ln(_("Nothing new to pack."));
424424

425-
close_all_packs(the_repository->objects);
425+
close_object_store(the_repository->objects);
426426

427427
/*
428428
* Ok we have prepared all new packfiles.

commit-graph.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -361,10 +361,10 @@ int generation_numbers_enabled(struct repository *r)
361361
return !!first_generation;
362362
}
363363

364-
void close_commit_graph(struct repository *r)
364+
void close_commit_graph(struct raw_object_store *o)
365365
{
366-
free_commit_graph(r->objects->commit_graph);
367-
r->objects->commit_graph = NULL;
366+
free_commit_graph(o->commit_graph);
367+
o->commit_graph = NULL;
368368
}
369369

370370
static int bsearch_graph(struct commit_graph *g, struct object_id *oid, uint32_t *pos)
@@ -1110,7 +1110,7 @@ void write_commit_graph(const char *obj_dir,
11101110
stop_progress(&progress);
11111111
strbuf_release(&progress_title);
11121112

1113-
close_commit_graph(the_repository);
1113+
close_commit_graph(the_repository->objects);
11141114
finalize_hashfile(f, NULL, CSUM_HASH_IN_STREAM | CSUM_FSYNC);
11151115
commit_lock_file(&lk);
11161116

commit-graph.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ void write_commit_graph(const char *obj_dir,
7474

7575
int verify_commit_graph(struct repository *r, struct commit_graph *g);
7676

77-
void close_commit_graph(struct repository *);
77+
void close_commit_graph(struct raw_object_store *);
7878
void free_commit_graph(struct commit_graph *);
7979

8080
#endif

object.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -517,7 +517,7 @@ void raw_object_store_clear(struct raw_object_store *o)
517517
o->loaded_alternates = 0;
518518

519519
INIT_LIST_HEAD(&o->packed_git_mru);
520-
close_all_packs(o);
520+
close_object_store(o);
521521
o->packed_git = NULL;
522522
}
523523

packfile.c

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
#include "tree.h"
1717
#include "object-store.h"
1818
#include "midx.h"
19+
#include "commit-graph.h"
1920

2021
char *odb_pack_name(struct strbuf *buf,
2122
const unsigned char *sha1,
@@ -336,7 +337,7 @@ void close_pack(struct packed_git *p)
336337
close_pack_index(p);
337338
}
338339

339-
void close_all_packs(struct raw_object_store *o)
340+
void close_object_store(struct raw_object_store *o)
340341
{
341342
struct packed_git *p;
342343

@@ -350,6 +351,8 @@ void close_all_packs(struct raw_object_store *o)
350351
close_midx(o->multi_pack_index);
351352
o->multi_pack_index = NULL;
352353
}
354+
355+
close_commit_graph(o);
353356
}
354357

355358
/*

packfile.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ uint32_t get_pack_fanout(struct packed_git *p, uint32_t value);
9090
unsigned char *use_pack(struct packed_git *, struct pack_window **, off_t, unsigned long *);
9191
void close_pack_windows(struct packed_git *);
9292
void close_pack(struct packed_git *);
93-
void close_all_packs(struct raw_object_store *o);
93+
void close_object_store(struct raw_object_store *o);
9494
void unuse_pack(struct pack_window **);
9595
void clear_delta_base_cache(void);
9696
struct packed_git *add_packed_git(const char *path, size_t path_len, int local);

upload-pack.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -722,7 +722,7 @@ static void deepen_by_rev_list(struct packet_writer *writer, int ac,
722722
{
723723
struct commit_list *result;
724724

725-
close_commit_graph(the_repository);
725+
close_commit_graph(the_repository->objects);
726726
result = get_shallow_commits_by_rev_list(ac, av, SHALLOW, NOT_SHALLOW);
727727
send_shallow(writer, result);
728728
free_commit_list(result);

0 commit comments

Comments
 (0)