@@ -47,6 +47,10 @@ enum {
47
47
TAGS_SET = 2
48
48
};
49
49
50
+ struct display_state {
51
+ int refcol_width ;
52
+ };
53
+
50
54
static int fetch_prune_config = -1 ; /* unspecified */
51
55
static int fetch_show_forced_updates = 1 ;
52
56
static uint64_t forced_updates_ms = 0 ;
@@ -741,16 +745,15 @@ static int s_update_ref(const char *action,
741
745
return ret ;
742
746
}
743
747
744
- static int refcol_width = 10 ;
745
748
static int compact_format ;
746
749
747
- static void adjust_refcol_width (const struct ref * ref )
750
+ static int refcol_width (const struct ref * ref )
748
751
{
749
752
int max , rlen , llen , len ;
750
753
751
754
/* uptodate lines are only shown on high verbosity level */
752
755
if (verbosity <= 0 && oideq (& ref -> peer_ref -> old_oid , & ref -> old_oid ))
753
- return ;
756
+ return 0 ;
754
757
755
758
max = term_columns ();
756
759
rlen = utf8_strwidth (prettify_refname (ref -> name ));
@@ -769,22 +772,18 @@ static void adjust_refcol_width(const struct ref *ref)
769
772
}
770
773
len = 21 /* flag and summary */ + rlen + 4 /* -> */ + llen ;
771
774
if (len >= max )
772
- return ;
775
+ return 0 ;
773
776
774
- /*
775
- * Not precise calculation for compact mode because '*' can
776
- * appear on the left hand side of '->' and shrink the column
777
- * back.
778
- */
779
- if (refcol_width < rlen )
780
- refcol_width = rlen ;
777
+ return rlen ;
781
778
}
782
779
783
- static void prepare_format_display ( struct ref * ref_map )
780
+ static void display_state_init ( struct display_state * display_state , struct ref * ref_map )
784
781
{
785
782
struct ref * rm ;
786
783
const char * format = "full" ;
787
784
785
+ memset (display_state , 0 , sizeof (* display_state ));
786
+
788
787
if (verbosity < 0 )
789
788
return ;
790
789
@@ -797,20 +796,32 @@ static void prepare_format_display(struct ref *ref_map)
797
796
die (_ ("invalid value for '%s': '%s'" ),
798
797
"fetch.output" , format );
799
798
799
+ display_state -> refcol_width = 10 ;
800
800
for (rm = ref_map ; rm ; rm = rm -> next ) {
801
+ int width ;
802
+
801
803
if (rm -> status == REF_STATUS_REJECT_SHALLOW ||
802
804
!rm -> peer_ref ||
803
805
!strcmp (rm -> name , "HEAD" ))
804
806
continue ;
805
807
806
- adjust_refcol_width (rm );
808
+ width = refcol_width (rm );
809
+
810
+ /*
811
+ * Not precise calculation for compact mode because '*' can
812
+ * appear on the left hand side of '->' and shrink the column
813
+ * back.
814
+ */
815
+ if (display_state -> refcol_width < width )
816
+ display_state -> refcol_width = width ;
807
817
}
808
818
}
809
819
810
- static void print_remote_to_local (struct strbuf * display ,
820
+ static void print_remote_to_local (struct display_state * display_state ,
821
+ struct strbuf * display_buffer ,
811
822
const char * remote , const char * local )
812
823
{
813
- strbuf_addf (display , "%-*s -> %s" , refcol_width , remote , local );
824
+ strbuf_addf (display_buffer , "%-*s -> %s" , display_state -> refcol_width , remote , local );
814
825
}
815
826
816
827
static int find_and_replace (struct strbuf * haystack ,
@@ -840,14 +851,14 @@ static int find_and_replace(struct strbuf *haystack,
840
851
return 1 ;
841
852
}
842
853
843
- static void print_compact (struct strbuf * display ,
854
+ static void print_compact (struct display_state * display_state , struct strbuf * display_buffer ,
844
855
const char * remote , const char * local )
845
856
{
846
857
struct strbuf r = STRBUF_INIT ;
847
858
struct strbuf l = STRBUF_INIT ;
848
859
849
860
if (!strcmp (remote , local )) {
850
- strbuf_addf (display , "%-*s -> *" , refcol_width , remote );
861
+ strbuf_addf (display_buffer , "%-*s -> *" , display_state -> refcol_width , remote );
851
862
return ;
852
863
}
853
864
@@ -856,13 +867,14 @@ static void print_compact(struct strbuf *display,
856
867
857
868
if (!find_and_replace (& r , local , "*" ))
858
869
find_and_replace (& l , remote , "*" );
859
- print_remote_to_local (display , r .buf , l .buf );
870
+ print_remote_to_local (display_state , display_buffer , r .buf , l .buf );
860
871
861
872
strbuf_release (& r );
862
873
strbuf_release (& l );
863
874
}
864
875
865
- static void format_display (struct strbuf * display , char code ,
876
+ static void format_display (struct display_state * display_state ,
877
+ struct strbuf * display_buffer , char code ,
866
878
const char * summary , const char * error ,
867
879
const char * remote , const char * local ,
868
880
int summary_width )
@@ -874,17 +886,18 @@ static void format_display(struct strbuf *display, char code,
874
886
875
887
width = (summary_width + strlen (summary ) - gettext_width (summary ));
876
888
877
- strbuf_addf (display , "%c %-*s " , code , width , summary );
889
+ strbuf_addf (display_buffer , "%c %-*s " , code , width , summary );
878
890
if (!compact_format )
879
- print_remote_to_local (display , remote , local );
891
+ print_remote_to_local (display_state , display_buffer , remote , local );
880
892
else
881
- print_compact (display , remote , local );
893
+ print_compact (display_state , display_buffer , remote , local );
882
894
if (error )
883
- strbuf_addf (display , " (%s)" , error );
895
+ strbuf_addf (display_buffer , " (%s)" , error );
884
896
}
885
897
886
898
static int update_local_ref (struct ref * ref ,
887
899
struct ref_transaction * transaction ,
900
+ struct display_state * display_state ,
888
901
const char * remote , const struct ref * remote_ref ,
889
902
struct strbuf * display , int summary_width )
890
903
{
@@ -897,7 +910,7 @@ static int update_local_ref(struct ref *ref,
897
910
898
911
if (oideq (& ref -> old_oid , & ref -> new_oid )) {
899
912
if (verbosity > 0 )
900
- format_display (display , '=' , _ ("[up to date]" ), NULL ,
913
+ format_display (display_state , display , '=' , _ ("[up to date]" ), NULL ,
901
914
remote , pretty_ref , summary_width );
902
915
return 0 ;
903
916
}
@@ -909,7 +922,7 @@ static int update_local_ref(struct ref *ref,
909
922
* If this is the head, and it's not okay to update
910
923
* the head, and the old value of the head isn't empty...
911
924
*/
912
- format_display (display , '!' , _ ("[rejected]" ),
925
+ format_display (display_state , display , '!' , _ ("[rejected]" ),
913
926
_ ("can't fetch into checked-out branch" ),
914
927
remote , pretty_ref , summary_width );
915
928
return 1 ;
@@ -920,12 +933,13 @@ static int update_local_ref(struct ref *ref,
920
933
if (force || ref -> force ) {
921
934
int r ;
922
935
r = s_update_ref ("updating tag" , ref , transaction , 0 );
923
- format_display (display , r ? '!' : 't' , _ ("[tag update]" ),
936
+ format_display (display_state , display , r ? '!' : 't' , _ ("[tag update]" ),
924
937
r ? _ ("unable to update local ref" ) : NULL ,
925
938
remote , pretty_ref , summary_width );
926
939
return r ;
927
940
} else {
928
- format_display (display , '!' , _ ("[rejected]" ), _ ("would clobber existing tag" ),
941
+ format_display (display_state , display , '!' , _ ("[rejected]" ),
942
+ _ ("would clobber existing tag" ),
929
943
remote , pretty_ref , summary_width );
930
944
return 1 ;
931
945
}
@@ -957,7 +971,7 @@ static int update_local_ref(struct ref *ref,
957
971
}
958
972
959
973
r = s_update_ref (msg , ref , transaction , 0 );
960
- format_display (display , r ? '!' : '*' , what ,
974
+ format_display (display_state , display , r ? '!' : '*' , what ,
961
975
r ? _ ("unable to update local ref" ) : NULL ,
962
976
remote , pretty_ref , summary_width );
963
977
return r ;
@@ -979,7 +993,7 @@ static int update_local_ref(struct ref *ref,
979
993
strbuf_addstr (& quickref , ".." );
980
994
strbuf_add_unique_abbrev (& quickref , & ref -> new_oid , DEFAULT_ABBREV );
981
995
r = s_update_ref ("fast-forward" , ref , transaction , 1 );
982
- format_display (display , r ? '!' : ' ' , quickref .buf ,
996
+ format_display (display_state , display , r ? '!' : ' ' , quickref .buf ,
983
997
r ? _ ("unable to update local ref" ) : NULL ,
984
998
remote , pretty_ref , summary_width );
985
999
strbuf_release (& quickref );
@@ -991,13 +1005,13 @@ static int update_local_ref(struct ref *ref,
991
1005
strbuf_addstr (& quickref , "..." );
992
1006
strbuf_add_unique_abbrev (& quickref , & ref -> new_oid , DEFAULT_ABBREV );
993
1007
r = s_update_ref ("forced-update" , ref , transaction , 1 );
994
- format_display (display , r ? '!' : '+' , quickref .buf ,
1008
+ format_display (display_state , display , r ? '!' : '+' , quickref .buf ,
995
1009
r ? _ ("unable to update local ref" ) : _ ("forced update" ),
996
1010
remote , pretty_ref , summary_width );
997
1011
strbuf_release (& quickref );
998
1012
return r ;
999
1013
} else {
1000
- format_display (display , '!' , _ ("[rejected]" ), _ ("non-fast-forward" ),
1014
+ format_display (display_state , display , '!' , _ ("[rejected]" ), _ ("non-fast-forward" ),
1001
1015
remote , pretty_ref , summary_width );
1002
1016
return 1 ;
1003
1017
}
@@ -1108,7 +1122,8 @@ N_("it took %.2f seconds to check forced updates; you can use\n"
1108
1122
"'--no-show-forced-updates' or run 'git config fetch.showForcedUpdates false'\n"
1109
1123
"to avoid this check\n" );
1110
1124
1111
- static int store_updated_refs (const char * raw_url , const char * remote_name ,
1125
+ static int store_updated_refs (struct display_state * display_state ,
1126
+ const char * raw_url , const char * remote_name ,
1112
1127
int connectivity_checked ,
1113
1128
struct ref_transaction * transaction , struct ref * ref_map ,
1114
1129
struct fetch_head * fetch_head )
@@ -1139,8 +1154,6 @@ static int store_updated_refs(const char *raw_url, const char *remote_name,
1139
1154
}
1140
1155
}
1141
1156
1142
- prepare_format_display (ref_map );
1143
-
1144
1157
/*
1145
1158
* We do a pass for each fetch_head_status type in their enum order, so
1146
1159
* merged entries are written before not-for-merge. That lets readers
@@ -1240,7 +1253,7 @@ static int store_updated_refs(const char *raw_url, const char *remote_name,
1240
1253
1241
1254
strbuf_reset (& note );
1242
1255
if (ref ) {
1243
- rc |= update_local_ref (ref , transaction , what ,
1256
+ rc |= update_local_ref (ref , transaction , display_state , what ,
1244
1257
rm , & note , summary_width );
1245
1258
free (ref );
1246
1259
} else if (write_fetch_head || dry_run ) {
@@ -1249,7 +1262,7 @@ static int store_updated_refs(const char *raw_url, const char *remote_name,
1249
1262
* would be written to FETCH_HEAD, if --dry-run
1250
1263
* is set).
1251
1264
*/
1252
- format_display (& note , '*' ,
1265
+ format_display (display_state , & note , '*' ,
1253
1266
* kind ? kind : "branch" , NULL ,
1254
1267
* what ? what : "HEAD" ,
1255
1268
"FETCH_HEAD" , summary_width );
@@ -1328,7 +1341,8 @@ static int check_exist_and_connected(struct ref *ref_map)
1328
1341
return check_connected (iterate_ref_map , & rm , & opt );
1329
1342
}
1330
1343
1331
- static int fetch_and_consume_refs (struct transport * transport ,
1344
+ static int fetch_and_consume_refs (struct display_state * display_state ,
1345
+ struct transport * transport ,
1332
1346
struct ref_transaction * transaction ,
1333
1347
struct ref * ref_map ,
1334
1348
struct fetch_head * fetch_head )
@@ -1352,7 +1366,7 @@ static int fetch_and_consume_refs(struct transport *transport,
1352
1366
}
1353
1367
1354
1368
trace2_region_enter ("fetch" , "consume_refs" , the_repository );
1355
- ret = store_updated_refs (transport -> url , transport -> remote -> name ,
1369
+ ret = store_updated_refs (display_state , transport -> url , transport -> remote -> name ,
1356
1370
connectivity_checked , transaction , ref_map ,
1357
1371
fetch_head );
1358
1372
trace2_region_leave ("fetch" , "consume_refs" , the_repository );
@@ -1362,7 +1376,8 @@ static int fetch_and_consume_refs(struct transport *transport,
1362
1376
return ret ;
1363
1377
}
1364
1378
1365
- static int prune_refs (struct refspec * rs ,
1379
+ static int prune_refs (struct display_state * display_state ,
1380
+ struct refspec * rs ,
1366
1381
struct ref_transaction * transaction ,
1367
1382
struct ref * ref_map ,
1368
1383
const char * raw_url )
@@ -1416,7 +1431,7 @@ static int prune_refs(struct refspec *rs,
1416
1431
fprintf (stderr , _ ("From %.*s\n" ), url_len , url );
1417
1432
shown_url = 1 ;
1418
1433
}
1419
- format_display (& sb , '-' , _ ("[deleted]" ), NULL ,
1434
+ format_display (display_state , & sb , '-' , _ ("[deleted]" ), NULL ,
1420
1435
_ ("(none)" ), prettify_refname (ref -> name ),
1421
1436
summary_width );
1422
1437
fprintf (stderr , " %s\n" ,sb .buf );
@@ -1542,7 +1557,8 @@ static struct transport *prepare_transport(struct remote *remote, int deepen)
1542
1557
return transport ;
1543
1558
}
1544
1559
1545
- static int backfill_tags (struct transport * transport ,
1560
+ static int backfill_tags (struct display_state * display_state ,
1561
+ struct transport * transport ,
1546
1562
struct ref_transaction * transaction ,
1547
1563
struct ref * ref_map ,
1548
1564
struct fetch_head * fetch_head )
@@ -1566,7 +1582,7 @@ static int backfill_tags(struct transport *transport,
1566
1582
transport_set_option (transport , TRANS_OPT_FOLLOWTAGS , NULL );
1567
1583
transport_set_option (transport , TRANS_OPT_DEPTH , "0" );
1568
1584
transport_set_option (transport , TRANS_OPT_DEEPEN_RELATIVE , NULL );
1569
- retcode = fetch_and_consume_refs (transport , transaction , ref_map , fetch_head );
1585
+ retcode = fetch_and_consume_refs (display_state , transport , transaction , ref_map , fetch_head );
1570
1586
1571
1587
if (gsecondary ) {
1572
1588
transport_disconnect (gsecondary );
@@ -1581,6 +1597,7 @@ static int do_fetch(struct transport *transport,
1581
1597
{
1582
1598
struct ref_transaction * transaction = NULL ;
1583
1599
struct ref * ref_map = NULL ;
1600
+ struct display_state display_state ;
1584
1601
int autotags = (transport -> remote -> fetch_tags == 1 );
1585
1602
int retcode = 0 ;
1586
1603
const struct ref * remote_refs ;
@@ -1662,6 +1679,8 @@ static int do_fetch(struct transport *transport,
1662
1679
if (retcode )
1663
1680
goto cleanup ;
1664
1681
1682
+ display_state_init (& display_state , ref_map );
1683
+
1665
1684
if (atomic_fetch ) {
1666
1685
transaction = ref_transaction_begin (& err );
1667
1686
if (!transaction ) {
@@ -1679,17 +1698,17 @@ static int do_fetch(struct transport *transport,
1679
1698
* don't care whether --tags was specified.
1680
1699
*/
1681
1700
if (rs -> nr ) {
1682
- retcode = prune_refs (rs , transaction , ref_map , transport -> url );
1701
+ retcode = prune_refs (& display_state , rs , transaction , ref_map , transport -> url );
1683
1702
} else {
1684
- retcode = prune_refs (& transport -> remote -> fetch ,
1703
+ retcode = prune_refs (& display_state , & transport -> remote -> fetch ,
1685
1704
transaction , ref_map ,
1686
1705
transport -> url );
1687
1706
}
1688
1707
if (retcode != 0 )
1689
1708
retcode = 1 ;
1690
1709
}
1691
1710
1692
- if (fetch_and_consume_refs (transport , transaction , ref_map , & fetch_head )) {
1711
+ if (fetch_and_consume_refs (& display_state , transport , transaction , ref_map , & fetch_head )) {
1693
1712
retcode = 1 ;
1694
1713
goto cleanup ;
1695
1714
}
@@ -1711,7 +1730,7 @@ static int do_fetch(struct transport *transport,
1711
1730
* when `--atomic` is passed: in that case we'll abort
1712
1731
* the transaction and don't commit anything.
1713
1732
*/
1714
- if (backfill_tags (transport , transaction , tags_ref_map ,
1733
+ if (backfill_tags (& display_state , transport , transaction , tags_ref_map ,
1715
1734
& fetch_head ))
1716
1735
retcode = 1 ;
1717
1736
}
0 commit comments