Coverage Report

Created: 2020-05-07 18:36

/proc/self/cwd/c/reftable.c
Line
Count
Source (jump to first uncovered line)
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 "reftable.h"
10
#include "record.h"
11
#include "reader.h"
12
#include "merged.h"
13
14
struct reftable_table_vtable {
15
  int (*seek)(void *tab, struct reftable_iterator *it, struct record);
16
};
17
18
static int reftable_reader_seek_void(void *tab, struct reftable_iterator *it,
19
             struct record rec)
20
10
{
21
10
  return reader_seek((struct reftable_reader *)tab, it, rec);
22
10
}
23
24
static struct reftable_table_vtable reader_vtable = {
25
  .seek = reftable_reader_seek_void,
26
};
27
28
static int reftable_merged_table_seek_void(void *tab,
29
             struct reftable_iterator *it,
30
             struct record rec)
31
226
{
32
226
  return merged_table_seek_record((struct reftable_merged_table *)tab, it,
33
226
          rec);
34
226
}
35
36
static struct reftable_table_vtable merged_table_vtable = {
37
  .seek = reftable_merged_table_seek_void,
38
};
39
40
int reftable_table_seek_ref(struct reftable_table tab,
41
          struct reftable_iterator *it, const char *name)
42
236
{
43
236
  struct reftable_ref_record ref = {
44
236
    .ref_name = (char *)name,
45
236
  };
46
236
  struct record rec = { 0 };
47
236
  record_from_ref(&rec, &ref);
48
236
  return tab.ops->seek(tab.table_arg, it, rec);
49
236
}
50
51
void reftable_table_from_reader(struct reftable_table *tab,
52
        struct reftable_reader *reader)
53
2
{
54
2
  assert(tab->ops == NULL);
55
2
  tab->ops = &reader_vtable;
56
2
  tab->table_arg = reader;
57
2
}
58
59
void reftable_table_from_merged_table(struct reftable_table *tab,
60
              struct reftable_merged_table *merged)
61
140
{
62
140
  assert(tab->ops == NULL);
63
140
  tab->ops = &merged_table_vtable;
64
140
  tab->table_arg = merged;
65
140
}
66
67
int reftable_table_read_ref(struct reftable_table tab, const char *name,
68
          struct reftable_ref_record *ref)
69
121
{
70
121
  struct reftable_iterator it = { 0 };
71
121
  int err = reftable_table_seek_ref(tab, &it, name);
72
121
  if (err) {
73
0
    goto exit;
74
0
  }
75
121
76
121
  err = reftable_iterator_next_ref(it, ref);
77
121
  if (err) {
78
10
    goto exit;
79
10
  }
80
111
81
111
  if (strcmp(ref->ref_name, name) ||
82
111
      reftable_ref_record_is_deletion(ref)) {
83
105
    reftable_ref_record_clear(ref);
84
105
    err = 1;
85
105
    goto exit;
86
105
  }
87
121
88
121
exit:
89
121
  reftable_iterator_destroy(&it);
90
121
  return err;
91
111
}