upload-pack: use skip_prefix() instead of starts_with()

Signed-off-by: Nguyễn Thái Ngọc Duy <pclouds@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Nguyễn Thái Ngọc Duy committed Jun 12, 2016 at 17:53 UTC 8bf3b75841ead5a796b62a54534b5a203adffae4
1 file changed +18 -14
upload-pack.c
+18 -14
@@ -276,7 +276,7 @@ static void create_pack_file(void)
276 die("git upload-pack: %s", abort_msg);
277 }
278
279 -static int got_sha1(char *hex, unsigned char *sha1)
279 +static int got_sha1(const char *hex, unsigned char *sha1)
280 {
281 struct object *o;
282 int we_knew_they_have = 0;
@@ -382,6 +382,8 @@ static int get_common_commits(void)
382
383 for (;;) {
384 char *line = packet_read_line(0, NULL);
385 + const char *arg;
386 +
387 reset_timeout();
388
389 if (!line) {
@@ -403,8 +405,8 @@ static int get_common_commits(void)
405 got_other = 0;
406 continue;
407 }
406 - if (starts_with(line, "have ")) {
407 - switch (got_sha1(line+5, sha1)) {
408 + if (skip_prefix(line, "have ", &arg)) {
409 + switch (got_sha1(arg, sha1)) {
410 case -1: /* they have what we do not */
411 got_other = 1;
412 if (multi_ack && ok_to_give_up()) {
@@ -620,14 +622,16 @@ static void receive_needs(void)
622 const char *features;
623 unsigned char sha1_buf[20];
624 char *line = packet_read_line(0, NULL);
625 + const char *arg;
626 +
627 reset_timeout();
628 if (!line)
629 break;
630
627 - if (starts_with(line, "shallow ")) {
631 + if (skip_prefix(line, "shallow ", &arg)) {
632 unsigned char sha1[20];
633 struct object *object;
630 - if (get_sha1_hex(line + 8, sha1))
634 + if (get_sha1_hex(arg, sha1))
635 die("invalid shallow line: %s", line);
636 object = parse_object(sha1);
637 if (!object)
@@ -640,19 +644,19 @@ static void receive_needs(void)
644 }
645 continue;
646 }
643 - if (starts_with(line, "deepen ")) {
647 + if (skip_prefix(line, "deepen ", &arg)) {
648 char *end;
645 - depth = strtol(line + 7, &end, 0);
646 - if (end == line + 7 || depth <= 0)
649 + depth = strtol(arg, &end, 0);
650 + if (end == arg || depth <= 0)
651 die("Invalid deepen: %s", line);
652 continue;
653 }
650 - if (!starts_with(line, "want ") ||
651 - get_sha1_hex(line+5, sha1_buf))
654 + if (!skip_prefix(line, "want ", &arg) ||
655 + get_sha1_hex(arg, sha1_buf))
656 die("git upload-pack: protocol error, "
657 "expected to get sha, not '%s'", line);
658
655 - features = line + 45;
659 + features = arg + 40;
660
661 if (parse_feature_request(features, "multi_ack_detailed"))
662 multi_ack = 2;
@@ -859,7 +863,7 @@ int main(int argc, char **argv)
863 check_replace_refs = 0;
864
865 for (i = 1; i < argc; i++) {
862 - char *arg = argv[i];
866 + const char *arg = argv[i];
867
868 if (arg[0] != '-')
869 break;
@@ -875,8 +879,8 @@ int main(int argc, char **argv)
879 strict = 1;
880 continue;
881 }
878 - if (starts_with(arg, "--timeout=")) {
879 - timeout = atoi(arg+10);
882 + if (skip_prefix(arg, "--timeout=", &arg)) {
883 + timeout = atoi(arg);
884 daemon_mode = 1;
885 continue;
886 }