Skip to content

Commit 37075e8

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 3e7ca7a + 5c00a23 commit 37075e8

File tree

5 files changed

+59
-21
lines changed

5 files changed

+59
-21
lines changed

object-file.c

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1939,9 +1939,9 @@ void *read_object_with_reference(struct repository *r,
19391939
}
19401940

19411941
static void hash_object_body(const struct git_hash_algo *algo, git_hash_ctx *c,
1942-
const void *buf, unsigned long len,
1942+
const void *buf, size_t len,
19431943
struct object_id *oid,
1944-
char *hdr, int *hdrlen)
1944+
char *hdr, size_t *hdrlen)
19451945
{
19461946
algo->init_fn(c);
19471947
algo->update_fn(c, hdr, *hdrlen);
@@ -1950,23 +1950,23 @@ static void hash_object_body(const struct git_hash_algo *algo, git_hash_ctx *c,
19501950
}
19511951

19521952
static void write_object_file_prepare(const struct git_hash_algo *algo,
1953-
const void *buf, unsigned long len,
1953+
const void *buf, size_t len,
19541954
enum object_type type, struct object_id *oid,
1955-
char *hdr, int *hdrlen)
1955+
char *hdr, size_t *hdrlen)
19561956
{
19571957
git_hash_ctx c;
19581958

19591959
/* Generate the header */
19601960
*hdrlen = format_object_header(hdr, *hdrlen, type, len);
19611961

1962-
/* Sha1.. */
1962+
/* Hash (function pointers) computation */
19631963
hash_object_body(algo, &c, buf, len, oid, hdr, hdrlen);
19641964
}
19651965

19661966
static void write_object_file_prepare_literally(const struct git_hash_algo *algo,
1967-
const void *buf, unsigned long len,
1967+
const void *buf, size_t len,
19681968
const char *type, struct object_id *oid,
1969-
char *hdr, int *hdrlen)
1969+
char *hdr, size_t *hdrlen)
19701970
{
19711971
git_hash_ctx c;
19721972

@@ -2086,17 +2086,17 @@ int finalize_object_file_flags(const char *tmpfile, const char *filename,
20862086
}
20872087

20882088
static void hash_object_file_literally(const struct git_hash_algo *algo,
2089-
const void *buf, unsigned long len,
2089+
const void *buf, size_t len,
20902090
const char *type, struct object_id *oid)
20912091
{
20922092
char hdr[MAX_HEADER_LEN];
2093-
int hdrlen = sizeof(hdr);
2093+
size_t hdrlen = sizeof(hdr);
20942094

20952095
write_object_file_prepare_literally(algo, buf, len, type, oid, hdr, &hdrlen);
20962096
}
20972097

20982098
void hash_object_file(const struct git_hash_algo *algo, const void *buf,
2099-
unsigned long len, enum object_type type,
2099+
size_t len, enum object_type type,
21002100
struct object_id *oid)
21012101
{
21022102
hash_object_file_literally(algo, buf, len, type_name(type), oid);
@@ -2462,7 +2462,7 @@ int stream_loose_object(struct input_stream *in_stream, size_t len,
24622462
return err;
24632463
}
24642464

2465-
int write_object_file_flags(const void *buf, unsigned long len,
2465+
int write_object_file_flags(const void *buf, size_t len,
24662466
enum object_type type, struct object_id *oid,
24672467
struct object_id *compat_oid_in, unsigned flags)
24682468
{
@@ -2471,7 +2471,7 @@ int write_object_file_flags(const void *buf, unsigned long len,
24712471
const struct git_hash_algo *compat = repo->compat_hash_algo;
24722472
struct object_id compat_oid;
24732473
char hdr[MAX_HEADER_LEN];
2474-
int hdrlen = sizeof(hdr);
2474+
size_t hdrlen = sizeof(hdr);
24752475

24762476
/* Generate compat_oid */
24772477
if (compat) {
@@ -2502,7 +2502,7 @@ int write_object_file_flags(const void *buf, unsigned long len,
25022502
return 0;
25032503
}
25042504

2505-
int write_object_file_literally(const void *buf, unsigned long len,
2505+
int write_object_file_literally(const void *buf, size_t len,
25062506
const char *type, struct object_id *oid,
25072507
unsigned flags)
25082508
{
@@ -2511,8 +2511,8 @@ int write_object_file_literally(const void *buf, unsigned long len,
25112511
const struct git_hash_algo *algo = repo->hash_algo;
25122512
const struct git_hash_algo *compat = repo->compat_hash_algo;
25132513
struct object_id compat_oid;
2514-
int hdrlen, status = 0;
2515-
int compat_type = -1;
2514+
size_t hdrlen;
2515+
int status = 0, compat_type = -1;
25162516

25172517
if (compat) {
25182518
compat_type = type_from_string_gently(type, -1, 1);

object-store-ll.h

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

267267
void hash_object_file(const struct git_hash_algo *algo, const void *buf,
268-
unsigned long len, enum object_type type,
268+
size_t len, enum object_type type,
269269
struct object_id *oid);
270270

271-
int write_object_file_flags(const void *buf, unsigned long len,
271+
int write_object_file_flags(const void *buf, size_t len,
272272
enum object_type type, struct object_id *oid,
273273
struct object_id *comapt_oid_in, unsigned flags);
274274
static inline int write_object_file(const void *buf, unsigned long len,
@@ -277,7 +277,7 @@ static inline int write_object_file(const void *buf, unsigned long len,
277277
return write_object_file_flags(buf, len, type, oid, NULL, 0);
278278
}
279279

280-
int write_object_file_literally(const void *buf, unsigned long len,
280+
int write_object_file_literally(const void *buf, size_t len,
281281
const char *type, struct object_id *oid,
282282
unsigned flags);
283283
int stream_loose_object(struct input_stream *in_stream, size_t len,

sha1dc_git.c

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,10 +27,9 @@ void git_SHA1DCFinal(unsigned char hash[20], SHA1_CTX *ctx)
2727
/*
2828
* Same as SHA1DCUpdate, but adjust types to match git's usual interface.
2929
*/
30-
void git_SHA1DCUpdate(SHA1_CTX *ctx, const void *vdata, unsigned long len)
30+
void git_SHA1DCUpdate(SHA1_CTX *ctx, const void *vdata, size_t len)
3131
{
3232
const char *data = vdata;
33-
/* We expect an unsigned long, but sha1dc only takes an int */
3433
while (len > INT_MAX) {
3534
SHA1DCUpdate(ctx, data, INT_MAX);
3635
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_IS_SHA1DC /* used by "test-tool sha1-is-sha1dc" */
2121

t/t1007-hash-object.sh

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

@@ -266,4 +269,40 @@ test_expect_success '--stdin outside of repository (uses SHA-1)' '
266269
test_cmp expect actual
267270
'
268271

272+
test_expect_success EXPENSIVE,SIZE_T_IS_64BIT,!LONG_IS_64BIT \
273+
'files over 4GB hash literally' '
274+
test-tool genzeros $((5*1024*1024*1024)) >big &&
275+
test_oid large5GB >expect &&
276+
git hash-object --stdin --literally <big >actual &&
277+
test_cmp expect actual
278+
'
279+
280+
test_expect_success EXPENSIVE,SIZE_T_IS_64BIT,!LONG_IS_64BIT \
281+
'files over 4GB hash correctly via --stdin' '
282+
{ test -f big || test-tool genzeros $((5*1024*1024*1024)) >big; } &&
283+
test_oid large5GB >expect &&
284+
git hash-object --stdin <big >actual &&
285+
test_cmp expect actual
286+
'
287+
288+
test_expect_success EXPENSIVE,SIZE_T_IS_64BIT,!LONG_IS_64BIT \
289+
'files over 4GB hash correctly' '
290+
{ test -f big || test-tool genzeros $((5*1024*1024*1024)) >big; } &&
291+
test_oid large5GB >expect &&
292+
git hash-object -- big >actual &&
293+
test_cmp expect actual
294+
'
295+
296+
# This clean filter does nothing, other than excercising the interface.
297+
# We ensure that cleaning doesn't mangle large files on 64-bit Windows.
298+
test_expect_success EXPENSIVE,SIZE_T_IS_64BIT,!LONG_IS_64BIT \
299+
'hash filtered files over 4GB correctly' '
300+
{ test -f big || test-tool genzeros $((5*1024*1024*1024)) >big; } &&
301+
test_oid large5GB >expect &&
302+
test_config filter.null-filter.clean "cat" &&
303+
echo "big filter=null-filter" >.gitattributes &&
304+
git hash-object -- big >actual &&
305+
test_cmp expect actual
306+
'
307+
269308
test_done

0 commit comments

Comments
 (0)