git@vger.kernel.org mailing list mirror (one of many)
 help / color / mirror / code / Atom feed
* [PATCH 13/23] http*: move common variables and macros to http.[ch]
@ 2009-06-05 16:04 Tay Ray Chuan
  0 siblings, 0 replies; 24+ messages in thread
From: Tay Ray Chuan @ 2009-06-05 16:04 UTC (permalink / raw)
  To: Git Mailing List; +Cc: Junio C Hamano, Johannes Schindelin, Mike Hommey

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>
---
 http-push.c   |    8 +-------
 http-walker.c |   18 +++++-------------
 http.c        |    9 +++++++++
 http.h        |    5 +++++
 4 files changed, 20 insertions(+), 20 deletions(-)

diff --git a/http-push.c b/http-push.c
index a6ca2ac..b01db75 100644
--- a/http-push.c
+++ b/http-push.c
@@ -27,7 +27,6 @@ enum XML_Status {
 #endif

 #define PREV_BUF_SIZE 4096
-#define RANGE_HEADER_SIZE 30

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

-static struct curl_slist *no_pragma_header;
-
 static int push_verbosely;
 static int push_all = MATCH_REFS_NONE;
 static int force_all;
@@ -2251,6 +2248,7 @@ int main(int argc, char **argv)
 			}
 			if (!strcmp(arg, "--verbose")) {
 				push_verbosely = 1;
+				http_is_verbose = 1;
 				continue;
 			}
 			if (!strcmp(arg, "-d")) {
@@ -2300,8 +2298,6 @@ int main(int argc, char **argv)
 	remote->url[remote->url_nr++] = repo->url;
 	http_init(remote);

-	no_pragma_header = curl_slist_append(no_pragma_header, "Pragma:");
-
 	if (repo->url && repo->url[strlen(repo->url)-1] != '/') {
 		rewritten_url = xmalloc(strlen(repo->url)+2);
 		strcpy(rewritten_url, repo->url);
@@ -2504,8 +2500,6 @@ int main(int argc, char **argv)
 		unlock_remote(info_ref_lock);
 	free(repo);

-	curl_slist_free_all(no_pragma_header);
-
 	http_cleanup();

 	request = request_queue_head;
diff --git a/http-walker.c b/http-walker.c
index d6cc622..032a7be 100644
--- a/http-walker.c
+++ b/http-walker.c
@@ -5,7 +5,6 @@
 #include "http.h"

 #define PREV_BUF_SIZE 4096
-#define RANGE_HEADER_SIZE 30

 struct alt_base
 {
@@ -57,7 +56,6 @@ struct walker_data {
 	const char *url;
 	int got_alternates;
 	struct alt_base *alt;
-	struct curl_slist *no_pragma_header;
 };

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

 	snprintf(prevfile, sizeof(prevfile), "%s.prev", obj_req->filename);
 	unlink_or_warn(prevfile);
@@ -205,7 +202,7 @@ static void start_object_request(struct walker *walker,
 	curl_easy_setopt(slot->curl, CURLOPT_WRITEFUNCTION, fwrite_sha1_file);
 	curl_easy_setopt(slot->curl, CURLOPT_ERRORBUFFER, obj_req->errorstr);
 	curl_easy_setopt(slot->curl, CURLOPT_URL, url);
-	curl_easy_setopt(slot->curl, CURLOPT_HTTPHEADER, data->no_pragma_header);
+	curl_easy_setopt(slot->curl, CURLOPT_HTTPHEADER, no_pragma_header);

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

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

 	FILE *indexfile;
 	struct active_request_slot *slot;
@@ -430,7 +428,7 @@ static int fetch_index(struct walker *walker, struct alt_base *repo, unsigned ch
 	curl_easy_setopt(slot->curl, CURLOPT_FILE, indexfile);
 	curl_easy_setopt(slot->curl, CURLOPT_WRITEFUNCTION, fwrite);
 	curl_easy_setopt(slot->curl, CURLOPT_URL, url);
-	curl_easy_setopt(slot->curl, CURLOPT_HTTPHEADER, data->no_pragma_header);
+	curl_easy_setopt(slot->curl, CURLOPT_HTTPHEADER, no_pragma_header);
 	slot->local = indexfile;

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

 	struct active_request_slot *slot;
 	struct slot_results results;
@@ -802,7 +799,7 @@ static int fetch_pack(struct walker *walker, struct alt_base *repo, unsigned cha
 	curl_easy_setopt(slot->curl, CURLOPT_FILE, packfile);
 	curl_easy_setopt(slot->curl, CURLOPT_WRITEFUNCTION, fwrite);
 	curl_easy_setopt(slot->curl, CURLOPT_URL, url);
-	curl_easy_setopt(slot->curl, CURLOPT_HTTPHEADER, data->no_pragma_header);
+	curl_easy_setopt(slot->curl, CURLOPT_HTTPHEADER, no_pragma_header);
 	slot->local = packfile;

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

 static void cleanup(struct walker *walker)
 {
-	struct walker_data *data = walker->data;
 	http_cleanup();
-
-	curl_slist_free_all(data->no_pragma_header);
 }

 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)

 	http_init(remote);

-	data->no_pragma_header = curl_slist_append(NULL, "Pragma:");
-
 	data->alt = xmalloc(sizeof(*data->alt));
 	data->alt->base = xmalloc(strlen(url) + 1);
 	strcpy(data->alt->base, url);
diff --git a/http.c b/http.c
index 2e3d649..3ca60bb 100644
--- a/http.c
+++ b/http.c
@@ -2,6 +2,7 @@

 int data_received;
 int active_requests;
+int http_is_verbose;

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

 static struct curl_slist *pragma_header;

+struct curl_slist *no_pragma_header;
+
 static struct active_request_slot *active_queue_head;

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

+	http_is_verbose = 0;
+
 	git_config(http_options, NULL);

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

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

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

+	curl_slist_free_all(no_pragma_header);
+	no_pragma_header = NULL;
+
 	if (curl_http_proxy) {
 		free((void *)curl_http_proxy);
 		curl_http_proxy = NULL;
diff --git a/http.h b/http.h
index 26abebe..1ef7dc1 100644
--- a/http.h
+++ b/http.h
@@ -88,11 +88,16 @@ extern void add_fill_function(void *data, int (*fill)(void *));
 extern void step_active_slots(void);
 #endif

+extern struct curl_slist *no_pragma_header;
+
+#define RANGE_HEADER_SIZE 30
+
 extern void http_init(struct remote *remote);
 extern void http_cleanup(void);

 extern int data_received;
 extern int active_requests;
+extern int http_is_verbose;

 extern char curl_errorstr[CURL_ERROR_SIZE];

--
1.6.3.1

^ permalink raw reply related	[flat|nested] 24+ messages in thread

end of thread, other threads:[~2009-06-06  8:51 UTC | newest]

Thread overview: 24+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
     [not found] <cover.1244277116.git.rctay89@gmail.com>
2009-06-06  8:43 ` [PATCH 01/23] t5540-http-push: test fetching of loose objects Tay Ray Chuan
2009-06-06  8:43 ` [PATCH 02/23] t5540-http-push: test fetching of packed objects Tay Ray Chuan
2009-06-06  8:43 ` [PATCH 03/23] http*: cleanup slot->local after fclose Tay Ray Chuan
2009-06-06  8:43 ` [PATCH 04/23] http-push: send out fetch requests on queue Tay Ray Chuan
2009-06-06  8:43 ` [PATCH 05/23] http-push: fix missing "#ifdef USE_CURL_MULTI" around "is_running_queue" Tay Ray Chuan
2009-06-06  8:43 ` [PATCH 06/23] t5550-http-fetch: test fetching of packed objects Tay Ray Chuan
2009-06-06  8:43 ` [PATCH 07/23] http-push, http-walker: style fixes Tay Ray Chuan
2009-06-06  8:43 ` [PATCH 08/23] http-walker: verify remote packs Tay Ray Chuan
2009-06-06  8:43 ` [PATCH 09/23] http*: copy string returned by sha1_to_hex Tay Ray Chuan
2009-06-06  8:43 ` [PATCH 10/23] http-push: do not SEGV after fetching a bad pack idx file Tay Ray Chuan
2009-06-06  8:43 ` [PATCH 11/23] Don't expect verify_pack() callers to set pack_size Tay Ray Chuan
2009-06-06  8:43 ` [PATCH 12/23] transport.c::get_refs_via_curl(): do not leak refs_url Tay Ray Chuan
2009-06-06  8:43 ` [PATCH 13/23] http*: move common variables and macros to http.[ch] Tay Ray Chuan
2009-06-06  8:43 ` [PATCH 14/23] http: create function end_url_with_slash Tay Ray Chuan
2009-06-06  8:43 ` [PATCH 15/23] http.c: new functions for the http API Tay Ray Chuan
2009-06-06  8:43 ` [PATCH 16/23] transport.c::get_refs_via_curl(): use the new " Tay Ray Chuan
2009-06-06  8:43 ` [PATCH 17/23] http.c::http_fetch_ref(): " Tay Ray Chuan
2009-06-06  8:43 ` [PATCH 18/23] http-push.c::remote_exists(): " Tay Ray Chuan
2009-06-06  8:43 ` [PATCH 19/23] http-push.c::fetch_symref(): " Tay Ray Chuan
2009-06-06  8:43 ` [PATCH 20/23] http*: add http_get_info_packs Tay Ray Chuan
2009-06-06  8:44 ` [PATCH 21/23] http: use new http API in fetch_index() Tay Ray Chuan
2009-06-06  8:44 ` [PATCH 22/23] http*: add helper methods for fetching packs Tay Ray Chuan
2009-06-06  8:44 ` [PATCH 23/23] http*: add helper methods for fetching objects (loose) Tay Ray Chuan
2009-06-05 16:04 [PATCH 13/23] http*: move common variables and macros to http.[ch] Tay Ray Chuan

Code repositories for project(s) associated with this public inbox

	https://80x24.org/mirrors/git.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).