summaryrefslogtreecommitdiff
path: root/fetch-pack.c
diff options
context:
space:
mode:
authorJunio C Hamano <junkio@cox.net>2005-12-14 22:17:38 -0800
committerJunio C Hamano <junkio@cox.net>2005-12-17 23:11:29 -0800
commitad8972150887a8ed3dd4869fc9318cc2e48dd69f (patch)
tree14caab692aff3f2be7365e7c6f18fa1e5aa3dfe3 /fetch-pack.c
parentc054d64e8783e5ac2fa68c382f00df9087bca0f9 (diff)
downloadgit-ad8972150887a8ed3dd4869fc9318cc2e48dd69f.tar.gz
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 <junkio@cox.net>
Diffstat (limited to 'fetch-pack.c')
-rw-r--r--fetch-pack.c58
1 files changed, 21 insertions, 37 deletions
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 <time.h>
-#include <sys/wait.h>
+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 <refs>...";
+"git-fetch-pack [-q] [-v] [-k] [--exec=upload-pack] [host:]directory <refs>...";
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;