struct ref_update: store refname as a FLEX_ARRAY
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
88615910db7f700ae437318308a8631888bd28cd
1 file changed
+6
-9
refs.c
+6
-9
@@ -3274,11 +3274,11 @@ static int update_ref_write(const char *action, const char *refname,
3274
* value or to zero to ensure the ref does not exist before update.
3275
*/
3276
struct ref_update {
3277
- const char *refname;
3277
unsigned char new_sha1[20];
3278
unsigned char old_sha1[20];
3279
int flags; /* REF_NODEREF? */
3280
int have_old; /* 1 if old_sha1 is valid, 0 otherwise */
3281
+ const char refname[FLEX_ARRAY];
3282
};
3283
3284
/*
@@ -3301,12 +3301,8 @@ static void ref_transaction_free(struct ref_transaction *transaction)
3301
{
3302
int i;
3303
3304
- for (i = 0; i < transaction->nr; i++) {
3305
- struct ref_update *update = transaction->updates[i];
3306
-
3307
- free((char *)update->refname);
3308
- free(update);
3309
- }
3304
+ for (i = 0; i < transaction->nr; i++)
3305
+ free(transaction->updates[i]);
3306
3307
free(transaction->updates);
3308
free(transaction);
@@ -3320,9 +3316,10 @@ void ref_transaction_rollback(struct ref_transaction *transaction)
3316
static struct ref_update *add_update(struct ref_transaction *transaction,
3317
const char *refname)
3318
{
3323
- struct ref_update *update = xcalloc(1, sizeof(*update));
3319
+ size_t len = strlen(refname);
3320
+ struct ref_update *update = xcalloc(1, sizeof(*update) + len + 1);
3321
3325
- update->refname = xstrdup(refname);
3322
+ strcpy((char *)update->refname, refname);
3323
ALLOC_GROW(transaction->updates, transaction->nr + 1, transaction->alloc);
3324
transaction->updates[transaction->nr++] = update;
3325
return update;