]> git.ipfire.org Git - thirdparty/git.git/blame - reftable/reftable-record.h
Merge branch 'vd/fsck-submodule-url-test'
[thirdparty/git.git] / reftable / reftable-record.h
CommitLineData
e303bf22
HWN
1/*
2Copyright 2020 Google LLC
3
4Use of this source code is governed by a BSD-style
5license that can be found in the LICENSE file or at
6https://developers.google.com/open-source/licenses/bsd
7*/
8
9#ifndef REFTABLE_RECORD_H
10#define REFTABLE_RECORD_H
11
7af607c5 12#include "hash-ll.h"
e303bf22
HWN
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 */
23struct reftable_ref_record {
24 char *refname; /* Name of the ref, malloced. */
25 uint64_t update_index; /* Logical timestamp at which this value is
26 * written */
27
28 enum {
29 /* tombstone to hide deletions from earlier tables */
30 REFTABLE_REF_DELETION = 0x0,
31
32 /* a simple ref */
33 REFTABLE_REF_VAL1 = 0x1,
34 /* a tag, plus its peeled hash */
35 REFTABLE_REF_VAL2 = 0x2,
36
37 /* a symbolic reference */
38 REFTABLE_REF_SYMREF = 0x3,
39#define REFTABLE_NR_REF_VALUETYPES 4
40 } value_type;
41 union {
7af607c5 42 unsigned char val1[GIT_MAX_RAWSZ];
e303bf22 43 struct {
b31e3cc6
PS
44 unsigned char value[GIT_MAX_RAWSZ]; /* first hash */
45 unsigned char target_value[GIT_MAX_RAWSZ]; /* second hash */
e303bf22
HWN
46 } val2;
47 char *symref; /* referent, malloced 0-terminated string */
48 } value;
49};
50
51/* Returns the first hash, or NULL if `rec` is not of type
52 * REFTABLE_REF_VAL1 or REFTABLE_REF_VAL2. */
88f59d9e 53const unsigned char *reftable_ref_record_val1(const struct reftable_ref_record *rec);
e303bf22
HWN
54
55/* Returns the second hash, or NULL if `rec` is not of type
56 * REFTABLE_REF_VAL2. */
88f59d9e 57const unsigned char *reftable_ref_record_val2(const struct reftable_ref_record *rec);
e303bf22
HWN
58
59/* returns whether 'ref' represents a deletion */
60int reftable_ref_record_is_deletion(const struct reftable_ref_record *ref);
61
62/* prints a reftable_ref_record onto stdout. Useful for debugging. */
a94b9450 63void reftable_ref_record_print(const struct reftable_ref_record *ref,
e303bf22
HWN
64 uint32_t hash_id);
65
66/* frees and nulls all pointer values inside `ref`. */
67void reftable_ref_record_release(struct reftable_ref_record *ref);
68
69/* returns whether two reftable_ref_records are the same. Useful for testing. */
a94b9450
HWN
70int reftable_ref_record_equal(const struct reftable_ref_record *a,
71 const struct reftable_ref_record *b, int hash_size);
e303bf22
HWN
72
73/* reftable_log_record holds a reflog entry */
74struct reftable_log_record {
75 char *refname;
76 uint64_t update_index; /* logical timestamp of a transactional update.
77 */
78
79 enum {
80 /* tombstone to hide deletions from earlier tables */
81 REFTABLE_LOG_DELETION = 0x0,
82
83 /* a simple update */
84 REFTABLE_LOG_UPDATE = 0x1,
85#define REFTABLE_NR_LOG_VALUETYPES 2
86 } value_type;
87
88 union {
89 struct {
90 uint8_t *new_hash;
91 uint8_t *old_hash;
92 char *name;
93 char *email;
94 uint64_t time;
95 int16_t tz_offset;
96 char *message;
97 } update;
98 } value;
99};
100
101/* returns whether 'ref' represents the deletion of a log record. */
102int reftable_log_record_is_deletion(const struct reftable_log_record *log);
103
104/* frees and nulls all pointer values. */
105void reftable_log_record_release(struct reftable_log_record *log);
106
107/* returns whether two records are equal. Useful for testing. */
a94b9450
HWN
108int reftable_log_record_equal(const struct reftable_log_record *a,
109 const struct reftable_log_record *b, int hash_size);
e303bf22
HWN
110
111/* dumps a reftable_log_record on stdout, for debugging/testing. */
112void reftable_log_record_print(struct reftable_log_record *log,
113 uint32_t hash_id);
114
115#endif