]> git.ipfire.org Git - thirdparty/git.git/blob - reftable/reftable-record.h
Merge branch 'rs/no-openssl-compilation-fix-on-macos'
[thirdparty/git.git] / reftable / reftable-record.h
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 "hash-ll.h"
13 #include <stdint.h>
14
15 /*
16 * Basic data types
17 *
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.
20 */
21
22 /* reftable_ref_record holds a ref database entry target_value */
23 struct reftable_ref_record {
24 char *refname; /* Name of the ref, malloced. */
25 size_t refname_cap;
26 uint64_t update_index; /* Logical timestamp at which this value is
27 * written */
28
29 enum {
30 /* tombstone to hide deletions from earlier tables */
31 REFTABLE_REF_DELETION = 0x0,
32
33 /* a simple ref */
34 REFTABLE_REF_VAL1 = 0x1,
35 /* a tag, plus its peeled hash */
36 REFTABLE_REF_VAL2 = 0x2,
37
38 /* a symbolic reference */
39 REFTABLE_REF_SYMREF = 0x3,
40 #define REFTABLE_NR_REF_VALUETYPES 4
41 } value_type;
42 union {
43 unsigned char val1[GIT_MAX_RAWSZ];
44 struct {
45 unsigned char value[GIT_MAX_RAWSZ]; /* first hash */
46 unsigned char target_value[GIT_MAX_RAWSZ]; /* second hash */
47 } val2;
48 char *symref; /* referent, malloced 0-terminated string */
49 } value;
50 };
51
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);
55
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);
59
60 /* returns whether 'ref' represents a deletion */
61 int reftable_ref_record_is_deletion(const struct reftable_ref_record *ref);
62
63 /* prints a reftable_ref_record onto stdout. Useful for debugging. */
64 void reftable_ref_record_print(const struct reftable_ref_record *ref,
65 uint32_t hash_id);
66
67 /* frees and nulls all pointer values inside `ref`. */
68 void reftable_ref_record_release(struct reftable_ref_record *ref);
69
70 /* returns whether two reftable_ref_records are the same. Useful for testing. */
71 int reftable_ref_record_equal(const struct reftable_ref_record *a,
72 const struct reftable_ref_record *b, int hash_size);
73
74 /* reftable_log_record holds a reflog entry */
75 struct reftable_log_record {
76 char *refname;
77 size_t refname_cap;
78 uint64_t update_index; /* logical timestamp of a transactional update.
79 */
80
81 enum {
82 /* tombstone to hide deletions from earlier tables */
83 REFTABLE_LOG_DELETION = 0x0,
84
85 /* a simple update */
86 REFTABLE_LOG_UPDATE = 0x1,
87 #define REFTABLE_NR_LOG_VALUETYPES 2
88 } value_type;
89
90 union {
91 struct {
92 unsigned char new_hash[GIT_MAX_RAWSZ];
93 unsigned char old_hash[GIT_MAX_RAWSZ];
94 char *name;
95 char *email;
96 uint64_t time;
97 int16_t tz_offset;
98 char *message;
99 size_t message_cap;
100 } update;
101 } value;
102 };
103
104 /* returns whether 'ref' represents the deletion of a log record. */
105 int reftable_log_record_is_deletion(const struct reftable_log_record *log);
106
107 /* frees and nulls all pointer values. */
108 void reftable_log_record_release(struct reftable_log_record *log);
109
110 /* returns whether two records are equal. Useful for testing. */
111 int reftable_log_record_equal(const struct reftable_log_record *a,
112 const struct reftable_log_record *b, int hash_size);
113
114 /* dumps a reftable_log_record on stdout, for debugging/testing. */
115 void reftable_log_record_print(struct reftable_log_record *log,
116 uint32_t hash_id);
117
118 #endif