{"thread":{"id":"4556","subject":"[PATCH 1/3] git-tar-tree: Simplify write_trailer()","startedAt":"2006-06-18T10:57:56Z","lastAt":"2006-06-18T10:57:56Z","messageCount":1,"participants":["Rene Scharfe"],"isPatch":true,"patchVersion":1,"patchTotal":3},"messages":[{"id":"22009","messageId":"1150628276770-git-send-email-rene.scharfe@lsrfire.ath.cx","threadId":"4556","inReplyTo":null,"subject":"[PATCH 1/3] git-tar-tree: Simplify write_trailer()","fromName":"Rene Scharfe","fromEmail":"rene.scharfe@lsrfire.ath.cx","sentAt":"2006-06-18T10:57:56Z","receivedAt":"2006-06-18T10:57:56Z","isPatch":true,"sender":{"key":"l.s.r@web.de","avatar":"https://avatars.githubusercontent.com/u/26122331?v=4"},"body":"We can write the trailer in one or at most two steps; it will always\nfit within two blocks.  With the last caller of get_record() gone we\ncan get rid of it.\n\nSigned-off-by: Rene Scharfe <rene.scharfe@lsrfire.ath.cx>\n---\n builtin-tar-tree.c |   40 +++++++++++++++-------------------------\n 1 files changed, 15 insertions(+), 25 deletions(-)\n\ndiff --git a/builtin-tar-tree.c b/builtin-tar-tree.c\nindex f6310b9..f646c5b 100644\n--- a/builtin-tar-tree.c\n+++ b/builtin-tar-tree.c\n@@ -47,31 +47,6 @@ static void write_if_needed(void)\n \t}\n }\n \n-/* acquire the next record from the buffer; user must call write_if_needed() */\n-static char *get_record(void)\n-{\n-\tchar *p = block + offset;\n-\tmemset(p, 0, RECORDSIZE);\n-\toffset += RECORDSIZE;\n-\treturn p;\n-}\n-\n-/*\n- * The end of tar archives is marked by 1024 nul bytes and after that\n- * follows the rest of the block (if any).\n- */\n-static void write_trailer(void)\n-{\n-\tget_record();\n-\twrite_if_needed();\n-\tget_record();\n-\twrite_if_needed();\n-\twhile (offset) {\n-\t\tget_record();\n-\t\twrite_if_needed();\n-\t}\n-}\n-\n /*\n  * queues up writes, so that all our write(2) calls write exactly one\n  * full block; pads writes to RECORDSIZE\n@@ -107,6 +82,21 @@ static void write_blocked(void *buf, uns\n \twrite_if_needed();\n }\n \n+/*\n+ * The end of tar archives is marked by 2*512 nul bytes and after that\n+ * follows the rest of the block (if any).\n+ */\n+static void write_trailer(void)\n+{\n+\tint tail = BLOCKSIZE - offset;\n+\tmemset(block + offset, 0, tail);\n+\treliable_write(block, BLOCKSIZE);\n+\tif (tail < 2 * RECORDSIZE) {\n+\t\tmemset(block, 0, offset);\n+\t\treliable_write(block, BLOCKSIZE);\n+\t}\n+}\n+\n static void strbuf_append_string(struct strbuf *sb, const char *s)\n {\n \tint slen = strlen(s);\n-- \n1.4.0\n"}]}