Re-implement 'git remote update' using 'git fetch'
[gitweb.git] / http.c
diff --git a/http.c b/http.c
index 98f9707625dd1e28dc3206f76ab27b231c1425a9..23b2a1932c7daebd585827da7effd1c5bbae5e69 100644 (file)
--- a/http.c
+++ b/http.c
@@ -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);
 }
@@ -864,20 +866,9 @@ static int fetch_pack_index(unsigned char *sha1, const char *base_url)
        int ret = 0;
        char *hex = xstrdup(sha1_to_hex(sha1));
        char *filename;
-       char *url;
+       char *url = NULL;
        struct strbuf buf = STRBUF_INIT;
 
-       /* Don't use the index if the pack isn't there */
-       end_url_with_slash(&buf, base_url);
-       strbuf_addf(&buf, "objects/pack/pack-%s.pack", hex);
-       url = strbuf_detach(&buf, 0);
-
-       if (http_get_strbuf(url, NULL, 0)) {
-               ret = error("Unable to verify pack %s is available",
-                           hex);
-               goto cleanup;
-       }
-
        if (has_pack_index(sha1)) {
                ret = 0;
                goto cleanup;
@@ -1187,7 +1178,11 @@ struct http_object_request *new_http_object_request(const char *base_url,
                if (prev_posn>0) {
                        prev_posn = 0;
                        lseek(freq->localfile, 0, SEEK_SET);
-                       ftruncate(freq->localfile, 0);
+                       if (ftruncate(freq->localfile, 0) < 0) {
+                               error("Couldn't truncate temporary file %s for %s: %s",
+                                         freq->tmpfile, freq->filename, strerror(errno));
+                               goto abort;
+                       }
                }
        }
 
@@ -1283,5 +1278,10 @@ void release_http_object_request(struct http_object_request *freq)
                free(freq->url);
                freq->url = NULL;
        }
-       freq->slot = NULL;
+       if (freq->slot != NULL) {
+               freq->slot->callback_func = NULL;
+               freq->slot->callback_data = NULL;
+               release_active_slot(freq->slot);
+               freq->slot = NULL;
+       }
 }