update_ref(): don't read old reference value before delete
[gitweb.git] / fast-import.c
index 6378726993445694581ac36d6351f817fe488c72..d7ed0653812be7ea047b98f7a2af3a28e0e70207 100644 (file)
@@ -1692,13 +1692,13 @@ static int update_branch(struct branch *b)
        unsigned char old_sha1[20];
        struct strbuf err = STRBUF_INIT;
 
-       if (read_ref(b->name, old_sha1))
-               hashclr(old_sha1);
        if (is_null_sha1(b->sha1)) {
                if (b->delete)
-                       delete_ref(b->name, old_sha1, 0);
+                       delete_ref(b->name, NULL, 0);
                return 0;
        }
+       if (read_ref(b->name, old_sha1))
+               hashclr(old_sha1);
        if (!force_update && !is_null_sha1(old_sha1)) {
                struct commit *old_cmit, *new_cmit;