aboutsummaryrefslogtreecommitdiff
path: root/connect.c
diff options
context:
space:
mode:
authorJonathan Nieder <jrnieder@gmail.com>2017-11-20 13:23:27 -0800
committerJunio C Hamano <gitster@pobox.com>2017-11-21 14:01:02 +0900
commit2ac67cb63b715989657cee97b3181455b1380b3f (patch)
tree1cdbbcd1ecf295229c1119c738df7caf197ed0c5 /connect.c
parent8e349780ecb9bcec52c7df22fcbfb4afd0d7936c (diff)
downloadgit-2ac67cb63b715989657cee97b3181455b1380b3f.tar.gz
git-2ac67cb63b715989657cee97b3181455b1380b3f.tar.xz
connect: split git:// setup into a separate function
The git_connect function is growing long. Split the PROTO_GIT-specific portion to a separate function to make it easier to read. No functional change intended. Signed-off-by: Jonathan Nieder <jrnieder@gmail.com> Reviewed-by: Stefan Beller <sbeller@google.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Diffstat (limited to 'connect.c')
-rw-r--r--connect.c103
1 files changed, 59 insertions, 44 deletions
diff --git a/connect.c b/connect.c
index aa994d151..942522920 100644
--- a/connect.c
+++ b/connect.c
@@ -862,6 +862,64 @@ static enum ssh_variant determine_ssh_variant(const char *ssh_command,
}
/*
+ * Open a connection using Git's native protocol.
+ *
+ * The caller is responsible for freeing hostandport, but this function may
+ * modify it (for example, to truncate it to remove the port part).
+ */
+static struct child_process *git_connect_git(int fd[2], char *hostandport,
+ const char *path, const char *prog,
+ int flags)
+{
+ struct child_process *conn;
+ struct strbuf request = STRBUF_INIT;
+ /*
+ * Set up virtual host information based on where we will
+ * connect, unless the user has overridden us in
+ * the environment.
+ */
+ char *target_host = getenv("GIT_OVERRIDE_VIRTUAL_HOST");
+ if (target_host)
+ target_host = xstrdup(target_host);
+ else
+ target_host = xstrdup(hostandport);
+
+ transport_check_allowed("git");
+
+ /* These underlying connection commands die() if they
+ * cannot connect.
+ */
+ if (git_use_proxy(hostandport))
+ conn = git_proxy_connect(fd, hostandport);
+ else
+ conn = git_tcp_connect(fd, hostandport, flags);
+ /*
+ * Separate original protocol components prog and path
+ * from extended host header with a NUL byte.
+ *
+ * Note: Do not add any other headers here! Doing so
+ * will cause older git-daemon servers to crash.
+ */
+ strbuf_addf(&request,
+ "%s %s%chost=%s%c",
+ prog, path, 0,
+ target_host, 0);
+
+ /* If using a new version put that stuff here after a second null byte */
+ if (get_protocol_version_config() > 0) {
+ strbuf_addch(&request, '\0');
+ strbuf_addf(&request, "version=%d%c",
+ get_protocol_version_config(), '\0');
+ }
+
+ packet_write(fd[1], request.buf, request.len);
+
+ free(target_host);
+ strbuf_release(&request);
+ return conn;
+}
+
+/*
* This returns the dummy child_process `no_fork` if the transport protocol
* does not need fork(2), or a struct child_process object if it does. Once
* done, finish the connection with finish_connect() with the value returned
@@ -892,50 +950,7 @@ struct child_process *git_connect(int fd[2], const char *url,
printf("Diag: path=%s\n", path ? path : "NULL");
conn = NULL;
} else if (protocol == PROTO_GIT) {
- struct strbuf request = STRBUF_INIT;
- /*
- * Set up virtual host information based on where we will
- * connect, unless the user has overridden us in
- * the environment.
- */
- char *target_host = getenv("GIT_OVERRIDE_VIRTUAL_HOST");
- if (target_host)
- target_host = xstrdup(target_host);
- else
- target_host = xstrdup(hostandport);
-
- transport_check_allowed("git");
-
- /* These underlying connection commands die() if they
- * cannot connect.
- */
- if (git_use_proxy(hostandport))
- conn = git_proxy_connect(fd, hostandport);
- else
- conn = git_tcp_connect(fd, hostandport, flags);
- /*
- * Separate original protocol components prog and path
- * from extended host header with a NUL byte.
- *
- * Note: Do not add any other headers here! Doing so
- * will cause older git-daemon servers to crash.
- */
- strbuf_addf(&request,
- "%s %s%chost=%s%c",
- prog, path, 0,
- target_host, 0);
-
- /* If using a new version put that stuff here after a second null byte */
- if (get_protocol_version_config() > 0) {
- strbuf_addch(&request, '\0');
- strbuf_addf(&request, "version=%d%c",
- get_protocol_version_config(), '\0');
- }
-
- packet_write(fd[1], request.buf, request.len);
-
- free(target_host);
- strbuf_release(&request);
+ conn = git_connect_git(fd, hostandport, path, prog, flags);
} else {
struct strbuf cmd = STRBUF_INIT;
const char *const *var;