1
-/*
2
-Copyright 2020 Google LLC
3
-
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
7
-*/
8
-
9
-#include "constants.h"
10
-#include "record.h"
11
-#include "generic.h"
12
-#include "iter.h"
13
-#include "reftable-iterator.h"
14
-#include "reftable-generic.h"
15
-
16
-void table_init_iter(struct reftable_table *tab,
17
- struct reftable_iterator *it,
18
- uint8_t typ)
19
-{
20
-
21
- tab->ops->init_iter(tab->table_arg, it, typ);
22
-}
23
-
24
-void reftable_table_init_ref_iter(struct reftable_table *tab,
25
- struct reftable_iterator *it)
26
-{
27
- table_init_iter(tab, it, BLOCK_TYPE_REF);
28
-}
29
-
30
-void reftable_table_init_log_iter(struct reftable_table *tab,
31
- struct reftable_iterator *it)
32
-{
33
- table_init_iter(tab, it, BLOCK_TYPE_LOG);
34
-}
35
-
36
-int reftable_table_read_ref(struct reftable_table *tab, const char *name,
37
- struct reftable_ref_record *ref)
38
-{
39
- struct reftable_iterator it = { NULL };
40
- int err;
41
-
42
- reftable_table_init_ref_iter(tab, &it);
43
-
44
- err = reftable_iterator_seek_ref(&it, name);
45
- if (err)
46
- goto done;
47
-
48
- err = reftable_iterator_next_ref(&it, ref);
49
- if (err)
50
- goto done;
51
-
52
- if (strcmp(ref->refname, name) ||
53
- reftable_ref_record_is_deletion(ref)) {
54
- reftable_ref_record_release(ref);
55
- err = 1;
56
- goto done;
57
- }
58
-
59
-done:
60
- reftable_iterator_destroy(&it);
61
- return err;
62
-}
63
-
64
-uint64_t reftable_table_max_update_index(struct reftable_table *tab)
65
-{
66
- return tab->ops->max_update_index(tab->table_arg);
67
-}
68
-
69
-uint64_t reftable_table_min_update_index(struct reftable_table *tab)
70
-{
71
- return tab->ops->min_update_index(tab->table_arg);
72
-}
73
-
74
-uint32_t reftable_table_hash_id(struct reftable_table *tab)
75
-{
76
- return tab->ops->hash_id(tab->table_arg);
77
-}