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

Function discover_refs

remote-curl.c:465–577  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

463}
464
465static struct discovery *discover_refs(const char *service, int for_push)
466{
467 struct strbuf type = STRBUF_INIT;
468 struct strbuf charset = STRBUF_INIT;
469 struct strbuf buffer = STRBUF_INIT;
470 struct strbuf refs_url = STRBUF_INIT;
471 struct strbuf effective_url = STRBUF_INIT;
472 struct strbuf protocol_header = STRBUF_INIT;
473 struct string_list extra_headers = STRING_LIST_INIT_DUP;
474 struct discovery *last = last_discovery;
475 int http_ret, maybe_smart = 0;
476 struct http_get_options http_options;
477 enum protocol_version version = get_protocol_version_config();
478
479 if (last && !strcmp(service, last->service))
480 return last;
481 free_discovery(last);
482
483 strbuf_addf(&refs_url, "%sinfo/refs", url.buf);
484 if ((starts_with(url.buf, "http://") || starts_with(url.buf, "https://")) &&
485 git_env_bool("GIT_SMART_HTTP", 1)) {
486 maybe_smart = 1;
487 if (!strchr(url.buf, '?'))
488 strbuf_addch(&refs_url, '?');
489 else
490 strbuf_addch(&refs_url, '&');
491 strbuf_addf(&refs_url, "service=%s", service);
492 }
493
494 /*
495 * NEEDSWORK: If we are trying to use protocol v2 and we are planning
496 * to perform any operation that doesn't involve upload-pack (i.e., a
497 * fetch, ls-remote, etc), then fallback to v0 since we don't know how
498 * to do anything else (like push or remote archive) via v2.
499 */
500 if (version == protocol_v2 && strcmp("git-upload-pack", service))
501 version = protocol_v0;
502
503 /* Add the extra Git-Protocol header */
504 if (get_protocol_http_header(version, &protocol_header))
505 string_list_append(&extra_headers, protocol_header.buf);
506
507 memset(&http_options, 0, sizeof(http_options));
508 http_options.content_type = &type;
509 http_options.charset = &charset;
510 http_options.effective_url = &effective_url;
511 http_options.base_url = &url;
512 http_options.extra_headers = &extra_headers;
513 http_options.initial_request = 1;
514 http_options.no_cache = 1;
515
516 http_ret = http_get_strbuf(refs_url.buf, &buffer, &http_options);
517 switch (http_ret) {
518 case HTTP_OK:
519 break;
520 case HTTP_MISSING_TARGET:
521 show_http_message(&type, &charset, &buffer);
522 die(_("repository '%s' not found"),

Callers 4

get_refsFunction · 0.85
fetchFunction · 0.85
pushFunction · 0.85
stateless_connectFunction · 0.85

Calls 15

free_discoveryFunction · 0.85
strbuf_addfFunction · 0.85
starts_withFunction · 0.85
git_env_boolFunction · 0.85
strbuf_addchFunction · 0.85
get_protocol_http_headerFunction · 0.85
http_get_strbufFunction · 0.85
show_http_messageFunction · 0.85
transport_anonymize_urlFunction · 0.85
warningFunction · 0.85
xcallocFunction · 0.85

Tested by

no test coverage detected