allow forcing index v2 and 64-bit offset treshold
This is necessary for testing the new capabilities in some automated way without having an actual 4GB+ pack. Signed-off-by: Nicolas Pitre <nico@cam.org> Signed-off-by: Junio C Hamano <junkio@cox.net>
This commit is contained in:
parent
8c681e07c9
commit
4ba7d71153
@ -597,6 +597,9 @@ static off_t write_pack_file(void)
|
|||||||
return last_obj_offset;
|
return last_obj_offset;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static uint32_t index_default_version = 1;
|
||||||
|
static uint32_t index_off32_limit = 0x7fffffff;
|
||||||
|
|
||||||
static void write_index_file(off_t last_obj_offset)
|
static void write_index_file(off_t last_obj_offset)
|
||||||
{
|
{
|
||||||
uint32_t i;
|
uint32_t i;
|
||||||
@ -608,7 +611,7 @@ static void write_index_file(off_t last_obj_offset)
|
|||||||
uint32_t index_version;
|
uint32_t index_version;
|
||||||
|
|
||||||
/* if last object's offset is >= 2^31 we should use index V2 */
|
/* if last object's offset is >= 2^31 we should use index V2 */
|
||||||
index_version = (last_obj_offset >> 31) ? 2 : 1;
|
index_version = (last_obj_offset >> 31) ? 2 : index_default_version;
|
||||||
|
|
||||||
/* index versions 2 and above need a header */
|
/* index versions 2 and above need a header */
|
||||||
if (index_version >= 2) {
|
if (index_version >= 2) {
|
||||||
@ -664,7 +667,7 @@ static void write_index_file(off_t last_obj_offset)
|
|||||||
list = sorted_by_sha;
|
list = sorted_by_sha;
|
||||||
for (i = 0; i < nr_objects; i++) {
|
for (i = 0; i < nr_objects; i++) {
|
||||||
struct object_entry *entry = *list++;
|
struct object_entry *entry = *list++;
|
||||||
uint32_t offset = (entry->offset <= 0x7fffffff) ?
|
uint32_t offset = (entry->offset <= index_off32_limit) ?
|
||||||
entry->offset : (0x80000000 | nr_large_offset++);
|
entry->offset : (0x80000000 | nr_large_offset++);
|
||||||
offset = htonl(offset);
|
offset = htonl(offset);
|
||||||
sha1write(f, &offset, 4);
|
sha1write(f, &offset, 4);
|
||||||
@ -675,7 +678,7 @@ static void write_index_file(off_t last_obj_offset)
|
|||||||
while (nr_large_offset) {
|
while (nr_large_offset) {
|
||||||
struct object_entry *entry = *list++;
|
struct object_entry *entry = *list++;
|
||||||
uint64_t offset = entry->offset;
|
uint64_t offset = entry->offset;
|
||||||
if (offset > 0x7fffffff) {
|
if (offset > index_off32_limit) {
|
||||||
uint32_t split[2];
|
uint32_t split[2];
|
||||||
split[0] = htonl(offset >> 32);
|
split[0] = htonl(offset >> 32);
|
||||||
split[1] = htonl(offset & 0xffffffff);
|
split[1] = htonl(offset & 0xffffffff);
|
||||||
@ -1714,6 +1717,17 @@ int cmd_pack_objects(int argc, const char **argv, const char *prefix)
|
|||||||
rp_av[1] = "--objects-edge";
|
rp_av[1] = "--objects-edge";
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
if (!prefixcmp(arg, "--index-version=")) {
|
||||||
|
char *c;
|
||||||
|
index_default_version = strtoul(arg + 16, &c, 10);
|
||||||
|
if (index_default_version > 2)
|
||||||
|
die("bad %s", arg);
|
||||||
|
if (*c == ',')
|
||||||
|
index_off32_limit = strtoul(c+1, &c, 0);
|
||||||
|
if (*c || index_off32_limit & 0x80000000)
|
||||||
|
die("bad %s", arg);
|
||||||
|
continue;
|
||||||
|
}
|
||||||
usage(pack_usage);
|
usage(pack_usage);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
18
index-pack.c
18
index-pack.c
@ -671,6 +671,9 @@ static void readjust_pack_header_and_sha1(unsigned char *sha1)
|
|||||||
write_or_die(output_fd, sha1, 20);
|
write_or_die(output_fd, sha1, 20);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static uint32_t index_default_version = 1;
|
||||||
|
static uint32_t index_off32_limit = 0x7fffffff;
|
||||||
|
|
||||||
static int sha1_compare(const void *_a, const void *_b)
|
static int sha1_compare(const void *_a, const void *_b)
|
||||||
{
|
{
|
||||||
struct object_entry *a = *(struct object_entry **)_a;
|
struct object_entry *a = *(struct object_entry **)_a;
|
||||||
@ -719,7 +722,7 @@ static const char *write_index_file(const char *index_name, unsigned char *sha1)
|
|||||||
f = sha1fd(fd, index_name);
|
f = sha1fd(fd, index_name);
|
||||||
|
|
||||||
/* if last object's offset is >= 2^31 we should use index V2 */
|
/* if last object's offset is >= 2^31 we should use index V2 */
|
||||||
index_version = (objects[nr_objects-1].offset >> 31) ? 2 : 1;
|
index_version = (objects[nr_objects-1].offset >> 31) ? 2 : index_default_version;
|
||||||
|
|
||||||
/* index versions 2 and above need a header */
|
/* index versions 2 and above need a header */
|
||||||
if (index_version >= 2) {
|
if (index_version >= 2) {
|
||||||
@ -779,7 +782,7 @@ static const char *write_index_file(const char *index_name, unsigned char *sha1)
|
|||||||
list = sorted_by_sha;
|
list = sorted_by_sha;
|
||||||
for (i = 0; i < nr_objects; i++) {
|
for (i = 0; i < nr_objects; i++) {
|
||||||
struct object_entry *obj = *list++;
|
struct object_entry *obj = *list++;
|
||||||
uint32_t offset = (obj->offset <= 0x7fffffff) ?
|
uint32_t offset = (obj->offset <= index_off32_limit) ?
|
||||||
obj->offset : (0x80000000 | nr_large_offset++);
|
obj->offset : (0x80000000 | nr_large_offset++);
|
||||||
offset = htonl(offset);
|
offset = htonl(offset);
|
||||||
sha1write(f, &offset, 4);
|
sha1write(f, &offset, 4);
|
||||||
@ -790,7 +793,7 @@ static const char *write_index_file(const char *index_name, unsigned char *sha1)
|
|||||||
while (nr_large_offset) {
|
while (nr_large_offset) {
|
||||||
struct object_entry *obj = *list++;
|
struct object_entry *obj = *list++;
|
||||||
uint64_t offset = obj->offset;
|
uint64_t offset = obj->offset;
|
||||||
if (offset > 0x7fffffff) {
|
if (offset > index_off32_limit) {
|
||||||
uint32_t split[2];
|
uint32_t split[2];
|
||||||
split[0] = htonl(offset >> 32);
|
split[0] = htonl(offset >> 32);
|
||||||
split[1] = htonl(offset & 0xffffffff);
|
split[1] = htonl(offset & 0xffffffff);
|
||||||
@ -929,6 +932,15 @@ int main(int argc, char **argv)
|
|||||||
if (index_name || (i+1) >= argc)
|
if (index_name || (i+1) >= argc)
|
||||||
usage(index_pack_usage);
|
usage(index_pack_usage);
|
||||||
index_name = argv[++i];
|
index_name = argv[++i];
|
||||||
|
} else if (!prefixcmp(arg, "--index-version=")) {
|
||||||
|
char *c;
|
||||||
|
index_default_version = strtoul(arg + 16, &c, 10);
|
||||||
|
if (index_default_version > 2)
|
||||||
|
die("bad %s", arg);
|
||||||
|
if (*c == ',')
|
||||||
|
index_off32_limit = strtoul(c+1, &c, 0);
|
||||||
|
if (*c || index_off32_limit & 0x80000000)
|
||||||
|
die("bad %s", arg);
|
||||||
} else
|
} else
|
||||||
usage(index_pack_usage);
|
usage(index_pack_usage);
|
||||||
continue;
|
continue;
|
||||||
|
Loading…
Reference in New Issue
Block a user