Skip to content

Commit f08f817

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 0b8e420 + bbcf639 commit f08f817

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
@@ -1865,9 +1865,9 @@ void *read_object_with_reference(struct repository *r,
18651865
}
18661866

18671867
static void hash_object_body(const struct git_hash_algo *algo, git_hash_ctx *c,
1868-
const void *buf, unsigned long len,
1868+
const void *buf, size_t len,
18691869
struct object_id *oid,
1870-
char *hdr, int *hdrlen)
1870+
char *hdr, size_t *hdrlen)
18711871
{
18721872
algo->init_fn(c);
18731873
algo->update_fn(c, hdr, *hdrlen);
@@ -1876,23 +1876,23 @@ static void hash_object_body(const struct git_hash_algo *algo, git_hash_ctx *c,
18761876
}
18771877

18781878
static void write_object_file_prepare(const struct git_hash_algo *algo,
1879-
const void *buf, unsigned long len,
1879+
const void *buf, size_t len,
18801880
enum object_type type, struct object_id *oid,
1881-
char *hdr, int *hdrlen)
1881+
char *hdr, size_t *hdrlen)
18821882
{
18831883
git_hash_ctx c;
18841884

18851885
/* Generate the header */
18861886
*hdrlen = format_object_header(hdr, *hdrlen, type, len);
18871887

1888-
/* Sha1.. */
1888+
/* Hash (function pointers) computation */
18891889
hash_object_body(algo, &c, buf, len, oid, hdr, hdrlen);
18901890
}
18911891

18921892
static void write_object_file_prepare_literally(const struct git_hash_algo *algo,
1893-
const void *buf, unsigned long len,
1893+
const void *buf, size_t len,
18941894
const char *type, struct object_id *oid,
1895-
char *hdr, int *hdrlen)
1895+
char *hdr, size_t *hdrlen)
18961896
{
18971897
git_hash_ctx c;
18981898

@@ -1944,17 +1944,17 @@ int finalize_object_file(const char *tmpfile, const char *filename)
19441944
}
19451945

19461946
static void hash_object_file_literally(const struct git_hash_algo *algo,
1947-
const void *buf, unsigned long len,
1947+
const void *buf, size_t len,
19481948
const char *type, struct object_id *oid)
19491949
{
19501950
char hdr[MAX_HEADER_LEN];
1951-
int hdrlen = sizeof(hdr);
1951+
size_t hdrlen = sizeof(hdr);
19521952

19531953
write_object_file_prepare_literally(algo, buf, len, type, oid, hdr, &hdrlen);
19541954
}
19551955

19561956
void hash_object_file(const struct git_hash_algo *algo, const void *buf,
1957-
unsigned long len, enum object_type type,
1957+
size_t len, enum object_type type,
19581958
struct object_id *oid)
19591959
{
19601960
hash_object_file_literally(algo, buf, len, type_name(type), oid);
@@ -2318,7 +2318,7 @@ int stream_loose_object(struct input_stream *in_stream, size_t len,
23182318
return err;
23192319
}
23202320

2321-
int write_object_file_flags(const void *buf, unsigned long len,
2321+
int write_object_file_flags(const void *buf, size_t len,
23222322
enum object_type type, struct object_id *oid,
23232323
struct object_id *compat_oid_in, unsigned flags)
23242324
{
@@ -2327,7 +2327,7 @@ int write_object_file_flags(const void *buf, unsigned long len,
23272327
const struct git_hash_algo *compat = repo->compat_hash_algo;
23282328
struct object_id compat_oid;
23292329
char hdr[MAX_HEADER_LEN];
2330-
int hdrlen = sizeof(hdr);
2330+
size_t hdrlen = sizeof(hdr);
23312331

23322332
/* Generate compat_oid */
23332333
if (compat) {
@@ -2358,7 +2358,7 @@ int write_object_file_flags(const void *buf, unsigned long len,
23582358
return 0;
23592359
}
23602360

2361-
int write_object_file_literally(const void *buf, unsigned long len,
2361+
int write_object_file_literally(const void *buf, size_t len,
23622362
const char *type, struct object_id *oid,
23632363
unsigned flags)
23642364
{
@@ -2367,8 +2367,8 @@ int write_object_file_literally(const void *buf, unsigned long len,
23672367
const struct git_hash_algo *algo = repo->hash_algo;
23682368
const struct git_hash_algo *compat = repo->compat_hash_algo;
23692369
struct object_id compat_oid;
2370-
int hdrlen, status = 0;
2371-
int compat_type = -1;
2370+
size_t hdrlen;
2371+
int status = 0, compat_type = -1;
23722372

23732373
if (compat) {
23742374
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
@@ -250,10 +250,10 @@ void *repo_read_object_file(struct repository *r,
250250
int oid_object_info(struct repository *r, const struct object_id *, unsigned long *);
251251

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

256-
int write_object_file_flags(const void *buf, unsigned long len,
256+
int write_object_file_flags(const void *buf, size_t len,
257257
enum object_type type, struct object_id *oid,
258258
struct object_id *comapt_oid_in, unsigned flags);
259259
static inline int write_object_file(const void *buf, unsigned long len,
@@ -262,7 +262,7 @@ static inline int write_object_file(const void *buf, unsigned long len,
262262
return write_object_file_flags(buf, len, type, oid, NULL, 0);
263263
}
264264

265-
int write_object_file_literally(const void *buf, unsigned long len,
265+
int write_object_file_literally(const void *buf, size_t len,
266266
const char *type, struct object_id *oid,
267267
unsigned flags);
268268
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
#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)