Skip to contentSkip to conversation

git http-push and MKCOL error (22/409)

DISCUSSION Thomas Schlichter 3 participants 12 messages Jun 15, 2016

lore
Share & tools
lore
#0 lore raw

Hello,

I was using git version 1.6.4 and a remote WebDAV repository. But unfortunately, git-http-push always returns following error:

schlicht@netbook:~/dummy$ git push
Fetching remote heads...
  refs
  refs/heads
  refs/tags
  refs/heads
  refs/tags
updating 'refs/heads/master'
  from 980385b1032efc0db665dff3ad54068f762af9aa
  to   98fd7fb8f32843c1bb40bd195a2f1cd6cab0751d
    sending 1 objects
MKCOL 98fd7fb8f32843c1bb40bd195a2f1cd6cab0751d failed, aborting (22/409)
Updating remote server info
error: failed to push some refs to 
'https://webdav.smartdrive.web.de/dummy.git'

Current "master" and "next" trees also have this problem. But as git version 1.6.4 does not have this problem, I was able to bisect it down to commit:

5424bc557fc6414660830b470dd45774b8f5f281 http*: add helper methods for fetching objects (loose)

I can always reproduce this problem, so I am willing to test patches to fix this regression.

Kind regards,
Thomas Schlichter

#1 lore raw

Hi,

Quoted 5 lines · Thomas Schlichter

Current "master" and "next" trees also have this problem. But as git version 1.6.4 does not have this problem, I was able to bisect it down to commit:

  5424bc557fc6414660830b470dd45774b8f5f281 http*: add helper methods for fetching objects (loose)

Interesting. Please do provide:

-steps to reproduce,
-your server's access log.

Signature · 2 lines
Cheers,
Ray Chuan
#2 lore raw

Hi,
Am Sonntag 16 August 2009 16:27:40 schrieb Tay Ray Chuan:

Quoted 4 lines

Interesting. Please do provide:

-steps to reproduce,
-your server's access log.

Unfortunately I cannot provide the server's access log. It is a server provided by the German E-Mail provider web.de. It allows to save files via a web-interface and via WebDAV.

Steps to reproduce:
1. locally set up a git archive:

     mkdir dummy.git
     cd dummy.git
     git init --bare

2. Upload this directory to the server.
I did do this using KDE's dolphin via WebDAV.
3. Clone this remote repository:
git clone https://webdav.smartdrive.web.de/dummy.git my_dummy
4. Create a local commit:
cd my_dummy
touch dummy.c
git commit -a
5. Push this commit up to the remote repository:
git push origin master

The last step fails es explained. During bisecting git I was able to commit several changes with versions before commit 5424bc557fc6414660830b470dd45774b8f5f281.

Kind regards,
Thomas Schlichter

P.S.: Maybe it is important that the server uses the secure https protocol, therefore I set my username and password combination in my local ~/.netrc file.

#3 lore raw

Hi,

Quoted 1 line · Thomas Schlichter

Steps to reproduce:

before I try this out, I have a few queries:

Quoted 8 lines

 1. locally set up a git archive:
    mkdir dummy.git
    cd dummy.git
    git init --bare
 2. Upload this directory to the server.
    I did do this using KDE's dolphin via WebDAV.
3. Clone this remote repository:
git clone https://webdav.smartdrive.web.de/dummy.git my_dummy

You didn't run git update-server-info before doing the clone; cloning wouldn't work cos git can't find a info/refs file. Perhaps you did do it and unintentionally left it out from your procedure listed here?

Quoted 4 lines

 4. Create a local commit:
    cd my_dummy
    touch dummy.c
    git commit -a

I assume you want to commit dummy.c? But you didn't tell git to track it in the first place (git add dummy.c).

Quoted 2 lines

 5. Push this commit up to the remote repository:
    git push origin master

I also find it strange that git only pushed 1 object from your git push output, when usually there would be a tree, a blob and a commit to push for a new commit.

Signature · 2 lines
Cheers,
Ray Chuan
#4 lore raw

Hi,

Am Montag 17 August 2009 06:52:32 schrieb Tay Ray Chuan:

Quoted 17 lines

Hi,

On Sun, Aug 16, 2009 at 10:52 PM, Thomas

Quoted 1 line · Schlichter

Steps to reproduce:

before I try this out, I have a few queries:

Quoted 8 lines

1. locally set up a git archive:

    mkdir dummy.git
    cd dummy.git
    git init --bare

2. Upload this directory to the server.
I did do this using KDE's dolphin via WebDAV.
3. Clone this remote repository:
git clone https://webdav.smartdrive.web.de/dummy.git my_dummy

Quoted 3 lines

You didn't run git update-server-info before doing the clone; cloning wouldn't work cos git can't find a info/refs file. Perhaps you did do it and unintentionally left it out from your procedure listed here?

Oh, yes, sorry.
I did run it but unintentionally left it out. At least I had no problem with clone, it did clone an "empty repository" without a problem. Even during bisecting, I never had a problem with pulling from the server, only with pushing to it.

Quoted 6 lines
Quoted 4 lines

4. Create a local commit:
cd my_dummy
touch dummy.c
git commit -a

I assume you want to commit dummy.c?

Yes, indeed...

Quoted 2 lines

But you didn't tell git to track
it in the first place (git add dummy.c).

I think that was not neccessary, the parameter "-a" should do it for me...

Quoted 6 lines
Quoted 2 lines

5. Push this commit up to the remote repository:
git push origin master

I also find it strange that git only pushed 1 object from your git push output, when usually there would be a tree, a blob and a commit to push for a new commit.

Yes, most of the times git tries to push three objects, and fails with all three. As I wrote, during bisecting I was able to commit several times. The reported message was the last one failing. Unfortunately git only needed to push one object that time. I didn't think it was important if it were three or just one object?!

Kind regards,
Thomas Schlichter

#5 lore raw

Hi,

Am Montag 17 August 2009 07:18:15 schrieb Thomas Schlichter:

Quoted 11 lines

Hi,

Am Montag 17 August 2009 06:52:32 schrieb Tay Ray Chuan:

Quoted 1 line

I assume you want to commit dummy.c?

Yes, indeed...

Quoted 2 lines

But you didn't tell git to track
it in the first place (git add dummy.c).

I think that was not neccessary, the parameter "-a" should do it for me...

OK, I tried it again, and the parameter "-a" was not sufficient. So I obviously did run a "git add dummy.c". Sorry for missing that.

Now I do also have the error message for the first commit:

schlicht@netbook:~/dummy2$ git push origin master
Fetching remote heads...
  refs
  refs/heads
  refs/tags
  refs/heads
  refs/tags
updating 'refs/heads/master'
  from 0000000000000000000000000000000000000000
  to   60157fdfdca4693f703c744fed95e1b31743bb4e
    sending 3 objects
MKCOL e69de29bb2d1d6434b8b29ae775ad8c2e48c5391 failed, aborting (22/409)
MKCOL 4aefccd66b8e2bfa58079910045c30bc792877dc failed, aborting (22/409)
MKCOL 60157fdfdca4693f703c744fed95e1b31743bb4e failed, aborting (22/409)
Updating remote server info
error: failed to push some refs to 
'https://webdav.smartdrive.web.de/dummy2.git'

Kind regards,
Thomas Schlichter

#6 lore raw
In reply to Tay Ray Chuan
Quoted 5 lines · Tay Ray Chuan
Quoted 3 lines · Thomas Schlichter

Current "master" and "next" trees also have this problem. But as git version 1.6.4 does not have this problem, I was able to bisect it down to commit:

Quoted 7 lines
Quoted 2 lines

  5424bc557fc6414660830b470dd45774b8f5f281 http*: add helper methods for fetching objects (loose)

Interesting. Please do provide:

-steps to reproduce,
-your server's access log.

The report said:

    MKCOL 98fd7fb8f32843c1bb40bd195a2f1cd6cab0751d failed, aborting (22/409)

As far as I can see you are trying (in http-push.c::start_mkcol()) to create the two-hexdigit fan-out directory (i.e. "98" for this example); it is strange to see a request to create the full 40-hexdigit collection in the first place.

In another thread you responded to earlier:

    http://thread.gmane.org/gmane.comp.version-control.git/125933/focus=125972

the original report did not give the exact error message, but in that one, instead of failing to create 40-hexdigit collection like this, I am guessing that it fails with something like "MKCOL 'refs' failed".

So are these unrelated "breakages"[1]?

[Foornote]

*1* Not necessarily in the sense the client is broken but in the sense that the server-client combination does not work for the reporter.

#7 lore raw

Hi,

Quoted 8 lines · Junio C Hamano

The report said:

   MKCOL 98fd7fb8f32843c1bb40bd195a2f1cd6cab0751d failed, aborting (22/409)

As far as I can see you are trying (in http-push.c::start_mkcol()) to create the two-hexdigit fan-out directory (i.e. "98" for this example); it is strange to see a request to create the full 40-hexdigit collection in the first place.

Yes, you're right, but git prints out the full SHA-1 hash even though it is actually referring to the 2-hexdigit directory that it failed to create/verify, for whatever reason.

Quoted 7 lines

In another thread you responded to earlier:

   http://thread.gmane.org/gmane.comp.version-control.git/125933/focus=125972

the original report did not give the exact error message, but in that one, instead of failing to create 40-hexdigit collection like this, I am guessing that it fails with something like "MKCOL 'refs' failed".

I guess by "original report" you refer to Thomas' initial email: yes, he (unwittingly) did provide theerror code in the subject line, the part which says (22/409). It actually means (<curl return code>/<http return code>). Referring again to
http://www.webdav.org/specs/rfc4918.html#rfc.section.9.3.1:

409 (Conflict) - A collection cannot be made at the Request-URI until one or more intermediate collections have been created. The server must not create those intermediate collections automatically.

meaning one or more parent directories weren't created.

Based on this and his procedure, I'm guessing that there's something wrong with his setup.

Quoted 2 lines

*1* Not necessarily in the sense the client is broken but in the sense that the server-client combination does not work for the reporter.

Indeed.

Signature · 2 lines
Cheers,
Ray Chuan
#8 lore raw

Hi,

Am Montag 17 August 2009 06:58:25 schrieb Tay Ray Chuan:

Quoted 39 lines

Hi,

Quoted 9 lines · Junio C Hamano

The report said:

   MKCOL 98fd7fb8f32843c1bb40bd195a2f1cd6cab0751d failed, aborting

(22/409)

As far as I can see you are trying (in http-push.c::start_mkcol()) to create the two-hexdigit fan-out directory (i.e. "98" for this example); it is strange to see a request to create the full 40-hexdigit collection in the first place.

Yes, you're right, but git prints out the full SHA-1 hash even though it is actually referring to the 2-hexdigit directory that it failed to create/verify, for whatever reason.

Quoted 9 lines

In another thread you responded to earlier:

http://thread.gmane.org/gmane.comp.version-control.git/125933/focus=1259
72

the original report did not give the exact error message, but in that one, instead of failing to create 40-hexdigit collection like this, I am guessing that it fails with something like "MKCOL 'refs' failed".

I guess by "original report" you refer to Thomas' initial email: yes, he (unwittingly) did provide theerror code in the subject line, the part which says (22/409). It actually means (<curl return code>/<http return code>). Referring again to
http://www.webdav.org/specs/rfc4918.html#rfc.section.9.3.1:

409 (Conflict) - A collection cannot be made at the Request-URI until one or more intermediate collections have been created. The server must not create those intermediate collections automatically.

meaning one or more parent directories weren't created.

Quoted 7 lines

Based on this and his procedure, I'm guessing that there's something wrong with his setup.

Quoted 2 lines

*1* Not necessarily in the sense the client is broken but in the sense that the server-client combination does not work for the reporter.

Indeed.

Hmm. I hope you won't take this as an argument for not fixing it, because it is a clear regression! I tried git version 1.6.3.4, and it works flawlessly with exactly this server! Even during bisecting, some versions worked, some didn't (these after the mentioned commit...)

So I think this commit didn't only refactor things, but unintentionally changed the behavior. And this must be the problem. As I'm not into this code, and the refactoring was not completely trivial, I was not able to quickly find the place where the behavior was changed...

Kind regards,
Thomas Schlichter

#9 lore raw

Hi,

Quoted 9 lines · Thomas Schlichter

Hmm. I hope you won't take this as an argument for not fixing it, because it is a clear regression! I tried git version 1.6.3.4, and it works flawlessly with exactly this server! Even during bisecting, some versions worked, some didn't (these after the mentioned commit...)

So I think this commit didn't only refactor things, but unintentionally changed the behavior. And this must be the problem. As I'm not into this code, and the refactoring was not completely trivial, I was not able to quickly find the place where the behavior was changed...

Thomas, indeed you're right about this, the commit you noted in your earlier email (5424bc5) was indeed at fault.

The commit changed how urls was handled, and resulted (incorrectly) in an extra slash being added to the url. In other words, urls now look like this:

http://server/repo.git//objects/2a/

This problem occurs only in http-push.c, because repo urls
(http://server/repo.git) are always made to end with a slash there.

Btw, on my Apache 2.2.x server, this didn't crop up when I tested, while Thomas worked with a 2.0.x.

I've attached a patch below that hopefully fixes it.

-- >8 --

Subject: [PATCH] http.c: don't assume that urls don't end with slash

Make append_remote_object_url() (and by implication, get_remote_object_url) use end_url_with_slash() to ensure that the url ends with a slash.

Previously, they assumed that the url did not end with a slash and as a result appended a slash, sometimes errorneously.

This fixes an issue introduced in 5424bc5 ("http*: add helper methods for fetching objects (loose)"), where the append_remote_object_url() implementation in http-push.c, which assumed that urls end with a slash, was replaced by another one in http.c, which assumed urls did not end with a slash.

The above issue was raised by Thomas Schlichter:

http://marc.info/?l=git&m=125043105231327

---
 http.c |    4 +++-
 1 files changed, 3 insertions(+), 1 deletions(-)
http.c +3 -1
index 14d5357..eb0c669 100644
@@ -719,7 +719,9 @@ void append_remote_object_url(struct strbuf *buf, const char *url,
 			      const char *hex,
 			      int only_two_digit_prefix)
 {
-	strbuf_addf(buf, "%s/objects/%.*s/", url, 2, hex);
+	end_url_with_slash(buf, url);
+
+	strbuf_addf(buf, "objects/%.*s/", 2, hex);
 	if (!only_two_digit_prefix)
 		strbuf_addf(buf, "%s", hex+2);
 }

--
1.6.4.dirty

author Tested-by
#10 lore raw

Hi,

Am Montag 17 August 2009 11:09:43 schrieb Tay Ray Chuan:

Quoted 15 lines

Subject: [PATCH] http.c: don't assume that urls don't end with slash

Make append_remote_object_url() (and by implication, get_remote_object_url) use end_url_with_slash() to ensure that the url ends with a slash.

Previously, they assumed that the url did not end with a slash and as a result appended a slash, sometimes errorneously.

This fixes an issue introduced in 5424bc5 ("http*: add helper methods for fetching objects (loose)"), where the append_remote_object_url() implementation in http-push.c, which assumed that urls end with a slash, was replaced by another one in http.c, which assumed urls did not end with a slash.

Quoted 5 lines

The above issue was raised by Thomas Schlichter:

http://marc.info/?l=git&m=125043105231327

Thank you very much!
This patch indeed fixes my problem.

You may add my

if you'd like to. I don't know how this is handled in the git-tree...

Is there a plan in which version this patch will be released? Will there be a 1.6.4.1 or is 1.6.5 next?

Kind regards,
Thomas Schlichter

#11 lore raw
In reply to Thomas Schlichter
Quoted 4 lines · Thomas Schlichter

Hmm. I hope you won't take this as an argument for not fixing it, because it is a clear regression! I tried git version 1.6.3.4, and it works flawlessly with exactly this server! Even during bisecting, some versions worked, some didn't (these after the mentioned commit...)

If it works (without changing anything else) with one version and with a problematic patch it doesn't, it is a clear regression.

If you revert 5424bc5 (http*: add helper methods for fetching objects (loose), 2009-06-06) from the tip of 'master', does it make the problem go away?

The patch should look like something like the attached.

http-push.c +198 -15
index 00e83dc..d1ea702 100644
@@ -115,10 +115,18 @@ struct transfer_request
 	struct remote_lock *lock;
 	struct curl_slist *headers;
 	struct buffer buffer;
+	char filename[PATH_MAX];
+	char tmpfile[PATH_MAX];
+	int local_fileno;
 	enum transfer_state state;
 	CURLcode curl_result;
 	char errorstr[CURL_ERROR_SIZE];
 	long http_code;
+	unsigned char real_sha1[20];
+	git_SHA_CTX c;
+	z_stream stream;
+	int zret;
+	int rename;
 	void *userData;
 	struct active_request_slot *slot;
 	struct transfer_request *next;
@@ -226,6 +234,15 @@ static struct curl_slist *get_dav_token_headers(struct remote_lock *lock, enum d
 	return dav_headers;
 }
 
+static void append_remote_object_url(struct strbuf *buf, const char *url,
+				     const char *hex,
+				     int only_two_digit_prefix)
+{
+	strbuf_addf(buf, "%sobjects/%.*s/", url, 2, hex);
+	if (!only_two_digit_prefix)
+		strbuf_addf(buf, "%s", hex+2);
+}
+
 static void finish_request(struct transfer_request *request);
 static void release_request(struct transfer_request *request);
 
@@ -239,29 +256,169 @@ static void process_response(void *callback_data)
 
 #ifdef USE_CURL_MULTI
 
+static char *get_remote_object_url(const char *url, const char *hex,
+				   int only_two_digit_prefix)
+{
+	struct strbuf buf = STRBUF_INIT;
+	append_remote_object_url(&buf, url, hex, only_two_digit_prefix);
+	return strbuf_detach(&buf, NULL);
+}
+
+static size_t fwrite_sha1_file(void *ptr, size_t eltsize, size_t nmemb,
+			       void *data)
+{
+	unsigned char expn[4096];
+	size_t size = eltsize * nmemb;
+	int posn = 0;
+	struct transfer_request *request = (struct transfer_request *)data;
+	do {
+		ssize_t retval = xwrite(request->local_fileno,
+					(char *) ptr + posn, size - posn);
+		if (retval < 0)
+			return posn;
+		posn += retval;
+	} while (posn < size);
+
+	request->stream.avail_in = size;
+	request->stream.next_in = ptr;
+	do {
+		request->stream.next_out = expn;
+		request->stream.avail_out = sizeof(expn);
+		request->zret = git_inflate(&request->stream, Z_SYNC_FLUSH);
+		git_SHA1_Update(&request->c, expn,
+				sizeof(expn) - request->stream.avail_out);
+	} while (request->stream.avail_in && request->zret == Z_OK);
+	data_received++;
+	return size;
+}
+
 static void start_fetch_loose(struct transfer_request *request)
 {
+	char *hex = sha1_to_hex(request->obj->sha1);
+	char *filename;
+	char prevfile[PATH_MAX];
+	char *url;
+	int prevlocal;
+	unsigned char prev_buf[PREV_BUF_SIZE];
+	ssize_t prev_read = 0;
+	long prev_posn = 0;
+	char range[RANGE_HEADER_SIZE];
+	struct curl_slist *range_header = NULL;
 	struct active_request_slot *slot;
-	struct http_object_request *obj_req;
 
-	obj_req = new_http_object_request(repo->url, request->obj->sha1);
-	if (obj_req == NULL) {
+	filename = sha1_file_name(request->obj->sha1);
+	snprintf(request->filename, sizeof(request->filename), "%s", filename);
+	snprintf(request->tmpfile, sizeof(request->tmpfile),
+		 "%s.temp", filename);
+
+	snprintf(prevfile, sizeof(prevfile), "%s.prev", request->filename);
+	unlink_or_warn(prevfile);
+	rename(request->tmpfile, prevfile);
+	unlink_or_warn(request->tmpfile);
+
+	if (request->local_fileno != -1)
+		error("fd leakage in start: %d", request->local_fileno);
+	request->local_fileno = open(request->tmpfile,
+				     O_WRONLY | O_CREAT | O_EXCL, 0666);
+	/*
+	 * This could have failed due to the "lazy directory creation";
+	 * try to mkdir the last path component.
+	 */
+	if (request->local_fileno < 0 && errno == ENOENT) {
+		char *dir = strrchr(request->tmpfile, '/');
+		if (dir) {
+			*dir = 0;
+			mkdir(request->tmpfile, 0777);
+			*dir = '/';
+		}
+		request->local_fileno = open(request->tmpfile,
+					     O_WRONLY | O_CREAT | O_EXCL, 0666);
+	}
+
+	if (request->local_fileno < 0) {
 		request->state = ABORTED;
+		error("Couldn't create temporary file %s for %s: %s",
+		      request->tmpfile, request->filename, strerror(errno));
 		return;
 	}
 
-	slot = obj_req->slot;
+	memset(&request->stream, 0, sizeof(request->stream));
+
+	git_inflate_init(&request->stream);
+
+	git_SHA1_Init(&request->c);
+
+	url = get_remote_object_url(repo->url, hex, 0);
+	request->url = xstrdup(url);
+
+	/*
+	 * If a previous temp file is present, process what was already
+	 * fetched.
+	 */
+	prevlocal = open(prevfile, O_RDONLY);
+	if (prevlocal != -1) {
+		do {
+			prev_read = xread(prevlocal, prev_buf, PREV_BUF_SIZE);
+			if (prev_read>0) {
+				if (fwrite_sha1_file(prev_buf,
+						     1,
+						     prev_read,
+						     request) == prev_read)
+					prev_posn += prev_read;
+				else
+					prev_read = -1;
+			}
+		} while (prev_read > 0);
+		close(prevlocal);
+	}
+	unlink_or_warn(prevfile);
+
+	/*
+	 * Reset inflate/SHA1 if there was an error reading the previous temp
+	 * file; also rewind to the beginning of the local file.
+	 */
+	if (prev_read == -1) {
+		memset(&request->stream, 0, sizeof(request->stream));
+		git_inflate_init(&request->stream);
+		git_SHA1_Init(&request->c);
+		if (prev_posn>0) {
+			prev_posn = 0;
+			lseek(request->local_fileno, 0, SEEK_SET);
+			ftruncate(request->local_fileno, 0);
+		}
+	}
+
+	slot = get_active_slot();
 	slot->callback_func = process_response;
 	slot->callback_data = request;
 	request->slot = slot;
-	request->userData = obj_req;
+
+	curl_easy_setopt(slot->curl, CURLOPT_FILE, request);
+	curl_easy_setopt(slot->curl, CURLOPT_WRITEFUNCTION, fwrite_sha1_file);
+	curl_easy_setopt(slot->curl, CURLOPT_ERRORBUFFER, request->errorstr);
+	curl_easy_setopt(slot->curl, CURLOPT_URL, url);
+	curl_easy_setopt(slot->curl, CURLOPT_HTTPHEADER, no_pragma_header);
+
+	/*
+	 * If we have successfully processed data from a previous fetch
+	 * attempt, only fetch the data we don't already have.
+	 */
+	if (prev_posn>0) {
+		if (push_verbosely)
+			fprintf(stderr,
+				"Resuming fetch of object %s at byte %ld\n",
+				hex, prev_posn);
+		sprintf(range, "Range: bytes=%ld-", prev_posn);
+		range_header = curl_slist_append(range_header, range);
+		curl_easy_setopt(slot->curl,
+				 CURLOPT_HTTPHEADER, range_header);
+	}
 
 	/* Try to get the request started, abort the request on error */
 	request->state = RUN_FETCH_LOOSE;
 	if (!start_active_slot(slot)) {
 		fprintf(stderr, "Unable to start GET request\n");
 		repo->can_update_info_refs = 0;
-		release_http_object_request(obj_req);
 		release_request(request);
 	}
 }
@@ -520,14 +677,16 @@ static void release_request(struct transfer_request *request)
 			entry->next = entry->next->next;
 	}
 
+	if (request->local_fileno != -1)
+		close(request->local_fileno);
 	free(request->url);
 	free(request);
 }
 
 static void finish_request(struct transfer_request *request)
 {
+	struct stat st;
 	struct http_pack_request *preq;
-	struct http_object_request *obj_req;
 
 	request->curl_result = request->slot->curl_result;
 	request->http_code = request->slot->http_code;
@@ -582,17 +741,39 @@ static void finish_request(struct transfer_request *request)
 			aborted = 1;
 		}
 	} else if (request->state == RUN_FETCH_LOOSE) {
-		obj_req = (struct http_object_request *)request->userData;
-
-		if (finish_http_object_request(obj_req) == 0)
-			if (obj_req->rename == 0)
-				request->obj->flags |= (LOCAL | REMOTE);
+		close(request->local_fileno);
+		request->local_fileno = -1;
+
+		if (request->curl_result != CURLE_OK &&
+		    request->http_code != 416) {
+			if (stat(request->tmpfile, &st) == 0) {
+				if (st.st_size == 0)
+					unlink_or_warn(request->tmpfile);
+			}
+		} else {
+			if (request->http_code == 416)
+				warning("requested range invalid; we may already have all the data.");
+
+			git_inflate_end(&request->stream);
+			git_SHA1_Final(request->real_sha1, &request->c);
+			if (request->zret != Z_STREAM_END) {
+				unlink_or_warn(request->tmpfile);
+			} else if (hashcmp(request->obj->sha1, request->real_sha1)) {
+				unlink_or_warn(request->tmpfile);
+			} else {
+				request->rename =
+					move_temp_to_file(
+						request->tmpfile,
+						request->filename);
+				if (request->rename == 0)
+					request->obj->flags |= (LOCAL | REMOTE);
+			}
+		}
 
 		/* Try fetching packed if necessary */
-		if (request->obj->flags & LOCAL) {
-			release_http_object_request(obj_req);
+		if (request->obj->flags & LOCAL)
 			release_request(request);
-		} else
+		else
 			start_fetch_packed(request);
 
 	} else if (request->state == RUN_FETCH_PACKED) {
@@ -664,6 +845,7 @@ static void add_fetch_request(struct object *obj)
 	request->url = NULL;
 	request->lock = NULL;
 	request->headers = NULL;
+	request->local_fileno = -1;
 	request->state = NEED_FETCH;
 	request->next = request_queue_head;
 	request_queue_head = request;
@@ -702,6 +884,7 @@ static int add_send_request(struct object *obj, struct remote_lock *lock)
 	request->url = NULL;
 	request->lock = lock;
 	request->headers = NULL;
+	request->local_fileno = -1;
 	request->state = NEED_PUSH;
 	request->next = request_queue_head;
 	request_queue_head = request;
http-walker.c +227 -40

388 lines not on this page · raw message

http.c +2 -250

273 lines not on this page · raw message

http.h +4 -33
index 4c4e99c..511c0c4 100644
@@ -88,6 +88,10 @@ extern void add_fill_function(void *data, int (*fill)(void *));
 extern void step_active_slots(void);
 #endif
 
+extern struct curl_slist *no_pragma_header;
+
+#define RANGE_HEADER_SIZE 30
+
 extern void http_init(struct remote *remote);
 extern void http_cleanup(void);
 
@@ -110,13 +114,6 @@ static inline int missing__target(int code, int result)
 
 #define missing_target(a) missing__target((a)->http_code, (a)->curl_result)
 
-/* Helpers for modifying and creating URLs */
-extern void append_remote_object_url(struct strbuf *buf, const char *url,
-				     const char *hex,
-				     int only_two_digit_prefix);
-extern char *get_remote_object_url(const char *url, const char *hex,
-				   int only_two_digit_prefix);
-
 /* Options for http_request_*() */
 #define HTTP_NO_CACHE		1
 
@@ -170,30 +167,4 @@ extern struct http_pack_request *new_http_pack_request(
 extern int finish_http_pack_request(struct http_pack_request *preq);
 extern void release_http_pack_request(struct http_pack_request *preq);
 
-/* Helpers for fetching object */
-struct http_object_request
-{
-	char *url;
-	char filename[PATH_MAX];
-	char tmpfile[PATH_MAX];
-	int localfile;
-	CURLcode curl_result;
-	char errorstr[CURL_ERROR_SIZE];
-	long http_code;
-	unsigned char sha1[20];
-	unsigned char real_sha1[20];
-	git_SHA_CTX c;
-	z_stream stream;
-	int zret;
-	int rename;
-	struct active_request_slot *slot;
-};
-
-extern struct http_object_request *new_http_object_request(
-	const char *base_url, unsigned char *sha1);
-extern void process_http_object_request(struct http_object_request *freq);
-extern int finish_http_object_request(struct http_object_request *freq);
-extern void abort_http_object_request(struct http_object_request *freq);
-extern void release_http_object_request(struct http_object_request *freq);
-
 #endif /* HTTP_H */