http*: move common variables and macros to http.[ch]
Move RANGE_HEADER_SIZE to http.h. Create no_pragma_header, the curl header list containing the header "Pragma:" in http.[ch]. It is allocated in http_init, and freed in http_cleanup. This replaces the no_pragma_header in http-push.c, and the no_pragma_header member in walker_data in http-walker.c. Create http_is_verbose. It is to be used by methods in http.c, and is modified at the entry points of http.c's users, namely http-push.c (when parsing options) and http-walker.c (in get_http_walker). 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
e917674597cc0b345ad2d6e29fd1a03e1039615a
4 files changed
+20
-20
http-push.c
+1
-7
@@ -27,7 +27,6 @@ enum XML_Status {
27
#endif
28
29
#define PREV_BUF_SIZE 4096
30
-#define RANGE_HEADER_SIZE 30
30
31
/* DAV methods */
32
#define DAV_LOCK "LOCK"
@@ -76,8 +75,6 @@ static int pushing;
75
static int aborted;
76
static signed char remote_dir_exists[256];
77
79
-static struct curl_slist *no_pragma_header;
80
-
78
static int push_verbosely;
79
static int push_all = MATCH_REFS_NONE;
80
static int force_all;
@@ -2250,6 +2247,7 @@ int main(int argc, char **argv)
2247
}
2248
if (!strcmp(arg, "--verbose")) {
2249
push_verbosely = 1;
2250
+ http_is_verbose = 1;
2251
continue;
2252
}
2253
if (!strcmp(arg, "-d")) {
@@ -2299,8 +2297,6 @@ int main(int argc, char **argv)
2297
remote->url[remote->url_nr++] = repo->url;
2298
http_init(remote);
2299
2302
- no_pragma_header = curl_slist_append(no_pragma_header, "Pragma:");
2303
-
2300
if (repo->url && repo->url[strlen(repo->url)-1] != '/') {
2301
rewritten_url = xmalloc(strlen(repo->url)+2);
2302
strcpy(rewritten_url, repo->url);
@@ -2503,8 +2499,6 @@ int main(int argc, char **argv)
2499
unlock_remote(info_ref_lock);
2500
free(repo);
2501
2506
- curl_slist_free_all(no_pragma_header);
2507
-
2502
http_cleanup();
2503
2504
request = request_queue_head;
http-walker.c
+5
-13
@@ -5,7 +5,6 @@
5
#include "http.h"
6
7
#define PREV_BUF_SIZE 4096
8
-#define RANGE_HEADER_SIZE 30
8
9
struct alt_base
10
{
@@ -57,7 +56,6 @@ struct walker_data {
56
const char *url;
57
int got_alternates;
58
struct alt_base *alt;
60
- struct curl_slist *no_pragma_header;
59
};
60
61
static struct object_request *object_queue_head;
@@ -108,7 +106,6 @@ static void start_object_request(struct walker *walker,
106
char range[RANGE_HEADER_SIZE];
107
struct curl_slist *range_header = NULL;
108
struct active_request_slot *slot;
111
- struct walker_data *data = walker->data;
109
110
snprintf(prevfile, sizeof(prevfile), "%s.prev", obj_req->filename);
111
unlink_or_warn(prevfile);
@@ -205,7 +202,7 @@ static void start_object_request(struct walker *walker,
202
curl_easy_setopt(slot->curl, CURLOPT_WRITEFUNCTION, fwrite_sha1_file);
203
curl_easy_setopt(slot->curl, CURLOPT_ERRORBUFFER, obj_req->errorstr);
204
curl_easy_setopt(slot->curl, CURLOPT_URL, url);
208
- curl_easy_setopt(slot->curl, CURLOPT_HTTPHEADER, data->no_pragma_header);
205
+ curl_easy_setopt(slot->curl, CURLOPT_HTTPHEADER, no_pragma_header);
206
207
/*
208
* If we have successfully processed data from a previous fetch
@@ -354,6 +351,8 @@ static void prefetch(struct walker *walker, unsigned char *sha1)
351
newreq->slot = NULL;
352
newreq->next = NULL;
353
354
+ http_is_verbose = walker->get_verbosely;
355
+
356
if (object_queue_head == NULL) {
357
object_queue_head = newreq;
358
} else {
@@ -379,7 +378,6 @@ static int fetch_index(struct walker *walker, struct alt_base *repo, unsigned ch
378
long prev_posn = 0;
379
char range[RANGE_HEADER_SIZE];
380
struct curl_slist *range_header = NULL;
382
- struct walker_data *data = walker->data;
381
382
FILE *indexfile;
383
struct active_request_slot *slot;
@@ -430,7 +428,7 @@ static int fetch_index(struct walker *walker, struct alt_base *repo, unsigned ch
428
curl_easy_setopt(slot->curl, CURLOPT_FILE, indexfile);
429
curl_easy_setopt(slot->curl, CURLOPT_WRITEFUNCTION, fwrite);
430
curl_easy_setopt(slot->curl, CURLOPT_URL, url);
433
- curl_easy_setopt(slot->curl, CURLOPT_HTTPHEADER, data->no_pragma_header);
431
+ curl_easy_setopt(slot->curl, CURLOPT_HTTPHEADER, no_pragma_header);
432
slot->local = indexfile;
433
434
/*
@@ -768,7 +766,6 @@ static int fetch_pack(struct walker *walker, struct alt_base *repo, unsigned cha
766
long prev_posn = 0;
767
char range[RANGE_HEADER_SIZE];
768
struct curl_slist *range_header = NULL;
771
- struct walker_data *data = walker->data;
769
770
struct active_request_slot *slot;
771
struct slot_results results;
@@ -802,7 +799,7 @@ static int fetch_pack(struct walker *walker, struct alt_base *repo, unsigned cha
799
curl_easy_setopt(slot->curl, CURLOPT_FILE, packfile);
800
curl_easy_setopt(slot->curl, CURLOPT_WRITEFUNCTION, fwrite);
801
curl_easy_setopt(slot->curl, CURLOPT_URL, url);
805
- curl_easy_setopt(slot->curl, CURLOPT_HTTPHEADER, data->no_pragma_header);
802
+ curl_easy_setopt(slot->curl, CURLOPT_HTTPHEADER, no_pragma_header);
803
slot->local = packfile;
804
805
/*
@@ -948,10 +945,7 @@ static int fetch_ref(struct walker *walker, struct ref *ref)
945
946
static void cleanup(struct walker *walker)
947
{
951
- struct walker_data *data = walker->data;
948
http_cleanup();
953
-
954
- curl_slist_free_all(data->no_pragma_header);
949
}
950
951
struct walker *get_http_walker(const char *url, struct remote *remote)
@@ -962,8 +956,6 @@ struct walker *get_http_walker(const char *url, struct remote *remote)
956
957
http_init(remote);
958
965
- data->no_pragma_header = curl_slist_append(NULL, "Pragma:");
966
-
959
data->alt = xmalloc(sizeof(*data->alt));
960
data->alt->base = xmalloc(strlen(url) + 1);
961
strcpy(data->alt->base, url);
http.c
+9
@@ -2,6 +2,7 @@
2
3
int data_received;
4
int active_requests;
5
+int http_is_verbose;
6
7
#ifdef USE_CURL_MULTI
8
static int max_requests = -1;
@@ -29,6 +30,8 @@ static char *user_name, *user_pass;
30
31
static struct curl_slist *pragma_header;
32
33
+struct curl_slist *no_pragma_header;
34
+
35
static struct active_request_slot *active_queue_head;
36
37
size_t fread_buffer(void *ptr, size_t eltsize, size_t nmemb, void *buffer_)
@@ -276,6 +279,8 @@ void http_init(struct remote *remote)
279
char *low_speed_limit;
280
char *low_speed_time;
281
282
+ http_is_verbose = 0;
283
+
284
git_config(http_options, NULL);
285
286
curl_global_init(CURL_GLOBAL_ALL);
@@ -284,6 +289,7 @@ void http_init(struct remote *remote)
289
curl_http_proxy = xstrdup(remote->http_proxy);
290
291
pragma_header = curl_slist_append(pragma_header, "Pragma: no-cache");
292
+ no_pragma_header = curl_slist_append(no_pragma_header, "Pragma:");
293
294
#ifdef USE_CURL_MULTI
295
{
@@ -366,6 +372,9 @@ void http_cleanup(void)
372
curl_slist_free_all(pragma_header);
373
pragma_header = NULL;
374
375
+ curl_slist_free_all(no_pragma_header);
376
+ no_pragma_header = NULL;
377
+
378
if (curl_http_proxy) {
379
free((void *)curl_http_proxy);
380
curl_http_proxy = NULL;
http.h
+5
@@ -88,11 +88,16 @@ extern void add_fill_function(void *data, int (*fill)(void *));
88
extern void step_active_slots(void);
89
#endif
90
91
+extern struct curl_slist *no_pragma_header;
92
+
93
+#define RANGE_HEADER_SIZE 30
94
+
95
extern void http_init(struct remote *remote);
96
extern void http_cleanup(void);
97
98
extern int data_received;
99
extern int active_requests;
100
+extern int http_is_verbose;
101
102
extern char curl_errorstr[CURL_ERROR_SIZE];
103