mailinfo: do not let handle_boundary() touch global "line" directly
[gitweb.git] / builtin / update-ref.c
index 9046443731a3a4b14b4ab55b71686a2495155f87..7f30d3a76f69e58ae3cdbbe05c5ebdce6c8a120d 100644 (file)
@@ -365,7 +365,7 @@ int cmd_update_ref(int argc, const char **argv, const char *prefix)
                                        N_("update <refname> not the one it points to")),
                OPT_BOOL('z', NULL, &end_null, N_("stdin has NUL-terminated arguments")),
                OPT_BOOL( 0 , "stdin", &read_stdin, N_("read updates from stdin")),
-               OPT_BOOL( 0 , "create-reflog", &create_reflog, N_("create_reflog")),
+               OPT_BOOL( 0 , "create-reflog", &create_reflog, N_("create a reflog")),
                OPT_END(),
        };
 
@@ -415,14 +415,27 @@ 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;
        if (delete)
-               return delete_ref(refname, oldval ? oldsha1 : NULL, flags);
+               /*
+                * For purposes of backwards compatibility, we treat
+                * NULL_SHA1 as "don't care" here:
+                */
+               return delete_ref(refname,
+                                 (oldval && !is_null_sha1(oldsha1)) ? oldsha1 : NULL,
+                                 flags);
        else
                return update_ref(msg, refname, sha1, oldval ? oldsha1 : NULL,
                                  flags | create_reflog_flag,