{"thread":{"id":"54196","subject":"[PATCH] fast-import: use write_pack_header()","startedAt":"2020-09-06T08:39:43Z","lastAt":"2020-09-10T21:53:44Z","messageCount":2,"participants":["René Scharfe","Jeff King"],"isPatch":true,"patchVersion":1,"patchTotal":null},"messages":[{"id":"405087","messageId":"7613ef32-f39c-ea4b-1cfc-88d255307186@web.de","threadId":"54196","inReplyTo":null,"subject":"[PATCH] fast-import: use write_pack_header()","fromName":"René Scharfe","fromEmail":"l.s.r@web.de","sentAt":"2020-09-06T08:39:23Z","receivedAt":"2020-09-06T08:39:43Z","isPatch":true,"sender":{"key":"l.s.r@web.de","avatar":"https://avatars.githubusercontent.com/u/26122331?v=4"},"body":"Call write_pack_header() to hash and write a pack header instead of\nopen-coding this function.  This gets rid of duplicate code and of the\nmagic version number 2 -- which has been used here since c90be46abd\n(Changed fast-import's pack header creation to use pack.h, 2006-08-16)\nand in pack.h (again) since 29f049a0c2 (Revert \"move pack creation to\nversion 3\", 2006-10-14).\n\nSigned-off-by: René Scharfe <l.s.r@web.de>\n---\n builtin/fast-import.c | 8 +-------\n 1 file changed, 1 insertion(+), 7 deletions(-)\n\ndiff --git a/builtin/fast-import.c b/builtin/fast-import.c\nindex 1c85eafe43..1bf50a73dc 100644\n--- a/builtin/fast-import.c\n+++ b/builtin/fast-import.c\n@@ -739,7 +739,6 @@ static void start_packfile(void)\n {\n \tstruct strbuf tmp_file = STRBUF_INIT;\n \tstruct packed_git *p;\n-\tstruct pack_header hdr;\n \tint pack_fd;\n\n \tpack_fd = odb_mkstemp(&tmp_file, \"pack/tmp_pack_XXXXXX\");\n@@ -750,13 +749,8 @@ static void start_packfile(void)\n \tp->do_not_close = 1;\n \tpack_file = hashfd(pack_fd, p->pack_name);\n\n-\thdr.hdr_signature = htonl(PACK_SIGNATURE);\n-\thdr.hdr_version = htonl(2);\n-\thdr.hdr_entries = 0;\n-\thashwrite(pack_file, &hdr, sizeof(hdr));\n-\n \tpack_data = p;\n-\tpack_size = sizeof(hdr);\n+\tpack_size = write_pack_header(pack_file, 0);\n \tobject_count = 0;\n\n \tREALLOC_ARRAY(all_packs, pack_id + 1);\n--\n2.28.0\n"},{"id":"405384","messageId":"20200910124128.GA58063@coredump.intra.peff.net","threadId":"54196","inReplyTo":"7613ef32-f39c-ea4b-1cfc-88d255307186@web.de","subject":"Re: [PATCH] fast-import: use write_pack_header()","fromName":"Jeff King","fromEmail":"peff@peff.net","sentAt":"2020-09-10T12:41:28Z","receivedAt":"2020-09-10T21:53:44Z","isPatch":true,"sender":{"key":"peff@peff.net","avatar":"https://avatars.githubusercontent.com/u/45925?v=4"},"body":"On Sun, Sep 06, 2020 at 10:39:23AM +0200, René Scharfe wrote:\n\n> Call write_pack_header() to hash and write a pack header instead of\n> open-coding this function.  This gets rid of duplicate code and of the\n> magic version number 2 -- which has been used here since c90be46abd\n> (Changed fast-import's pack header creation to use pack.h, 2006-08-16)\n> and in pack.h (again) since 29f049a0c2 (Revert \"move pack creation to\n> version 3\", 2006-10-14).\n\nI think this is worth doing. It locks us into using PACK_VERSION, but\nthat has been constant for quite a long time now. If we ever finally\nhave a v4 pack, I expect write_pack_header would grow a version option\nand we could deal with it then. :)\n\n-Peff\n"}]}