summary | shortlog | log | commit | commitdiff | tree
raw | patch | inline | side by side (parent: a69e542)
raw | patch | inline | side by side (parent: a69e542)
author | Junio C Hamano <junkio@cox.net> | |
Tue, 23 Jan 2007 06:37:33 +0000 (22:37 -0800) | ||
committer | Junio C Hamano <junkio@cox.net> | |
Thu, 25 Jan 2007 02:08:02 +0000 (18:08 -0800) |
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>
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>
fetch-pack.c | patch | blob | history |
diff --git a/fetch-pack.c b/fetch-pack.c
index 3546aef7bcc667542f30fb6dae2fda1e6376a0c1..dd67e48fc7cb945d4f1e11f30abca89d16adfc9d 100644 (file)
--- a/fetch-pack.c
+++ b/fetch-pack.c
#include "commit.h"
#include "tag.h"
#include "exec_cmd.h"
+#include "pack.h"
#include "sideband.h"
static int keep_pack;
+static int keep_auto;
static int quiet;
static int verbose;
static int fetch_all;
return side_pid;
}
-static int get_pack(int xd[2], const char **argv)
+static int get_pack(int xd[2])
{
int status;
pid_t pid, side_pid;
int fd[2];
+ const char *argv[20];
+ char keep_arg[256];
+ char hdr_arg[256];
+ const char **av;
+ int do_keep = keep_pack;
side_pid = setup_sideband(fd, xd);
+
+ av = argv;
+ *hdr_arg = 0;
+ if (keep_auto) {
+ struct pack_header header;
+
+ if (read_pack_header(fd[0], &header))
+ die("protocol error: bad pack header");
+ snprintf(hdr_arg, sizeof(hdr_arg), "--pack_header=%u,%u",
+ ntohl(header.hdr_version), ntohl(header.hdr_entries));
+ if (ntohl(header.hdr_entries) < keep_auto)
+ do_keep = 0;
+ else
+ do_keep = 1;
+ }
+
+ if (do_keep) {
+ *av++ = "index-pack";
+ *av++ = "--stdin";
+ if (!quiet)
+ *av++ = "-v";
+ if (use_thin_pack)
+ *av++ = "--fix-thin";
+ if (keep_pack > 1 || keep_auto) {
+ int s = sprintf(keep_arg,
+ "--keep=fetch-pack %d on ", getpid());
+ if (gethostname(keep_arg + s, sizeof(keep_arg) - s))
+ strcpy(keep_arg + s, "localhost");
+ *av++ = keep_arg;
+ }
+ }
+ else {
+ *av++ = "unpack-objects";
+ if (quiet)
+ *av++ = "-q";
+ }
+ if (*hdr_arg)
+ *av++ = hdr_arg;
+ *av++ = NULL;
+
pid = fork();
if (pid < 0)
die("fetch-pack: unable to fork off %s", argv[0]);
die("%s died of unnatural causes %d", argv[0], status);
}
-static int explode_rx_pack(int xd[2])
-{
- const char *argv[3] = { "unpack-objects", quiet ? "-q" : NULL, NULL };
- return get_pack(xd, argv);
-}
-
-static int keep_rx_pack(int xd[2])
-{
- const char *argv[6];
- char keep_arg[256];
- int n = 0;
-
- argv[n++] = "index-pack";
- argv[n++] = "--stdin";
- if (!quiet)
- argv[n++] = "-v";
- if (use_thin_pack)
- argv[n++] = "--fix-thin";
- if (keep_pack > 1) {
- int s = sprintf(keep_arg, "--keep=fetch-pack %i on ", getpid());
- if (gethostname(keep_arg + s, sizeof(keep_arg) - s))
- strcpy(keep_arg + s, "localhost");
- argv[n++] = keep_arg;
- }
- argv[n] = NULL;
- return get_pack(xd, argv);
-}
-
static int fetch_pack(int fd[2], int nr_match, char **match)
{
struct ref *ref;
unsigned char sha1[20];
- int status;
get_remote_heads(fd[0], &ref, 0, NULL, 0);
if (is_repository_shallow() && !server_supports("shallow"))
*/
fprintf(stderr, "warning: no common commits\n");
- status = (keep_pack) ? keep_rx_pack(fd) : explode_rx_pack(fd);
- if (status)
+ if (get_pack(fd))
die("git-fetch-pack: fetch failed.");
all_done:
keep_pack++;
continue;
}
+ if (!strcmp("--keep-auto", arg)) {
+ keep_auto = 100;
+ continue;
+ }
+ if (!strncmp("--keep-auto=", arg, 12)) {
+ keep_auto = strtoul(arg + 12, NULL, 0);
+ if (keep_auto < 20)
+ keep_auto = 20;
+ continue;
+ }
if (!strcmp("--thin", arg)) {
use_thin_pack = 1;
continue;