aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorTaylor Blau <me@ttaylorr.com>2024-10-30 13:08:02 -0400
committerTaylor Blau <me@ttaylorr.com>2024-10-30 13:08:02 -0400
commit6f763d798b9cfed734c3f2fcc6da37db9a83710e (patch)
treec264d26e56f1af271b391e4ce99de45296156272
parentbc627658b06155a0b1c3d0b1b0bf72db70770dc9 (diff)
parent2e7c6d2f4112dd374f615f4e612e1cebbcb6d431 (diff)
downloadgit-6f763d798b9cfed734c3f2fcc6da37db9a83710e.tar.gz
Merge branch 'ps/ref-filter-sort'
Teaches the ref-filter machinery to recognize and avoid cases where sorting would be redundant. * ps/ref-filter-sort: ref-filter: format iteratively with lexicographic refname sorting
-rw-r--r--ref-filter.c29
1 files changed, 21 insertions, 8 deletions
diff --git a/ref-filter.c b/ref-filter.c
index dd195007ce..84c6036107 100644
--- a/ref-filter.c
+++ b/ref-filter.c
@@ -3244,21 +3244,40 @@ int filter_refs(struct ref_array *array, struct ref_filter *filter, unsigned int
return ret;
}
+struct ref_sorting {
+ struct ref_sorting *next;
+ int atom; /* index into used_atom array (internal) */
+ enum ref_sorting_order sort_flags;
+};
+
static inline int can_do_iterative_format(struct ref_filter *filter,
struct ref_sorting *sorting,
struct ref_format *format)
{
/*
+ * Reference backends sort patterns lexicographically by refname, so if
+ * the sorting options ask for exactly that we are able to do iterative
+ * formatting.
+ *
+ * Note that we do not have to worry about multiple name patterns,
+ * either. Those get sorted and deduplicated eventually in
+ * `refs_for_each_fullref_in_prefixes()`, so we return names in the
+ * correct ordering here, too.
+ */
+ if (sorting && (sorting->next ||
+ sorting->sort_flags ||
+ used_atom[sorting->atom].atom_type != ATOM_REFNAME))
+ return 0;
+
+ /*
* Filtering & formatting results within a single ref iteration
* callback is not compatible with options that require
* post-processing a filtered ref_array. These include:
* - filtering on reachability
- * - sorting the filtered results
* - including ahead-behind information in the formatted output
*/
return !(filter->reachable_from ||
filter->unreachable_from ||
- sorting ||
format->bases.nr ||
format->is_base_tips.nr);
}
@@ -3316,12 +3335,6 @@ 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;