refs: always treat iterators as ordered
In the preceding commit we have converted the reflog iterator of the "files" backend to be ordered, which was the only remaining ref iterator that wasn't ordered. Refactor the ref iterator infrastructure so that we always assume iterators to be ordered, thus simplifying the code. Signed-off-by: Patrick Steinhardt <ps@pks.im> Signed-off-by: Junio C Hamano <gitster@pobox.com>
This commit is contained in:

committed by
Junio C Hamano

parent
6f22780017
commit
5e01d83841
@ -25,11 +25,9 @@ int ref_iterator_abort(struct ref_iterator *ref_iterator)
|
||||
}
|
||||
|
||||
void base_ref_iterator_init(struct ref_iterator *iter,
|
||||
struct ref_iterator_vtable *vtable,
|
||||
int ordered)
|
||||
struct ref_iterator_vtable *vtable)
|
||||
{
|
||||
iter->vtable = vtable;
|
||||
iter->ordered = !!ordered;
|
||||
iter->refname = NULL;
|
||||
iter->oid = NULL;
|
||||
iter->flags = 0;
|
||||
@ -74,7 +72,7 @@ struct ref_iterator *empty_ref_iterator_begin(void)
|
||||
struct empty_ref_iterator *iter = xcalloc(1, sizeof(*iter));
|
||||
struct ref_iterator *ref_iterator = &iter->base;
|
||||
|
||||
base_ref_iterator_init(ref_iterator, &empty_ref_iterator_vtable, 1);
|
||||
base_ref_iterator_init(ref_iterator, &empty_ref_iterator_vtable);
|
||||
return ref_iterator;
|
||||
}
|
||||
|
||||
@ -250,7 +248,6 @@ static struct ref_iterator_vtable merge_ref_iterator_vtable = {
|
||||
};
|
||||
|
||||
struct ref_iterator *merge_ref_iterator_begin(
|
||||
int ordered,
|
||||
struct ref_iterator *iter0, struct ref_iterator *iter1,
|
||||
ref_iterator_select_fn *select, void *cb_data)
|
||||
{
|
||||
@ -265,7 +262,7 @@ struct ref_iterator *merge_ref_iterator_begin(
|
||||
* references through only if they exist in both iterators.
|
||||
*/
|
||||
|
||||
base_ref_iterator_init(ref_iterator, &merge_ref_iterator_vtable, ordered);
|
||||
base_ref_iterator_init(ref_iterator, &merge_ref_iterator_vtable);
|
||||
iter->iter0 = iter0;
|
||||
iter->iter1 = iter1;
|
||||
iter->select = select;
|
||||
@ -314,12 +311,9 @@ struct ref_iterator *overlay_ref_iterator_begin(
|
||||
} else if (is_empty_ref_iterator(back)) {
|
||||
ref_iterator_abort(back);
|
||||
return front;
|
||||
} else if (!front->ordered || !back->ordered) {
|
||||
BUG("overlay_ref_iterator requires ordered inputs");
|
||||
}
|
||||
|
||||
return merge_ref_iterator_begin(1, front, back,
|
||||
overlay_iterator_select, NULL);
|
||||
return merge_ref_iterator_begin(front, back, overlay_iterator_select, NULL);
|
||||
}
|
||||
|
||||
struct prefix_ref_iterator {
|
||||
@ -358,16 +352,12 @@ static int prefix_ref_iterator_advance(struct ref_iterator *ref_iterator)
|
||||
|
||||
if (cmp > 0) {
|
||||
/*
|
||||
* If the source iterator is ordered, then we
|
||||
* As the source iterator is ordered, we
|
||||
* can stop the iteration as soon as we see a
|
||||
* refname that comes after the prefix:
|
||||
*/
|
||||
if (iter->iter0->ordered) {
|
||||
ok = ref_iterator_abort(iter->iter0);
|
||||
break;
|
||||
} else {
|
||||
continue;
|
||||
}
|
||||
ok = ref_iterator_abort(iter->iter0);
|
||||
break;
|
||||
}
|
||||
|
||||
if (iter->trim) {
|
||||
@ -439,7 +429,7 @@ struct ref_iterator *prefix_ref_iterator_begin(struct ref_iterator *iter0,
|
||||
CALLOC_ARRAY(iter, 1);
|
||||
ref_iterator = &iter->base;
|
||||
|
||||
base_ref_iterator_init(ref_iterator, &prefix_ref_iterator_vtable, iter0->ordered);
|
||||
base_ref_iterator_init(ref_iterator, &prefix_ref_iterator_vtable);
|
||||
|
||||
iter->iter0 = iter0;
|
||||
iter->prefix = xstrdup(prefix);
|
||||
|
Reference in New Issue
Block a user