git-tar-tree: Simplify write_trailer()
We can write the trailer in one or at most two steps; it will always fit within two blocks. With the last caller of get_record() gone we can get rid of it. Signed-off-by: Rene Scharfe <rene.scharfe@lsrfire.ath.cx> Signed-off-by: Junio C Hamano <junkio@cox.net>
Rene Scharfe committed
Jun 18, 2006 at 12:57 UTC
37958be79227dc01f965993174af42672fc6756c
1 file changed
+15
-25
builtin-tar-tree.c
+15
-25
@@ -47,31 +47,6 @@ static void write_if_needed(void)
47
}
48
}
49
50
-/* acquire the next record from the buffer; user must call write_if_needed() */
51
-static char *get_record(void)
52
-{
53
- char *p = block + offset;
54
- memset(p, 0, RECORDSIZE);
55
- offset += RECORDSIZE;
56
- return p;
57
-}
58
-
59
-/*
60
- * The end of tar archives is marked by 1024 nul bytes and after that
61
- * follows the rest of the block (if any).
62
- */
63
-static void write_trailer(void)
64
-{
65
- get_record();
66
- write_if_needed();
67
- get_record();
68
- write_if_needed();
69
- while (offset) {
70
- get_record();
71
- write_if_needed();
72
- }
73
-}
74
-
50
/*
51
* queues up writes, so that all our write(2) calls write exactly one
52
* full block; pads writes to RECORDSIZE
@@ -107,6 +82,21 @@ static void write_blocked(void *buf, unsigned long size)
82
write_if_needed();
83
}
84
85
+/*
86
+ * The end of tar archives is marked by 2*512 nul bytes and after that
87
+ * follows the rest of the block (if any).
88
+ */
89
+static void write_trailer(void)
90
+{
91
+ int tail = BLOCKSIZE - offset;
92
+ memset(block + offset, 0, tail);
93
+ reliable_write(block, BLOCKSIZE);
94
+ if (tail < 2 * RECORDSIZE) {
95
+ memset(block, 0, offset);
96
+ reliable_write(block, BLOCKSIZE);
97
+ }
98
+}
99
+
100
static void strbuf_append_string(struct strbuf *sb, const char *s)
101
{
102
int slen = strlen(s);