Merge branch 'jc/fix-ref-sorting-parse'

Things like "git -c branch.sort=bogus branch new HEAD", i.e. the
operation modes of the "git branch" command that do not need the
sort key information, no longer errors out by seeing a bogus sort
key.

* jc/fix-ref-sorting-parse:
  for-each-ref: delay parsing of --sort=<atom> options
This commit is contained in:
Junio C Hamano
2021-11-29 15:41:47 -08:00
8 changed files with 96 additions and 53 deletions

View File

@ -2470,6 +2470,12 @@ static int memcasecmp(const void *vs1, const void *vs2, size_t n)
return 0;
}
struct ref_sorting {
struct ref_sorting *next;
int atom; /* index into used_atom array (internal) */
enum ref_sorting_order sort_flags;
};
static int cmp_ref_sorting(struct ref_sorting *s, struct ref_array_item *a, struct ref_array_item *b)
{
struct atom_value *va, *vb;
@ -2663,7 +2669,7 @@ static int parse_sorting_atom(const char *atom)
}
/* If no sorting option is given, use refname to sort as default */
struct ref_sorting *ref_default_sorting(void)
static struct ref_sorting *ref_default_sorting(void)
{
static const char cstr_name[] = "refname";
@ -2674,7 +2680,7 @@ struct ref_sorting *ref_default_sorting(void)
return sorting;
}
void parse_ref_sorting(struct ref_sorting **sorting_tail, const char *arg)
static void parse_ref_sorting(struct ref_sorting **sorting_tail, const char *arg)
{
struct ref_sorting *s;
@ -2692,17 +2698,25 @@ void parse_ref_sorting(struct ref_sorting **sorting_tail, const char *arg)
s->atom = parse_sorting_atom(arg);
}
int parse_opt_ref_sorting(const struct option *opt, const char *arg, int unset)
struct ref_sorting *ref_sorting_options(struct string_list *options)
{
/*
* NEEDSWORK: We should probably clear the list in this case, but we've
* already munged the global used_atoms list, which would need to be
* undone.
*/
BUG_ON_OPT_NEG(unset);
struct string_list_item *item;
struct ref_sorting *sorting = NULL, **tail = &sorting;
parse_ref_sorting(opt->value, arg);
return 0;
if (!options->nr) {
sorting = ref_default_sorting();
} else {
for_each_string_list_item(item, options)
parse_ref_sorting(tail, item->string);
}
/*
* From here on, the ref_sorting list should be used to talk
* about the sort order used for the output. The caller
* should not touch the string form anymore.
*/
string_list_clear(options, 0);
return sorting;
}
void ref_sorting_release(struct ref_sorting *sorting)