Skip to content

Commit e917674

Browse files
rctaygitster
authored andcommitted
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 <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent df00521 commit e917674

File tree

4 files changed

+20
-20
lines changed

4 files changed

+20
-20
lines changed

http-push.c

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,6 @@ enum XML_Status {
2727
#endif
2828

2929
#define PREV_BUF_SIZE 4096
30-
#define RANGE_HEADER_SIZE 30
3130

3231
/* DAV methods */
3332
#define DAV_LOCK "LOCK"
@@ -76,8 +75,6 @@ static int pushing;
7675
static int aborted;
7776
static signed char remote_dir_exists[256];
7877

79-
static struct curl_slist *no_pragma_header;
80-
8178
static int push_verbosely;
8279
static int push_all = MATCH_REFS_NONE;
8380
static int force_all;
@@ -2250,6 +2247,7 @@ int main(int argc, char **argv)
22502247
}
22512248
if (!strcmp(arg, "--verbose")) {
22522249
push_verbosely = 1;
2250+
http_is_verbose = 1;
22532251
continue;
22542252
}
22552253
if (!strcmp(arg, "-d")) {
@@ -2299,8 +2297,6 @@ int main(int argc, char **argv)
22992297
remote->url[remote->url_nr++] = repo->url;
23002298
http_init(remote);
23012299

2302-
no_pragma_header = curl_slist_append(no_pragma_header, "Pragma:");
2303-
23042300
if (repo->url && repo->url[strlen(repo->url)-1] != '/') {
23052301
rewritten_url = xmalloc(strlen(repo->url)+2);
23062302
strcpy(rewritten_url, repo->url);
@@ -2503,8 +2499,6 @@ int main(int argc, char **argv)
25032499
unlock_remote(info_ref_lock);
25042500
free(repo);
25052501

2506-
curl_slist_free_all(no_pragma_header);
2507-
25082502
http_cleanup();
25092503

25102504
request = request_queue_head;

http-walker.c

Lines changed: 5 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55
#include "http.h"
66

77
#define PREV_BUF_SIZE 4096
8-
#define RANGE_HEADER_SIZE 30
98

109
struct alt_base
1110
{
@@ -57,7 +56,6 @@ struct walker_data {
5756
const char *url;
5857
int got_alternates;
5958
struct alt_base *alt;
60-
struct curl_slist *no_pragma_header;
6159
};
6260

6361
static struct object_request *object_queue_head;
@@ -108,7 +106,6 @@ static void start_object_request(struct walker *walker,
108106
char range[RANGE_HEADER_SIZE];
109107
struct curl_slist *range_header = NULL;
110108
struct active_request_slot *slot;
111-
struct walker_data *data = walker->data;
112109

113110
snprintf(prevfile, sizeof(prevfile), "%s.prev", obj_req->filename);
114111
unlink_or_warn(prevfile);
@@ -205,7 +202,7 @@ static void start_object_request(struct walker *walker,
205202
curl_easy_setopt(slot->curl, CURLOPT_WRITEFUNCTION, fwrite_sha1_file);
206203
curl_easy_setopt(slot->curl, CURLOPT_ERRORBUFFER, obj_req->errorstr);
207204
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);
209206

210207
/*
211208
* If we have successfully processed data from a previous fetch
@@ -354,6 +351,8 @@ static void prefetch(struct walker *walker, unsigned char *sha1)
354351
newreq->slot = NULL;
355352
newreq->next = NULL;
356353

354+
http_is_verbose = walker->get_verbosely;
355+
357356
if (object_queue_head == NULL) {
358357
object_queue_head = newreq;
359358
} else {
@@ -379,7 +378,6 @@ static int fetch_index(struct walker *walker, struct alt_base *repo, unsigned ch
379378
long prev_posn = 0;
380379
char range[RANGE_HEADER_SIZE];
381380
struct curl_slist *range_header = NULL;
382-
struct walker_data *data = walker->data;
383381

384382
FILE *indexfile;
385383
struct active_request_slot *slot;
@@ -430,7 +428,7 @@ static int fetch_index(struct walker *walker, struct alt_base *repo, unsigned ch
430428
curl_easy_setopt(slot->curl, CURLOPT_FILE, indexfile);
431429
curl_easy_setopt(slot->curl, CURLOPT_WRITEFUNCTION, fwrite);
432430
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);
434432
slot->local = indexfile;
435433

436434
/*
@@ -768,7 +766,6 @@ static int fetch_pack(struct walker *walker, struct alt_base *repo, unsigned cha
768766
long prev_posn = 0;
769767
char range[RANGE_HEADER_SIZE];
770768
struct curl_slist *range_header = NULL;
771-
struct walker_data *data = walker->data;
772769

773770
struct active_request_slot *slot;
774771
struct slot_results results;
@@ -802,7 +799,7 @@ static int fetch_pack(struct walker *walker, struct alt_base *repo, unsigned cha
802799
curl_easy_setopt(slot->curl, CURLOPT_FILE, packfile);
803800
curl_easy_setopt(slot->curl, CURLOPT_WRITEFUNCTION, fwrite);
804801
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);
806803
slot->local = packfile;
807804

808805
/*
@@ -948,10 +945,7 @@ static int fetch_ref(struct walker *walker, struct ref *ref)
948945

949946
static void cleanup(struct walker *walker)
950947
{
951-
struct walker_data *data = walker->data;
952948
http_cleanup();
953-
954-
curl_slist_free_all(data->no_pragma_header);
955949
}
956950

957951
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)
962956

963957
http_init(remote);
964958

965-
data->no_pragma_header = curl_slist_append(NULL, "Pragma:");
966-
967959
data->alt = xmalloc(sizeof(*data->alt));
968960
data->alt->base = xmalloc(strlen(url) + 1);
969961
strcpy(data->alt->base, url);

http.c

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
int data_received;
44
int active_requests;
5+
int http_is_verbose;
56

67
#ifdef USE_CURL_MULTI
78
static int max_requests = -1;
@@ -29,6 +30,8 @@ static char *user_name, *user_pass;
2930

3031
static struct curl_slist *pragma_header;
3132

33+
struct curl_slist *no_pragma_header;
34+
3235
static struct active_request_slot *active_queue_head;
3336

3437
size_t fread_buffer(void *ptr, size_t eltsize, size_t nmemb, void *buffer_)
@@ -276,6 +279,8 @@ void http_init(struct remote *remote)
276279
char *low_speed_limit;
277280
char *low_speed_time;
278281

282+
http_is_verbose = 0;
283+
279284
git_config(http_options, NULL);
280285

281286
curl_global_init(CURL_GLOBAL_ALL);
@@ -284,6 +289,7 @@ void http_init(struct remote *remote)
284289
curl_http_proxy = xstrdup(remote->http_proxy);
285290

286291
pragma_header = curl_slist_append(pragma_header, "Pragma: no-cache");
292+
no_pragma_header = curl_slist_append(no_pragma_header, "Pragma:");
287293

288294
#ifdef USE_CURL_MULTI
289295
{
@@ -366,6 +372,9 @@ void http_cleanup(void)
366372
curl_slist_free_all(pragma_header);
367373
pragma_header = NULL;
368374

375+
curl_slist_free_all(no_pragma_header);
376+
no_pragma_header = NULL;
377+
369378
if (curl_http_proxy) {
370379
free((void *)curl_http_proxy);
371380
curl_http_proxy = NULL;

http.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,11 +88,16 @@ extern void add_fill_function(void *data, int (*fill)(void *));
8888
extern void step_active_slots(void);
8989
#endif
9090

91+
extern struct curl_slist *no_pragma_header;
92+
93+
#define RANGE_HEADER_SIZE 30
94+
9195
extern void http_init(struct remote *remote);
9296
extern void http_cleanup(void);
9397

9498
extern int data_received;
9599
extern int active_requests;
100+
extern int http_is_verbose;
96101

97102
extern char curl_errorstr[CURL_ERROR_SIZE];
98103

0 commit comments

Comments
 (0)