@@ -998,17 +998,27 @@ int read_ref_at(struct ref_store *refs, const char *refname,
return 1;
}
-struct ref_transaction *ref_store_transaction_begin(struct ref_store *refs,
- struct strbuf *err)
+struct ref_transaction *ref_store_transaction_begin_extended(struct ref_store *refs,
+ unsigned int hook_flags,
+ struct strbuf *err)
{
struct ref_transaction *tr;
assert(err);
CALLOC_ARRAY(tr, 1);
tr->ref_store = refs;
+ tr->hook_flags = hook_flags;
return tr;
}
+struct ref_transaction *ref_store_transaction_begin(struct ref_store *refs,
+ struct strbuf *err)
+{
+ return ref_store_transaction_begin_extended(refs,
+ REF_TRANSACTION_RUN_ALL_HOOKS,
+ err);
+}
+
struct ref_transaction *ref_transaction_begin(struct strbuf *err)
{
return ref_store_transaction_begin(get_main_ref_store(the_repository), err);
@@ -2074,6 +2084,17 @@ static int run_transaction_hook(struct ref_transaction *transaction,
const char *hook;
int ret = 0, i;
+ if (!strcmp(state, "prepared")) {
+ if (!(transaction->hook_flags & REF_TRANSACTION_RUN_PREPARED_HOOK))
+ return 0;
+ } else if (!strcmp(state, "committed")) {
+ if (!(transaction->hook_flags & REF_TRANSACTION_RUN_COMMITTED_HOOK))
+ return 0;
+ } else if (!strcmp(state, "aborted")) {
+ if (!(transaction->hook_flags & REF_TRANSACTION_RUN_ABORTED_HOOK))
+ return 0;
+ }
+
hook = find_hook("reference-transaction");
if (!hook)
return ret;
@@ -570,6 +570,9 @@ enum action_on_err {
* Begin a reference transaction. The reference transaction must
* be freed by calling ref_transaction_free().
*/
+struct ref_transaction *ref_store_transaction_begin_extended(struct ref_store *refs,
+ unsigned int hook_flags,
+ struct strbuf *err);
struct ref_transaction *ref_store_transaction_begin(struct ref_store *refs,
struct strbuf *err);
struct ref_transaction *ref_transaction_begin(struct strbuf *err);
@@ -201,6 +201,13 @@ enum ref_transaction_state {
REF_TRANSACTION_CLOSED = 2
};
+#define REF_TRANSACTION_RUN_PREPARED_HOOK (1 << 0)
+#define REF_TRANSACTION_RUN_COMMITTED_HOOK (1 << 1)
+#define REF_TRANSACTION_RUN_ABORTED_HOOK (1 << 2)
+#define REF_TRANSACTION_RUN_ALL_HOOKS \
+ (REF_TRANSACTION_RUN_PREPARED_HOOK | \
+ REF_TRANSACTION_RUN_COMMITTED_HOOK | \
+ REF_TRANSACTION_RUN_ABORTED_HOOK)
/*
* Data structure for holding a reference transaction, which can
* consist of checks and updates to multiple references, carried out
@@ -212,6 +219,7 @@ struct ref_transaction {
size_t alloc;
size_t nr;
enum ref_transaction_state state;
+ unsigned int hook_flags;
void *backend_data;
};