diff options
author | Ronnie Sahlberg <sahlberg@google.com> | 2014-04-30 12:22:42 -0700 |
---|---|---|
committer | Junio C Hamano <gitster@pobox.com> | 2014-10-15 10:47:22 -0700 |
commit | db7516ab9f435e3ce86b257c6631fb4d2dfb12ae (patch) | |
tree | 84b452b76a6315511691d30f7e97a2a9388b25c1 /refs.c | |
parent | dbdcac7d5c5eea314ec4c318a5e88cff427e9f0e (diff) | |
download | git-db7516ab9f435e3ce86b257c6631fb4d2dfb12ae.tar.gz |
refs.c: pass the ref log message to _create/delete/update instead of _commit
Change the ref transaction API so that we pass the reflog message to the
create/delete/update functions instead of to ref_transaction_commit.
This allows different reflog messages for each ref update in a multi-ref
transaction.
Signed-off-by: Ronnie Sahlberg <sahlberg@google.com>
Signed-off-by: Jonathan Nieder <jrnieder@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
Diffstat (limited to 'refs.c')
-rw-r--r-- | refs.c | 34 |
1 files changed, 21 insertions, 13 deletions
@@ -2445,8 +2445,8 @@ static void prune_ref(struct ref_to_prune *r) transaction = ref_transaction_begin(&err); if (!transaction || ref_transaction_delete(transaction, r->name, r->sha1, - REF_ISPRUNING, 1, &err) || - ref_transaction_commit(transaction, NULL, &err)) { + REF_ISPRUNING, 1, NULL, &err) || + ref_transaction_commit(transaction, &err)) { ref_transaction_free(transaction); error("%s", err.buf); strbuf_release(&err); @@ -2621,8 +2621,8 @@ int delete_ref(const char *refname, const unsigned char *sha1, int delopt) transaction = ref_transaction_begin(&err); if (!transaction || ref_transaction_delete(transaction, refname, sha1, delopt, - sha1 && !is_null_sha1(sha1), &err) || - ref_transaction_commit(transaction, NULL, &err)) { + sha1 && !is_null_sha1(sha1), NULL, &err) || + ref_transaction_commit(transaction, &err)) { error("%s", err.buf); ref_transaction_free(transaction); strbuf_release(&err); @@ -3404,6 +3404,7 @@ struct ref_update { int have_old; /* 1 if old_sha1 is valid, 0 otherwise */ struct ref_lock *lock; int type; + char *msg; const char refname[FLEX_ARRAY]; }; @@ -3446,9 +3447,10 @@ void ref_transaction_free(struct ref_transaction *transaction) if (!transaction) return; - for (i = 0; i < transaction->nr; i++) + for (i = 0; i < transaction->nr; i++) { + free(transaction->updates[i]->msg); free(transaction->updates[i]); - + } free(transaction->updates); free(transaction); } @@ -3469,7 +3471,7 @@ int ref_transaction_update(struct ref_transaction *transaction, const char *refname, const unsigned char *new_sha1, const unsigned char *old_sha1, - int flags, int have_old, + int flags, int have_old, const char *msg, struct strbuf *err) { struct ref_update *update; @@ -3486,13 +3488,15 @@ int ref_transaction_update(struct ref_transaction *transaction, update->have_old = have_old; if (have_old) hashcpy(update->old_sha1, old_sha1); + if (msg) + update->msg = xstrdup(msg); return 0; } int ref_transaction_create(struct ref_transaction *transaction, const char *refname, const unsigned char *new_sha1, - int flags, + int flags, const char *msg, struct strbuf *err) { struct ref_update *update; @@ -3509,13 +3513,15 @@ int ref_transaction_create(struct ref_transaction *transaction, hashclr(update->old_sha1); update->flags = flags; update->have_old = 1; + if (msg) + update->msg = xstrdup(msg); return 0; } int ref_transaction_delete(struct ref_transaction *transaction, const char *refname, const unsigned char *old_sha1, - int flags, int have_old, + int flags, int have_old, const char *msg, struct strbuf *err) { struct ref_update *update; @@ -3533,6 +3539,8 @@ int ref_transaction_delete(struct ref_transaction *transaction, assert(!is_null_sha1(old_sha1)); hashcpy(update->old_sha1, old_sha1); } + if (msg) + update->msg = xstrdup(msg); return 0; } @@ -3546,8 +3554,8 @@ int update_ref(const char *action, const char *refname, t = ref_transaction_begin(&err); if (!t || ref_transaction_update(t, refname, sha1, oldval, flags, - !!oldval, &err) || - ref_transaction_commit(t, action, &err)) { + !!oldval, action, &err) || + ref_transaction_commit(t, &err)) { const char *str = "update_ref failed for ref '%s': %s"; ref_transaction_free(t); @@ -3593,7 +3601,7 @@ static int ref_update_reject_duplicates(struct ref_update **updates, int n, } int ref_transaction_commit(struct ref_transaction *transaction, - const char *msg, struct strbuf *err) + struct strbuf *err) { int ret = 0, delnum = 0, i; const char **delnames; @@ -3642,7 +3650,7 @@ int ref_transaction_commit(struct ref_transaction *transaction, if (!is_null_sha1(update->new_sha1)) { ret = write_ref_sha1(update->lock, update->new_sha1, - msg); + update->msg); update->lock = NULL; /* freed by write_ref_sha1 */ if (ret) { if (err) |