50
50
struct display_state {
51
51
int refcol_width ;
52
52
int compact_format ;
53
+
54
+ char * url ;
55
+ int url_len , shown_url ;
53
56
};
54
57
55
58
static int fetch_prune_config = -1 ; /* unspecified */
@@ -84,7 +87,6 @@ static const char *submodule_prefix = "";
84
87
static int recurse_submodules = RECURSE_SUBMODULES_DEFAULT ;
85
88
static int recurse_submodules_cli = RECURSE_SUBMODULES_DEFAULT ;
86
89
static int recurse_submodules_default = RECURSE_SUBMODULES_ON_DEMAND ;
87
- static int shown_url = 0 ;
88
90
static struct refspec refmap = REFSPEC_INIT_FETCH ;
89
91
static struct list_objects_filter_options filter_options = LIST_OBJECTS_FILTER_INIT ;
90
92
static struct string_list server_options = STRING_LIST_INIT_DUP ;
@@ -776,13 +778,27 @@ static int refcol_width(const struct ref *ref, int compact_format)
776
778
return rlen ;
777
779
}
778
780
779
- static void display_state_init (struct display_state * display_state , struct ref * ref_map )
781
+ static void display_state_init (struct display_state * display_state , struct ref * ref_map ,
782
+ const char * raw_url )
780
783
{
781
784
struct ref * rm ;
782
785
const char * format = "full" ;
786
+ int i ;
783
787
784
788
memset (display_state , 0 , sizeof (* display_state ));
785
789
790
+ if (raw_url )
791
+ display_state -> url = transport_anonymize_url (raw_url );
792
+ else
793
+ display_state -> url = xstrdup ("foreign" );
794
+
795
+ display_state -> url_len = strlen (display_state -> url );
796
+ for (i = display_state -> url_len - 1 ; display_state -> url [i ] == '/' && 0 <= i ; i -- )
797
+ ;
798
+ display_state -> url_len = i + 1 ;
799
+ if (4 < i && !strncmp (".git" , display_state -> url + i - 3 , 4 ))
800
+ display_state -> url_len = i - 3 ;
801
+
786
802
if (verbosity < 0 )
787
803
return ;
788
804
@@ -816,6 +832,11 @@ static void display_state_init(struct display_state *display_state, struct ref *
816
832
}
817
833
}
818
834
835
+ static void display_state_release (struct display_state * display_state )
836
+ {
837
+ free (display_state -> url );
838
+ }
839
+
819
840
static void print_remote_to_local (struct display_state * display_state ,
820
841
struct strbuf * display_buffer ,
821
842
const char * remote , const char * local )
@@ -883,6 +904,12 @@ static void format_display(struct display_state *display_state,
883
904
if (verbosity < 0 )
884
905
return ;
885
906
907
+ if (!display_state -> shown_url ) {
908
+ strbuf_addf (display_buffer , _ ("From %.*s\n" ),
909
+ display_state -> url_len , display_state -> url );
910
+ display_state -> shown_url = 1 ;
911
+ }
912
+
886
913
width = (summary_width + strlen (summary ) - gettext_width (summary ));
887
914
888
915
strbuf_addf (display_buffer , " %c %-*s " , code , width , summary );
@@ -1122,33 +1149,28 @@ N_("it took %.2f seconds to check forced updates; you can use\n"
1122
1149
"to avoid this check\n" );
1123
1150
1124
1151
static int store_updated_refs (struct display_state * display_state ,
1125
- const char * raw_url , const char * remote_name ,
1152
+ const char * remote_name ,
1126
1153
int connectivity_checked ,
1127
1154
struct ref_transaction * transaction , struct ref * ref_map ,
1128
1155
struct fetch_head * fetch_head )
1129
1156
{
1130
- int url_len , i , rc = 0 ;
1157
+ int rc = 0 ;
1131
1158
struct strbuf note = STRBUF_INIT ;
1132
1159
const char * what , * kind ;
1133
1160
struct ref * rm ;
1134
- char * url ;
1135
1161
int want_status ;
1136
1162
int summary_width = 0 ;
1137
1163
1138
1164
if (verbosity >= 0 )
1139
1165
summary_width = transport_summary_width (ref_map );
1140
1166
1141
- if (raw_url )
1142
- url = transport_anonymize_url (raw_url );
1143
- else
1144
- url = xstrdup ("foreign" );
1145
-
1146
1167
if (!connectivity_checked ) {
1147
1168
struct check_connected_options opt = CHECK_CONNECTED_INIT ;
1148
1169
1149
1170
rm = ref_map ;
1150
1171
if (check_connected (iterate_ref_map , & rm , & opt )) {
1151
- rc = error (_ ("%s did not send all necessary objects\n" ), url );
1172
+ rc = error (_ ("%s did not send all necessary objects\n" ),
1173
+ display_state -> url );
1152
1174
goto abort ;
1153
1175
}
1154
1176
}
@@ -1232,13 +1254,6 @@ static int store_updated_refs(struct display_state *display_state,
1232
1254
what = rm -> name ;
1233
1255
}
1234
1256
1235
- url_len = strlen (url );
1236
- for (i = url_len - 1 ; url [i ] == '/' && 0 <= i ; i -- )
1237
- ;
1238
- url_len = i + 1 ;
1239
- if (4 < i && !strncmp (".git" , url + i - 3 , 4 ))
1240
- url_len = i - 3 ;
1241
-
1242
1257
strbuf_reset (& note );
1243
1258
if (* what ) {
1244
1259
if (* kind )
@@ -1248,7 +1263,8 @@ static int store_updated_refs(struct display_state *display_state,
1248
1263
1249
1264
append_fetch_head (fetch_head , & rm -> old_oid ,
1250
1265
rm -> fetch_head_status ,
1251
- note .buf , url , url_len );
1266
+ note .buf , display_state -> url ,
1267
+ display_state -> url_len );
1252
1268
1253
1269
strbuf_reset (& note );
1254
1270
if (ref ) {
@@ -1266,14 +1282,8 @@ static int store_updated_refs(struct display_state *display_state,
1266
1282
* what ? what : "HEAD" ,
1267
1283
"FETCH_HEAD" , summary_width );
1268
1284
}
1269
- if (note .len ) {
1270
- if (!shown_url ) {
1271
- fprintf (stderr , _ ("From %.*s\n" ),
1272
- url_len , url );
1273
- shown_url = 1 ;
1274
- }
1285
+ if (note .len )
1275
1286
fputs (note .buf , stderr );
1276
- }
1277
1287
}
1278
1288
}
1279
1289
@@ -1293,7 +1303,6 @@ static int store_updated_refs(struct display_state *display_state,
1293
1303
1294
1304
abort :
1295
1305
strbuf_release (& note );
1296
- free (url );
1297
1306
return rc ;
1298
1307
}
1299
1308
@@ -1365,7 +1374,7 @@ static int fetch_and_consume_refs(struct display_state *display_state,
1365
1374
}
1366
1375
1367
1376
trace2_region_enter ("fetch" , "consume_refs" , the_repository );
1368
- ret = store_updated_refs (display_state , transport -> url , transport -> remote -> name ,
1377
+ ret = store_updated_refs (display_state , transport -> remote -> name ,
1369
1378
connectivity_checked , transaction , ref_map ,
1370
1379
fetch_head );
1371
1380
trace2_region_leave ("fetch" , "consume_refs" , the_repository );
@@ -1378,30 +1387,15 @@ static int fetch_and_consume_refs(struct display_state *display_state,
1378
1387
static int prune_refs (struct display_state * display_state ,
1379
1388
struct refspec * rs ,
1380
1389
struct ref_transaction * transaction ,
1381
- struct ref * ref_map ,
1382
- const char * raw_url )
1390
+ struct ref * ref_map )
1383
1391
{
1384
- int url_len , i , result = 0 ;
1392
+ int result = 0 ;
1385
1393
struct ref * ref , * stale_refs = get_stale_heads (rs , ref_map );
1386
1394
struct strbuf err = STRBUF_INIT ;
1387
- char * url ;
1388
1395
const char * dangling_msg = dry_run
1389
1396
? _ (" (%s will become dangling)" )
1390
1397
: _ (" (%s has become dangling)" );
1391
1398
1392
- if (raw_url )
1393
- url = transport_anonymize_url (raw_url );
1394
- else
1395
- url = xstrdup ("foreign" );
1396
-
1397
- url_len = strlen (url );
1398
- for (i = url_len - 1 ; url [i ] == '/' && 0 <= i ; i -- )
1399
- ;
1400
-
1401
- url_len = i + 1 ;
1402
- if (4 < i && !strncmp (".git" , url + i - 3 , 4 ))
1403
- url_len = i - 3 ;
1404
-
1405
1399
if (!dry_run ) {
1406
1400
if (transaction ) {
1407
1401
for (ref = stale_refs ; ref ; ref = ref -> next ) {
@@ -1426,10 +1420,6 @@ static int prune_refs(struct display_state *display_state,
1426
1420
1427
1421
for (ref = stale_refs ; ref ; ref = ref -> next ) {
1428
1422
struct strbuf sb = STRBUF_INIT ;
1429
- if (!shown_url ) {
1430
- fprintf (stderr , _ ("From %.*s\n" ), url_len , url );
1431
- shown_url = 1 ;
1432
- }
1433
1423
format_display (display_state , & sb , '-' , _ ("[deleted]" ), NULL ,
1434
1424
_ ("(none)" ), ref -> name ,
1435
1425
summary_width );
@@ -1441,7 +1431,6 @@ static int prune_refs(struct display_state *display_state,
1441
1431
1442
1432
cleanup :
1443
1433
strbuf_release (& err );
1444
- free (url );
1445
1434
free_refs (stale_refs );
1446
1435
return result ;
1447
1436
}
@@ -1596,7 +1585,7 @@ static int do_fetch(struct transport *transport,
1596
1585
{
1597
1586
struct ref_transaction * transaction = NULL ;
1598
1587
struct ref * ref_map = NULL ;
1599
- struct display_state display_state ;
1588
+ struct display_state display_state = { 0 } ;
1600
1589
int autotags = (transport -> remote -> fetch_tags == 1 );
1601
1590
int retcode = 0 ;
1602
1591
const struct ref * remote_refs ;
@@ -1678,7 +1667,7 @@ static int do_fetch(struct transport *transport,
1678
1667
if (retcode )
1679
1668
goto cleanup ;
1680
1669
1681
- display_state_init (& display_state , ref_map );
1670
+ display_state_init (& display_state , ref_map , transport -> url );
1682
1671
1683
1672
if (atomic_fetch ) {
1684
1673
transaction = ref_transaction_begin (& err );
@@ -1697,11 +1686,10 @@ static int do_fetch(struct transport *transport,
1697
1686
* don't care whether --tags was specified.
1698
1687
*/
1699
1688
if (rs -> nr ) {
1700
- retcode = prune_refs (& display_state , rs , transaction , ref_map , transport -> url );
1689
+ retcode = prune_refs (& display_state , rs , transaction , ref_map );
1701
1690
} else {
1702
1691
retcode = prune_refs (& display_state , & transport -> remote -> fetch ,
1703
- transaction , ref_map ,
1704
- transport -> url );
1692
+ transaction , ref_map );
1705
1693
}
1706
1694
if (retcode != 0 )
1707
1695
retcode = 1 ;
@@ -1812,6 +1800,7 @@ static int do_fetch(struct transport *transport,
1812
1800
error ("%s" , err .buf );
1813
1801
}
1814
1802
1803
+ display_state_release (& display_state );
1815
1804
close_fetch_head (& fetch_head );
1816
1805
strbuf_release (& err );
1817
1806
free_refs (ref_map );
0 commit comments