From 74d817cf8cf68104564cf6c93c1361f66dad1901 Mon Sep 17 00:00:00 2001 From: Jochen Voss Date: Sat, 28 Jun 2008 17:04:24 +0100 Subject: avoid off-by-one error in run_upload_archive Make sure that buf has enough space to store the trailing \0 of the command line argument, too. Signed-off-by: Jochen Voss Signed-off-by: Junio C Hamano --- builtin-upload-archive.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'builtin-upload-archive.c') diff --git a/builtin-upload-archive.c b/builtin-upload-archive.c index 48ae09e9b..371400d49 100644 --- a/builtin-upload-archive.c +++ b/builtin-upload-archive.c @@ -30,7 +30,7 @@ static int run_upload_archive(int argc, const char **argv, const char *prefix) if (argc != 2) usage(upload_archive_usage); - if (strlen(argv[1]) > sizeof(buf)) + if (strlen(argv[1]) + 1 > sizeof(buf)) die("insanely long repository name"); strcpy(buf, argv[1]); /* enter-repo smudges its argument */ -- cgit v1.2.1 From 1b1dd23f2d6a707b7077cdf6bc6d4055bd0bfb7d Mon Sep 17 00:00:00 2001 From: Stephan Beyer Date: Sun, 13 Jul 2008 15:36:15 +0200 Subject: Make usage strings dash-less When you misuse a git command, you are shown the usage string. But this is currently shown in the dashed form. So if you just copy what you see, it will not work, when the dashed form is no longer supported. This patch makes git commands show the dash-less version. For shell scripts that do not specify OPTIONS_SPEC, git-sh-setup.sh generates a dash-less usage string now. Signed-off-by: Stephan Beyer Signed-off-by: Junio C Hamano --- builtin-upload-archive.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'builtin-upload-archive.c') diff --git a/builtin-upload-archive.c b/builtin-upload-archive.c index 371400d49..64381330c 100644 --- a/builtin-upload-archive.c +++ b/builtin-upload-archive.c @@ -8,13 +8,13 @@ #include "sideband.h" static const char upload_archive_usage[] = - "git-upload-archive "; + "git upload-archive "; static const char deadchild[] = -"git-upload-archive: archiver died with error"; +"git upload-archive: archiver died with error"; static const char lostchild[] = -"git-upload-archive: archiver process was lost"; +"git upload-archive: archiver process was lost"; static int run_upload_archive(int argc, const char **argv, const char *prefix) -- cgit v1.2.1 From 34533004b27df4f34e18d9e26832fcc956a39fca Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ren=C3=A9=20Scharfe?= Date: Tue, 15 Jul 2008 09:49:40 +0200 Subject: archive: remove args member from struct archiver Pass struct archiver and struct archiver_args explicitly to parse_archive_args and remove the latter from the former. This allows us to get rid of struct archiver_desc and simplifies the code a bit. Signed-off-by: Rene Scharfe Signed-off-by: Junio C Hamano --- builtin-upload-archive.c | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) (limited to 'builtin-upload-archive.c') diff --git a/builtin-upload-archive.c b/builtin-upload-archive.c index 371400d49..295e24c2f 100644 --- a/builtin-upload-archive.c +++ b/builtin-upload-archive.c @@ -19,7 +19,8 @@ static const char lostchild[] = static int run_upload_archive(int argc, const char **argv, const char *prefix) { - struct archiver ar; + const struct archiver *ar; + struct archiver_args args; const char *sent_argv[MAX_ARGS]; const char *arg_cmd = "argument "; char *p, buf[4096]; @@ -65,12 +66,12 @@ static int run_upload_archive(int argc, const char **argv, const char *prefix) sent_argv[sent_argc] = NULL; /* parse all options sent by the client */ - treeish_idx = parse_archive_args(sent_argc, sent_argv, &ar); + treeish_idx = parse_archive_args(sent_argc, sent_argv, &ar, &args); - parse_treeish_arg(sent_argv + treeish_idx, &ar.args, prefix); - parse_pathspec_arg(sent_argv + treeish_idx + 1, &ar.args); + parse_treeish_arg(sent_argv + treeish_idx, &args, prefix); + parse_pathspec_arg(sent_argv + treeish_idx + 1, &args); - return ar.write_archive(&ar.args); + return ar->write_archive(&args); } static void error_clnt(const char *fmt, ...) -- cgit v1.2.1 From 6e94e6835f397cd2602ca1eb12002e51aa6b0500 Mon Sep 17 00:00:00 2001 From: Rene Scharfe Date: Fri, 25 Jul 2008 12:41:21 +0200 Subject: archive: add write_archive() Both archive and upload-archive have to parse command line arguments and then call the archiver specific write function. Move the duplicate code to a new function, write_archive(). Signed-off-by: Rene Scharfe Signed-off-by: Junio C Hamano --- builtin-upload-archive.c | 10 +--------- 1 file changed, 1 insertion(+), 9 deletions(-) (limited to 'builtin-upload-archive.c') diff --git a/builtin-upload-archive.c b/builtin-upload-archive.c index 13a6c6203..cc37b36d9 100644 --- a/builtin-upload-archive.c +++ b/builtin-upload-archive.c @@ -19,12 +19,9 @@ static const char lostchild[] = static int run_upload_archive(int argc, const char **argv, const char *prefix) { - const struct archiver *ar; - struct archiver_args args; const char *sent_argv[MAX_ARGS]; const char *arg_cmd = "argument "; char *p, buf[4096]; - int treeish_idx; int sent_argc; int len; @@ -66,12 +63,7 @@ static int run_upload_archive(int argc, const char **argv, const char *prefix) sent_argv[sent_argc] = NULL; /* parse all options sent by the client */ - treeish_idx = parse_archive_args(sent_argc, sent_argv, &ar, &args); - - parse_treeish_arg(sent_argv + treeish_idx, &args, prefix); - parse_pathspec_arg(sent_argv + treeish_idx + 1, &args); - - return ar->write_archive(&args); + return write_archive(sent_argc, sent_argv, prefix, 0); } static void error_clnt(const char *fmt, ...) -- cgit v1.2.1 From 7f4d0511af9d6c93656dda5a683632f5ae5b5278 Mon Sep 17 00:00:00 2001 From: Rene Scharfe Date: Fri, 25 Jul 2008 12:41:23 +0200 Subject: archive: define MAX_ARGS where it's needed MAX_EXTRA_ARGS is not used anymore, so remove it. MAX_ARGS is used only in builtin-upload-archive.c, so define it there. Also report the actual value we're comparing against when the number of args is too big. Signed-off-by: Rene Scharfe Signed-off-by: Junio C Hamano --- builtin-upload-archive.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'builtin-upload-archive.c') diff --git a/builtin-upload-archive.c b/builtin-upload-archive.c index cc37b36d9..a9b02fa32 100644 --- a/builtin-upload-archive.c +++ b/builtin-upload-archive.c @@ -16,6 +16,7 @@ static const char deadchild[] = static const char lostchild[] = "git upload-archive: archiver process was lost"; +#define MAX_ARGS (64) static int run_upload_archive(int argc, const char **argv, const char *prefix) { @@ -45,7 +46,7 @@ static int run_upload_archive(int argc, const char **argv, const char *prefix) if (len == 0) break; /* got a flush */ if (sent_argc > MAX_ARGS - 2) - die("Too many options (>29)"); + die("Too many options (>%d)", MAX_ARGS - 2); if (p[len-1] == '\n') { p[--len] = 0; -- cgit v1.2.1 From 05ac6b34e2c2adda5cb85dd0bdacb47fe5db953e Mon Sep 17 00:00:00 2001 From: Jeff King Date: Wed, 4 Mar 2009 03:32:29 -0500 Subject: improve missing repository error message Certain remote commands, when asked to do something in a particular directory that was not actually a git repository, would say "unable to chdir or not a git archive". The "chdir" bit is an unnecessary detail, and the term "git archive" is much less common these days than "git repository". So let's switch them all to: fatal: '%s' does not appear to be a git repository Signed-off-by: Jeff King Acked-by: Shawn O. Pearce Signed-off-by: Junio C Hamano --- builtin-upload-archive.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'builtin-upload-archive.c') diff --git a/builtin-upload-archive.c b/builtin-upload-archive.c index a9b02fa32..0206b416c 100644 --- a/builtin-upload-archive.c +++ b/builtin-upload-archive.c @@ -35,7 +35,7 @@ static int run_upload_archive(int argc, const char **argv, const char *prefix) strcpy(buf, argv[1]); /* enter-repo smudges its argument */ if (!enter_repo(buf, 0)) - die("not a git archive"); + die("'%s' does not appear to be a git repository", buf); /* put received options in sent_argv[] */ sent_argc = 1; -- cgit v1.2.1 From 1b19fa46344f512949270dc88089574950519ea3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ren=C3=A9=20Scharfe?= Date: Wed, 17 Jun 2009 12:11:10 +0200 Subject: upload-archive: fix infinite loop on Cygwin On Cygwin, poll() reports POLLIN even for file descriptors that have reached their end. This caused git upload-archive to be stuck in an infinite loop, as it only looked at the POLLIN flag. In addition to POLLIN, check if read() returned 0, which indicates end-of-file, and keep looping only as long as at least one of the file descriptors has input. This lets the following command finish on its own when run in a git repository on Cygwin, instead of it getting stuck after printing all file names: $ git archive -v --remote . HEAD >/dev/null Reported-by: Bob Kagy Signed-off-by: Rene Scharfe Signed-off-by: Junio C Hamano --- builtin-upload-archive.c | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) (limited to 'builtin-upload-archive.c') diff --git a/builtin-upload-archive.c b/builtin-upload-archive.c index a9b02fa32..f6c4c0f14 100644 --- a/builtin-upload-archive.c +++ b/builtin-upload-archive.c @@ -80,16 +80,17 @@ 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 ssize_t process_input(int child_fd, int band) { char buf[16384]; ssize_t sz = read(child_fd, buf, sizeof(buf)); if (sz < 0) { if (errno != EAGAIN && errno != EINTR) error_clnt("read error: %s\n", strerror(errno)); - return; + return sz; } send_sideband(1, band, buf, sz, LARGE_PACKET_MAX); + return sz; } int cmd_upload_archive(int argc, const char **argv, const char *prefix) @@ -131,6 +132,7 @@ int cmd_upload_archive(int argc, const char **argv, const char *prefix) while (1) { struct pollfd pfd[2]; + ssize_t processed[2] = { 0, 0 }; int status; pfd[0].fd = fd1[0]; @@ -147,12 +149,12 @@ 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); + processed[0] = process_input(pfd[0].fd, 1); if (pfd[1].revents & POLLIN) /* Status stream ready */ - process_input(pfd[1].fd, 2); + processed[1] = process_input(pfd[1].fd, 2); /* Always finish to read data when available */ - if ((pfd[0].revents | pfd[1].revents) & POLLIN) + if (processed[0] || processed[1]) continue; if (waitpid(writer, &status, 0) < 0) -- cgit v1.2.1