@matheusbsbs / matheus-bagliano / commits / 13c2499249
Fork 0

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 <me@ttaylorr.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Taylor Blau committed Feb 3, 2020 at 13:18 UTC 13c249924995d504001eb8083fac106041b32f98
3 files changed +25 -20
builtin/commit-graph.c
+1 -1
@@ -98,7 +98,7 @@ static int graph_verify(int argc, const char **argv)
98 if (open_ok)
99 graph = load_commit_graph_one_fd_st(fd, &st);
100 else
101 - graph = read_commit_graph_one(the_repository, odb->path);
101 + graph = read_commit_graph_one(the_repository, odb);
102
103 /* Return failure if open_ok predicted success */
104 if (!graph)
commit-graph.c
+21 -17
@@ -327,14 +327,15 @@ static struct commit_graph *load_commit_graph_one(const char *graph_file)
327 return g;
328 }
329
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)
332 {
332 - char *graph_name = get_commit_graph_filename(obj_dir);
333 + char *graph_name = get_commit_graph_filename(odb->path);
334 struct commit_graph *g = load_commit_graph_one(graph_name);
335 free(graph_name);
336
337 if (g)
337 - g->obj_dir = obj_dir;
338 + g->odb = odb;
339
340 return g;
341 }
@@ -372,14 +373,15 @@ static int add_graph_to_chain(struct commit_graph *g,
373 return 1;
374 }
375
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)
378 {
379 struct commit_graph *graph_chain = NULL;
380 struct strbuf line = STRBUF_INIT;
381 struct stat st;
382 struct object_id *oids;
383 int i = 0, valid = 1, count;
382 - char *chain_name = get_chain_filename(obj_dir);
384 + char *chain_name = get_chain_filename(odb->path);
385 FILE *fp;
386 int stat_res;
387
@@ -418,7 +420,7 @@ static struct commit_graph *load_commit_graph_chain(struct repository *r, const
420 free(graph_name);
421
422 if (g) {
421 - g->obj_dir = odb->path;
423 + g->odb = odb;
424
425 if (add_graph_to_chain(g, graph_chain, oids, i)) {
426 graph_chain = g;
@@ -442,23 +444,25 @@ static struct commit_graph *load_commit_graph_chain(struct repository *r, const
444 return graph_chain;
445 }
446
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)
449 {
447 - struct commit_graph *g = load_commit_graph_v1(r, obj_dir);
450 + struct commit_graph *g = load_commit_graph_v1(r, odb);
451
452 if (!g)
450 - g = load_commit_graph_chain(r, obj_dir);
453 + g = load_commit_graph_chain(r, odb);
454
455 return g;
456 }
457
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)
460 {
461
462 if (r->objects->commit_graph)
463 return;
464
461 - r->objects->commit_graph = read_commit_graph_one(r, obj_dir);
465 + r->objects->commit_graph = read_commit_graph_one(r, odb);
466 }
467
468 /*
@@ -505,7 +509,7 @@ static int prepare_commit_graph(struct repository *r)
509 for (odb = r->objects->odb;
510 !r->objects->commit_graph && odb;
511 odb = odb->next)
508 - prepare_commit_graph_one(r, odb->path);
512 + prepare_commit_graph_one(r, odb);
513 return !!r->objects->commit_graph;
514 }
515
@@ -1470,7 +1474,7 @@ static int write_commit_graph_file(struct write_commit_graph_context *ctx)
1474
1475 if (ctx->split && ctx->base_graph_name && ctx->num_commit_graphs_after > 1) {
1476 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);
1478
1479 free(ctx->commit_graph_filenames_after[ctx->num_commit_graphs_after - 2]);
1480 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)
1557
1558 while (g && (g->num_commits <= size_mult * num_commits ||
1559 (max_commits && num_commits > max_commits))) {
1556 - if (strcmp(g->obj_dir, ctx->odb->path))
1560 + if (strcmp(g->odb->path, ctx->odb->path))
1561 break;
1562
1563 num_commits += g->num_commits;
@@ -1565,10 +1569,10 @@ static void split_graph_merge_strategy(struct write_commit_graph_context *ctx)
1569 ctx->new_base_graph = g;
1570
1571 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);
1573
1574 if (!strcmp(g->filename, old_graph_name) &&
1571 - strcmp(g->obj_dir, ctx->odb->path)) {
1575 + strcmp(g->odb->path, ctx->odb->path)) {
1576 ctx->num_commit_graphs_after = 1;
1577 ctx->new_base_graph = NULL;
1578 }
@@ -1816,7 +1820,7 @@ int write_commit_graph(struct object_directory *odb,
1820 ctx->oids.alloc = split_opts->max_commits;
1821
1822 if (ctx->append) {
1819 - prepare_commit_graph_one(ctx->r, ctx->odb->path);
1823 + prepare_commit_graph_one(ctx->r, ctx->odb);
1824 if (ctx->r->objects->commit_graph)
1825 ctx->oids.alloc += ctx->r->objects->commit_graph->num_commits;
1826 }
commit-graph.h
+3 -2
@@ -49,7 +49,7 @@ struct commit_graph {
49 uint32_t num_commits;
50 struct object_id oid;
51 char *filename;
52 - const char *obj_dir;
52 + struct object_directory *odb;
53
54 uint32_t num_commits_in_base;
55 struct commit_graph *base_graph;
@@ -62,7 +62,8 @@ struct commit_graph {
62 };
63
64 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);
67 struct commit_graph *parse_commit_graph(void *graph_map, int fd,
68 size_t graph_size);
69