Skip to content

Commit 0b3b63b

Browse files
committed
commit-graph: close_commit_graph before shallow walk
Make close_commit_graph() work for arbitrary repositories. Call close_commit_graph() when about to start a rev-list walk that includes shallow commits. This is necessary in code paths that "fake" shallow commits for the sake of fetch. Specifically, test 351 in t5500-fetch-pack.sh runs git fetch --shallow-exclude one origin with a file-based transfer. When the "remote" has a commit-graph, we do not prevent the commit-graph from being loaded, but then the commits are intended to be dynamically transferred into shallow commits during get_shallow_commits_by_rev_list(). By closing the commit-graph before this call, we prevent this interaction. Signed-off-by: Derrick Stolee <[email protected]>
1 parent ac64a88 commit 0b3b63b

File tree

3 files changed

+7
-4
lines changed

3 files changed

+7
-4
lines changed

commit-graph.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -257,10 +257,10 @@ static int prepare_commit_graph(struct repository *r)
257257
return !!r->objects->commit_graph;
258258
}
259259

260-
static void close_commit_graph(void)
260+
void close_commit_graph(struct repository *r)
261261
{
262-
free_commit_graph(the_repository->objects->commit_graph);
263-
the_repository->objects->commit_graph = NULL;
262+
free_commit_graph(r->objects->commit_graph);
263+
r->objects->commit_graph = NULL;
264264
}
265265

266266
static int bsearch_graph(struct commit_graph *g, struct object_id *oid, uint32_t *pos)
@@ -872,7 +872,7 @@ void write_commit_graph(const char *obj_dir,
872872
write_graph_chunk_data(f, GRAPH_OID_LEN, commits.list, commits.nr);
873873
write_graph_chunk_large_edges(f, commits.list, commits.nr);
874874

875-
close_commit_graph();
875+
close_commit_graph(the_repository);
876876
finalize_hashfile(f, NULL, CSUM_HASH_IN_STREAM | CSUM_FSYNC);
877877
commit_lock_file(&lk);
878878

commit-graph.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,7 @@ void write_commit_graph(const char *obj_dir,
5959

6060
int verify_commit_graph(struct repository *r, struct commit_graph *g);
6161

62+
void close_commit_graph(struct repository *);
6263
void free_commit_graph(struct commit_graph *);
6364

6465
#endif

upload-pack.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
#include "quote.h"
2525
#include "upload-pack.h"
2626
#include "serve.h"
27+
#include "commit-graph.h"
2728

2829
/* Remember to update object flag allocation in object.h */
2930
#define THEY_HAVE (1u << 11)
@@ -739,6 +740,7 @@ static void deepen_by_rev_list(int ac, const char **av,
739740
{
740741
struct commit_list *result;
741742

743+
close_commit_graph(the_repository);
742744
result = get_shallow_commits_by_rev_list(ac, av, SHALLOW, NOT_SHALLOW);
743745
send_shallow(result);
744746
free_commit_list(result);

0 commit comments

Comments
 (0)