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
9 #ifndef REFTABLE_RECORD_H
10 #define REFTABLE_RECORD_H
12 #include "reftable-basics.h"
18 * Reftables store the state of each ref in struct reftable_ref_record, and they
19 * store a sequence of reflog updates in struct reftable_log_record.
22 /* reftable_ref_record holds a ref database entry target_value */
23 struct reftable_ref_record
{
24 char *refname
; /* Name of the ref, malloced. */
26 uint64_t update_index
; /* Logical timestamp at which this value is
30 /* tombstone to hide deletions from earlier tables */
31 REFTABLE_REF_DELETION
= 0x0,
34 REFTABLE_REF_VAL1
= 0x1,
35 /* a tag, plus its peeled hash */
36 REFTABLE_REF_VAL2
= 0x2,
38 /* a symbolic reference */
39 REFTABLE_REF_SYMREF
= 0x3,
40 #define REFTABLE_NR_REF_VALUETYPES 4
43 unsigned char val1
[REFTABLE_HASH_SIZE_MAX
];
45 unsigned char value
[REFTABLE_HASH_SIZE_MAX
]; /* first hash */
46 unsigned char target_value
[REFTABLE_HASH_SIZE_MAX
]; /* second hash */
48 char *symref
; /* referent, malloced 0-terminated string */
52 /* Returns the first hash, or NULL if `rec` is not of type
53 * REFTABLE_REF_VAL1 or REFTABLE_REF_VAL2. */
54 const unsigned char *reftable_ref_record_val1(const struct reftable_ref_record
*rec
);
56 /* Returns the second hash, or NULL if `rec` is not of type
57 * REFTABLE_REF_VAL2. */
58 const unsigned char *reftable_ref_record_val2(const struct reftable_ref_record
*rec
);
60 /* returns whether 'ref' represents a deletion */
61 int reftable_ref_record_is_deletion(const struct reftable_ref_record
*ref
);
63 /* frees and nulls all pointer values inside `ref`. */
64 void reftable_ref_record_release(struct reftable_ref_record
*ref
);
66 /* returns whether two reftable_ref_records are the same. Useful for testing. */
67 int reftable_ref_record_equal(const struct reftable_ref_record
*a
,
68 const struct reftable_ref_record
*b
, uint32_t hash_size
);
70 /* reftable_log_record holds a reflog entry */
71 struct reftable_log_record
{
74 uint64_t update_index
; /* logical timestamp of a transactional update.
78 /* tombstone to hide deletions from earlier tables */
79 REFTABLE_LOG_DELETION
= 0x0,
82 REFTABLE_LOG_UPDATE
= 0x1,
83 #define REFTABLE_NR_LOG_VALUETYPES 2
88 unsigned char new_hash
[REFTABLE_HASH_SIZE_MAX
];
89 unsigned char old_hash
[REFTABLE_HASH_SIZE_MAX
];
100 /* returns whether 'ref' represents the deletion of a log record. */
101 int reftable_log_record_is_deletion(const struct reftable_log_record
*log
);
103 /* frees and nulls all pointer values. */
104 void reftable_log_record_release(struct reftable_log_record
*log
);
106 /* returns whether two records are equal. Useful for testing. */
107 int reftable_log_record_equal(const struct reftable_log_record
*a
,
108 const struct reftable_log_record
*b
, uint32_t hash_size
);