summaryrefslogtreecommitdiff
path: root/sha1_file.c
diff options
context:
space:
mode:
authorLibravatar Michael Lukashov <michael.lukashov@gmail.com>2010-02-16 23:42:54 +0000
committerLibravatar Junio C Hamano <gitster@pobox.com>2010-02-17 15:30:20 -0800
commit1b22b6c897efa8aec6eeb51f72a73d507d5e336f (patch)
tree3c5bbefcdabc6c3f5dff047e78cbe8e6426a93a2 /sha1_file.c
parentMerge branch 'np/fast-import-idx-v2' (diff)
downloadtgif-1b22b6c897efa8aec6eeb51f72a73d507d5e336f.tar.xz
refactor duplicated encode_header in pack-objects and fast-import
The following function is duplicated: encode_header Move this function to sha1_file.c and rename it 'encode_in_pack_object_header', as suggested by Junio C Hamano Signed-off-by: Michael Lukashov <michael.lukashov@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Diffstat (limited to 'sha1_file.c')
-rw-r--r--sha1_file.c20
1 files changed, 20 insertions, 0 deletions
diff --git a/sha1_file.c b/sha1_file.c
index 657825e14e..f3c9823c56 100644
--- a/sha1_file.c
+++ b/sha1_file.c
@@ -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)
{