{"thread":{"id":"7536","subject":"[PATCH 07/13] we need our own version of fast-import.c:fixup_header_footer()","startedAt":"2007-04-05T22:33:56Z","lastAt":"2007-04-05T22:33:56Z","messageCount":1,"participants":["Dana How"],"isPatch":true,"patchVersion":1,"patchTotal":13},"messages":[{"id":"38748","messageId":"56b7f5510704051533m1265ce33na2ae0c5e9748e861@mail.gmail.com","threadId":"7536","inReplyTo":null,"subject":"[PATCH 07/13] we need our own version of fast-import.c:fixup_header_footer()","fromName":"Dana How","fromEmail":"danahow@gmail.com","sentAt":"2007-04-05T22:33:56Z","receivedAt":"2007-04-05T22:33:56Z","isPatch":true,"sender":{"key":"danahow@gmail.com","avatar":null},"body":"---\n builtin-pack-objects.c |   40 ++++++++++++++++++++++++++++++++++++++++\n 1 files changed, 40 insertions(+), 0 deletions(-)\n\n-- \nDana L. How  danahow@gmail.com  +1 650 804 5991 cell\n\n\nFrom 3e8e1611653c28d1c3054152fb212a44fee24e2a Mon Sep 17 00:00:00 2001\nFrom: Dana How <how@deathvalley.cswitch.com>\nDate: Thu, 5 Apr 2007 13:54:58 -0700\nSubject: [PATCH 07/13] we need our own version of fast-import.c:fixup_header_footer()\n\n---\n builtin-pack-objects.c |   40 ++++++++++++++++++++++++++++++++++++++++\n 1 files changed, 40 insertions(+), 0 deletions(-)\n\ndiff --git a/builtin-pack-objects.c b/builtin-pack-objects.c\nindex 0a9deb0..9eb5fd6 100644\n--- a/builtin-pack-objects.c\n+++ b/builtin-pack-objects.c\n@@ -519,6 +519,46 @@ static off_t write_one(struct sha1file *f,\n \treturn offset + write_object(f, e);\n }\n \n+/*\n+ * Move this, the version in fast-import.c,\n+ * and index_pack.c:readjust_pack_header_and_sha1 into sha1_file.c ?\n+ */\n+static void fixup_header_footer(int pack_fd, unsigned char *pack_file_sha1,\n+\t\t\t\tchar *pack_name, uint32_t object_count)\n+{\n+\tstatic const int buf_sz = 128 * 1024;\n+\tSHA_CTX c;\n+\tstruct pack_header hdr;\n+\tchar *buf;\n+\n+\tif (lseek(pack_fd, 0, SEEK_SET) != 0)\n+\t\tdie(\"Failed seeking to start: %s\", strerror(errno));\n+\tif (read_in_full(pack_fd, &hdr, sizeof(hdr)) != sizeof(hdr))\n+\t\tdie(\"Unable to reread header of %s\", pack_name);\n+\tif (lseek(pack_fd, 0, SEEK_SET) != 0)\n+\t\tdie(\"Failed seeking to start: %s\", strerror(errno));\n+\thdr.hdr_entries = htonl(object_count);\n+\twrite_or_die(pack_fd, &hdr, sizeof(hdr));\n+\n+\tSHA1_Init(&c);\n+\tSHA1_Update(&c, &hdr, sizeof(hdr));\n+\n+\tbuf = xmalloc(buf_sz);\n+\tfor (;;) {\n+\t\tsize_t n = xread(pack_fd, buf, buf_sz);\n+\t\tif (!n)\n+\t\t\tbreak;\n+\t\tif (n < 0)\n+\t\t\tdie(\"Failed to checksum %s\", pack_name);\n+\t\tSHA1_Update(&c, buf, n);\n+\t}\n+\tfree(buf);\n+\n+\tSHA1_Final(pack_file_sha1, &c);\n+\twrite_or_die(pack_fd, pack_file_sha1, 20);\n+\tclose(pack_fd);\n+}\n+\n typedef int (*entry_sort_t)(const struct object_entry *, const struct object_entry *);\n \n static entry_sort_t current_sort;\n-- \n1.5.1.rc2.18.g9c88-dirty\n\n"}]}