Skip to content

Commit cf93982

Browse files
bk2204gitster
authored andcommitted
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>
1 parent 654b9a9 commit cf93982

File tree

1 file changed

+25
-25
lines changed

1 file changed

+25
-25
lines changed

upload-pack.c

Lines changed: 25 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -286,19 +286,19 @@ static void create_pack_file(void)
286286
die("git upload-pack: %s", abort_msg);
287287
}
288288

289-
static int got_sha1(const char *hex, unsigned char *sha1)
289+
static int got_oid(const char *hex, struct object_id *oid)
290290
{
291291
struct object *o;
292292
int we_knew_they_have = 0;
293293

294-
if (get_sha1_hex(hex, sha1))
294+
if (get_oid_hex(hex, oid))
295295
die("git upload-pack: expected SHA1 object, got '%s'", hex);
296-
if (!has_sha1_file(sha1))
296+
if (!has_object_file(oid))
297297
return -1;
298298

299-
o = parse_object(sha1);
299+
o = parse_object(oid->hash);
300300
if (!o)
301-
die("oops (%s)", sha1_to_hex(sha1));
301+
die("oops (%s)", oid_to_hex(oid));
302302
if (o->type == OBJ_COMMIT) {
303303
struct commit_list *parents;
304304
struct commit *commit = (struct commit *)o;
@@ -382,8 +382,8 @@ static int ok_to_give_up(void)
382382

383383
static int get_common_commits(void)
384384
{
385-
unsigned char sha1[20];
386-
char last_hex[41];
385+
struct object_id oid;
386+
char last_hex[GIT_MAX_HEXSZ + 1];
387387
int got_common = 0;
388388
int got_other = 0;
389389
int sent_ready = 0;
@@ -416,11 +416,11 @@ static int get_common_commits(void)
416416
continue;
417417
}
418418
if (skip_prefix(line, "have ", &arg)) {
419-
switch (got_sha1(arg, sha1)) {
419+
switch (got_oid(arg, &oid)) {
420420
case -1: /* they have what we do not */
421421
got_other = 1;
422422
if (multi_ack && ok_to_give_up()) {
423-
const char *hex = sha1_to_hex(sha1);
423+
const char *hex = oid_to_hex(&oid);
424424
if (multi_ack == 2) {
425425
sent_ready = 1;
426426
packet_write_fmt(1, "ACK %s ready\n", hex);
@@ -430,7 +430,7 @@ static int get_common_commits(void)
430430
break;
431431
default:
432432
got_common = 1;
433-
memcpy(last_hex, sha1_to_hex(sha1), 41);
433+
memcpy(last_hex, oid_to_hex(&oid), 41);
434434
if (multi_ack == 2)
435435
packet_write_fmt(1, "ACK %s common\n", last_hex);
436436
else if (multi_ack)
@@ -492,7 +492,7 @@ static int do_reachable_revlist(struct child_process *cmd,
492492
goto error;
493493

494494
namebuf[0] = '^';
495-
namebuf[41] = '\n';
495+
namebuf[GIT_SHA1_HEXSZ + 1] = '\n';
496496
for (i = get_max_object_index(); 0 < i; ) {
497497
o = get_indexed_object(--i);
498498
if (!o)
@@ -502,10 +502,10 @@ static int do_reachable_revlist(struct child_process *cmd,
502502
if (!is_our_ref(o))
503503
continue;
504504
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)
506506
goto error;
507507
}
508-
namebuf[40] = '\n';
508+
namebuf[GIT_SHA1_HEXSZ] = '\n';
509509
for (i = 0; i < src->nr; i++) {
510510
o = src->objects[i].item;
511511
if (is_our_ref(o)) {
@@ -516,7 +516,7 @@ static int do_reachable_revlist(struct child_process *cmd,
516516
if (reachable && o->type == OBJ_COMMIT)
517517
o->flags |= TMP_MARK;
518518
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)
520520
goto error;
521521
}
522522
close(cmd->in);
@@ -742,7 +742,7 @@ static void receive_needs(void)
742742
for (;;) {
743743
struct object *o;
744744
const char *features;
745-
unsigned char sha1_buf[20];
745+
struct object_id oid_buf;
746746
char *line = packet_read_line(0, NULL);
747747
const char *arg;
748748

@@ -751,15 +751,15 @@ static void receive_needs(void)
751751
break;
752752

753753
if (skip_prefix(line, "shallow ", &arg)) {
754-
unsigned char sha1[20];
754+
struct object_id oid;
755755
struct object *object;
756-
if (get_sha1_hex(arg, sha1))
756+
if (get_oid_hex(arg, &oid))
757757
die("invalid shallow line: %s", line);
758-
object = parse_object(sha1);
758+
object = parse_object(oid.hash);
759759
if (!object)
760760
continue;
761761
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));
763763
if (!(object->flags & CLIENT_SHALLOW)) {
764764
object->flags |= CLIENT_SHALLOW;
765765
add_object_array(object, NULL, &shallows);
@@ -785,16 +785,16 @@ static void receive_needs(void)
785785
}
786786
if (skip_prefix(line, "deepen-not ", &arg)) {
787787
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)
790790
die("git upload-pack: ambiguous deepen-not: %s", line);
791791
string_list_append(&deepen_not, ref);
792792
free(ref);
793793
deepen_rev_list = 1;
794794
continue;
795795
}
796796
if (!skip_prefix(line, "want ", &arg) ||
797-
get_sha1_hex(arg, sha1_buf))
797+
get_oid_hex(arg, &oid_buf))
798798
die("git upload-pack: protocol error, "
799799
"expected to get sha, not '%s'", line);
800800

@@ -821,13 +821,13 @@ static void receive_needs(void)
821821
if (parse_feature_request(features, "include-tag"))
822822
use_include_tag = 1;
823823

824-
o = parse_object(sha1_buf);
824+
o = parse_object(oid_buf.hash);
825825
if (!o) {
826826
packet_write_fmt(1,
827827
"ERR upload-pack: not our ref %s",
828-
sha1_to_hex(sha1_buf));
828+
oid_to_hex(&oid_buf));
829829
die("git upload-pack: not our ref %s",
830-
sha1_to_hex(sha1_buf));
830+
oid_to_hex(&oid_buf));
831831
}
832832
if (!(o->flags & WANTED)) {
833833
o->flags |= WANTED;

0 commit comments

Comments
 (0)