Skip to content

Commit 78e67cd

Browse files
committed
Merge branch 'mt/use-passed-repo-more-in-funcs'
Some codepaths were given a repository instance as a parameter to work in the repository, but passed the_repository instance to its callees, which has been cleaned up (somewhat). * mt/use-passed-repo-more-in-funcs: sha1-file: allow check_object_signature() to handle any repo sha1-file: pass git_hash_algo to hash_object_file() sha1-file: pass git_hash_algo to write_object_file_prepare() streaming: allow open_istream() to handle any repo pack-check: use given repo's hash_algo at verify_packfile() cache-tree: use given repo's hash_algo at verify_one() diff: make diff_populate_filespec() honor its repo argument
2 parents df04a31 + b98d188 commit 78e67cd

22 files changed

+106
-76
lines changed

apply.c

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3157,7 +3157,8 @@ static int apply_binary(struct apply_state *state,
31573157
* See if the old one matches what the patch
31583158
* applies to.
31593159
*/
3160-
hash_object_file(img->buf, img->len, blob_type, &oid);
3160+
hash_object_file(the_hash_algo, img->buf, img->len, blob_type,
3161+
&oid);
31613162
if (strcmp(oid_to_hex(&oid), patch->old_oid_prefix))
31623163
return error(_("the patch applies to '%s' (%s), "
31633164
"which does not match the "
@@ -3202,7 +3203,8 @@ static int apply_binary(struct apply_state *state,
32023203
name);
32033204

32043205
/* verify that the result matches */
3205-
hash_object_file(img->buf, img->len, blob_type, &oid);
3206+
hash_object_file(the_hash_algo, img->buf, img->len, blob_type,
3207+
&oid);
32063208
if (strcmp(oid_to_hex(&oid), patch->new_oid_prefix))
32073209
return error(_("binary patch to '%s' creates incorrect result (expecting %s, got %s)"),
32083210
name, patch->new_oid_prefix, oid_to_hex(&oid));

archive-tar.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -112,15 +112,15 @@ static void write_trailer(void)
112112
* queues up writes, so that all our write(2) calls write exactly one
113113
* full block; pads writes to RECORDSIZE
114114
*/
115-
static int stream_blocked(const struct object_id *oid)
115+
static int stream_blocked(struct repository *r, const struct object_id *oid)
116116
{
117117
struct git_istream *st;
118118
enum object_type type;
119119
unsigned long sz;
120120
char buf[BLOCKSIZE];
121121
ssize_t readlen;
122122

123-
st = open_istream(oid, &type, &sz, NULL);
123+
st = open_istream(r, oid, &type, &sz, NULL);
124124
if (!st)
125125
return error(_("cannot stream blob %s"), oid_to_hex(oid));
126126
for (;;) {
@@ -324,7 +324,7 @@ static int write_tar_entry(struct archiver_args *args,
324324
if (buffer)
325325
write_blocked(buffer, size);
326326
else
327-
err = stream_blocked(oid);
327+
err = stream_blocked(args->repo, oid);
328328
}
329329
free(buffer);
330330
return err;

archive-zip.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -345,7 +345,8 @@ static int write_zip_entry(struct archiver_args *args,
345345

346346
if (S_ISREG(mode) && type == OBJ_BLOB && !args->convert &&
347347
size > big_file_threshold) {
348-
stream = open_istream(oid, &type, &size, NULL);
348+
stream = open_istream(args->repo, oid, &type, &size,
349+
NULL);
349350
if (!stream)
350351
return error(_("cannot stream blob %s"),
351352
oid_to_hex(oid));

builtin/fast-export.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -293,7 +293,8 @@ static void export_blob(const struct object_id *oid)
293293
buf = read_object_file(oid, &type, &size);
294294
if (!buf)
295295
die("could not read blob %s", oid_to_hex(oid));
296-
if (check_object_signature(oid, buf, size, type_name(type)) < 0)
296+
if (check_object_signature(the_repository, oid, buf, size,
297+
type_name(type)) < 0)
297298
die("oid mismatch in blob %s", oid_to_hex(oid));
298299
object = parse_object_buffer(the_repository, oid, type,
299300
size, buf, &eaten);

builtin/index-pack.c

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -757,7 +757,8 @@ static int check_collison(struct object_entry *entry)
757757

758758
memset(&data, 0, sizeof(data));
759759
data.entry = entry;
760-
data.st = open_istream(&entry->idx.oid, &type, &size, NULL);
760+
data.st = open_istream(the_repository, &entry->idx.oid, &type, &size,
761+
NULL);
761762
if (!data.st)
762763
return -1;
763764
if (size != entry->size || type != entry->type)
@@ -948,7 +949,7 @@ static void resolve_delta(struct object_entry *delta_obj,
948949
free(delta_data);
949950
if (!result->data)
950951
bad_object(delta_obj->idx.offset, _("failed to apply delta"));
951-
hash_object_file(result->data, result->size,
952+
hash_object_file(the_hash_algo, result->data, result->size,
952953
type_name(delta_obj->real_type), &delta_obj->idx.oid);
953954
sha1_object(result->data, NULL, result->size, delta_obj->real_type,
954955
&delta_obj->idx.oid);
@@ -1383,8 +1384,9 @@ static void fix_unresolved_deltas(struct hashfile *f)
13831384
if (!base_obj->data)
13841385
continue;
13851386

1386-
if (check_object_signature(&d->oid, base_obj->data,
1387-
base_obj->size, type_name(type)))
1387+
if (check_object_signature(the_repository, &d->oid,
1388+
base_obj->data, base_obj->size,
1389+
type_name(type)))
13881390
die(_("local object %s is corrupt"), oid_to_hex(&d->oid));
13891391
base_obj->obj = append_obj_to_pack(f, d->oid.hash,
13901392
base_obj->data, base_obj->size, type);

builtin/mktag.c

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,11 @@ static int verify_object(const struct object_id *oid, const char *expected_type)
2929
const struct object_id *repl = lookup_replace_object(the_repository, oid);
3030

3131
if (buffer) {
32-
if (type == type_from_string(expected_type))
33-
ret = check_object_signature(repl, buffer, size, expected_type);
32+
if (type == type_from_string(expected_type)) {
33+
ret = check_object_signature(the_repository, repl,
34+
buffer, size,
35+
expected_type);
36+
}
3437
free(buffer);
3538
}
3639
return ret;

builtin/pack-objects.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -304,7 +304,8 @@ static unsigned long write_no_reuse_object(struct hashfile *f, struct object_ent
304304
if (!usable_delta) {
305305
if (oe_type(entry) == OBJ_BLOB &&
306306
oe_size_greater_than(&to_pack, entry, big_file_threshold) &&
307-
(st = open_istream(&entry->idx.oid, &type, &size, NULL)) != NULL)
307+
(st = open_istream(the_repository, &entry->idx.oid, &type,
308+
&size, NULL)) != NULL)
308309
buf = NULL;
309310
else {
310311
buf = read_object_file(&entry->idx.oid, &type, &size);

builtin/replace.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -409,7 +409,8 @@ static int check_one_mergetag(struct commit *commit,
409409
struct tag *tag;
410410
int i;
411411

412-
hash_object_file(extra->value, extra->len, type_name(OBJ_TAG), &tag_oid);
412+
hash_object_file(the_hash_algo, extra->value, extra->len,
413+
type_name(OBJ_TAG), &tag_oid);
413414
tag = lookup_tag(the_repository, &tag_oid);
414415
if (!tag)
415416
return error(_("bad mergetag in commit '%s'"), ref);

builtin/unpack-objects.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -265,7 +265,8 @@ static void write_object(unsigned nr, enum object_type type,
265265
} else {
266266
struct object *obj;
267267
int eaten;
268-
hash_object_file(buf, size, type_name(type), &obj_list[nr].oid);
268+
hash_object_file(the_hash_algo, buf, size, type_name(type),
269+
&obj_list[nr].oid);
269270
added_object(nr, type, buf, size);
270271
obj = parse_object_buffer(the_repository, &obj_list[nr].oid,
271272
type, size, buf,

cache-tree.c

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -407,13 +407,15 @@ static int update_one(struct cache_tree *it,
407407

408408
if (repair) {
409409
struct object_id oid;
410-
hash_object_file(buffer.buf, buffer.len, tree_type, &oid);
410+
hash_object_file(the_hash_algo, buffer.buf, buffer.len,
411+
tree_type, &oid);
411412
if (has_object_file_with_flags(&oid, OBJECT_INFO_SKIP_FETCH_OBJECT))
412413
oidcpy(&it->oid, &oid);
413414
else
414415
to_invalidate = 1;
415416
} else if (dryrun) {
416-
hash_object_file(buffer.buf, buffer.len, tree_type, &it->oid);
417+
hash_object_file(the_hash_algo, buffer.buf, buffer.len,
418+
tree_type, &it->oid);
417419
} else if (write_object_file(buffer.buf, buffer.len, tree_type,
418420
&it->oid)) {
419421
strbuf_release(&buffer);
@@ -826,9 +828,10 @@ static void verify_one(struct repository *r,
826828
i++;
827829
}
828830
strbuf_addf(&tree_buf, "%o %.*s%c", mode, entlen, name, '\0');
829-
strbuf_add(&tree_buf, oid->hash, the_hash_algo->rawsz);
831+
strbuf_add(&tree_buf, oid->hash, r->hash_algo->rawsz);
830832
}
831-
hash_object_file(tree_buf.buf, tree_buf.len, tree_type, &new_oid);
833+
hash_object_file(r->hash_algo, tree_buf.buf, tree_buf.len, tree_type,
834+
&new_oid);
832835
if (!oideq(&new_oid, &it->oid))
833836
BUG("cache-tree for path %.*s does not match. "
834837
"Expected %s got %s", len, path->buf,

0 commit comments

Comments
 (0)