@matheusbsbs / matheus-bagliano / commits / 4ba7d71153
Fork 0

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>

Nicolas Pitre committed Apr 9, 2007 at 17:32 UTC 4ba7d711539122c21bd44af06b6cab4fc4f65a74
2 files changed +32 -6
builtin-pack-objects.c
+17 -3
@@ -597,6 +597,9 @@ static off_t write_pack_file(void)
597 return last_obj_offset;
598 }
599
600 +static uint32_t index_default_version = 1;
601 +static uint32_t index_off32_limit = 0x7fffffff;
602 +
603 static void write_index_file(off_t last_obj_offset)
604 {
605 uint32_t i;
@@ -608,7 +611,7 @@ static void write_index_file(off_t last_obj_offset)
611 uint32_t index_version;
612
613 /* if last object's offset is >= 2^31 we should use index V2 */
611 - index_version = (last_obj_offset >> 31) ? 2 : 1;
614 + index_version = (last_obj_offset >> 31) ? 2 : index_default_version;
615
616 /* index versions 2 and above need a header */
617 if (index_version >= 2) {
@@ -664,7 +667,7 @@ static void write_index_file(off_t last_obj_offset)
667 list = sorted_by_sha;
668 for (i = 0; i < nr_objects; i++) {
669 struct object_entry *entry = *list++;
667 - uint32_t offset = (entry->offset <= 0x7fffffff) ?
670 + uint32_t offset = (entry->offset <= index_off32_limit) ?
671 entry->offset : (0x80000000 | nr_large_offset++);
672 offset = htonl(offset);
673 sha1write(f, &offset, 4);
@@ -675,7 +678,7 @@ static void write_index_file(off_t last_obj_offset)
678 while (nr_large_offset) {
679 struct object_entry *entry = *list++;
680 uint64_t offset = entry->offset;
678 - if (offset > 0x7fffffff) {
681 + if (offset > index_off32_limit) {
682 uint32_t split[2];
683 split[0] = htonl(offset >> 32);
684 split[1] = htonl(offset & 0xffffffff);
@@ -1714,6 +1717,17 @@ int cmd_pack_objects(int argc, const char **argv, const char *prefix)
1717 rp_av[1] = "--objects-edge";
1718 continue;
1719 }
1720 + if (!prefixcmp(arg, "--index-version=")) {
1721 + char *c;
1722 + index_default_version = strtoul(arg + 16, &c, 10);
1723 + if (index_default_version > 2)
1724 + die("bad %s", arg);
1725 + if (*c == ',')
1726 + index_off32_limit = strtoul(c+1, &c, 0);
1727 + if (*c || index_off32_limit & 0x80000000)
1728 + die("bad %s", arg);
1729 + continue;
1730 + }
1731 usage(pack_usage);
1732 }
1733
index-pack.c
+15 -3
@@ -671,6 +671,9 @@ static void readjust_pack_header_and_sha1(unsigned char *sha1)
671 write_or_die(output_fd, sha1, 20);
672 }
673
674 +static uint32_t index_default_version = 1;
675 +static uint32_t index_off32_limit = 0x7fffffff;
676 +
677 static int sha1_compare(const void *_a, const void *_b)
678 {
679 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)
722 f = sha1fd(fd, index_name);
723
724 /* if last object's offset is >= 2^31 we should use index V2 */
722 - index_version = (objects[nr_objects-1].offset >> 31) ? 2 : 1;
725 + index_version = (objects[nr_objects-1].offset >> 31) ? 2 : index_default_version;
726
727 /* index versions 2 and above need a header */
728 if (index_version >= 2) {
@@ -779,7 +782,7 @@ static const char *write_index_file(const char *index_name, unsigned char *sha1)
782 list = sorted_by_sha;
783 for (i = 0; i < nr_objects; i++) {
784 struct object_entry *obj = *list++;
782 - uint32_t offset = (obj->offset <= 0x7fffffff) ?
785 + uint32_t offset = (obj->offset <= index_off32_limit) ?
786 obj->offset : (0x80000000 | nr_large_offset++);
787 offset = htonl(offset);
788 sha1write(f, &offset, 4);
@@ -790,7 +793,7 @@ static const char *write_index_file(const char *index_name, unsigned char *sha1)
793 while (nr_large_offset) {
794 struct object_entry *obj = *list++;
795 uint64_t offset = obj->offset;
793 - if (offset > 0x7fffffff) {
796 + if (offset > index_off32_limit) {
797 uint32_t split[2];
798 split[0] = htonl(offset >> 32);
799 split[1] = htonl(offset & 0xffffffff);
@@ -929,6 +932,15 @@ int main(int argc, char **argv)
932 if (index_name || (i+1) >= argc)
933 usage(index_pack_usage);
934 index_name = argv[++i];
935 + } else if (!prefixcmp(arg, "--index-version=")) {
936 + char *c;
937 + index_default_version = strtoul(arg + 16, &c, 10);
938 + if (index_default_version > 2)
939 + die("bad %s", arg);
940 + if (*c == ',')
941 + index_off32_limit = strtoul(c+1, &c, 0);
942 + if (*c || index_off32_limit & 0x80000000)
943 + die("bad %s", arg);
944 } else
945 usage(index_pack_usage);
946 continue;