Thread (21 messages) flat view 21 messages, 6 authors, 2016-06-15
STALE3730d

[PATCH 1/2] archive: factor out write phase of tar format

From: Jeff King <hidden>
Date: 2016-06-15 22:51:28
Subsystem: the rest · Maintainer: Linus Torvalds

The code to output the tar format for git-archive always
assumes we are writing directly to stdout. Let's factor out
that bit of code so that we can put an in-process gzip
filter in place.

Signed-off-by: Jeff King <redacted>
---
 archive-tar.c |   22 +++++++++++++++++-----
 1 files changed, 17 insertions(+), 5 deletions(-)
diff --git a/archive-tar.c b/archive-tar.c
index cee06ce..b1aea87 100644
--- a/archive-tar.c
+++ b/archive-tar.c
@@ -10,6 +10,7 @@
 
 static char block[BLOCKSIZE];
 static unsigned long offset;
+static void (*output)(const char *buf, unsigned long size);
 
 static int tar_umask = 002;
 
@@ -17,7 +18,7 @@ static int tar_umask = 002;
 static void write_if_needed(void)
 {
 	if (offset == BLOCKSIZE) {
-		write_or_die(1, block, BLOCKSIZE);
+		output(block, BLOCKSIZE);
 		offset = 0;
 	}
 }
@@ -42,7 +43,7 @@ static void write_blocked(const void *data, unsigned long size)
 		write_if_needed();
 	}
 	while (size >= BLOCKSIZE) {
-		write_or_die(1, buf, BLOCKSIZE);
+		output(buf, BLOCKSIZE);
 		size -= BLOCKSIZE;
 		buf += BLOCKSIZE;
 	}
@@ -66,10 +67,10 @@ static void write_trailer(void)
 {
 	int tail = BLOCKSIZE - offset;
 	memset(block + offset, 0, tail);
-	write_or_die(1, block, BLOCKSIZE);
+	output(block, BLOCKSIZE);
 	if (tail < 2 * RECORDSIZE) {
 		memset(block, 0, offset);
-		write_or_die(1, block, BLOCKSIZE);
+		output(block, BLOCKSIZE);
 	}
 }
 
@@ -234,7 +235,7 @@ static int git_tar_config(const char *var, const char *value, void *cb)
 	return git_default_config(var, value, cb);
 }
 
-int write_tar_archive(struct archiver_args *args)
+static int write_tar_archive_internal(struct archiver_args *args)
 {
 	int err = 0;
 
@@ -248,3 +249,14 @@ int write_tar_archive(struct archiver_args *args)
 		write_trailer();
 	return err;
 }
+
+static void output_write(const char *buf, unsigned long len)
+{
+	write_or_die(1, buf, len);
+}
+
+int write_tar_archive(struct archiver_args *args)
+{
+	output = output_write;
+	return write_tar_archive_internal(args);
+}
-- 
1.7.6.rc1.37.g6d4ed.dirty
Keyboard shortcuts
hback out one level
jnext message in thread
kprevious message in thread
ldrill in
Escclose help / fold thread tree
?toggle this help