From ad8972150887a8ed3dd4869fc9318cc2e48dd69f Mon Sep 17 00:00:00 2001 From: Junio C Hamano Date: Wed, 14 Dec 2005 22:17:38 -0800 Subject: fetch-pack: -k option to keep downloaded pack. Split out the functions that deal with the socketpair after finishing git protocol handshake to receive the packed data into a separate file, and use it in fetch-pack to keep/explode the received pack data. We earlier had something like that on clone-pack side once, but the list discussion resulted in the decision that it makes sense to always keep the pack for clone-pack, so unpacking option is not enabled on the clone-pack side, but we later still could do so easily if we wanted to with this change. Signed-off-by: Junio C Hamano --- fetch-pack.c | 58 +++++++++++++++++++++------------------------------------- 1 file changed, 21 insertions(+), 37 deletions(-) (limited to 'fetch-pack.c') diff --git a/fetch-pack.c b/fetch-pack.c index 58ba2094dc..2528053fa8 100644 --- a/fetch-pack.c +++ b/fetch-pack.c @@ -3,13 +3,12 @@ #include "pkt-line.h" #include "commit.h" #include "tag.h" -#include -#include +static int keep_pack; static int quiet; static int verbose; static const char fetch_pack_usage[] = -"git-fetch-pack [-q] [-v] [--exec=upload-pack] [host:]directory ..."; +"git-fetch-pack [-q] [-v] [-k] [--exec=upload-pack] [host:]directory ..."; static const char *exec = "git-upload-pack"; #define COMPLETE (1U << 0) @@ -363,7 +362,6 @@ static int fetch_pack(int fd[2], int nr_match, char **match) struct ref *ref; unsigned char sha1[20]; int status; - pid_t pid; get_remote_heads(fd[0], &ref, 0, NULL, 0); if (server_supports("multi_ack")) { @@ -381,40 +379,22 @@ static int fetch_pack(int fd[2], int nr_match, char **match) } if (find_common(fd, sha1, ref) < 0) fprintf(stderr, "warning: no common commits\n"); - pid = fork(); - if (pid < 0) - die("git-fetch-pack: unable to fork off git-unpack-objects"); - if (!pid) { - dup2(fd[0], 0); - close(fd[0]); - close(fd[1]); - execlp("git-unpack-objects", "git-unpack-objects", - quiet ? "-q" : NULL, NULL); - die("git-unpack-objects exec failed"); - } - close(fd[0]); - close(fd[1]); - while (waitpid(pid, &status, 0) < 0) { - if (errno != EINTR) - die("waiting for git-unpack-objects: %s", strerror(errno)); - } - if (WIFEXITED(status)) { - int code = WEXITSTATUS(status); - if (code) - die("git-unpack-objects died with error code %d", code); -all_done: - while (ref) { - printf("%s %s\n", - sha1_to_hex(ref->old_sha1), ref->name); - ref = ref->next; - } - return 0; - } - if (WIFSIGNALED(status)) { - int sig = WTERMSIG(status); - die("git-unpack-objects died of signal %d", sig); + + if (keep_pack) + status = receive_keep_pack(fd, "git-fetch-pack"); + else + status = receive_unpack_pack(fd, "git-fetch-pack", quiet); + + if (status) + die("git-fetch-pack: fetch failed."); + + all_done: + while (ref) { + printf("%s %s\n", + sha1_to_hex(ref->old_sha1), ref->name); + ref = ref->next; } - die("Sherlock Holmes! git-unpack-objects died of unnatural causes %d!", status); + return 0; } int main(int argc, char **argv) @@ -440,6 +420,10 @@ int main(int argc, char **argv) quiet = 1; continue; } + if (!strcmp("-k", arg)) { + keep_pack = 1; + continue; + } if (!strcmp("-v", arg)) { verbose = 1; continue; -- cgit v1.3 From 2247efb40b304f158b9ab41455bd711366a44f57 Mon Sep 17 00:00:00 2001 From: Junio C Hamano Date: Sun, 18 Dec 2005 01:55:29 -0800 Subject: clone-pack: remove unused and undocumented --keep flag While we are at it, give fully spelled --keep to fetch-pack. Also give --quiet in addition to -q to fetch-pack as well. Signed-off-by: Junio C Hamano --- clone-pack.c | 2 -- fetch-pack.c | 4 ++-- 2 files changed, 2 insertions(+), 4 deletions(-) (limited to 'fetch-pack.c') diff --git a/clone-pack.c b/clone-pack.c index 03dbc2ead6..f634431be1 100644 --- a/clone-pack.c +++ b/clone-pack.c @@ -160,8 +160,6 @@ int main(int argc, char **argv) exec = arg + 7; continue; } - if (!strcmp("--keep", arg)) - continue; usage(clone_pack_usage); } dest = arg; diff --git a/fetch-pack.c b/fetch-pack.c index 2528053fa8..d34f322477 100644 --- a/fetch-pack.c +++ b/fetch-pack.c @@ -416,11 +416,11 @@ int main(int argc, char **argv) exec = arg + 7; continue; } - if (!strcmp("-q", arg)) { + if (!strcmp("--quiet", arg) || !strcmp("-q", arg)) { quiet = 1; continue; } - if (!strcmp("-k", arg)) { + if (!strcmp("--keep", arg) || !strcmp("-k", arg)) { keep_pack = 1; continue; } -- cgit v1.3