@matheusbsbs / matheus-bagliano / commits / 9e10fd1ac0
Fork 0

Allow fetch-pack to decide keeping the fetched pack without exploding

With --keep-auto option, fetch-pack decides to keep the pack without exploding it just like receive-pack does. We may want to later make this the default. Signed-off-by: Junio C Hamano <junkio@cox.net>

Junio C Hamano committed Jan 22, 2007 at 22:37 UTC 9e10fd1ac0bb50202138efb9291568160dacd7ab
1 file changed +59 -32
fetch-pack.c
+59 -32
@@ -4,9 +4,11 @@
4 #include "commit.h"
5 #include "tag.h"
6 #include "exec_cmd.h"
7 +#include "pack.h"
8 #include "sideband.h"
9
10 static int keep_pack;
11 +static int keep_auto;
12 static int quiet;
13 static int verbose;
14 static int fetch_all;
@@ -486,13 +488,58 @@ static pid_t setup_sideband(int fd[2], int xd[2])
488 return side_pid;
489 }
490
489 -static int get_pack(int xd[2], const char **argv)
491 +static int get_pack(int xd[2])
492 {
493 int status;
494 pid_t pid, side_pid;
495 int fd[2];
496 + const char *argv[20];
497 + char keep_arg[256];
498 + char hdr_arg[256];
499 + const char **av;
500 + int do_keep = keep_pack;
501
502 side_pid = setup_sideband(fd, xd);
503 +
504 + av = argv;
505 + *hdr_arg = 0;
506 + if (keep_auto) {
507 + struct pack_header header;
508 +
509 + if (read_pack_header(fd[0], &header))
510 + die("protocol error: bad pack header");
511 + snprintf(hdr_arg, sizeof(hdr_arg), "--pack_header=%u,%u",
512 + ntohl(header.hdr_version), ntohl(header.hdr_entries));
513 + if (ntohl(header.hdr_entries) < keep_auto)
514 + do_keep = 0;
515 + else
516 + do_keep = 1;
517 + }
518 +
519 + if (do_keep) {
520 + *av++ = "index-pack";
521 + *av++ = "--stdin";
522 + if (!quiet)
523 + *av++ = "-v";
524 + if (use_thin_pack)
525 + *av++ = "--fix-thin";
526 + if (keep_pack > 1 || keep_auto) {
527 + int s = sprintf(keep_arg,
528 + "--keep=fetch-pack %d on ", getpid());
529 + if (gethostname(keep_arg + s, sizeof(keep_arg) - s))
530 + strcpy(keep_arg + s, "localhost");
531 + *av++ = keep_arg;
532 + }
533 + }
534 + else {
535 + *av++ = "unpack-objects";
536 + if (quiet)
537 + *av++ = "-q";
538 + }
539 + if (*hdr_arg)
540 + *av++ = hdr_arg;
541 + *av++ = NULL;
542 +
543 pid = fork();
544 if (pid < 0)
545 die("fetch-pack: unable to fork off %s", argv[0]);
@@ -522,39 +569,10 @@ static int get_pack(int xd[2], const char **argv)
569 die("%s died of unnatural causes %d", argv[0], status);
570 }
571
525 -static int explode_rx_pack(int xd[2])
526 -{
527 - const char *argv[3] = { "unpack-objects", quiet ? "-q" : NULL, NULL };
528 - return get_pack(xd, argv);
529 -}
530 -
531 -static int keep_rx_pack(int xd[2])
532 -{
533 - const char *argv[6];
534 - char keep_arg[256];
535 - int n = 0;
536 -
537 - argv[n++] = "index-pack";
538 - argv[n++] = "--stdin";
539 - if (!quiet)
540 - argv[n++] = "-v";
541 - if (use_thin_pack)
542 - argv[n++] = "--fix-thin";
543 - if (keep_pack > 1) {
544 - int s = sprintf(keep_arg, "--keep=fetch-pack %i on ", getpid());
545 - if (gethostname(keep_arg + s, sizeof(keep_arg) - s))
546 - strcpy(keep_arg + s, "localhost");
547 - argv[n++] = keep_arg;
548 - }
549 - argv[n] = NULL;
550 - return get_pack(xd, argv);
551 -}
552 -
572 static int fetch_pack(int fd[2], int nr_match, char **match)
573 {
574 struct ref *ref;
575 unsigned char sha1[20];
557 - int status;
576
577 get_remote_heads(fd[0], &ref, 0, NULL, 0);
578 if (is_repository_shallow() && !server_supports("shallow"))
@@ -589,8 +607,7 @@ static int fetch_pack(int fd[2], int nr_match, char **match)
607 */
608 fprintf(stderr, "warning: no common commits\n");
609
592 - status = (keep_pack) ? keep_rx_pack(fd) : explode_rx_pack(fd);
593 - if (status)
610 + if (get_pack(fd))
611 die("git-fetch-pack: fetch failed.");
612
613 all_done:
@@ -659,6 +676,16 @@ int main(int argc, char **argv)
676 keep_pack++;
677 continue;
678 }
679 + if (!strcmp("--keep-auto", arg)) {
680 + keep_auto = 100;
681 + continue;
682 + }
683 + if (!strncmp("--keep-auto=", arg, 12)) {
684 + keep_auto = strtoul(arg + 12, NULL, 0);
685 + if (keep_auto < 20)
686 + keep_auto = 20;
687 + continue;
688 + }
689 if (!strcmp("--thin", arg)) {
690 use_thin_pack = 1;
691 continue;