public inbox for git@vger.kernel.org 
 help / color / mirror / Atom feed
From: "René Scharfe" <rene.scharfe@lsrfire•ath.cx>
To: Bob Kagy <bobkagy@gmail•com>
Cc: git@vger•kernel.org
Subject: Re: git archive, cygwin, and --git-dir vs --remote
Date: Thu, 21 May 2009 11:08:37 +0200	[thread overview]
Message-ID: <4A151A15.6040609@lsrfire.ath.cx> (raw)
In-Reply-To: <e664dae0905180737mae29811ie4cae889b3e3904f@mail.gmail.com>

Bob Kagy schrieb:
> I'm using git on cygwin, and am confused by behavior from git archive.
> 
> git --version
> git version 1.6.1.2
> 
> This command works as expected:
> git --git-dir=/cygdrive/w archive --format=tar --verbose --prefix=tmp/
> HEAD | tar -xpf -
> The latest copy is retrieved and dumped to the tmp subdirectory.
> 
> However, I first went down the path of using the --remote option, as
> described in the git-archive man page:
> git archive --format=tar --verbose --prefix=tmp/ --remote=/cygdrive/w
> HEAD | tar -xpf -
> 
> When I use the --remote branch it seems to create the same files.  But
> then rather than exiting it hangs out until I kill the process, using
> about the same CPU % as it did when creating files.

That's strange.  It seems that poll() reports that there is data to read
from the child (which is running git-upload-archive), even though it
already called exit().

The following patch works around this issue by terminating the otherwise
endless loop after read() returned nothing for the thousandth time in a
row.  I'm not sure that there's really no way to get a thousand empty
reads without the child being done, though.

 builtin-upload-archive.c |   14 ++++++++++----
 1 files changed, 10 insertions(+), 4 deletions(-)

diff --git a/builtin-upload-archive.c b/builtin-upload-archive.c
index 0206b41..3d7b11b 100644
--- a/builtin-upload-archive.c
+++ b/builtin-upload-archive.c
@@ -17,6 +17,7 @@ static const char lostchild[] =
 "git upload-archive: archiver process was lost";
 
 #define MAX_ARGS (64)
+#define MAX_EMPTY_READS (1000)
 
 static int run_upload_archive(int argc, const char **argv, const char *prefix)
 {
@@ -80,10 +81,11 @@ static void error_clnt(const char *fmt, ...)
 	die("sent error to the client: %s", buf);
 }
 
-static void process_input(int child_fd, int band)
+static void process_input(int child_fd, int band, int *empty_reads)
 {
 	char buf[16384];
 	ssize_t sz = read(child_fd, buf, sizeof(buf));
+	*empty_reads = sz ? 0 : *empty_reads + 1;
 	if (sz < 0) {
 		if (errno != EAGAIN && errno != EINTR)
 			error_clnt("read error: %s\n", strerror(errno));
@@ -96,6 +98,8 @@ int cmd_upload_archive(int argc, const char **argv, const char *prefix)
 {
 	pid_t writer;
 	int fd1[2], fd2[2];
+	int empty_reads_1 = 0;
+	int empty_reads_2 = 0;
 	/*
 	 * Set up sideband subprocess.
 	 *
@@ -147,12 +151,14 @@ int cmd_upload_archive(int argc, const char **argv, const char *prefix)
 		}
 		if (pfd[0].revents & POLLIN)
 			/* Data stream ready */
-			process_input(pfd[0].fd, 1);
+			process_input(pfd[0].fd, 1, &empty_reads_1);
 		if (pfd[1].revents & POLLIN)
 			/* Status stream ready */
-			process_input(pfd[1].fd, 2);
+			process_input(pfd[1].fd, 2, &empty_reads_2);
 		/* Always finish to read data when available */
-		if ((pfd[0].revents | pfd[1].revents) & POLLIN)
+		if (((pfd[0].revents | pfd[1].revents) & POLLIN) &&
+		    empty_reads_1 <= MAX_EMPTY_READS &&
+		    empty_reads_2 <= MAX_EMPTY_READS)
 			continue;
 
 		if (waitpid(writer, &status, 0) < 0)

  reply	other threads:[~2009-05-21  9:08 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2009-05-18 14:37 git archive, cygwin, and --git-dir vs --remote Bob Kagy
2009-05-21  9:08 ` René Scharfe [this message]
2009-05-21 13:32   ` Tony Finch
2009-05-21 14:29     ` René Scharfe
2009-06-17 10:11       ` [PATCH] upload-archive: fix infinite loop on Cygwin René Scharfe
2009-06-18 17:18         ` Tony Finch

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=4A151A15.6040609@lsrfire.ath.cx \
    --to=rene.scharfe@lsrfire$(echo .)ath.cx \
    --cc=bobkagy@gmail$(echo .)com \
    --cc=git@vger$(echo .)kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html
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