105
static void write_n_ref_tables(struct reftable_stack *st,
106
size_t n)
107
{
108
- struct strbuf buf = STRBUF_INIT;
108
int disable_auto_compact;
109
int err;
110
116
.update_index = reftable_stack_next_update_index(st),
117
.value_type = REFTABLE_REF_VAL1,
118
};
119
+ char buf[128];
120
121
- strbuf_reset(&buf);
122
- strbuf_addf(&buf, "refs/heads/branch-%04"PRIuMAX, (uintmax_t)i);
123
- ref.refname = buf.buf;
121
+ snprintf(buf, sizeof(buf), "refs/heads/branch-%04"PRIuMAX, (uintmax_t)i);
122
+ ref.refname = buf;
123
t_reftable_set_hash(ref.value.val1, i, GIT_SHA1_FORMAT_ID);
124
125
err = reftable_stack_add(st, &write_test_ref, &ref);
127
}
128
129
st->opts.disable_auto_compact = disable_auto_compact;
131
- strbuf_release(&buf);
130
}
131
132
struct write_log_arg {
432
* Adding a new table to the stack should not be impacted by this, even
433
* though auto-compaction will now fail.
434
*/
437
- strbuf_addf(&table_path, "%s/%s.lock", dir, st->readers[0]->name);
435
+ strbuf_addstr(&table_path, dir);
436
+ strbuf_addstr(&table_path, "/");
437
+ strbuf_addstr(&table_path, st->readers[0]->name);
438
+ strbuf_addstr(&table_path, ".lock");
439
write_file_buf(table_path.buf, "", 0);
440
441
ref.update_index = 2;
1078
* size, we expect that auto-compaction will want to compact all of the
1079
* tables. Locking any of the tables will keep it from doing so.
1080
*/
1080
- strbuf_reset(&buf);
1081
- strbuf_addf(&buf, "%s/%s.lock", dir, st->readers[2]->name);
1081
+ strbuf_addstr(&buf, dir);
1082
+ strbuf_addstr(&buf, "/");
1083
+ strbuf_addstr(&buf, st->readers[2]->name);
1084
+ strbuf_addstr(&buf, ".lock");
1085
write_file_buf(buf.buf, "", 0);
1086
1087
/*
1104
{
1105
struct reftable_write_options opts = { 0 };
1106
struct reftable_stack *st = NULL;
1104
- struct strbuf refname = STRBUF_INIT;
1107
char *dir = get_tmp_dir(__LINE__);
1108
int err;
1109
size_t i, n = 20;
1117
.value_type = REFTABLE_REF_SYMREF,
1118
.value.symref = (char *) "master",
1119
};
1120
+ char buf[128];
1121
1122
/*
1123
* Disable auto-compaction for all but the last runs. Like this
1126
*/
1127
st->opts.disable_auto_compact = i != n;
1128
1126
- strbuf_reset(&refname);
1127
- strbuf_addf(&refname, "branch-%04"PRIuMAX, (uintmax_t)i);
1128
- ref.refname = refname.buf;
1129
+ snprintf(buf, sizeof(buf), "branch-%04"PRIuMAX, (uintmax_t)i);
1130
+ ref.refname = buf;
1131
1132
err = reftable_stack_add(st, write_test_ref, &ref);
1133
check(!err);
1144
}
1145
1146
reftable_stack_destroy(st);
1145
- strbuf_release(&refname);
1147
clear_dir(dir);
1148
}
1149
1164
check_int(st->merged->readers_len, ==, 3);
1165
1166
/* Lock one of the tables that we're about to compact. */
1166
- strbuf_reset(&buf);
1167
- strbuf_addf(&buf, "%s/%s.lock", dir, st->readers[1]->name);
1167
+ strbuf_addstr(&buf, dir);
1168
+ strbuf_addstr(&buf, "/");
1169
+ strbuf_addstr(&buf, st->readers[1]->name);
1170
+ strbuf_addstr(&buf, ".lock");
1171
write_file_buf(buf.buf, "", 0);
1172
1173
/*
1324
* our old readers. This should trigger a partial reload of the stack,
1325
* where we try to reuse our old readers.
1326
*/
1324
- strbuf_addf(&content, "%s\n", st->readers[0]->name);
1325
- strbuf_addf(&content, "%s\n", st->readers[1]->name);
1327
+ strbuf_addstr(&content, st->readers[0]->name);
1328
+ strbuf_addstr(&content, "\n");
1329
+ strbuf_addstr(&content, st->readers[1]->name);
1330
+ strbuf_addstr(&content, "\n");
1331
strbuf_addstr(&content, "garbage\n");
1327
- strbuf_addf(&table_path, "%s.lock", st->list_file);
1332
+ strbuf_addstr(&table_path, st->list_file);
1333
+ strbuf_addstr(&table_path, ".lock");
1334
write_file_buf(table_path.buf, content.buf, content.len);
1335
err = rename(table_path.buf, st->list_file);
1336
check(!err);