Verify remote packs, speed up pending request queue
Verify that remote packs exist before using the pack index, add requests to the beginning of the queue to locate pending requests faster. Signed-off-by: Nick Hengeveld <nickh@reactrix.com> Signed-off-by: Junio C Hamano <junkio@cox.net>
Nick Hengeveld committed
Nov 4, 2005 at 14:22 UTC
c17fb6ee074cb0c9d71e5de42e2ad00786fedc18
1 file changed
+21
-16
http-push.c
+21
-16
@@ -727,7 +727,6 @@ void process_waiting_requests(void)
727
void add_request(unsigned char *sha1, char *lock_token)
728
{
729
struct transfer_request *request = request_queue_head;
730
- struct transfer_request *tail;
730
struct packed_git *target;
731
732
while (request != NULL && memcmp(request->sha1, sha1, 20))
@@ -745,17 +744,8 @@ void add_request(unsigned char *sha1, char *lock_token)
744
request->lock_token = lock_token;
745
request->headers = NULL;
746
request->state = NEED_CHECK;
748
- request->next = NULL;
749
-
750
- if (request_queue_head == NULL) {
751
- request_queue_head = request;
752
- } else {
753
- tail = request_queue_head;
754
- while (tail->next != NULL) {
755
- tail = tail->next;
756
- }
757
- tail->next = request;
758
- }
747
+ request->next = request_queue_head;
748
+ request_queue_head = request;
749
#ifdef USE_CURL_MULTI
750
process_request_queue();
751
process_curl_messages();
@@ -775,13 +765,29 @@ static int fetch_index(unsigned char *sha1)
765
FILE *indexfile;
766
struct active_request_slot *slot;
767
768
+ /* Don't use the index if the pack isn't there */
769
+ url = xmalloc(strlen(remote->url) + 65);
770
+ sprintf(url, "%s/objects/pack/pack-%s.pack", remote->url, hex);
771
+ slot = get_active_slot();
772
+ curl_easy_setopt(slot->curl, CURLOPT_URL, url);
773
+ curl_easy_setopt(slot->curl, CURLOPT_NOBODY, 1);
774
+ if (start_active_slot(slot)) {
775
+ run_active_slot(slot);
776
+ if (slot->curl_result != CURLE_OK) {
777
+ free(url);
778
+ return error("Unable to verify pack %s is available",
779
+ hex);
780
+ }
781
+ } else {
782
+ return error("Unable to start request");
783
+ }
784
+
785
if (has_pack_index(sha1))
786
return 0;
787
788
if (push_verbosely)
789
fprintf(stderr, "Getting index for pack %s\n", hex);
790
784
- url = xmalloc(strlen(remote->url) + 64);
791
sprintf(url, "%s/objects/pack/pack-%s.idx", remote->url, hex);
792
793
filename = sha1_pack_index_name(sha1);
@@ -792,6 +798,8 @@ static int fetch_index(unsigned char *sha1)
798
filename);
799
800
slot = get_active_slot();
801
+ curl_easy_setopt(slot->curl, CURLOPT_NOBODY, 0);
802
+ curl_easy_setopt(slot->curl, CURLOPT_HTTPGET, 1);
803
curl_easy_setopt(slot->curl, CURLOPT_FILE, indexfile);
804
curl_easy_setopt(slot->curl, CURLOPT_WRITEFUNCTION, fwrite);
805
curl_easy_setopt(slot->curl, CURLOPT_URL, url);
@@ -833,8 +841,6 @@ static int fetch_index(unsigned char *sha1)
841
static int setup_index(unsigned char *sha1)
842
{
843
struct packed_git *new_pack;
836
- if (has_pack_file(sha1))
837
- return 0; // don't list this as something we can get
844
845
if (fetch_index(sha1))
846
return -1;
@@ -1610,7 +1616,6 @@ int main(int argc, char **argv)
1616
while (request != NULL) {
1617
next_request = request->next;
1618
release_request(request);
1613
- free(request);
1619
request = next_request;
1620
}
1621