1010
1111static struct remote * remote ;
1212static const char * url ;
13- static struct walker * walker ;
1413
1514struct options {
1615 int verbosity ;
@@ -22,12 +21,6 @@ struct options {
2221};
2322static struct options options ;
2423
25- static void init_walker (void )
26- {
27- if (!walker )
28- walker = get_http_walker (url , remote );
29- }
30-
3124static int set_option (const char * name , const char * value )
3225{
3326 if (!strcmp (name , "verbosity" )) {
@@ -119,7 +112,6 @@ static struct discovery* discover_refs(const char *service)
119112 }
120113 refs_url = strbuf_detach (& buffer , NULL );
121114
122- init_walker ();
123115 http_ret = http_get_strbuf (refs_url , & buffer , HTTP_NO_CACHE );
124116
125117 /* try again with "plain" url (no ? or & appended) */
@@ -250,9 +242,8 @@ static struct ref *parse_info_refs(struct discovery *heads)
250242 i ++ ;
251243 }
252244
253- init_walker ();
254245 ref = alloc_ref ("HEAD" );
255- if (!walker -> fetch_ref ( walker , ref ) &&
246+ if (!http_fetch_ref ( url , ref ) &&
256247 !resolve_remote_symref (ref , refs )) {
257248 ref -> next = refs ;
258249 refs = ref ;
@@ -502,7 +493,6 @@ static int rpc_service(struct rpc_state *rpc, struct discovery *heads)
502493 struct child_process client ;
503494 int err = 0 ;
504495
505- init_walker ();
506496 memset (& client , 0 , sizeof (client ));
507497 client .in = -1 ;
508498 client .out = -1 ;
@@ -554,6 +544,7 @@ static int rpc_service(struct rpc_state *rpc, struct discovery *heads)
554544
555545static int fetch_dumb (int nr_heads , struct ref * * to_fetch )
556546{
547+ struct walker * walker ;
557548 char * * targets = xmalloc (nr_heads * sizeof (char * ));
558549 int ret , i ;
559550
@@ -562,13 +553,14 @@ static int fetch_dumb(int nr_heads, struct ref **to_fetch)
562553 for (i = 0 ; i < nr_heads ; i ++ )
563554 targets [i ] = xstrdup (sha1_to_hex (to_fetch [i ]-> old_sha1 ));
564555
565- init_walker ( );
556+ walker = get_http_walker ( url );
566557 walker -> get_all = 1 ;
567558 walker -> get_tree = 1 ;
568559 walker -> get_history = 1 ;
569560 walker -> get_verbosely = options .verbosity >= 3 ;
570561 walker -> get_recover = 0 ;
571562 ret = walker_fetch (walker , nr_heads , targets , NULL , NULL );
563+ walker_free (walker );
572564
573565 for (i = 0 ; i < nr_heads ; i ++ )
574566 free (targets [i ]);
@@ -811,6 +803,8 @@ int main(int argc, const char **argv)
811803 url = remote -> url [0 ];
812804 }
813805
806+ http_init (remote );
807+
814808 do {
815809 if (strbuf_getline (& buf , stdin , '\n' ) == EOF )
816810 break ;
@@ -856,5 +850,8 @@ int main(int argc, const char **argv)
856850 }
857851 strbuf_reset (& buf );
858852 } while (1 );
853+
854+ http_cleanup ();
855+
859856 return 0 ;
860857}
0 commit comments