Git fork

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

authored by

Patrick Steinhardt and committed by
Junio C Hamano
89cc9b9a f1141b43

+18 -15
+2 -1
builtin/commit-graph.c
··· 109 109 opened = OPENED_GRAPH; 110 110 else if (errno != ENOENT) 111 111 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)) 113 114 opened = OPENED_CHAIN; 114 115 else if (errno != ENOENT) 115 116 die_errno(_("could not open commit-graph chain '%s'"), chain_name);
+14 -13
commit-graph.c
··· 265 265 266 266 graph_size = xsize_t(st->st_size); 267 267 268 - if (graph_size < graph_min_size(the_hash_algo)) { 268 + if (graph_size < graph_min_size(r->hash_algo)) { 269 269 close(fd); 270 270 error(_("commit-graph file is too small")); 271 271 return NULL; ··· 320 320 size_t chunk_size, void *data) 321 321 { 322 322 struct commit_graph *g = data; 323 - if (chunk_size / graph_data_width(the_hash_algo) != g->num_commits) 323 + if (chunk_size / graph_data_width(g->hash_algo) != g->num_commits) 324 324 return error(_("commit-graph commit data chunk is wrong size")); 325 325 g->chunk_commit_data = chunk_start; 326 326 return 0; ··· 621 621 } 622 622 623 623 int open_commit_graph_chain(const char *chain_file, 624 - int *fd, struct stat *st) 624 + int *fd, struct stat *st, 625 + const struct git_hash_algo *hash_algo) 625 626 { 626 627 *fd = git_open(chain_file); 627 628 if (*fd < 0) ··· 630 631 close(*fd); 631 632 return 0; 632 633 } 633 - if (st->st_size < the_hash_algo->hexsz) { 634 + if (st->st_size < hash_algo->hexsz) { 634 635 close(*fd); 635 636 if (!st->st_size) { 636 637 /* treat empty files the same as missing */ ··· 654 655 int i = 0, valid = 1, count; 655 656 FILE *fp = xfdopen(fd, "r"); 656 657 657 - count = st->st_size / (the_hash_algo->hexsz + 1); 658 + count = st->st_size / (r->hash_algo->hexsz + 1); 658 659 CALLOC_ARRAY(oids, count); 659 660 660 661 odb_prepare_alternates(r->objects); ··· 716 717 int fd; 717 718 struct commit_graph *g = NULL; 718 719 719 - if (open_commit_graph_chain(chain_file, &fd, &st)) { 720 + if (open_commit_graph_chain(chain_file, &fd, &st, r->hash_algo)) { 720 721 int incomplete; 721 722 /* ownership of fd is taken over by load function */ 722 723 g = load_commit_graph_chain_fd_st(r, fd, &st, &incomplete); ··· 908 909 die(_("invalid commit position. commit-graph is likely corrupt")); 909 910 910 911 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); 912 913 913 914 graph_data = commit_graph_data_at(item); 914 915 graph_data->graph_pos = pos; ··· 1112 1113 g = g->base_graph; 1113 1114 1114 1115 commit_data = g->chunk_commit_data + 1115 - st_mult(graph_data_width(the_hash_algo), 1116 + st_mult(graph_data_width(g->hash_algo), 1116 1117 graph_pos - g->num_commits_in_base); 1117 1118 1118 1119 oidread(&oid, commit_data, the_repository->hash_algo); ··· 1221 1222 int count; 1222 1223 for (count = 0; count < ctx->commits.nr; count++, list++) { 1223 1224 display_progress(ctx->progress, ++ctx->progress_cnt); 1224 - hashwrite(f, (*list)->object.oid.hash, the_hash_algo->rawsz); 1225 + hashwrite(f, (*list)->object.oid.hash, f->algop->rawsz); 1225 1226 } 1226 1227 1227 1228 return 0; ··· 1252 1253 die(_("unable to parse commit %s"), 1253 1254 oid_to_hex(&(*list)->object.oid)); 1254 1255 tree = get_commit_tree_oid(*list); 1255 - hashwrite(f, tree->hash, the_hash_algo->rawsz); 1256 + hashwrite(f, tree->hash, ctx->r->hash_algo->rawsz); 1256 1257 1257 1258 parent = (*list)->parents; 1258 1259 ··· 2035 2036 return 0; 2036 2037 2037 2038 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); 2039 2040 return num + 1; 2040 2041 } 2041 2042 ··· 2059 2060 struct hashfile *f; 2060 2061 struct tempfile *graph_layer; /* when ctx->split is non-zero */ 2061 2062 struct lock_file lk = LOCK_INIT; 2062 - const unsigned hashsz = the_hash_algo->rawsz; 2063 + const unsigned hashsz = ctx->r->hash_algo->rawsz; 2063 2064 struct strbuf progress_title = STRBUF_INIT; 2064 2065 struct chunkfile *cf; 2065 2066 unsigned char file_hash[GIT_MAX_RAWSZ]; ··· 2147 2148 hashwrite_be32(f, GRAPH_SIGNATURE); 2148 2149 2149 2150 hashwrite_u8(f, GRAPH_VERSION); 2150 - hashwrite_u8(f, oid_version(the_hash_algo)); 2151 + hashwrite_u8(f, oid_version(ctx->r->hash_algo)); 2151 2152 hashwrite_u8(f, get_num_chunks(cf)); 2152 2153 hashwrite_u8(f, ctx->num_commit_graphs_after - 1); 2153 2154
+2 -1
commit-graph.h
··· 32 32 char *get_commit_graph_filename(struct odb_source *source); 33 33 char *get_commit_graph_chain_filename(struct odb_source *source); 34 34 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); 36 37 37 38 /* 38 39 * Given a commit struct, try to fill the commit struct info, including: