Skip to content

Commit d20c6db

Browse files
pks-tgitster
authored andcommitted
commit-graph: stop using the_hash_algo
Stop using `the_hash_algo` as it implicitly relies on `the_repository`. Instead, we either use the hash algo provided via the context or, if there is no such hash algo, we use `the_repository` explicitly. Such uses will be removed in subsequent commits. Signed-off-by: Patrick Steinhardt <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent aee7878 commit d20c6db

File tree

3 files changed

+18
-15
lines changed

3 files changed

+18
-15
lines changed

builtin/commit-graph.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,8 @@ static int graph_verify(int argc, const char **argv, const char *prefix,
109109
opened = OPENED_GRAPH;
110110
else if (errno != ENOENT)
111111
die_errno(_("Could not open commit-graph '%s'"), graph_name);
112-
else if (open_commit_graph_chain(chain_name, &fd, &st))
112+
else if (open_commit_graph_chain(chain_name, &fd, &st,
113+
the_repository->hash_algo))
113114
opened = OPENED_CHAIN;
114115
else if (errno != ENOENT)
115116
die_errno(_("could not open commit-graph chain '%s'"), chain_name);

commit-graph.c

Lines changed: 14 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -264,7 +264,7 @@ struct commit_graph *load_commit_graph_one_fd_st(struct repository *r,
264264

265265
graph_size = xsize_t(st->st_size);
266266

267-
if (graph_size < graph_min_size(the_hash_algo)) {
267+
if (graph_size < graph_min_size(r->hash_algo)) {
268268
close(fd);
269269
error(_("commit-graph file is too small"));
270270
return NULL;
@@ -319,7 +319,7 @@ static int graph_read_commit_data(const unsigned char *chunk_start,
319319
size_t chunk_size, void *data)
320320
{
321321
struct commit_graph *g = data;
322-
if (chunk_size / graph_data_width(the_hash_algo) != g->num_commits)
322+
if (chunk_size / graph_data_width(g->hash_algo) != g->num_commits)
323323
return error(_("commit-graph commit data chunk is wrong size"));
324324
g->chunk_commit_data = chunk_start;
325325
return 0;
@@ -620,7 +620,8 @@ static int add_graph_to_chain(struct commit_graph *g,
620620
}
621621

622622
int open_commit_graph_chain(const char *chain_file,
623-
int *fd, struct stat *st)
623+
int *fd, struct stat *st,
624+
const struct git_hash_algo *hash_algo)
624625
{
625626
*fd = git_open(chain_file);
626627
if (*fd < 0)
@@ -629,7 +630,7 @@ int open_commit_graph_chain(const char *chain_file,
629630
close(*fd);
630631
return 0;
631632
}
632-
if (st->st_size < (ssize_t) the_hash_algo->hexsz) {
633+
if (st->st_size < (ssize_t) hash_algo->hexsz) {
633634
close(*fd);
634635
if (!st->st_size) {
635636
/* treat empty files the same as missing */
@@ -654,7 +655,7 @@ struct commit_graph *load_commit_graph_chain_fd_st(struct repository *r,
654655
FILE *fp = xfdopen(fd, "r");
655656
size_t count;
656657

657-
count = st->st_size / (the_hash_algo->hexsz + 1);
658+
count = st->st_size / (r->hash_algo->hexsz + 1);
658659
CALLOC_ARRAY(oids, count);
659660

660661
odb_prepare_alternates(r->objects);
@@ -716,7 +717,7 @@ static struct commit_graph *load_commit_graph_chain(struct repository *r,
716717
int fd;
717718
struct commit_graph *g = NULL;
718719

719-
if (open_commit_graph_chain(chain_file, &fd, &st)) {
720+
if (open_commit_graph_chain(chain_file, &fd, &st, r->hash_algo)) {
720721
int incomplete;
721722
/* ownership of fd is taken over by load function */
722723
g = load_commit_graph_chain_fd_st(r, fd, &st, &incomplete);
@@ -908,7 +909,7 @@ static void fill_commit_graph_info(struct commit *item, struct commit_graph *g,
908909
die(_("invalid commit position. commit-graph is likely corrupt"));
909910

910911
lex_index = pos - g->num_commits_in_base;
911-
commit_data = g->chunk_commit_data + st_mult(graph_data_width(the_hash_algo), lex_index);
912+
commit_data = g->chunk_commit_data + st_mult(graph_data_width(g->hash_algo), lex_index);
912913

913914
graph_data = commit_graph_data_at(item);
914915
graph_data->graph_pos = pos;
@@ -1112,7 +1113,7 @@ static struct tree *load_tree_for_commit(struct repository *r,
11121113
g = g->base_graph;
11131114

11141115
commit_data = g->chunk_commit_data +
1115-
st_mult(graph_data_width(the_hash_algo),
1116+
st_mult(graph_data_width(g->hash_algo),
11161117
graph_pos - g->num_commits_in_base);
11171118

11181119
oidread(&oid, commit_data, the_repository->hash_algo);
@@ -1222,7 +1223,7 @@ static int write_graph_chunk_oids(struct hashfile *f,
12221223

12231224
for (count = 0; count < ctx->commits.nr; count++, list++) {
12241225
display_progress(ctx->progress, ++ctx->progress_cnt);
1225-
hashwrite(f, (*list)->object.oid.hash, the_hash_algo->rawsz);
1226+
hashwrite(f, (*list)->object.oid.hash, f->algop->rawsz);
12261227
}
12271228

12281229
return 0;
@@ -1253,7 +1254,7 @@ static int write_graph_chunk_data(struct hashfile *f,
12531254
die(_("unable to parse commit %s"),
12541255
oid_to_hex(&(*list)->object.oid));
12551256
tree = get_commit_tree_oid(*list);
1256-
hashwrite(f, tree->hash, the_hash_algo->rawsz);
1257+
hashwrite(f, tree->hash, ctx->r->hash_algo->rawsz);
12571258

12581259
parent = (*list)->parents;
12591260

@@ -2035,7 +2036,7 @@ static size_t write_graph_chunk_base_1(struct hashfile *f,
20352036
return 0;
20362037

20372038
num = write_graph_chunk_base_1(f, g->base_graph);
2038-
hashwrite(f, g->oid.hash, the_hash_algo->rawsz);
2039+
hashwrite(f, g->oid.hash, g->hash_algo->rawsz);
20392040
return num + 1;
20402041
}
20412042

@@ -2059,7 +2060,7 @@ static int write_commit_graph_file(struct write_commit_graph_context *ctx)
20592060
struct hashfile *f;
20602061
struct tempfile *graph_layer; /* when ctx->split is non-zero */
20612062
struct lock_file lk = LOCK_INIT;
2062-
const unsigned hashsz = the_hash_algo->rawsz;
2063+
const unsigned hashsz = ctx->r->hash_algo->rawsz;
20632064
struct strbuf progress_title = STRBUF_INIT;
20642065
struct chunkfile *cf;
20652066
unsigned char file_hash[GIT_MAX_RAWSZ];
@@ -2147,7 +2148,7 @@ static int write_commit_graph_file(struct write_commit_graph_context *ctx)
21472148
hashwrite_be32(f, GRAPH_SIGNATURE);
21482149

21492150
hashwrite_u8(f, GRAPH_VERSION);
2150-
hashwrite_u8(f, oid_version(the_hash_algo));
2151+
hashwrite_u8(f, oid_version(ctx->r->hash_algo));
21512152
hashwrite_u8(f, get_num_chunks(cf));
21522153
hashwrite_u8(f, ctx->num_commit_graphs_after - 1);
21532154

commit-graph.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,8 @@ struct string_list;
3232
char *get_commit_graph_filename(struct odb_source *source);
3333
char *get_commit_graph_chain_filename(struct odb_source *source);
3434
int open_commit_graph(const char *graph_file, int *fd, struct stat *st);
35-
int open_commit_graph_chain(const char *chain_file, int *fd, struct stat *st);
35+
int open_commit_graph_chain(const char *chain_file, int *fd, struct stat *st,
36+
const struct git_hash_algo *hash_algo);
3637

3738
/*
3839
* Given a commit struct, try to fill the commit struct info, including:

0 commit comments

Comments
 (0)