Skip to content

Commit 3d23078

Browse files
dschoGit for Windows Build Agent
authored andcommitted
Merge pull request git-for-windows#3533 from PhilipOakley/hashliteral_t
Begin `unsigned long`->`size_t` conversion to support large files on Windows
2 parents e225340 + 2d5a0dc commit 3d23078

5 files changed

Lines changed: 52 additions & 14 deletions

File tree

object-file.c

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -561,9 +561,9 @@ int odb_source_loose_read_object_info(struct odb_source *source,
561561
}
562562

563563
static void hash_object_body(const struct git_hash_algo *algo, struct git_hash_ctx *c,
564-
const void *buf, unsigned long len,
564+
const void *buf, size_t len,
565565
struct object_id *oid,
566-
char *hdr, int *hdrlen)
566+
char *hdr, size_t *hdrlen)
567567
{
568568
algo->init_fn(c);
569569
git_hash_update(c, hdr, *hdrlen);
@@ -572,16 +572,16 @@ static void hash_object_body(const struct git_hash_algo *algo, struct git_hash_c
572572
}
573573

574574
static void write_object_file_prepare(const struct git_hash_algo *algo,
575-
const void *buf, unsigned long len,
575+
const void *buf, size_t len,
576576
enum object_type type, struct object_id *oid,
577-
char *hdr, int *hdrlen)
577+
char *hdr, size_t *hdrlen)
578578
{
579579
struct git_hash_ctx c;
580580

581581
/* Generate the header */
582582
*hdrlen = format_object_header(hdr, *hdrlen, type, len);
583583

584-
/* Sha1.. */
584+
/* Hash (function pointers) computation */
585585
hash_object_body(algo, &c, buf, len, oid, hdr, hdrlen);
586586
}
587587

@@ -717,11 +717,11 @@ int finalize_object_file_flags(struct repository *repo,
717717
}
718718

719719
void hash_object_file(const struct git_hash_algo *algo, const void *buf,
720-
unsigned long len, enum object_type type,
720+
size_t len, enum object_type type,
721721
struct object_id *oid)
722722
{
723723
char hdr[MAX_HEADER_LEN];
724-
int hdrlen = sizeof(hdr);
724+
size_t hdrlen = sizeof(hdr);
725725

726726
write_object_file_prepare(algo, buf, len, type, oid, hdr, &hdrlen);
727727
}
@@ -1177,7 +1177,7 @@ int odb_source_loose_write_stream(struct odb_source *source,
11771177
}
11781178

11791179
int odb_source_loose_write_object(struct odb_source *source,
1180-
const void *buf, unsigned long len,
1180+
const void *buf, size_t len,
11811181
enum object_type type, struct object_id *oid,
11821182
struct object_id *compat_oid_in,
11831183
enum odb_write_object_flags flags)
@@ -1186,7 +1186,7 @@ int odb_source_loose_write_object(struct odb_source *source,
11861186
const struct git_hash_algo *compat = source->odb->repo->compat_hash_algo;
11871187
struct object_id compat_oid;
11881188
char hdr[MAX_HEADER_LEN];
1189-
int hdrlen = sizeof(hdr);
1189+
size_t hdrlen = sizeof(hdr);
11901190

11911191
/* Generate compat_oid */
11921192
if (compat) {

object-file.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ int odb_source_loose_freshen_object(struct odb_source *source,
6666
const struct object_id *oid);
6767

6868
int odb_source_loose_write_object(struct odb_source *source,
69-
const void *buf, unsigned long len,
69+
const void *buf, size_t len,
7070
enum object_type type, struct object_id *oid,
7171
struct object_id *compat_oid_in,
7272
enum odb_write_object_flags flags);
@@ -201,7 +201,7 @@ int finalize_object_file_flags(struct repository *repo,
201201
enum finalize_object_file_flags flags);
202202

203203
void hash_object_file(const struct git_hash_algo *algo, const void *buf,
204-
unsigned long len, enum object_type type,
204+
size_t len, enum object_type type,
205205
struct object_id *oid);
206206

207207
/* Helper to check and "touch" a file */

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
@@ -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

@@ -258,4 +261,40 @@ test_expect_success '--stdin outside of repository (uses default hash)' '
258261
test_cmp expect actual
259262
'
260263

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

0 commit comments

Comments
 (0)