Skip to content

Commit 04ad622

Browse files
rsahlberggitster
authored andcommitted
refs.c: remove the update_ref_write function
Since we only call update_ref_write from a single place and we only call it with onerr==QUIET_ON_ERR we can just as well get rid of it and just call write_ref_sha1 directly. This changes the return status for _commit from 1 to -1 on failures when writing to the ref. Eventually we will want _commit to start returning more detailed error conditions than the current simple success/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>
1 parent 45421e2 commit 04ad622

1 file changed

Lines changed: 8 additions & 26 deletions

File tree

refs.c

Lines changed: 8 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -3336,25 +3336,6 @@ int for_each_reflog(each_ref_fn fn, void *cb_data)
33363336
return retval;
33373337
}
33383338

3339-
static int update_ref_write(const char *action, const char *refname,
3340-
const unsigned char *sha1, struct ref_lock *lock,
3341-
struct strbuf *err, enum action_on_err onerr)
3342-
{
3343-
if (write_ref_sha1(lock, sha1, action) < 0) {
3344-
const char *str = "Cannot update the ref '%s'.";
3345-
if (err)
3346-
strbuf_addf(err, str, refname);
3347-
3348-
switch (onerr) {
3349-
case UPDATE_REFS_MSG_ON_ERR: error(str, refname); break;
3350-
case UPDATE_REFS_DIE_ON_ERR: die(str, refname); break;
3351-
case UPDATE_REFS_QUIET_ON_ERR: break;
3352-
}
3353-
return 1;
3354-
}
3355-
return 0;
3356-
}
3357-
33583339
/**
33593340
* Information needed for a single ref update. Set new_sha1 to the
33603341
* new value or to zero to delete the ref. To check the old value
@@ -3605,14 +3586,15 @@ int ref_transaction_commit(struct ref_transaction *transaction,
36053586
struct ref_update *update = updates[i];
36063587

36073588
if (!is_null_sha1(update->new_sha1)) {
3608-
ret = update_ref_write(msg,
3609-
update->refname,
3610-
update->new_sha1,
3611-
update->lock, err,
3612-
UPDATE_REFS_QUIET_ON_ERR);
3613-
update->lock = NULL; /* freed by update_ref_write */
3614-
if (ret)
3589+
ret = write_ref_sha1(update->lock, update->new_sha1,
3590+
msg);
3591+
update->lock = NULL; /* freed by write_ref_sha1 */
3592+
if (ret) {
3593+
if (err)
3594+
strbuf_addf(err, "Cannot update the ref '%s'.",
3595+
update->refname);
36153596
goto cleanup;
3597+
}
36163598
}
36173599
}
36183600

0 commit comments

Comments
 (0)