Fix object packing/unpacking.

This actually successfully packed and unpacked a git archive down to
1.3MB (17MB unpacked).

Right now unpacking is way too noisy, lots of debug messages left.
This commit is contained in:
Linus Torvalds
2005-06-26 08:40:08 -07:00
parent 8ee378a0f0
commit c4fb06c0d0
2 changed files with 49 additions and 62 deletions

View File

@ -96,7 +96,7 @@ static unsigned long write_object(FILE *f, struct object_entry *entry)
unsigned long size;
char type[10];
void *buf = read_sha1_file(entry->sha1, type, &size);
char header[21];
char header[25];
unsigned hdrlen, datalen;
if (!buf)
@ -110,16 +110,16 @@ static unsigned long write_object(FILE *f, struct object_entry *entry)
* instead.
*/
header[0] = ".CTB"[entry->type];
datalen = htonl(size);
memcpy(header+1, &datalen, 4);
hdrlen = 5;
if (entry->delta) {
header[0] = 'D';
memcpy(header+1, entry->delta, 20);
memcpy(header+5, entry->delta, 20);
buf = delta_against(buf, size, entry);
size = entry->delta_size;
hdrlen = 21;
hdrlen = 25;
}
datalen = htonl(size);
memcpy(header+1, &datalen, 4);
fwrite(header, hdrlen, 1, f);
datalen = fwrite_compressed(buf, size, f);
free(buf);