| 3056 | } |
| 3057 | |
| 3058 | int refs_delete_refs(struct ref_store *refs, const char *logmsg, |
| 3059 | struct string_list *refnames, unsigned int flags) |
| 3060 | { |
| 3061 | struct ref_transaction *transaction; |
| 3062 | struct strbuf err = STRBUF_INIT; |
| 3063 | struct string_list_item *item; |
| 3064 | int ret = 0, failures = 0; |
| 3065 | char *msg; |
| 3066 | |
| 3067 | if (!refnames->nr) |
| 3068 | return 0; |
| 3069 | |
| 3070 | msg = normalize_reflog_message(logmsg); |
| 3071 | |
| 3072 | /* |
| 3073 | * Since we don't check the references' old_oids, the |
| 3074 | * individual updates can't fail, so we can pack all of the |
| 3075 | * updates into a single transaction. |
| 3076 | */ |
| 3077 | transaction = ref_store_transaction_begin(refs, 0, &err); |
| 3078 | if (!transaction) { |
| 3079 | ret = error("%s", err.buf); |
| 3080 | goto out; |
| 3081 | } |
| 3082 | |
| 3083 | for_each_string_list_item(item, refnames) { |
| 3084 | ret = ref_transaction_delete(transaction, item->string, |
| 3085 | NULL, NULL, flags, msg, &err); |
| 3086 | if (ret) { |
| 3087 | warning(_("could not delete reference %s: %s"), |
| 3088 | item->string, err.buf); |
| 3089 | strbuf_reset(&err); |
| 3090 | failures = 1; |
| 3091 | } |
| 3092 | } |
| 3093 | |
| 3094 | ret = ref_transaction_commit(transaction, &err); |
| 3095 | if (ret) { |
| 3096 | if (refnames->nr == 1) |
| 3097 | error(_("could not delete reference %s: %s"), |
| 3098 | refnames->items[0].string, err.buf); |
| 3099 | else |
| 3100 | error(_("could not delete references: %s"), err.buf); |
| 3101 | } |
| 3102 | |
| 3103 | out: |
| 3104 | if (!ret && failures) |
| 3105 | ret = -1; |
| 3106 | ref_transaction_free(transaction); |
| 3107 | strbuf_release(&err); |
| 3108 | free(msg); |
| 3109 | return ret; |
| 3110 | } |
| 3111 | |
| 3112 | int refs_rename_ref(struct ref_store *refs, const char *oldref, |
| 3113 | const char *newref, const char *logmsg) |