summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJunio C Hamano <gitster@pobox.com>2011-11-30 21:27:24 -0800
committerJunio C Hamano <gitster@pobox.com>2011-12-01 12:15:45 -0800
commit7cea3ffe518d6db2527c081b8b50189786b77bd7 (patch)
treed75026fad42194bedad41278c01c1d62cd0c4956
parent78e4f637c1bd3952aadafa5bb079792f9b71657b (diff)
downloadgit-7cea3ffe518d6db2527c081b8b50189786b77bd7.tar.gz
new representation types in the packstream
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@pobox.com>
-rw-r--r--cache.h4
-rw-r--r--pack-write.c23
-rw-r--r--sha1_file.c11
3 files changed, 31 insertions, 7 deletions
diff --git a/cache.h b/cache.h
index 4f2086151c..4a3b42119f 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 5702cec103..9309dd1f9a 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 f066c2baf0..14902cc223 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;
}