struct ref_update: add a lock field
Now that we manage ref_update objects internally, we can use them to hold some of the scratch space we need when actually carrying out the updates. Store the (struct ref_lock *) there. Signed-off-by: Michael Haggerty <mhagger@alum.mit.edu> Signed-off-by: Junio C Hamano <gitster@pobox.com>maint
parent
cb198d21d3
commit
81c960e4dc
28
refs.c
28
refs.c
|
@ -3278,6 +3278,7 @@ struct ref_update {
|
||||||
unsigned char old_sha1[20];
|
unsigned char old_sha1[20];
|
||||||
int flags; /* REF_NODEREF? */
|
int flags; /* REF_NODEREF? */
|
||||||
int have_old; /* 1 if old_sha1 is valid, 0 otherwise */
|
int have_old; /* 1 if old_sha1 is valid, 0 otherwise */
|
||||||
|
struct ref_lock *lock;
|
||||||
const char refname[FLEX_ARRAY];
|
const char refname[FLEX_ARRAY];
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -3413,7 +3414,6 @@ int ref_transaction_commit(struct ref_transaction *transaction,
|
||||||
int ret = 0, delnum = 0, i;
|
int ret = 0, delnum = 0, i;
|
||||||
struct ref_update **updates;
|
struct ref_update **updates;
|
||||||
int *types;
|
int *types;
|
||||||
struct ref_lock **locks;
|
|
||||||
const char **delnames;
|
const char **delnames;
|
||||||
int n = transaction->nr;
|
int n = transaction->nr;
|
||||||
|
|
||||||
|
@ -3423,7 +3423,6 @@ int ref_transaction_commit(struct ref_transaction *transaction,
|
||||||
/* Allocate work space */
|
/* Allocate work space */
|
||||||
updates = xmalloc(sizeof(*updates) * n);
|
updates = xmalloc(sizeof(*updates) * n);
|
||||||
types = xmalloc(sizeof(*types) * n);
|
types = xmalloc(sizeof(*types) * n);
|
||||||
locks = xcalloc(n, sizeof(*locks));
|
|
||||||
delnames = xmalloc(sizeof(*delnames) * n);
|
delnames = xmalloc(sizeof(*delnames) * n);
|
||||||
|
|
||||||
/* Copy, sort, and reject duplicate refs */
|
/* Copy, sort, and reject duplicate refs */
|
||||||
|
@ -3437,12 +3436,12 @@ int ref_transaction_commit(struct ref_transaction *transaction,
|
||||||
for (i = 0; i < n; i++) {
|
for (i = 0; i < n; i++) {
|
||||||
struct ref_update *update = updates[i];
|
struct ref_update *update = updates[i];
|
||||||
|
|
||||||
locks[i] = update_ref_lock(update->refname,
|
update->lock = update_ref_lock(update->refname,
|
||||||
(update->have_old ?
|
(update->have_old ?
|
||||||
update->old_sha1 : NULL),
|
update->old_sha1 : NULL),
|
||||||
update->flags,
|
update->flags,
|
||||||
&types[i], onerr);
|
&types[i], onerr);
|
||||||
if (!locks[i]) {
|
if (!update->lock) {
|
||||||
ret = 1;
|
ret = 1;
|
||||||
goto cleanup;
|
goto cleanup;
|
||||||
}
|
}
|
||||||
|
@ -3456,19 +3455,23 @@ int ref_transaction_commit(struct ref_transaction *transaction,
|
||||||
ret = update_ref_write(msg,
|
ret = update_ref_write(msg,
|
||||||
update->refname,
|
update->refname,
|
||||||
update->new_sha1,
|
update->new_sha1,
|
||||||
locks[i], onerr);
|
update->lock, onerr);
|
||||||
locks[i] = NULL; /* freed by update_ref_write */
|
update->lock = NULL; /* freed by update_ref_write */
|
||||||
if (ret)
|
if (ret)
|
||||||
goto cleanup;
|
goto cleanup;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Perform deletes now that updates are safely completed */
|
/* Perform deletes now that updates are safely completed */
|
||||||
for (i = 0; i < n; i++)
|
for (i = 0; i < n; i++) {
|
||||||
if (locks[i]) {
|
struct ref_update *update = updates[i];
|
||||||
delnames[delnum++] = locks[i]->ref_name;
|
|
||||||
ret |= delete_ref_loose(locks[i], types[i]);
|
if (update->lock) {
|
||||||
|
delnames[delnum++] = update->lock->ref_name;
|
||||||
|
ret |= delete_ref_loose(update->lock, types[i]);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
ret |= repack_without_refs(delnames, delnum);
|
ret |= repack_without_refs(delnames, delnum);
|
||||||
for (i = 0; i < delnum; i++)
|
for (i = 0; i < delnum; i++)
|
||||||
unlink_or_warn(git_path("logs/%s", delnames[i]));
|
unlink_or_warn(git_path("logs/%s", delnames[i]));
|
||||||
|
@ -3476,11 +3479,10 @@ int ref_transaction_commit(struct ref_transaction *transaction,
|
||||||
|
|
||||||
cleanup:
|
cleanup:
|
||||||
for (i = 0; i < n; i++)
|
for (i = 0; i < n; i++)
|
||||||
if (locks[i])
|
if (updates[i]->lock)
|
||||||
unlock_ref(locks[i]);
|
unlock_ref(updates[i]->lock);
|
||||||
free(updates);
|
free(updates);
|
||||||
free(types);
|
free(types);
|
||||||
free(locks);
|
|
||||||
free(delnames);
|
free(delnames);
|
||||||
ref_transaction_free(transaction);
|
ref_transaction_free(transaction);
|
||||||
return ret;
|
return ret;
|
||||||
|
|
Loading…
Reference in New Issue