aboutsummaryrefslogtreecommitdiff
path: root/refs.c
diff options
context:
space:
mode:
Diffstat (limited to 'refs.c')
-rw-r--r--refs.c18
1 files changed, 15 insertions, 3 deletions
diff --git a/refs.c b/refs.c
index 6fb8f9d10c..5d1d28523d 100644
--- a/refs.c
+++ b/refs.c
@@ -64,6 +64,9 @@ const char *ref_storage_format_to_name(enum ref_storage_format ref_storage_forma
return be->name;
}
+static const char *abort_by_ref_transaction_hook =
+ N_("in '%s' phase, update aborted by the reference-transaction hook");
+
/*
* How to handle various characters in refnames:
* 0: An acceptable character for refs
@@ -740,7 +743,8 @@ static char *substitute_branch_name(struct repository *r,
return NULL;
}
-void copy_branchname(struct strbuf *sb, const char *name, unsigned allowed)
+void copy_branchname(struct strbuf *sb, const char *name,
+ enum interpret_branch_kind allowed)
{
int len = strlen(name);
struct interpret_branch_name_options options = {
@@ -2591,7 +2595,8 @@ static int transaction_hook_feed_stdin(int hook_stdin_fd, void *pp_cb, void *pp_
static void *transaction_feed_cb_data_alloc(void *feed_pipe_ctx UNUSED)
{
- struct transaction_feed_cb_data *data = xmalloc(sizeof(*data));
+ struct transaction_feed_cb_data *data;
+ CALLOC_ARRAY(data, 1);
strbuf_init(&data->buf, 0);
data->index = 0;
return data;
@@ -2655,6 +2660,13 @@ int ref_transaction_prepare(struct ref_transaction *transaction,
if (ref_update_reject_duplicates(&transaction->refnames, err))
return REF_TRANSACTION_ERROR_GENERIC;
+ /* Preparing checks before locking references */
+ ret = run_transaction_hook(transaction, "preparing");
+ if (ret) {
+ ref_transaction_abort(transaction, err);
+ die(_(abort_by_ref_transaction_hook), "preparing");
+ }
+
ret = refs->be->transaction_prepare(refs, transaction, err);
if (ret)
return ret;
@@ -2662,7 +2674,7 @@ int ref_transaction_prepare(struct ref_transaction *transaction,
ret = run_transaction_hook(transaction, "prepared");
if (ret) {
ref_transaction_abort(transaction, err);
- die(_("ref updates aborted by hook"));
+ die(_(abort_by_ref_transaction_hook), "prepared");
}
return 0;