reftable/system: stop depending on "hash.h"
We include "hash.h" in "reftable/system.h" such that we can use hash format IDs as well as the raw size of SHA1 and SHA256. As we are in the process of converting the reftable library to become standalone we of course cannot rely on those constants anymore. Introduce a new `enum reftable_hash` to replace internal uses of the hash format IDs and new constants that replace internal uses of the hash size. Adapt the reftable backend to set up the correct hash function. Signed-off-by: Patrick Steinhardt <ps@pks.im> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Patrick Steinhardt committed
Nov 18, 2024 at 16:33 UTC
c2f08236ed786a48e50af33ecc5c0f951c14761b
25 files changed
+166
-143
refs/reftable-backend.c
+11
-1
@@ -15,6 +15,7 @@
15
#include "../object.h"
16
#include "../path.h"
17
#include "../refs.h"
18
+#include "../reftable/reftable-basics.h"
19
#include "../reftable/reftable-stack.h"
20
#include "../reftable/reftable-record.h"
21
#include "../reftable/reftable-error.h"
@@ -289,7 +290,16 @@ static struct ref_store *reftable_be_init(struct repository *repo,
290
refs->store_flags = store_flags;
291
refs->log_all_ref_updates = repo_settings_get_log_all_ref_updates(repo);
292
292
- refs->write_options.hash_id = repo->hash_algo->format_id;
293
+ switch (repo->hash_algo->format_id) {
294
+ case GIT_SHA1_FORMAT_ID:
295
+ refs->write_options.hash_id = REFTABLE_HASH_SHA1;
296
+ break;
297
+ case GIT_SHA256_FORMAT_ID:
298
+ refs->write_options.hash_id = REFTABLE_HASH_SHA256;
299
+ break;
300
+ default:
301
+ BUG("unknown hash algorithm %d", repo->hash_algo->format_id);
302
+ }
303
refs->write_options.default_permissions = calc_shared_perm(0666 & ~mask);
304
refs->write_options.disable_auto_compact =
305
!git_env_bool("GIT_TEST_REFTABLE_AUTOCOMPACTION", 1);
reftable/basics.c
+7
-6
@@ -271,14 +271,15 @@ int common_prefix_size(struct reftable_buf *a, struct reftable_buf *b)
271
return p;
272
}
273
274
-int hash_size(uint32_t id)
274
+int hash_size(enum reftable_hash id)
275
{
276
+ if (!id)
277
+ return REFTABLE_HASH_SIZE_SHA1;
278
switch (id) {
277
- case 0:
278
- case GIT_SHA1_FORMAT_ID:
279
- return GIT_SHA1_RAWSZ;
280
- case GIT_SHA256_FORMAT_ID:
281
- return GIT_SHA256_RAWSZ;
279
+ case REFTABLE_HASH_SHA1:
280
+ return REFTABLE_HASH_SIZE_SHA1;
281
+ case REFTABLE_HASH_SHA256:
282
+ return REFTABLE_HASH_SIZE_SHA256;
283
}
284
abort();
285
}
reftable/basics.h
+1
-1
@@ -148,7 +148,7 @@ char *reftable_strdup(const char *str);
148
/* Find the longest shared prefix size of `a` and `b` */
149
int common_prefix_size(struct reftable_buf *a, struct reftable_buf *b);
150
151
-int hash_size(uint32_t id);
151
+int hash_size(enum reftable_hash id);
152
153
/*
154
* Format IDs that identify the hash function used by a reftable. Note that
reftable/merged.c
+2
-2
@@ -181,7 +181,7 @@ static void iterator_from_merged_iter(struct reftable_iterator *it,
181
182
int reftable_merged_table_new(struct reftable_merged_table **dest,
183
struct reftable_reader **readers, size_t n,
184
- uint32_t hash_id)
184
+ enum reftable_hash hash_id)
185
{
186
struct reftable_merged_table *m = NULL;
187
uint64_t last_max = 0;
@@ -293,7 +293,7 @@ int reftable_merged_table_init_log_iterator(struct reftable_merged_table *mt,
293
return merged_table_init_iter(mt, it, BLOCK_TYPE_LOG);
294
}
295
296
-uint32_t reftable_merged_table_hash_id(struct reftable_merged_table *mt)
296
+enum reftable_hash reftable_merged_table_hash_id(struct reftable_merged_table *mt)
297
{
298
return mt->hash_id;
299
}
reftable/merged.h
+2
-1
@@ -10,11 +10,12 @@ https://developers.google.com/open-source/licenses/bsd
10
#define MERGED_H
11
12
#include "system.h"
13
+#include "reftable-basics.h"
14
15
struct reftable_merged_table {
16
struct reftable_reader **readers;
17
size_t readers_len;
17
- uint32_t hash_id;
18
+ enum reftable_hash hash_id;
19
20
/* If unset, produce deletions. This is useful for compaction. For the
21
* full stack, deletions should be produced. */
reftable/reader.c
+4
-4
@@ -67,7 +67,7 @@ static int reader_get_block(struct reftable_reader *r,
67
return block_source_read_block(&r->source, dest, off, sz);
68
}
69
70
-uint32_t reftable_reader_hash_id(struct reftable_reader *r)
70
+enum reftable_hash reftable_reader_hash_id(struct reftable_reader *r)
71
{
72
return r->hash_id;
73
}
@@ -107,14 +107,14 @@ static int parse_footer(struct reftable_reader *r, uint8_t *footer,
107
f += 8;
108
109
if (r->version == 1) {
110
- r->hash_id = GIT_SHA1_FORMAT_ID;
110
+ r->hash_id = REFTABLE_HASH_SHA1;
111
} else {
112
switch (get_be32(f)) {
113
case REFTABLE_FORMAT_ID_SHA1:
114
- r->hash_id = GIT_SHA1_FORMAT_ID;
114
+ r->hash_id = REFTABLE_HASH_SHA1;
115
break;
116
case REFTABLE_FORMAT_ID_SHA256:
117
- r->hash_id = GIT_SHA256_FORMAT_ID;
117
+ r->hash_id = REFTABLE_HASH_SHA256;
118
break;
119
default:
120
err = REFTABLE_FORMAT_ERROR;
reftable/reader.h
+2
-2
@@ -37,8 +37,8 @@ struct reftable_reader {
37
/* Size of the file, excluding the footer. */
38
uint64_t size;
39
40
- /* 'sha1' for SHA1, 's256' for SHA-256 */
41
- uint32_t hash_id;
40
+ /* The hash function used for ref records. */
41
+ enum reftable_hash hash_id;
42
43
uint32_t block_size;
44
uint64_t min_update_index;
reftable/reftable-basics.h
+13
@@ -11,6 +11,19 @@
11
12
#include <stddef.h>
13
14
+/*
15
+ * Hash functions understood by the reftable library. Note that the values are
16
+ * arbitrary and somewhat random such that we can easily detect cases where the
17
+ * hash hasn't been properly set up.
18
+ */
19
+enum reftable_hash {
20
+ REFTABLE_HASH_SHA1 = 89,
21
+ REFTABLE_HASH_SHA256 = 247,
22
+};
23
+#define REFTABLE_HASH_SIZE_SHA1 20
24
+#define REFTABLE_HASH_SIZE_SHA256 32
25
+#define REFTABLE_HASH_SIZE_MAX REFTABLE_HASH_SIZE_SHA256
26
+
27
/* Overrides the functions to use for memory management. */
28
void reftable_set_alloc(void *(*malloc)(size_t),
29
void *(*realloc)(void *, size_t), void (*free)(void *));
reftable/reftable-merged.h
+2
-2
@@ -34,7 +34,7 @@ struct reftable_reader;
34
*/
35
int reftable_merged_table_new(struct reftable_merged_table **dest,
36
struct reftable_reader **readers, size_t n,
37
- uint32_t hash_id);
37
+ enum reftable_hash hash_id);
38
39
/* Initialize a merged table iterator for reading refs. */
40
int reftable_merged_table_init_ref_iterator(struct reftable_merged_table *mt,
@@ -56,6 +56,6 @@ reftable_merged_table_min_update_index(struct reftable_merged_table *mt);
56
void reftable_merged_table_free(struct reftable_merged_table *m);
57
58
/* return the hash ID of the merged table. */
59
-uint32_t reftable_merged_table_hash_id(struct reftable_merged_table *m);
59
+enum reftable_hash reftable_merged_table_hash_id(struct reftable_merged_table *m);
60
61
#endif
reftable/reftable-reader.h
+1
-1
@@ -54,7 +54,7 @@ int reftable_reader_init_log_iterator(struct reftable_reader *r,
54
struct reftable_iterator *it);
55
56
/* returns the hash ID used in this table. */
57
-uint32_t reftable_reader_hash_id(struct reftable_reader *r);
57
+enum reftable_hash reftable_reader_hash_id(struct reftable_reader *r);
58
59
/* return an iterator for the refs pointing to `oid`. */
60
int reftable_reader_refs_for(struct reftable_reader *r,
reftable/reftable-record.h
+6
-6
@@ -9,7 +9,7 @@ https://developers.google.com/open-source/licenses/bsd
9
#ifndef REFTABLE_RECORD_H
10
#define REFTABLE_RECORD_H
11
12
-#include "hash.h"
12
+#include "reftable-basics.h"
13
#include <stdint.h>
14
15
/*
@@ -40,10 +40,10 @@ struct reftable_ref_record {
40
#define REFTABLE_NR_REF_VALUETYPES 4
41
} value_type;
42
union {
43
- unsigned char val1[GIT_MAX_RAWSZ];
43
+ unsigned char val1[REFTABLE_HASH_SIZE_MAX];
44
struct {
45
- unsigned char value[GIT_MAX_RAWSZ]; /* first hash */
46
- unsigned char target_value[GIT_MAX_RAWSZ]; /* second hash */
45
+ unsigned char value[REFTABLE_HASH_SIZE_MAX]; /* first hash */
46
+ unsigned char target_value[REFTABLE_HASH_SIZE_MAX]; /* second hash */
47
} val2;
48
char *symref; /* referent, malloced 0-terminated string */
49
} value;
@@ -85,8 +85,8 @@ struct reftable_log_record {
85
86
union {
87
struct {
88
- unsigned char new_hash[GIT_MAX_RAWSZ];
89
- unsigned char old_hash[GIT_MAX_RAWSZ];
88
+ unsigned char new_hash[REFTABLE_HASH_SIZE_MAX];
89
+ unsigned char old_hash[REFTABLE_HASH_SIZE_MAX];
90
char *name;
91
char *email;
92
uint64_t time;
reftable/reftable-writer.h
+1
-1
@@ -33,7 +33,7 @@ struct reftable_write_options {
33
/* 4-byte identifier ("sha1", "s256") of the hash.
34
* Defaults to SHA1 if unset
35
*/
36
- uint32_t hash_id;
36
+ enum reftable_hash hash_id;
37
38
/* Default mode for creating files. If unset, use 0666 (+umask) */
39
unsigned int default_permissions;
reftable/stack.c
+2
-2
@@ -73,7 +73,7 @@ int reftable_new_stack(struct reftable_stack **dest, const char *dir,
73
if (_opts)
74
opts = *_opts;
75
if (opts.hash_id == 0)
76
- opts.hash_id = GIT_SHA1_FORMAT_ID;
76
+ opts.hash_id = REFTABLE_HASH_SHA1;
77
78
*dest = NULL;
79
@@ -1603,7 +1603,7 @@ struct segment suggest_compaction_segment(uint64_t *sizes, size_t n,
1603
1604
static uint64_t *stack_table_sizes_for_compaction(struct reftable_stack *st)
1605
{
1606
- int version = (st->opts.hash_id == GIT_SHA1_FORMAT_ID) ? 1 : 2;
1606
+ int version = (st->opts.hash_id == REFTABLE_HASH_SHA1) ? 1 : 2;
1607
int overhead = header_size(version) - 1;
1608
uint64_t *sizes;
1609
reftable/system.h
-3
@@ -14,8 +14,5 @@ https://developers.google.com/open-source/licenses/bsd
14
#include "git-compat-util.h"
15
#include "lockfile.h"
16
#include "tempfile.h"
17
-#include "hash.h" /* hash ID, sizes.*/
18
-
19
-int hash_size(uint32_t id);
17
18
#endif
reftable/writer.c
+4
-4
@@ -79,7 +79,7 @@ static void options_set_defaults(struct reftable_write_options *opts)
79
}
80
81
if (opts->hash_id == 0) {
82
- opts->hash_id = GIT_SHA1_FORMAT_ID;
82
+ opts->hash_id = REFTABLE_HASH_SHA1;
83
}
84
if (opts->block_size == 0) {
85
opts->block_size = DEFAULT_BLOCK_SIZE;
@@ -88,7 +88,7 @@ static void options_set_defaults(struct reftable_write_options *opts)
88
89
static int writer_version(struct reftable_writer *w)
90
{
91
- return (w->opts.hash_id == 0 || w->opts.hash_id == GIT_SHA1_FORMAT_ID) ?
91
+ return (w->opts.hash_id == 0 || w->opts.hash_id == REFTABLE_HASH_SHA1) ?
92
1 :
93
2;
94
}
@@ -106,10 +106,10 @@ static int writer_write_header(struct reftable_writer *w, uint8_t *dest)
106
uint32_t hash_id;
107
108
switch (w->opts.hash_id) {
109
- case GIT_SHA1_FORMAT_ID:
109
+ case REFTABLE_HASH_SHA1:
110
hash_id = REFTABLE_FORMAT_ID_SHA1;
111
break;
112
- case GIT_SHA256_FORMAT_ID:
112
+ case REFTABLE_HASH_SHA256:
113
hash_id = REFTABLE_FORMAT_ID_SHA256;
114
break;
115
default:
t/helper/test-reftable.c
+2
-2
@@ -156,7 +156,7 @@ int cmd__dump_reftable(int argc, const char **argv)
156
int opt_dump_blocks = 0;
157
int opt_dump_table = 0;
158
int opt_dump_stack = 0;
159
- uint32_t opt_hash_id = GIT_SHA1_FORMAT_ID;
159
+ uint32_t opt_hash_id = REFTABLE_HASH_SHA1;
160
const char *arg = NULL, *argv0 = argv[0];
161
162
for (; argc > 1; argv++, argc--)
@@ -167,7 +167,7 @@ int cmd__dump_reftable(int argc, const char **argv)
167
else if (!strcmp("-t", argv[1]))
168
opt_dump_table = 1;
169
else if (!strcmp("-6", argv[1]))
170
- opt_hash_id = GIT_SHA256_FORMAT_ID;
170
+ opt_hash_id = REFTABLE_HASH_SHA256;
171
else if (!strcmp("-s", argv[1]))
172
opt_dump_stack = 1;
173
else if (!strcmp("-?", argv[1]) || !strcmp("-h", argv[1])) {
t/unit-tests/lib-reftable.c
+2
-2
@@ -3,7 +3,7 @@
3
#include "reftable/constants.h"
4
#include "reftable/writer.h"
5
6
-void t_reftable_set_hash(uint8_t *p, int i, uint32_t id)
6
+void t_reftable_set_hash(uint8_t *p, int i, enum reftable_hash id)
7
{
8
memset(p, (uint8_t)i, hash_size(id));
9
}
@@ -82,7 +82,7 @@ void t_reftable_write_to_buf(struct reftable_buf *buf,
82
size_t off = i * (opts.block_size ? opts.block_size
83
: DEFAULT_BLOCK_SIZE);
84
if (!off)
85
- off = header_size(opts.hash_id == GIT_SHA256_FORMAT_ID ? 2 : 1);
85
+ off = header_size(opts.hash_id == REFTABLE_HASH_SHA256 ? 2 : 1);
86
check_char(buf->buf[off], ==, 'r');
87
}
88
t/unit-tests/lib-reftable.h
+1
-1
@@ -6,7 +6,7 @@
6
7
struct reftable_buf;
8
9
-void t_reftable_set_hash(uint8_t *p, int i, uint32_t id);
9
+void t_reftable_set_hash(uint8_t *p, int i, enum reftable_hash id);
10
11
struct reftable_writer *t_reftable_strbuf_writer(struct reftable_buf *buf,
12
struct reftable_write_options *opts);
t/unit-tests/t-reftable-block.c
+20
-20
@@ -36,7 +36,7 @@ static void t_ref_block_read_write(void)
36
block.len = block_size;
37
block_source_from_buf(&block.source ,&buf);
38
ret = block_writer_init(&bw, BLOCK_TYPE_REF, block.data, block_size,
39
- header_off, hash_size(GIT_SHA1_FORMAT_ID));
39
+ header_off, hash_size(REFTABLE_HASH_SHA1));
40
check(!ret);
41
42
rec.u.ref.refname = (char *) "";
@@ -47,7 +47,7 @@ static void t_ref_block_read_write(void)
47
for (i = 0; i < N; i++) {
48
rec.u.ref.refname = xstrfmt("branch%02"PRIuMAX, (uintmax_t)i);
49
rec.u.ref.value_type = REFTABLE_REF_VAL1;
50
- memset(rec.u.ref.value.val1, i, GIT_SHA1_RAWSZ);
50
+ memset(rec.u.ref.value.val1, i, REFTABLE_HASH_SIZE_SHA1);
51
52
recs[i] = rec;
53
ret = block_writer_add(&bw, &rec);
@@ -61,7 +61,7 @@ static void t_ref_block_read_write(void)
61
62
block_writer_release(&bw);
63
64
- block_reader_init(&br, &block, header_off, block_size, GIT_SHA1_RAWSZ);
64
+ block_reader_init(&br, &block, header_off, block_size, REFTABLE_HASH_SIZE_SHA1);
65
66
block_iter_seek_start(&it, &br);
67
@@ -72,7 +72,7 @@ static void t_ref_block_read_write(void)
72
check_int(i, ==, N);
73
break;
74
}
75
- check(reftable_record_equal(&recs[i], &rec, GIT_SHA1_RAWSZ));
75
+ check(reftable_record_equal(&recs[i], &rec, REFTABLE_HASH_SIZE_SHA1));
76
}
77
78
for (i = 0; i < N; i++) {
@@ -85,7 +85,7 @@ static void t_ref_block_read_write(void)
85
ret = block_iter_next(&it, &rec);
86
check_int(ret, ==, 0);
87
88
- check(reftable_record_equal(&recs[i], &rec, GIT_SHA1_RAWSZ));
88
+ check(reftable_record_equal(&recs[i], &rec, REFTABLE_HASH_SIZE_SHA1));
89
90
want.len--;
91
ret = block_iter_seek_key(&it, &br, &want);
@@ -93,7 +93,7 @@ static void t_ref_block_read_write(void)
93
94
ret = block_iter_next(&it, &rec);
95
check_int(ret, ==, 0);
96
- check(reftable_record_equal(&recs[10 * (i / 10)], &rec, GIT_SHA1_RAWSZ));
96
+ check(reftable_record_equal(&recs[10 * (i / 10)], &rec, REFTABLE_HASH_SIZE_SHA1));
97
}
98
99
block_reader_release(&br);
@@ -130,7 +130,7 @@ static void t_log_block_read_write(void)
130
block.len = block_size;
131
block_source_from_buf(&block.source ,&buf);
132
ret = block_writer_init(&bw, BLOCK_TYPE_LOG, block.data, block_size,
133
- header_off, hash_size(GIT_SHA1_FORMAT_ID));
133
+ header_off, hash_size(REFTABLE_HASH_SHA1));
134
check(!ret);
135
136
for (i = 0; i < N; i++) {
@@ -150,7 +150,7 @@ static void t_log_block_read_write(void)
150
151
block_writer_release(&bw);
152
153
- block_reader_init(&br, &block, header_off, block_size, GIT_SHA1_RAWSZ);
153
+ block_reader_init(&br, &block, header_off, block_size, REFTABLE_HASH_SIZE_SHA1);
154
155
block_iter_seek_start(&it, &br);
156
@@ -161,7 +161,7 @@ static void t_log_block_read_write(void)
161
check_int(i, ==, N);
162
break;
163
}
164
- check(reftable_record_equal(&recs[i], &rec, GIT_SHA1_RAWSZ));
164
+ check(reftable_record_equal(&recs[i], &rec, REFTABLE_HASH_SIZE_SHA1));
165
}
166
167
for (i = 0; i < N; i++) {
@@ -175,7 +175,7 @@ static void t_log_block_read_write(void)
175
ret = block_iter_next(&it, &rec);
176
check_int(ret, ==, 0);
177
178
- check(reftable_record_equal(&recs[i], &rec, GIT_SHA1_RAWSZ));
178
+ check(reftable_record_equal(&recs[i], &rec, REFTABLE_HASH_SIZE_SHA1));
179
180
want.len--;
181
ret = block_iter_seek_key(&it, &br, &want);
@@ -183,7 +183,7 @@ static void t_log_block_read_write(void)
183
184
ret = block_iter_next(&it, &rec);
185
check_int(ret, ==, 0);
186
- check(reftable_record_equal(&recs[10 * (i / 10)], &rec, GIT_SHA1_RAWSZ));
186
+ check(reftable_record_equal(&recs[10 * (i / 10)], &rec, REFTABLE_HASH_SIZE_SHA1));
187
}
188
189
block_reader_release(&br);
@@ -220,7 +220,7 @@ static void t_obj_block_read_write(void)
220
block.len = block_size;
221
block_source_from_buf(&block.source, &buf);
222
ret = block_writer_init(&bw, BLOCK_TYPE_OBJ, block.data, block_size,
223
- header_off, hash_size(GIT_SHA1_FORMAT_ID));
223
+ header_off, hash_size(REFTABLE_HASH_SHA1));
224
check(!ret);
225
226
for (i = 0; i < N; i++) {
@@ -242,7 +242,7 @@ static void t_obj_block_read_write(void)
242
243
block_writer_release(&bw);
244
245
- block_reader_init(&br, &block, header_off, block_size, GIT_SHA1_RAWSZ);
245
+ block_reader_init(&br, &block, header_off, block_size, REFTABLE_HASH_SIZE_SHA1);
246
247
block_iter_seek_start(&it, &br);
248
@@ -253,7 +253,7 @@ static void t_obj_block_read_write(void)
253
check_int(i, ==, N);
254
break;
255
}
256
- check(reftable_record_equal(&recs[i], &rec, GIT_SHA1_RAWSZ));
256
+ check(reftable_record_equal(&recs[i], &rec, REFTABLE_HASH_SIZE_SHA1));
257
}
258
259
for (i = 0; i < N; i++) {
@@ -266,7 +266,7 @@ static void t_obj_block_read_write(void)
266
ret = block_iter_next(&it, &rec);
267
check_int(ret, ==, 0);
268
269
- check(reftable_record_equal(&recs[i], &rec, GIT_SHA1_RAWSZ));
269
+ check(reftable_record_equal(&recs[i], &rec, REFTABLE_HASH_SIZE_SHA1));
270
}
271
272
block_reader_release(&br);
@@ -304,7 +304,7 @@ static void t_index_block_read_write(void)
304
block.len = block_size;
305
block_source_from_buf(&block.source, &buf);
306
ret = block_writer_init(&bw, BLOCK_TYPE_INDEX, block.data, block_size,
307
- header_off, hash_size(GIT_SHA1_FORMAT_ID));
307
+ header_off, hash_size(REFTABLE_HASH_SHA1));
308
check(!ret);
309
310
for (i = 0; i < N; i++) {
@@ -326,7 +326,7 @@ static void t_index_block_read_write(void)
326
327
block_writer_release(&bw);
328
329
- block_reader_init(&br, &block, header_off, block_size, GIT_SHA1_RAWSZ);
329
+ block_reader_init(&br, &block, header_off, block_size, REFTABLE_HASH_SIZE_SHA1);
330
331
block_iter_seek_start(&it, &br);
332
@@ -337,7 +337,7 @@ static void t_index_block_read_write(void)
337
check_int(i, ==, N);
338
break;
339
}
340
- check(reftable_record_equal(&recs[i], &rec, GIT_SHA1_RAWSZ));
340
+ check(reftable_record_equal(&recs[i], &rec, REFTABLE_HASH_SIZE_SHA1));
341
}
342
343
for (i = 0; i < N; i++) {
@@ -350,7 +350,7 @@ static void t_index_block_read_write(void)
350
ret = block_iter_next(&it, &rec);
351
check_int(ret, ==, 0);
352
353
- check(reftable_record_equal(&recs[i], &rec, GIT_SHA1_RAWSZ));
353
+ check(reftable_record_equal(&recs[i], &rec, REFTABLE_HASH_SIZE_SHA1));
354
355
want.len--;
356
ret = block_iter_seek_key(&it, &br, &want);
@@ -358,7 +358,7 @@ static void t_index_block_read_write(void)
358
359
ret = block_iter_next(&it, &rec);
360
check_int(ret, ==, 0);
361
- check(reftable_record_equal(&recs[10 * (i / 10)], &rec, GIT_SHA1_RAWSZ));
361
+ check(reftable_record_equal(&recs[10 * (i / 10)], &rec, REFTABLE_HASH_SIZE_SHA1));
362
}
363
364
block_reader_release(&br);
t/unit-tests/t-reftable-merged.c
+13
-13
@@ -42,7 +42,7 @@ merged_table_from_records(struct reftable_ref_record **refs,
42
check(!err);
43
}
44
45
- err = reftable_merged_table_new(&mt, *readers, n, GIT_SHA1_FORMAT_ID);
45
+ err = reftable_merged_table_new(&mt, *readers, n, REFTABLE_HASH_SHA1);
46
check(!err);
47
return mt;
48
}
@@ -91,7 +91,7 @@ static void t_merged_single_record(void)
91
92
err = reftable_iterator_next_ref(&it, &ref);
93
check(!err);
94
- check(reftable_ref_record_equal(&r2[0], &ref, GIT_SHA1_RAWSZ));
94
+ check(reftable_ref_record_equal(&r2[0], &ref, REFTABLE_HASH_SIZE_SHA1));
95
reftable_ref_record_release(&ref);
96
reftable_iterator_destroy(&it);
97
readers_destroy(readers, 3);
@@ -168,7 +168,7 @@ static void t_merged_refs(void)
168
check(!err);
169
err = reftable_iterator_seek_ref(&it, "a");
170
check(!err);
171
- check_int(reftable_merged_table_hash_id(mt), ==, GIT_SHA1_FORMAT_ID);
171
+ check_int(reftable_merged_table_hash_id(mt), ==, REFTABLE_HASH_SHA1);
172
check_int(reftable_merged_table_min_update_index(mt), ==, 1);
173
check_int(reftable_merged_table_max_update_index(mt), ==, 3);
174
@@ -186,7 +186,7 @@ static void t_merged_refs(void)
186
check_int(ARRAY_SIZE(want), ==, len);
187
for (i = 0; i < len; i++)
188
check(reftable_ref_record_equal(want[i], &out[i],
189
- GIT_SHA1_RAWSZ));
189
+ REFTABLE_HASH_SIZE_SHA1));
190
for (i = 0; i < len; i++)
191
reftable_ref_record_release(&out[i]);
192
reftable_free(out);
@@ -252,12 +252,12 @@ static void t_merged_seek_multiple_times(void)
252
253
err = reftable_iterator_next_ref(&it, &rec);
254
check(!err);
255
- err = reftable_ref_record_equal(&rec, &r1[1], GIT_SHA1_RAWSZ);
255
+ err = reftable_ref_record_equal(&rec, &r1[1], REFTABLE_HASH_SIZE_SHA1);
256
check(err == 1);
257
258
err = reftable_iterator_next_ref(&it, &rec);
259
check(!err);
260
- err = reftable_ref_record_equal(&rec, &r2[1], GIT_SHA1_RAWSZ);
260
+ err = reftable_ref_record_equal(&rec, &r2[1], REFTABLE_HASH_SIZE_SHA1);
261
check(err == 1);
262
263
err = reftable_iterator_next_ref(&it, &rec);
@@ -300,7 +300,7 @@ merged_table_from_log_records(struct reftable_log_record **logs,
300
check(!err);
301
}
302
303
- err = reftable_merged_table_new(&mt, *readers, n, GIT_SHA1_FORMAT_ID);
303
+ err = reftable_merged_table_new(&mt, *readers, n, REFTABLE_HASH_SHA1);
304
check(!err);
305
return mt;
306
}
@@ -377,7 +377,7 @@ static void t_merged_logs(void)
377
check(!err);
378
err = reftable_iterator_seek_log(&it, "a");
379
check(!err);
380
- check_int(reftable_merged_table_hash_id(mt), ==, GIT_SHA1_FORMAT_ID);
380
+ check_int(reftable_merged_table_hash_id(mt), ==, REFTABLE_HASH_SHA1);
381
check_int(reftable_merged_table_min_update_index(mt), ==, 1);
382
check_int(reftable_merged_table_max_update_index(mt), ==, 3);
383
@@ -395,7 +395,7 @@ static void t_merged_logs(void)
395
check_int(ARRAY_SIZE(want), ==, len);
396
for (i = 0; i < len; i++)
397
check(reftable_log_record_equal(want[i], &out[i],
398
- GIT_SHA1_RAWSZ));
398
+ REFTABLE_HASH_SIZE_SHA1));
399
400
err = merged_table_init_iter(mt, &it, BLOCK_TYPE_LOG);
401
check(!err);
@@ -404,7 +404,7 @@ static void t_merged_logs(void)
404
reftable_log_record_release(&out[0]);
405
err = reftable_iterator_next_log(&it, &out[0]);
406
check(!err);
407
- check(reftable_log_record_equal(&out[0], &r3[0], GIT_SHA1_RAWSZ));
407
+ check(reftable_log_record_equal(&out[0], &r3[0], REFTABLE_HASH_SIZE_SHA1));
408
reftable_iterator_destroy(&it);
409
410
for (i = 0; i < len; i++)
@@ -448,11 +448,11 @@ static void t_default_write_opts(void)
448
check(!err);
449
450
hash_id = reftable_reader_hash_id(rd);
451
- check_int(hash_id, ==, GIT_SHA1_FORMAT_ID);
451
+ check_int(hash_id, ==, REFTABLE_HASH_SHA1);
452
453
- err = reftable_merged_table_new(&merged, &rd, 1, GIT_SHA256_FORMAT_ID);
453
+ err = reftable_merged_table_new(&merged, &rd, 1, REFTABLE_HASH_SHA256);
454
check_int(err, ==, REFTABLE_FORMAT_ERROR);
455
- err = reftable_merged_table_new(&merged, &rd, 1, GIT_SHA1_FORMAT_ID);
455
+ err = reftable_merged_table_new(&merged, &rd, 1, REFTABLE_HASH_SHA1);
456
check(!err);
457
458
reftable_reader_decref(rd);
t/unit-tests/t-reftable-pq.c
+1
-1
@@ -132,7 +132,7 @@ static void t_merged_iter_pqueue_top(void)
132
133
merged_iter_pqueue_check(&pq);
134
check(pq_entry_equal(&top, &e));
135
- check(reftable_record_equal(top.rec, &recs[i], GIT_SHA1_RAWSZ));
135
+ check(reftable_record_equal(top.rec, &recs[i], REFTABLE_HASH_SIZE_SHA1));
136
for (size_t j = 0; i < pq.len; j++) {
137
check(pq_less(&top, &pq.heap[j]));
138
check_int(top.index, >, j);
t/unit-tests/t-reftable-reader.c
+2
-2
@@ -31,7 +31,7 @@ static int t_reader_seek_once(void)
31
ret = reftable_iterator_next_ref(&it, &ref);
32
check(!ret);
33
34
- ret = reftable_ref_record_equal(&ref, &records[0], GIT_SHA1_RAWSZ);
34
+ ret = reftable_ref_record_equal(&ref, &records[0], REFTABLE_HASH_SIZE_SHA1);
35
check_int(ret, ==, 1);
36
37
ret = reftable_iterator_next_ref(&it, &ref);
@@ -74,7 +74,7 @@ static int t_reader_reseek(void)
74
ret = reftable_iterator_next_ref(&it, &ref);
75
check(!ret);
76
77
- ret = reftable_ref_record_equal(&ref, &records[0], GIT_SHA1_RAWSZ);
77
+ ret = reftable_ref_record_equal(&ref, &records[0], REFTABLE_HASH_SIZE_SHA1);
78
check_int(ret, ==, 1);
79
80
ret = reftable_iterator_next_ref(&it, &ref);
t/unit-tests/t-reftable-readwrite.c
+20
-20
@@ -41,7 +41,7 @@ static void t_buffer(void)
41
}
42
43
static void write_table(char ***names, struct reftable_buf *buf, int N,
44
- int block_size, uint32_t hash_id)
44
+ int block_size, enum reftable_hash hash_id)
45
{
46
struct reftable_write_options opts = {
47
.block_size = block_size,
@@ -62,7 +62,7 @@ static void write_table(char ***names, struct reftable_buf *buf, int N,
62
refs[i].refname = (*names)[i] = xstrfmt("refs/heads/branch%02d", i);
63
refs[i].update_index = update_index;
64
refs[i].value_type = REFTABLE_REF_VAL1;
65
- t_reftable_set_hash(refs[i].value.val1, i, GIT_SHA1_FORMAT_ID);
65
+ t_reftable_set_hash(refs[i].value.val1, i, REFTABLE_HASH_SHA1);
66
}
67
68
for (i = 0; i < N; i++) {
@@ -70,7 +70,7 @@ static void write_table(char ***names, struct reftable_buf *buf, int N,
70
logs[i].update_index = update_index;
71
logs[i].value_type = REFTABLE_LOG_UPDATE;
72
t_reftable_set_hash(logs[i].value.update.new_hash, i,
73
- GIT_SHA1_FORMAT_ID);
73
+ REFTABLE_HASH_SHA1);
74
logs[i].value.update.message = (char *) "message";
75
}
76
@@ -104,7 +104,7 @@ static void t_log_buffer_size(void)
104
/* This tests buffer extension for log compression. Must use a random
105
hash, to ensure that the compressed part is larger than the original.
106
*/
107
- for (i = 0; i < GIT_SHA1_RAWSZ; i++) {
107
+ for (i = 0; i < REFTABLE_HASH_SIZE_SHA1; i++) {
108
log.value.update.old_hash[i] = (uint8_t)(git_rand() % 256);
109
log.value.update.new_hash[i] = (uint8_t)(git_rand() % 256);
110
}
@@ -191,9 +191,9 @@ static void t_log_write_read(void)
191
log.update_index = i;
192
log.value_type = REFTABLE_LOG_UPDATE;
193
t_reftable_set_hash(log.value.update.old_hash, i,
194
- GIT_SHA1_FORMAT_ID);
194
+ REFTABLE_HASH_SHA1);
195
t_reftable_set_hash(log.value.update.new_hash, i + 1,
196
- GIT_SHA1_FORMAT_ID);
196
+ REFTABLE_HASH_SHA1);
197
198
err = reftable_writer_add_log(w, &log);
199
check(!err);
@@ -326,7 +326,7 @@ static void t_table_read_write_sequential(void)
326
int err = 0;
327
int j = 0;
328
329
- write_table(&names, &buf, N, 256, GIT_SHA1_FORMAT_ID);
329
+ write_table(&names, &buf, N, 256, REFTABLE_HASH_SHA1);
330
331
block_source_from_buf(&source, &buf);
332
@@ -361,7 +361,7 @@ static void t_table_write_small_table(void)
361
char **names;
362
struct reftable_buf buf = REFTABLE_BUF_INIT;
363
int N = 1;
364
- write_table(&names, &buf, N, 4096, GIT_SHA1_FORMAT_ID);
364
+ write_table(&names, &buf, N, 4096, REFTABLE_HASH_SHA1);
365
check_int(buf.len, <, 200);
366
reftable_buf_release(&buf);
367
free_names(names);
@@ -378,7 +378,7 @@ static void t_table_read_api(void)
378
struct reftable_log_record log = { 0 };
379
struct reftable_iterator it = { 0 };
380
381
- write_table(&names, &buf, N, 256, GIT_SHA1_FORMAT_ID);
381
+ write_table(&names, &buf, N, 256, REFTABLE_HASH_SHA1);
382
383
block_source_from_buf(&source, &buf);
384
@@ -400,7 +400,7 @@ static void t_table_read_api(void)
400
reftable_buf_release(&buf);
401
}
402
403
-static void t_table_read_write_seek(int index, int hash_id)
403
+static void t_table_read_write_seek(int index, enum reftable_hash hash_id)
404
{
405
char **names;
406
struct reftable_buf buf = REFTABLE_BUF_INIT;
@@ -467,24 +467,24 @@ static void t_table_read_write_seek(int index, int hash_id)
467
468
static void t_table_read_write_seek_linear(void)
469
{
470
- t_table_read_write_seek(0, GIT_SHA1_FORMAT_ID);
470
+ t_table_read_write_seek(0, REFTABLE_HASH_SHA1);
471
}
472
473
static void t_table_read_write_seek_linear_sha256(void)
474
{
475
- t_table_read_write_seek(0, GIT_SHA256_FORMAT_ID);
475
+ t_table_read_write_seek(0, REFTABLE_HASH_SHA256);
476
}
477
478
static void t_table_read_write_seek_index(void)
479
{
480
- t_table_read_write_seek(1, GIT_SHA1_FORMAT_ID);
480
+ t_table_read_write_seek(1, REFTABLE_HASH_SHA1);
481
}
482
483
static void t_table_refs_for(int indexed)
484
{
485
char **want_names;
486
int want_names_len = 0;
487
- uint8_t want_hash[GIT_SHA1_RAWSZ];
487
+ uint8_t want_hash[REFTABLE_HASH_SIZE_SHA1];
488
489
struct reftable_write_options opts = {
490
.block_size = 256,
@@ -500,10 +500,10 @@ static void t_table_refs_for(int indexed)
500
want_names = reftable_calloc(N + 1, sizeof(*want_names));
501
check(want_names != NULL);
502
503
- t_reftable_set_hash(want_hash, 4, GIT_SHA1_FORMAT_ID);
503
+ t_reftable_set_hash(want_hash, 4, REFTABLE_HASH_SHA1);
504
505
for (i = 0; i < N; i++) {
506
- uint8_t hash[GIT_SHA1_RAWSZ];
506
+ uint8_t hash[REFTABLE_HASH_SIZE_SHA1];
507
char fill[51] = { 0 };
508
char name[100];
509
struct reftable_ref_record ref = { 0 };
@@ -517,9 +517,9 @@ static void t_table_refs_for(int indexed)
517
518
ref.value_type = REFTABLE_REF_VAL2;
519
t_reftable_set_hash(ref.value.val2.value, i / 4,
520
- GIT_SHA1_FORMAT_ID);
520
+ REFTABLE_HASH_SHA1);
521
t_reftable_set_hash(ref.value.val2.target_value, 3 + i / 4,
522
- GIT_SHA1_FORMAT_ID);
522
+ REFTABLE_HASH_SHA1);
523
524
/* 80 bytes / entry, so 3 entries per block. Yields 17
525
*/
@@ -527,8 +527,8 @@ static void t_table_refs_for(int indexed)
527
n = reftable_writer_add_ref(w, &ref);
528
check_int(n, ==, 0);
529
530
- if (!memcmp(ref.value.val2.value, want_hash, GIT_SHA1_RAWSZ) ||
531
- !memcmp(ref.value.val2.target_value, want_hash, GIT_SHA1_RAWSZ))
530
+ if (!memcmp(ref.value.val2.value, want_hash, REFTABLE_HASH_SIZE_SHA1) ||
531
+ !memcmp(ref.value.val2.target_value, want_hash, REFTABLE_HASH_SIZE_SHA1))
532
want_names[want_names_len++] = xstrdup(name);
533
}
534
t/unit-tests/t-reftable-record.c
+30
-29
@@ -7,6 +7,7 @@
7
*/
8
9
#include "test-lib.h"
10
+#include "reftable/basics.h"
11
#include "reftable/constants.h"
12
#include "reftable/record.h"
13
@@ -17,10 +18,10 @@ static void t_copy(struct reftable_record *rec)
18
19
typ = reftable_record_type(rec);
20
reftable_record_init(©, typ);
20
- reftable_record_copy_from(©, rec, GIT_SHA1_RAWSZ);
21
+ reftable_record_copy_from(©, rec, REFTABLE_HASH_SIZE_SHA1);
22
/* do it twice to catch memory leaks */
22
- reftable_record_copy_from(©, rec, GIT_SHA1_RAWSZ);
23
- check(reftable_record_equal(rec, ©, GIT_SHA1_RAWSZ));
23
+ reftable_record_copy_from(©, rec, REFTABLE_HASH_SIZE_SHA1);
24
+ check(reftable_record_equal(rec, ©, REFTABLE_HASH_SIZE_SHA1));
25
26
reftable_record_release(©);
27
}
@@ -59,7 +60,7 @@ static void t_varint_roundtrip(void)
60
61
static void set_hash(uint8_t *h, int j)
62
{
62
- for (int i = 0; i < hash_size(GIT_SHA1_FORMAT_ID); i++)
63
+ for (int i = 0; i < hash_size(REFTABLE_HASH_SHA1); i++)
64
h[i] = (j >> i) & 0xff;
65
}
66
@@ -84,14 +85,14 @@ static void t_reftable_ref_record_comparison(void)
85
},
86
};
87
87
- check(!reftable_record_equal(&in[0], &in[1], GIT_SHA1_RAWSZ));
88
+ check(!reftable_record_equal(&in[0], &in[1], REFTABLE_HASH_SIZE_SHA1));
89
check(!reftable_record_cmp(&in[0], &in[1]));
90
90
- check(!reftable_record_equal(&in[1], &in[2], GIT_SHA1_RAWSZ));
91
+ check(!reftable_record_equal(&in[1], &in[2], REFTABLE_HASH_SIZE_SHA1));
92
check_int(reftable_record_cmp(&in[1], &in[2]), >, 0);
93
94
in[1].u.ref.value_type = in[0].u.ref.value_type;
94
- check(reftable_record_equal(&in[0], &in[1], GIT_SHA1_RAWSZ));
95
+ check(reftable_record_equal(&in[0], &in[1], REFTABLE_HASH_SIZE_SHA1));
96
check(!reftable_record_cmp(&in[0], &in[1]));
97
}
98
@@ -155,15 +156,15 @@ static void t_reftable_ref_record_roundtrip(void)
156
check_int(reftable_record_is_deletion(&in), ==, i == REFTABLE_REF_DELETION);
157
158
reftable_record_key(&in, &key);
158
- n = reftable_record_encode(&in, dest, GIT_SHA1_RAWSZ);
159
+ n = reftable_record_encode(&in, dest, REFTABLE_HASH_SIZE_SHA1);
160
check_int(n, >, 0);
161
162
/* decode into a non-zero reftable_record to test for leaks. */
162
- m = reftable_record_decode(&out, key, i, dest, GIT_SHA1_RAWSZ, &scratch);
163
+ m = reftable_record_decode(&out, key, i, dest, REFTABLE_HASH_SIZE_SHA1, &scratch);
164
check_int(n, ==, m);
165
166
check(reftable_ref_record_equal(&in.u.ref, &out.u.ref,
166
- GIT_SHA1_RAWSZ));
167
+ REFTABLE_HASH_SIZE_SHA1));
168
reftable_record_release(&in);
169
170
reftable_buf_release(&key);
@@ -193,15 +194,15 @@ static void t_reftable_log_record_comparison(void)
194
},
195
};
196
196
- check(!reftable_record_equal(&in[0], &in[1], GIT_SHA1_RAWSZ));
197
- check(!reftable_record_equal(&in[1], &in[2], GIT_SHA1_RAWSZ));
197
+ check(!reftable_record_equal(&in[0], &in[1], REFTABLE_HASH_SIZE_SHA1));
198
+ check(!reftable_record_equal(&in[1], &in[2], REFTABLE_HASH_SIZE_SHA1));
199
check_int(reftable_record_cmp(&in[1], &in[2]), >, 0);
200
/* comparison should be reversed for equal keys, because
201
* comparison is now performed on the basis of update indices */
202
check_int(reftable_record_cmp(&in[0], &in[1]), <, 0);
203
204
in[1].u.log.update_index = in[0].u.log.update_index;
204
- check(reftable_record_equal(&in[0], &in[1], GIT_SHA1_RAWSZ));
205
+ check(reftable_record_equal(&in[0], &in[1], REFTABLE_HASH_SIZE_SHA1));
206
check(!reftable_record_cmp(&in[0], &in[1]));
207
}
208
@@ -303,15 +304,15 @@ static void t_reftable_log_record_roundtrip(void)
304
305
reftable_record_key(&rec, &key);
306
306
- n = reftable_record_encode(&rec, dest, GIT_SHA1_RAWSZ);
307
+ n = reftable_record_encode(&rec, dest, REFTABLE_HASH_SIZE_SHA1);
308
check_int(n, >=, 0);
309
valtype = reftable_record_val_type(&rec);
310
m = reftable_record_decode(&out, key, valtype, dest,
310
- GIT_SHA1_RAWSZ, &scratch);
311
+ REFTABLE_HASH_SIZE_SHA1, &scratch);
312
check_int(n, ==, m);
313
314
check(reftable_log_record_equal(&in[i], &out.u.log,
314
- GIT_SHA1_RAWSZ));
315
+ REFTABLE_HASH_SIZE_SHA1));
316
reftable_log_record_release(&in[i]);
317
reftable_buf_release(&key);
318
reftable_record_release(&out);
@@ -380,20 +381,20 @@ static void t_reftable_obj_record_comparison(void)
381
},
382
};
383
383
- check(!reftable_record_equal(&in[0], &in[1], GIT_SHA1_RAWSZ));
384
+ check(!reftable_record_equal(&in[0], &in[1], REFTABLE_HASH_SIZE_SHA1));
385
check(!reftable_record_cmp(&in[0], &in[1]));
386
386
- check(!reftable_record_equal(&in[1], &in[2], GIT_SHA1_RAWSZ));
387
+ check(!reftable_record_equal(&in[1], &in[2], REFTABLE_HASH_SIZE_SHA1));
388
check_int(reftable_record_cmp(&in[1], &in[2]), >, 0);
389
390
in[1].u.obj.offset_len = in[0].u.obj.offset_len;
390
- check(reftable_record_equal(&in[0], &in[1], GIT_SHA1_RAWSZ));
391
+ check(reftable_record_equal(&in[0], &in[1], REFTABLE_HASH_SIZE_SHA1));
392
check(!reftable_record_cmp(&in[0], &in[1]));
393
}
394
395
static void t_reftable_obj_record_roundtrip(void)
396
{
396
- uint8_t testHash1[GIT_SHA1_RAWSZ] = { 1, 2, 3, 4, 0 };
397
+ uint8_t testHash1[REFTABLE_HASH_SIZE_SHA1] = { 1, 2, 3, 4, 0 };
398
uint64_t till9[] = { 1, 2, 3, 4, 500, 600, 700, 800, 9000 };
399
struct reftable_obj_record recs[3] = {
400
{
@@ -435,14 +436,14 @@ static void t_reftable_obj_record_roundtrip(void)
436
check(!reftable_record_is_deletion(&in));
437
t_copy(&in);
438
reftable_record_key(&in, &key);
438
- n = reftable_record_encode(&in, dest, GIT_SHA1_RAWSZ);
439
+ n = reftable_record_encode(&in, dest, REFTABLE_HASH_SIZE_SHA1);
440
check_int(n, >, 0);
441
extra = reftable_record_val_type(&in);
442
m = reftable_record_decode(&out, key, extra, dest,
442
- GIT_SHA1_RAWSZ, &scratch);
443
+ REFTABLE_HASH_SIZE_SHA1, &scratch);
444
check_int(n, ==, m);
445
445
- check(reftable_record_equal(&in, &out, GIT_SHA1_RAWSZ));
446
+ check(reftable_record_equal(&in, &out, REFTABLE_HASH_SIZE_SHA1));
447
reftable_buf_release(&key);
448
reftable_record_release(&out);
449
}
@@ -473,14 +474,14 @@ static void t_reftable_index_record_comparison(void)
474
check(!reftable_buf_addstr(&in[1].u.idx.last_key, "refs/heads/master"));
475
check(!reftable_buf_addstr(&in[2].u.idx.last_key, "refs/heads/branch"));
476
476
- check(!reftable_record_equal(&in[0], &in[1], GIT_SHA1_RAWSZ));
477
+ check(!reftable_record_equal(&in[0], &in[1], REFTABLE_HASH_SIZE_SHA1));
478
check(!reftable_record_cmp(&in[0], &in[1]));
479
479
- check(!reftable_record_equal(&in[1], &in[2], GIT_SHA1_RAWSZ));
480
+ check(!reftable_record_equal(&in[1], &in[2], REFTABLE_HASH_SIZE_SHA1));
481
check_int(reftable_record_cmp(&in[1], &in[2]), >, 0);
482
483
in[1].u.idx.offset = in[0].u.idx.offset;
483
- check(reftable_record_equal(&in[0], &in[1], GIT_SHA1_RAWSZ));
484
+ check(reftable_record_equal(&in[0], &in[1], REFTABLE_HASH_SIZE_SHA1));
485
check(!reftable_record_cmp(&in[0], &in[1]));
486
487
for (size_t i = 0; i < ARRAY_SIZE(in); i++)
@@ -516,15 +517,15 @@ static void t_reftable_index_record_roundtrip(void)
517
518
check(!reftable_record_is_deletion(&in));
519
check(!reftable_buf_cmp(&key, &in.u.idx.last_key));
519
- n = reftable_record_encode(&in, dest, GIT_SHA1_RAWSZ);
520
+ n = reftable_record_encode(&in, dest, REFTABLE_HASH_SIZE_SHA1);
521
check_int(n, >, 0);
522
523
extra = reftable_record_val_type(&in);
523
- m = reftable_record_decode(&out, key, extra, dest, GIT_SHA1_RAWSZ,
524
+ m = reftable_record_decode(&out, key, extra, dest, REFTABLE_HASH_SIZE_SHA1,
525
&scratch);
526
check_int(m, ==, n);
527
527
- check(reftable_record_equal(&in, &out, GIT_SHA1_RAWSZ));
528
+ check(reftable_record_equal(&in, &out, REFTABLE_HASH_SIZE_SHA1));
529
530
reftable_record_release(&out);
531
reftable_buf_release(&key);
t/unit-tests/t-reftable-stack.c
+17
-17
@@ -121,7 +121,7 @@ static void write_n_ref_tables(struct reftable_stack *st,
121
122
snprintf(buf, sizeof(buf), "refs/heads/branch-%04"PRIuMAX, (uintmax_t)i);
123
ref.refname = buf;
124
- t_reftable_set_hash(ref.value.val1, i, GIT_SHA1_FORMAT_ID);
124
+ t_reftable_set_hash(ref.value.val1, i, REFTABLE_HASH_SHA1);
125
126
err = reftable_stack_add(st, &write_test_ref, &ref);
127
check(!err);
@@ -169,7 +169,7 @@ static void t_reftable_stack_add_one(void)
169
170
err = reftable_stack_read_ref(st, ref.refname, &dest);
171
check(!err);
172
- check(reftable_ref_record_equal(&ref, &dest, GIT_SHA1_RAWSZ));
172
+ check(reftable_ref_record_equal(&ref, &dest, REFTABLE_HASH_SIZE_SHA1));
173
check_int(st->readers_len, >, 0);
174
175
#ifndef GIT_WINDOWS_NATIVE
@@ -280,7 +280,7 @@ static void t_reftable_stack_transaction_api(void)
280
err = reftable_stack_read_ref(st, ref.refname, &dest);
281
check(!err);
282
check_int(REFTABLE_REF_SYMREF, ==, dest.value_type);
283
- check(reftable_ref_record_equal(&ref, &dest, GIT_SHA1_RAWSZ));
283
+ check(reftable_ref_record_equal(&ref, &dest, REFTABLE_HASH_SIZE_SHA1));
284
285
reftable_ref_record_release(&dest);
286
reftable_stack_destroy(st);
@@ -340,7 +340,7 @@ static void t_reftable_stack_transaction_with_reload(void)
340
for (size_t i = 0; i < ARRAY_SIZE(refs); i++) {
341
err = reftable_stack_read_ref(st2, refs[i].refname, &ref);
342
check(!err);
343
- check(reftable_ref_record_equal(&refs[i], &ref, GIT_SHA1_RAWSZ));
343
+ check(reftable_ref_record_equal(&refs[i], &ref, REFTABLE_HASH_SIZE_SHA1));
344
}
345
346
reftable_ref_record_release(&ref);
@@ -530,13 +530,13 @@ static void t_reftable_stack_add(void)
530
refs[i].refname = xstrdup(buf);
531
refs[i].update_index = i + 1;
532
refs[i].value_type = REFTABLE_REF_VAL1;
533
- t_reftable_set_hash(refs[i].value.val1, i, GIT_SHA1_FORMAT_ID);
533
+ t_reftable_set_hash(refs[i].value.val1, i, REFTABLE_HASH_SHA1);
534
535
logs[i].refname = xstrdup(buf);
536
logs[i].update_index = N + i + 1;
537
logs[i].value_type = REFTABLE_LOG_UPDATE;
538
logs[i].value.update.email = xstrdup("identity@invalid");
539
- t_reftable_set_hash(logs[i].value.update.new_hash, i, GIT_SHA1_FORMAT_ID);
539
+ t_reftable_set_hash(logs[i].value.update.new_hash, i, REFTABLE_HASH_SHA1);
540
}
541
542
for (i = 0; i < N; i++) {
@@ -562,7 +562,7 @@ static void t_reftable_stack_add(void)
562
int err = reftable_stack_read_ref(st, refs[i].refname, &dest);
563
check(!err);
564
check(reftable_ref_record_equal(&dest, refs + i,
565
- GIT_SHA1_RAWSZ));
565
+ REFTABLE_HASH_SIZE_SHA1));
566
reftable_ref_record_release(&dest);
567
}
568
@@ -571,7 +571,7 @@ static void t_reftable_stack_add(void)
571
int err = reftable_stack_read_log(st, refs[i].refname, &dest);
572
check(!err);
573
check(reftable_log_record_equal(&dest, logs + i,
574
- GIT_SHA1_RAWSZ));
574
+ REFTABLE_HASH_SIZE_SHA1));
575
reftable_log_record_release(&dest);
576
}
577
@@ -622,14 +622,14 @@ static void t_reftable_stack_iterator(void)
622
refs[i].refname = xstrfmt("branch%02"PRIuMAX, (uintmax_t)i);
623
refs[i].update_index = i + 1;
624
refs[i].value_type = REFTABLE_REF_VAL1;
625
- t_reftable_set_hash(refs[i].value.val1, i, GIT_SHA1_FORMAT_ID);
625
+ t_reftable_set_hash(refs[i].value.val1, i, REFTABLE_HASH_SHA1);
626
627
logs[i].refname = xstrfmt("branch%02"PRIuMAX, (uintmax_t)i);
628
logs[i].update_index = i + 1;
629
logs[i].value_type = REFTABLE_LOG_UPDATE;
630
logs[i].value.update.email = xstrdup("johndoe@invalid");
631
logs[i].value.update.message = xstrdup("commit\n");
632
- t_reftable_set_hash(logs[i].value.update.new_hash, i, GIT_SHA1_FORMAT_ID);
632
+ t_reftable_set_hash(logs[i].value.update.new_hash, i, REFTABLE_HASH_SHA1);
633
}
634
635
for (i = 0; i < N; i++) {
@@ -656,7 +656,7 @@ static void t_reftable_stack_iterator(void)
656
if (err > 0)
657
break;
658
check(!err);
659
- check(reftable_ref_record_equal(&ref, &refs[i], GIT_SHA1_RAWSZ));
659
+ check(reftable_ref_record_equal(&ref, &refs[i], REFTABLE_HASH_SIZE_SHA1));
660
reftable_ref_record_release(&ref);
661
}
662
check_int(i, ==, N);
@@ -674,7 +674,7 @@ static void t_reftable_stack_iterator(void)
674
if (err > 0)
675
break;
676
check(!err);
677
- check(reftable_log_record_equal(&log, &logs[i], GIT_SHA1_RAWSZ));
677
+ check(reftable_log_record_equal(&log, &logs[i], REFTABLE_HASH_SIZE_SHA1));
678
reftable_log_record_release(&log);
679
}
680
check_int(i, ==, N);
@@ -767,7 +767,7 @@ static void t_reftable_stack_tombstone(void)
767
if (i % 2 == 0) {
768
refs[i].value_type = REFTABLE_REF_VAL1;
769
t_reftable_set_hash(refs[i].value.val1, i,
770
- GIT_SHA1_FORMAT_ID);
770
+ REFTABLE_HASH_SHA1);
771
}
772
773
logs[i].refname = xstrdup(buf);
@@ -776,7 +776,7 @@ static void t_reftable_stack_tombstone(void)
776
if (i % 2 == 0) {
777
logs[i].value_type = REFTABLE_LOG_UPDATE;
778
t_reftable_set_hash(logs[i].value.update.new_hash, i,
779
- GIT_SHA1_FORMAT_ID);
779
+ REFTABLE_HASH_SHA1);
780
logs[i].value.update.email =
781
xstrdup("identity@invalid");
782
}
@@ -836,7 +836,7 @@ static void t_reftable_stack_hash_id(void)
836
.value.symref = (char *) "target",
837
.update_index = 1,
838
};
839
- struct reftable_write_options opts32 = { .hash_id = GIT_SHA256_FORMAT_ID };
839
+ struct reftable_write_options opts32 = { .hash_id = REFTABLE_HASH_SHA256 };
840
struct reftable_stack *st32 = NULL;
841
struct reftable_write_options opts_default = { 0 };
842
struct reftable_stack *st_default = NULL;
@@ -859,7 +859,7 @@ static void t_reftable_stack_hash_id(void)
859
err = reftable_stack_read_ref(st_default, "master", &dest);
860
check(!err);
861
862
- check(reftable_ref_record_equal(&ref, &dest, GIT_SHA1_RAWSZ));
862
+ check(reftable_ref_record_equal(&ref, &dest, REFTABLE_HASH_SIZE_SHA1));
863
reftable_ref_record_release(&dest);
864
reftable_stack_destroy(st);
865
reftable_stack_destroy(st_default);
@@ -909,7 +909,7 @@ static void t_reflog_expire(void)
909
logs[i].value.update.time = i;
910
logs[i].value.update.email = xstrdup("identity@invalid");
911
t_reftable_set_hash(logs[i].value.update.new_hash, i,
912
- GIT_SHA1_FORMAT_ID);
912
+ REFTABLE_HASH_SHA1);
913
}
914
915
for (i = 1; i <= N; i++) {