Skip to content

Commit c881bc9

Browse files
committed
Merge pull request #3533 from PhilipOakley/hashliteral_t
Begin `unsigned long`->`size_t` conversion to support large files on Windows
2 parents d8967aa + 16ce7fc commit c881bc9

File tree

5 files changed

+54
-15
lines changed

5 files changed

+54
-15
lines changed

object-file.c

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1770,16 +1770,16 @@ void *read_object_with_reference(struct repository *r,
17701770
}
17711771

17721772
static void write_object_file_prepare(const struct git_hash_algo *algo,
1773-
const void *buf, unsigned long len,
1773+
const void *buf, size_t len,
17741774
const char *type, struct object_id *oid,
1775-
char *hdr, int *hdrlen)
1775+
char *hdr, size_t *hdrlen)
17761776
{
17771777
git_hash_ctx c;
17781778

17791779
/* Generate the header */
17801780
*hdrlen = xsnprintf(hdr, *hdrlen, "%s %"PRIuMAX , type, (uintmax_t)len)+1;
17811781

1782-
/* Sha1.. */
1782+
/* Hash (function pointers) computation */
17831783
algo->init_fn(&c);
17841784
algo->update_fn(&c, hdr, *hdrlen);
17851785
algo->update_fn(&c, buf, len);
@@ -1837,11 +1837,11 @@ static int write_buffer(int fd, const void *buf, size_t len)
18371837
}
18381838

18391839
int hash_object_file(const struct git_hash_algo *algo, const void *buf,
1840-
unsigned long len, const char *type,
1840+
size_t len, const char *type,
18411841
struct object_id *oid)
18421842
{
18431843
char hdr[MAX_HEADER_LEN];
1844-
int hdrlen = sizeof(hdr);
1844+
size_t hdrlen = sizeof(hdr);
18451845
write_object_file_prepare(algo, buf, len, type, oid, hdr, &hdrlen);
18461846
return 0;
18471847
}
@@ -1997,12 +1997,12 @@ static int freshen_packed_object(const struct object_id *oid)
19971997
return 1;
19981998
}
19991999

2000-
int write_object_file_flags(const void *buf, unsigned long len,
2000+
int write_object_file_flags(const void *buf, size_t len,
20012001
const char *type, struct object_id *oid,
20022002
unsigned flags)
20032003
{
20042004
char hdr[MAX_HEADER_LEN];
2005-
int hdrlen = sizeof(hdr);
2005+
size_t hdrlen = sizeof(hdr);
20062006

20072007
/* Normally if we have it in the pack then we do not bother writing
20082008
* it out into .git/objects/??/?{38} file.
@@ -2014,12 +2014,13 @@ int write_object_file_flags(const void *buf, unsigned long len,
20142014
return write_loose_object(oid, hdr, hdrlen, buf, len, 0, flags);
20152015
}
20162016

2017-
int hash_object_file_literally(const void *buf, unsigned long len,
2017+
int hash_object_file_literally(const void *buf, size_t len,
20182018
const char *type, struct object_id *oid,
20192019
unsigned flags)
20202020
{
20212021
char *header;
2022-
int hdrlen, status = 0;
2022+
size_t hdrlen;
2023+
int status = 0;
20232024

20242025
/* type string, SP, %lu of the length plus NUL must fit this */
20252026
hdrlen = strlen(type) + MAX_HEADER_LEN;

object-store.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -246,10 +246,10 @@ static inline void *repo_read_object_file(struct repository *r,
246246
int oid_object_info(struct repository *r, const struct object_id *, unsigned long *);
247247

248248
int hash_object_file(const struct git_hash_algo *algo, const void *buf,
249-
unsigned long len, const char *type,
249+
size_t len, const char *type,
250250
struct object_id *oid);
251251

252-
int write_object_file_flags(const void *buf, unsigned long len,
252+
int write_object_file_flags(const void *buf, size_t len,
253253
const char *type, struct object_id *oid,
254254
unsigned flags);
255255
static inline int write_object_file(const void *buf, unsigned long len,
@@ -258,7 +258,7 @@ static inline int write_object_file(const void *buf, unsigned long len,
258258
return write_object_file_flags(buf, len, type, oid, 0);
259259
}
260260

261-
int hash_object_file_literally(const void *buf, unsigned long len,
261+
int hash_object_file_literally(const void *buf, size_t len,
262262
const char *type, struct object_id *oid,
263263
unsigned flags);
264264

sha1dc_git.c

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,10 +25,9 @@ void git_SHA1DCFinal(unsigned char hash[20], SHA1_CTX *ctx)
2525
/*
2626
* Same as SHA1DCUpdate, but adjust types to match git's usual interface.
2727
*/
28-
void git_SHA1DCUpdate(SHA1_CTX *ctx, const void *vdata, unsigned long len)
28+
void git_SHA1DCUpdate(SHA1_CTX *ctx, const void *vdata, size_t len)
2929
{
3030
const char *data = vdata;
31-
/* We expect an unsigned long, but sha1dc only takes an int */
3231
while (len > INT_MAX) {
3332
SHA1DCUpdate(ctx, data, INT_MAX);
3433
data += INT_MAX;

sha1dc_git.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ void git_SHA1DCInit(SHA1_CTX *);
1515
#endif
1616

1717
void git_SHA1DCFinal(unsigned char [20], SHA1_CTX *);
18-
void git_SHA1DCUpdate(SHA1_CTX *ctx, const void *data, unsigned long len);
18+
void git_SHA1DCUpdate(SHA1_CTX *ctx, const void *data, size_t len);
1919

2020
#define platform_SHA_CTX SHA1_CTX
2121
#define platform_SHA1_Init git_SHA1DCInit

t/t1007-hash-object.sh

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,9 @@ test_expect_success 'setup' '
4949
5050
example sha1:ddd3f836d3e3fbb7ae289aa9ae83536f76956399
5151
example sha256:b44fe1fe65589848253737db859bd490453510719d7424daab03daf0767b85ae
52+
53+
large5GB sha1:0be2be10a4c8764f32c4bf372a98edc731a4b204
54+
large5GB sha256:dc18ca621300c8d3cfa505a275641ebab00de189859e022a975056882d313e64
5255
EOF
5356
'
5457

@@ -248,4 +251,40 @@ test_expect_success '--literally with extra-long type' '
248251
echo example | git hash-object -t $t --literally --stdin
249252
'
250253

254+
test_expect_success EXPENSIVE,SIZE_T_IS_64BIT,!LONG_IS_64BIT \
255+
'files over 4GB hash literally' '
256+
test-tool genzeros $((5*1024*1024*1024)) >big &&
257+
test_oid large5GB >expect &&
258+
git hash-object --stdin --literally <big >actual &&
259+
test_cmp expect actual
260+
'
261+
262+
test_expect_success EXPENSIVE,SIZE_T_IS_64BIT,!LONG_IS_64BIT \
263+
'files over 4GB hash correctly via --stdin' '
264+
{ test -f big || test-tool genzeros $((5*1024*1024*1024)) >big; } &&
265+
test_oid large5GB >expect &&
266+
git hash-object --stdin <big >actual &&
267+
test_cmp expect actual
268+
'
269+
270+
test_expect_success EXPENSIVE,SIZE_T_IS_64BIT,!LONG_IS_64BIT \
271+
'files over 4GB hash correctly' '
272+
{ test -f big || test-tool genzeros $((5*1024*1024*1024)) >big; } &&
273+
test_oid large5GB >expect &&
274+
git hash-object -- big >actual &&
275+
test_cmp expect actual
276+
'
277+
278+
# This clean filter does nothing, other than excercising the interface.
279+
# We ensure that cleaning doesn't mangle large files on 64-bit Windows.
280+
test_expect_success EXPENSIVE,SIZE_T_IS_64BIT,!LONG_IS_64BIT \
281+
'hash filtered files over 4GB correctly' '
282+
{ test -f big || test-tool genzeros $((5*1024*1024*1024)) >big; } &&
283+
test_oid large5GB >expect &&
284+
test_config filter.null-filter.clean "cat" &&
285+
echo "big filter=null-filter" >.gitattributes &&
286+
git hash-object -- big >actual &&
287+
test_cmp expect actual
288+
'
289+
251290
test_done

0 commit comments

Comments
 (0)