]>
git.ipfire.org Git - thirdparty/git.git/blob - reftable/record.h
da75d7d1f11922b39c276a841435271f909bdc25
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
16 #include "reftable-record.h"
19 * A substring of existing string data. This structure takes no responsibility
20 * for the lifetime of the data it points to.
27 /* Advance `s.buf` by `n`, and decrease length. */
28 void string_view_consume(struct string_view
*s
, int n
);
30 /* utilities for de/encoding varints */
32 int get_var_int(uint64_t *dest
, struct string_view
*in
);
33 int put_var_int(struct string_view
*dest
, uint64_t val
);
35 /* Methods for records. */
36 struct reftable_record_vtable
{
37 /* encode the key of to a uint8_t strbuf. */
38 void (*key
)(const void *rec
, struct strbuf
*dest
);
40 /* The record type of ('r' for ref). */
43 void (*copy_from
)(void *dest
, const void *src
, int hash_size
);
45 /* a value of [0..7], indicating record subvariants (eg. ref vs. symref
47 uint8_t (*val_type
)(const void *rec
);
49 /* encodes rec into dest, returning how much space was used. */
50 int (*encode
)(const void *rec
, struct string_view dest
, int hash_size
);
52 /* decode data from `src` into the record. */
53 int (*decode
)(void *rec
, struct strbuf key
, uint8_t extra
,
54 struct string_view src
, int hash_size
);
56 /* deallocate and null the record. */
57 void (*release
)(void *rec
);
59 /* is this a tombstone? */
60 int (*is_deletion
)(const void *rec
);
62 /* Are two records equal? This assumes they have the same type. Returns 0 for non-equal. */
63 int (*equal
)(const void *a
, const void *b
, int hash_size
);
66 /* record is a generic wrapper for different types of records. */
67 struct reftable_record
{
69 struct reftable_record_vtable
*ops
;
72 /* returns true for recognized block types. Block start with the block type. */
73 int reftable_is_block_type(uint8_t typ
);
75 /* creates a malloced record of the given type. Dispose with record_destroy */
76 struct reftable_record
reftable_new_record(uint8_t typ
);
78 /* Encode `key` into `dest`. Sets `is_restart` to indicate a restart. Returns
79 * number of bytes written. */
80 int reftable_encode_key(int *is_restart
, struct string_view dest
,
81 struct strbuf prev_key
, struct strbuf key
,
84 /* Decode into `key` and `extra` from `in` */
85 int reftable_decode_key(struct strbuf
*key
, uint8_t *extra
,
86 struct strbuf last_key
, struct string_view in
);
88 /* reftable_index_record are used internally to speed up lookups. */
89 struct reftable_index_record
{
90 uint64_t offset
; /* Offset of block */
91 struct strbuf last_key
; /* Last key of the block. */
94 /* reftable_obj_record stores an object ID => ref mapping. */
95 struct reftable_obj_record
{
96 uint8_t *hash_prefix
; /* leading bytes of the object ID */
97 int hash_prefix_len
; /* number of leading bytes. Constant
98 * across a single table. */
99 uint64_t *offsets
; /* a vector of file offsets. */
103 /* see struct record_vtable */
104 int reftable_record_equal(struct reftable_record
*a
, struct reftable_record
*b
, int hash_size
);
105 void reftable_record_key(struct reftable_record
*rec
, struct strbuf
*dest
);
106 uint8_t reftable_record_type(struct reftable_record
*rec
);
107 void reftable_record_copy_from(struct reftable_record
*rec
,
108 struct reftable_record
*src
, int hash_size
);
109 uint8_t reftable_record_val_type(struct reftable_record
*rec
);
110 int reftable_record_encode(struct reftable_record
*rec
, struct string_view dest
,
112 int reftable_record_decode(struct reftable_record
*rec
, struct strbuf key
,
113 uint8_t extra
, struct string_view src
,
115 int reftable_record_is_deletion(struct reftable_record
*rec
);
117 /* zeroes out the embedded record */
118 void reftable_record_release(struct reftable_record
*rec
);
120 /* clear and deallocate embedded record, and zero `rec`. */
121 void reftable_record_destroy(struct reftable_record
*rec
);
123 /* initialize generic records from concrete records. The generic record should
125 void reftable_record_from_obj(struct reftable_record
*rec
,
126 struct reftable_obj_record
*objrec
);
127 void reftable_record_from_index(struct reftable_record
*rec
,
128 struct reftable_index_record
*idxrec
);
129 void reftable_record_from_ref(struct reftable_record
*rec
,
130 struct reftable_ref_record
*refrec
);
131 void reftable_record_from_log(struct reftable_record
*rec
,
132 struct reftable_log_record
*logrec
);
133 struct reftable_ref_record
*reftable_record_as_ref(struct reftable_record
*ref
);
134 struct reftable_log_record
*reftable_record_as_log(struct reftable_record
*ref
);
137 int reftable_ref_record_compare_name(const void *a
, const void *b
);
140 int reftable_log_record_compare_key(const void *a
, const void *b
);