[PATCH] Don't fetch objects that exist in the local repository
[git.git] / http-fetch.c
index b034a45..d1e4593 100644 (file)
@@ -489,7 +489,10 @@ void process_request_queue()
 
        while (active_requests < max_requests && request != NULL) {
                if (request->state == WAITING) {
-                       start_request(request);
+                       if (has_sha1_file(request->sha1))
+                               release_request(request);
+                       else
+                               start_request(request);
                        curl_multi_perform(curlm, &num_transfers);
                }
                request = request->next;
@@ -890,6 +893,11 @@ static int fetch_object(struct alt_base *repo, unsigned char *sha1)
        if (request == NULL)
                return error("Couldn't find request for %s in the queue", hex);
 
+       if (has_sha1_file(request->sha1)) {
+               release_request(request);
+               return 0;
+       }
+
 #ifdef USE_CURL_MULTI
        int num_transfers;
        while (request->state == WAITING) {
@@ -1034,22 +1042,11 @@ int main(int argc, char **argv)
                        arg++;
                } else if (!strcmp(argv[arg], "--recover")) {
                        get_recover = 1;
-#ifdef USE_CURL_MULTI
-               } else if (argv[arg][1] == 'r') {
-                       max_requests = atoi(argv[arg + 1]);
-                       if (max_requests < 1)
-                               max_requests = DEFAULT_MAX_REQUESTS;
-                       arg++;
-#endif
                }
                arg++;
        }
        if (argc < arg + 2) {
-#ifdef USE_CURL_MULTI
-               usage("git-http-fetch [-c] [-t] [-a] [-d] [-v] [-r concurrent-request-limit] [--recover] [-w ref] commit-id url");
-#else
                usage("git-http-fetch [-c] [-t] [-a] [-d] [-v] [--recover] [-w ref] commit-id url");
-#endif
                return 1;
        }
        commit_id = argv[arg];
@@ -1058,6 +1055,12 @@ int main(int argc, char **argv)
        curl_global_init(CURL_GLOBAL_ALL);
 
 #ifdef USE_CURL_MULTI
+       char *http_max_requests = getenv("GIT_HTTP_MAX_REQUESTS");
+       if (http_max_requests != NULL)
+               max_requests = atoi(http_max_requests);
+       if (max_requests < 1)
+               max_requests = DEFAULT_MAX_REQUESTS;
+
        curlm = curl_multi_init();
        if (curlm == NULL) {
                fprintf(stderr, "Error creating curl multi handle.\n");