struct ref_update: add a type field

It used to be that ref_transaction_commit() allocated a temporary array to hold the types of references while it is working. Instead, add a type field to ref_update that ref_transaction_commit() can use as its scratch space. Signed-off-by: Michael Haggerty <mhagger@alum.mit.edu> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Michael Haggerty committed Apr 7, 2014 at 15:48 UTC 84178db76f34d0b8d363545f6e18c99f6e37df4e
1 file changed +3 -5
refs.c
+3 -5
@@ -3279,6 +3279,7 @@ struct ref_update {
3279 int flags; /* REF_NODEREF? */
3280 int have_old; /* 1 if old_sha1 is valid, 0 otherwise */
3281 struct ref_lock *lock;
3282 + int type;
3283 const char refname[FLEX_ARRAY];
3284 };
3285
@@ -3413,7 +3414,6 @@ int ref_transaction_commit(struct ref_transaction *transaction,
3414 {
3415 int ret = 0, delnum = 0, i;
3416 struct ref_update **updates;
3416 - int *types;
3417 const char **delnames;
3418 int n = transaction->nr;
3419
@@ -3422,7 +3422,6 @@ int ref_transaction_commit(struct ref_transaction *transaction,
3422
3423 /* Allocate work space */
3424 updates = xmalloc(sizeof(*updates) * n);
3425 - types = xmalloc(sizeof(*types) * n);
3425 delnames = xmalloc(sizeof(*delnames) * n);
3426
3427 /* Copy, sort, and reject duplicate refs */
@@ -3440,7 +3439,7 @@ int ref_transaction_commit(struct ref_transaction *transaction,
3439 (update->have_old ?
3440 update->old_sha1 : NULL),
3441 update->flags,
3443 - &types[i], onerr);
3442 + &update->type, onerr);
3443 if (!update->lock) {
3444 ret = 1;
3445 goto cleanup;
@@ -3468,7 +3467,7 @@ int ref_transaction_commit(struct ref_transaction *transaction,
3467
3468 if (update->lock) {
3469 delnames[delnum++] = update->lock->ref_name;
3471 - ret |= delete_ref_loose(update->lock, types[i]);
3470 + ret |= delete_ref_loose(update->lock, update->type);
3471 }
3472 }
3473
@@ -3482,7 +3481,6 @@ cleanup:
3481 if (updates[i]->lock)
3482 unlock_ref(updates[i]->lock);
3483 free(updates);
3485 - free(types);
3484 free(delnames);
3485 ref_transaction_free(transaction);
3486 return ret;