refactor duplicated encode_header in pack-objects and fast-import
[gitweb.git] / sha1_file.c
index 657825e14ef78c19649779fe89e1d09ae672901a..f3c9823c569782df5f6bd4c3ffd77cb872d14ba3 100644 (file)
@@ -1475,6 +1475,26 @@ const char *packed_object_info_detail(struct packed_git *p,
        }
 }
 
+int encode_in_pack_object_header(enum object_type type, uintmax_t size, unsigned char *hdr)
+{
+       int n = 1;
+       unsigned char c;
+
+       if (type < OBJ_COMMIT || type > OBJ_REF_DELTA)
+               die("bad type %d", type);
+
+       c = (type << 4) | (size & 15);
+       size >>= 4;
+       while (size) {
+               *hdr++ = c | 0x80;
+               c = size & 0x7f;
+               size >>= 7;
+               n++;
+       }
+       *hdr = c;
+       return n;
+}
+
 static int packed_object_info(struct packed_git *p, off_t obj_offset,
                              unsigned long *sizep)
 {