Skip to content

Commit 84178db

Browse files
mhaggergitster
authored andcommitted
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>
1 parent 81c960e commit 84178db

1 file changed

Lines changed: 3 additions & 5 deletions

File tree

refs.c

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3279,6 +3279,7 @@ struct ref_update {
32793279
int flags; /* REF_NODEREF? */
32803280
int have_old; /* 1 if old_sha1 is valid, 0 otherwise */
32813281
struct ref_lock *lock;
3282+
int type;
32823283
const char refname[FLEX_ARRAY];
32833284
};
32843285

@@ -3413,7 +3414,6 @@ int ref_transaction_commit(struct ref_transaction *transaction,
34133414
{
34143415
int ret = 0, delnum = 0, i;
34153416
struct ref_update **updates;
3416-
int *types;
34173417
const char **delnames;
34183418
int n = transaction->nr;
34193419

@@ -3422,7 +3422,6 @@ int ref_transaction_commit(struct ref_transaction *transaction,
34223422

34233423
/* Allocate work space */
34243424
updates = xmalloc(sizeof(*updates) * n);
3425-
types = xmalloc(sizeof(*types) * n);
34263425
delnames = xmalloc(sizeof(*delnames) * n);
34273426

34283427
/* Copy, sort, and reject duplicate refs */
@@ -3440,7 +3439,7 @@ int ref_transaction_commit(struct ref_transaction *transaction,
34403439
(update->have_old ?
34413440
update->old_sha1 : NULL),
34423441
update->flags,
3443-
&types[i], onerr);
3442+
&update->type, onerr);
34443443
if (!update->lock) {
34453444
ret = 1;
34463445
goto cleanup;
@@ -3468,7 +3467,7 @@ int ref_transaction_commit(struct ref_transaction *transaction,
34683467

34693468
if (update->lock) {
34703469
delnames[delnum++] = update->lock->ref_name;
3471-
ret |= delete_ref_loose(update->lock, types[i]);
3470+
ret |= delete_ref_loose(update->lock, update->type);
34723471
}
34733472
}
34743473

@@ -3482,7 +3481,6 @@ int ref_transaction_commit(struct ref_transaction *transaction,
34823481
if (updates[i]->lock)
34833482
unlock_ref(updates[i]->lock);
34843483
free(updates);
3485-
free(types);
34863484
free(delnames);
34873485
ref_transaction_free(transaction);
34883486
return ret;

0 commit comments

Comments
 (0)