48
48
};
49
49
50
50
struct display_state {
51
+ struct strbuf buf ;
52
+
51
53
int refcol_width ;
52
54
int compact_format ;
53
55
@@ -787,6 +789,8 @@ static void display_state_init(struct display_state *display_state, struct ref *
787
789
788
790
memset (display_state , 0 , sizeof (* display_state ));
789
791
792
+ strbuf_init (& display_state -> buf , 0 );
793
+
790
794
if (raw_url )
791
795
display_state -> url = transport_anonymize_url (raw_url );
792
796
else
@@ -834,14 +838,15 @@ static void display_state_init(struct display_state *display_state, struct ref *
834
838
835
839
static void display_state_release (struct display_state * display_state )
836
840
{
841
+ strbuf_release (& display_state -> buf );
837
842
free (display_state -> url );
838
843
}
839
844
840
845
static void print_remote_to_local (struct display_state * display_state ,
841
- struct strbuf * display_buffer ,
842
846
const char * remote , const char * local )
843
847
{
844
- strbuf_addf (display_buffer , "%-*s -> %s" , display_state -> refcol_width , remote , local );
848
+ strbuf_addf (& display_state -> buf , "%-*s -> %s" ,
849
+ display_state -> refcol_width , remote , local );
845
850
}
846
851
847
852
static int find_and_replace (struct strbuf * haystack ,
@@ -871,14 +876,14 @@ static int find_and_replace(struct strbuf *haystack,
871
876
return 1 ;
872
877
}
873
878
874
- static void print_compact (struct display_state * display_state , struct strbuf * display_buffer ,
879
+ static void print_compact (struct display_state * display_state ,
875
880
const char * remote , const char * local )
876
881
{
877
882
struct strbuf r = STRBUF_INIT ;
878
883
struct strbuf l = STRBUF_INIT ;
879
884
880
885
if (!strcmp (remote , local )) {
881
- strbuf_addf (display_buffer , "%-*s -> *" , display_state -> refcol_width , remote );
886
+ strbuf_addf (& display_state -> buf , "%-*s -> *" , display_state -> refcol_width , remote );
882
887
return ;
883
888
}
884
889
@@ -887,46 +892,49 @@ static void print_compact(struct display_state *display_state, struct strbuf *di
887
892
888
893
if (!find_and_replace (& r , local , "*" ))
889
894
find_and_replace (& l , remote , "*" );
890
- print_remote_to_local (display_state , display_buffer , r .buf , l .buf );
895
+ print_remote_to_local (display_state , r .buf , l .buf );
891
896
892
897
strbuf_release (& r );
893
898
strbuf_release (& l );
894
899
}
895
900
896
- static void format_display (struct display_state * display_state ,
897
- struct strbuf * display_buffer , char code ,
898
- const char * summary , const char * error ,
899
- const char * remote , const char * local ,
900
- int summary_width )
901
+ static void display_ref_update (struct display_state * display_state , char code ,
902
+ const char * summary , const char * error ,
903
+ const char * remote , const char * local ,
904
+ int summary_width )
901
905
{
902
906
int width ;
903
907
904
908
if (verbosity < 0 )
905
909
return ;
906
910
911
+ strbuf_reset (& display_state -> buf );
912
+
907
913
if (!display_state -> shown_url ) {
908
- strbuf_addf (display_buffer , _ ("From %.*s\n" ),
914
+ strbuf_addf (& display_state -> buf , _ ("From %.*s\n" ),
909
915
display_state -> url_len , display_state -> url );
910
916
display_state -> shown_url = 1 ;
911
917
}
912
918
913
919
width = (summary_width + strlen (summary ) - gettext_width (summary ));
914
920
915
- strbuf_addf (display_buffer , " %c %-*s " , code , width , summary );
921
+ strbuf_addf (& display_state -> buf , " %c %-*s " , code , width , summary );
916
922
if (!display_state -> compact_format )
917
- print_remote_to_local (display_state , display_buffer , remote , prettify_refname (local ));
923
+ print_remote_to_local (display_state , remote , prettify_refname (local ));
918
924
else
919
- print_compact (display_state , display_buffer , remote , prettify_refname (local ));
925
+ print_compact (display_state , remote , prettify_refname (local ));
920
926
if (error )
921
- strbuf_addf (display_buffer , " (%s)" , error );
922
- strbuf_addch (display_buffer , '\n' );
927
+ strbuf_addf (& display_state -> buf , " (%s)" , error );
928
+ strbuf_addch (& display_state -> buf , '\n' );
929
+
930
+ fputs (display_state -> buf .buf , stderr );
923
931
}
924
932
925
933
static int update_local_ref (struct ref * ref ,
926
934
struct ref_transaction * transaction ,
927
935
struct display_state * display_state ,
928
936
const char * remote , const struct ref * remote_ref ,
929
- struct strbuf * display , int summary_width )
937
+ int summary_width )
930
938
{
931
939
struct commit * current = NULL , * updated ;
932
940
int fast_forward = 0 ;
@@ -936,8 +944,8 @@ static int update_local_ref(struct ref *ref,
936
944
937
945
if (oideq (& ref -> old_oid , & ref -> new_oid )) {
938
946
if (verbosity > 0 )
939
- format_display (display_state , display , '=' , _ ("[up to date]" ), NULL ,
940
- remote , ref -> name , summary_width );
947
+ display_ref_update (display_state , '=' , _ ("[up to date]" ), NULL ,
948
+ remote , ref -> name , summary_width );
941
949
return 0 ;
942
950
}
943
951
@@ -948,9 +956,9 @@ static int update_local_ref(struct ref *ref,
948
956
* If this is the head, and it's not okay to update
949
957
* the head, and the old value of the head isn't empty...
950
958
*/
951
- format_display (display_state , display , '!' , _ ("[rejected]" ),
952
- _ ("can't fetch into checked-out branch" ),
953
- remote , ref -> name , summary_width );
959
+ display_ref_update (display_state , '!' , _ ("[rejected]" ),
960
+ _ ("can't fetch into checked-out branch" ),
961
+ remote , ref -> name , summary_width );
954
962
return 1 ;
955
963
}
956
964
@@ -959,14 +967,14 @@ static int update_local_ref(struct ref *ref,
959
967
if (force || ref -> force ) {
960
968
int r ;
961
969
r = s_update_ref ("updating tag" , ref , transaction , 0 );
962
- format_display (display_state , display , r ? '!' : 't' , _ ("[tag update]" ),
963
- r ? _ ("unable to update local ref" ) : NULL ,
964
- remote , ref -> name , summary_width );
970
+ display_ref_update (display_state , r ? '!' : 't' , _ ("[tag update]" ),
971
+ r ? _ ("unable to update local ref" ) : NULL ,
972
+ remote , ref -> name , summary_width );
965
973
return r ;
966
974
} else {
967
- format_display (display_state , display , '!' , _ ("[rejected]" ),
968
- _ ("would clobber existing tag" ),
969
- remote , ref -> name , summary_width );
975
+ display_ref_update (display_state , '!' , _ ("[rejected]" ),
976
+ _ ("would clobber existing tag" ),
977
+ remote , ref -> name , summary_width );
970
978
return 1 ;
971
979
}
972
980
}
@@ -997,9 +1005,9 @@ static int update_local_ref(struct ref *ref,
997
1005
}
998
1006
999
1007
r = s_update_ref (msg , ref , transaction , 0 );
1000
- format_display (display_state , display , r ? '!' : '*' , what ,
1001
- r ? _ ("unable to update local ref" ) : NULL ,
1002
- remote , ref -> name , summary_width );
1008
+ display_ref_update (display_state , r ? '!' : '*' , what ,
1009
+ r ? _ ("unable to update local ref" ) : NULL ,
1010
+ remote , ref -> name , summary_width );
1003
1011
return r ;
1004
1012
}
1005
1013
@@ -1019,9 +1027,9 @@ static int update_local_ref(struct ref *ref,
1019
1027
strbuf_addstr (& quickref , ".." );
1020
1028
strbuf_add_unique_abbrev (& quickref , & ref -> new_oid , DEFAULT_ABBREV );
1021
1029
r = s_update_ref ("fast-forward" , ref , transaction , 1 );
1022
- format_display (display_state , display , r ? '!' : ' ' , quickref .buf ,
1023
- r ? _ ("unable to update local ref" ) : NULL ,
1024
- remote , ref -> name , summary_width );
1030
+ display_ref_update (display_state , r ? '!' : ' ' , quickref .buf ,
1031
+ r ? _ ("unable to update local ref" ) : NULL ,
1032
+ remote , ref -> name , summary_width );
1025
1033
strbuf_release (& quickref );
1026
1034
return r ;
1027
1035
} else if (force || ref -> force ) {
@@ -1031,14 +1039,14 @@ static int update_local_ref(struct ref *ref,
1031
1039
strbuf_addstr (& quickref , "..." );
1032
1040
strbuf_add_unique_abbrev (& quickref , & ref -> new_oid , DEFAULT_ABBREV );
1033
1041
r = s_update_ref ("forced-update" , ref , transaction , 1 );
1034
- format_display (display_state , display , r ? '!' : '+' , quickref .buf ,
1035
- r ? _ ("unable to update local ref" ) : _ ("forced update" ),
1036
- remote , ref -> name , summary_width );
1042
+ display_ref_update (display_state , r ? '!' : '+' , quickref .buf ,
1043
+ r ? _ ("unable to update local ref" ) : _ ("forced update" ),
1044
+ remote , ref -> name , summary_width );
1037
1045
strbuf_release (& quickref );
1038
1046
return r ;
1039
1047
} else {
1040
- format_display (display_state , display , '!' , _ ("[rejected]" ), _ ("non-fast-forward" ),
1041
- remote , ref -> name , summary_width );
1048
+ display_ref_update (display_state , '!' , _ ("[rejected]" ), _ ("non-fast-forward" ),
1049
+ remote , ref -> name , summary_width );
1042
1050
return 1 ;
1043
1051
}
1044
1052
}
@@ -1266,24 +1274,21 @@ static int store_updated_refs(struct display_state *display_state,
1266
1274
note .buf , display_state -> url ,
1267
1275
display_state -> url_len );
1268
1276
1269
- strbuf_reset (& note );
1270
1277
if (ref ) {
1271
1278
rc |= update_local_ref (ref , transaction , display_state , what ,
1272
- rm , & note , summary_width );
1279
+ rm , summary_width );
1273
1280
free (ref );
1274
1281
} else if (write_fetch_head || dry_run ) {
1275
1282
/*
1276
1283
* Display fetches written to FETCH_HEAD (or
1277
1284
* would be written to FETCH_HEAD, if --dry-run
1278
1285
* is set).
1279
1286
*/
1280
- format_display (display_state , & note , '*' ,
1281
- * kind ? kind : "branch" , NULL ,
1282
- * what ? what : "HEAD" ,
1283
- "FETCH_HEAD" , summary_width );
1287
+ display_ref_update (display_state , '*' ,
1288
+ * kind ? kind : "branch" , NULL ,
1289
+ * what ? what : "HEAD" ,
1290
+ "FETCH_HEAD" , summary_width );
1284
1291
}
1285
- if (note .len )
1286
- fputs (note .buf , stderr );
1287
1292
}
1288
1293
}
1289
1294
@@ -1419,12 +1424,9 @@ static int prune_refs(struct display_state *display_state,
1419
1424
int summary_width = transport_summary_width (stale_refs );
1420
1425
1421
1426
for (ref = stale_refs ; ref ; ref = ref -> next ) {
1422
- struct strbuf sb = STRBUF_INIT ;
1423
- format_display (display_state , & sb , '-' , _ ("[deleted]" ), NULL ,
1424
- _ ("(none)" ), ref -> name ,
1425
- summary_width );
1426
- fputs (sb .buf , stderr );
1427
- strbuf_release (& sb );
1427
+ display_ref_update (display_state , '-' , _ ("[deleted]" ), NULL ,
1428
+ _ ("(none)" ), ref -> name ,
1429
+ summary_width );
1428
1430
warn_dangling_symref (stderr , dangling_msg , ref -> name );
1429
1431
}
1430
1432
}
0 commit comments