cmd_update_ref(): make logic more straightforward

Restructure the code to avoid clearing oldsha1 when oldval is unset. It's value is not needed in that case, so this change makes it more obvious that its initialization is consistent with its later use. 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 e2991c80485c646c86f5d80423f9ae983bed120b
1 file changed +10 -3
builtin/update-ref.c
+10 -3
@@ -408,9 +408,16 @@ int cmd_update_ref(int argc, const char **argv, const char *prefix)
408 die("%s: not a valid SHA1", value);
409 }
410
411 - hashclr(oldsha1); /* all-zero hash in case oldval is the empty string */
412 - if (oldval && *oldval && get_sha1(oldval, oldsha1))
413 - die("%s: not a valid old SHA1", oldval);
411 + if (oldval) {
412 + if (!*oldval)
413 + /*
414 + * The empty string implies that the reference
415 + * must not already exist:
416 + */
417 + hashclr(oldsha1);
418 + else if (get_sha1(oldval, oldsha1))
419 + die("%s: not a valid old SHA1", oldval);
420 + }
421
422 if (no_deref)
423 flags = REF_NODEREF;