http-push.c::fetch_symref(): use the new http API
PATCH 13/17 http-push.c::fetch_symref(): use the new http API
From: Mike Hommey <[email protected]>
Subject: [WIP Patch 09/12] Use the new http API in fetch_symref()
Date: Sun, 18 Jan 2009 09:04:34 +0100
--- http-push.c | 20 +++----------------- 1 files changed, 3 insertions(+), 17 deletions(-)
http-push.c +3 -17
@@ -2024,27 +2024,13 @@ static void fetch_symref(const char *path, char **symref, unsigned char *sha1) {char *url;struct strbuf buffer =STRBUF_INIT ; -struct active_request_slot *slot; -struct slot_results results; url =xmalloc (strlen (repo->url) +strlen (path) +1 );sprintf (url,"%s%s" , repo->url, path); - slot =get_active_slot (); - slot->results = &results; -curl_easy_setopt (slot->curl,CURLOPT_FILE , &buffer); -curl_easy_setopt (slot->curl,CURLOPT_WRITEFUNCTION , fwrite_buffer); -curl_easy_setopt (slot->curl,CURLOPT_HTTPHEADER ,NULL ); -curl_easy_setopt (slot->curl,CURLOPT_URL , url); -if (start_active_slot (slot)) { -run_active_slot (slot); -if (results.curl_result !=CURLE_OK ) { -die ("Couldn't get %s for remote symref\n%s" , - url, curl_errorstr); - } - }else { -die ("Unable to start remote symref request" ); - } +if (http_get_strbuf (url, &buffer,0 ) !=HTTP_OK ) +die ("Couldn't get %s for remote symref\n%s" , url, + curl_errorstr);free (url);free (*symref);
--
1.6.3.1
PATCH 14/17 http*: add http_get_info_packs
http-push.c and http-walker.c no longer have to use fetch_index or setup_index; they simply need to use http_get_info_packs, a new http method, in their fetch_indices implementations.
Move fetch_index() and rename to fetch_pack_index() in http.c; this method is not meant to be used outside of http.c. It invokes end_url_with_slash with base_url; apart from that change, the code is identical.
Move setup_index() and rename to fetch_and_setup_pack_index() in http.c; this method is not meant to be used outside of http.c.
--- http-push.c | 174 +----------------------------------------------------- http-walker.c | 180 ++------------------------------------------------------ http.c | 163 +++++++++++++++++++++++++++++++++++++++++++++++++++ http.h | 4 + 4 files changed, 178 insertions(+), 343 deletions(-)
http-push.c +4 -170
@@ -950,182 +950,16 @@ static int add_send_request(struct object *obj, struct remote_lock *lock)return 1 ; } -static int fetch_index (unsigned char *sha1) -{ -int ret =0 ; -char *hex =xstrdup (sha1_to_hex (sha1)); -char *filename; -char *url; -char tmpfile[PATH_MAX ]; -long prev_posn =0 ; -char range[RANGE_HEADER_SIZE ]; -struct curl_slist *range_header =NULL ; - -FILE *indexfile; -struct active_request_slot *slot; -struct slot_results results; - -/* Don't use the index if the pack isn't there */ - url =xmalloc (strlen (repo->url) +64 ); -sprintf (url,"%sobjects/pack/pack-%s.pack" , repo->url, hex); - slot =get_active_slot (); - slot->results = &results; -curl_easy_setopt (slot->curl,CURLOPT_URL , url); -curl_easy_setopt (slot->curl,CURLOPT_NOBODY ,1 ); -if (start_active_slot (slot)) { -run_active_slot (slot); -if (results.curl_result !=CURLE_OK ) { - ret =error ("Unable to verify pack %s is available" , - hex); - goto cleanup_pack; - } - }else { - ret =error ("Unable to start request" ); - goto cleanup_pack; - } - -if (has_pack_index (sha1)) { - ret =0 ; - goto cleanup_pack; - } - -if (push_verbosely) -fprintf (stderr,"Getting index for pack %s\n" , hex); - -sprintf (url,"%sobjects/pack/pack-%s.idx" , repo->url, hex); - - filename =sha1_pack_index_name (sha1); -snprintf (tmpfile,sizeof (tmpfile),"%s.temp" , filename); - indexfile =fopen (tmpfile,"a" ); -if (!indexfile) { - ret =error ("Unable to open local file %s for pack index" , - tmpfile); - goto cleanup_pack; - } - - slot =get_active_slot (); - slot->results = &results; -curl_easy_setopt (slot->curl,CURLOPT_NOBODY ,0 ); -curl_easy_setopt (slot->curl,CURLOPT_HTTPGET ,1 ); -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 , no_pragma_header); - slot->local = indexfile; - -/* -* If there is data present from a previous transfer attempt, -* resume where it left off -*/ - prev_posn =ftell (indexfile); -if (prev_posn>0 ) { -if (push_verbosely) -fprintf (stderr, -"Resuming fetch of index for pack %s at byte %ld\n" , - hex, prev_posn); -sprintf (range,"Range: bytes=%ld-" , prev_posn); - range_header =curl_slist_append (range_header, range); -curl_easy_setopt (slot->curl,CURLOPT_HTTPHEADER , range_header); - } - -if (start_active_slot (slot)) { -run_active_slot (slot); -if (results.curl_result !=CURLE_OK ) { - ret =error ("Unable to get pack index %s\n%s" , url, - curl_errorstr); - goto cleanup_index; - } - }else { - ret =error ("Unable to start request" ); - goto cleanup_index; - } - - ret =move_temp_to_file (tmpfile, filename); - -cleanup_index: -fclose (indexfile); -cleanup_pack: -free (url); -free (hex); -return ret; -} - -static int setup_index (unsigned char *sha1) -{ -struct packed_git *new_pack; - -if (fetch_index (sha1)) -return -1 ; - - new_pack =parse_pack_index (sha1); -if (!new_pack) -return -1 ;/* parse_pack_index() already issued error message */ - new_pack->next = repo->packs; - repo->packs = new_pack; -return 0 ; -} -static int fetch_indices (void ) { -unsigned char sha1[20 ]; -char *url; -struct strbuf buffer =STRBUF_INIT ; -char *data; -int i =0 ; - -struct active_request_slot *slot; -struct slot_results results; -if (push_verbosely)fprintf (stderr,"Getting pack list\n" ); - url =xmalloc (strlen (repo->url) +20 ); -sprintf (url,"%sobjects/info/packs" , repo->url); - - slot =get_active_slot (); - slot->results = &results; -curl_easy_setopt (slot->curl,CURLOPT_FILE , &buffer); -curl_easy_setopt (slot->curl,CURLOPT_WRITEFUNCTION , fwrite_buffer); -curl_easy_setopt (slot->curl,CURLOPT_URL , url); -curl_easy_setopt (slot->curl,CURLOPT_HTTPHEADER ,NULL ); -if (start_active_slot (slot)) { -run_active_slot (slot); -if (results.curl_result !=CURLE_OK ) { -strbuf_release (&buffer); -free (url); -if (results.http_code ==404 ) -return 0 ; -else -return error ("%s" , curl_errorstr); - } - }else { -strbuf_release (&buffer); -free (url); -return error ("Unable to start request" ); - } -free (url); - - data = buffer.buf; -while (i < buffer.len) { -switch (data[i]) { -case 'P' : - i++; -if (i +52 < buffer.len && - !prefixcmp (data + i," pack-" ) && - !prefixcmp (data + i +46 ,".pack\n" )) { -get_sha1_hex (data + i +6 , sha1); -setup_index (sha1); - i +=51 ; -break ; - } -default : -while (data[i] !='\n' ) - i++; - } - i++; - } +if (http_get_info_packs (repo->url, &repo->packs) ==HTTP_OK ) +return 0 ; +else +return -1 ; -strbuf_release (&buffer);return 0 ; }
http-walker.c +7 -173
203 lines not on this page · raw message
http.c +163 -0
166 lines not on this page · raw message
http.h +4 -0
@@ -146,4 +146,8 @@ int http_error(const char *url, int ret);extern int http_fetch_ref (const char *base,struct ref *ref); +/* Helpers for fetching packs */ +extern int http_get_info_packs (const char *base_url, +struct packed_git **packs_head); +#endif /* HTTP_H */
--
1.6.3.1
Re: [PATCH 14/17] http*: add http_get_info_packs
Quoted 3 lines · Tay Ray Chuan
http-push.c +0
-0@@ -950,182 +950,16 @@ static int add_send_request(struct object *obj, struct remote_lock *lock)
[...]
Quoted 2 lines
static int
fetch_indices(void)
{
[...]
Quoted 8 lines
http-push.c +0
-8-if (results.curl_result !=CURLE_OK ) { -strbuf_release (&buffer); -free (url); -if (results.http_code ==404 ) -return 0 ; -else -return error ("%s" , curl_errorstr); - }
[...]
http-push.c static int add_send_request(struct object *obj, struct remote_lock *lock) · line 961
Quoted 4 lines
http-push.c +4
-0+if (http_get_info_packs (repo->url, &repo->packs) ==HTTP_OK ) +return 0 ; +else +return -1 ;
fetch_indices() used to return 0 if the pack info was missing. Now it returns an error. I also think we could get rid of repo->has_info_packs. This could easily be handled within fetch_indices().
Clemens
Re: [PATCH 14/17] http*: add http_get_info_packs
Hi,
Quoted 2 lines · Clemens Buchacher
fetch_indices()used to return 0 if the pack info was missing. Now it returns an error.
Thanks for noticing this.
Quoted 2 lines
I also think we could get rid of
repo->has_info_packs. This could easily be handled withinfetch_indices().
Indeed, sending out somewhat redundant HEAD requests is done pretty often; a separate patch/patch series should handle those.
Signature · 2 lines
Cheers, Ray Chuan