]>
Commit | Line | Data |
---|---|---|
e303bf22 HWN |
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 | #ifndef REFTABLE_RECORD_H | |
10 | #define REFTABLE_RECORD_H | |
11 | ||
12 | #include <stdint.h> | |
13 | ||
14 | /* | |
15 | * Basic data types | |
16 | * | |
17 | * Reftables store the state of each ref in struct reftable_ref_record, and they | |
18 | * store a sequence of reflog updates in struct reftable_log_record. | |
19 | */ | |
20 | ||
21 | /* reftable_ref_record holds a ref database entry target_value */ | |
22 | struct reftable_ref_record { | |
23 | char *refname; /* Name of the ref, malloced. */ | |
24 | uint64_t update_index; /* Logical timestamp at which this value is | |
25 | * written */ | |
26 | ||
27 | enum { | |
28 | /* tombstone to hide deletions from earlier tables */ | |
29 | REFTABLE_REF_DELETION = 0x0, | |
30 | ||
31 | /* a simple ref */ | |
32 | REFTABLE_REF_VAL1 = 0x1, | |
33 | /* a tag, plus its peeled hash */ | |
34 | REFTABLE_REF_VAL2 = 0x2, | |
35 | ||
36 | /* a symbolic reference */ | |
37 | REFTABLE_REF_SYMREF = 0x3, | |
38 | #define REFTABLE_NR_REF_VALUETYPES 4 | |
39 | } value_type; | |
40 | union { | |
41 | uint8_t *val1; /* malloced hash. */ | |
42 | struct { | |
43 | uint8_t *value; /* first value, malloced hash */ | |
44 | uint8_t *target_value; /* second value, malloced hash */ | |
45 | } val2; | |
46 | char *symref; /* referent, malloced 0-terminated string */ | |
47 | } value; | |
48 | }; | |
49 | ||
50 | /* Returns the first hash, or NULL if `rec` is not of type | |
51 | * REFTABLE_REF_VAL1 or REFTABLE_REF_VAL2. */ | |
a94b9450 | 52 | uint8_t *reftable_ref_record_val1(const struct reftable_ref_record *rec); |
e303bf22 HWN |
53 | |
54 | /* Returns the second hash, or NULL if `rec` is not of type | |
55 | * REFTABLE_REF_VAL2. */ | |
a94b9450 | 56 | uint8_t *reftable_ref_record_val2(const struct reftable_ref_record *rec); |
e303bf22 HWN |
57 | |
58 | /* returns whether 'ref' represents a deletion */ | |
59 | int reftable_ref_record_is_deletion(const struct reftable_ref_record *ref); | |
60 | ||
61 | /* prints a reftable_ref_record onto stdout. Useful for debugging. */ | |
a94b9450 | 62 | void reftable_ref_record_print(const struct reftable_ref_record *ref, |
e303bf22 HWN |
63 | uint32_t hash_id); |
64 | ||
65 | /* frees and nulls all pointer values inside `ref`. */ | |
66 | void reftable_ref_record_release(struct reftable_ref_record *ref); | |
67 | ||
68 | /* returns whether two reftable_ref_records are the same. Useful for testing. */ | |
a94b9450 HWN |
69 | int reftable_ref_record_equal(const struct reftable_ref_record *a, |
70 | const struct reftable_ref_record *b, int hash_size); | |
e303bf22 HWN |
71 | |
72 | /* reftable_log_record holds a reflog entry */ | |
73 | struct reftable_log_record { | |
74 | char *refname; | |
75 | uint64_t update_index; /* logical timestamp of a transactional update. | |
76 | */ | |
77 | ||
78 | enum { | |
79 | /* tombstone to hide deletions from earlier tables */ | |
80 | REFTABLE_LOG_DELETION = 0x0, | |
81 | ||
82 | /* a simple update */ | |
83 | REFTABLE_LOG_UPDATE = 0x1, | |
84 | #define REFTABLE_NR_LOG_VALUETYPES 2 | |
85 | } value_type; | |
86 | ||
87 | union { | |
88 | struct { | |
89 | uint8_t *new_hash; | |
90 | uint8_t *old_hash; | |
91 | char *name; | |
92 | char *email; | |
93 | uint64_t time; | |
94 | int16_t tz_offset; | |
95 | char *message; | |
96 | } update; | |
97 | } value; | |
98 | }; | |
99 | ||
100 | /* returns whether 'ref' represents the deletion of a log record. */ | |
101 | int reftable_log_record_is_deletion(const struct reftable_log_record *log); | |
102 | ||
103 | /* frees and nulls all pointer values. */ | |
104 | void reftable_log_record_release(struct reftable_log_record *log); | |
105 | ||
106 | /* returns whether two records are equal. Useful for testing. */ | |
a94b9450 HWN |
107 | int reftable_log_record_equal(const struct reftable_log_record *a, |
108 | const struct reftable_log_record *b, int hash_size); | |
e303bf22 HWN |
109 | |
110 | /* dumps a reftable_log_record on stdout, for debugging/testing. */ | |
111 | void reftable_log_record_print(struct reftable_log_record *log, | |
112 | uint32_t hash_id); | |
113 | ||
114 | #endif |