upload-pack: convert remaining parse_object callers to object_id
Convert the remaining parse_object callers to struct object_id. Use named constants for several hard-coded values. In addition, rename got_sha1 to got_oid to reflect the new argument. Signed-off-by: brian m. carlson <sandals@crustytoothpaste.net> Signed-off-by: Junio C Hamano <gitster@pobox.com>
brian m. carlson committed
May 6, 2017 at 22:10 UTC
cf93982faefd3a9a488ea9a68c60e3a81a4e0432
1 file changed
+25
-25
upload-pack.c
+25
-25
@@ -286,19 +286,19 @@ static void create_pack_file(void)
286
die("git upload-pack: %s", abort_msg);
287
}
288
289
-static int got_sha1(const char *hex, unsigned char *sha1)
289
+static int got_oid(const char *hex, struct object_id *oid)
290
{
291
struct object *o;
292
int we_knew_they_have = 0;
293
294
- if (get_sha1_hex(hex, sha1))
294
+ if (get_oid_hex(hex, oid))
295
die("git upload-pack: expected SHA1 object, got '%s'", hex);
296
- if (!has_sha1_file(sha1))
296
+ if (!has_object_file(oid))
297
return -1;
298
299
- o = parse_object(sha1);
299
+ o = parse_object(oid->hash);
300
if (!o)
301
- die("oops (%s)", sha1_to_hex(sha1));
301
+ die("oops (%s)", oid_to_hex(oid));
302
if (o->type == OBJ_COMMIT) {
303
struct commit_list *parents;
304
struct commit *commit = (struct commit *)o;
@@ -382,8 +382,8 @@ static int ok_to_give_up(void)
382
383
static int get_common_commits(void)
384
{
385
- unsigned char sha1[20];
386
- char last_hex[41];
385
+ struct object_id oid;
386
+ char last_hex[GIT_MAX_HEXSZ + 1];
387
int got_common = 0;
388
int got_other = 0;
389
int sent_ready = 0;
@@ -416,11 +416,11 @@ static int get_common_commits(void)
416
continue;
417
}
418
if (skip_prefix(line, "have ", &arg)) {
419
- switch (got_sha1(arg, sha1)) {
419
+ switch (got_oid(arg, &oid)) {
420
case -1: /* they have what we do not */
421
got_other = 1;
422
if (multi_ack && ok_to_give_up()) {
423
- const char *hex = sha1_to_hex(sha1);
423
+ const char *hex = oid_to_hex(&oid);
424
if (multi_ack == 2) {
425
sent_ready = 1;
426
packet_write_fmt(1, "ACK %s ready\n", hex);
@@ -430,7 +430,7 @@ static int get_common_commits(void)
430
break;
431
default:
432
got_common = 1;
433
- memcpy(last_hex, sha1_to_hex(sha1), 41);
433
+ memcpy(last_hex, oid_to_hex(&oid), 41);
434
if (multi_ack == 2)
435
packet_write_fmt(1, "ACK %s common\n", last_hex);
436
else if (multi_ack)
@@ -492,7 +492,7 @@ static int do_reachable_revlist(struct child_process *cmd,
492
goto error;
493
494
namebuf[0] = '^';
495
- namebuf[41] = '\n';
495
+ namebuf[GIT_SHA1_HEXSZ + 1] = '\n';
496
for (i = get_max_object_index(); 0 < i; ) {
497
o = get_indexed_object(--i);
498
if (!o)
@@ -502,10 +502,10 @@ static int do_reachable_revlist(struct child_process *cmd,
502
if (!is_our_ref(o))
503
continue;
504
memcpy(namebuf + 1, oid_to_hex(&o->oid), GIT_SHA1_HEXSZ);
505
- if (write_in_full(cmd->in, namebuf, 42) < 0)
505
+ if (write_in_full(cmd->in, namebuf, GIT_SHA1_HEXSZ + 2) < 0)
506
goto error;
507
}
508
- namebuf[40] = '\n';
508
+ namebuf[GIT_SHA1_HEXSZ] = '\n';
509
for (i = 0; i < src->nr; i++) {
510
o = src->objects[i].item;
511
if (is_our_ref(o)) {
@@ -516,7 +516,7 @@ static int do_reachable_revlist(struct child_process *cmd,
516
if (reachable && o->type == OBJ_COMMIT)
517
o->flags |= TMP_MARK;
518
memcpy(namebuf, oid_to_hex(&o->oid), GIT_SHA1_HEXSZ);
519
- if (write_in_full(cmd->in, namebuf, 41) < 0)
519
+ if (write_in_full(cmd->in, namebuf, GIT_SHA1_HEXSZ + 1) < 0)
520
goto error;
521
}
522
close(cmd->in);
@@ -742,7 +742,7 @@ static void receive_needs(void)
742
for (;;) {
743
struct object *o;
744
const char *features;
745
- unsigned char sha1_buf[20];
745
+ struct object_id oid_buf;
746
char *line = packet_read_line(0, NULL);
747
const char *arg;
748
@@ -751,15 +751,15 @@ static void receive_needs(void)
751
break;
752
753
if (skip_prefix(line, "shallow ", &arg)) {
754
- unsigned char sha1[20];
754
+ struct object_id oid;
755
struct object *object;
756
- if (get_sha1_hex(arg, sha1))
756
+ if (get_oid_hex(arg, &oid))
757
die("invalid shallow line: %s", line);
758
- object = parse_object(sha1);
758
+ object = parse_object(oid.hash);
759
if (!object)
760
continue;
761
if (object->type != OBJ_COMMIT)
762
- die("invalid shallow object %s", sha1_to_hex(sha1));
762
+ die("invalid shallow object %s", oid_to_hex(&oid));
763
if (!(object->flags & CLIENT_SHALLOW)) {
764
object->flags |= CLIENT_SHALLOW;
765
add_object_array(object, NULL, &shallows);
@@ -785,8 +785,8 @@ static void receive_needs(void)
785
}
786
if (skip_prefix(line, "deepen-not ", &arg)) {
787
char *ref = NULL;
788
- unsigned char sha1[20];
789
- if (expand_ref(arg, strlen(arg), sha1, &ref) != 1)
788
+ struct object_id oid;
789
+ if (expand_ref(arg, strlen(arg), oid.hash, &ref) != 1)
790
die("git upload-pack: ambiguous deepen-not: %s", line);
791
string_list_append(&deepen_not, ref);
792
free(ref);
@@ -794,7 +794,7 @@ static void receive_needs(void)
794
continue;
795
}
796
if (!skip_prefix(line, "want ", &arg) ||
797
- get_sha1_hex(arg, sha1_buf))
797
+ get_oid_hex(arg, &oid_buf))
798
die("git upload-pack: protocol error, "
799
"expected to get sha, not '%s'", line);
800
@@ -821,13 +821,13 @@ static void receive_needs(void)
821
if (parse_feature_request(features, "include-tag"))
822
use_include_tag = 1;
823
824
- o = parse_object(sha1_buf);
824
+ o = parse_object(oid_buf.hash);
825
if (!o) {
826
packet_write_fmt(1,
827
"ERR upload-pack: not our ref %s",
828
- sha1_to_hex(sha1_buf));
828
+ oid_to_hex(&oid_buf));
829
die("git upload-pack: not our ref %s",
830
- sha1_to_hex(sha1_buf));
830
+ oid_to_hex(&oid_buf));
831
}
832
if (!(o->flags & WANTED)) {
833
o->flags |= WANTED;