2 Copyright 2020 Google LLC
4 Use of this source code is governed by a BSD-style
5 license that can be found in the LICENSE file or at
6 https://developers.google.com/open-source/licenses/bsd
12 #include "reftable-iterator.h"
13 #include "reftable-generic.h"
15 int reftable_table_seek_ref(struct reftable_table
*tab
,
16 struct reftable_iterator
*it
, const char *name
)
18 struct reftable_ref_record ref
= {
19 .refname
= (char *)name
,
21 struct reftable_record rec
= { NULL
};
22 reftable_record_from_ref(&rec
, &ref
);
23 return tab
->ops
->seek_record(tab
->table_arg
, it
, &rec
);
26 int reftable_table_read_ref(struct reftable_table
*tab
, const char *name
,
27 struct reftable_ref_record
*ref
)
29 struct reftable_iterator it
= { NULL
};
30 int err
= reftable_table_seek_ref(tab
, &it
, name
);
34 err
= reftable_iterator_next_ref(&it
, ref
);
38 if (strcmp(ref
->refname
, name
) ||
39 reftable_ref_record_is_deletion(ref
)) {
40 reftable_ref_record_release(ref
);
46 reftable_iterator_destroy(&it
);
50 uint64_t reftable_table_max_update_index(struct reftable_table
*tab
)
52 return tab
->ops
->max_update_index(tab
->table_arg
);
55 uint64_t reftable_table_min_update_index(struct reftable_table
*tab
)
57 return tab
->ops
->min_update_index(tab
->table_arg
);
60 uint32_t reftable_table_hash_id(struct reftable_table
*tab
)
62 return tab
->ops
->hash_id(tab
->table_arg
);
65 void reftable_iterator_destroy(struct reftable_iterator
*it
)
70 it
->ops
->close(it
->iter_arg
);
72 FREE_AND_NULL(it
->iter_arg
);
75 int reftable_iterator_next_ref(struct reftable_iterator
*it
,
76 struct reftable_ref_record
*ref
)
78 struct reftable_record rec
= { NULL
};
79 reftable_record_from_ref(&rec
, ref
);
80 return iterator_next(it
, &rec
);
83 int reftable_iterator_next_log(struct reftable_iterator
*it
,
84 struct reftable_log_record
*log
)
86 struct reftable_record rec
= { NULL
};
87 reftable_record_from_log(&rec
, log
);
88 return iterator_next(it
, &rec
);
91 int iterator_next(struct reftable_iterator
*it
, struct reftable_record
*rec
)
93 return it
->ops
->next(it
->iter_arg
, rec
);
96 static int empty_iterator_next(void *arg
, struct reftable_record
*rec
)
101 static void empty_iterator_close(void *arg
)
105 static struct reftable_iterator_vtable empty_vtable
= {
106 .next
= &empty_iterator_next
,
107 .close
= &empty_iterator_close
,
110 void iterator_set_empty(struct reftable_iterator
*it
)
114 it
->ops
= &empty_vtable
;