Skip to content

Commit cd94f76

Browse files
rsahlberggitster
authored andcommitted
fetch.c: change s_update_ref to use a ref transaction
Change s_update_ref to use a ref transaction for the ref update. Signed-off-by: Ronnie Sahlberg <[email protected]> Signed-off-by: Jonathan Nieder <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 28e6a97 commit cd94f76

File tree

1 file changed

+24
-10
lines changed

1 file changed

+24
-10
lines changed

builtin/fetch.c

Lines changed: 24 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -404,23 +404,37 @@ static int s_update_ref(const char *action,
404404
{
405405
char msg[1024];
406406
char *rla = getenv("GIT_REFLOG_ACTION");
407-
static struct ref_lock *lock;
407+
struct ref_transaction *transaction;
408+
struct strbuf err = STRBUF_INIT;
409+
int ret, df_conflict = 0;
408410

409411
if (dry_run)
410412
return 0;
411413
if (!rla)
412414
rla = default_rla.buf;
413415
snprintf(msg, sizeof(msg), "%s: %s", rla, action);
414-
lock = lock_any_ref_for_update(ref->name,
415-
check_old ? ref->old_sha1 : NULL,
416-
0, NULL);
417-
if (!lock)
418-
return errno == ENOTDIR ? STORE_REF_ERROR_DF_CONFLICT :
419-
STORE_REF_ERROR_OTHER;
420-
if (write_ref_sha1(lock, ref->new_sha1, msg) < 0)
421-
return errno == ENOTDIR ? STORE_REF_ERROR_DF_CONFLICT :
422-
STORE_REF_ERROR_OTHER;
416+
417+
transaction = ref_transaction_begin(&err);
418+
if (!transaction ||
419+
ref_transaction_update(transaction, ref->name, ref->new_sha1,
420+
ref->old_sha1, 0, check_old, msg, &err))
421+
goto fail;
422+
423+
ret = ref_transaction_commit(transaction, &err);
424+
if (ret) {
425+
df_conflict = (ret == TRANSACTION_NAME_CONFLICT);
426+
goto fail;
427+
}
428+
429+
ref_transaction_free(transaction);
430+
strbuf_release(&err);
423431
return 0;
432+
fail:
433+
ref_transaction_free(transaction);
434+
error("%s", err.buf);
435+
strbuf_release(&err);
436+
return df_conflict ? STORE_REF_ERROR_DF_CONFLICT
437+
: STORE_REF_ERROR_OTHER;
424438
}
425439

426440
#define REFCOL_WIDTH 10

0 commit comments

Comments
 (0)