git.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: "René Scharfe" <rene.scharfe@lsrfire.ath.cx>
To: Johannes Sixt <j6t@kdbg.org>
Cc: Jeff King <peff@peff.net>, Erik Faye-Lund <kusmabite@gmail.com>,
	Junio C Hamano <gitster@pobox.com>,
	git@vger.kernel.org
Subject: Re: [PATCH v2 4/4] upload-archive: use start_command instead of fork
Date: Sat, 06 Aug 2011 11:40:45 +0200	[thread overview]
Message-ID: <4E3D0C1D.9000807@lsrfire.ath.cx> (raw)
In-Reply-To: <4E388A55.6080606@kdbg.org>

Am 03.08.2011 01:37, schrieb Johannes Sixt:
> Am 02.08.2011 20:13, schrieb Jeff King:
>> Hmm. So it's not _just_ the pipe vs file thing. What's different about
>> calling it from the shell, versus the way we call it from git-archive?
> 
> When the parent process of an MSYS process is itself an MSYS process,
> such as bash, then the child does not do its own
> binary-mode-vs.-text-mode detection, but just uses whatever it is told
> by the parent. This is achieved by MSYS's fork emulation.
> 
> But if the parent is a regular Windows program, such as git(-archive),
> then the autodection happens and file descriptors pointing to files are
> put into text mode.

So here's an ugly patch to implement an internal passthrough filter to
avoid newline conversions.  It makes the tar filter command (gzip etc.)
write to a pipe instead of directly to a file.

The patch does this unconditionally, which is a waste on all unaffected
systems, of course.  We could #ifdef it out, but is there perhaps a nice
way to integrate this functionality into run_command/finish_command?

René

---
 archive-tar.c |   31 +++++++++++++++++++++++++++++++
 1 files changed, 31 insertions(+), 0 deletions(-)

diff --git a/archive-tar.c b/archive-tar.c
index 20af005..22d52c5 100644
--- a/archive-tar.c
+++ b/archive-tar.c
@@ -314,6 +314,25 @@ static int write_tar_archive(const struct archiver *ar,
 	return err;
 }
 
+static int cat_fn(int in, int out, void *data)
+{
+	for (;;) {
+		char buf[16 * 1024];
+		ssize_t got = xread(in, buf, sizeof(buf));
+		if (got == 0)
+			break;
+		if (got < 0) {
+			if (errno == EPIPE)
+				break;
+			die_errno("read errror");
+		}
+		write_or_die(out, buf, got);
+	}
+	close(in);
+	close(out);
+	return 0;
+}
+
 static int write_tar_filter_archive(const struct archiver *ar,
 				    struct archiver_args *args)
 {
@@ -321,6 +340,14 @@ static int write_tar_filter_archive(const struct archiver *ar,
 	struct child_process filter;
 	const char *argv[2];
 	int r;
+	struct async cat;
+
+	memset(&cat, 0, sizeof(cat));
+	cat.proc = cat_fn;
+	cat.in = -1;
+	cat.out = dup(1);
+	if (start_async(&cat))
+		die("unable to start passthrough filter");
 
 	if (!ar->data)
 		die("BUG: tar-filter archiver called with no filter defined");
@@ -335,6 +362,7 @@ static int write_tar_filter_archive(const struct archiver *ar,
 	filter.argv = argv;
 	filter.use_shell = 1;
 	filter.in = -1;
+	filter.out = cat.in;
 
 	if (start_command(&filter) < 0)
 		die_errno("unable to start '%s' filter", argv[0]);
@@ -349,6 +377,9 @@ static int write_tar_filter_archive(const struct archiver *ar,
 	if (finish_command(&filter) != 0)
 		die("'%s' filter reported error", argv[0]);
 
+	if (finish_async(&cat))
+		die("passthrough filter reported error");
+
 	strbuf_release(&cmd);
 	return r;
 }

  parent reply	other threads:[~2011-08-06  9:41 UTC|newest]

Thread overview: 33+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2011-07-18 18:08 [PATCH v2 0/4] port upload-archive to Windows Erik Faye-Lund
2011-07-18 18:08 ` [PATCH v2 1/4] compat/win32/sys/poll.c: upgrade from upstream Erik Faye-Lund
2011-07-18 18:08 ` [PATCH v2 2/4] mingw: fix compilation of poll-emulation Erik Faye-Lund
2011-07-18 18:08 ` [PATCH v2 3/4] enter_repo: do not modify input Erik Faye-Lund
2011-07-18 18:08 ` [PATCH v2 4/4] upload-archive: use start_command instead of fork Erik Faye-Lund
2011-07-19 21:09   ` Junio C Hamano
2011-07-28  8:32     ` Erik Faye-Lund
2011-07-28 16:08       ` Jeff King
2011-07-28 16:47         ` Jeff King
2011-07-28 17:02           ` Jeff King
2011-08-01 14:45             ` Erik Faye-Lund
2011-08-01 17:46               ` Jeff King
2011-08-01 18:02                 ` Erik Faye-Lund
2011-08-01 18:25                   ` Jeff King
2011-08-01 20:48                     ` René Scharfe
2011-08-01 21:20                       ` Johannes Sixt
2011-08-01 21:42                         ` René Scharfe
2011-08-01 21:52                         ` René Scharfe
2011-08-02  4:00                           ` Jeff King
2011-08-02 16:46                             ` René Scharfe
2011-08-02 18:13                               ` Jeff King
2011-08-02 23:37                                 ` Johannes Sixt
2011-08-03  5:49                                   ` Jeff King
2011-08-06  9:40                                   ` René Scharfe [this message]
2011-08-07 20:02                                     ` Johannes Sixt
2011-08-07 21:06                                       ` Jeff King
2011-08-08 17:10                                       ` René Scharfe
2011-08-09  5:02                                         ` Jeff King
2011-08-09 10:25                                           ` René Scharfe
2011-08-09 20:05                                             ` Jeff King
2011-09-29 19:54                                               ` Erik Faye-Lund
2011-09-29 20:18                                                 ` René Scharfe
2011-09-29 20:20                                                   ` Erik Faye-Lund

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=4E3D0C1D.9000807@lsrfire.ath.cx \
    --to=rene.scharfe@lsrfire.ath.cx \
    --cc=git@vger.kernel.org \
    --cc=gitster@pobox.com \
    --cc=j6t@kdbg.org \
    --cc=kusmabite@gmail.com \
    --cc=peff@peff.net \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).