Teach packing about "tag" objects
(And teach sha1_file and unpack-object know how to unpack them too, of course)maint
parent
62bb99606d
commit
a69d094366
|
@ -6,21 +6,21 @@
|
||||||
|
|
||||||
static const char pack_usage[] = "git-pack-objects [--window=N] [--depth=N] base-name < object-list";
|
static const char pack_usage[] = "git-pack-objects [--window=N] [--depth=N] base-name < object-list";
|
||||||
|
|
||||||
enum object_type {
|
/*
|
||||||
OBJ_NONE,
|
* The object type is a single-character shorthand:
|
||||||
OBJ_COMMIT,
|
* - 'C' for "Commit"
|
||||||
OBJ_TREE,
|
* - 'T' for "Tree"
|
||||||
OBJ_BLOB,
|
* - 'B' for "Blob"
|
||||||
OBJ_DELTA
|
* - 'G' for "taG"
|
||||||
};
|
* - 'D' for "Delta"
|
||||||
|
*/
|
||||||
struct object_entry {
|
struct object_entry {
|
||||||
unsigned char sha1[20];
|
unsigned char sha1[20];
|
||||||
unsigned long size;
|
unsigned long size;
|
||||||
unsigned long offset;
|
unsigned long offset;
|
||||||
unsigned int depth;
|
unsigned int depth;
|
||||||
unsigned int hash;
|
unsigned int hash;
|
||||||
enum object_type type;
|
unsigned char type;
|
||||||
unsigned long delta_size;
|
unsigned long delta_size;
|
||||||
struct object_entry *delta;
|
struct object_entry *delta;
|
||||||
};
|
};
|
||||||
|
@ -67,7 +67,7 @@ static unsigned long write_object(struct sha1file *f, struct object_entry *entry
|
||||||
* length, except for deltas that has the 20 bytes of delta sha
|
* length, except for deltas that has the 20 bytes of delta sha
|
||||||
* instead.
|
* instead.
|
||||||
*/
|
*/
|
||||||
header[0] = ".CTB"[entry->type];
|
header[0] = entry->type;
|
||||||
hdrlen = 5;
|
hdrlen = 5;
|
||||||
if (entry->delta) {
|
if (entry->delta) {
|
||||||
header[0] = 'D';
|
header[0] = 'D';
|
||||||
|
@ -164,11 +164,13 @@ static void check_object(struct object_entry *entry)
|
||||||
|
|
||||||
if (!sha1_object_info(entry->sha1, type, &entry->size)) {
|
if (!sha1_object_info(entry->sha1, type, &entry->size)) {
|
||||||
if (!strcmp(type, "commit")) {
|
if (!strcmp(type, "commit")) {
|
||||||
entry->type = OBJ_COMMIT;
|
entry->type = 'C';
|
||||||
} else if (!strcmp(type, "tree")) {
|
} else if (!strcmp(type, "tree")) {
|
||||||
entry->type = OBJ_TREE;
|
entry->type = 'T';
|
||||||
} else if (!strcmp(type, "blob")) {
|
} else if (!strcmp(type, "blob")) {
|
||||||
entry->type = OBJ_BLOB;
|
entry->type = 'B';
|
||||||
|
} else if (!strcmp(type, "tag")) {
|
||||||
|
entry->type = 'G';
|
||||||
} else
|
} else
|
||||||
die("unable to pack object %s of type %s",
|
die("unable to pack object %s of type %s",
|
||||||
sha1_to_hex(entry->sha1), type);
|
sha1_to_hex(entry->sha1), type);
|
||||||
|
|
|
@ -695,6 +695,9 @@ static int packed_object_info(struct pack_entry *entry,
|
||||||
case 'B':
|
case 'B':
|
||||||
strcpy(type, "blob");
|
strcpy(type, "blob");
|
||||||
break;
|
break;
|
||||||
|
case 'G':
|
||||||
|
strcpy(type, "tag");
|
||||||
|
break;
|
||||||
default:
|
default:
|
||||||
die("corrupted pack file");
|
die("corrupted pack file");
|
||||||
}
|
}
|
||||||
|
@ -807,6 +810,9 @@ static void *unpack_entry(struct pack_entry *entry,
|
||||||
case 'B':
|
case 'B':
|
||||||
strcpy(type, "blob");
|
strcpy(type, "blob");
|
||||||
break;
|
break;
|
||||||
|
case 'G':
|
||||||
|
strcpy(type, "tag");
|
||||||
|
break;
|
||||||
default:
|
default:
|
||||||
die("corrupted pack file");
|
die("corrupted pack file");
|
||||||
}
|
}
|
||||||
|
|
|
@ -124,6 +124,7 @@ static int unpack_non_delta_entry(struct pack_entry *entry,
|
||||||
case 'C': type_s = "commit"; break;
|
case 'C': type_s = "commit"; break;
|
||||||
case 'T': type_s = "tree"; break;
|
case 'T': type_s = "tree"; break;
|
||||||
case 'B': type_s = "blob"; break;
|
case 'B': type_s = "blob"; break;
|
||||||
|
case 'G': type_s = "tag"; break;
|
||||||
default: goto err_finish;
|
default: goto err_finish;
|
||||||
}
|
}
|
||||||
if (write_sha1_file(buffer, size, type_s, sha1) < 0)
|
if (write_sha1_file(buffer, size, type_s, sha1) < 0)
|
||||||
|
@ -249,7 +250,7 @@ static void unpack_entry(struct pack_entry *entry)
|
||||||
size = (pack[1] << 24) + (pack[2] << 16) + (pack[3] << 8) + pack[4];
|
size = (pack[1] << 24) + (pack[2] << 16) + (pack[3] << 8) + pack[4];
|
||||||
left = pack_size - offset - 5;
|
left = pack_size - offset - 5;
|
||||||
switch (*pack) {
|
switch (*pack) {
|
||||||
case 'C': case 'T': case 'B':
|
case 'C': case 'T': case 'B': case 'G':
|
||||||
unpack_non_delta_entry(entry, *pack, pack+5, size, left);
|
unpack_non_delta_entry(entry, *pack, pack+5, size, left);
|
||||||
break;
|
break;
|
||||||
case 'D':
|
case 'D':
|
||||||
|
|
Loading…
Reference in New Issue