зеркало из https://github.com/microsoft/git.git
refs.c: make delete_ref use a transaction
Change delete_ref to use a ref transaction for the deletion. At the same time since we no longer have any callers of repack_without_ref we can now delete this function. Change delete_ref to return 0 on success and 1 on failure instead of the previous 0 on success either 1 or -1 on failure. Signed-off-by: Ronnie Sahlberg <sahlberg@google.com> Reviewed-by: Michael Haggerty <mhagger@alum.mit.edu> Signed-off-by: Jonathan Nieder <jrnieder@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
This commit is contained in:
Родитель
029cdb4ab2
Коммит
7521cc4611
35
refs.c
35
refs.c
|
@ -2548,11 +2548,6 @@ int repack_without_refs(const char **refnames, int n, struct strbuf *err)
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int repack_without_ref(const char *refname)
|
|
||||||
{
|
|
||||||
return repack_without_refs(&refname, 1, NULL);
|
|
||||||
}
|
|
||||||
|
|
||||||
static int delete_ref_loose(struct ref_lock *lock, int flag)
|
static int delete_ref_loose(struct ref_lock *lock, int flag)
|
||||||
{
|
{
|
||||||
if (!(flag & REF_ISPACKED) || flag & REF_ISSYMREF) {
|
if (!(flag & REF_ISPACKED) || flag & REF_ISSYMREF) {
|
||||||
|
@ -2570,24 +2565,22 @@ static int delete_ref_loose(struct ref_lock *lock, int flag)
|
||||||
|
|
||||||
int delete_ref(const char *refname, const unsigned char *sha1, int delopt)
|
int delete_ref(const char *refname, const unsigned char *sha1, int delopt)
|
||||||
{
|
{
|
||||||
struct ref_lock *lock;
|
struct ref_transaction *transaction;
|
||||||
int ret = 0, flag = 0;
|
struct strbuf err = STRBUF_INIT;
|
||||||
|
|
||||||
lock = lock_ref_sha1_basic(refname, sha1, delopt, &flag);
|
transaction = ref_transaction_begin(&err);
|
||||||
if (!lock)
|
if (!transaction ||
|
||||||
|
ref_transaction_delete(transaction, refname, sha1, delopt,
|
||||||
|
sha1 && !is_null_sha1(sha1), &err) ||
|
||||||
|
ref_transaction_commit(transaction, NULL, &err)) {
|
||||||
|
error("%s", err.buf);
|
||||||
|
ref_transaction_free(transaction);
|
||||||
|
strbuf_release(&err);
|
||||||
return 1;
|
return 1;
|
||||||
ret |= delete_ref_loose(lock, flag);
|
}
|
||||||
|
ref_transaction_free(transaction);
|
||||||
/* removing the loose one could have resurrected an earlier
|
strbuf_release(&err);
|
||||||
* packed one. Also, if it was not loose we need to repack
|
return 0;
|
||||||
* without it.
|
|
||||||
*/
|
|
||||||
ret |= repack_without_ref(lock->ref_name);
|
|
||||||
|
|
||||||
unlink_or_warn(git_path("logs/%s", lock->ref_name));
|
|
||||||
clear_loose_ref_cache(&ref_cache);
|
|
||||||
unlock_ref(lock);
|
|
||||||
return ret;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
|
Загрузка…
Ссылка в новой задаче