Skip to content

Commit f8712ef

Browse files
dschoGit for Windows Build Agent
authored andcommitted
Merge pull request #3533 from PhilipOakley/hashliteral_t
Begin `unsigned long`->`size_t` conversion to support large files on Windows
2 parents a6cbf0a + ad4e182 commit f8712ef

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
@@ -1785,9 +1785,9 @@ void *read_object_with_reference(struct repository *r,
17851785
}
17861786

17871787
static void hash_object_body(const struct git_hash_algo *algo, git_hash_ctx *c,
1788-
const void *buf, unsigned long len,
1788+
const void *buf, size_t len,
17891789
struct object_id *oid,
1790-
char *hdr, int *hdrlen)
1790+
char *hdr, size_t *hdrlen)
17911791
{
17921792
algo->init_fn(c);
17931793
algo->update_fn(c, hdr, *hdrlen);
@@ -1796,23 +1796,23 @@ static void hash_object_body(const struct git_hash_algo *algo, git_hash_ctx *c,
17961796
}
17971797

17981798
static void write_object_file_prepare(const struct git_hash_algo *algo,
1799-
const void *buf, unsigned long len,
1799+
const void *buf, size_t len,
18001800
enum object_type type, struct object_id *oid,
1801-
char *hdr, int *hdrlen)
1801+
char *hdr, size_t *hdrlen)
18021802
{
18031803
git_hash_ctx c;
18041804

18051805
/* Generate the header */
18061806
*hdrlen = format_object_header(hdr, *hdrlen, type, len);
18071807

1808-
/* Sha1.. */
1808+
/* Hash (function pointers) computation */
18091809
hash_object_body(algo, &c, buf, len, oid, hdr, hdrlen);
18101810
}
18111811

18121812
static void write_object_file_prepare_literally(const struct git_hash_algo *algo,
1813-
const void *buf, unsigned long len,
1813+
const void *buf, size_t len,
18141814
const char *type, struct object_id *oid,
1815-
char *hdr, int *hdrlen)
1815+
char *hdr, size_t *hdrlen)
18161816
{
18171817
git_hash_ctx c;
18181818

@@ -1871,17 +1871,17 @@ static int write_buffer(int fd, const void *buf, size_t len)
18711871
}
18721872

18731873
static void hash_object_file_literally(const struct git_hash_algo *algo,
1874-
const void *buf, unsigned long len,
1874+
const void *buf, size_t len,
18751875
const char *type, struct object_id *oid)
18761876
{
18771877
char hdr[MAX_HEADER_LEN];
1878-
int hdrlen = sizeof(hdr);
1878+
size_t hdrlen = sizeof(hdr);
18791879

18801880
write_object_file_prepare_literally(algo, buf, len, type, oid, hdr, &hdrlen);
18811881
}
18821882

18831883
void hash_object_file(const struct git_hash_algo *algo, const void *buf,
1884-
unsigned long len, enum object_type type,
1884+
size_t len, enum object_type type,
18851885
struct object_id *oid)
18861886
{
18871887
hash_object_file_literally(algo, buf, len, type_name(type), oid);
@@ -2050,12 +2050,12 @@ static int freshen_packed_object(const struct object_id *oid)
20502050
return 1;
20512051
}
20522052

2053-
int write_object_file_flags(const void *buf, unsigned long len,
2053+
int write_object_file_flags(const void *buf, size_t len,
20542054
enum object_type type, struct object_id *oid,
20552055
unsigned flags)
20562056
{
20572057
char hdr[MAX_HEADER_LEN];
2058-
int hdrlen = sizeof(hdr);
2058+
size_t hdrlen = sizeof(hdr);
20592059

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

2070-
int write_object_file_literally(const void *buf, unsigned long len,
2070+
int write_object_file_literally(const void *buf, size_t len,
20712071
const char *type, struct object_id *oid,
20722072
unsigned flags)
20732073
{
20742074
char *header;
2075-
int hdrlen, status = 0;
2075+
size_t hdrlen;
2076+
int status = 0;
20762077

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

object-store.h

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

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

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

269-
int write_object_file_literally(const void *buf, unsigned long len,
269+
int write_object_file_literally(const void *buf, size_t len,
270270
const char *type, struct object_id *oid,
271271
unsigned flags);
272272

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_CTX SHA1_CTX
2121
#define platform_SHA1_Init git_SHA1DCInit

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

@@ -249,4 +252,40 @@ test_expect_success '--literally with extra-long type' '
249252
echo example | git hash-object -t $t --literally --stdin
250253
'
251254

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

0 commit comments

Comments
 (0)