Skip to content

Commit 18323f5

Browse files
pks-tgitster
authored andcommitted
object-file: stop using the_hash_algo
There are a couple of users of the `the_hash_algo` macro, which implicitly depends on `the_repository`. Adapt these callers to not do so anymore, either by deriving it from already-available context or by using `the_repository->hash_algo`. The latter variant doesn't yet help to remove the global dependency, but such users will be adapted in the following commits to not use `the_repository` anymore. Signed-off-by: Patrick Steinhardt <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 80e7f52 commit 18323f5

File tree

2 files changed

+25
-16
lines changed

2 files changed

+25
-16
lines changed

object-file.c

Lines changed: 24 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
#include "pack.h"
2626
#include "packfile.h"
2727
#include "path.h"
28+
#include "read-cache-ll.h"
2829
#include "setup.h"
2930
#include "streaming.h"
3031

@@ -41,9 +42,11 @@ static int get_conv_flags(unsigned flags)
4142
return 0;
4243
}
4344

44-
static void fill_loose_path(struct strbuf *buf, const struct object_id *oid)
45+
static void fill_loose_path(struct strbuf *buf,
46+
const struct object_id *oid,
47+
const struct git_hash_algo *algop)
4548
{
46-
for (size_t i = 0; i < the_hash_algo->rawsz; i++) {
49+
for (size_t i = 0; i < algop->rawsz; i++) {
4750
static char hex[] = "0123456789abcdef";
4851
unsigned int val = oid->hash[i];
4952
strbuf_addch(buf, hex[val >> 4]);
@@ -60,7 +63,7 @@ const char *odb_loose_path(struct odb_source *source,
6063
strbuf_reset(buf);
6164
strbuf_addstr(buf, source->path);
6265
strbuf_addch(buf, '/');
63-
fill_loose_path(buf, oid);
66+
fill_loose_path(buf, oid, source->odb->repo->hash_algo);
6467
return buf->buf;
6568
}
6669

@@ -1165,15 +1168,15 @@ static int index_mem(struct index_state *istate,
11651168

11661169
opts.strict = 1;
11671170
opts.error_func = hash_format_check_report;
1168-
if (fsck_buffer(null_oid(the_hash_algo), type, buf, size, &opts))
1171+
if (fsck_buffer(null_oid(istate->repo->hash_algo), type, buf, size, &opts))
11691172
die(_("refusing to create malformed object"));
11701173
fsck_finish(&opts);
11711174
}
11721175

11731176
if (write_object)
11741177
ret = write_object_file(buf, size, type, oid);
11751178
else
1176-
hash_object_file(the_hash_algo, buf, size, type, oid);
1179+
hash_object_file(istate->repo->hash_algo, buf, size, type, oid);
11771180

11781181
strbuf_release(&nbuf);
11791182
return ret;
@@ -1199,7 +1202,7 @@ static int index_stream_convert_blob(struct index_state *istate,
11991202
ret = write_object_file(sbuf.buf, sbuf.len, OBJ_BLOB,
12001203
oid);
12011204
else
1202-
hash_object_file(the_hash_algo, sbuf.buf, sbuf.len, OBJ_BLOB,
1205+
hash_object_file(istate->repo->hash_algo, sbuf.buf, sbuf.len, OBJ_BLOB,
12031206
oid);
12041207
strbuf_release(&sbuf);
12051208
return ret;
@@ -1297,7 +1300,7 @@ int index_path(struct index_state *istate, struct object_id *oid,
12971300
if (strbuf_readlink(&sb, path, st->st_size))
12981301
return error_errno("readlink(\"%s\")", path);
12991302
if (!(flags & INDEX_WRITE_OBJECT))
1300-
hash_object_file(the_hash_algo, sb.buf, sb.len,
1303+
hash_object_file(istate->repo->hash_algo, sb.buf, sb.len,
13011304
OBJ_BLOB, oid);
13021305
else if (write_object_file(sb.buf, sb.len, OBJ_BLOB, oid))
13031306
rc = error(_("%s: failed to insert into database"), path);
@@ -1328,6 +1331,7 @@ int read_pack_header(int fd, struct pack_header *header)
13281331

13291332
int for_each_file_in_obj_subdir(unsigned int subdir_nr,
13301333
struct strbuf *path,
1334+
const struct git_hash_algo *algop,
13311335
each_loose_object_fn obj_cb,
13321336
each_loose_cruft_fn cruft_cb,
13331337
each_loose_subdir_fn subdir_cb,
@@ -1364,12 +1368,12 @@ int for_each_file_in_obj_subdir(unsigned int subdir_nr,
13641368
namelen = strlen(de->d_name);
13651369
strbuf_setlen(path, baselen);
13661370
strbuf_add(path, de->d_name, namelen);
1367-
if (namelen == the_hash_algo->hexsz - 2 &&
1371+
if (namelen == algop->hexsz - 2 &&
13681372
!hex_to_bytes(oid.hash + 1, de->d_name,
1369-
the_hash_algo->rawsz - 1)) {
1370-
oid_set_algo(&oid, the_hash_algo);
1371-
memset(oid.hash + the_hash_algo->rawsz, 0,
1372-
GIT_MAX_RAWSZ - the_hash_algo->rawsz);
1373+
algop->rawsz - 1)) {
1374+
oid_set_algo(&oid, algop);
1375+
memset(oid.hash + algop->rawsz, 0,
1376+
GIT_MAX_RAWSZ - algop->rawsz);
13731377
if (obj_cb) {
13741378
r = obj_cb(&oid, path->buf, data);
13751379
if (r)
@@ -1405,7 +1409,8 @@ int for_each_loose_file_in_objdir_buf(struct strbuf *path,
14051409
int i;
14061410

14071411
for (i = 0; i < 256; i++) {
1408-
r = for_each_file_in_obj_subdir(i, path, obj_cb, cruft_cb,
1412+
r = for_each_file_in_obj_subdir(i, path, the_repository->hash_algo,
1413+
obj_cb, cruft_cb,
14091414
subdir_cb, data);
14101415
if (r)
14111416
break;
@@ -1481,6 +1486,7 @@ struct oidtree *odb_loose_cache(struct odb_source *source,
14811486
}
14821487
strbuf_addstr(&buf, source->path);
14831488
for_each_file_in_obj_subdir(subdir_nr, &buf,
1489+
source->odb->repo->hash_algo,
14841490
append_loose_object,
14851491
NULL, NULL,
14861492
source->loose_objects_cache);
@@ -1501,15 +1507,16 @@ static int check_stream_oid(git_zstream *stream,
15011507
const char *hdr,
15021508
unsigned long size,
15031509
const char *path,
1504-
const struct object_id *expected_oid)
1510+
const struct object_id *expected_oid,
1511+
const struct git_hash_algo *algop)
15051512
{
15061513
struct git_hash_ctx c;
15071514
struct object_id real_oid;
15081515
unsigned char buf[4096];
15091516
unsigned long total_read;
15101517
int status = Z_OK;
15111518

1512-
the_hash_algo->init_fn(&c);
1519+
algop->init_fn(&c);
15131520
git_hash_update(&c, hdr, stream->total_out);
15141521

15151522
/*
@@ -1594,7 +1601,8 @@ int read_loose_object(const char *path,
15941601

15951602
if (*oi->typep == OBJ_BLOB &&
15961603
*size > repo_settings_get_big_file_threshold(the_repository)) {
1597-
if (check_stream_oid(&stream, hdr, *size, path, expected_oid) < 0)
1604+
if (check_stream_oid(&stream, hdr, *size, path, expected_oid,
1605+
the_repository->hash_algo) < 0)
15981606
goto out_inflate;
15991607
} else {
16001608
*contents = unpack_loose_rest(&stream, hdr, *size, expected_oid);

object-file.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,7 @@ typedef int each_loose_subdir_fn(unsigned int nr,
8989
void *data);
9090
int for_each_file_in_obj_subdir(unsigned int subdir_nr,
9191
struct strbuf *path,
92+
const struct git_hash_algo *algo,
9293
each_loose_object_fn obj_cb,
9394
each_loose_cruft_fn cruft_cb,
9495
each_loose_subdir_fn subdir_cb,

0 commit comments

Comments
 (0)