summaryrefslogtreecommitdiff
path: root/builtin/update-ref.c
diff options
context:
space:
mode:
authorMichael Haggerty <mhagger@alum.mit.edu>2015-06-22 14:03:09 (GMT)
committerJunio C Hamano <gitster@pobox.com>2015-06-22 20:17:14 (GMT)
commite2991c80485c646c86f5d80423f9ae983bed120b (patch)
treeeb7f420f02b65e1a006fafdf1f7325b7c44a9832 /builtin/update-ref.c
parenta1c9eb918b9af809d75ee3206e684f3a8f29ee63 (diff)
downloadgit-e2991c80485c646c86f5d80423f9ae983bed120b.zip
git-e2991c80485c646c86f5d80423f9ae983bed120b.tar.gz
git-e2991c80485c646c86f5d80423f9ae983bed120b.tar.bz2
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>
Diffstat (limited to 'builtin/update-ref.c')
-rw-r--r--builtin/update-ref.c13
1 files changed, 10 insertions, 3 deletions
diff --git a/builtin/update-ref.c b/builtin/update-ref.c
index 3d79a46..160c7ac 100644
--- a/builtin/update-ref.c
+++ b/builtin/update-ref.c
@@ -408,9 +408,16 @@ int cmd_update_ref(int argc, const char **argv, const char *prefix)
die("%s: not a valid SHA1", value);
}
- hashclr(oldsha1); /* all-zero hash in case oldval is the empty string */
- if (oldval && *oldval && get_sha1(oldval, oldsha1))
- die("%s: not a valid old SHA1", oldval);
+ if (oldval) {
+ if (!*oldval)
+ /*
+ * The empty string implies that the reference
+ * must not already exist:
+ */
+ hashclr(oldsha1);
+ else if (get_sha1(oldval, oldsha1))
+ die("%s: not a valid old SHA1", oldval);
+ }
if (no_deref)
flags = REF_NODEREF;