зеркало из https://github.com/microsoft/git.git
Merge pull request #3533 from PhilipOakley/hashliteral_t
Begin `unsigned long`->`size_t` conversion to support large files on Windows
This commit is contained in:
Коммит
d726c7679a
|
@ -1763,9 +1763,9 @@ void *read_object_with_reference(struct repository *r,
|
|||
}
|
||||
|
||||
static void hash_object_body(const struct git_hash_algo *algo, git_hash_ctx *c,
|
||||
const void *buf, unsigned long len,
|
||||
const void *buf, size_t len,
|
||||
struct object_id *oid,
|
||||
char *hdr, int *hdrlen)
|
||||
char *hdr, size_t *hdrlen)
|
||||
{
|
||||
algo->init_fn(c);
|
||||
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,
|
|||
}
|
||||
|
||||
static void write_object_file_prepare(const struct git_hash_algo *algo,
|
||||
const void *buf, unsigned long len,
|
||||
const void *buf, size_t len,
|
||||
enum object_type type, struct object_id *oid,
|
||||
char *hdr, int *hdrlen)
|
||||
char *hdr, size_t *hdrlen)
|
||||
{
|
||||
git_hash_ctx c;
|
||||
|
||||
/* Generate the header */
|
||||
*hdrlen = format_object_header(hdr, *hdrlen, type, len);
|
||||
|
||||
/* Sha1.. */
|
||||
/* Hash (function pointers) computation */
|
||||
hash_object_body(algo, &c, buf, len, oid, hdr, hdrlen);
|
||||
}
|
||||
|
||||
static void write_object_file_prepare_literally(const struct git_hash_algo *algo,
|
||||
const void *buf, unsigned long len,
|
||||
const void *buf, size_t len,
|
||||
const char *type, struct object_id *oid,
|
||||
char *hdr, int *hdrlen)
|
||||
char *hdr, size_t *hdrlen)
|
||||
{
|
||||
git_hash_ctx c;
|
||||
|
||||
|
@ -1842,17 +1842,17 @@ out:
|
|||
}
|
||||
|
||||
static void hash_object_file_literally(const struct git_hash_algo *algo,
|
||||
const void *buf, unsigned long len,
|
||||
const void *buf, size_t len,
|
||||
const char *type, struct object_id *oid)
|
||||
{
|
||||
char hdr[MAX_HEADER_LEN];
|
||||
int hdrlen = sizeof(hdr);
|
||||
size_t hdrlen = sizeof(hdr);
|
||||
|
||||
write_object_file_prepare_literally(algo, buf, len, type, oid, hdr, &hdrlen);
|
||||
}
|
||||
|
||||
void hash_object_file(const struct git_hash_algo *algo, const void *buf,
|
||||
unsigned long len, enum object_type type,
|
||||
size_t len, enum object_type type,
|
||||
struct object_id *oid)
|
||||
{
|
||||
hash_object_file_literally(algo, buf, len, type_name(type), oid);
|
||||
|
@ -2194,12 +2194,12 @@ cleanup:
|
|||
return err;
|
||||
}
|
||||
|
||||
int write_object_file_flags(const void *buf, unsigned long len,
|
||||
int write_object_file_flags(const void *buf, size_t len,
|
||||
enum object_type type, struct object_id *oid,
|
||||
unsigned flags)
|
||||
{
|
||||
char hdr[MAX_HEADER_LEN];
|
||||
int hdrlen = sizeof(hdr);
|
||||
size_t hdrlen = sizeof(hdr);
|
||||
|
||||
/* Normally if we have it in the pack then we do not bother writing
|
||||
* it out into .git/objects/??/?{38} file.
|
||||
|
@ -2211,12 +2211,13 @@ int write_object_file_flags(const void *buf, unsigned long len,
|
|||
return write_loose_object(oid, hdr, hdrlen, buf, len, 0, flags);
|
||||
}
|
||||
|
||||
int write_object_file_literally(const void *buf, unsigned long len,
|
||||
int write_object_file_literally(const void *buf, size_t len,
|
||||
const char *type, struct object_id *oid,
|
||||
unsigned flags)
|
||||
{
|
||||
char *header;
|
||||
int hdrlen, status = 0;
|
||||
size_t hdrlen;
|
||||
int status = 0;
|
||||
|
||||
/* type string, SP, %lu of the length plus NUL must fit this */
|
||||
hdrlen = strlen(type) + MAX_HEADER_LEN;
|
||||
|
|
|
@ -253,10 +253,10 @@ void *repo_read_object_file(struct repository *r,
|
|||
int oid_object_info(struct repository *r, const struct object_id *, unsigned long *);
|
||||
|
||||
void hash_object_file(const struct git_hash_algo *algo, const void *buf,
|
||||
unsigned long len, enum object_type type,
|
||||
size_t len, enum object_type type,
|
||||
struct object_id *oid);
|
||||
|
||||
int write_object_file_flags(const void *buf, unsigned long len,
|
||||
int write_object_file_flags(const void *buf, size_t len,
|
||||
enum object_type type, struct object_id *oid,
|
||||
unsigned flags);
|
||||
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,
|
|||
return write_object_file_flags(buf, len, type, oid, 0);
|
||||
}
|
||||
|
||||
int write_object_file_literally(const void *buf, unsigned long len,
|
||||
int write_object_file_literally(const void *buf, size_t len,
|
||||
const char *type, struct object_id *oid,
|
||||
unsigned flags);
|
||||
int stream_loose_object(struct input_stream *in_stream, size_t len,
|
||||
|
|
|
@ -25,10 +25,9 @@ void git_SHA1DCFinal(unsigned char hash[20], SHA1_CTX *ctx)
|
|||
/*
|
||||
* Same as SHA1DCUpdate, but adjust types to match git's usual interface.
|
||||
*/
|
||||
void git_SHA1DCUpdate(SHA1_CTX *ctx, const void *vdata, unsigned long len)
|
||||
void git_SHA1DCUpdate(SHA1_CTX *ctx, const void *vdata, size_t len)
|
||||
{
|
||||
const char *data = vdata;
|
||||
/* We expect an unsigned long, but sha1dc only takes an int */
|
||||
while (len > INT_MAX) {
|
||||
SHA1DCUpdate(ctx, data, INT_MAX);
|
||||
data += INT_MAX;
|
||||
|
|
|
@ -15,7 +15,7 @@ void git_SHA1DCInit(SHA1_CTX *);
|
|||
#endif
|
||||
|
||||
void git_SHA1DCFinal(unsigned char [20], SHA1_CTX *);
|
||||
void git_SHA1DCUpdate(SHA1_CTX *ctx, const void *data, unsigned long len);
|
||||
void git_SHA1DCUpdate(SHA1_CTX *ctx, const void *data, size_t len);
|
||||
|
||||
#define platform_SHA_IS_SHA1DC /* used by "test-tool sha1-is-sha1dc" */
|
||||
#define platform_SHA_CTX SHA1_CTX
|
||||
|
|
|
@ -50,6 +50,9 @@ test_expect_success 'setup' '
|
|||
|
||||
example sha1:ddd3f836d3e3fbb7ae289aa9ae83536f76956399
|
||||
example sha256:b44fe1fe65589848253737db859bd490453510719d7424daab03daf0767b85ae
|
||||
|
||||
large5GB sha1:0be2be10a4c8764f32c4bf372a98edc731a4b204
|
||||
large5GB sha256:dc18ca621300c8d3cfa505a275641ebab00de189859e022a975056882d313e64
|
||||
EOF
|
||||
'
|
||||
|
||||
|
@ -260,4 +263,40 @@ test_expect_success '--literally with extra-long type' '
|
|||
echo example | git hash-object -t $t --literally --stdin
|
||||
'
|
||||
|
||||
test_expect_success EXPENSIVE,SIZE_T_IS_64BIT,!LONG_IS_64BIT \
|
||||
'files over 4GB hash literally' '
|
||||
test-tool genzeros $((5*1024*1024*1024)) >big &&
|
||||
test_oid large5GB >expect &&
|
||||
git hash-object --stdin --literally <big >actual &&
|
||||
test_cmp expect actual
|
||||
'
|
||||
|
||||
test_expect_success EXPENSIVE,SIZE_T_IS_64BIT,!LONG_IS_64BIT \
|
||||
'files over 4GB hash correctly via --stdin' '
|
||||
{ test -f big || test-tool genzeros $((5*1024*1024*1024)) >big; } &&
|
||||
test_oid large5GB >expect &&
|
||||
git hash-object --stdin <big >actual &&
|
||||
test_cmp expect actual
|
||||
'
|
||||
|
||||
test_expect_success EXPENSIVE,SIZE_T_IS_64BIT,!LONG_IS_64BIT \
|
||||
'files over 4GB hash correctly' '
|
||||
{ test -f big || test-tool genzeros $((5*1024*1024*1024)) >big; } &&
|
||||
test_oid large5GB >expect &&
|
||||
git hash-object -- big >actual &&
|
||||
test_cmp expect actual
|
||||
'
|
||||
|
||||
# This clean filter does nothing, other than excercising the interface.
|
||||
# We ensure that cleaning doesn't mangle large files on 64-bit Windows.
|
||||
test_expect_success EXPENSIVE,SIZE_T_IS_64BIT,!LONG_IS_64BIT \
|
||||
'hash filtered files over 4GB correctly' '
|
||||
{ test -f big || test-tool genzeros $((5*1024*1024*1024)) >big; } &&
|
||||
test_oid large5GB >expect &&
|
||||
test_config filter.null-filter.clean "cat" &&
|
||||
echo "big filter=null-filter" >.gitattributes &&
|
||||
git hash-object -- big >actual &&
|
||||
test_cmp expect actual
|
||||
'
|
||||
|
||||
test_done
|
||||
|
|
Загрузка…
Ссылка в новой задаче