ref-filter: move is-base tip to used_atom
The string_list "is_base_tips" in struct ref_format stores the committish part of "is-base:<committish>". It has the same problems that its sibling string_list "bases" had. Fix them the same way as the previous commit did for the latter, by replacing the string_list with fields in "used_atom". Helped-by: Jeff King <peff@peff.net> Signed-off-by: René Scharfe <l.s.r@web.de> Signed-off-by: Junio C Hamano <gitster@pobox.com>
This commit is contained in:

committed by
Junio C Hamano

parent
5e58db6575
commit
7ee4fd18ac
56
ref-filter.c
56
ref-filter.c
@ -236,6 +236,7 @@ static struct used_atom {
|
|||||||
S_FINGERPRINT, S_PRI_KEY_FP, S_TRUST_LEVEL } option;
|
S_FINGERPRINT, S_PRI_KEY_FP, S_TRUST_LEVEL } option;
|
||||||
} signature;
|
} signature;
|
||||||
struct {
|
struct {
|
||||||
|
char *name;
|
||||||
struct commit *commit;
|
struct commit *commit;
|
||||||
} base;
|
} base;
|
||||||
struct strvec describe_args;
|
struct strvec describe_args;
|
||||||
@ -908,18 +909,16 @@ static int ahead_behind_atom_parser(struct ref_format *format UNUSED,
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int is_base_atom_parser(struct ref_format *format,
|
static int is_base_atom_parser(struct ref_format *format UNUSED,
|
||||||
struct used_atom *atom UNUSED,
|
struct used_atom *atom,
|
||||||
const char *arg, struct strbuf *err)
|
const char *arg, struct strbuf *err)
|
||||||
{
|
{
|
||||||
struct string_list_item *item;
|
|
||||||
|
|
||||||
if (!arg)
|
if (!arg)
|
||||||
return strbuf_addf_ret(err, -1, _("expected format: %%(is-base:<committish>)"));
|
return strbuf_addf_ret(err, -1, _("expected format: %%(is-base:<committish>)"));
|
||||||
|
|
||||||
item = string_list_append(&format->is_base_tips, arg);
|
atom->u.base.name = xstrdup(arg);
|
||||||
item->util = lookup_commit_reference_by_name(arg);
|
atom->u.base.commit = lookup_commit_reference_by_name(arg);
|
||||||
if (!item->util)
|
if (!atom->u.base.commit)
|
||||||
die("failed to find '%s'", arg);
|
die("failed to find '%s'", arg);
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
@ -3009,6 +3008,8 @@ void ref_array_clear(struct ref_array *array)
|
|||||||
free(atom->u.head);
|
free(atom->u.head);
|
||||||
else if (atom->atom_type == ATOM_DESCRIBE)
|
else if (atom->atom_type == ATOM_DESCRIBE)
|
||||||
strvec_clear(&atom->u.describe_args);
|
strvec_clear(&atom->u.describe_args);
|
||||||
|
else if (atom->atom_type == ATOM_ISBASE)
|
||||||
|
free(atom->u.base.name);
|
||||||
else if (atom->atom_type == ATOM_TRAILERS ||
|
else if (atom->atom_type == ATOM_TRAILERS ||
|
||||||
(atom->atom_type == ATOM_CONTENTS &&
|
(atom->atom_type == ATOM_CONTENTS &&
|
||||||
atom->u.contents.option == C_TRAILERS)) {
|
atom->u.contents.option == C_TRAILERS)) {
|
||||||
@ -3133,14 +3134,20 @@ void filter_ahead_behind(struct repository *r,
|
|||||||
}
|
}
|
||||||
|
|
||||||
void filter_is_base(struct repository *r,
|
void filter_is_base(struct repository *r,
|
||||||
struct ref_format *format,
|
|
||||||
struct ref_array *array)
|
struct ref_array *array)
|
||||||
{
|
{
|
||||||
struct commit **bases;
|
struct commit **bases;
|
||||||
size_t bases_nr = 0;
|
size_t bases_nr = 0, is_base_nr;
|
||||||
struct ref_array_item **back_index;
|
struct ref_array_item **back_index;
|
||||||
|
|
||||||
if (!format->is_base_tips.nr || !array->nr)
|
if (!array->nr)
|
||||||
|
return;
|
||||||
|
|
||||||
|
for (size_t i = is_base_nr = 0; i < used_atom_cnt; i++) {
|
||||||
|
if (used_atom[i].atom_type == ATOM_ISBASE)
|
||||||
|
is_base_nr++;
|
||||||
|
}
|
||||||
|
if (!is_base_nr)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
CALLOC_ARRAY(back_index, array->nr);
|
CALLOC_ARRAY(back_index, array->nr);
|
||||||
@ -3150,7 +3157,7 @@ void filter_is_base(struct repository *r,
|
|||||||
const char *name = array->items[i]->refname;
|
const char *name = array->items[i]->refname;
|
||||||
struct commit *c = lookup_commit_reference_by_name_gently(name, 1);
|
struct commit *c = lookup_commit_reference_by_name_gently(name, 1);
|
||||||
|
|
||||||
CALLOC_ARRAY(array->items[i]->is_base, format->is_base_tips.nr);
|
CALLOC_ARRAY(array->items[i]->is_base, is_base_nr);
|
||||||
|
|
||||||
if (!c)
|
if (!c)
|
||||||
continue;
|
continue;
|
||||||
@ -3160,15 +3167,20 @@ void filter_is_base(struct repository *r,
|
|||||||
bases_nr++;
|
bases_nr++;
|
||||||
}
|
}
|
||||||
|
|
||||||
for (size_t i = 0; i < format->is_base_tips.nr; i++) {
|
for (size_t i = 0, j = 0; i < used_atom_cnt; i++) {
|
||||||
struct commit *tip = format->is_base_tips.items[i].util;
|
struct commit *tip;
|
||||||
int base_index = get_branch_base_for_tip(r, tip, bases, bases_nr);
|
int base_index;
|
||||||
|
|
||||||
|
if (used_atom[i].atom_type != ATOM_ISBASE)
|
||||||
|
continue;
|
||||||
|
|
||||||
|
tip = used_atom[i].u.base.commit;
|
||||||
|
base_index = get_branch_base_for_tip(r, tip, bases, bases_nr);
|
||||||
if (base_index < 0)
|
if (base_index < 0)
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
/* Store the string for use in output later. */
|
/* Store the string for use in output later. */
|
||||||
back_index[base_index]->is_base[i] = xstrdup(format->is_base_tips.items[i].string);
|
back_index[base_index]->is_base[j++] = xstrdup(used_atom[i].u.base.name);
|
||||||
}
|
}
|
||||||
|
|
||||||
free(back_index);
|
free(back_index);
|
||||||
@ -3260,8 +3272,7 @@ struct ref_sorting {
|
|||||||
};
|
};
|
||||||
|
|
||||||
static inline int can_do_iterative_format(struct ref_filter *filter,
|
static inline int can_do_iterative_format(struct ref_filter *filter,
|
||||||
struct ref_sorting *sorting,
|
struct ref_sorting *sorting)
|
||||||
struct ref_format *format)
|
|
||||||
{
|
{
|
||||||
/*
|
/*
|
||||||
* Reference backends sort patterns lexicographically by refname, so if
|
* Reference backends sort patterns lexicographically by refname, so if
|
||||||
@ -3288,17 +3299,17 @@ static inline int can_do_iterative_format(struct ref_filter *filter,
|
|||||||
for (size_t i = 0; i < used_atom_cnt; i++) {
|
for (size_t i = 0; i < used_atom_cnt; i++) {
|
||||||
if (used_atom[i].atom_type == ATOM_AHEADBEHIND)
|
if (used_atom[i].atom_type == ATOM_AHEADBEHIND)
|
||||||
return 0;
|
return 0;
|
||||||
|
if (used_atom[i].atom_type == ATOM_ISBASE)
|
||||||
|
return 0;
|
||||||
}
|
}
|
||||||
return !(filter->reachable_from ||
|
return !(filter->reachable_from || filter->unreachable_from);
|
||||||
filter->unreachable_from ||
|
|
||||||
format->is_base_tips.nr);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void filter_and_format_refs(struct ref_filter *filter, unsigned int type,
|
void filter_and_format_refs(struct ref_filter *filter, unsigned int type,
|
||||||
struct ref_sorting *sorting,
|
struct ref_sorting *sorting,
|
||||||
struct ref_format *format)
|
struct ref_format *format)
|
||||||
{
|
{
|
||||||
if (can_do_iterative_format(filter, sorting, format)) {
|
if (can_do_iterative_format(filter, sorting)) {
|
||||||
int save_commit_buffer_orig;
|
int save_commit_buffer_orig;
|
||||||
struct ref_filter_and_format_cbdata ref_cbdata = {
|
struct ref_filter_and_format_cbdata ref_cbdata = {
|
||||||
.filter = filter,
|
.filter = filter,
|
||||||
@ -3315,7 +3326,7 @@ void filter_and_format_refs(struct ref_filter *filter, unsigned int type,
|
|||||||
struct ref_array array = { 0 };
|
struct ref_array array = { 0 };
|
||||||
filter_refs(&array, filter, type);
|
filter_refs(&array, filter, type);
|
||||||
filter_ahead_behind(the_repository, &array);
|
filter_ahead_behind(the_repository, &array);
|
||||||
filter_is_base(the_repository, format, &array);
|
filter_is_base(the_repository, &array);
|
||||||
ref_array_sort(sorting, &array);
|
ref_array_sort(sorting, &array);
|
||||||
print_formatted_ref_array(&array, format);
|
print_formatted_ref_array(&array, format);
|
||||||
ref_array_clear(&array);
|
ref_array_clear(&array);
|
||||||
@ -3658,6 +3669,5 @@ void ref_format_init(struct ref_format *format)
|
|||||||
|
|
||||||
void ref_format_clear(struct ref_format *format)
|
void ref_format_clear(struct ref_format *format)
|
||||||
{
|
{
|
||||||
string_list_clear(&format->is_base_tips, 0);
|
|
||||||
ref_format_init(format);
|
ref_format_init(format);
|
||||||
}
|
}
|
||||||
|
@ -99,9 +99,6 @@ struct ref_format {
|
|||||||
/* Internal state to ref-filter */
|
/* Internal state to ref-filter */
|
||||||
int need_color_reset_at_eol;
|
int need_color_reset_at_eol;
|
||||||
|
|
||||||
/* List of bases for is-base indicators. */
|
|
||||||
struct string_list is_base_tips;
|
|
||||||
|
|
||||||
struct {
|
struct {
|
||||||
int max_count;
|
int max_count;
|
||||||
int omit_empty;
|
int omit_empty;
|
||||||
@ -114,7 +111,6 @@ struct ref_format {
|
|||||||
}
|
}
|
||||||
#define REF_FORMAT_INIT { \
|
#define REF_FORMAT_INIT { \
|
||||||
.use_color = -1, \
|
.use_color = -1, \
|
||||||
.is_base_tips = STRING_LIST_INIT_DUP, \
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Macros for checking --merged and --no-merged options */
|
/* Macros for checking --merged and --no-merged options */
|
||||||
@ -210,7 +206,6 @@ void filter_ahead_behind(struct repository *r,
|
|||||||
* If this is not called, then any is-base atoms will be blank.
|
* If this is not called, then any is-base atoms will be blank.
|
||||||
*/
|
*/
|
||||||
void filter_is_base(struct repository *r,
|
void filter_is_base(struct repository *r,
|
||||||
struct ref_format *format,
|
|
||||||
struct ref_array *array);
|
struct ref_array *array);
|
||||||
|
|
||||||
void ref_filter_init(struct ref_filter *filter);
|
void ref_filter_init(struct ref_filter *filter);
|
||||||
|
@ -733,4 +733,33 @@ test_expect_success 'for-each-ref is-base:multiple' '
|
|||||||
--format="%(refname)[%(is-base:commit-2-3)-%(is-base:commit-6-5)]" --stdin
|
--format="%(refname)[%(is-base:commit-2-3)-%(is-base:commit-6-5)]" --stdin
|
||||||
'
|
'
|
||||||
|
|
||||||
|
test_expect_success 'for-each-ref is-base: --sort' '
|
||||||
|
cat >input <<-\EOF &&
|
||||||
|
refs/heads/commit-1-1
|
||||||
|
refs/heads/commit-4-2
|
||||||
|
refs/heads/commit-4-4
|
||||||
|
refs/heads/commit-8-4
|
||||||
|
EOF
|
||||||
|
|
||||||
|
cat >expect <<-\EOF &&
|
||||||
|
refs/heads/commit-1-1
|
||||||
|
refs/heads/commit-4-4
|
||||||
|
refs/heads/commit-8-4
|
||||||
|
refs/heads/commit-4-2
|
||||||
|
EOF
|
||||||
|
run_all_modes git for-each-ref \
|
||||||
|
--format="%(refname)" --stdin \
|
||||||
|
--sort=refname --sort=is-base:commit-2-3 &&
|
||||||
|
|
||||||
|
cat >expect <<-\EOF &&
|
||||||
|
refs/heads/commit-4-2
|
||||||
|
refs/heads/commit-1-1
|
||||||
|
refs/heads/commit-4-4
|
||||||
|
refs/heads/commit-8-4
|
||||||
|
EOF
|
||||||
|
run_all_modes git for-each-ref \
|
||||||
|
--format="%(refname)" --stdin \
|
||||||
|
--sort=refname --sort=-is-base:commit-2-3
|
||||||
|
'
|
||||||
|
|
||||||
test_done
|
test_done
|
||||||
|
Reference in New Issue
Block a user