@matheusbsbs / matheus-bagliano / commits / 4f66250df6
Fork 0

http-push: send out fetch requests on queue

Previously, requests for remote files were simply added to the queue (pointed to by request_queue_head) and no transfer actually takes place (the fill function add_fill_function() is not added until line 2441), even though code that followed may rely on these remote files to be present (eg. the setup_revisions invocation). The code that sends out the requests on the request queue is refactored into the method run_request_queue. After the get_dav_remote_heads invocation (ie. after fetch requests are added to the queue), the requests on the queue are sent out through an invocation to run_request_queue. This invocation to run_request_queue entails adding a fill function before pushing checks take place, which may lead to accidental, unwanted pushes previously. The flag is_running_queue is introduced to prevent this from occurring. fill_active_slot is made to check the flag is_running_queue before the sending of the requests proceeds. Signed-off-by: Tay Ray Chuan <rctay89@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Tay Ray Chuan committed Jun 6, 2009 at 16:43 UTC 4f66250df641362f381faae2aec439850a5a6e41
2 files changed +28 -13
http-push.c
+26 -11
@@ -846,11 +846,12 @@ static void finish_request(struct transfer_request *request)
846 }
847
848 #ifdef USE_CURL_MULTI
849 +static int is_running_queue;
850 static int fill_active_slot(void *unused)
851 {
852 struct transfer_request *request;
853
853 - if (aborted)
854 + if (aborted || !is_running_queue)
855 return 0;
856
857 for (request = request_queue_head; request; request = request->next) {
@@ -2173,6 +2174,25 @@ static int delete_remote_branch(char *pattern, int force)
2174 return 0;
2175 }
2176
2177 +void run_request_queue(void)
2178 +{
2179 +#ifdef USE_CURL_MULTI
2180 + is_running_queue = 1;
2181 + fill_active_slots();
2182 + add_fill_function(NULL, fill_active_slot);
2183 +#endif
2184 + do {
2185 + finish_all_active_slots();
2186 +#ifdef USE_CURL_MULTI
2187 + fill_active_slots();
2188 +#endif
2189 + } while (request_queue_head && !aborted);
2190 +
2191 +#ifdef USE_CURL_MULTI
2192 + is_running_queue = 0;
2193 +#endif
2194 +}
2195 +
2196 int main(int argc, char **argv)
2197 {
2198 struct transfer_request *request;
@@ -2277,6 +2297,8 @@ int main(int argc, char **argv)
2297 repo->url = rewritten_url;
2298 }
2299
2300 + is_running_queue = 0;
2301 +
2302 /* Verify DAV compliance/lock support */
2303 if (!locking_available()) {
2304 rc = 1;
@@ -2306,6 +2328,7 @@ int main(int argc, char **argv)
2328 local_refs = get_local_heads();
2329 fprintf(stderr, "Fetching remote heads...\n");
2330 get_dav_remote_heads();
2331 + run_request_queue();
2332
2333 /* Remove a remote branch if -d or -D was specified */
2334 if (delete_branch) {
@@ -2435,16 +2458,8 @@ int main(int argc, char **argv)
2458 if (objects_to_send)
2459 fprintf(stderr, " sending %d objects\n",
2460 objects_to_send);
2438 -#ifdef USE_CURL_MULTI
2439 - fill_active_slots();
2440 - add_fill_function(NULL, fill_active_slot);
2441 -#endif
2442 - do {
2443 - finish_all_active_slots();
2444 -#ifdef USE_CURL_MULTI
2445 - fill_active_slots();
2446 -#endif
2447 - } while (request_queue_head && !aborted);
2461 +
2462 + run_request_queue();
2463
2464 /* Update the remote branch if all went well */
2465 if (aborted || !update_remote(ref->new_sha1, ref_lock))
t/t5540-http-push.sh
+2 -2
@@ -67,7 +67,7 @@ test_expect_success ' push to remote repository with unpacked refs' '
67 test $HEAD = $(git rev-parse --verify HEAD))
68 '
69
70 -test_expect_failure 'http-push fetches unpacked objects' '
70 +test_expect_success 'http-push fetches unpacked objects' '
71 cp -R "$HTTPD_DOCUMENT_ROOT_PATH"/test_repo.git \
72 "$HTTPD_DOCUMENT_ROOT_PATH"/test_repo_unpacked.git &&
73
@@ -83,7 +83,7 @@ test_expect_failure 'http-push fetches unpacked objects' '
83 git push -f -v $HTTPD_URL/test_repo_unpacked.git master)
84 '
85
86 -test_expect_failure 'http-push fetches packed objects' '
86 +test_expect_success 'http-push fetches packed objects' '
87 cp -R "$HTTPD_DOCUMENT_ROOT_PATH"/test_repo.git \
88 "$HTTPD_DOCUMENT_ROOT_PATH"/test_repo_packed.git &&
89