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

Function git_connect

connect.c:1401–1500  ·  view source on GitHub ↗

* 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 * from this function (it is safe to call finish_connect() with NULL to * support the former case). * * If it returns, the connect is successful; it just dies on errors

Source from the content-addressed store, hash-verified

1399 * the connection failed).
1400 */
1401struct child_process *git_connect(int fd[2], const char *url,
1402 enum git_connect_service service,
1403 const char *prog, int flags)
1404{
1405 char *hostandport, *path;
1406 struct child_process *conn;
1407 enum url_scheme scheme;
1408 enum protocol_version version = get_protocol_version_config();
1409
1410 /*
1411 * NEEDSWORK: If we are trying to use protocol v2 and we are planning
1412 * to perform any operation that doesn't involve upload-pack (i.e., a
1413 * fetch, ls-remote, etc), then fallback to v0 since we don't know how
1414 * to do anything else (like push or remote archive) via v2.
1415 */
1416 if (version == protocol_v2 && service != GIT_CONNECT_UPLOAD_PACK)
1417 version = protocol_v0;
1418
1419 /* Without this we cannot rely on waitpid() to tell
1420 * what happened to our children.
1421 */
1422 signal(SIGCHLD, SIG_DFL);
1423
1424 scheme = parse_connect_url(url, &hostandport, &path);
1425 if ((flags & CONNECT_DIAG_URL) && (scheme != URL_SCHEME_SSH)) {
1426 printf("Diag: url=%s\n", url ? url : "NULL");
1427 printf("Diag: protocol=%s\n", url_scheme_name(scheme));
1428 printf("Diag: hostandport=%s\n", hostandport ? hostandport : "NULL");
1429 printf("Diag: path=%s\n", path ? path : "NULL");
1430 conn = NULL;
1431 } else if (scheme == URL_SCHEME_GIT) {
1432 conn = git_connect_git(fd, hostandport, path, prog, version, flags);
1433 conn->trace2_child_class = "transport/git";
1434 } else {
1435 struct strbuf cmd = STRBUF_INIT;
1436 const char *const *var;
1437
1438 conn = xmalloc(sizeof(*conn));
1439 child_process_init(conn);
1440
1441 if (looks_like_command_line_option(path))
1442 die(_("strange pathname '%s' blocked"), path);
1443
1444 strbuf_addstr(&cmd, prog);
1445 strbuf_addch(&cmd, ' ');
1446 sq_quote_buf(&cmd, path);
1447
1448 /* remove repo-local variables from the environment */
1449 for (var = local_repo_env; *var; var++)
1450 strvec_push(&conn->env, *var);
1451
1452 conn->use_shell = 1;
1453 conn->in = conn->out = -1;
1454 if (scheme == URL_SCHEME_SSH) {
1455 char *ssh_host = hostandport;
1456 const char *port = NULL;
1457 transport_check_allowed("ssh");
1458 get_host_and_port(&ssh_host, &port);

Callers 4

connect_setupFunction · 0.85
connect_gitFunction · 0.85
cmd_fetch_packFunction · 0.85
cmd_send_packFunction · 0.85

Calls 15

parse_connect_urlFunction · 0.85
url_scheme_nameFunction · 0.85
git_connect_gitFunction · 0.85
child_process_initFunction · 0.85
strbuf_addstrFunction · 0.85
strbuf_addchFunction · 0.85
sq_quote_bufFunction · 0.85
strvec_pushFunction · 0.85
transport_check_allowedFunction · 0.85
get_host_and_portFunction · 0.85

Tested by

no test coverage detected