mirror of
https://github.com/git/git.git
synced 2025-12-12 20:36:24 +01:00
refs: support rejection in batch updates during F/D checks
The `refs_verify_refnames_available()` is used to batch check refnames for F/D conflicts. While this is the more performant alternative than its individual version, it does not provide rejection capabilities on a single update level. For batched updates, this would mean a rejection of the entire transaction whenever one reference has a F/D conflict. Modify the function to call `ref_transaction_maybe_set_rejected()` to check if a single update can be rejected. Since this function is only internally used within 'refs/' and we want to pass in a `struct ref_transaction *` as a variable. We also move and mark `refs_verify_refnames_available()` to 'refs-internal.h' to be an internal function. Signed-off-by: Karthik Nayak <karthik.188@gmail.com> Acked-by: Patrick Steinhardt <ps@pks.im> Signed-off-by: Junio C Hamano <gitster@pobox.com>
This commit is contained in:
committed by
Junio C Hamano
parent
23fc8e4f61
commit
31726bb90d
37
refs.c
37
refs.c
@@ -2540,6 +2540,7 @@ enum ref_transaction_error refs_verify_refnames_available(struct ref_store *refs
|
||||
const struct string_list *refnames,
|
||||
const struct string_list *extras,
|
||||
const struct string_list *skip,
|
||||
struct ref_transaction *transaction,
|
||||
unsigned int initial_transaction,
|
||||
struct strbuf *err)
|
||||
{
|
||||
@@ -2547,6 +2548,7 @@ enum ref_transaction_error refs_verify_refnames_available(struct ref_store *refs
|
||||
struct strbuf referent = STRBUF_INIT;
|
||||
struct string_list_item *item;
|
||||
struct ref_iterator *iter = NULL;
|
||||
struct strset conflicting_dirnames;
|
||||
struct strset dirnames;
|
||||
int ret = REF_TRANSACTION_ERROR_NAME_CONFLICT;
|
||||
|
||||
@@ -2557,9 +2559,11 @@ enum ref_transaction_error refs_verify_refnames_available(struct ref_store *refs
|
||||
|
||||
assert(err);
|
||||
|
||||
strset_init(&conflicting_dirnames);
|
||||
strset_init(&dirnames);
|
||||
|
||||
for_each_string_list_item(item, refnames) {
|
||||
const size_t *update_idx = (size_t *)item->util;
|
||||
const char *refname = item->string;
|
||||
const char *extra_refname;
|
||||
struct object_id oid;
|
||||
@@ -2597,14 +2601,30 @@ enum ref_transaction_error refs_verify_refnames_available(struct ref_store *refs
|
||||
continue;
|
||||
|
||||
if (!initial_transaction &&
|
||||
!refs_read_raw_ref(refs, dirname.buf, &oid, &referent,
|
||||
&type, &ignore_errno)) {
|
||||
(strset_contains(&conflicting_dirnames, dirname.buf) ||
|
||||
!refs_read_raw_ref(refs, dirname.buf, &oid, &referent,
|
||||
&type, &ignore_errno))) {
|
||||
if (transaction && ref_transaction_maybe_set_rejected(
|
||||
transaction, *update_idx,
|
||||
REF_TRANSACTION_ERROR_NAME_CONFLICT)) {
|
||||
strset_remove(&dirnames, dirname.buf);
|
||||
strset_add(&conflicting_dirnames, dirname.buf);
|
||||
continue;
|
||||
}
|
||||
|
||||
strbuf_addf(err, _("'%s' exists; cannot create '%s'"),
|
||||
dirname.buf, refname);
|
||||
goto cleanup;
|
||||
}
|
||||
|
||||
if (extras && string_list_has_string(extras, dirname.buf)) {
|
||||
if (transaction && ref_transaction_maybe_set_rejected(
|
||||
transaction, *update_idx,
|
||||
REF_TRANSACTION_ERROR_NAME_CONFLICT)) {
|
||||
strset_remove(&dirnames, dirname.buf);
|
||||
continue;
|
||||
}
|
||||
|
||||
strbuf_addf(err, _("cannot process '%s' and '%s' at the same time"),
|
||||
refname, dirname.buf);
|
||||
goto cleanup;
|
||||
@@ -2637,6 +2657,11 @@ enum ref_transaction_error refs_verify_refnames_available(struct ref_store *refs
|
||||
string_list_has_string(skip, iter->refname))
|
||||
continue;
|
||||
|
||||
if (transaction && ref_transaction_maybe_set_rejected(
|
||||
transaction, *update_idx,
|
||||
REF_TRANSACTION_ERROR_NAME_CONFLICT))
|
||||
continue;
|
||||
|
||||
strbuf_addf(err, _("'%s' exists; cannot create '%s'"),
|
||||
iter->refname, refname);
|
||||
goto cleanup;
|
||||
@@ -2648,6 +2673,11 @@ enum ref_transaction_error refs_verify_refnames_available(struct ref_store *refs
|
||||
|
||||
extra_refname = find_descendant_ref(dirname.buf, extras, skip);
|
||||
if (extra_refname) {
|
||||
if (transaction && ref_transaction_maybe_set_rejected(
|
||||
transaction, *update_idx,
|
||||
REF_TRANSACTION_ERROR_NAME_CONFLICT))
|
||||
continue;
|
||||
|
||||
strbuf_addf(err, _("cannot process '%s' and '%s' at the same time"),
|
||||
refname, extra_refname);
|
||||
goto cleanup;
|
||||
@@ -2659,6 +2689,7 @@ enum ref_transaction_error refs_verify_refnames_available(struct ref_store *refs
|
||||
cleanup:
|
||||
strbuf_release(&referent);
|
||||
strbuf_release(&dirname);
|
||||
strset_clear(&conflicting_dirnames);
|
||||
strset_clear(&dirnames);
|
||||
ref_iterator_free(iter);
|
||||
return ret;
|
||||
@@ -2679,7 +2710,7 @@ enum ref_transaction_error refs_verify_refname_available(
|
||||
};
|
||||
|
||||
return refs_verify_refnames_available(refs, &refnames, extras, skip,
|
||||
initial_transaction, err);
|
||||
NULL, initial_transaction, err);
|
||||
}
|
||||
|
||||
struct do_for_each_reflog_help {
|
||||
|
||||
Reference in New Issue
Block a user