update_ref(): don't read old reference value before delete

If we are deleting the reference, then we don't need to read the reference's old value. It doesn't provide any race safety, because the value read just before the delete is no "better" than the value that would be read under lock during the delete. And even if the reference previously didn't exist, we can call delete_ref() on it if we don't provide an old_sha1 value. Signed-off-by: Michael Haggerty <mhagger@alum.mit.edu> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Michael Haggerty committed Jun 22, 2015 at 16:03 UTC a1c9eb918b9af809d75ee3206e684f3a8f29ee63
1 file changed +3 -3
fast-import.c
+3 -3
@@ -1692,13 +1692,13 @@ static int update_branch(struct branch *b)
1692 unsigned char old_sha1[20];
1693 struct strbuf err = STRBUF_INIT;
1694
1695 - if (read_ref(b->name, old_sha1))
1696 - hashclr(old_sha1);
1695 if (is_null_sha1(b->sha1)) {
1696 if (b->delete)
1699 - delete_ref(b->name, old_sha1, 0);
1697 + delete_ref(b->name, NULL, 0);
1698 return 0;
1699 }
1700 + if (read_ref(b->name, old_sha1))
1701 + hashclr(old_sha1);
1702 if (!force_update && !is_null_sha1(old_sha1)) {
1703 struct commit *old_cmit, *new_cmit;
1704