In addition to four basic types (commit, tree, blob and tag), the pack stream can encode a few other "representation" types, such as REF_DELTA and OFS_DELTA. As we allocate 3 bits in the first byte for this purpose, we do not have much room to add new representation types in place, but we do have one value reserved for future expansion. When encoding a new representation type, the early part of the in-pack object header is encoded as if its type is OBJ_EXT (= 5) using exactly the same way as before. That is, the lower 4-bit of the first byte is used for the lowest 4-bit of the size information, the next 3-bit has the type information, and the MSB says if the subsequent bytes encodes higher bits for the size information. An in-pack object header that records OBJ_EXT as the type is followed by an integer in the same variable-length encoding as OFS_DELTA offset is encoded. This value is the real type of the representation minus 8 (as we do not need to use OBJ_EXT to encode types smaller than 8). Because we do not foresee very many representation types, in practice we would have a single byte with its MSB clear, to represent types 8-135. The code does not type=8 and upwards for anything yet. Signed-off-by: Junio C Hamano <gitster@xxxxxxxxx> --- cache.h | 4 +++- pack-write.c | 23 +++++++++++++++++------ sha1_file.c | 11 +++++++++++ 3 files changed, 31 insertions(+), 7 deletions(-) diff --git a/cache.h b/cache.h index 4f20861..4a3b421 100644 --- a/cache.h +++ b/cache.h @@ -381,12 +381,14 @@ enum object_type { OBJ_TREE = 2, OBJ_BLOB = 3, OBJ_TAG = 4, - /* 5 for future expansion */ + OBJ_EXT = 5, OBJ_OFS_DELTA = 6, OBJ_REF_DELTA = 7, OBJ_ANY, OBJ_MAX }; +#define OBJ_LAST_BASE_TYPE OBJ_REF_DELTA +#define OBJ_LAST_VALID_TYPE OBJ_REF_DELTA static inline enum object_type object_type(unsigned int mode) { diff --git a/pack-write.c b/pack-write.c index 5702cec..9309dd1 100644 --- a/pack-write.c +++ b/pack-write.c @@ -338,22 +338,33 @@ int encode_in_pack_varint(uintmax_t value, unsigned char *buf) */ int encode_in_pack_object_header(enum object_type type, uintmax_t size, unsigned char *hdr) { - int n = 1; + unsigned char *hdr_base; unsigned char c; + enum object_type header_type; - if (type < OBJ_COMMIT || type > OBJ_REF_DELTA) + if (type < OBJ_COMMIT || OBJ_LAST_VALID_TYPE < type) die("bad type %d", type); + else if (OBJ_LAST_BASE_TYPE < type) + header_type = OBJ_EXT; + else + header_type = type; - c = (type << 4) | (size & 15); + c = (header_type << 4) | (size & 15); size >>= 4; + hdr_base = hdr; while (size) { *hdr++ = c | 0x80; c = size & 0x7f; size >>= 7; - n++; } - *hdr = c; - return n; + *hdr++ = c; + if (header_type != type) { + int sz; + type = type - (OBJ_LAST_BASE_TYPE + 1); + sz = encode_in_pack_varint(type, hdr); + hdr += sz; + } + return hdr - hdr_base; } struct sha1file *create_tmp_packfile(char **pack_tmp_name) diff --git a/sha1_file.c b/sha1_file.c index f066c2b..14902cc 100644 --- a/sha1_file.c +++ b/sha1_file.c @@ -1275,6 +1275,17 @@ unsigned long unpack_object_header_buffer(const unsigned char *buf, shift += 7; } *sizep = size; + if (*type == OBJ_EXT) { + const unsigned char *p = buf + used; + uintmax_t val = decode_in_pack_varint(&p); + + if (p == buf + used && !val) { + error("bad extended object type"); + return 0; + } + *type = val + (OBJ_LAST_BASE_TYPE + 1); + used = p - buf; + } return used; } -- 1.7.8.rc4.177.g4d64 -- To unsubscribe from this list: send the line "unsubscribe git" in the body of a message to majordomo@xxxxxxxxxxxxxxx More majordomo info at http://vger.kernel.org/majordomo-info.html