Skip to contentSkip to conversation

Support 64-bit indexes for pack files.

PATCH In review Troy Telford 5 participants 20 messages Jun 15, 2016

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 Support 64-bit indexes for pack files.

As I've not been involved with git development before, I'm
aware that this may already be on somebody's 'todo' list. It was an itch I needed to scratch, as I have a repository whose size is multiple gigabytes, and 'git clone' (by default) forces everything into a single packfile with >=git-1.5.0.

Since I'm an insane form of lazy, needed the C practice, and wanted to avoid those few keystrokes needed to tweak the default push/fetch behavior, I'm attempting to either fix git or break it in a new and interesting way.

The patch introduces a new packfile index version, which adds a:
* header to the index file (index version info).
* leaves the object indexes within the index at 32-bit
* extends the offsets used to describe the packfile to 64-bit.

The new index format is only used when the associated packfile becomes large enough to warrant a 64-bit index; otherwise the original index format is used.

Operations such as git-fsck, checkouts, diffs, and branches all appear to work properly on x86-64 architectures. I've done testing on both x86 and x86_64 architectures, using a git repository with a single 5.4 GB packfile.

32-bit architectures still have issues using the 64-bit indexes (git- fsck, pull/fetch return various errors) so it's not yet complete.

I did have quite a bit of help from Eric Biederman, whom I'd like to acknowledge and thank for his help.

---
 builtin-pack-objects.c |   50 ++++++++++++-
 cache.h                |   13 ++-
 index-pack.c           |   30 ++++++-
 pack-check.c           |    8 +-
 pack-redundant.c       |   83 +++++++++++++++------
 pack.h                 |    4 +
 sha1_file.c            |  193 +++++++++++++++++++++++++++++++++++-------------
 show-index.c           |   81 +++++++++++++++-----
 8 files changed, 349 insertions(+), 113 deletions(-)
builtin-pack-objects.c +46 -4
index b5ed9ce..92087c1 100644
@@ -101,7 +101,7 @@ static int object_ix_hashsz;
  * get the object sha1 from the main index.
  */
 struct revindex_entry {
-	unsigned int offset;
+	off_t offset;
 	unsigned int nr;
 };
 struct pack_revindex {
@@ -163,12 +163,12 @@ static int cmp_offset(const void *a_, const void *b_)
 /*
  * Ordered list of offsets of objects in the pack.
  */
-static void prepare_pack_revindex(struct pack_revindex *rix)
+static void prepare_pack_revindex_v0(struct pack_revindex *rix)
 {
 	struct packed_git *p = rix->p;
 	int num_ent = num_packed_objects(p);
 	int i;
-	void *index = p->index_base + 256;
+	void *index = p->index.base + 256;
 
 	rix->revindex = xmalloc(sizeof(*rix->revindex) * (num_ent + 1));
 	for (i = 0; i < num_ent; i++) {
@@ -184,6 +184,43 @@ static void prepare_pack_revindex(struct pack_revindex *rix)
 	qsort(rix->revindex, num_ent, sizeof(*rix->revindex), cmp_offset);
 }
 
+static void prepare_pack_revindex_v1(struct pack_revindex *rix)
+{
+	struct packed_git *p = rix->p;
+	int num_ent = num_packed_objects(p);
+	int i;
+	uint32_t *index = p->index.base + 256 + 2;
+
+	rix->revindex = xmalloc(sizeof(*rix->revindex) * (num_ent + 1));
+	for (i = 0; i < num_ent; i++) {
+		off_t offset;
+		offset = ntohl(*(index + (7 * i)));
+		offset <<=32;
+		offset |= ntohl(*(index + ((7 * i) + 1)));
+		rix->revindex[i].offset = offset;
+		rix->revindex[i].nr = i;
+	}
+	/* This knows the pack format -- the 20-byte trailer
+	 * follows immediately after the last object data.
+	 */
+	rix->revindex[num_ent].offset = p->pack_size - 20;
+	rix->revindex[num_ent].nr = -1;
+	qsort(rix->revindex, num_ent, sizeof(*rix->revindex), cmp_offset);
+}
+static void prepare_pack_revindex(struct pack_revindex *rix)
+{
+	switch (rix->p->index.version)
+	{
+	case 0:
+		return prepare_pack_revindex_v0(rix);
+	case 1:
+		return prepare_pack_revindex_v1(rix);
+	default:
+		die("Unsupported Pack Version");
+
+	}
+}
+
 static struct revindex_entry * find_packed_object(struct packed_git *p,
 						  unsigned int ofs)
 {
@@ -224,7 +261,12 @@ static unsigned char *find_packed_object_name(struct packed_git *p,
 					      unsigned long ofs)
 {
 	struct revindex_entry *entry = find_packed_object(p, ofs);
-	return (unsigned char *)(p->index_base + 256) + 24 * entry->nr + 4;
+	if (p->index.version == 0)
+		return (unsigned char *)(p->index.base + 256) + 24 * entry->nr + 4;
+	else if (p->index.version == 1)
+		return (unsigned char *)(p->index.base + 256 + 2) + 28 * entry->nr + 8;
+	else
+		die("Unsupported index version");
 }
 
 static void *delta_against(void *buf, unsigned long size, struct object_entry *entry)
cache.h +9 -4
index 04f8e63..b329ca4 100644
@@ -362,12 +362,17 @@ struct pack_window {
 	unsigned int inuse_cnt;
 };
 
+struct index_info {
+	off_t	size;
+	uint32_t *base;
+	uint32_t version;
+};
+
 extern struct packed_git {
 	struct packed_git *next;
 	struct pack_window *windows;
-	uint32_t *index_base;
-	off_t index_size;
 	off_t pack_size;
+	struct index_info index;
 	int pack_fd;
 	int pack_local;
 	unsigned char sha1[20];
@@ -376,7 +381,7 @@ extern struct packed_git {
 } *packed_git;
 
 struct pack_entry {
-	unsigned int offset;
+	off_t offset;
 	unsigned char sha1[20];
 	struct packed_git *p;
 };
@@ -420,7 +425,7 @@ extern void unuse_pack(struct pack_window **);
 extern struct packed_git *add_packed_git(char *, int, int);
 extern int num_packed_objects(const struct packed_git *p);
 extern int nth_packed_object_sha1(const struct packed_git *, int, unsigned char*);
-extern unsigned long find_pack_entry_one(const unsigned char *, struct packed_git *);
+extern off_t find_pack_entry_one(const unsigned char *, struct packed_git *);
 extern void *unpack_entry(struct packed_git *, unsigned long, char *, unsigned long *);
 extern unsigned long unpack_object_header_gently(const unsigned char *buf, unsigned long len, enum object_type *type, unsigned long *sizep);
 extern void packed_object_info_detail(struct packed_git *, unsigned long, char *, unsigned long *, unsigned long *, unsigned int *, unsigned char *);
index-pack.c +25 -5
index fa9a0e7..cc22ea2 100644
@@ -12,7 +12,7 @@ static const char index_pack_usage[] =
 
 struct object_entry
 {
-	unsigned long offset;
+	off_t offset;
 	unsigned long size;
 	unsigned int hdr_size;
 	enum object_type type;
@@ -83,7 +83,7 @@ static unsigned display_progress(unsigned n, unsigned total, unsigned last_pc)
 
 /* We always read in 4kB chunks. */
 static unsigned char input_buffer[4096];
-static unsigned long input_offset, input_len, consumed_bytes;
+static off_t input_offset, input_len, consumed_bytes;
 static SHA_CTX input_ctx;
 static int input_fd, output_fd, pack_fd;
 
@@ -707,6 +707,13 @@ static const char *write_index_file(const char *index_name, unsigned char *sha1)
 		die("unable to create %s: %s", index_name, strerror(errno));
 	f = sha1fd(fd, index_name);
 
+	if ( consumed_bytes >= 0xffffffffUL )
+	{
+		struct pack_idx_header hdr;
+		hdr.idx_signature = htonl(PACK_IDX_SIGNATURE);
+		hdr.idx_version = htonl(1);
+		sha1write(f, &hdr, sizeof(hdr));
+	}
 	/*
 	 * Write the first-level table (the list is sorted,
 	 * but we use a 256-entry lookup to be able to avoid
@@ -736,9 +743,22 @@ static const char *write_index_file(const char *index_name, unsigned char *sha1)
 	list = sorted_by_sha;
 	for (i = 0; i < nr_objects; i++) {
 		struct object_entry *obj = *list++;
-		unsigned int offset = htonl(obj->offset);
-		sha1write(f, &offset, 4);
-		sha1write(f, obj->sha1, 20);
+		if ( consumed_bytes < 0xffffffffUL )
+		{
+			unsigned int offset = htonl(obj->offset);
+			sha1write(f, &offset, 4);
+			sha1write(f, obj->sha1, 20);
+		}
+		else
+		{
+			uint32_t low;
+			uint32_t high;
+			low=htonl(obj->offset & 0xffffffff);
+			high=htonl((obj->offset >>32) & 0xffffffff);
+			sha1write(f, &high, 4);
+			sha1write(f, &low, 4);
+			sha1write(f, obj->sha1, 20);
+		}
 		SHA1_Update(&ctx, obj->sha1, 20);
 	}
 	sha1write(f, sha1, 20);
pack-check.c +4 -4
index 08a9fd8..12ee933 100644
@@ -4,8 +4,8 @@
 static int verify_packfile(struct packed_git *p,
 		struct pack_window **w_curs)
 {
-	unsigned long index_size = p->index_size;
-	void *index_base = p->index_base;
+	off_t index_size = p->index.size;
+	void *index_base = p->index.base;
 	SHA_CTX ctx;
 	unsigned char sha1[20];
 	unsigned long offset = 0, pack_sig = p->pack_size - 20;
@@ -123,8 +123,8 @@ static void show_pack_info(struct packed_git *p)
 
 int verify_pack(struct packed_git *p, int verbose)
 {
-	unsigned long index_size = p->index_size;
-	void *index_base = p->index_base;
+	off_t index_size = p->index.size;
+	void *index_base = p->index.base;
 	SHA_CTX ctx;
 	unsigned char sha1[20];
 	int ret;
pack-redundant.c +59 -24

140 lines not on this page · raw message

pack.h +4 -0
index deb427e..fbf7992 100644
@@ -41,6 +41,10 @@ struct pack_header {
  * byte word.  This would be true in the proposed future index
  * format as idx_signature would be greater than idx_version.
  */
+struct pack_idx_header {
+	uint32_t idx_signature;
+	uint32_t idx_version;
+};
 #define PACK_IDX_SIGNATURE 0xff744f63	/* "\377tOc" */
 
 extern int verify_pack(struct packed_git *, int);
sha1_file.c +141 -52

292 lines not on this page · raw message

show-index.c +61 -20

89 lines not on this page · raw message

Signature · 1 line
1.5.0.1
#1 lore raw
Quoted 6 lines · Troy Telford

As I've not been involved with git development before, I'm
aware that this may already be on somebody's 'todo' list. It was an itch I needed to scratch, as I have a repository whose size is multiple gigabytes, and 'git clone' (by default) forces everything into a single packfile with >=git-1.5.0.

Quoted 8 lines

The patch introduces a new packfile index version, which adds a:
* header to the index file (index version info).
* leaves the object indexes within the index at 32-bit
* extends the offsets used to describe the packfile to 64-bit.

The new index format is only used when the associated packfile becomes large enough to warrant a 64-bit index; otherwise the original index format is used.

Clearly a good deal of work has been put into this patch. I cannot say that reviewed every bit of it... because...

Nico and I are neck deep in our pack version 4 topic. That topic hits all of the same code you touched with your patch.

Our topic also requires us to change the index file format, and in doing so we have decided to extend the index records to look something like the following[*1*]:

object SHA-1
64-bit offset within packfile
32-bit index of next object in packfile

The latter field is to help pack-objects reuse existing packfile data, as today it needs to sort everything on its own on the fly. Having that last field of data will help avoid that, and will keep the index nicely aligned for 64-bit accesses to the offset.

I want to say your patch shouldn't be merged without even bothering to review it. The last time I was in this part of the git code (implementing sliding mmap window) Nico and Junio also both went in here and rewrote huge chunks. Their changes prevented sliding mmap window from applying. It was 6 months before I got back around to rewriting the patch.

Right now I'm neck deep in pack v4. I hope to have the topic in pu-ready state by some time mid-next week, hopefully in time for Junio's git day. I'm very unlikely to have the time to rewrite the topic again until late June/July if something like your patch goes in now.

So would you mind waiting a couple of weeks for 64 bit indexes?

*1*: This was Nico's idea; I'm in agreement with him about it.
The actual disk layout here has not been set in stone as we want to kick around different layouts before we settle on something final. I'm a little unhappy with the way the above lays out in memory when we mmap it, for example.

Signature · 1 line
Shawn.
#2 lore raw
Quoted 2 lines · Shawn O. Pearce

Nico and I are neck deep in our pack version 4 topic. That topic hits all of the same code you touched with your patch.

It looked like that may have been the case; but I figured it wouldn't hurt. I've been coping with the 'too-small' index issue for about a year now, and have been on IRC and kept at least a lazy eye on it hoping that it would be attended to.

I've decided I need to start doing some C coding again, and it seemed to be as good an itch as any to scratch...

Quoted 4 lines

Our topic also requires us to change the index file format, and in doing so we have decided to extend the index records to look something like the following[*1*]:

Quoted 8 lines

object SHA-1
64-bit offset within packfile
32-bit index of next object in packfile

The latter field is to help pack-objects reuse existing packfile data, as today it needs to sort everything on its own on the fly. Having that last field of data will help avoid that, and will keep the index nicely aligned for 64-bit accesses to the offset.

Exactly why I left the packfile itself alone. Well, that and laziness. I may have a huge repository, but I don't have single files so large that it needs a 32-bit index for the next object in the packfile.

Most of the things that large I've seen are binary anyway.

Quoted 2 lines

I want to say your patch shouldn't be merged without even bothering to review it.

No hard feelings on my part, it was as much a learning thing for me as anything else.

Quoted 5 lines

The last time I was in this part of the git code (implementing sliding mmap window) Nico and Junio also both went in here and rewrote huge chunks. Their changes prevented sliding mmap window from applying. It was 6 months before I got back around to rewriting the patch.

Ouch.

Quoted 7 lines

Right now I'm neck deep in pack v4. I hope to have the topic in pu-ready state by some time mid-next week, hopefully in time for Junio's git day. I'm very unlikely to have the time to rewrite the topic again until late June/July if something like your patch goes in now.

So would you mind waiting a couple of weeks for 64 bit indexes?

All I'm concerned with is being able to handle my (huge) source repository with git. I wrote the patch in the hopes that it would accelerate the process, and that I'd learn something. If all I have to do is wait that's fine. I figured I'd at least be able to bring an idea or two to the table. If the code doesn't get accepted, but still get the desired functionality, I still met 1/2 of my goals in doing it.

Signature · 1 line
Troy Telford
#3 lore raw
In reply to Shawn O. Pearce
Quoted 4 lines · Shawn O. Pearce

Our topic also requires us to change the index file format, and in doing so we have decided to extend the index records to look something like the following[*1*]:

Quoted 8 lines

object SHA-1
64-bit offset within packfile
32-bit index of next object in packfile

The latter field is to help pack-objects reuse existing packfile data, as today it needs to sort everything on its own on the fly. Having that last field of data will help avoid that, and will keep the index nicely aligned for 64-bit accesses to the offset.

Wouldn't that later field help the sliding mmap code as well, knowing in advance what storage size a given object has? (I didn't look at the sliding mmap code so I don't know).

Actually I've been thinking about another format already.

What about keeping the pack offset as 32 bits like it is today, but for index v2 if the top bit is set then this become an index into another table containing 64-bit offsets as needed. This way there is no waste of space for most projects where the pack has yet to reach the 2GB limit for many years to come.

Nicolas

#4 lore raw
Quoted 9 lines · Nicolas Pitre
Quoted 4 lines · Shawn O. Pearce

The latter field is to help pack-objects reuse existing packfile data, as today it needs to sort everything on its own on the fly. Having that last field of data will help avoid that, and will keep the index nicely aligned for 64-bit accesses to the offset.

Wouldn't that later field help the sliding mmap code as well, knowing in advance what storage size a given object has? (I didn't look at the sliding mmap code so I don't know).

Yes, it probably would.

Quoted 7 lines

Actually I've been thinking about another format already.

What about keeping the pack offset as 32 bits like it is today, but for index v2 if the top bit is set then this become an index into another table containing 64-bit offsets as needed. This way there is no waste of space for most projects where the pack has yet to reach the 2GB limit for many years to come.

Actually Troy's patch tries to do this by using the current format and only switching to the new one if the packfile exceeds 4 GiB. Rather smart.

One thought I had here was to expand the fan-out table from 1<<8 entries to 1<<16 entries, then store only the low 18 bytes of the SHA-1. We would have another 2 bytes worth of space to store the offset, pushing our total offset up to 48 bits.

Signature · 1 line
Shawn.
#5 lore raw
Quoted 9 lines · Shawn O. Pearce
Quoted 7 lines · Nicolas Pitre

Actually I've been thinking about another format already.

What about keeping the pack offset as 32 bits like it is today, but for index v2 if the top bit is set then this become an index into another table containing 64-bit offsets as needed. This way there is no waste of space for most projects where the pack has yet to reach the 2GB limit for many years to come.

Quoted 3 lines

Actually Troy's patch tries to do this by using the current format and only switching to the new one if the packfile exceeds 4 GiB. Rather smart.

Yes I saw the patch. But what I propose is different. In fact I'd require far less changes to the existing code. The idea is to continue to store a 32-bit value along with the SHA1 just like we do today. Then, appended to that would be another table containing a list of 64-bit offsets.

Now if the offset stored in the index is smaller than 2GB you store it as we do today. If it is >= 2GB then a 64-bit index would be added to the extra offset table and the 32-bit entry along with the SHA1 would be an index into that second table instead, with the top bit set to distinguish it from a normal 32-bit offset (actually 31 bits). So for offsets larger than 31 bits then they have an additional level of indirection.

The code to implement this would be minimal. And since objects placed at the end of a pack (those more likely to incure the indirection overhead) are further back in history they won't get accessed very often anyway.

Then nothing prevents us from inserting the next-object-index table in between (its size is known while the 64-bit offset one may vary) then the code that doesn't care about it need no look at it.

Quoted 4 lines

One thought I had here was to expand the fan-out table from 1<<8 entries to 1<<16 entries, then store only the low 18 bytes of the SHA-1. We would have another 2 bytes worth of space to store the offset, pushing our total offset up to 48 bits.

That would penalize small packs a lot. the index would always start from 256KB in size. With a pack of 100 objects (our current treshold for keeping a pack) that means a 258KB index file. Currently the index file for a 100-object pack is 3.4KB.

Nicolas

#6 lore raw
Quoted 9 lines · Nicolas Pitre
Quoted 4 lines

One thought I had here was to expand the fan-out table from 1<<8 entries to 1<<16 entries, then store only the low 18 bytes of the SHA-1. We would have another 2 bytes worth of space to store the offset, pushing our total offset up to 48 bits.

That would penalize small packs a lot. the index would always start from 256KB in size. With a pack of 100 objects (our current treshold for keeping a pack) that means a 258KB index file. Currently the index file for a 100-object pack is 3.4KB.

Why can't we do it with the current 1<<8 entry fan-out? This would allow increases of pack file size up to 1 TB. For larger repositories, we just need to use multiple pack files. A couple hundred 1 TB pack files doesn't seem to be a big issue.

Say a couple years from now, we can write data to stable storage (disks/flash/holograms or whatever) at 1 GB/sec, then it would still take 16 minutes to write a 1 TB file. At that point we'd need a bigger overhaul than just larger offsets in the pack file.

BTW, here are a few issues with the current pack file format:
- The final SHA1 consists of the count of objects in the file and all compressed data. Why? This is horrible for streaming applications where you only know the count of objects at the end, then you need to access *all* data to compute the SHA-1. Much better to just use compute a SHA1 over the SHA1's of each object. That way at least the data streamed can be streamed to disk. Buffering one SHA1 per object is probably going to be OK.

- The object count is implicit in the SHA1 of all objects and the objects we find in the file. Why do we need it in the first place? Better to recompute it when necessary. This makes true streaming possible.

-Geert

#7 lore raw
Quoted 2 lines · Geert Bosch

Why can't we do it with the current 1<<8 entry fan-out? This would allow increases of pack file size up to 1 TB.

I had the exact same thought while I was writing the previous mail. It is indeed perfectly fine and would require less than 10 lines of code to implement.

Quoted 8 lines

BTW, here are a few issues with the current pack file format:
- The final SHA1 consists of the count of objects in the file and all compressed data. Why? This is horrible for streaming applications where you only know the count of objects at the end, then you need to access *all* data to compute the SHA-1. Much better to just use compute a SHA1 over the SHA1's of each object. That way at least the data streamed can be streamed to disk. Buffering one SHA1 per object is probably going to be OK.

We always know the number of objects before actually constructing or streaming a pack. Finding best delta matches require that we sort the object list by type, but for good locality we need to re-sort that list by recency. So we always know the number of objects before starting to write since we need to have the list of objects in memory anyway.

Also the receiving end of a streamed pack wants to know the number of objects first if only to provide the user with some progress report.

Quoted 4 lines

- The object count is implicit in the SHA1 of all objects and the objects we find in the file. Why do we need it in the first place? Better to recompute it when necessary. This makes true streaming possible.

Sorry, I don't follow you here.

Nicolas

#8 lore raw
Quoted 9 lines · Nicolas Pitre
Quoted 8 lines

BTW, here are a few issues with the current pack file format:
- The final SHA1 consists of the count of objects in the file and all compressed data. Why? This is horrible for streaming applications where you only know the count of objects at the end, then you need to access *all* data to compute the SHA-1. Much better to just use compute a SHA1 over the SHA1's of each object. That way at least the data streamed can be streamed to disk. Buffering one SHA1 per object is probably going to be OK.

Quoted 5 lines

We always know the number of objects before actually constructing or streaming a pack. Finding best delta matches require that we sort the object list by type, but for good locality we need to re-sort that list by recency. So we always know the number of objects before starting to write since we need to have the list of objects in memory anyway.

When I import a large code-base (such as a *.tar.gz), I don't know beforehand how many objects I'm going to create. Ideally, I'd like to stream them directly into a new pack without ever having to write the expanded source to the filesystem.

Quoted 9 lines

Also the receiving end of a streamed pack wants to know the number of objects first if only to provide the user with some progress report.

Quoted 4 lines

- The object count is implicit in the SHA1 of all objects and the objects we find in the file. Why do we need it in the first place? Better to recompute it when necessary. This makes true streaming possible.

Sorry, I don't follow you here.

The object-count at the beginning of the pack is a little strange for local on-disk pack files, as it is data that can easily be derived. The *index* would seem to be the proper place for this.

Also, it is not possible to write a dummy 0 in the count and then fill in the correct count at the end, because the final SHA1 at the end of the pack file is a checksum over the count followed by all the pack data.
So for creating a large pack from a stream of data, you have to do the following:
1. write out a temporary pack file to disk without correct count
2. fix-up the count
3. read the entire temporary pack file to compute the final SHA-1
4. fix-up the SHA1 at the end of the file
5. construct and write out the index

There are a few ways to fixing this:
- Have a count of 0xffffffff mean: look in the index for the count. Pulling/pushing would still use regular counted pack files.
- Have the pack file checksum be the SHA1 of (the count followed by the SHA1 of the compressed data of each object). This would
allow 3.
to be done without reading back all data.

-Geert

#9 lore raw
Quoted 4 lines · Geert Bosch

When I import a large code-base (such as a *.tar.gz), I don't know beforehand how many objects I'm going to create. Ideally, I'd like to stream them directly into a new pack without ever having to write the expanded source to the filesystem.

See git-fast-import. If you are coming from a tar, also see contrib/fast-import/import-tars.perl. :-)

Quoted 7 lines

So for creating a large pack from a stream of data, you have to do the following:
1. write out a temporary pack file to disk without correct count
2. fix-up the count
3. read the entire temporary pack file to compute the final SHA-1
4. fix-up the SHA1 at the end of the file
5. construct and write out the index

Yes, this is exactly what git-fast-import does. Yes, it sort of sucks. But its not as bad as you think.

Quoted 7 lines

There are a few ways to fixing this:
- Have a count of 0xffffffff mean: look in the index for the count. Pulling/pushing would still use regular counted pack files.
- Have the pack file checksum be the SHA1 of (the count followed by the SHA1 of the compressed data of each object). This would
allow 3.
to be done without reading back all data.

I don't think it is worth it. Aside from git-fast-import we always know the object count before we start writing any data. But despite that, fast-import runs quite well.

Signature · 1 line
Shawn.
#10 lore raw
Quoted 8 lines · Shawn O. Pearce
Quoted 4 lines · Geert Bosch

When I import a large code-base (such as a *.tar.gz), I don't know beforehand how many objects I'm going to create. Ideally, I'd like to stream them directly into a new pack without ever having to write the expanded source to the filesystem.

See git-fast-import. If you are coming from a tar, also see contrib/fast-import/import-tars.perl. :-)

Yes, I saw that, really nice. I had written something myself to create pack files from a streaming data source. Basically, I'm breaking arbitrary data-streams (mostly backups) into chunks along content-defined boundaries and then link the chunks together in a tree. This eliminates any duplicate files, and even chunks of larger files that are identical. I create new pack files whenever the old one gets larger than a certain predefined size (128 MB, currently).

I'm happy I can base this on git-fast-import now.

Quoted 10 lines
Quoted 7 lines

So for creating a large pack from a stream of data, you have to do the following:
1. write out a temporary pack file to disk without correct count
2. fix-up the count
3. read the entire temporary pack file to compute the final SHA-1
4. fix-up the SHA1 at the end of the file
5. construct and write out the index

Yes, this is exactly what git-fast-import does. Yes, it sort of sucks. But its not as bad as you think.

For smaller packs, the I/O is all going to be buffered anyway, but if we're going to have >4GB pack files, it adds a lot of real I/O and SHA1 computation for no good reason. If we get a rare chance to have a new pack format, why not fix this wart at the same time?

-Geert

#11 lore raw
Quoted 4 lines · Geert Bosch

For smaller packs, the I/O is all going to be buffered anyway, but if we're going to have >4GB pack files, it adds a lot of real I/O and SHA1 computation for no good reason. If we get a rare chance to have a new pack format, why not fix this wart at the same time?

Fair enough.

Nicolas

#12 lore raw
Quoted 7 lines · Nicolas Pitre
Quoted 4 lines · Geert Bosch

For smaller packs, the I/O is all going to be buffered anyway, but if we're going to have >4GB pack files, it adds a lot of real I/O and SHA1 computation for no good reason. If we get a rare chance to have a new pack format, why not fix this wart at the same time?

Fair enough.

OK, so lets say that if both ends of a network transport support pack v4 then we can use pack v4. If pack v4 omits the count field from its header (because its easily derived or obtained from the index, and doesn't add any additional data protection over the SHA-1s) why not add some machine-readable sideband that can provide transfer progress?

I think we would want four values, number of objects (sent/total) and uncompressed bytes (sent/total), to send to the client.

Estimating the total uncompressed bytes is very easy in pack-objects before we start sending even the header; actually if we are reusing a majority of the objects from an existing packfile we even have a good approximation of the compressed size ready. That would give the client a reasonable progress meter; certainly better than nothing at all! ;-)

Signature · 1 line
Shawn.
#13 lore raw
Quoted 7 lines · Shawn O. Pearce
Quoted 6 lines · Nicolas Pitre
Quoted 4 lines · Geert Bosch

For smaller packs, the I/O is all going to be buffered anyway, but if we're going to have >4GB pack files, it adds a lot of real I/O and SHA1 computation for no good reason. If we get a rare chance to have a new pack format, why not fix this wart at the same time?

Quoted 7 lines
Quoted 1 line

Fair enough.

OK, so lets say that if both ends of a network transport support pack v4 then we can use pack v4. If pack v4 omits the count field from its header (because its easily derived or obtained from the index, and doesn't add any additional data protection over the SHA-1s)

I don't agree we should omit it at all.

I agree it might just not be included in the whole pack SHA1. Actually the whole pack header might be ommitted from the pack SHA1. This way, if data is appended at the end like index-pack does in the thin pack case, the header can be fixed up without invalidating the SHA1 that was computed while receiving the pack. Why the whole header? Well who knows if we won't dynamically change the pack version while receiving it as well in the future. In fact, we could just add the header to the SHA1 checksum but after the data payload (for the checksum only not in the actual pack). this way we preserve the same protection/validity strength as we have today.

Quoted 5 lines

why not add some machine-readable sideband that can provide transfer progress?

I think we would want four values, number of objects (sent/total) and uncompressed bytes (sent/total), to send to the client.

Uncompressed bytes is meaningless when evaluating throughput of compressed data since compression ratio is variable during a single fetch. It doesn't provide more accurate progress than what we have today with number of objects either.

Quoted 6 lines

Estimating the total uncompressed bytes is very easy in pack-objects before we start sending even the header; actually if we are reusing a majority of the objects from an existing packfile we even have a good approximation of the compressed size ready. That would give the client a reasonable progress meter; certainly better than nothing at all! ;-)

IMHO it is not worth it. And it won't help git-pack-index if run on a local pack either.

Nicolas

#14 lore raw
In reply to Geert Bosch

Hi,

Quoted 2 lines · Geert Bosch

The object-count at the beginning of the pack is a little strange for local on-disk pack files, as it is data that can easily be derived.

The SHA1 is also easily derived. So think of it as a doubly secure way to ensure integrity.

Remember, there were some people unable to accept that SHA1 collisions are _unlikely_...

Ciao,
Dscho

#15 lore raw
Quoted 10 lines · Johannes Schindelin
Quoted 2 lines · Geert Bosch

The object-count at the beginning of the pack is a little strange for local on-disk pack files, as it is data that can easily be derived.

The SHA1 is also easily derived. So think of it as a doubly secure way to ensure integrity.

Remember, there were some people unable to accept that SHA1 collisions are _unlikely_...

Ah, you include the count because you don't trust the SHA1 and now you can count that you got the right number of objects ;-)

It's just that I don't see a use for the count in a local on-disk pack. In these cases we'll always have an index. We can keep the current protocol for sending/receiving packs, no need to ever upgrade to v4 there.

-Geert

#16 lore raw

Hi,

Quoted 8 lines · Geert Bosch
Quoted 6 lines · Johannes Schindelin
Quoted 3 lines · Geert Bosch

The object-count at the beginning of the pack is a little strange for local on-disk pack files, as it is data that can easily be derived.

Quoted 8 lines
Quoted 5 lines

The SHA1 is also easily derived. So think of it as a doubly secure way to ensure integrity.

Remember, there were some people unable to accept that SHA1 collisions are _unlikely_...

Ah, you include the count because you don't trust the SHA1 and now you can count that you got the right number of objects ;-)

I don't know if it was included for that reason, but you can excuse it that way. :-)

Quoted 4 lines

It's just that I don't see a use for the count in a local on-disk pack. In these cases we'll always have an index. We can keep the current protocol for sending/receiving packs, no need to ever upgrade to v4 there.

But the protocol expects a valid pack! (Including a count...)

Besides, the pack index is a purely local thin, reconstructed from the pack when fetching...

Ciao,
Dscho

#17 lore raw
In reply to Geert Bosch
Quoted 18 lines · Geert Bosch
Quoted 9 lines · Nicolas Pitre
Quoted 8 lines

BTW, here are a few issues with the current pack file format:
- The final SHA1 consists of the count of objects in the file and all compressed data. Why? This is horrible for streaming applications where you only know the count of objects at the end, then you need to access *all* data to compute the SHA-1. Much better to just use compute a SHA1 over the SHA1's of each object. That way at least the data streamed can be streamed to disk. Buffering one SHA1 per object is probably going to be OK.

Quoted 5 lines

We always know the number of objects before actually constructing or streaming a pack. Finding best delta matches require that we sort the object list by type, but for good locality we need to re-sort that list by recency. So we always know the number of objects before starting to write since we need to have the list of objects in memory anyway.

Quoted 4 lines

When I import a large code-base (such as a *.tar.gz), I don't know beforehand how many objects I'm going to create. Ideally, I'd like to stream them directly into a new pack without ever having to write the expanded source to the filesystem.

Have a look at git-fast-import and contrib/fast-import/import-tars.perl.

Regardless, you cannot produce a decent pack without knowing in advance how many objects you have. Thisis why git-fast-import produces a suboptimal pack that needs to be repacked in the end.

Quoted 3 lines

The object-count at the beginning of the pack is a little strange for local on-disk pack files, as it is data that can easily be derived. The *index* would seem to be the proper place for this.

The index is _not_ sent over the network protocol by design. But like I said the receiving end wants to know up front how many objects it'll have to parse.

Quoted 10 lines

Also, it is not possible to write a dummy 0 in the count and then fill in the correct count at the end, because the final SHA1 at the end of the pack file is a checksum over the count followed by all the pack data. So for creating a large pack from a stream of data, you have to do the following:
1. write out a temporary pack file to disk without correct count
2. fix-up the count
3. read the entire temporary pack file to compute the final SHA-1
4. fix-up the SHA1 at the end of the file
5. construct and write out the index

Sure. That's in fact what index-pack does when it has to fix up a thin pack. But did you find any _real_ issue with this? Resolving deltas and recomputing the index is far more costly than simply redoing the whole pack checksum.

Quoted 6 lines

There are a few ways to fixing this:
- Have a count of 0xffffffff mean: look in the index for the count. Pulling/pushing would still use regular counted pack files.
- Have the pack file checksum be the SHA1 of (the count followed by the SHA1 of the compressed data of each object). This would allow 3. to be done without reading back all data.

Well we _could_ exclude the object count (or even the entire pack header for that matter) from the pack checksum. This way a streamed pack streamed to disk could be seeked back to have its object number fixed up once it is known without needing to start the checksum all over. Maybe something to consider for pack v4. But in practice I don't see that as a big issue.

Nicolas

#18 lore raw
In reply to Shawn O. Pearce
Quoted 2 lines · Shawn O. Pearce

Nico and I are neck deep in our pack version 4 topic. That topic hits all of the same code you touched with your patch.

Although a good deal of code has been written already, we're still throwing completely crazy ideas back and forth which, if they survive the reality test, might change things quite a lot for the index.

Quoted 3 lines

Our topic also requires us to change the index file format, and in doing so we have decided to extend the index records to look something like the following[*1*]:

[ delete new index format layout description ]

Although I suggested that format... like... yesterday, I'm already dismissing it now. I'd go with what I just posted instead.

But yet this depends on whether or not we consider this latest idea of ours a good thing or not, which require some math to be done to prove its usefulness.

Maybe we should post our notes here in order to gather extra comments from people or to debunk some of our insane ideas faster.

Quoted 6 lines

I want to say your patch shouldn't be merged without even bothering to review it. The last time I was in this part of the git code (implementing sliding mmap window) Nico and Junio also both went in here and rewrote huge chunks. Their changes prevented sliding mmap window from applying. It was 6 months before I got back around to rewriting the patch.

The thing is, regardless of the pack v4 work, I think the approach used is not the best one. And because of the pack v4 work, we'll have to settle on something before too long anyway.

Quoted 1 line

So would you mind waiting a couple of weeks for 64 bit indexes?

Of course Troy's patch might be used by those who need it now. I think Junio might even park it in pu for reference. The pack index is not a precious piece of information and it can be thrown away and recreated with git-index-pack whenever there is an officially supported new index format.

Quoted 1 line

*1*: This was Nico's idea; I'm in agreement with him about it.

As mentioned above I'm not in agreement with myself anymore about it. ;-)

Nicolas

#19 lore raw
In reply to Troy Telford

Subject: [PATCH] 32-bit support for large indexes

This patch continues the work I've done on large indexes, and was completed largely as an educational exercise; I'm obviously aware of Pack v4 making these two patches unnecessary, and that inclusion is unlikely. I'm submitting the patch to make my previous patch on 64-bit indexes more complete, should anyone actually use it.

It also introduced changes that may be expressing a bug
in the SHA1 code. (Or at least, that's all myself and Eric Biederman can think of... but it was late and we were tired.)

The long and the short of it is a large number of 'offset' variables are 'unsigned long', and needed to be changed to 'off_t', with a few cleanups
to accommodate this change.

The primary goal was to get the extended index to work on x86 (as well as x86_64) machines. Operations such as 'git fetch/pull', 'git cat-file -p', and of course 'git-fsck --full' were either failing or reporting errors.

In the process of testing, I found an issue on x86 (x86_64 worked fine) where 'git-fsck' would report problems "error: packed <sha1> from <packfile> is corrupt" (On 3 files in a very large repository; the number of 'corrupt' files is a small percentage)

The patch has some (currently disabled) code that would write the offending blobs to disk, as well as print some related data to the screen. In the test repository, the 'corrupt' blobs were fairly large binaries, which ended up being either tar.gz or tar.bz2. (Of sizes 200-19 MB). I checked the blobs for internal consistency (gzip -t and bzip2 -t), and they checked out OK. Similarly, git-cat-file -p could extract the 'corrupt' blob without any issues.

Being a bit confused at this point, I checked with Eric Biederman, who also couldn't find why the blob was being labeled as 'corrupt'. Eric's only guess was that something funny was happening in the SHA1 generation, which I don't believe my code even touches.

That being said, the only problem I've found at this point is with git-fsck, and then only with 32-bit machines. Other (previously broken with both the old and 'new' index formats) operations such as fetch/pull, and cat-file now work on 32-bit systems. This marks the first time I've ever been able to use git with my large repository on 32-bit systems.

---
 builtin-pack-objects.c   |   30 ++++++++++----------
 builtin-unpack-objects.c |   12 ++++----
 cache.h                  |    6 ++--
 index-pack.c             |   20 +++++++------
 pack-check.c             |   35 ++++++++++++++++++++----
 sha1_file.c              |   67 ++++++++++++++++++++++++++-------------------
 6 files changed, 103 insertions(+), 67 deletions(-)
builtin-pack-objects.c +15 -15
index 92087c1..c1b41b5 100644
@@ -23,7 +23,7 @@ git-pack-objects [{ -q | --progress | --all-progress }] \n\
 struct object_entry {
 	unsigned char sha1[20];
 	unsigned long size;	/* uncompressed size */
-	unsigned long offset;	/* offset into the final pack file;
+	off_t offset;		/* offset into the final pack file;
 				 * nonzero if already written.
 				 */
 	unsigned int depth;	/* delta depth */
@@ -222,7 +222,7 @@ static void prepare_pack_revindex(struct pack_revindex *rix)
 }
 
 static struct revindex_entry * find_packed_object(struct packed_git *p,
-						  unsigned int ofs)
+						  off_t ofs)
 {
 	int num;
 	int lo, hi;
@@ -250,15 +250,15 @@ static struct revindex_entry * find_packed_object(struct packed_git *p,
 	die("internal error: pack revindex corrupt");
 }
 
-static unsigned long find_packed_object_size(struct packed_git *p,
-					     unsigned long ofs)
+static off_t find_packed_object_size(struct packed_git *p,
+					     off_t ofs)
 {
 	struct revindex_entry *entry = find_packed_object(p, ofs);
 	return entry[1].offset - ofs;
 }
 
 static unsigned char *find_packed_object_name(struct packed_git *p,
-					      unsigned long ofs)
+					      off_t ofs)
 {
 	struct revindex_entry *entry = find_packed_object(p, ofs);
 	if (p->index.version == 0)
@@ -320,7 +320,7 @@ static int encode_header(enum object_type type, unsigned long size, unsigned cha
  */
 static int check_pack_inflate(struct packed_git *p,
 		struct pack_window **w_curs,
-		unsigned long offset,
+		off_t offset,
 		unsigned long len,
 		unsigned long expect)
 {
@@ -347,7 +347,7 @@ static int check_pack_inflate(struct packed_git *p,
 static void copy_pack_data(struct sha1file *f,
 		struct packed_git *p,
 		struct pack_window **w_curs,
-		unsigned long offset,
+		off_t offset,
 		unsigned long len)
 {
 	unsigned char *in;
@@ -483,7 +483,7 @@ static unsigned long write_object(struct sha1file *f,
 			 * encoding of the relative offset for the delta
 			 * base from this object's position in the pack.
 			 */
-			unsigned long ofs = entry->offset - entry->delta->offset;
+			off_t ofs = entry->offset - entry->delta->offset;
 			unsigned pos = sizeof(header) - 1;
 			header[pos] = ofs & 127;
 			while (ofs >>= 7)
@@ -504,7 +504,7 @@ static unsigned long write_object(struct sha1file *f,
 	else {
 		struct packed_git *p = entry->in_pack;
 		struct pack_window *w_curs = NULL;
-		unsigned long offset;
+		off_t offset;
 
 		if (entry->delta) {
 			obj_type = (allow_ofs_delta && entry->delta->offset) ?
@@ -514,7 +514,7 @@ static unsigned long write_object(struct sha1file *f,
 		hdrlen = encode_header(obj_type, entry->size, header);
 		sha1write(f, header, hdrlen);
 		if (obj_type == OBJ_OFS_DELTA) {
-			unsigned long ofs = entry->offset - entry->delta->offset;
+			off_t ofs = entry->offset - entry->delta->offset;
 			unsigned pos = sizeof(header) - 1;
 			header[pos] = ofs & 127;
 			while (ofs >>= 7)
@@ -544,7 +544,7 @@ static unsigned long write_object(struct sha1file *f,
 
 static unsigned long write_one(struct sha1file *f,
 			       struct object_entry *e,
-			       unsigned long offset)
+			       off_t offset)
 {
 	if (e->offset || e->preferred_base)
 		/* offset starts from header size and cannot be zero
@@ -562,7 +562,7 @@ static void write_pack_file(void)
 {
 	int i;
 	struct sha1file *f;
-	unsigned long offset;
+	off_t offset;
 	struct pack_header hdr;
 	unsigned last_percent = 999;
 	int do_progress = progress;
@@ -721,7 +721,7 @@ static int add_object_entry(const unsigned char *sha1, unsigned hash, int exclud
 
 	if (!exclude) {
 		for (p = packed_git; p; p = p->next) {
-			unsigned long offset = find_pack_entry_one(sha1, p);
+			off_t offset = find_pack_entry_one(sha1, p);
 			if (offset) {
 				if (incremental)
 					return 0;
@@ -1044,7 +1044,7 @@ static void check_object(struct object_entry *entry)
 		 */
 		if (!no_reuse_delta) {
 			unsigned char c, *base_name;
-			unsigned long ofs;
+			off_t ofs;
 			unsigned long used_0;
 			/* there is at least 20 bytes left in the pack */
 			switch (entry->in_pack_type) {
@@ -1061,7 +1061,7 @@ static void check_object(struct object_entry *entry)
 				ofs = c & 127;
 				while (c & 128) {
 					ofs += 1;
-					if (!ofs || ofs & ~(~0UL >> 7))
+					if (!ofs || ofs & ~(~((off_t) 0) >> 7))
 						die("delta base offset overflow in pack for %s",
 						    sha1_to_hex(entry->sha1));
 					c = buf[used_0++];
builtin-unpack-objects.c +6 -6
index 8f8e898..b85c557 100644
@@ -13,7 +13,7 @@ static const char unpack_usage[] = "git-unpack-objects [-n] [-q] [-r] < pack-fil
 
 /* We always read in 4kB chunks. */
 static unsigned char buffer[4096];
-static unsigned long offset, len, consumed_bytes;
+static off_t offset, len, consumed_bytes;
 static SHA_CTX ctx;
 
 /*
@@ -88,7 +88,7 @@ static void *get_data(unsigned long size)
 
 struct delta_info {
 	unsigned char base_sha1[20];
-	unsigned long base_offset;
+	off_t base_offset;
 	unsigned long size;
 	void *delta;
 	unsigned nr;
@@ -98,7 +98,7 @@ struct delta_info {
 static struct delta_info *delta_list;
 
 static void add_delta_to_list(unsigned nr, unsigned const char *base_sha1,
-			      unsigned long base_offset,
+			      off_t base_offset,
 			      void *delta, unsigned long size)
 {
 	struct delta_info *info = xmalloc(sizeof(*info));
@@ -113,7 +113,7 @@ static void add_delta_to_list(unsigned nr, unsigned const char *base_sha1,
 }
 
 struct obj_info {
-	unsigned long offset;
+	off_t offset;
 	unsigned char sha1[20];
 };
 
@@ -209,7 +209,7 @@ static void unpack_delta_entry(enum object_type kind, unsigned long delta_size,
 	} else {
 		unsigned base_found = 0;
 		unsigned char *pack, c;
-		unsigned long base_offset;
+		off_t base_offset;
 		unsigned lo, mid, hi;
 
 		pack = fill(1);
@@ -218,7 +218,7 @@ static void unpack_delta_entry(enum object_type kind, unsigned long delta_size,
 		base_offset = c & 127;
 		while (c & 128) {
 			base_offset += 1;
-			if (!base_offset || base_offset & ~(~0UL >> 7))
+			if (!base_offset || base_offset & ~(~((off_t) 0) >> 7))
 				die("offset value overflow for delta base object");
 			pack = fill(1);
 			c = *pack;
cache.h +3 -3
index b329ca4..88565b0 100644
@@ -420,15 +420,15 @@ extern struct packed_git *find_sha1_pack(const unsigned char *sha1,
 					 struct packed_git *packs);
 
 extern void pack_report(void);
-extern unsigned char* use_pack(struct packed_git *, struct pack_window **, unsigned long, unsigned int *);
+extern unsigned char* use_pack(struct packed_git *, struct pack_window **, off_t, unsigned int *);
 extern void unuse_pack(struct pack_window **);
 extern struct packed_git *add_packed_git(char *, int, int);
 extern int num_packed_objects(const struct packed_git *p);
 extern int nth_packed_object_sha1(const struct packed_git *, int, unsigned char*);
 extern off_t find_pack_entry_one(const unsigned char *, struct packed_git *);
-extern void *unpack_entry(struct packed_git *, unsigned long, char *, unsigned long *);
+extern void *unpack_entry(struct packed_git *, off_t, char *, unsigned long *);
 extern unsigned long unpack_object_header_gently(const unsigned char *buf, unsigned long len, enum object_type *type, unsigned long *sizep);
-extern void packed_object_info_detail(struct packed_git *, unsigned long, char *, unsigned long *, unsigned long *, unsigned int *, unsigned char *);
+extern void packed_object_info_detail(struct packed_git *, off_t, char *, unsigned long *, unsigned long *, unsigned int *, unsigned char *);
 
 /* Dumb servers support */
 extern int update_server_info(int);
index-pack.c +11 -9
index cc22ea2..ef10e38 100644
@@ -22,7 +22,7 @@ struct object_entry
 
 union delta_base {
 	unsigned char sha1[20];
-	unsigned long offset;
+	off_t offset;
 };
 
 /*
@@ -173,10 +173,10 @@ static void parse_pack_header(void)
 	use(sizeof(struct pack_header));
 }
 
-static void bad_object(unsigned long offset, const char *format,
+static void bad_object(off_t offset, const char *format,
 		       ...) NORETURN __attribute__((format (printf, 2, 3)));
 
-static void bad_object(unsigned long offset, const char *format, ...)
+static void bad_object(off_t offset, const char *format, ...)
 {
 	va_list params;
 	char buf[1024];
@@ -184,10 +184,11 @@ static void bad_object(unsigned long offset, const char *format, ...)
 	va_start(params, format);
 	vsnprintf(buf, sizeof(buf), format, params);
 	va_end(params);
-	die("pack has bad object at offset %lu: %s", offset, buf);
+	die("pack has bad object at offset %llu: %s",
+		(unsigned long long) offset, buf);
 }
 
-static void *unpack_entry_data(unsigned long offset, unsigned long size)
+static void *unpack_entry_data(off_t offset, unsigned long size)
 {
 	z_stream stream;
 	void *buf = xmalloc(size);
@@ -216,7 +217,8 @@ static void *unpack_entry_data(unsigned long offset, unsigned long size)
 static void *unpack_raw_entry(struct object_entry *obj, union delta_base *delta_base)
 {
 	unsigned char *p, c;
-	unsigned long size, base_offset;
+	unsigned long size;
+	off_t base_offset;
 	unsigned shift;
 
 	obj->offset = consumed_bytes;
@@ -249,7 +251,7 @@ static void *unpack_raw_entry(struct object_entry *obj, union delta_base *delta_
 		base_offset = c & 127;
 		while (c & 128) {
 			base_offset += 1;
-			if (!base_offset || base_offset & ~(~0UL >> 7))
+			if (!base_offset || base_offset & ~(~((off_t)0) >> 7))
 				bad_object(obj->offset, "offset value overflow for delta base object");
 			p = fill(1);
 			c = *p;
@@ -275,8 +277,8 @@ static void *unpack_raw_entry(struct object_entry *obj, union delta_base *delta_
 
 static void *get_data_from_pack(struct object_entry *obj)
 {
-	unsigned long from = obj[0].offset + obj[0].hdr_size;
-	unsigned long len = obj[1].offset - from;
+	off_t from = obj[0].offset + obj[0].hdr_size;
+	off_t len = obj[1].offset - from;
 	unsigned char *src, *data;
 	z_stream stream;
 	int st;
pack-check.c +29 -6
index 12ee933..af5fd3b 100644
@@ -8,7 +8,7 @@ static int verify_packfile(struct packed_git *p,
 	void *index_base = p->index.base;
 	SHA_CTX ctx;
 	unsigned char sha1[20];
-	unsigned long offset = 0, pack_sig = p->pack_size - 20;
+	off_t offset = 0, pack_sig = p->pack_size - 20;
 	int nr_objects, err, i;
 
 	/* Note that the pack header checks are actually performed by
@@ -22,9 +22,11 @@ static int verify_packfile(struct packed_git *p,
 		unsigned int remaining;
 		unsigned char *in = use_pack(p, w_curs, offset, &remaining);
 		offset += remaining;
+/*		printf("Offset: %llu\tpack_sig: %llu\tremaining: %u\tfirst foo\n",(unsigned long long) offset, (unsigned long long) pack_sig, remaining);*/
 		if (offset > pack_sig)
 			remaining -= offset - pack_sig;
 		SHA1_Update(&ctx, in, remaining);
+/*		printf("Offset: %llu\tpack_sig: %llu\tremaining: %u\n",(unsigned long long) offset, (unsigned long long) pack_sig, remaining);*/
 	}
 	SHA1_Final(sha1, &ctx);
 	if (hashcmp(sha1, use_pack(p, w_curs, pack_sig, NULL)))
@@ -33,6 +35,7 @@ static int verify_packfile(struct packed_git *p,
 	if (hashcmp(sha1, (unsigned char *)index_base + index_size - 40))
 		return error("Packfile %s SHA1 mismatch with idx",
 			     p->pack_name);
+/*	printf("Success; pack name: %s\t%s\n", p->pack_name, sha1_to_hex(sha1));*/
 	unuse_pack(w_curs);
 
 	/* Make sure everything reachable from idx is valid.  Since we
@@ -44,7 +47,8 @@ static int verify_packfile(struct packed_git *p,
 		unsigned char sha1[20];
 		void *data;
 		char type[20];
-		unsigned long size, offset;
+		unsigned long size;
+		off_t offset;
 
 		if (nth_packed_object_sha1(p, i, sha1))
 			die("internal error pack-check nth-packed-object");
@@ -58,6 +62,23 @@ static int verify_packfile(struct packed_git *p,
 			continue;
 		}
 		if (check_sha1_signature(sha1, data, size, type)) {
+#if 0
+			int fd;
+			fd = open(sha1_to_hex(sha1), O_RDWR | O_CREAT,0777);
+			if (fd >= 0) {
+				ssize_t written = 0, chunk;
+				while (written != size) {
+					chunk = xwrite(fd, data + written, size - written);
+					if (chunk < 0)
+						die("OUch!");
+					written += chunk;
+				}
+				close(fd);
+				printf("wrote the data\n");
+			}
+#endif
+			printf("Size=%lu\n",size);
+
 			err = error("packed %s from %s is corrupt",
 				    sha1_to_hex(sha1), p->pack_name);
 			free(data);
@@ -85,7 +106,7 @@ static void show_pack_info(struct packed_git *p)
 		char type[20];
 		unsigned long size;
 		unsigned long store_size;
-		unsigned long offset;
+		off_t offset;
 		unsigned int delta_chain_length;
 
 		if (nth_packed_object_sha1(p, i, sha1))
@@ -99,10 +120,12 @@ static void show_pack_info(struct packed_git *p)
 					  base_sha1);
 		printf("%s ", sha1_to_hex(sha1));
 		if (!delta_chain_length)
-			printf("%-6s %lu %lu\n", type, size, offset);
+			printf("%-6s %lu %llu\n", type, size,
+				(unsigned long long) offset);
 		else {
-			printf("%-6s %lu %lu %u %s\n", type, size, offset,
-			       delta_chain_length, sha1_to_hex(base_sha1));
+			printf("%-6s %lu %llu %u %s\n", type, size,
+				(unsigned long long) offset,
+				delta_chain_length, sha1_to_hex(base_sha1));
 			if (delta_chain_length < MAX_CHAIN)
 				chain_histogram[delta_chain_length]++;
 			else
sha1_file.c +39 -28

182 lines not on this page · raw message

Signature · 1 line
1.5.0.2