Skip to content

Commit 4c29fe3

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 209436c + a39d3b2 commit 4c29fe3

File tree

5 files changed

+59
-20
lines changed

5 files changed

+59
-20
lines changed

object-file.c

Lines changed: 15 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1763,9 +1763,9 @@ void *read_object_with_reference(struct repository *r,
17631763
}
17641764

17651765
static void hash_object_body(const struct git_hash_algo *algo, git_hash_ctx *c,
1766-
const void *buf, unsigned long len,
1766+
const void *buf, size_t len,
17671767
struct object_id *oid,
1768-
char *hdr, int *hdrlen)
1768+
char *hdr, size_t *hdrlen)
17691769
{
17701770
algo->init_fn(c);
17711771
algo->update_fn(c, hdr, *hdrlen);
@@ -1774,23 +1774,23 @@ static void hash_object_body(const struct git_hash_algo *algo, git_hash_ctx *c,
17741774
}
17751775

17761776
static void write_object_file_prepare(const struct git_hash_algo *algo,
1777-
const void *buf, unsigned long len,
1777+
const void *buf, size_t len,
17781778
enum object_type type, struct object_id *oid,
1779-
char *hdr, int *hdrlen)
1779+
char *hdr, size_t *hdrlen)
17801780
{
17811781
git_hash_ctx c;
17821782

17831783
/* Generate the header */
17841784
*hdrlen = format_object_header(hdr, *hdrlen, type, len);
17851785

1786-
/* Sha1.. */
1786+
/* Hash (function pointers) computation */
17871787
hash_object_body(algo, &c, buf, len, oid, hdr, hdrlen);
17881788
}
17891789

17901790
static void write_object_file_prepare_literally(const struct git_hash_algo *algo,
1791-
const void *buf, unsigned long len,
1791+
const void *buf, size_t len,
17921792
const char *type, struct object_id *oid,
1793-
char *hdr, int *hdrlen)
1793+
char *hdr, size_t *hdrlen)
17941794
{
17951795
git_hash_ctx c;
17961796

@@ -1842,17 +1842,17 @@ int finalize_object_file(const char *tmpfile, const char *filename)
18421842
}
18431843

18441844
static void hash_object_file_literally(const struct git_hash_algo *algo,
1845-
const void *buf, unsigned long len,
1845+
const void *buf, size_t len,
18461846
const char *type, struct object_id *oid)
18471847
{
18481848
char hdr[MAX_HEADER_LEN];
1849-
int hdrlen = sizeof(hdr);
1849+
size_t hdrlen = sizeof(hdr);
18501850

18511851
write_object_file_prepare_literally(algo, buf, len, type, oid, hdr, &hdrlen);
18521852
}
18531853

18541854
void hash_object_file(const struct git_hash_algo *algo, const void *buf,
1855-
unsigned long len, enum object_type type,
1855+
size_t len, enum object_type type,
18561856
struct object_id *oid)
18571857
{
18581858
hash_object_file_literally(algo, buf, len, type_name(type), oid);
@@ -2194,12 +2194,12 @@ int stream_loose_object(struct input_stream *in_stream, size_t len,
21942194
return err;
21952195
}
21962196

2197-
int write_object_file_flags(const void *buf, unsigned long len,
2197+
int write_object_file_flags(const void *buf, size_t len,
21982198
enum object_type type, struct object_id *oid,
21992199
unsigned flags)
22002200
{
22012201
char hdr[MAX_HEADER_LEN];
2202-
int hdrlen = sizeof(hdr);
2202+
size_t hdrlen = sizeof(hdr);
22032203

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

2214-
int write_object_file_literally(const void *buf, unsigned long len,
2214+
int write_object_file_literally(const void *buf, size_t len,
22152215
const char *type, struct object_id *oid,
22162216
unsigned flags)
22172217
{
22182218
char *header;
2219-
int hdrlen, status = 0;
2219+
size_t hdrlen;
2220+
int status = 0;
22202221

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

object-store.h

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

255255
void hash_object_file(const struct git_hash_algo *algo, const void *buf,
256-
unsigned long len, enum object_type type,
256+
size_t len, enum object_type type,
257257
struct object_id *oid);
258258

259-
int write_object_file_flags(const void *buf, unsigned long len,
259+
int write_object_file_flags(const void *buf, size_t len,
260260
enum object_type type, struct object_id *oid,
261261
unsigned flags);
262262
static inline int write_object_file(const void *buf, unsigned long len,
@@ -265,7 +265,7 @@ static inline int write_object_file(const void *buf, unsigned long len,
265265
return write_object_file_flags(buf, len, type, oid, 0);
266266
}
267267

268-
int write_object_file_literally(const void *buf, unsigned long len,
268+
int write_object_file_literally(const void *buf, size_t len,
269269
const char *type, struct object_id *oid,
270270
unsigned flags);
271271
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
@@ -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_IS_SHA1DC /* used by "test-tool sha1-is-sha1dc" */
2121
#define platform_SHA_CTX SHA1_CTX

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

@@ -260,4 +263,40 @@ test_expect_success '--literally with extra-long type' '
260263
echo example | git hash-object -t $t --literally --stdin
261264
'
262265

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

0 commit comments

Comments
 (0)