@matheusbsbs / matheus-bagliano / commits / b19696c2e7
Fork 0

Use thin pack transfer in "git fetch".

Signed-off-by: Junio C Hamano <junkio@cox.net>

Junio C Hamano committed Feb 20, 2006 at 00:38 UTC b19696c2e7c3e753777189100b2ac09c9e04080b
3 files changed +20 -8
fetch-pack.c
+11 -4
@@ -8,7 +8,7 @@ static int keep_pack;
8 static int quiet;
9 static int verbose;
10 static const char fetch_pack_usage[] =
11 -"git-fetch-pack [-q] [-v] [-k] [--exec=upload-pack] [host:]directory <refs>...";
11 +"git-fetch-pack [-q] [-v] [-k] [--thin] [--exec=upload-pack] [host:]directory <refs>...";
12 static const char *exec = "git-upload-pack";
13
14 #define COMPLETE (1U << 0)
@@ -18,7 +18,7 @@ static const char *exec = "git-upload-pack";
18 #define POPPED (1U << 4)
19
20 static struct commit_list *rev_list = NULL;
21 -static int non_common_revs = 0, multi_ack = 0;
21 +static int non_common_revs = 0, multi_ack = 0, use_thin_pack = 0;
22
23 static void rev_list_push(struct commit *commit, int mark)
24 {
@@ -156,8 +156,9 @@ static int find_common(int fd[2], unsigned char *result_sha1,
156 continue;
157 }
158
159 - packet_write(fd[1], "want %s%s\n", sha1_to_hex(remote),
160 - multi_ack ? " multi_ack" : "");
159 + packet_write(fd[1], "want %s%s%s\n", sha1_to_hex(remote),
160 + (multi_ack ? " multi_ack" : ""),
161 + (use_thin_pack ? " thin-pack" : ""));
162 fetching++;
163 }
164 packet_flush(fd[1]);
@@ -421,6 +422,10 @@ int main(int argc, char **argv)
422 keep_pack = 1;
423 continue;
424 }
425 + if (!strcmp("--thin", arg)) {
426 + use_thin_pack = 1;
427 + continue;
428 + }
429 if (!strcmp("-v", arg)) {
430 verbose = 1;
431 continue;
@@ -434,6 +439,8 @@ int main(int argc, char **argv)
439 }
440 if (!dest)
441 usage(fetch_pack_usage);
442 + if (keep_pack)
443 + use_thin_pack = 0;
444 pid = git_connect(fd, dest, exec);
445 if (pid < 0)
446 return 1;
git-fetch.sh
+1 -1
@@ -320,7 +320,7 @@ fetch_main () {
320 ( : subshell because we muck with IFS
321 IFS=" $LF"
322 (
323 - git-fetch-pack $exec $keep "$remote" $rref || echo failed "$remote"
323 + git-fetch-pack $exec $keep --thin "$remote" $rref || echo failed "$remote"
324 ) |
325 while read sha1 remote_name
326 do
upload-pack.c
+8 -3
@@ -14,6 +14,7 @@ static const char upload_pack_usage[] = "git-upload-pack [--strict] [--timeout=n
14 #define MAX_HAS 256
15 #define MAX_NEEDS 256
16 static int nr_has = 0, nr_needs = 0, multi_ack = 0, nr_our_refs = 0;
17 +static int use_thin_pack = 0;
18 static unsigned char has_sha1[MAX_HAS][20];
19 static unsigned char needs_sha1[MAX_NEEDS][20];
20 static unsigned int timeout = 0;
@@ -49,8 +50,10 @@ static void create_pack_file(void)
50 char *buf;
51 char **p;
52
52 - if (create_full_pack)
53 + if (create_full_pack) {
54 args = 10;
55 + use_thin_pack = 0; /* no point doing it */
56 + }
57 else
58 args = nr_has + nr_needs + 5;
59 argv = xmalloc(args * sizeof(char *));
@@ -62,7 +65,7 @@ static void create_pack_file(void)
65 close(fd[0]);
66 close(fd[1]);
67 *p++ = "rev-list";
65 - *p++ = "--objects";
68 + *p++ = use_thin_pack ? "--objects-edge" : "--objects";
69 if (create_full_pack || MAX_NEEDS <= nr_needs)
70 *p++ = "--all";
71 else {
@@ -192,6 +195,8 @@ static int receive_needs(void)
195 "expected to get sha, not '%s'", line);
196 if (strstr(line+45, "multi_ack"))
197 multi_ack = 1;
198 + if (strstr(line+45, "thin-pack"))
199 + use_thin_pack = 1;
200
201 /* We have sent all our refs already, and the other end
202 * should have chosen out of them; otherwise they are
@@ -213,7 +218,7 @@ static int receive_needs(void)
218
219 static int send_ref(const char *refname, const unsigned char *sha1)
220 {
216 - static char *capabilities = "multi_ack";
221 + static char *capabilities = "multi_ack thin-pack";
222 struct object *o = parse_object(sha1);
223
224 if (capabilities)