@@ -318,120 +318,115 @@ static void read_branches_file(struct remote *remote)
318318static int handle_config (const char * key , const char * value , void * cb )
319319{
320320 const char * name ;
321+ int namelen ;
321322 const char * subkey ;
322323 struct remote * remote ;
323324 struct branch * branch ;
324- if (starts_with (key , "branch." )) {
325- name = key + 7 ;
326- subkey = strrchr (name , '.' );
327- if (!subkey )
325+ if (parse_config_key (key , "branch" , & name , & namelen , & subkey ) >= 0 ) {
326+ if (!name )
328327 return 0 ;
329- branch = make_branch (name , subkey - name );
330- if (!strcmp (subkey , ". remote" )) {
328+ branch = make_branch (name , namelen );
329+ if (!strcmp (subkey , "remote" )) {
331330 return git_config_string (& branch -> remote_name , key , value );
332- } else if (!strcmp (subkey , ". pushremote" )) {
331+ } else if (!strcmp (subkey , "pushremote" )) {
333332 return git_config_string (& branch -> pushremote_name , key , value );
334- } else if (!strcmp (subkey , ". merge" )) {
333+ } else if (!strcmp (subkey , "merge" )) {
335334 if (!value )
336335 return config_error_nonbool (key );
337336 add_merge (branch , xstrdup (value ));
338337 }
339338 return 0 ;
340339 }
341- if (starts_with (key , "url." ) ) {
340+ if (parse_config_key (key , "url" , & name , & namelen , & subkey ) >= 0 ) {
342341 struct rewrite * rewrite ;
343- name = key + 4 ;
344- subkey = strrchr (name , '.' );
345- if (!subkey )
342+ if (!name )
346343 return 0 ;
347- if (!strcmp (subkey , ". insteadof" )) {
348- rewrite = make_rewrite (& rewrites , name , subkey - name );
344+ if (!strcmp (subkey , "insteadof" )) {
345+ rewrite = make_rewrite (& rewrites , name , namelen );
349346 if (!value )
350347 return config_error_nonbool (key );
351348 add_instead_of (rewrite , xstrdup (value ));
352- } else if (!strcmp (subkey , ". pushinsteadof" )) {
353- rewrite = make_rewrite (& rewrites_push , name , subkey - name );
349+ } else if (!strcmp (subkey , "pushinsteadof" )) {
350+ rewrite = make_rewrite (& rewrites_push , name , namelen );
354351 if (!value )
355352 return config_error_nonbool (key );
356353 add_instead_of (rewrite , xstrdup (value ));
357354 }
358355 }
359356
360- if (! starts_with (key , "remote." ) )
357+ if (parse_config_key (key , "remote" , & name , & namelen , & subkey ) < 0 )
361358 return 0 ;
362- name = key + 7 ;
363359
364360 /* Handle remote.* variables */
365- if (!strcmp (name , "pushdefault" ))
361+ if (!name && ! strcmp (subkey , "pushdefault" ))
366362 return git_config_string (& pushremote_name , key , value );
367363
364+ if (!name )
365+ return 0 ;
368366 /* Handle remote.<name>.* variables */
369367 if (* name == '/' ) {
370368 warning ("Config remote shorthand cannot begin with '/': %s" ,
371369 name );
372370 return 0 ;
373371 }
374- subkey = strrchr (name , '.' );
375- if (!subkey )
376- return 0 ;
377- remote = make_remote (name , subkey - name );
372+ remote = make_remote (name , namelen );
378373 remote -> origin = REMOTE_CONFIG ;
379- if (!strcmp (subkey , ". mirror" ))
374+ if (!strcmp (subkey , "mirror" ))
380375 remote -> mirror = git_config_bool (key , value );
381- else if (!strcmp (subkey , ". skipdefaultupdate" ))
376+ else if (!strcmp (subkey , "skipdefaultupdate" ))
382377 remote -> skip_default_update = git_config_bool (key , value );
383- else if (!strcmp (subkey , ". skipfetchall" ))
378+ else if (!strcmp (subkey , "skipfetchall" ))
384379 remote -> skip_default_update = git_config_bool (key , value );
385- else if (!strcmp (subkey , ". prune" ))
380+ else if (!strcmp (subkey , "prune" ))
386381 remote -> prune = git_config_bool (key , value );
387- else if (!strcmp (subkey , ". url" )) {
382+ else if (!strcmp (subkey , "url" )) {
388383 const char * v ;
389384 if (git_config_string (& v , key , value ))
390385 return -1 ;
391386 add_url (remote , v );
392- } else if (!strcmp (subkey , ". pushurl" )) {
387+ } else if (!strcmp (subkey , "pushurl" )) {
393388 const char * v ;
394389 if (git_config_string (& v , key , value ))
395390 return -1 ;
396391 add_pushurl (remote , v );
397- } else if (!strcmp (subkey , ". push" )) {
392+ } else if (!strcmp (subkey , "push" )) {
398393 const char * v ;
399394 if (git_config_string (& v , key , value ))
400395 return -1 ;
401396 add_push_refspec (remote , v );
402- } else if (!strcmp (subkey , ". fetch" )) {
397+ } else if (!strcmp (subkey , "fetch" )) {
403398 const char * v ;
404399 if (git_config_string (& v , key , value ))
405400 return -1 ;
406401 add_fetch_refspec (remote , v );
407- } else if (!strcmp (subkey , ". receivepack" )) {
402+ } else if (!strcmp (subkey , "receivepack" )) {
408403 const char * v ;
409404 if (git_config_string (& v , key , value ))
410405 return -1 ;
411406 if (!remote -> receivepack )
412407 remote -> receivepack = v ;
413408 else
414409 error ("more than one receivepack given, using the first" );
415- } else if (!strcmp (subkey , ". uploadpack" )) {
410+ } else if (!strcmp (subkey , "uploadpack" )) {
416411 const char * v ;
417412 if (git_config_string (& v , key , value ))
418413 return -1 ;
419414 if (!remote -> uploadpack )
420415 remote -> uploadpack = v ;
421416 else
422417 error ("more than one uploadpack given, using the first" );
423- } else if (!strcmp (subkey , ". tagopt" )) {
418+ } else if (!strcmp (subkey , "tagopt" )) {
424419 if (!strcmp (value , "--no-tags" ))
425420 remote -> fetch_tags = -1 ;
426421 else if (!strcmp (value , "--tags" ))
427422 remote -> fetch_tags = 2 ;
428- } else if (!strcmp (subkey , ". proxy" )) {
423+ } else if (!strcmp (subkey , "proxy" )) {
429424 return git_config_string ((const char * * )& remote -> http_proxy ,
430425 key , value );
431- } else if (!strcmp (subkey , ". proxyauthmethod" )) {
426+ } else if (!strcmp (subkey , "proxyauthmethod" )) {
432427 return git_config_string ((const char * * )& remote -> http_proxy_authmethod ,
433428 key , value );
434- } else if (!strcmp (subkey , ". vcs" )) {
429+ } else if (!strcmp (subkey , "vcs" )) {
435430 return git_config_string (& remote -> foreign_vcs , key , value );
436431 }
437432 return 0 ;
@@ -718,18 +713,9 @@ struct remote *pushremote_get(const char *name)
718713 return remote_get_1 (name , pushremote_for_branch );
719714}
720715
721- int remote_is_configured (const char * name )
716+ int remote_is_configured (struct remote * remote )
722717{
723- struct remotes_hash_key lookup ;
724- struct hashmap_entry lookup_entry ;
725- read_config ();
726-
727- init_remotes_hash ();
728- lookup .str = name ;
729- lookup .len = strlen (name );
730- hashmap_entry_init (& lookup_entry , memhash (name , lookup .len ));
731-
732- return hashmap_get (& remotes_hash , & lookup_entry , & lookup ) != NULL ;
718+ return remote && remote -> origin ;
733719}
734720
735721int for_each_remote (each_remote_fn fn , void * priv )
0 commit comments