@@ -972,26 +972,31 @@ static int get_remote_ref_states(const char *name,
972
972
}
973
973
974
974
struct show_info {
975
- struct string_list * list ;
976
- struct ref_states * states ;
975
+ struct string_list list ;
976
+ struct ref_states states ;
977
977
int width , width2 ;
978
978
int any_rebase ;
979
979
};
980
980
981
+ #define SHOW_INFO_INIT { \
982
+ .list = STRING_LIST_INIT_DUP, \
983
+ .states = REF_STATES_INIT, \
984
+ }
985
+
981
986
static int add_remote_to_show_info (struct string_list_item * item , void * cb_data )
982
987
{
983
988
struct show_info * info = cb_data ;
984
989
int n = strlen (item -> string );
985
990
if (n > info -> width )
986
991
info -> width = n ;
987
- string_list_insert (info -> list , item -> string );
992
+ string_list_insert (& info -> list , item -> string );
988
993
return 0 ;
989
994
}
990
995
991
996
static int show_remote_info_item (struct string_list_item * item , void * cb_data )
992
997
{
993
998
struct show_info * info = cb_data ;
994
- struct ref_states * states = info -> states ;
999
+ struct ref_states * states = & info -> states ;
995
1000
const char * name = item -> string ;
996
1001
997
1002
if (states -> queried ) {
@@ -1018,7 +1023,7 @@ static int show_remote_info_item(struct string_list_item *item, void *cb_data)
1018
1023
static int add_local_to_show_info (struct string_list_item * branch_item , void * cb_data )
1019
1024
{
1020
1025
struct show_info * show_info = cb_data ;
1021
- struct ref_states * states = show_info -> states ;
1026
+ struct ref_states * states = & show_info -> states ;
1022
1027
struct branch_info * branch_info = branch_item -> util ;
1023
1028
struct string_list_item * item ;
1024
1029
int n ;
@@ -1031,7 +1036,7 @@ static int add_local_to_show_info(struct string_list_item *branch_item, void *cb
1031
1036
if (branch_info -> rebase >= REBASE_TRUE )
1032
1037
show_info -> any_rebase = 1 ;
1033
1038
1034
- item = string_list_insert (show_info -> list , branch_item -> string );
1039
+ item = string_list_insert (& show_info -> list , branch_item -> string );
1035
1040
item -> util = branch_info ;
1036
1041
1037
1042
return 0 ;
@@ -1086,7 +1091,7 @@ static int add_push_to_show_info(struct string_list_item *push_item, void *cb_da
1086
1091
show_info -> width = n ;
1087
1092
if ((n = strlen (push_info -> dest )) > show_info -> width2 )
1088
1093
show_info -> width2 = n ;
1089
- item = string_list_append (show_info -> list , push_item -> string );
1094
+ item = string_list_append (& show_info -> list , push_item -> string );
1090
1095
item -> util = push_item -> util ;
1091
1096
return 0 ;
1092
1097
}
@@ -1214,9 +1219,7 @@ static int show(int argc, const char **argv)
1214
1219
OPT_BOOL ('n' , NULL , & no_query , N_ ("do not query remotes" )),
1215
1220
OPT_END ()
1216
1221
};
1217
- struct ref_states states = REF_STATES_INIT ;
1218
- struct string_list info_list = STRING_LIST_INIT_NODUP ;
1219
- struct show_info info ;
1222
+ struct show_info info = SHOW_INFO_INIT ;
1220
1223
1221
1224
argc = parse_options (argc , argv , NULL , options , builtin_remote_show_usage ,
1222
1225
0 );
@@ -1227,25 +1230,22 @@ static int show(int argc, const char **argv)
1227
1230
if (!no_query )
1228
1231
query_flag = (GET_REF_STATES | GET_HEAD_NAMES | GET_PUSH_REF_STATES );
1229
1232
1230
- memset (& info , 0 , sizeof (info ));
1231
- info .states = & states ;
1232
- info .list = & info_list ;
1233
1233
for (; argc ; argc -- , argv ++ ) {
1234
1234
int i ;
1235
1235
const char * * url ;
1236
1236
int url_nr ;
1237
1237
1238
- get_remote_ref_states (* argv , & states , query_flag );
1238
+ get_remote_ref_states (* argv , & info . states , query_flag );
1239
1239
1240
1240
printf_ln (_ ("* remote %s" ), * argv );
1241
- printf_ln (_ (" Fetch URL: %s" ), states .remote -> url_nr > 0 ?
1242
- states .remote -> url [0 ] : _ ("(no URL)" ));
1243
- if (states .remote -> pushurl_nr ) {
1244
- url = states .remote -> pushurl ;
1245
- url_nr = states .remote -> pushurl_nr ;
1241
+ printf_ln (_ (" Fetch URL: %s" ), info . states .remote -> url_nr > 0 ?
1242
+ info . states .remote -> url [0 ] : _ ("(no URL)" ));
1243
+ if (info . states .remote -> pushurl_nr ) {
1244
+ url = info . states .remote -> pushurl ;
1245
+ url_nr = info . states .remote -> pushurl_nr ;
1246
1246
} else {
1247
- url = states .remote -> url ;
1248
- url_nr = states .remote -> url_nr ;
1247
+ url = info . states .remote -> url ;
1248
+ url_nr = info . states .remote -> url_nr ;
1249
1249
}
1250
1250
for (i = 0 ; i < url_nr ; i ++ )
1251
1251
/*
@@ -1258,57 +1258,57 @@ static int show(int argc, const char **argv)
1258
1258
printf_ln (_ (" Push URL: %s" ), _ ("(no URL)" ));
1259
1259
if (no_query )
1260
1260
printf_ln (_ (" HEAD branch: %s" ), _ ("(not queried)" ));
1261
- else if (!states .heads .nr )
1261
+ else if (!info . states .heads .nr )
1262
1262
printf_ln (_ (" HEAD branch: %s" ), _ ("(unknown)" ));
1263
- else if (states .heads .nr == 1 )
1264
- printf_ln (_ (" HEAD branch: %s" ), states .heads .items [0 ].string );
1263
+ else if (info . states .heads .nr == 1 )
1264
+ printf_ln (_ (" HEAD branch: %s" ), info . states .heads .items [0 ].string );
1265
1265
else {
1266
1266
printf (_ (" HEAD branch (remote HEAD is ambiguous,"
1267
1267
" may be one of the following):\n" ));
1268
- for (i = 0 ; i < states .heads .nr ; i ++ )
1269
- printf (" %s\n" , states .heads .items [i ].string );
1268
+ for (i = 0 ; i < info . states .heads .nr ; i ++ )
1269
+ printf (" %s\n" , info . states .heads .items [i ].string );
1270
1270
}
1271
1271
1272
1272
/* remote branch info */
1273
1273
info .width = 0 ;
1274
- for_each_string_list (& states .new_refs , add_remote_to_show_info , & info );
1275
- for_each_string_list (& states .tracked , add_remote_to_show_info , & info );
1276
- for_each_string_list (& states .stale , add_remote_to_show_info , & info );
1277
- if (info .list -> nr )
1274
+ for_each_string_list (& info . states .new_refs , add_remote_to_show_info , & info );
1275
+ for_each_string_list (& info . states .tracked , add_remote_to_show_info , & info );
1276
+ for_each_string_list (& info . states .stale , add_remote_to_show_info , & info );
1277
+ if (info .list . nr )
1278
1278
printf_ln (Q_ (" Remote branch:%s" ,
1279
1279
" Remote branches:%s" ,
1280
- info .list -> nr ),
1280
+ info .list . nr ),
1281
1281
no_query ? _ (" (status not queried)" ) : "" );
1282
- for_each_string_list (info .list , show_remote_info_item , & info );
1283
- string_list_clear (info .list , 0 );
1282
+ for_each_string_list (& info .list , show_remote_info_item , & info );
1283
+ string_list_clear (& info .list , 0 );
1284
1284
1285
1285
/* git pull info */
1286
1286
info .width = 0 ;
1287
1287
info .any_rebase = 0 ;
1288
1288
for_each_string_list (& branch_list , add_local_to_show_info , & info );
1289
- if (info .list -> nr )
1289
+ if (info .list . nr )
1290
1290
printf_ln (Q_ (" Local branch configured for 'git pull':" ,
1291
1291
" Local branches configured for 'git pull':" ,
1292
- info .list -> nr ));
1293
- for_each_string_list (info .list , show_local_info_item , & info );
1294
- string_list_clear (info .list , 0 );
1292
+ info .list . nr ));
1293
+ for_each_string_list (& info .list , show_local_info_item , & info );
1294
+ string_list_clear (& info .list , 0 );
1295
1295
1296
1296
/* git push info */
1297
- if (states .remote -> mirror )
1297
+ if (info . states .remote -> mirror )
1298
1298
printf_ln (_ (" Local refs will be mirrored by 'git push'" ));
1299
1299
1300
1300
info .width = info .width2 = 0 ;
1301
- for_each_string_list (& states .push , add_push_to_show_info , & info );
1302
- QSORT (info .list -> items , info .list -> nr , cmp_string_with_push );
1303
- if (info .list -> nr )
1301
+ for_each_string_list (& info . states .push , add_push_to_show_info , & info );
1302
+ QSORT (info .list . items , info .list . nr , cmp_string_with_push );
1303
+ if (info .list . nr )
1304
1304
printf_ln (Q_ (" Local ref configured for 'git push'%s:" ,
1305
1305
" Local refs configured for 'git push'%s:" ,
1306
- info .list -> nr ),
1306
+ info .list . nr ),
1307
1307
no_query ? _ (" (status not queried)" ) : "" );
1308
- for_each_string_list (info .list , show_push_info_item , & info );
1309
- string_list_clear (info .list , 0 );
1308
+ for_each_string_list (& info .list , show_push_info_item , & info );
1309
+ string_list_clear (& info .list , 0 );
1310
1310
1311
- free_remote_ref_states (& states );
1311
+ free_remote_ref_states (& info . states );
1312
1312
}
1313
1313
1314
1314
return result ;
0 commit comments