Skip to content

Commit 7ad5c44

Browse files
matheustavaresgitster
authored andcommitted
sha1-file: pass git_hash_algo to write_object_file_prepare()
Allow write_object_file_prepare() to receive arbitrary 'struct git_hash_algo's instead of always using the_hash_algo. The added parameter will be used in the next commit to make hash_object_file() be able to work with arbitrary git_hash_algo's, as well. Signed-off-by: Matheus Tavares <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent c8123e7 commit 7ad5c44

File tree

1 file changed

+12
-8
lines changed

1 file changed

+12
-8
lines changed

sha1-file.c

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1648,7 +1648,8 @@ void *read_object_with_reference(struct repository *r,
16481648
}
16491649
}
16501650

1651-
static void write_object_file_prepare(const void *buf, unsigned long len,
1651+
static void write_object_file_prepare(const struct git_hash_algo *algo,
1652+
const void *buf, unsigned long len,
16521653
const char *type, struct object_id *oid,
16531654
char *hdr, int *hdrlen)
16541655
{
@@ -1658,10 +1659,10 @@ static void write_object_file_prepare(const void *buf, unsigned long len,
16581659
*hdrlen = xsnprintf(hdr, *hdrlen, "%s %"PRIuMAX , type, (uintmax_t)len)+1;
16591660

16601661
/* Sha1.. */
1661-
the_hash_algo->init_fn(&c);
1662-
the_hash_algo->update_fn(&c, hdr, *hdrlen);
1663-
the_hash_algo->update_fn(&c, buf, len);
1664-
the_hash_algo->final_fn(oid->hash, &c);
1662+
algo->init_fn(&c);
1663+
algo->update_fn(&c, hdr, *hdrlen);
1664+
algo->update_fn(&c, buf, len);
1665+
algo->final_fn(oid->hash, &c);
16651666
}
16661667

16671668
/*
@@ -1719,7 +1720,8 @@ int hash_object_file(const void *buf, unsigned long len, const char *type,
17191720
{
17201721
char hdr[MAX_HEADER_LEN];
17211722
int hdrlen = sizeof(hdr);
1722-
write_object_file_prepare(buf, len, type, oid, hdr, &hdrlen);
1723+
write_object_file_prepare(the_hash_algo, buf, len, type, oid, hdr,
1724+
&hdrlen);
17231725
return 0;
17241726
}
17251727

@@ -1877,7 +1879,8 @@ int write_object_file(const void *buf, unsigned long len, const char *type,
18771879
/* Normally if we have it in the pack then we do not bother writing
18781880
* it out into .git/objects/??/?{38} file.
18791881
*/
1880-
write_object_file_prepare(buf, len, type, oid, hdr, &hdrlen);
1882+
write_object_file_prepare(the_hash_algo, buf, len, type, oid, hdr,
1883+
&hdrlen);
18811884
if (freshen_packed_object(oid) || freshen_loose_object(oid))
18821885
return 0;
18831886
return write_loose_object(oid, hdr, hdrlen, buf, len, 0);
@@ -1893,7 +1896,8 @@ int hash_object_file_literally(const void *buf, unsigned long len,
18931896
/* type string, SP, %lu of the length plus NUL must fit this */
18941897
hdrlen = strlen(type) + MAX_HEADER_LEN;
18951898
header = xmalloc(hdrlen);
1896-
write_object_file_prepare(buf, len, type, oid, header, &hdrlen);
1899+
write_object_file_prepare(the_hash_algo, buf, len, type, oid, header,
1900+
&hdrlen);
18971901

18981902
if (!(flags & HASH_WRITE_OBJECT))
18991903
goto cleanup;

0 commit comments

Comments
 (0)