* Parse an argument separator followed by the next argument, if any. * If there is an argument, convert it to a SHA-1, write it to sha1, * set *next to point at the character terminating the argument, and * return 0. If there is no argument at all (not even the empty * string), return 1 and leave *next unchanged. If the value is * provided but cannot be converted to a SHA-1, die. flags can
| 170 | * include PARSE_SHA1_OLD and/or PARSE_SHA1_ALLOW_EMPTY. |
| 171 | */ |
| 172 | static int parse_next_oid(const char **next, const char *end, |
| 173 | struct object_id *oid, |
| 174 | const char *command, const char *refname, |
| 175 | int flags) |
| 176 | { |
| 177 | struct strbuf arg = STRBUF_INIT; |
| 178 | int ret = 0; |
| 179 | |
| 180 | if (*next == end) |
| 181 | goto eof; |
| 182 | |
| 183 | if (line_termination) { |
| 184 | /* Without -z, consume SP and use next argument */ |
| 185 | if (!**next || **next == line_termination) |
| 186 | return 1; |
| 187 | if (**next != ' ') |
| 188 | die("%s %s: expected SP but got: %s", |
| 189 | command, refname, *next); |
| 190 | (*next)++; |
| 191 | *next = parse_arg(*next, &arg); |
| 192 | if (arg.len) { |
| 193 | if (repo_get_oid_with_flags(the_repository, arg.buf, oid, |
| 194 | GET_OID_SKIP_AMBIGUITY_CHECK)) |
| 195 | goto invalid; |
| 196 | } else { |
| 197 | /* Without -z, an empty value means all zeros: */ |
| 198 | oidclr(oid, the_repository->hash_algo); |
| 199 | } |
| 200 | } else { |
| 201 | /* With -z, read the next NUL-terminated line */ |
| 202 | if (**next) |
| 203 | die("%s %s: expected NUL but got: %s", |
| 204 | command, refname, *next); |
| 205 | (*next)++; |
| 206 | if (*next == end) |
| 207 | goto eof; |
| 208 | strbuf_addstr(&arg, *next); |
| 209 | *next += arg.len; |
| 210 | |
| 211 | if (arg.len) { |
| 212 | if (repo_get_oid_with_flags(the_repository, arg.buf, oid, |
| 213 | GET_OID_SKIP_AMBIGUITY_CHECK)) |
| 214 | goto invalid; |
| 215 | } else if (flags & PARSE_SHA1_ALLOW_EMPTY) { |
| 216 | /* With -z, treat an empty value as all zeros: */ |
| 217 | warning("%s %s: missing <new-oid>, treating as zero", |
| 218 | command, refname); |
| 219 | oidclr(oid, the_repository->hash_algo); |
| 220 | } else { |
| 221 | /* |
| 222 | * With -z, an empty non-required value means |
| 223 | * unspecified: |
| 224 | */ |
| 225 | ret = 1; |
| 226 | } |
| 227 | } |
| 228 | |
| 229 | strbuf_release(&arg); |
no test coverage detected