Skip to content

Commit 4865707

Browse files
KarthikNayakgitster
authored andcommitted
refs: remove create_symref and associated dead code
In the previous commits, we converted `refs_create_symref()` to utilize transactions to perform symref updates. Earlier `refs_create_symref()` used `create_symref()` to do the same. We can now remove `create_symref()` and any code associated with it which is no longer used. We remove `create_symref()` code from all the reference backends and also remove it entirely from the `ref_storage_be` struct. Signed-off-by: Karthik Nayak <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent f151dfe commit 4865707

File tree

5 files changed

+0
-172
lines changed

5 files changed

+0
-172
lines changed

refs/debug.c

Lines changed: 0 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -131,18 +131,6 @@ static int debug_pack_refs(struct ref_store *ref_store, struct pack_refs_opts *o
131131
return res;
132132
}
133133

134-
static int debug_create_symref(struct ref_store *ref_store,
135-
const char *ref_name, const char *target,
136-
const char *logmsg)
137-
{
138-
struct debug_ref_store *drefs = (struct debug_ref_store *)ref_store;
139-
int res = drefs->refs->be->create_symref(drefs->refs, ref_name, target,
140-
logmsg);
141-
trace_printf_key(&trace_refs, "create_symref: %s -> %s \"%s\": %d\n", ref_name,
142-
target, logmsg, res);
143-
return res;
144-
}
145-
146134
static int debug_rename_ref(struct ref_store *ref_store, const char *oldref,
147135
const char *newref, const char *logmsg)
148136
{
@@ -441,7 +429,6 @@ struct ref_storage_be refs_be_debug = {
441429
.initial_transaction_commit = debug_initial_transaction_commit,
442430

443431
.pack_refs = debug_pack_refs,
444-
.create_symref = debug_create_symref,
445432
.rename_ref = debug_rename_ref,
446433
.copy_ref = debug_copy_ref,
447434

refs/files-backend.c

Lines changed: 0 additions & 67 deletions
Original file line numberDiff line numberDiff line change
@@ -1903,23 +1903,6 @@ static int create_ref_symlink(struct ref_lock *lock, const char *target)
19031903
return ret;
19041904
}
19051905

1906-
static void update_symref_reflog(struct files_ref_store *refs,
1907-
struct ref_lock *lock, const char *refname,
1908-
const char *target, const char *logmsg)
1909-
{
1910-
struct strbuf err = STRBUF_INIT;
1911-
struct object_id new_oid;
1912-
1913-
if (logmsg &&
1914-
refs_resolve_ref_unsafe(&refs->base, target,
1915-
RESOLVE_REF_READING, &new_oid, NULL) &&
1916-
files_log_ref_write(refs, refname, &lock->old_oid,
1917-
&new_oid, logmsg, 0, &err)) {
1918-
error("%s", err.buf);
1919-
strbuf_release(&err);
1920-
}
1921-
}
1922-
19231906
static int create_symref_lock(struct files_ref_store *refs,
19241907
struct ref_lock *lock, const char *refname,
19251908
const char *target, struct strbuf *err)
@@ -1939,55 +1922,6 @@ static int create_symref_lock(struct files_ref_store *refs,
19391922
return 0;
19401923
}
19411924

1942-
static int create_and_commit_symref(struct files_ref_store *refs,
1943-
struct ref_lock *lock, const char *refname,
1944-
const char *target, const char *logmsg)
1945-
{
1946-
struct strbuf err = STRBUF_INIT;
1947-
int ret;
1948-
1949-
if (prefer_symlink_refs && !create_ref_symlink(lock, target)) {
1950-
update_symref_reflog(refs, lock, refname, target, logmsg);
1951-
return 0;
1952-
}
1953-
1954-
ret = create_symref_lock(refs, lock, refname, target, &err);
1955-
if (!ret) {
1956-
update_symref_reflog(refs, lock, refname, target, logmsg);
1957-
1958-
if (commit_ref(lock) < 0)
1959-
return error("unable to write symref for %s: %s", refname,
1960-
strerror(errno));
1961-
} else {
1962-
return error("%s", err.buf);
1963-
}
1964-
1965-
return ret;
1966-
}
1967-
1968-
static int files_create_symref(struct ref_store *ref_store,
1969-
const char *refname, const char *target,
1970-
const char *logmsg)
1971-
{
1972-
struct files_ref_store *refs =
1973-
files_downcast(ref_store, REF_STORE_WRITE, "create_symref");
1974-
struct strbuf err = STRBUF_INIT;
1975-
struct ref_lock *lock;
1976-
int ret;
1977-
1978-
lock = lock_ref_oid_basic(refs, refname, &err);
1979-
if (!lock) {
1980-
error("%s", err.buf);
1981-
strbuf_release(&err);
1982-
return -1;
1983-
}
1984-
1985-
ret = create_and_commit_symref(refs, lock, refname, target, logmsg);
1986-
1987-
unlock_ref(lock);
1988-
return ret;
1989-
}
1990-
19911925
static int files_reflog_exists(struct ref_store *ref_store,
19921926
const char *refname)
19931927
{
@@ -3374,7 +3308,6 @@ struct ref_storage_be refs_be_files = {
33743308
.initial_transaction_commit = files_initial_transaction_commit,
33753309

33763310
.pack_refs = files_pack_refs,
3377-
.create_symref = files_create_symref,
33783311
.rename_ref = files_rename_ref,
33793312
.copy_ref = files_copy_ref,
33803313

refs/packed-backend.c

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1714,7 +1714,6 @@ struct ref_storage_be refs_be_packed = {
17141714
.initial_transaction_commit = packed_initial_transaction_commit,
17151715

17161716
.pack_refs = packed_pack_refs,
1717-
.create_symref = NULL,
17181717
.rename_ref = NULL,
17191718
.copy_ref = NULL,
17201719

refs/refs-internal.h

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -566,10 +566,6 @@ typedef int ref_transaction_commit_fn(struct ref_store *refs,
566566

567567
typedef int pack_refs_fn(struct ref_store *ref_store,
568568
struct pack_refs_opts *opts);
569-
typedef int create_symref_fn(struct ref_store *ref_store,
570-
const char *ref_target,
571-
const char *refs_heads_master,
572-
const char *logmsg);
573569
typedef int rename_ref_fn(struct ref_store *ref_store,
574570
const char *oldref, const char *newref,
575571
const char *logmsg);
@@ -690,7 +686,6 @@ struct ref_storage_be {
690686
ref_transaction_commit_fn *initial_transaction_commit;
691687

692688
pack_refs_fn *pack_refs;
693-
create_symref_fn *create_symref;
694689
rename_ref_fn *rename_ref;
695690
copy_ref_fn *copy_ref;
696691

refs/reftable-backend.c

Lines changed: 0 additions & 86 deletions
Original file line numberDiff line numberDiff line change
@@ -1256,91 +1256,6 @@ struct write_create_symref_arg {
12561256
const char *logmsg;
12571257
};
12581258

1259-
static int write_create_symref_table(struct reftable_writer *writer, void *cb_data)
1260-
{
1261-
struct write_create_symref_arg *create = cb_data;
1262-
uint64_t ts = reftable_stack_next_update_index(create->stack);
1263-
struct reftable_ref_record ref = {
1264-
.refname = (char *)create->refname,
1265-
.value_type = REFTABLE_REF_SYMREF,
1266-
.value.symref = (char *)create->target,
1267-
.update_index = ts,
1268-
};
1269-
struct reftable_log_record log = {0};
1270-
struct object_id new_oid;
1271-
struct object_id old_oid;
1272-
int ret;
1273-
1274-
reftable_writer_set_limits(writer, ts, ts);
1275-
1276-
ret = reftable_writer_add_ref(writer, &ref);
1277-
if (ret)
1278-
return ret;
1279-
1280-
/*
1281-
* Note that it is important to try and resolve the reference before we
1282-
* write the log entry. This is because `should_write_log()` will munge
1283-
* `core.logAllRefUpdates`, which is undesirable when we create a new
1284-
* repository because it would be written into the config. As HEAD will
1285-
* not resolve for new repositories this ordering will ensure that this
1286-
* never happens.
1287-
*/
1288-
if (!create->logmsg ||
1289-
!refs_resolve_ref_unsafe(&create->refs->base, create->target,
1290-
RESOLVE_REF_READING, &new_oid, NULL) ||
1291-
!should_write_log(&create->refs->base, create->refname))
1292-
return 0;
1293-
1294-
fill_reftable_log_record(&log);
1295-
log.refname = xstrdup(create->refname);
1296-
log.update_index = ts;
1297-
log.value.update.message = xstrndup(create->logmsg,
1298-
create->refs->write_options.block_size / 2);
1299-
memcpy(log.value.update.new_hash, new_oid.hash, GIT_MAX_RAWSZ);
1300-
if (refs_resolve_ref_unsafe(&create->refs->base, create->refname,
1301-
RESOLVE_REF_READING, &old_oid, NULL))
1302-
memcpy(log.value.update.old_hash, old_oid.hash, GIT_MAX_RAWSZ);
1303-
1304-
ret = reftable_writer_add_log(writer, &log);
1305-
reftable_log_record_release(&log);
1306-
return ret;
1307-
}
1308-
1309-
static int reftable_be_create_symref(struct ref_store *ref_store,
1310-
const char *refname,
1311-
const char *target,
1312-
const char *logmsg)
1313-
{
1314-
struct reftable_ref_store *refs =
1315-
reftable_be_downcast(ref_store, REF_STORE_WRITE, "create_symref");
1316-
struct reftable_stack *stack = stack_for(refs, refname, &refname);
1317-
struct write_create_symref_arg arg = {
1318-
.refs = refs,
1319-
.stack = stack,
1320-
.refname = refname,
1321-
.target = target,
1322-
.logmsg = logmsg,
1323-
};
1324-
int ret;
1325-
1326-
ret = refs->err;
1327-
if (ret < 0)
1328-
goto done;
1329-
1330-
ret = reftable_stack_reload(stack);
1331-
if (ret)
1332-
goto done;
1333-
1334-
ret = reftable_stack_add(stack, &write_create_symref_table, &arg);
1335-
1336-
done:
1337-
assert(ret != REFTABLE_API_ERROR);
1338-
if (ret)
1339-
error("unable to write symref for %s: %s", refname,
1340-
reftable_error_str(ret));
1341-
return ret;
1342-
}
1343-
13441259
struct write_copy_arg {
13451260
struct reftable_ref_store *refs;
13461261
struct reftable_stack *stack;
@@ -2248,7 +2163,6 @@ struct ref_storage_be refs_be_reftable = {
22482163
.initial_transaction_commit = reftable_be_initial_transaction_commit,
22492164

22502165
.pack_refs = reftable_be_pack_refs,
2251-
.create_symref = reftable_be_create_symref,
22522166
.rename_ref = reftable_be_rename_ref,
22532167
.copy_ref = reftable_be_copy_ref,
22542168

0 commit comments

Comments
 (0)