From fd4bd1ee6224e75f757d3003407770f518f0cfb7 Mon Sep 17 00:00:00 2001 From: Johannes Schindelin Date: Mon, 28 Oct 2019 00:06:11 +0100 Subject: [PATCH] TO-SPLIT A proof-of-concept how to test for `git push` via `git://`, intended as a starter patch for https://github.com/git-for-windows/git/pull/2375/. Signed-off-by: Johannes Schindelin --- daemon.c | 14 ++++++++++++++ t/lib-git-daemon.sh | 23 ++++++++++------------- t/t5700-protocol-v1.sh | 7 ++++++- 3 files changed, 30 insertions(+), 14 deletions(-) diff --git a/daemon.c b/daemon.c index 9d2e0d20ef302a..c4d40e3404b6e5 100644 --- a/daemon.c +++ b/daemon.c @@ -15,6 +15,7 @@ static enum log_destination { LOG_DESTINATION_STDERR = 1, LOG_DESTINATION_SYSLOG = 2, } log_destination = LOG_DESTINATION_UNSET; +static FILE *log_tee_file; static int verbose; static int reuseaddr; static int informative_errors; @@ -88,6 +89,13 @@ static void logreport(int priority, const char *err, va_list params) break; } case LOG_DESTINATION_STDERR: + if (log_tee_file) { + fprintf(log_tee_file, "[%"PRIuMAX"] ", + (uintmax_t)getpid()); + vfprintf(log_tee_file, err, params); + fputc('\n', log_tee_file); + fflush(log_tee_file); + } /* * Since stderr is set to buffered mode, the * logging of different processes will not overlap @@ -1317,6 +1325,12 @@ int cmd_main(int argc, const char **argv) } else if (!strcmp(v, "stderr")) { log_destination = LOG_DESTINATION_STDERR; continue; + } else if (skip_prefix(v, "tee:", &v)) { + log_destination = LOG_DESTINATION_STDERR; + if (log_tee_file) + fclose(log_tee_file); + log_tee_file = xfopen(v, "a"); + continue; } else if (!strcmp(v, "none")) { log_destination = LOG_DESTINATION_NONE; continue; diff --git a/t/lib-git-daemon.sh b/t/lib-git-daemon.sh index fb8f8870801eb5..0b558bac060df3 100644 --- a/t/lib-git-daemon.sh +++ b/t/lib-git-daemon.sh @@ -21,11 +21,6 @@ then test_done fi -if test_have_prereq !PIPE -then - test_skip_or_die GIT_TEST_GIT_DAEMON "file system does not support FIFOs" -fi - test_set_port LIB_GIT_DAEMON_PORT GIT_DAEMON_PID= @@ -52,21 +47,23 @@ start_git_daemon() { fi say >&3 "Starting git daemon ..." - mkfifo git_daemon_output ${LIB_GIT_DAEMON_COMMAND:-git daemon} \ --listen=127.0.0.1 --port="$LIB_GIT_DAEMON_PORT" \ --reuseaddr --verbose --pid-file="$GIT_DAEMON_PIDFILE" \ + --log-destination=tee:git_daemon_output \ --base-path="$GIT_DAEMON_DOCUMENT_ROOT_PATH" \ "$@" "$GIT_DAEMON_DOCUMENT_ROOT_PATH" \ - >&3 2>git_daemon_output & + >&3 2>&4 & GIT_DAEMON_PID=$! - { - read -r line <&7 - printf "%s\n" "$line" >&4 - cat <&7 >&4 & - } 7&3 2>&4 ret=$? - if ! test_match_signal 15 $ret + if ! test_match_signal 15 $ret && test 127 != $ret then error "git daemon exited with status: $ret" fi diff --git a/t/t5700-protocol-v1.sh b/t/t5700-protocol-v1.sh index 7c9511c593c175..fc726b3db69624 100755 --- a/t/t5700-protocol-v1.sh +++ b/t/t5700-protocol-v1.sh @@ -67,6 +67,11 @@ test_expect_success 'pull with git:// using protocol v1' ' test_expect_success 'push with git:// using protocol v1' ' test_commit -C daemon_child three && + if test_have_prereq MINGW + then + test_config -C daemon_child sendpack.sideband false + fi && + # Push to another branch, as the target repository has the # master branch checked out and we cannot push into it. GIT_TRACE_PACKET=1 git -C daemon_child -c protocol.version=1 \ @@ -169,7 +174,7 @@ test_expect_success 'create repo to be served by ssh:// transport' ' test_expect_success 'clone with ssh:// using protocol v1' ' GIT_TRACE_PACKET=1 git -c protocol.version=1 \ - clone "ssh://myhost:$(pwd)/ssh_parent" ssh_child 2>log && + clone "ssh://myhost:$PWD/ssh_parent" ssh_child 2>log && expect_ssh git-upload-pack && git -C ssh_child log -1 --format=%s >actual &&