{"thread":{"id":"22771","subject":"[PATCH] move encode_in_pack_object_header() to a better place","startedAt":"2010-02-23T20:02:37Z","lastAt":"2010-02-23T20:02:37Z","messageCount":1,"participants":["Nicolas Pitre"],"isPatch":true,"patchVersion":1,"patchTotal":null},"messages":[{"id":"135454","messageId":"alpine.LFD.2.00.1002231500210.1946@xanadu.home","threadId":"22771","inReplyTo":null,"subject":"[PATCH] move encode_in_pack_object_header() to a better place","fromName":"Nicolas Pitre","fromEmail":"nico@fluxnic.net","sentAt":"2010-02-23T20:02:37Z","receivedAt":"2010-02-23T20:02:37Z","isPatch":true,"sender":{"key":"nico@fluxnic.net","avatar":"https://avatars.githubusercontent.com/u/702790?v=4"},"body":"\nCommit 1b22b6c897 made duplicated versions of encode_header() into a\ncommon version called encode_in_pack_object_header(). There is however\na better location that sha1_file.c for such a function though, as\nsha1_file.c contains nothing related to the creation of packs, and\nit is quite populated already.\n\nAlso the comment that was moved to the header file should really remain\nnear the function as it covers implementation details and provides no\ninformation about the actual function interface.\n\nSigned-off-by: Nicolas Pitre <nico@fluxnic.net>\n\ndiff --git a/cache.h b/cache.h\nindex c863085..d454b7e 100644\n--- a/cache.h\n+++ b/cache.h\n@@ -911,14 +911,6 @@ extern void *unpack_entry(struct packed_git *, off_t, enum object_type *, unsign\n extern unsigned long unpack_object_header_buffer(const unsigned char *buf, unsigned long len, enum object_type *type, unsigned long *sizep);\n extern unsigned long get_size_from_delta(struct packed_git *, struct pack_window **, off_t);\n extern const char *packed_object_info_detail(struct packed_git *, off_t, unsigned long *, unsigned long *, unsigned int *, unsigned char *);\n-/*\n- * The per-object header is a pretty dense thing, which is\n- *  - first byte: low four bits are \"size\", then three bits of \"type\",\n- *    and the high bit is \"size continues\".\n- *  - each byte afterwards: low seven bits are size continuation,\n- *    with the high bit being \"size continues\"\n- */\n-int encode_in_pack_object_header(enum object_type type, uintmax_t size, unsigned char *hdr);\n \n /* Dumb servers support */\n extern int update_server_info(int);\ndiff --git a/pack-write.c b/pack-write.c\nindex 9f47cf9..a905ca4 100644\n--- a/pack-write.c\n+++ b/pack-write.c\n@@ -253,3 +253,30 @@ char *index_pack_lockfile(int ip_out)\n \t}\n \treturn NULL;\n }\n+\n+/*\n+ * The per-object header is a pretty dense thing, which is\n+ *  - first byte: low four bits are \"size\", then three bits of \"type\",\n+ *    and the high bit is \"size continues\".\n+ *  - each byte afterwards: low seven bits are size continuation,\n+ *    with the high bit being \"size continues\"\n+ */\n+int encode_in_pack_object_header(enum object_type type, uintmax_t size, unsigned char *hdr)\n+{\n+\tint n = 1;\n+\tunsigned char c;\n+\n+\tif (type < OBJ_COMMIT || type > OBJ_REF_DELTA)\n+\t\tdie(\"bad type %d\", type);\n+\n+\tc = (type << 4) | (size & 15);\n+\tsize >>= 4;\n+\twhile (size) {\n+\t\t*hdr++ = c | 0x80;\n+\t\tc = size & 0x7f;\n+\t\tsize >>= 7;\n+\t\tn++;\n+\t}\n+\t*hdr = c;\n+\treturn n;\n+}\ndiff --git a/pack.h b/pack.h\nindex b759a23..d268c01 100644\n--- a/pack.h\n+++ b/pack.h\n@@ -60,6 +60,7 @@ extern int check_pack_crc(struct packed_git *p, struct pack_window **w_curs, off\n extern int verify_pack(struct packed_git *);\n extern void fixup_pack_header_footer(int, unsigned char *, const char *, uint32_t, unsigned char *, off_t);\n extern char *index_pack_lockfile(int fd);\n+extern int encode_in_pack_object_header(enum object_type, uintmax_t, unsigned char *);\n \n #define PH_ERROR_EOF\t\t(-1)\n #define PH_ERROR_PACK_SIGNATURE\t(-2)\ndiff --git a/sha1_file.c b/sha1_file.c\nindex be6f37e..006321e 100644\n--- a/sha1_file.c\n+++ b/sha1_file.c\n@@ -1475,26 +1475,6 @@ const char *packed_object_info_detail(struct packed_git *p,\n \t}\n }\n \n-int encode_in_pack_object_header(enum object_type type, uintmax_t size, unsigned char *hdr)\n-{\n-\tint n = 1;\n-\tunsigned char c;\n-\n-\tif (type < OBJ_COMMIT || type > OBJ_REF_DELTA)\n-\t\tdie(\"bad type %d\", type);\n-\n-\tc = (type << 4) | (size & 15);\n-\tsize >>= 4;\n-\twhile (size) {\n-\t\t*hdr++ = c | 0x80;\n-\t\tc = size & 0x7f;\n-\t\tsize >>= 7;\n-\t\tn++;\n-\t}\n-\t*hdr = c;\n-\treturn n;\n-}\n-\n static int packed_object_info(struct packed_git *p, off_t obj_offset,\n \t\t\t      unsigned long *sizep)\n {\n"}]}