MCPcopy Create free account
hub / github.com/git/git / write_copy_table

Function write_copy_table

refs/reftable-backend.c:1730–1940  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

1728};
1729
1730static int write_copy_table(struct reftable_writer *writer, void *cb_data)
1731{
1732 struct write_copy_arg *arg = cb_data;
1733 uint64_t deletion_ts, creation_ts;
1734 struct reftable_ref_record old_ref = {0}, refs[2] = {0};
1735 struct reftable_log_record old_log = {0}, *logs = NULL;
1736 struct reftable_iterator it = {0};
1737 struct string_list skip = STRING_LIST_INIT_NODUP;
1738 struct ident_split committer_ident = {0};
1739 struct strbuf errbuf = STRBUF_INIT;
1740 size_t logs_nr = 0, logs_alloc = 0, i;
1741 const char *committer_info;
1742 int ret;
1743
1744 committer_info = git_committer_info(0);
1745 if (split_ident_line(&committer_ident, committer_info, strlen(committer_info)))
1746 BUG("failed splitting committer info");
1747
1748 if (reftable_stack_read_ref(arg->be->stack, arg->oldname, &old_ref)) {
1749 ret = error(_("refname %s not found"), arg->oldname);
1750 goto done;
1751 }
1752 if (old_ref.value_type == REFTABLE_REF_SYMREF) {
1753 ret = error(_("refname %s is a symbolic ref, copying it is not supported"),
1754 arg->oldname);
1755 goto done;
1756 }
1757
1758 /*
1759 * There's nothing to do in case the old and new name are the same, so
1760 * we exit early in that case.
1761 */
1762 if (!strcmp(arg->oldname, arg->newname)) {
1763 ret = 0;
1764 goto done;
1765 }
1766
1767 /*
1768 * Verify that the new refname is available.
1769 */
1770 if (arg->delete_old)
1771 string_list_insert(&skip, arg->oldname);
1772 ret = refs_verify_refname_available(&arg->refs->base, arg->newname,
1773 NULL, &skip, 0, &errbuf);
1774 if (ret < 0) {
1775 error("%s", errbuf.buf);
1776 goto done;
1777 }
1778
1779 /*
1780 * When deleting the old reference we have to use two update indices:
1781 * once to delete the old ref and its reflog, and once to create the
1782 * new ref and its reflog. They need to be staged with two separate
1783 * indices because the new reflog needs to encode both the deletion of
1784 * the old branch and the creation of the new branch, and we cannot do
1785 * two changes to a reflog in a single update.
1786 */
1787 deletion_ts = creation_ts = reftable_stack_next_update_index(arg->be->stack);

Callers

nothing calls this directly

Calls 15

git_committer_infoFunction · 0.85
split_ident_lineFunction · 0.85
reftable_stack_read_refFunction · 0.85
errorFunction · 0.85
string_list_insertFunction · 0.85
xstrdupFunction · 0.85
reftable_writer_add_refsFunction · 0.85
fill_reftable_log_recordFunction · 0.85
xstrndupFunction · 0.85

Tested by

no test coverage detected