builtin/update_ref: convert to struct object_id
Convert the uses of unsigned char * to struct object_id. Signed-off-by: brian m. carlson <sandals@crustytoothpaste.net> Signed-off-by: Junio C Hamano <gitster@pobox.com>
brian m. carlson committed
Jul 13, 2017 at 23:49 UTC
a0bb5535429ca34c1cc888fbc1649925ba69dc84
1 file changed
+34
-35
builtin/update-ref.c
+34
-35
@@ -94,10 +94,10 @@ static char *parse_refname(struct strbuf *input, const char **next)
94
* provided but cannot be converted to a SHA-1, die. flags can
95
* include PARSE_SHA1_OLD and/or PARSE_SHA1_ALLOW_EMPTY.
96
*/
97
-static int parse_next_sha1(struct strbuf *input, const char **next,
98
- unsigned char *sha1,
99
- const char *command, const char *refname,
100
- int flags)
97
+static int parse_next_oid(struct strbuf *input, const char **next,
98
+ struct object_id *oid,
99
+ const char *command, const char *refname,
100
+ int flags)
101
{
102
struct strbuf arg = STRBUF_INIT;
103
int ret = 0;
@@ -115,11 +115,11 @@ static int parse_next_sha1(struct strbuf *input, const char **next,
115
(*next)++;
116
*next = parse_arg(*next, &arg);
117
if (arg.len) {
118
- if (get_sha1(arg.buf, sha1))
118
+ if (get_oid(arg.buf, oid))
119
goto invalid;
120
} else {
121
/* Without -z, an empty value means all zeros: */
122
- hashclr(sha1);
122
+ oidclr(oid);
123
}
124
} else {
125
/* With -z, read the next NUL-terminated line */
@@ -133,13 +133,13 @@ static int parse_next_sha1(struct strbuf *input, const char **next,
133
*next += arg.len;
134
135
if (arg.len) {
136
- if (get_sha1(arg.buf, sha1))
136
+ if (get_oid(arg.buf, oid))
137
goto invalid;
138
} else if (flags & PARSE_SHA1_ALLOW_EMPTY) {
139
/* With -z, treat an empty value as all zeros: */
140
warning("%s %s: missing <newvalue>, treating as zero",
141
command, refname);
142
- hashclr(sha1);
142
+ oidclr(oid);
143
} else {
144
/*
145
* With -z, an empty non-required value means
@@ -182,26 +182,25 @@ static const char *parse_cmd_update(struct ref_transaction *transaction,
182
{
183
struct strbuf err = STRBUF_INIT;
184
char *refname;
185
- unsigned char new_sha1[20];
186
- unsigned char old_sha1[20];
185
+ struct object_id new_oid, old_oid;
186
int have_old;
187
188
refname = parse_refname(input, &next);
189
if (!refname)
190
die("update: missing <ref>");
191
193
- if (parse_next_sha1(input, &next, new_sha1, "update", refname,
194
- PARSE_SHA1_ALLOW_EMPTY))
192
+ if (parse_next_oid(input, &next, &new_oid, "update", refname,
193
+ PARSE_SHA1_ALLOW_EMPTY))
194
die("update %s: missing <newvalue>", refname);
195
197
- have_old = !parse_next_sha1(input, &next, old_sha1, "update", refname,
198
- PARSE_SHA1_OLD);
196
+ have_old = !parse_next_oid(input, &next, &old_oid, "update", refname,
197
+ PARSE_SHA1_OLD);
198
199
if (*next != line_termination)
200
die("update %s: extra input: %s", refname, next);
201
202
if (ref_transaction_update(transaction, refname,
204
- new_sha1, have_old ? old_sha1 : NULL,
203
+ new_oid.hash, have_old ? old_oid.hash : NULL,
204
update_flags | create_reflog_flag,
205
msg, &err))
206
die("%s", err.buf);
@@ -218,22 +217,22 @@ static const char *parse_cmd_create(struct ref_transaction *transaction,
217
{
218
struct strbuf err = STRBUF_INIT;
219
char *refname;
221
- unsigned char new_sha1[20];
220
+ struct object_id new_oid;
221
222
refname = parse_refname(input, &next);
223
if (!refname)
224
die("create: missing <ref>");
225
227
- if (parse_next_sha1(input, &next, new_sha1, "create", refname, 0))
226
+ if (parse_next_oid(input, &next, &new_oid, "create", refname, 0))
227
die("create %s: missing <newvalue>", refname);
228
230
- if (is_null_sha1(new_sha1))
229
+ if (is_null_oid(&new_oid))
230
die("create %s: zero <newvalue>", refname);
231
232
if (*next != line_termination)
233
die("create %s: extra input: %s", refname, next);
234
236
- if (ref_transaction_create(transaction, refname, new_sha1,
235
+ if (ref_transaction_create(transaction, refname, new_oid.hash,
236
update_flags | create_reflog_flag,
237
msg, &err))
238
die("%s", err.buf);
@@ -250,18 +249,18 @@ static const char *parse_cmd_delete(struct ref_transaction *transaction,
249
{
250
struct strbuf err = STRBUF_INIT;
251
char *refname;
253
- unsigned char old_sha1[20];
252
+ struct object_id old_oid;
253
int have_old;
254
255
refname = parse_refname(input, &next);
256
if (!refname)
257
die("delete: missing <ref>");
258
260
- if (parse_next_sha1(input, &next, old_sha1, "delete", refname,
261
- PARSE_SHA1_OLD)) {
259
+ if (parse_next_oid(input, &next, &old_oid, "delete", refname,
260
+ PARSE_SHA1_OLD)) {
261
have_old = 0;
262
} else {
264
- if (is_null_sha1(old_sha1))
263
+ if (is_null_oid(&old_oid))
264
die("delete %s: zero <oldvalue>", refname);
265
have_old = 1;
266
}
@@ -270,7 +269,7 @@ static const char *parse_cmd_delete(struct ref_transaction *transaction,
269
die("delete %s: extra input: %s", refname, next);
270
271
if (ref_transaction_delete(transaction, refname,
273
- have_old ? old_sha1 : NULL,
272
+ have_old ? old_oid.hash : NULL,
273
update_flags, msg, &err))
274
die("%s", err.buf);
275
@@ -286,20 +285,20 @@ static const char *parse_cmd_verify(struct ref_transaction *transaction,
285
{
286
struct strbuf err = STRBUF_INIT;
287
char *refname;
289
- unsigned char old_sha1[20];
288
+ struct object_id old_oid;
289
290
refname = parse_refname(input, &next);
291
if (!refname)
292
die("verify: missing <ref>");
293
295
- if (parse_next_sha1(input, &next, old_sha1, "verify", refname,
296
- PARSE_SHA1_OLD))
297
- hashclr(old_sha1);
294
+ if (parse_next_oid(input, &next, &old_oid, "verify", refname,
295
+ PARSE_SHA1_OLD))
296
+ oidclr(&old_oid);
297
298
if (*next != line_termination)
299
die("verify %s: extra input: %s", refname, next);
300
302
- if (ref_transaction_verify(transaction, refname, old_sha1,
301
+ if (ref_transaction_verify(transaction, refname, old_oid.hash,
302
update_flags, &err))
303
die("%s", err.buf);
304
@@ -355,7 +354,7 @@ static void update_refs_stdin(struct ref_transaction *transaction)
354
int cmd_update_ref(int argc, const char **argv, const char *prefix)
355
{
356
const char *refname, *oldval;
358
- unsigned char sha1[20], oldsha1[20];
357
+ struct object_id oid, oldoid;
358
int delete = 0, no_deref = 0, read_stdin = 0, end_null = 0;
359
unsigned int flags = 0;
360
int create_reflog = 0;
@@ -412,7 +411,7 @@ int cmd_update_ref(int argc, const char **argv, const char *prefix)
411
refname = argv[0];
412
value = argv[1];
413
oldval = argv[2];
415
- if (get_sha1(value, sha1))
414
+ if (get_oid(value, &oid))
415
die("%s: not a valid SHA1", value);
416
}
417
@@ -422,8 +421,8 @@ int cmd_update_ref(int argc, const char **argv, const char *prefix)
421
* The empty string implies that the reference
422
* must not already exist:
423
*/
425
- hashclr(oldsha1);
426
- else if (get_sha1(oldval, oldsha1))
424
+ oidclr(&oldoid);
425
+ else if (get_oid(oldval, &oldoid))
426
die("%s: not a valid old SHA1", oldval);
427
}
428
@@ -435,10 +434,10 @@ int cmd_update_ref(int argc, const char **argv, const char *prefix)
434
* NULL_SHA1 as "don't care" here:
435
*/
436
return delete_ref(msg, refname,
438
- (oldval && !is_null_sha1(oldsha1)) ? oldsha1 : NULL,
437
+ (oldval && !is_null_oid(&oldoid)) ? oldoid.hash : NULL,
438
flags);
439
else
441
- return update_ref(msg, refname, sha1, oldval ? oldsha1 : NULL,
440
+ return update_ref(msg, refname, oid.hash, oldval ? oldoid.hash : NULL,
441
flags | create_reflog_flag,
442
UPDATE_REFS_DIE_ON_ERR);
443
}