Skip to content

Commit 7f596c1

Browse files
committed
commit-graph: not compatible with replace objects
Create new method commit_graph_compatible(r) to check if a given repository r is compatible with the commit-graph feature. Fill the method with a check to see if replace-objects exist. Test this interaction succeeds, including ignoring an existing commit-graph and failing to write a new commit-graph. Signed-off-by: Derrick Stolee <[email protected]>
1 parent 88711a3 commit 7f596c1

File tree

4 files changed

+42
-1
lines changed

4 files changed

+42
-1
lines changed

commit-graph.c

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@
1313
#include "commit-graph.h"
1414
#include "object-store.h"
1515
#include "alloc.h"
16+
#include "hashmap.h"
17+
#include "replace-object.h"
1618

1719
#define GRAPH_SIGNATURE 0x43475048 /* "CGPH" */
1820
#define GRAPH_CHUNKID_OIDFANOUT 0x4f494446 /* "OIDF" */
@@ -56,6 +58,15 @@ static struct commit_graph *alloc_commit_graph(void)
5658
return g;
5759
}
5860

61+
static int commit_graph_compatible(struct repository *r)
62+
{
63+
prepare_replace_object(r);
64+
if (hashmap_get_size(&r->objects->replace_map->map))
65+
return 0;
66+
67+
return 1;
68+
}
69+
5970
struct commit_graph *load_commit_graph_one(const char *graph_file)
6071
{
6172
void *graph_map;
@@ -223,6 +234,9 @@ static int prepare_commit_graph(struct repository *r)
223234
*/
224235
return 0;
225236

237+
if (!commit_graph_compatible(r))
238+
return 0;
239+
226240
obj_dir = r->objects->objectdir;
227241
prepare_commit_graph_one(r, obj_dir);
228242
prepare_alt_odb(r);
@@ -693,6 +707,9 @@ void write_commit_graph(const char *obj_dir,
693707
int num_extra_edges;
694708
struct commit_list *parent;
695709

710+
if (!commit_graph_compatible(the_repository))
711+
return;
712+
696713
oids.nr = 0;
697714
oids.alloc = approximate_object_count() / 4;
698715

replace-object.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ static int register_replace_ref(struct repository *r,
3232
return 0;
3333
}
3434

35-
static void prepare_replace_object(struct repository *r)
35+
void prepare_replace_object(struct repository *r)
3636
{
3737
if (r->objects->replace_map)
3838
return;

replace-object.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@ struct replace_object {
1010
struct object_id replacement;
1111
};
1212

13+
void prepare_replace_object(struct repository *r);
14+
1315
/*
1416
* This internal function is only declared here for the benefit of
1517
* lookup_replace_object(). Please do not call it directly.

t/t5318-commit-graph.sh

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -259,6 +259,28 @@ test_expect_success 'check that gc computes commit-graph' '
259259
test_cmp commit-graph-after-gc $objdir/info/commit-graph
260260
'
261261

262+
test_expect_success 'replace-objects invalidates commit-graph' '
263+
cd "$TRASH_DIRECTORY" &&
264+
test_when_finished rm -rf replace &&
265+
git clone full replace &&
266+
(
267+
cd replace &&
268+
git commit-graph write --reachable &&
269+
test_path_is_file .git/objects/info/commit-graph &&
270+
git replace HEAD~1 HEAD~2 &&
271+
git -c core.commitGraph=false log >expect &&
272+
git -c core.commitGraph=true log >actual &&
273+
test_cmp expect actual &&
274+
git commit-graph write --reachable &&
275+
git -c core.commitGraph=false --no-replace-objects log >expect &&
276+
git -c core.commitGraph=true --no-replace-objects log >actual &&
277+
test_cmp expect actual &&
278+
rm -rf .git/objects/info/commit-graph &&
279+
git commit-graph write --reachable &&
280+
test_path_is_missing .git/objects/info/commit-graph
281+
)
282+
'
283+
262284
# the verify tests below expect the commit-graph to contain
263285
# exactly the commits reachable from the commits/8 branch.
264286
# If the file changes the set of commits in the list, then the

0 commit comments

Comments
 (0)