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

Function prepare_single_update

refs/reftable-backend.c:1042–1291  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

1040}
1041
1042static enum ref_transaction_error prepare_single_update(struct reftable_ref_store *refs,
1043 struct reftable_transaction_data *tx_data,
1044 struct ref_transaction *transaction,
1045 struct reftable_backend *be,
1046 struct ref_update *u,
1047 size_t update_idx,
1048 struct string_list *refnames_to_check,
1049 unsigned int head_type,
1050 struct strbuf *head_referent,
1051 struct strbuf *referent,
1052 struct strbuf *err)
1053{
1054 enum ref_transaction_error ret = 0;
1055 struct object_id current_oid = {0};
1056 const char *rewritten_ref;
1057
1058 /*
1059 * There is no need to reload the respective backends here as
1060 * we have already reloaded them when preparing the transaction
1061 * update. And given that the stacks have been locked there
1062 * shouldn't have been any concurrent modifications of the
1063 * stack.
1064 */
1065 ret = backend_for(&be, refs, u->refname, &rewritten_ref, 0);
1066 if (ret)
1067 return REF_TRANSACTION_ERROR_GENERIC;
1068
1069 if (u->flags & REF_LOG_USE_PROVIDED_OIDS) {
1070 if (!(u->flags & REF_HAVE_OLD) ||
1071 !(u->flags & REF_HAVE_NEW) ||
1072 !(u->flags & REF_LOG_ONLY)) {
1073 strbuf_addf(err, _("trying to write reflog for '%s' "
1074 "with incomplete values"), u->refname);
1075 return REF_TRANSACTION_ERROR_GENERIC;
1076 }
1077
1078 if (queue_transaction_update(refs, tx_data, u, &u->old_oid, err))
1079 return REF_TRANSACTION_ERROR_GENERIC;
1080 return 0;
1081 }
1082
1083 /*
1084 * When we update the reference that HEAD points to we enqueue
1085 * a second log-only update for HEAD so that its reflog is
1086 * updated accordingly.
1087 */
1088 if (head_type == REF_ISSYMREF &&
1089 !(u->flags & REF_LOG_ONLY) &&
1090 !(u->flags & REF_UPDATE_VIA_HEAD) &&
1091 !strcmp(rewritten_ref, head_referent->buf)) {
1092 /*
1093 * First make sure that HEAD is not already in the
1094 * transaction. This check is O(lg N) in the transaction
1095 * size, but it happens at most once per transaction.
1096 */
1097 if (string_list_has_string(&transaction->refnames, "HEAD")) {
1098 /* An entry already existed */
1099 strbuf_addf(err,

Callers 1

Calls 15

backend_forFunction · 0.85
strbuf_addfFunction · 0.85
queue_transaction_updateFunction · 0.85
string_list_has_stringFunction · 0.85
refs_resolve_ref_unsafeFunction · 0.85
oideqFunction · 0.85

Tested by

no test coverage detected