Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.kernel.org/pub/scm/git/git.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorÆvar Arnfjörð Bjarmason <avarab@gmail.com>2021-01-07 12:51:51 +0300
committerJunio C Hamano <gitster@pobox.com>2021-01-08 02:13:21 +0300
commit7c269a7b162027d0465d52203e778903a2ddbdbf (patch)
treef36f9bd2273e9dce33d596752aa99d73d18940b1 /ref-filter.c
parentd0947483a3386204918447775b617ab3dac833b0 (diff)
ref-filter: move ref_sorting flags to a bitfield
Change the reverse/ignore_case/version sort flags in the ref_sorting struct into a bitfield. Having three of them was already a bit unwieldy, but it would be even more so if another flag needed a function like ref_sorting_icase_all() introduced in 76f9e569adb (ref-filter: apply --ignore-case to all sorting keys, 2020-05-03). A follow-up change will introduce such a flag, so let's move this over to a bitfield. Instead of using the usual '#define' pattern I'm using the "enum" pattern from builtin/rebase.c's b4c8eb024af (builtin rebase: support --quiet, 2018-09-04). Perhaps there's a more idiomatic way of doing the "for each in list amend mask" pattern than this "mask/on" variable combo. This function doesn't allow us to e.g. do any arbitrary changes to the bitfield for multiple flags, but I think in this case that's fine. The common case is that we're calling this with a list of one. Signed-off-by: Ævar Arnfjörð Bjarmason <avarab@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Diffstat (limited to 'ref-filter.c')
-rw-r--r--ref-filter.c24
1 files changed, 15 insertions, 9 deletions
diff --git a/ref-filter.c b/ref-filter.c
index 8882128cd3..fe587afb80 100644
--- a/ref-filter.c
+++ b/ref-filter.c
@@ -2362,11 +2362,12 @@ static int cmp_ref_sorting(struct ref_sorting *s, struct ref_array_item *a, stru
if (get_ref_atom_value(b, s->atom, &vb, &err))
die("%s", err.buf);
strbuf_release(&err);
- if (s->version) {
+ if (s->sort_flags & REF_SORTING_VERSION) {
cmp = versioncmp(va->s, vb->s);
} else if (cmp_type == FIELD_STR) {
int (*cmp_fn)(const char *, const char *);
- cmp_fn = s->ignore_case ? strcasecmp : strcmp;
+ cmp_fn = s->sort_flags & REF_SORTING_ICASE
+ ? strcasecmp : strcmp;
cmp = cmp_fn(va->s, vb->s);
} else {
if (va->value < vb->value)
@@ -2377,7 +2378,7 @@ static int cmp_ref_sorting(struct ref_sorting *s, struct ref_array_item *a, stru
cmp = 1;
}
- return (s->reverse) ? -cmp : cmp;
+ return (s->sort_flags & REF_SORTING_REVERSE) ? -cmp : cmp;
}
static int compare_refs(const void *a_, const void *b_, void *ref_sorting)
@@ -2392,15 +2393,20 @@ static int compare_refs(const void *a_, const void *b_, void *ref_sorting)
return cmp;
}
s = ref_sorting;
- return s && s->ignore_case ?
+ return s && s->sort_flags & REF_SORTING_ICASE ?
strcasecmp(a->refname, b->refname) :
strcmp(a->refname, b->refname);
}
-void ref_sorting_icase_all(struct ref_sorting *sorting, int flag)
+void ref_sorting_set_sort_flags_all(struct ref_sorting *sorting,
+ unsigned int mask, int on)
{
- for (; sorting; sorting = sorting->next)
- sorting->ignore_case = !!flag;
+ for (; sorting; sorting = sorting->next) {
+ if (on)
+ sorting->sort_flags |= mask;
+ else
+ sorting->sort_flags &= ~mask;
+ }
}
void ref_array_sort(struct ref_sorting *sorting, struct ref_array *array)
@@ -2537,12 +2543,12 @@ void parse_ref_sorting(struct ref_sorting **sorting_tail, const char *arg)
*sorting_tail = s;
if (*arg == '-') {
- s->reverse = 1;
+ s->sort_flags |= REF_SORTING_REVERSE;
arg++;
}
if (skip_prefix(arg, "version:", &arg) ||
skip_prefix(arg, "v:", &arg))
- s->version = 1;
+ s->sort_flags |= REF_SORTING_VERSION;
s->atom = parse_sorting_atom(arg);
}