MCPcopy Index your code
hub / github.com/git/git / lock_remote

Function lock_remote

http-push.c:843–954  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

841}
842
843static struct remote_lock *lock_remote(const char *path, long timeout)
844{
845 struct active_request_slot *slot;
846 struct slot_results results;
847 struct buffer out_buffer = { STRBUF_INIT, 0 };
848 struct strbuf in_buffer = STRBUF_INIT;
849 char *url;
850 char *ep;
851 char timeout_header[25];
852 struct remote_lock *lock = NULL;
853 struct curl_slist *dav_headers = http_copy_default_headers();
854 struct xml_ctx ctx;
855 char *escaped;
856
857 url = xstrfmt("%s%s", repo->url, path);
858
859 /* Make sure leading directories exist for the remote ref */
860 ep = strchr(url + strlen(repo->url) + 1, '/');
861 while (ep) {
862 char saved_character = ep[1];
863 ep[1] = '\0';
864 slot = get_active_slot();
865 slot->results = &results;
866 curl_setup_http_get(slot->curl, url, DAV_MKCOL);
867 if (start_active_slot(slot)) {
868 run_active_slot(slot);
869 if (results.curl_result != CURLE_OK &&
870 results.http_code != 405) {
871 fprintf(stderr,
872 "Unable to create branch path %s\n",
873 url);
874 free(url);
875 return NULL;
876 }
877 } else {
878 fprintf(stderr, "Unable to start MKCOL request\n");
879 free(url);
880 return NULL;
881 }
882 ep[1] = saved_character;
883 ep = strchr(ep + 1, '/');
884 }
885
886 escaped = xml_entities(ident_default_email());
887 strbuf_addf(&out_buffer.buf, LOCK_REQUEST, escaped);
888 free(escaped);
889
890 xsnprintf(timeout_header, sizeof(timeout_header), "Timeout: Second-%ld", timeout);
891 dav_headers = curl_slist_append(dav_headers, timeout_header);
892 dav_headers = curl_slist_append(dav_headers, "Content-Type: text/xml");
893
894 slot = get_active_slot();
895 slot->results = &results;
896 curl_setup_http(slot->curl, url, DAV_LOCK, &out_buffer, fwrite_buffer);
897 curl_easy_setopt(slot->curl, CURLOPT_HTTPHEADER, dav_headers);
898 curl_easy_setopt(slot->curl, CURLOPT_WRITEDATA, &in_buffer);
899
900 CALLOC_ARRAY(lock, 1);

Callers 1

cmd_mainFunction · 0.85

Calls 13

xstrfmtFunction · 0.85
get_active_slotFunction · 0.85
curl_setup_http_getFunction · 0.85
start_active_slotFunction · 0.85
run_active_slotFunction · 0.85
xml_entitiesFunction · 0.85
ident_default_emailFunction · 0.85
strbuf_addfFunction · 0.85
xsnprintfFunction · 0.85
curl_setup_httpFunction · 0.85
xcallocFunction · 0.85

Tested by

no test coverage detected