Skip to content

Commit 455d61b

Browse files
pks-tgitster
authored andcommitted
refs/reftable: perform explicit D/F check when writing symrefs
We already perform explicit D/F checks in all reftable callbacks which write refs, except when writing symrefs. For one this leads to an error message which isn't perfectly actionable because we only tell the user that there was a D/F conflict, but not which refs conflicted with each other. But second, once all ref updating callbacks explicitly check for D/F conflicts, we can disable the D/F checks in the reftable library itself and thus avoid some duplicated efforts. Refactor the code that writes symref tables to explicitly call into `refs_verify_refname_available()` when writing symrefs. Signed-off-by: Patrick Steinhardt <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent f57cc98 commit 455d61b

File tree

2 files changed

+18
-4
lines changed

2 files changed

+18
-4
lines changed

refs/reftable-backend.c

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1217,6 +1217,7 @@ static int reftable_be_pack_refs(struct ref_store *ref_store,
12171217
struct write_create_symref_arg {
12181218
struct reftable_ref_store *refs;
12191219
struct reftable_stack *stack;
1220+
struct strbuf *err;
12201221
const char *refname;
12211222
const char *target;
12221223
const char *logmsg;
@@ -1239,6 +1240,11 @@ static int write_create_symref_table(struct reftable_writer *writer, void *cb_da
12391240

12401241
reftable_writer_set_limits(writer, ts, ts);
12411242

1243+
ret = refs_verify_refname_available(&create->refs->base, create->refname,
1244+
NULL, NULL, create->err);
1245+
if (ret < 0)
1246+
return ret;
1247+
12421248
ret = reftable_writer_add_ref(writer, &ref);
12431249
if (ret)
12441250
return ret;
@@ -1280,12 +1286,14 @@ static int reftable_be_create_symref(struct ref_store *ref_store,
12801286
struct reftable_ref_store *refs =
12811287
reftable_be_downcast(ref_store, REF_STORE_WRITE, "create_symref");
12821288
struct reftable_stack *stack = stack_for(refs, refname, &refname);
1289+
struct strbuf err = STRBUF_INIT;
12831290
struct write_create_symref_arg arg = {
12841291
.refs = refs,
12851292
.stack = stack,
12861293
.refname = refname,
12871294
.target = target,
12881295
.logmsg = logmsg,
1296+
.err = &err,
12891297
};
12901298
int ret;
12911299

@@ -1301,9 +1309,15 @@ static int reftable_be_create_symref(struct ref_store *ref_store,
13011309

13021310
done:
13031311
assert(ret != REFTABLE_API_ERROR);
1304-
if (ret)
1305-
error("unable to write symref for %s: %s", refname,
1306-
reftable_error_str(ret));
1312+
if (ret) {
1313+
if (err.len)
1314+
error("%s", err.buf);
1315+
else
1316+
error("unable to write symref for %s: %s", refname,
1317+
reftable_error_str(ret));
1318+
}
1319+
1320+
strbuf_release(&err);
13071321
return ret;
13081322
}
13091323

t/t0610-reftable-basics.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -255,7 +255,7 @@ test_expect_success 'ref transaction: creating symbolic ref fails with F/D confl
255255
git init repo &&
256256
test_commit -C repo A &&
257257
cat >expect <<-EOF &&
258-
error: unable to write symref for refs/heads: file/directory conflict
258+
error: ${SQ}refs/heads/main${SQ} exists; cannot create ${SQ}refs/heads${SQ}
259259
EOF
260260
test_must_fail git -C repo symbolic-ref refs/heads refs/heads/foo 2>err &&
261261
test_cmp expect err

0 commit comments

Comments
 (0)