@@ -347,6 +347,14 @@ struct ref_states {
347
347
int queried ;
348
348
};
349
349
350
+ #define REF_STATES_INIT { \
351
+ .new_refs = STRING_LIST_INIT_DUP, \
352
+ .stale = STRING_LIST_INIT_DUP, \
353
+ .tracked = STRING_LIST_INIT_DUP, \
354
+ .heads = STRING_LIST_INIT_DUP, \
355
+ .push = STRING_LIST_INIT_DUP, \
356
+ }
357
+
350
358
static int get_ref_states (const struct ref * remote_refs , struct ref_states * states )
351
359
{
352
360
struct ref * fetch_map = NULL , * * tail = & fetch_map ;
@@ -358,9 +366,6 @@ static int get_ref_states(const struct ref *remote_refs, struct ref_states *stat
358
366
die (_ ("Could not get fetch map for refspec %s" ),
359
367
states -> remote -> fetch .raw [i ]);
360
368
361
- states -> new_refs .strdup_strings = 1 ;
362
- states -> tracked .strdup_strings = 1 ;
363
- states -> stale .strdup_strings = 1 ;
364
369
for (ref = fetch_map ; ref ; ref = ref -> next ) {
365
370
if (!ref -> peer_ref || !ref_exists (ref -> peer_ref -> name ))
366
371
string_list_append (& states -> new_refs , abbrev_branch (ref -> name ));
@@ -409,7 +414,6 @@ static int get_push_ref_states(const struct ref *remote_refs,
409
414
410
415
match_push_refs (local_refs , & push_map , & remote -> push , MATCH_REFS_NONE );
411
416
412
- states -> push .strdup_strings = 1 ;
413
417
for (ref = push_map ; ref ; ref = ref -> next ) {
414
418
struct string_list_item * item ;
415
419
struct push_info * info ;
@@ -452,7 +456,6 @@ static int get_push_ref_states_noquery(struct ref_states *states)
452
456
if (remote -> mirror )
453
457
return 0 ;
454
458
455
- states -> push .strdup_strings = 1 ;
456
459
if (!remote -> push .nr ) {
457
460
item = string_list_append (& states -> push , _ ("(matching)" ));
458
461
info = item -> util = xcalloc (1 , sizeof (struct push_info ));
@@ -486,7 +489,6 @@ static int get_head_names(const struct ref *remote_refs, struct ref_states *stat
486
489
refspec .force = 0 ;
487
490
refspec .pattern = 1 ;
488
491
refspec .src = refspec .dst = "refs/heads/*" ;
489
- states -> heads .strdup_strings = 1 ;
490
492
get_fetch_map (remote_refs , & refspec , & fetch_map_tail , 0 );
491
493
matches = guess_remote_head (find_ref_by_name (remote_refs , "HEAD" ),
492
494
fetch_map , 1 );
@@ -973,26 +975,31 @@ static int get_remote_ref_states(const char *name,
973
975
}
974
976
975
977
struct show_info {
976
- struct string_list * list ;
977
- struct ref_states * states ;
978
+ struct string_list list ;
979
+ struct ref_states states ;
978
980
int width , width2 ;
979
981
int any_rebase ;
980
982
};
981
983
984
+ #define SHOW_INFO_INIT { \
985
+ .list = STRING_LIST_INIT_DUP, \
986
+ .states = REF_STATES_INIT, \
987
+ }
988
+
982
989
static int add_remote_to_show_info (struct string_list_item * item , void * cb_data )
983
990
{
984
991
struct show_info * info = cb_data ;
985
992
int n = strlen (item -> string );
986
993
if (n > info -> width )
987
994
info -> width = n ;
988
- string_list_insert (info -> list , item -> string );
995
+ string_list_insert (& info -> list , item -> string );
989
996
return 0 ;
990
997
}
991
998
992
999
static int show_remote_info_item (struct string_list_item * item , void * cb_data )
993
1000
{
994
1001
struct show_info * info = cb_data ;
995
- struct ref_states * states = info -> states ;
1002
+ struct ref_states * states = & info -> states ;
996
1003
const char * name = item -> string ;
997
1004
998
1005
if (states -> queried ) {
@@ -1019,7 +1026,7 @@ static int show_remote_info_item(struct string_list_item *item, void *cb_data)
1019
1026
static int add_local_to_show_info (struct string_list_item * branch_item , void * cb_data )
1020
1027
{
1021
1028
struct show_info * show_info = cb_data ;
1022
- struct ref_states * states = show_info -> states ;
1029
+ struct ref_states * states = & show_info -> states ;
1023
1030
struct branch_info * branch_info = branch_item -> util ;
1024
1031
struct string_list_item * item ;
1025
1032
int n ;
@@ -1032,7 +1039,7 @@ static int add_local_to_show_info(struct string_list_item *branch_item, void *cb
1032
1039
if (branch_info -> rebase >= REBASE_TRUE )
1033
1040
show_info -> any_rebase = 1 ;
1034
1041
1035
- item = string_list_insert (show_info -> list , branch_item -> string );
1042
+ item = string_list_insert (& show_info -> list , branch_item -> string );
1036
1043
item -> util = branch_info ;
1037
1044
1038
1045
return 0 ;
@@ -1087,7 +1094,7 @@ static int add_push_to_show_info(struct string_list_item *push_item, void *cb_da
1087
1094
show_info -> width = n ;
1088
1095
if ((n = strlen (push_info -> dest )) > show_info -> width2 )
1089
1096
show_info -> width2 = n ;
1090
- item = string_list_append (show_info -> list , push_item -> string );
1097
+ item = string_list_append (& show_info -> list , push_item -> string );
1091
1098
item -> util = push_item -> util ;
1092
1099
return 0 ;
1093
1100
}
@@ -1215,9 +1222,7 @@ static int show(int argc, const char **argv)
1215
1222
OPT_BOOL ('n' , NULL , & no_query , N_ ("do not query remotes" )),
1216
1223
OPT_END ()
1217
1224
};
1218
- struct ref_states states ;
1219
- struct string_list info_list = STRING_LIST_INIT_NODUP ;
1220
- struct show_info info ;
1225
+ struct show_info info = SHOW_INFO_INIT ;
1221
1226
1222
1227
argc = parse_options (argc , argv , NULL , options , builtin_remote_show_usage ,
1223
1228
0 );
@@ -1228,26 +1233,22 @@ static int show(int argc, const char **argv)
1228
1233
if (!no_query )
1229
1234
query_flag = (GET_REF_STATES | GET_HEAD_NAMES | GET_PUSH_REF_STATES );
1230
1235
1231
- memset (& states , 0 , sizeof (states ));
1232
- memset (& info , 0 , sizeof (info ));
1233
- info .states = & states ;
1234
- info .list = & info_list ;
1235
1236
for (; argc ; argc -- , argv ++ ) {
1236
1237
int i ;
1237
1238
const char * * url ;
1238
1239
int url_nr ;
1239
1240
1240
- get_remote_ref_states (* argv , & states , query_flag );
1241
+ get_remote_ref_states (* argv , & info . states , query_flag );
1241
1242
1242
1243
printf_ln (_ ("* remote %s" ), * argv );
1243
- printf_ln (_ (" Fetch URL: %s" ), states .remote -> url_nr > 0 ?
1244
- states .remote -> url [0 ] : _ ("(no URL)" ));
1245
- if (states .remote -> pushurl_nr ) {
1246
- url = states .remote -> pushurl ;
1247
- url_nr = states .remote -> pushurl_nr ;
1244
+ printf_ln (_ (" Fetch URL: %s" ), info . states .remote -> url_nr > 0 ?
1245
+ info . states .remote -> url [0 ] : _ ("(no URL)" ));
1246
+ if (info . states .remote -> pushurl_nr ) {
1247
+ url = info . states .remote -> pushurl ;
1248
+ url_nr = info . states .remote -> pushurl_nr ;
1248
1249
} else {
1249
- url = states .remote -> url ;
1250
- url_nr = states .remote -> url_nr ;
1250
+ url = info . states .remote -> url ;
1251
+ url_nr = info . states .remote -> url_nr ;
1251
1252
}
1252
1253
for (i = 0 ; i < url_nr ; i ++ )
1253
1254
/*
@@ -1260,57 +1261,57 @@ static int show(int argc, const char **argv)
1260
1261
printf_ln (_ (" Push URL: %s" ), _ ("(no URL)" ));
1261
1262
if (no_query )
1262
1263
printf_ln (_ (" HEAD branch: %s" ), _ ("(not queried)" ));
1263
- else if (!states .heads .nr )
1264
+ else if (!info . states .heads .nr )
1264
1265
printf_ln (_ (" HEAD branch: %s" ), _ ("(unknown)" ));
1265
- else if (states .heads .nr == 1 )
1266
- printf_ln (_ (" HEAD branch: %s" ), states .heads .items [0 ].string );
1266
+ else if (info . states .heads .nr == 1 )
1267
+ printf_ln (_ (" HEAD branch: %s" ), info . states .heads .items [0 ].string );
1267
1268
else {
1268
1269
printf (_ (" HEAD branch (remote HEAD is ambiguous,"
1269
1270
" may be one of the following):\n" ));
1270
- for (i = 0 ; i < states .heads .nr ; i ++ )
1271
- printf (" %s\n" , states .heads .items [i ].string );
1271
+ for (i = 0 ; i < info . states .heads .nr ; i ++ )
1272
+ printf (" %s\n" , info . states .heads .items [i ].string );
1272
1273
}
1273
1274
1274
1275
/* remote branch info */
1275
1276
info .width = 0 ;
1276
- for_each_string_list (& states .new_refs , add_remote_to_show_info , & info );
1277
- for_each_string_list (& states .tracked , add_remote_to_show_info , & info );
1278
- for_each_string_list (& states .stale , add_remote_to_show_info , & info );
1279
- if (info .list -> nr )
1277
+ for_each_string_list (& info . states .new_refs , add_remote_to_show_info , & info );
1278
+ for_each_string_list (& info . states .tracked , add_remote_to_show_info , & info );
1279
+ for_each_string_list (& info . states .stale , add_remote_to_show_info , & info );
1280
+ if (info .list . nr )
1280
1281
printf_ln (Q_ (" Remote branch:%s" ,
1281
1282
" Remote branches:%s" ,
1282
- info .list -> nr ),
1283
+ info .list . nr ),
1283
1284
no_query ? _ (" (status not queried)" ) : "" );
1284
- for_each_string_list (info .list , show_remote_info_item , & info );
1285
- string_list_clear (info .list , 0 );
1285
+ for_each_string_list (& info .list , show_remote_info_item , & info );
1286
+ string_list_clear (& info .list , 0 );
1286
1287
1287
1288
/* git pull info */
1288
1289
info .width = 0 ;
1289
1290
info .any_rebase = 0 ;
1290
1291
for_each_string_list (& branch_list , add_local_to_show_info , & info );
1291
- if (info .list -> nr )
1292
+ if (info .list . nr )
1292
1293
printf_ln (Q_ (" Local branch configured for 'git pull':" ,
1293
1294
" Local branches configured for 'git pull':" ,
1294
- info .list -> nr ));
1295
- for_each_string_list (info .list , show_local_info_item , & info );
1296
- string_list_clear (info .list , 0 );
1295
+ info .list . nr ));
1296
+ for_each_string_list (& info .list , show_local_info_item , & info );
1297
+ string_list_clear (& info .list , 0 );
1297
1298
1298
1299
/* git push info */
1299
- if (states .remote -> mirror )
1300
+ if (info . states .remote -> mirror )
1300
1301
printf_ln (_ (" Local refs will be mirrored by 'git push'" ));
1301
1302
1302
1303
info .width = info .width2 = 0 ;
1303
- for_each_string_list (& states .push , add_push_to_show_info , & info );
1304
- QSORT (info .list -> items , info .list -> nr , cmp_string_with_push );
1305
- if (info .list -> nr )
1304
+ for_each_string_list (& info . states .push , add_push_to_show_info , & info );
1305
+ QSORT (info .list . items , info .list . nr , cmp_string_with_push );
1306
+ if (info .list . nr )
1306
1307
printf_ln (Q_ (" Local ref configured for 'git push'%s:" ,
1307
1308
" Local refs configured for 'git push'%s:" ,
1308
- info .list -> nr ),
1309
+ info .list . nr ),
1309
1310
no_query ? _ (" (status not queried)" ) : "" );
1310
- for_each_string_list (info .list , show_push_info_item , & info );
1311
- string_list_clear (info .list , 0 );
1311
+ for_each_string_list (& info .list , show_push_info_item , & info );
1312
+ string_list_clear (& info .list , 0 );
1312
1313
1313
- free_remote_ref_states (& states );
1314
+ free_remote_ref_states (& info . states );
1314
1315
}
1315
1316
1316
1317
return result ;
@@ -1337,8 +1338,7 @@ static int set_head(int argc, const char **argv)
1337
1338
if (!opt_a && !opt_d && argc == 2 ) {
1338
1339
head_name = xstrdup (argv [1 ]);
1339
1340
} else if (opt_a && !opt_d && argc == 1 ) {
1340
- struct ref_states states ;
1341
- memset (& states , 0 , sizeof (states ));
1341
+ struct ref_states states = REF_STATES_INIT ;
1342
1342
get_remote_ref_states (argv [0 ], & states , GET_HEAD_NAMES );
1343
1343
if (!states .heads .nr )
1344
1344
result |= error (_ ("Cannot determine remote HEAD" ));
@@ -1377,14 +1377,13 @@ static int set_head(int argc, const char **argv)
1377
1377
static int prune_remote (const char * remote , int dry_run )
1378
1378
{
1379
1379
int result = 0 ;
1380
- struct ref_states states ;
1380
+ struct ref_states states = REF_STATES_INIT ;
1381
1381
struct string_list refs_to_prune = STRING_LIST_INIT_NODUP ;
1382
1382
struct string_list_item * item ;
1383
1383
const char * dangling_msg = dry_run
1384
1384
? _ (" %s will become dangling!" )
1385
1385
: _ (" %s has become dangling!" );
1386
1386
1387
- memset (& states , 0 , sizeof (states ));
1388
1387
get_remote_ref_states (remote , & states , GET_REF_STATES );
1389
1388
1390
1389
if (!states .stale .nr ) {
0 commit comments