@@ -242,6 +242,12 @@ static struct used_atom {
242
242
} * used_atom ;
243
243
static int used_atom_cnt , need_tagged , need_symref ;
244
244
245
+ /* List of bases for ahead-behind counts. */
246
+ static struct string_list bases = STRING_LIST_INIT_DUP ;
247
+
248
+ /* List of bases for is-base indicators. */
249
+ static struct string_list is_base_tips = STRING_LIST_INIT_DUP ;
250
+
245
251
/*
246
252
* Expand string, append it to strbuf *sb, then return error code ret.
247
253
* Allow to save few lines of code.
@@ -891,7 +897,7 @@ static int rest_atom_parser(struct ref_format *format UNUSED,
891
897
return 0 ;
892
898
}
893
899
894
- static int ahead_behind_atom_parser (struct ref_format * format ,
900
+ static int ahead_behind_atom_parser (struct ref_format * format UNUSED ,
895
901
struct used_atom * atom UNUSED ,
896
902
const char * arg , struct strbuf * err )
897
903
{
@@ -900,15 +906,15 @@ static int ahead_behind_atom_parser(struct ref_format *format,
900
906
if (!arg )
901
907
return strbuf_addf_ret (err , -1 , _ ("expected format: %%(ahead-behind:<committish>)" ));
902
908
903
- item = string_list_append (& format -> bases , arg );
909
+ item = string_list_append (& bases , arg );
904
910
item -> util = lookup_commit_reference_by_name (arg );
905
911
if (!item -> util )
906
912
die ("failed to find '%s'" , arg );
907
913
908
914
return 0 ;
909
915
}
910
916
911
- static int is_base_atom_parser (struct ref_format * format ,
917
+ static int is_base_atom_parser (struct ref_format * format UNUSED ,
912
918
struct used_atom * atom UNUSED ,
913
919
const char * arg , struct strbuf * err )
914
920
{
@@ -917,7 +923,7 @@ static int is_base_atom_parser(struct ref_format *format,
917
923
if (!arg )
918
924
return strbuf_addf_ret (err , -1 , _ ("expected format: %%(is-base:<committish>)" ));
919
925
920
- item = string_list_append (& format -> is_base_tips , arg );
926
+ item = string_list_append (& is_base_tips , arg );
921
927
item -> util = lookup_commit_reference_by_name (arg );
922
928
if (!item -> util )
923
929
die ("failed to find '%s'" , arg );
@@ -3024,6 +3030,8 @@ void ref_array_clear(struct ref_array *array)
3024
3030
}
3025
3031
FREE_AND_NULL (used_atom );
3026
3032
used_atom_cnt = 0 ;
3033
+ string_list_clear (& bases , 0 );
3034
+ string_list_clear (& is_base_tips , 0 );
3027
3035
3028
3036
if (ref_to_worktree_map .worktrees ) {
3029
3037
hashmap_clear_and_free (& (ref_to_worktree_map .map ),
@@ -3084,22 +3092,21 @@ static void reach_filter(struct ref_array *array,
3084
3092
}
3085
3093
3086
3094
void filter_ahead_behind (struct repository * r ,
3087
- struct ref_format * format ,
3088
3095
struct ref_array * array )
3089
3096
{
3090
3097
struct commit * * commits ;
3091
- size_t commits_nr = format -> bases .nr + array -> nr ;
3098
+ size_t commits_nr = bases .nr + array -> nr ;
3092
3099
3093
- if (!format -> bases .nr || !array -> nr )
3100
+ if (!bases .nr || !array -> nr )
3094
3101
return ;
3095
3102
3096
3103
ALLOC_ARRAY (commits , commits_nr );
3097
- for (size_t i = 0 ; i < format -> bases .nr ; i ++ )
3098
- commits [i ] = format -> bases .items [i ].util ;
3104
+ for (size_t i = 0 ; i < bases .nr ; i ++ )
3105
+ commits [i ] = bases .items [i ].util ;
3099
3106
3100
- ALLOC_ARRAY (array -> counts , st_mult (format -> bases .nr , array -> nr ));
3107
+ ALLOC_ARRAY (array -> counts , st_mult (bases .nr , array -> nr ));
3101
3108
3102
- commits_nr = format -> bases .nr ;
3109
+ commits_nr = bases .nr ;
3103
3110
array -> counts_nr = 0 ;
3104
3111
for (size_t i = 0 ; i < array -> nr ; i ++ ) {
3105
3112
const char * name = array -> items [i ]-> refname ;
@@ -3108,8 +3115,8 @@ void filter_ahead_behind(struct repository *r,
3108
3115
if (!commits [commits_nr ])
3109
3116
continue ;
3110
3117
3111
- CALLOC_ARRAY (array -> items [i ]-> counts , format -> bases .nr );
3112
- for (size_t j = 0 ; j < format -> bases .nr ; j ++ ) {
3118
+ CALLOC_ARRAY (array -> items [i ]-> counts , bases .nr );
3119
+ for (size_t j = 0 ; j < bases .nr ; j ++ ) {
3113
3120
struct ahead_behind_count * count ;
3114
3121
count = & array -> counts [array -> counts_nr ++ ];
3115
3122
count -> tip_index = commits_nr ;
@@ -3125,14 +3132,13 @@ void filter_ahead_behind(struct repository *r,
3125
3132
}
3126
3133
3127
3134
void filter_is_base (struct repository * r ,
3128
- struct ref_format * format ,
3129
3135
struct ref_array * array )
3130
3136
{
3131
3137
struct commit * * bases ;
3132
3138
size_t bases_nr = 0 ;
3133
3139
struct ref_array_item * * back_index ;
3134
3140
3135
- if (!format -> is_base_tips .nr || !array -> nr )
3141
+ if (!is_base_tips .nr || !array -> nr )
3136
3142
return ;
3137
3143
3138
3144
CALLOC_ARRAY (back_index , array -> nr );
@@ -3142,7 +3148,7 @@ void filter_is_base(struct repository *r,
3142
3148
const char * name = array -> items [i ]-> refname ;
3143
3149
struct commit * c = lookup_commit_reference_by_name_gently (name , 1 );
3144
3150
3145
- CALLOC_ARRAY (array -> items [i ]-> is_base , format -> is_base_tips .nr );
3151
+ CALLOC_ARRAY (array -> items [i ]-> is_base , is_base_tips .nr );
3146
3152
3147
3153
if (!c )
3148
3154
continue ;
@@ -3152,15 +3158,15 @@ void filter_is_base(struct repository *r,
3152
3158
bases_nr ++ ;
3153
3159
}
3154
3160
3155
- for (size_t i = 0 ; i < format -> is_base_tips .nr ; i ++ ) {
3156
- struct commit * tip = format -> is_base_tips .items [i ].util ;
3161
+ for (size_t i = 0 ; i < is_base_tips .nr ; i ++ ) {
3162
+ struct commit * tip = is_base_tips .items [i ].util ;
3157
3163
int base_index = get_branch_base_for_tip (r , tip , bases , bases_nr );
3158
3164
3159
3165
if (base_index < 0 )
3160
3166
continue ;
3161
3167
3162
3168
/* Store the string for use in output later. */
3163
- back_index [base_index ]-> is_base [i ] = xstrdup (format -> is_base_tips .items [i ].string );
3169
+ back_index [base_index ]-> is_base [i ] = xstrdup (is_base_tips .items [i ].string );
3164
3170
}
3165
3171
3166
3172
free (back_index );
@@ -3252,8 +3258,7 @@ struct ref_sorting {
3252
3258
};
3253
3259
3254
3260
static inline int can_do_iterative_format (struct ref_filter * filter ,
3255
- struct ref_sorting * sorting ,
3256
- struct ref_format * format )
3261
+ struct ref_sorting * sorting )
3257
3262
{
3258
3263
/*
3259
3264
* Reference backends sort patterns lexicographically by refname, so if
@@ -3279,15 +3284,15 @@ static inline int can_do_iterative_format(struct ref_filter *filter,
3279
3284
*/
3280
3285
return !(filter -> reachable_from ||
3281
3286
filter -> unreachable_from ||
3282
- format -> bases .nr ||
3283
- format -> is_base_tips .nr );
3287
+ bases .nr ||
3288
+ is_base_tips .nr );
3284
3289
}
3285
3290
3286
3291
void filter_and_format_refs (struct ref_filter * filter , unsigned int type ,
3287
3292
struct ref_sorting * sorting ,
3288
3293
struct ref_format * format )
3289
3294
{
3290
- if (can_do_iterative_format (filter , sorting , format )) {
3295
+ if (can_do_iterative_format (filter , sorting )) {
3291
3296
int save_commit_buffer_orig ;
3292
3297
struct ref_filter_and_format_cbdata ref_cbdata = {
3293
3298
.filter = filter ,
@@ -3303,8 +3308,8 @@ void filter_and_format_refs(struct ref_filter *filter, unsigned int type,
3303
3308
} else {
3304
3309
struct ref_array array = { 0 };
3305
3310
filter_refs (& array , filter , type );
3306
- filter_ahead_behind (the_repository , format , & array );
3307
- filter_is_base (the_repository , format , & array );
3311
+ filter_ahead_behind (the_repository , & array );
3312
+ filter_is_base (the_repository , & array );
3308
3313
ref_array_sort (sorting , & array );
3309
3314
print_formatted_ref_array (& array , format );
3310
3315
ref_array_clear (& array );
@@ -3638,16 +3643,3 @@ void ref_filter_clear(struct ref_filter *filter)
3638
3643
free_commit_list (filter -> unreachable_from );
3639
3644
ref_filter_init (filter );
3640
3645
}
3641
-
3642
- void ref_format_init (struct ref_format * format )
3643
- {
3644
- struct ref_format blank = REF_FORMAT_INIT ;
3645
- memcpy (format , & blank , sizeof (blank ));
3646
- }
3647
-
3648
- void ref_format_clear (struct ref_format * format )
3649
- {
3650
- string_list_clear (& format -> bases , 0 );
3651
- string_list_clear (& format -> is_base_tips , 0 );
3652
- ref_format_init (format );
3653
- }
0 commit comments