120
strbuf_release(&scratch);
121
}
122
123
-static void t_reftable_log_record_equal(void)
123
+static void t_reftable_log_record_comparison(void)
124
{
125
- struct reftable_log_record in[2] = {
125
+ struct reftable_record in[3] = {
126
{
127
- .refname = xstrdup("refs/heads/master"),
128
- .update_index = 42,
127
+ .type = BLOCK_TYPE_LOG,
128
+ .u.log.refname = (char *) "refs/heads/master",
129
+ .u.log.update_index = 42,
130
},
131
{
131
- .refname = xstrdup("refs/heads/master"),
132
- .update_index = 22,
133
- }
132
+ .type = BLOCK_TYPE_LOG,
133
+ .u.log.refname = (char *) "refs/heads/master",
134
+ .u.log.update_index = 22,
135
+ },
136
+ {
137
+ .type = BLOCK_TYPE_LOG,
138
+ .u.log.refname = (char *) "refs/heads/main",
139
+ .u.log.update_index = 22,
140
+ },
141
};
142
136
- check(!reftable_log_record_equal(&in[0], &in[1], GIT_SHA1_RAWSZ));
137
- in[1].update_index = in[0].update_index;
138
- check(reftable_log_record_equal(&in[0], &in[1], GIT_SHA1_RAWSZ));
139
- reftable_log_record_release(&in[0]);
140
- reftable_log_record_release(&in[1]);
143
+ check(!reftable_record_equal(&in[0], &in[1], GIT_SHA1_RAWSZ));
144
+ check(!reftable_record_equal(&in[1], &in[2], GIT_SHA1_RAWSZ));
145
+ check_int(reftable_record_cmp(&in[1], &in[2]), >, 0);
146
+ /* comparison should be reversed for equal keys, because
147
+ * comparison is now performed on the basis of update indices */
148
+ check_int(reftable_record_cmp(&in[0], &in[1]), <, 0);
149
+
150
+ in[1].u.log.update_index = in[0].u.log.update_index;
151
+ check(reftable_record_equal(&in[0], &in[1], GIT_SHA1_RAWSZ));
152
+ check(!reftable_record_cmp(&in[0], &in[1]));
153
}
154
155
static void t_reftable_log_record_roundtrip(void)
371
372
int cmd_main(int argc, const char *argv[])
373
{
362
- TEST(t_reftable_log_record_equal(), "reftable_log_record_equal works");
374
+ TEST(t_reftable_log_record_comparison(), "comparison operations work on log record");
375
TEST(t_reftable_log_record_roundtrip(), "record operations work on log record");
376
TEST(t_reftable_ref_record_roundtrip(), "record operations work on ref record");
377
TEST(t_varint_roundtrip(), "put_var_int and get_var_int work");