Skip to content

Commit 2dcde20

Browse files
matheustavaresgitster
authored andcommitted
sha1-file: pass git_hash_algo to hash_object_file()
Allow hash_object_file() to work on arbitrary repos by introducing a git_hash_algo parameter. Change callers which have a struct repository pointer in their scope to pass on the git_hash_algo from the said repo. For all other callers, pass on the_hash_algo, which was already being used internally at hash_object_file(). This functionality will be used in the following patch to make check_object_signature() be able to work on arbitrary repos (which, in turn, will be used to fix an inconsistency at object.c:parse_object()). Signed-off-by: Matheus Tavares <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 7ad5c44 commit 2dcde20

File tree

11 files changed

+36
-25
lines changed

11 files changed

+36
-25
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));

builtin/index-pack.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -949,7 +949,7 @@ static void resolve_delta(struct object_entry *delta_obj,
949949
free(delta_data);
950950
if (!result->data)
951951
bad_object(delta_obj->idx.offset, _("failed to apply delta"));
952-
hash_object_file(result->data, result->size,
952+
hash_object_file(the_hash_algo, result->data, result->size,
953953
type_name(delta_obj->real_type), &delta_obj->idx.oid);
954954
sha1_object(result->data, NULL, result->size, delta_obj->real_type,
955955
&delta_obj->idx.oid);

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: 6 additions & 3 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);
@@ -828,7 +830,8 @@ static void verify_one(struct repository *r,
828830
strbuf_addf(&tree_buf, "%o %.*s%c", mode, entlen, name, '\0');
829831
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,

convert.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1146,7 +1146,7 @@ static int ident_to_worktree(const char *src, size_t len,
11461146
/* are we "faking" in place editing ? */
11471147
if (src == buf->buf)
11481148
to_free = strbuf_detach(buf, NULL);
1149-
hash_object_file(src, len, "blob", &oid);
1149+
hash_object_file(the_hash_algo, src, len, "blob", &oid);
11501150

11511151
strbuf_grow(buf, len + cnt * (the_hash_algo->hexsz + 3));
11521152
for (;;) {

diffcore-rename.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -263,8 +263,8 @@ static unsigned int hash_filespec(struct repository *r,
263263
if (!filespec->oid_valid) {
264264
if (diff_populate_filespec(r, filespec, 0))
265265
return 0;
266-
hash_object_file(filespec->data, filespec->size, "blob",
267-
&filespec->oid);
266+
hash_object_file(r->hash_algo, filespec->data, filespec->size,
267+
"blob", &filespec->oid);
268268
}
269269
return oidhash(&filespec->oid);
270270
}

dir.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1002,8 +1002,8 @@ static int add_patterns(const char *fname, const char *base, int baselen,
10021002
oidcpy(&oid_stat->oid,
10031003
&istate->cache[pos]->oid);
10041004
else
1005-
hash_object_file(buf, size, "blob",
1006-
&oid_stat->oid);
1005+
hash_object_file(the_hash_algo, buf, size,
1006+
"blob", &oid_stat->oid);
10071007
fill_stat_data(&oid_stat->stat, &st);
10081008
oid_stat->valid = 1;
10091009
}

log-tree.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -501,7 +501,8 @@ static int show_one_mergetag(struct commit *commit,
501501
int status, nth;
502502
size_t payload_size, gpg_message_offset;
503503

504-
hash_object_file(extra->value, extra->len, type_name(OBJ_TAG), &oid);
504+
hash_object_file(the_hash_algo, extra->value, extra->len,
505+
type_name(OBJ_TAG), &oid);
505506
tag = lookup_tag(the_repository, &oid);
506507
if (!tag)
507508
return -1; /* error message already given */

object-store.h

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -198,8 +198,9 @@ static inline void *repo_read_object_file(struct repository *r,
198198
/* Read and unpack an object file into memory, write memory to an object file */
199199
int oid_object_info(struct repository *r, const struct object_id *, unsigned long *);
200200

201-
int hash_object_file(const void *buf, unsigned long len,
202-
const char *type, struct object_id *oid);
201+
int hash_object_file(const struct git_hash_algo *algo, const void *buf,
202+
unsigned long len, const char *type,
203+
struct object_id *oid);
203204

204205
int write_object_file(const void *buf, unsigned long len,
205206
const char *type, struct object_id *oid);

0 commit comments

Comments
 (0)