{"thread":{"id":"7696","subject":"[PATCH 8/9] add get_size_from_delta()","startedAt":"2007-04-16T16:31:56Z","lastAt":"2007-04-16T16:31:56Z","messageCount":1,"participants":["Nicolas Pitre"],"isPatch":true,"patchVersion":1,"patchTotal":9},"messages":[{"id":"39551","messageId":"alpine.LFD.0.98.0704161231370.4504@xanadu.home","threadId":"7696","inReplyTo":null,"subject":"[PATCH 8/9] add get_size_from_delta()","fromName":"Nicolas Pitre","fromEmail":"nico@cam.org","sentAt":"2007-04-16T16:31:56Z","receivedAt":"2007-04-16T16:31:56Z","isPatch":true,"sender":{"key":"nico@fluxnic.net","avatar":"https://avatars.githubusercontent.com/u/702790?v=4"},"body":"... which consists of existing code split out of packed_delta_info()\nfor other callers to use it as well.\n\nSigned-off-by: Nicolas Pitre <nico@cam.org>\n---\n cache.h     |    1 +\n sha1_file.c |   73 +++++++++++++++++++++++++++++++---------------------------\n 2 files changed, 40 insertions(+), 34 deletions(-)\n\ndiff --git a/cache.h b/cache.h\nindex 4d058c7..b9c2104 100644\n--- a/cache.h\n+++ b/cache.h\n@@ -456,6 +456,7 @@ extern const unsigned char *nth_packed_object_sha1(const struct packed_git *, ui\n extern off_t find_pack_entry_one(const unsigned char *, struct packed_git *);\n extern void *unpack_entry(struct packed_git *, off_t, enum object_type *, unsigned long *);\n extern unsigned long unpack_object_header_gently(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 /* Dumb servers support */\ndiff --git a/sha1_file.c b/sha1_file.c\nindex 76e0048..2864ce8 100644\n--- a/sha1_file.c\n+++ b/sha1_file.c\n@@ -1161,6 +1161,43 @@ static void *unpack_sha1_file(void *map, unsigned long mapsize, enum object_type\n \treturn unpack_sha1_rest(&stream, hdr, *size, sha1);\n }\n \n+unsigned long get_size_from_delta(struct packed_git *p,\n+\t\t        \t  struct pack_window **w_curs,\n+\t\t\t          off_t curpos)\n+{\n+\tconst unsigned char *data;\n+\tunsigned char delta_head[20], *in;\n+\tz_stream stream;\n+\tint st;\n+\n+\tmemset(&stream, 0, sizeof(stream));\n+\tstream.next_out = delta_head;\n+\tstream.avail_out = sizeof(delta_head);\n+\n+\tinflateInit(&stream);\n+\tdo {\n+\t\tin = use_pack(p, w_curs, curpos, &stream.avail_in);\n+\t\tstream.next_in = in;\n+\t\tst = inflate(&stream, Z_FINISH);\n+\t\tcurpos += stream.next_in - in;\n+\t} while ((st == Z_OK || st == Z_BUF_ERROR) &&\n+\t\t stream.total_out < sizeof(delta_head));\n+\tinflateEnd(&stream);\n+\tif ((st != Z_STREAM_END) && stream.total_out != sizeof(delta_head))\n+\t\tdie(\"delta data unpack-initial failed\");\n+\n+\t/* Examine the initial part of the delta to figure out\n+\t * the result size.\n+\t */\n+\tdata = delta_head;\n+\n+\t/* ignore base size */\n+\tget_delta_hdr_size(&data, delta_head+sizeof(delta_head));\n+\n+\t/* Read the result size */\n+\treturn get_delta_hdr_size(&data, delta_head+sizeof(delta_head));\n+}\n+\n static off_t get_delta_base(struct packed_git *p,\n \t\t\t\t    struct pack_window **w_curs,\n \t\t\t\t    off_t *curpos,\n@@ -1224,40 +1261,8 @@ static int packed_delta_info(struct packed_git *p,\n \t * based on a base with a wrong size.  This saves tons of\n \t * inflate() calls.\n \t */\n-\tif (sizep) {\n-\t\tconst unsigned char *data;\n-\t\tunsigned char delta_head[20], *in;\n-\t\tz_stream stream;\n-\t\tint st;\n-\n-\t\tmemset(&stream, 0, sizeof(stream));\n-\t\tstream.next_out = delta_head;\n-\t\tstream.avail_out = sizeof(delta_head);\n-\n-\t\tinflateInit(&stream);\n-\t\tdo {\n-\t\t\tin = use_pack(p, w_curs, curpos, &stream.avail_in);\n-\t\t\tstream.next_in = in;\n-\t\t\tst = inflate(&stream, Z_FINISH);\n-\t\t\tcurpos += stream.next_in - in;\n-\t\t} while ((st == Z_OK || st == Z_BUF_ERROR)\n-\t\t\t&& stream.total_out < sizeof(delta_head));\n-\t\tinflateEnd(&stream);\n-\t\tif ((st != Z_STREAM_END) &&\n-\t\t    stream.total_out != sizeof(delta_head))\n-\t\t\tdie(\"delta data unpack-initial failed\");\n-\n-\t\t/* Examine the initial part of the delta to figure out\n-\t\t * the result size.\n-\t\t */\n-\t\tdata = delta_head;\n-\n-\t\t/* ignore base size */\n-\t\tget_delta_hdr_size(&data, delta_head+sizeof(delta_head));\n-\n-\t\t/* Read the result size */\n-\t\t*sizep = get_delta_hdr_size(&data, delta_head+sizeof(delta_head));\n-\t}\n+\tif (sizep)\n+\t\t*sizep = get_size_from_delta(p, w_curs, curpos);\n \n \treturn type;\n }\n-- \n1.5.1.1.781.g65e8\n"}]}