@@ -318,120 +318,115 @@ static void read_branches_file(struct remote *remote)
318
318
static int handle_config (const char * key , const char * value , void * cb )
319
319
{
320
320
const char * name ;
321
+ int namelen ;
321
322
const char * subkey ;
322
323
struct remote * remote ;
323
324
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 )
328
327
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" )) {
331
330
return git_config_string (& branch -> remote_name , key , value );
332
- } else if (!strcmp (subkey , ". pushremote" )) {
331
+ } else if (!strcmp (subkey , "pushremote" )) {
333
332
return git_config_string (& branch -> pushremote_name , key , value );
334
- } else if (!strcmp (subkey , ". merge" )) {
333
+ } else if (!strcmp (subkey , "merge" )) {
335
334
if (!value )
336
335
return config_error_nonbool (key );
337
336
add_merge (branch , xstrdup (value ));
338
337
}
339
338
return 0 ;
340
339
}
341
- if (starts_with (key , "url." ) ) {
340
+ if (parse_config_key (key , "url" , & name , & namelen , & subkey ) >= 0 ) {
342
341
struct rewrite * rewrite ;
343
- name = key + 4 ;
344
- subkey = strrchr (name , '.' );
345
- if (!subkey )
342
+ if (!name )
346
343
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 );
349
346
if (!value )
350
347
return config_error_nonbool (key );
351
348
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 );
354
351
if (!value )
355
352
return config_error_nonbool (key );
356
353
add_instead_of (rewrite , xstrdup (value ));
357
354
}
358
355
}
359
356
360
- if (! starts_with (key , "remote." ) )
357
+ if (parse_config_key (key , "remote" , & name , & namelen , & subkey ) < 0 )
361
358
return 0 ;
362
- name = key + 7 ;
363
359
364
360
/* Handle remote.* variables */
365
- if (!strcmp (name , "pushdefault" ))
361
+ if (!name && ! strcmp (subkey , "pushdefault" ))
366
362
return git_config_string (& pushremote_name , key , value );
367
363
364
+ if (!name )
365
+ return 0 ;
368
366
/* Handle remote.<name>.* variables */
369
367
if (* name == '/' ) {
370
368
warning ("Config remote shorthand cannot begin with '/': %s" ,
371
369
name );
372
370
return 0 ;
373
371
}
374
- subkey = strrchr (name , '.' );
375
- if (!subkey )
376
- return 0 ;
377
- remote = make_remote (name , subkey - name );
372
+ remote = make_remote (name , namelen );
378
373
remote -> origin = REMOTE_CONFIG ;
379
- if (!strcmp (subkey , ". mirror" ))
374
+ if (!strcmp (subkey , "mirror" ))
380
375
remote -> mirror = git_config_bool (key , value );
381
- else if (!strcmp (subkey , ". skipdefaultupdate" ))
376
+ else if (!strcmp (subkey , "skipdefaultupdate" ))
382
377
remote -> skip_default_update = git_config_bool (key , value );
383
- else if (!strcmp (subkey , ". skipfetchall" ))
378
+ else if (!strcmp (subkey , "skipfetchall" ))
384
379
remote -> skip_default_update = git_config_bool (key , value );
385
- else if (!strcmp (subkey , ". prune" ))
380
+ else if (!strcmp (subkey , "prune" ))
386
381
remote -> prune = git_config_bool (key , value );
387
- else if (!strcmp (subkey , ". url" )) {
382
+ else if (!strcmp (subkey , "url" )) {
388
383
const char * v ;
389
384
if (git_config_string (& v , key , value ))
390
385
return -1 ;
391
386
add_url (remote , v );
392
- } else if (!strcmp (subkey , ". pushurl" )) {
387
+ } else if (!strcmp (subkey , "pushurl" )) {
393
388
const char * v ;
394
389
if (git_config_string (& v , key , value ))
395
390
return -1 ;
396
391
add_pushurl (remote , v );
397
- } else if (!strcmp (subkey , ". push" )) {
392
+ } else if (!strcmp (subkey , "push" )) {
398
393
const char * v ;
399
394
if (git_config_string (& v , key , value ))
400
395
return -1 ;
401
396
add_push_refspec (remote , v );
402
- } else if (!strcmp (subkey , ". fetch" )) {
397
+ } else if (!strcmp (subkey , "fetch" )) {
403
398
const char * v ;
404
399
if (git_config_string (& v , key , value ))
405
400
return -1 ;
406
401
add_fetch_refspec (remote , v );
407
- } else if (!strcmp (subkey , ". receivepack" )) {
402
+ } else if (!strcmp (subkey , "receivepack" )) {
408
403
const char * v ;
409
404
if (git_config_string (& v , key , value ))
410
405
return -1 ;
411
406
if (!remote -> receivepack )
412
407
remote -> receivepack = v ;
413
408
else
414
409
error ("more than one receivepack given, using the first" );
415
- } else if (!strcmp (subkey , ". uploadpack" )) {
410
+ } else if (!strcmp (subkey , "uploadpack" )) {
416
411
const char * v ;
417
412
if (git_config_string (& v , key , value ))
418
413
return -1 ;
419
414
if (!remote -> uploadpack )
420
415
remote -> uploadpack = v ;
421
416
else
422
417
error ("more than one uploadpack given, using the first" );
423
- } else if (!strcmp (subkey , ". tagopt" )) {
418
+ } else if (!strcmp (subkey , "tagopt" )) {
424
419
if (!strcmp (value , "--no-tags" ))
425
420
remote -> fetch_tags = -1 ;
426
421
else if (!strcmp (value , "--tags" ))
427
422
remote -> fetch_tags = 2 ;
428
- } else if (!strcmp (subkey , ". proxy" )) {
423
+ } else if (!strcmp (subkey , "proxy" )) {
429
424
return git_config_string ((const char * * )& remote -> http_proxy ,
430
425
key , value );
431
- } else if (!strcmp (subkey , ". proxyauthmethod" )) {
426
+ } else if (!strcmp (subkey , "proxyauthmethod" )) {
432
427
return git_config_string ((const char * * )& remote -> http_proxy_authmethod ,
433
428
key , value );
434
- } else if (!strcmp (subkey , ". vcs" )) {
429
+ } else if (!strcmp (subkey , "vcs" )) {
435
430
return git_config_string (& remote -> foreign_vcs , key , value );
436
431
}
437
432
return 0 ;
@@ -718,18 +713,9 @@ struct remote *pushremote_get(const char *name)
718
713
return remote_get_1 (name , pushremote_for_branch );
719
714
}
720
715
721
- int remote_is_configured (const char * name )
716
+ int remote_is_configured (struct remote * remote )
722
717
{
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 ;
733
719
}
734
720
735
721
int for_each_remote (each_remote_fn fn , void * priv )
0 commit comments