MCPcopy Create free account
hub / github.com/git/git / git_connect_git

Function git_connect_git

connect.c:1221–1275  ·  view source on GitHub ↗

* 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). */

Source from the content-addressed store, hash-verified

1219 * modify it (for example, to truncate it to remove the port part).
1220 */
1221static struct child_process *git_connect_git(int fd[2], char *hostandport,
1222 const char *path, const char *prog,
1223 enum protocol_version version,
1224 int flags)
1225{
1226 struct child_process *conn;
1227 struct strbuf request = STRBUF_INIT;
1228 /*
1229 * Set up virtual host information based on where we will
1230 * connect, unless the user has overridden us in
1231 * the environment.
1232 */
1233 char *target_host = getenv("GIT_OVERRIDE_VIRTUAL_HOST");
1234 if (target_host)
1235 target_host = xstrdup(target_host);
1236 else
1237 target_host = xstrdup(hostandport);
1238
1239 transport_check_allowed("git");
1240 if (strchr(target_host, '\n') || strchr(path, '\n'))
1241 die(_("newline is forbidden in git:// hosts and repo paths"));
1242
1243 /*
1244 * These underlying connection commands die() if they
1245 * cannot connect.
1246 */
1247 if (git_use_proxy(hostandport))
1248 conn = git_proxy_connect(fd, hostandport);
1249 else
1250 conn = git_tcp_connect(fd, hostandport, flags);
1251 /*
1252 * Separate original protocol components prog and path
1253 * from extended host header with a NUL byte.
1254 *
1255 * Note: Do not add any other headers here! Doing so
1256 * will cause older git-daemon servers to crash.
1257 */
1258 strbuf_addf(&request,
1259 "%s %s%chost=%s%c",
1260 prog, path, 0,
1261 target_host, 0);
1262
1263 /* If using a new version put that stuff here after a second null byte */
1264 if (version > 0) {
1265 strbuf_addch(&request, '\0');
1266 strbuf_addf(&request, "version=%d%c",
1267 version, '\0');
1268 }
1269
1270 packet_write(fd[1], request.buf, request.len);
1271
1272 free(target_host);
1273 strbuf_release(&request);
1274 return conn;
1275}
1276
1277/*
1278 * Append the appropriate environment variables to `env` and options to

Callers 1

git_connectFunction · 0.85

Calls 10

xstrdupFunction · 0.85
transport_check_allowedFunction · 0.85
git_use_proxyFunction · 0.85
git_proxy_connectFunction · 0.85
git_tcp_connectFunction · 0.85
strbuf_addfFunction · 0.85
strbuf_addchFunction · 0.85
packet_writeFunction · 0.85
strbuf_releaseFunction · 0.85
dieFunction · 0.70

Tested by

no test coverage detected