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

Function new_http_object_request

http.c:2828–2959  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

2826}
2827
2828struct http_object_request *new_http_object_request(const char *base_url,
2829 const struct object_id *oid)
2830{
2831 struct odb_source_files *files = odb_source_files_downcast(the_repository->objects->sources);
2832 char *hex = oid_to_hex(oid);
2833 struct strbuf filename = STRBUF_INIT;
2834 struct strbuf prevfile = STRBUF_INIT;
2835 int prevlocal;
2836 char prev_buf[PREV_BUF_SIZE];
2837 ssize_t prev_read = 0;
2838 off_t prev_posn = 0;
2839 struct http_object_request *freq;
2840
2841 CALLOC_ARRAY(freq, 1);
2842 strbuf_init(&freq->tmpfile, 0);
2843 oidcpy(&freq->oid, oid);
2844 freq->localfile = -1;
2845
2846 odb_loose_path(files->loose, &filename, oid);
2847 strbuf_addf(&freq->tmpfile, "%s.temp", filename.buf);
2848
2849 strbuf_addf(&prevfile, "%s.prev", filename.buf);
2850 unlink_or_warn(prevfile.buf);
2851 rename(freq->tmpfile.buf, prevfile.buf);
2852 unlink_or_warn(freq->tmpfile.buf);
2853 strbuf_release(&filename);
2854
2855 if (freq->localfile != -1)
2856 error("fd leakage in start: %d", freq->localfile);
2857 freq->localfile = open(freq->tmpfile.buf,
2858 O_WRONLY | O_CREAT | O_EXCL, 0666);
2859 /*
2860 * This could have failed due to the "lazy directory creation";
2861 * try to mkdir the last path component.
2862 */
2863 if (freq->localfile < 0 && errno == ENOENT) {
2864 char *dir = strrchr(freq->tmpfile.buf, '/');
2865 if (dir) {
2866 *dir = 0;
2867 mkdir(freq->tmpfile.buf, 0777);
2868 *dir = '/';
2869 }
2870 freq->localfile = open(freq->tmpfile.buf,
2871 O_WRONLY | O_CREAT | O_EXCL, 0666);
2872 }
2873
2874 if (freq->localfile < 0) {
2875 error_errno("Couldn't create temporary file %s",
2876 freq->tmpfile.buf);
2877 goto abort;
2878 }
2879
2880 git_inflate_init(&freq->stream);
2881
2882 the_hash_algo->init_fn(&freq->c);
2883
2884 freq->url = get_remote_object_url(base_url, hex, 0);
2885

Callers 2

start_object_requestFunction · 0.85
start_fetch_looseFunction · 0.85

Calls 15

oid_to_hexFunction · 0.85
strbuf_initFunction · 0.85
oidcpyFunction · 0.85
odb_loose_pathFunction · 0.85
strbuf_addfFunction · 0.85
unlink_or_warnFunction · 0.85
strbuf_releaseFunction · 0.85
errorFunction · 0.85
error_errnoFunction · 0.85
git_inflate_initFunction · 0.85
get_remote_object_urlFunction · 0.85

Tested by

no test coverage detected