235
enum { S_BARE, S_GRADE, S_SIGNER, S_KEY,
236
S_FINGERPRINT, S_PRI_KEY_FP, S_TRUST_LEVEL } option;
237
} signature;
238
+ struct {
239
+ struct commit *commit;
240
+ } base;
241
struct strvec describe_args;
242
struct refname_atom refname;
243
char *head;
894
return 0;
895
}
896
894
-static int ahead_behind_atom_parser(struct ref_format *format,
895
- struct used_atom *atom UNUSED,
897
+static int ahead_behind_atom_parser(struct ref_format *format UNUSED,
898
+ struct used_atom *atom,
899
const char *arg, struct strbuf *err)
900
{
898
- struct string_list_item *item;
899
-
901
if (!arg)
902
return strbuf_addf_ret(err, -1, _("expected format: %%(ahead-behind:<committish>)"));
903
903
- item = string_list_append(&format->bases, arg);
904
- item->util = lookup_commit_reference_by_name(arg);
905
- if (!item->util)
904
+ atom->u.base.commit = lookup_commit_reference_by_name(arg);
905
+ if (!atom->u.base.commit)
906
die("failed to find '%s'", arg);
907
908
return 0;
3084
}
3085
3086
void filter_ahead_behind(struct repository *r,
3087
- struct ref_format *format,
3087
struct ref_array *array)
3088
{
3089
struct commit **commits;
3091
- size_t commits_nr = format->bases.nr + array->nr;
3090
+ size_t bases_nr, commits_nr;
3091
3093
- if (!format->bases.nr || !array->nr)
3092
+ if (!array->nr)
3093
return;
3094
3096
- ALLOC_ARRAY(commits, commits_nr);
3097
- for (size_t i = 0; i < format->bases.nr; i++)
3098
- commits[i] = format->bases.items[i].util;
3095
+ for (size_t i = bases_nr = 0; i < used_atom_cnt; i++) {
3096
+ if (used_atom[i].atom_type == ATOM_AHEADBEHIND)
3097
+ bases_nr++;
3098
+ }
3099
+ if (!bases_nr)
3100
+ return;
3101
3100
- ALLOC_ARRAY(array->counts, st_mult(format->bases.nr, array->nr));
3102
+ ALLOC_ARRAY(commits, st_add(bases_nr, array->nr));
3103
+ for (size_t i = 0, j = 0; i < used_atom_cnt; i++) {
3104
+ if (used_atom[i].atom_type == ATOM_AHEADBEHIND)
3105
+ commits[j++] = used_atom[i].u.base.commit;
3106
+ }
3107
3102
- commits_nr = format->bases.nr;
3108
+ ALLOC_ARRAY(array->counts, st_mult(bases_nr, array->nr));
3109
+
3110
+ commits_nr = bases_nr;
3111
array->counts_nr = 0;
3112
for (size_t i = 0; i < array->nr; i++) {
3113
const char *name = array->items[i]->refname;
3116
if (!commits[commits_nr])
3117
continue;
3118
3111
- CALLOC_ARRAY(array->items[i]->counts, format->bases.nr);
3112
- for (size_t j = 0; j < format->bases.nr; j++) {
3119
+ CALLOC_ARRAY(array->items[i]->counts, bases_nr);
3120
+ for (size_t j = 0; j < bases_nr; j++) {
3121
struct ahead_behind_count *count;
3122
count = &array->counts[array->counts_nr++];
3123
count->tip_index = commits_nr;
3285
* - filtering on reachability
3286
* - including ahead-behind information in the formatted output
3287
*/
3288
+ for (size_t i = 0; i < used_atom_cnt; i++) {
3289
+ if (used_atom[i].atom_type == ATOM_AHEADBEHIND)
3290
+ return 0;
3291
+ }
3292
return !(filter->reachable_from ||
3293
filter->unreachable_from ||
3282
- format->bases.nr ||
3294
format->is_base_tips.nr);
3295
}
3296
3314
} else {
3315
struct ref_array array = { 0 };
3316
filter_refs(&array, filter, type);
3306
- filter_ahead_behind(the_repository, format, &array);
3317
+ filter_ahead_behind(the_repository, &array);
3318
filter_is_base(the_repository, format, &array);
3319
ref_array_sort(sorting, &array);
3320
print_formatted_ref_array(&array, format);
3658
3659
void ref_format_clear(struct ref_format *format)
3660
{
3650
- string_list_clear(&format->bases, 0);
3661
string_list_clear(&format->is_base_tips, 0);
3662
ref_format_init(format);
3663
}