update-ref --stdin -z: deprecate interpreting the empty string as zeros
In the original version of this command, for the single case of the "update" command's <newvalue>, the empty string was interpreted as being equivalent to 40 "0"s. This shorthand is unnecessary (binary input will usually be generated programmatically anyway), and it complicates the parser and the documentation. So gently deprecate this usage: remove its description from the documentation and emit a warning if it is found. But for reasons of backwards compatibility, continue to accept it. Helped-by: Brad King <brad.king@kitware.com> Signed-off-by: Michael Haggerty <mhagger@alum.mit.edu> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Michael Haggerty committed
Apr 7, 2014 at 15:48 UTC
1fbd504942b20a541ba4fcbe90d3ea21b03717e4
3 files changed
+17
-8
Documentation/git-update-ref.txt
+12
-6
@@ -68,7 +68,12 @@ performs all modifications together. Specify commands of the form:
68
option SP <opt> LF
69
70
Quote fields containing whitespace as if they were strings in C source
71
-code. Alternatively, use `-z` to specify commands without quoting:
71
+code; i.e., surrounded by double-quotes and with backslash escapes.
72
+Use 40 "0" characters or the empty string to specify a zero value. To
73
+specify a missing value, omit the value and its preceding SP entirely.
74
+
75
+Alternatively, use `-z` to specify in NUL-terminated format, without
76
+quoting:
77
78
update SP <ref> NUL <newvalue> NUL [<oldvalue>] NUL
79
create SP <ref> NUL <newvalue> NUL
@@ -76,8 +81,12 @@ code. Alternatively, use `-z` to specify commands without quoting:
81
verify SP <ref> NUL [<oldvalue>] NUL
82
option SP <opt> NUL
83
79
-Lines of any other format or a repeated <ref> produce an error.
80
-Command meanings are:
84
+In this format, use 40 "0" to specify a zero value, and use the empty
85
+string to specify a missing value.
86
+
87
+In either format, values can be specified in any form that Git
88
+recognizes as an object name. Commands in any other format or a
89
+repeated <ref> produce an error. Command meanings are:
90
91
update::
92
Set <ref> to <newvalue> after verifying <oldvalue>, if given.
@@ -102,9 +111,6 @@ option::
111
The only valid option is `no-deref` to avoid dereferencing
112
a symbolic ref.
113
105
-Use 40 "0" or the empty string to specify a zero value, except that
106
-with `-z` an empty <oldvalue> is considered missing.
107
-
114
If all <ref>s can be locked with matching <oldvalue>s
115
simultaneously, all modifications are performed. Otherwise, no
116
modifications are performed. Note that while each individual
builtin/update-ref.c
+2
@@ -154,6 +154,8 @@ static int parse_next_sha1(struct strbuf *input, const char **next,
154
goto invalid;
155
} else if (flags & PARSE_SHA1_ALLOW_EMPTY) {
156
/* With -z, treat an empty value as all zeros: */
157
+ warning("%s %s: missing <newvalue>, treating as zero",
158
+ command, refname);
159
hashclr(sha1);
160
} else {
161
/*
t/t1400-update-ref.sh
+3
-2
@@ -730,10 +730,11 @@ test_expect_success 'stdin -z fails update with bad ref name' '
730
grep "fatal: invalid ref format: ~a" err
731
'
732
733
-test_expect_success 'stdin -z treats empty new value as zeros' '
733
+test_expect_success 'stdin -z emits warning with empty new value' '
734
git update-ref $a $m &&
735
printf $F "update $a" "" "" >stdin &&
736
- git update-ref -z --stdin <stdin &&
736
+ git update-ref -z --stdin <stdin 2>err &&
737
+ grep "warning: update $a: missing <newvalue>, treating as zero" err &&
738
test_must_fail git rev-parse --verify -q $a
739
'
740