diff options
author | Nguyễn Thái Ngọc Duy <pclouds@gmail.com> | 2017-03-26 09:42:35 +0700 |
---|---|---|
committer | Junio C Hamano <gitster@pobox.com> | 2017-04-14 03:53:25 -0700 |
commit | c0fe4e8ba3db828079f1288169a94294e713b3d8 (patch) | |
tree | 1d07025e41a5624acbad8cbfad1d7969a986d3c4 /refs.c | |
parent | 7d2df051d05bc65a0a540ba080f07b421b4d99d7 (diff) | |
download | git-c0fe4e8ba3db828079f1288169a94294e713b3d8.tar.gz |
refs: new transaction related ref-store api
The transaction struct now takes a ref store at creation and will
operate on that ref store alone.
Signed-off-by: Nguyễn Thái Ngọc Duy <pclouds@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
Diffstat (limited to 'refs.c')
-rw-r--r-- | refs.c | 55 |
1 files changed, 43 insertions, 12 deletions
@@ -630,16 +630,20 @@ static int delete_pseudoref(const char *pseudoref, const unsigned char *old_sha1 return 0; } -int delete_ref(const char *msg, const char *refname, - const unsigned char *old_sha1, unsigned int flags) +int refs_delete_ref(struct ref_store *refs, const char *msg, + const char *refname, + const unsigned char *old_sha1, + unsigned int flags) { struct ref_transaction *transaction; struct strbuf err = STRBUF_INIT; - if (ref_type(refname) == REF_TYPE_PSEUDOREF) + if (ref_type(refname) == REF_TYPE_PSEUDOREF) { + assert(refs == get_main_ref_store()); return delete_pseudoref(refname, old_sha1); + } - transaction = ref_transaction_begin(&err); + transaction = ref_store_transaction_begin(refs, &err); if (!transaction || ref_transaction_delete(transaction, refname, old_sha1, flags, msg, &err) || @@ -654,6 +658,13 @@ int delete_ref(const char *msg, const char *refname, return 0; } +int delete_ref(const char *msg, const char *refname, + const unsigned char *old_sha1, unsigned int flags) +{ + return refs_delete_ref(get_main_ref_store(), msg, refname, + old_sha1, flags); +} + int copy_reflog_msg(char *buf, const char *msg) { char *cp = buf; @@ -813,11 +824,20 @@ int read_ref_at(const char *refname, unsigned int flags, unsigned long at_time, return 1; } -struct ref_transaction *ref_transaction_begin(struct strbuf *err) +struct ref_transaction *ref_store_transaction_begin(struct ref_store *refs, + struct strbuf *err) { + struct ref_transaction *tr; assert(err); - return xcalloc(1, sizeof(struct ref_transaction)); + tr = xcalloc(1, sizeof(struct ref_transaction)); + tr->ref_store = refs; + return tr; +} + +struct ref_transaction *ref_transaction_begin(struct strbuf *err) +{ + return ref_store_transaction_begin(get_main_ref_store(), err); } void ref_transaction_free(struct ref_transaction *transaction) @@ -934,18 +954,20 @@ int update_ref_oid(const char *msg, const char *refname, old_oid ? old_oid->hash : NULL, flags, onerr); } -int update_ref(const char *msg, const char *refname, - const unsigned char *new_sha1, const unsigned char *old_sha1, - unsigned int flags, enum action_on_err onerr) +int refs_update_ref(struct ref_store *refs, const char *msg, + const char *refname, const unsigned char *new_sha1, + const unsigned char *old_sha1, unsigned int flags, + enum action_on_err onerr) { struct ref_transaction *t = NULL; struct strbuf err = STRBUF_INIT; int ret = 0; if (ref_type(refname) == REF_TYPE_PSEUDOREF) { + assert(refs == get_main_ref_store()); ret = write_pseudoref(refname, new_sha1, old_sha1, &err); } else { - t = ref_transaction_begin(&err); + t = ref_store_transaction_begin(refs, &err); if (!t || ref_transaction_update(t, refname, new_sha1, old_sha1, flags, msg, &err) || @@ -976,6 +998,15 @@ int update_ref(const char *msg, const char *refname, return 0; } +int update_ref(const char *msg, const char *refname, + const unsigned char *new_sha1, + const unsigned char *old_sha1, + unsigned int flags, enum action_on_err onerr) +{ + return refs_update_ref(get_main_ref_store(), msg, refname, new_sha1, + old_sha1, flags, onerr); +} + char *shorten_unambiguous_ref(const char *refname, int strict) { int i; @@ -1607,7 +1638,7 @@ int create_symref(const char *ref_target, const char *refs_heads_master, int ref_transaction_commit(struct ref_transaction *transaction, struct strbuf *err) { - struct ref_store *refs = get_main_ref_store(); + struct ref_store *refs = transaction->ref_store; return refs->be->transaction_commit(refs, transaction, err); } @@ -1726,7 +1757,7 @@ int reflog_expire(const char *refname, const unsigned char *sha1, int initial_ref_transaction_commit(struct ref_transaction *transaction, struct strbuf *err) { - struct ref_store *refs = get_main_ref_store(); + struct ref_store *refs = transaction->ref_store; return refs->be->initial_transaction_commit(refs, transaction, err); } |