Skip to content

Commit 13c2499

Browse files
ttaylorrgitster
authored andcommitted
commit-graph.h: store object directory in 'struct commit_graph'
In a previous patch, the 'char *object_dir' in 'struct commit_graph' was replaced with a 'struct object_directory'. This patch applies the same treatment to 'struct commit_graph', which is another intermediate step towards getting rid of all path normalization in 'commit-graph.c'. Instead of taking a 'char *object_dir', functions that construct a 'struct commit_graph' now take a 'struct object_directory *'. Any code that needs an object directory path use '->path' instead. This ensures that all calls to functions that perform path normalization are given arguments which do not themselves require normalization. This prepares those functions to drop their normalization entirely, which will occur in the subsequent patch. Signed-off-by: Taylor Blau <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 0bd52e2 commit 13c2499

File tree

3 files changed

+25
-20
lines changed

3 files changed

+25
-20
lines changed

builtin/commit-graph.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,7 @@ static int graph_verify(int argc, const char **argv)
9898
if (open_ok)
9999
graph = load_commit_graph_one_fd_st(fd, &st);
100100
else
101-
graph = read_commit_graph_one(the_repository, odb->path);
101+
graph = read_commit_graph_one(the_repository, odb);
102102

103103
/* Return failure if open_ok predicted success */
104104
if (!graph)

commit-graph.c

Lines changed: 21 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -327,14 +327,15 @@ static struct commit_graph *load_commit_graph_one(const char *graph_file)
327327
return g;
328328
}
329329

330-
static struct commit_graph *load_commit_graph_v1(struct repository *r, const char *obj_dir)
330+
static struct commit_graph *load_commit_graph_v1(struct repository *r,
331+
struct object_directory *odb)
331332
{
332-
char *graph_name = get_commit_graph_filename(obj_dir);
333+
char *graph_name = get_commit_graph_filename(odb->path);
333334
struct commit_graph *g = load_commit_graph_one(graph_name);
334335
free(graph_name);
335336

336337
if (g)
337-
g->obj_dir = obj_dir;
338+
g->odb = odb;
338339

339340
return g;
340341
}
@@ -372,14 +373,15 @@ static int add_graph_to_chain(struct commit_graph *g,
372373
return 1;
373374
}
374375

375-
static struct commit_graph *load_commit_graph_chain(struct repository *r, const char *obj_dir)
376+
static struct commit_graph *load_commit_graph_chain(struct repository *r,
377+
struct object_directory *odb)
376378
{
377379
struct commit_graph *graph_chain = NULL;
378380
struct strbuf line = STRBUF_INIT;
379381
struct stat st;
380382
struct object_id *oids;
381383
int i = 0, valid = 1, count;
382-
char *chain_name = get_chain_filename(obj_dir);
384+
char *chain_name = get_chain_filename(odb->path);
383385
FILE *fp;
384386
int stat_res;
385387

@@ -418,7 +420,7 @@ static struct commit_graph *load_commit_graph_chain(struct repository *r, const
418420
free(graph_name);
419421

420422
if (g) {
421-
g->obj_dir = odb->path;
423+
g->odb = odb;
422424

423425
if (add_graph_to_chain(g, graph_chain, oids, i)) {
424426
graph_chain = g;
@@ -442,23 +444,25 @@ static struct commit_graph *load_commit_graph_chain(struct repository *r, const
442444
return graph_chain;
443445
}
444446

445-
struct commit_graph *read_commit_graph_one(struct repository *r, const char *obj_dir)
447+
struct commit_graph *read_commit_graph_one(struct repository *r,
448+
struct object_directory *odb)
446449
{
447-
struct commit_graph *g = load_commit_graph_v1(r, obj_dir);
450+
struct commit_graph *g = load_commit_graph_v1(r, odb);
448451

449452
if (!g)
450-
g = load_commit_graph_chain(r, obj_dir);
453+
g = load_commit_graph_chain(r, odb);
451454

452455
return g;
453456
}
454457

455-
static void prepare_commit_graph_one(struct repository *r, const char *obj_dir)
458+
static void prepare_commit_graph_one(struct repository *r,
459+
struct object_directory *odb)
456460
{
457461

458462
if (r->objects->commit_graph)
459463
return;
460464

461-
r->objects->commit_graph = read_commit_graph_one(r, obj_dir);
465+
r->objects->commit_graph = read_commit_graph_one(r, odb);
462466
}
463467

464468
/*
@@ -505,7 +509,7 @@ static int prepare_commit_graph(struct repository *r)
505509
for (odb = r->objects->odb;
506510
!r->objects->commit_graph && odb;
507511
odb = odb->next)
508-
prepare_commit_graph_one(r, odb->path);
512+
prepare_commit_graph_one(r, odb);
509513
return !!r->objects->commit_graph;
510514
}
511515

@@ -1470,7 +1474,7 @@ static int write_commit_graph_file(struct write_commit_graph_context *ctx)
14701474

14711475
if (ctx->split && ctx->base_graph_name && ctx->num_commit_graphs_after > 1) {
14721476
char *new_base_hash = xstrdup(oid_to_hex(&ctx->new_base_graph->oid));
1473-
char *new_base_name = get_split_graph_filename(ctx->new_base_graph->obj_dir, new_base_hash);
1477+
char *new_base_name = get_split_graph_filename(ctx->new_base_graph->odb->path, new_base_hash);
14741478

14751479
free(ctx->commit_graph_filenames_after[ctx->num_commit_graphs_after - 2]);
14761480
free(ctx->commit_graph_hash_after[ctx->num_commit_graphs_after - 2]);
@@ -1553,7 +1557,7 @@ static void split_graph_merge_strategy(struct write_commit_graph_context *ctx)
15531557

15541558
while (g && (g->num_commits <= size_mult * num_commits ||
15551559
(max_commits && num_commits > max_commits))) {
1556-
if (strcmp(g->obj_dir, ctx->odb->path))
1560+
if (strcmp(g->odb->path, ctx->odb->path))
15571561
break;
15581562

15591563
num_commits += g->num_commits;
@@ -1565,10 +1569,10 @@ static void split_graph_merge_strategy(struct write_commit_graph_context *ctx)
15651569
ctx->new_base_graph = g;
15661570

15671571
if (ctx->num_commit_graphs_after == 2) {
1568-
char *old_graph_name = get_commit_graph_filename(g->obj_dir);
1572+
char *old_graph_name = get_commit_graph_filename(g->odb->path);
15691573

15701574
if (!strcmp(g->filename, old_graph_name) &&
1571-
strcmp(g->obj_dir, ctx->odb->path)) {
1575+
strcmp(g->odb->path, ctx->odb->path)) {
15721576
ctx->num_commit_graphs_after = 1;
15731577
ctx->new_base_graph = NULL;
15741578
}
@@ -1816,7 +1820,7 @@ int write_commit_graph(struct object_directory *odb,
18161820
ctx->oids.alloc = split_opts->max_commits;
18171821

18181822
if (ctx->append) {
1819-
prepare_commit_graph_one(ctx->r, ctx->odb->path);
1823+
prepare_commit_graph_one(ctx->r, ctx->odb);
18201824
if (ctx->r->objects->commit_graph)
18211825
ctx->oids.alloc += ctx->r->objects->commit_graph->num_commits;
18221826
}

commit-graph.h

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ struct commit_graph {
4949
uint32_t num_commits;
5050
struct object_id oid;
5151
char *filename;
52-
const char *obj_dir;
52+
struct object_directory *odb;
5353

5454
uint32_t num_commits_in_base;
5555
struct commit_graph *base_graph;
@@ -62,7 +62,8 @@ struct commit_graph {
6262
};
6363

6464
struct commit_graph *load_commit_graph_one_fd_st(int fd, struct stat *st);
65-
struct commit_graph *read_commit_graph_one(struct repository *r, const char *obj_dir);
65+
struct commit_graph *read_commit_graph_one(struct repository *r,
66+
struct object_directory *odb);
6667
struct commit_graph *parse_commit_graph(void *graph_map, int fd,
6768
size_t graph_size);
6869

0 commit comments

Comments
 (0)