Skip to content

Commit 0000e81

Browse files
avargitster
authored andcommitted
builtin/remote.c: add and use SHOW_INFO_INIT
In the preceding commit we introduced REF_STATES_INIT, but did not change the "struct show_info" to have a corresponding initializer. Let's do that, and make it use "REF_STATES_INIT" and "STRING_LIST_INIT_DUP", doing that requires changing "list" and "states" away from being pointers. The resulting end-state is simpler since we omit the local "info_list" and "states" variables in show() as well as the memset(). Signed-off-by: Ævar Arnfjörð Bjarmason <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 0bc7787 commit 0000e81

File tree

1 file changed

+45
-45
lines changed

1 file changed

+45
-45
lines changed

builtin/remote.c

Lines changed: 45 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -972,26 +972,31 @@ static int get_remote_ref_states(const char *name,
972972
}
973973

974974
struct show_info {
975-
struct string_list *list;
976-
struct ref_states *states;
975+
struct string_list list;
976+
struct ref_states states;
977977
int width, width2;
978978
int any_rebase;
979979
};
980980

981+
#define SHOW_INFO_INIT { \
982+
.list = STRING_LIST_INIT_DUP, \
983+
.states = REF_STATES_INIT, \
984+
}
985+
981986
static int add_remote_to_show_info(struct string_list_item *item, void *cb_data)
982987
{
983988
struct show_info *info = cb_data;
984989
int n = strlen(item->string);
985990
if (n > info->width)
986991
info->width = n;
987-
string_list_insert(info->list, item->string);
992+
string_list_insert(&info->list, item->string);
988993
return 0;
989994
}
990995

991996
static int show_remote_info_item(struct string_list_item *item, void *cb_data)
992997
{
993998
struct show_info *info = cb_data;
994-
struct ref_states *states = info->states;
999+
struct ref_states *states = &info->states;
9951000
const char *name = item->string;
9961001

9971002
if (states->queried) {
@@ -1018,7 +1023,7 @@ static int show_remote_info_item(struct string_list_item *item, void *cb_data)
10181023
static int add_local_to_show_info(struct string_list_item *branch_item, void *cb_data)
10191024
{
10201025
struct show_info *show_info = cb_data;
1021-
struct ref_states *states = show_info->states;
1026+
struct ref_states *states = &show_info->states;
10221027
struct branch_info *branch_info = branch_item->util;
10231028
struct string_list_item *item;
10241029
int n;
@@ -1031,7 +1036,7 @@ static int add_local_to_show_info(struct string_list_item *branch_item, void *cb
10311036
if (branch_info->rebase >= REBASE_TRUE)
10321037
show_info->any_rebase = 1;
10331038

1034-
item = string_list_insert(show_info->list, branch_item->string);
1039+
item = string_list_insert(&show_info->list, branch_item->string);
10351040
item->util = branch_info;
10361041

10371042
return 0;
@@ -1086,7 +1091,7 @@ static int add_push_to_show_info(struct string_list_item *push_item, void *cb_da
10861091
show_info->width = n;
10871092
if ((n = strlen(push_info->dest)) > show_info->width2)
10881093
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);
10901095
item->util = push_item->util;
10911096
return 0;
10921097
}
@@ -1214,9 +1219,7 @@ static int show(int argc, const char **argv)
12141219
OPT_BOOL('n', NULL, &no_query, N_("do not query remotes")),
12151220
OPT_END()
12161221
};
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;
12201223

12211224
argc = parse_options(argc, argv, NULL, options, builtin_remote_show_usage,
12221225
0);
@@ -1227,25 +1230,22 @@ static int show(int argc, const char **argv)
12271230
if (!no_query)
12281231
query_flag = (GET_REF_STATES | GET_HEAD_NAMES | GET_PUSH_REF_STATES);
12291232

1230-
memset(&info, 0, sizeof(info));
1231-
info.states = &states;
1232-
info.list = &info_list;
12331233
for (; argc; argc--, argv++) {
12341234
int i;
12351235
const char **url;
12361236
int url_nr;
12371237

1238-
get_remote_ref_states(*argv, &states, query_flag);
1238+
get_remote_ref_states(*argv, &info.states, query_flag);
12391239

12401240
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;
12461246
} 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;
12491249
}
12501250
for (i = 0; i < url_nr; i++)
12511251
/*
@@ -1258,57 +1258,57 @@ static int show(int argc, const char **argv)
12581258
printf_ln(_(" Push URL: %s"), _("(no URL)"));
12591259
if (no_query)
12601260
printf_ln(_(" HEAD branch: %s"), _("(not queried)"));
1261-
else if (!states.heads.nr)
1261+
else if (!info.states.heads.nr)
12621262
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);
12651265
else {
12661266
printf(_(" HEAD branch (remote HEAD is ambiguous,"
12671267
" 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);
12701270
}
12711271

12721272
/* remote branch info */
12731273
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)
12781278
printf_ln(Q_(" Remote branch:%s",
12791279
" Remote branches:%s",
1280-
info.list->nr),
1280+
info.list.nr),
12811281
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);
12841284

12851285
/* git pull info */
12861286
info.width = 0;
12871287
info.any_rebase = 0;
12881288
for_each_string_list(&branch_list, add_local_to_show_info, &info);
1289-
if (info.list->nr)
1289+
if (info.list.nr)
12901290
printf_ln(Q_(" Local branch configured for 'git pull':",
12911291
" 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);
12951295

12961296
/* git push info */
1297-
if (states.remote->mirror)
1297+
if (info.states.remote->mirror)
12981298
printf_ln(_(" Local refs will be mirrored by 'git push'"));
12991299

13001300
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)
13041304
printf_ln(Q_(" Local ref configured for 'git push'%s:",
13051305
" Local refs configured for 'git push'%s:",
1306-
info.list->nr),
1306+
info.list.nr),
13071307
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);
13101310

1311-
free_remote_ref_states(&states);
1311+
free_remote_ref_states(&info.states);
13121312
}
13131313

13141314
return result;

0 commit comments

Comments
 (0)