Skip to content

Commit 5f5081d

Browse files
dschoGit for Windows Build Agent
authored and
Git for Windows Build Agent
committed
Merge pull request #3533 from PhilipOakley/hashliteral_t
Begin `unsigned long`->`size_t` conversion to support large files on Windows
2 parents 06ff912 + 4f302c8 commit 5f5081d

5 files changed

+59
-21
lines changed

object-file.c

+15-15
Original file line numberDiff line numberDiff line change
@@ -1675,9 +1675,9 @@ void *read_object_with_reference(struct repository *r,
16751675
}
16761676

16771677
static void hash_object_body(const struct git_hash_algo *algo, struct git_hash_ctx *c,
1678-
const void *buf, unsigned long len,
1678+
const void *buf, size_t len,
16791679
struct object_id *oid,
1680-
char *hdr, int *hdrlen)
1680+
char *hdr, size_t *hdrlen)
16811681
{
16821682
algo->init_fn(c);
16831683
git_hash_update(c, hdr, *hdrlen);
@@ -1686,23 +1686,23 @@ static void hash_object_body(const struct git_hash_algo *algo, struct git_hash_c
16861686
}
16871687

16881688
static void write_object_file_prepare(const struct git_hash_algo *algo,
1689-
const void *buf, unsigned long len,
1689+
const void *buf, size_t len,
16901690
enum object_type type, struct object_id *oid,
1691-
char *hdr, int *hdrlen)
1691+
char *hdr, size_t *hdrlen)
16921692
{
16931693
struct git_hash_ctx c;
16941694

16951695
/* Generate the header */
16961696
*hdrlen = format_object_header(hdr, *hdrlen, type, len);
16971697

1698-
/* Sha1.. */
1698+
/* Hash (function pointers) computation */
16991699
hash_object_body(algo, &c, buf, len, oid, hdr, hdrlen);
17001700
}
17011701

17021702
static void write_object_file_prepare_literally(const struct git_hash_algo *algo,
1703-
const void *buf, unsigned long len,
1703+
const void *buf, size_t len,
17041704
const char *type, struct object_id *oid,
1705-
char *hdr, int *hdrlen)
1705+
char *hdr, size_t *hdrlen)
17061706
{
17071707
struct git_hash_ctx c;
17081708

@@ -1840,17 +1840,17 @@ int finalize_object_file_flags(const char *tmpfile, const char *filename,
18401840
}
18411841

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

18491849
write_object_file_prepare_literally(algo, buf, len, type, oid, hdr, &hdrlen);
18501850
}
18511851

18521852
void hash_object_file(const struct git_hash_algo *algo, const void *buf,
1853-
unsigned long len, enum object_type type,
1853+
size_t len, enum object_type type,
18541854
struct object_id *oid)
18551855
{
18561856
hash_object_file_literally(algo, buf, len, type_name(type), oid);
@@ -2214,7 +2214,7 @@ int stream_loose_object(struct input_stream *in_stream, size_t len,
22142214
return err;
22152215
}
22162216

2217-
int write_object_file_flags(const void *buf, unsigned long len,
2217+
int write_object_file_flags(const void *buf, size_t len,
22182218
enum object_type type, struct object_id *oid,
22192219
struct object_id *compat_oid_in, unsigned flags)
22202220
{
@@ -2223,7 +2223,7 @@ int write_object_file_flags(const void *buf, unsigned long len,
22232223
const struct git_hash_algo *compat = repo->compat_hash_algo;
22242224
struct object_id compat_oid;
22252225
char hdr[MAX_HEADER_LEN];
2226-
int hdrlen = sizeof(hdr);
2226+
size_t hdrlen = sizeof(hdr);
22272227

22282228
/* Generate compat_oid */
22292229
if (compat) {
@@ -2254,7 +2254,7 @@ int write_object_file_flags(const void *buf, unsigned long len,
22542254
return 0;
22552255
}
22562256

2257-
int write_object_file_literally(const void *buf, unsigned long len,
2257+
int write_object_file_literally(const void *buf, size_t len,
22582258
const char *type, struct object_id *oid,
22592259
unsigned flags)
22602260
{
@@ -2263,8 +2263,8 @@ int write_object_file_literally(const void *buf, unsigned long len,
22632263
const struct git_hash_algo *algo = repo->hash_algo;
22642264
const struct git_hash_algo *compat = repo->compat_hash_algo;
22652265
struct object_id compat_oid;
2266-
int hdrlen, status = 0;
2267-
int compat_type = -1;
2266+
size_t hdrlen;
2267+
int status = 0, compat_type = -1;
22682268

22692269
if (compat) {
22702270
compat_type = type_from_string_gently(type, -1, 1);

object-store-ll.h

+3-3
Original file line numberDiff line numberDiff line change
@@ -270,10 +270,10 @@ void *repo_read_object_file(struct repository *r,
270270
int oid_object_info(struct repository *r, const struct object_id *, unsigned long *);
271271

272272
void hash_object_file(const struct git_hash_algo *algo, const void *buf,
273-
unsigned long len, enum object_type type,
273+
size_t len, enum object_type type,
274274
struct object_id *oid);
275275

276-
int write_object_file_flags(const void *buf, unsigned long len,
276+
int write_object_file_flags(const void *buf, size_t len,
277277
enum object_type type, struct object_id *oid,
278278
struct object_id *comapt_oid_in, unsigned flags);
279279
static inline int write_object_file(const void *buf, unsigned long len,
@@ -282,7 +282,7 @@ static inline int write_object_file(const void *buf, unsigned long len,
282282
return write_object_file_flags(buf, len, type, oid, NULL, 0);
283283
}
284284

285-
int write_object_file_literally(const void *buf, unsigned long len,
285+
int write_object_file_literally(const void *buf, size_t len,
286286
const char *type, struct object_id *oid,
287287
unsigned flags);
288288
int stream_loose_object(struct input_stream *in_stream, size_t len,

sha1dc_git.c

+1-2
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

+1-1
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

+39
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

@@ -265,4 +268,40 @@ test_expect_success '--stdin outside of repository (uses SHA-1)' '
265268
test_cmp expect actual
266269
'
267270

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

0 commit comments

Comments
 (0)