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

send-pack --keep: do not explode into loose objects on the receiving end.

This adds "keep-pack" extension to send-pack vs receive pack protocol, and makes the receiver invoke "index-pack --stdin --fix-thin". With this, you can ask send-pack not to explode the result into loose objects on the receiving end. I've patched has_sha1_file() to re-check for added packs just like is done in read_sha1_file() for now, but I think the static "re-prepare" interface for packs was a mistake. Creation of a new pack inside a process that needs to read objects in them back ought to be a rare event, so we are better off making the callers (such as receive-pack that calls "index-pack --stdin --fix-thin") explicitly call re-prepare. That way we do not have to penalize ordinary users of read_sha1_file() and has_sha1_file(). We would need to fix this someday. Signed-off-by: Junio C Hamano <junkio@cox.net>

Junio C Hamano committed Oct 29, 2006 at 00:47 UTC c7740a943ec896247ebc5514b6be02710caf3c53
4 files changed +48 -10
receive-pack.c
+16 -3
@@ -8,10 +8,14 @@
8 static const char receive_pack_usage[] = "git-receive-pack <git-dir>";
9
10 static const char *unpacker[] = { "unpack-objects", NULL };
11 +static const char *keep_packer[] = {
12 + "index-pack", "--stdin", "--fix-thin", NULL
13 +};
14
15 static int report_status;
16 +static int keep_pack;
17
14 -static char capabilities[] = "report-status";
18 +static char capabilities[] = "report-status keep-pack";
19 static int capabilities_sent;
20
21 static int show_ref(const char *path, const unsigned char *sha1)
@@ -261,6 +265,8 @@ static void read_head_info(void)
265 if (reflen + 82 < len) {
266 if (strstr(refname + reflen + 1, "report-status"))
267 report_status = 1;
268 + if (strstr(refname + reflen + 1, "keep-pack"))
269 + keep_pack = 1;
270 }
271 cmd = xmalloc(sizeof(struct command) + len - 80);
272 hashcpy(cmd->old_sha1, old_sha1);
@@ -275,7 +281,14 @@ static void read_head_info(void)
281
282 static const char *unpack(int *error_code)
283 {
278 - int code = run_command_v_opt(1, unpacker, RUN_GIT_CMD);
284 + int code;
285 +
286 + if (keep_pack)
287 + code = run_command_v_opt(ARRAY_SIZE(keep_packer) - 1,
288 + keep_packer, RUN_GIT_CMD);
289 + else
290 + code = run_command_v_opt(ARRAY_SIZE(unpacker) - 1,
291 + unpacker, RUN_GIT_CMD);
292
293 *error_code = 0;
294 switch (code) {
@@ -335,7 +348,7 @@ int main(int argc, char **argv)
348 if (!dir)
349 usage(receive_pack_usage);
350
338 - if(!enter_repo(dir, 0))
351 + if (!enter_repo(dir, 0))
352 die("'%s': unable to chdir or not a git archive", dir);
353
354 write_head_info();
send-pack.c
+18 -5
@@ -6,13 +6,14 @@
6 #include "exec_cmd.h"
7
8 static const char send_pack_usage[] =
9 -"git-send-pack [--all] [--exec=git-receive-pack] <remote> [<head>...]\n"
9 +"git-send-pack [--all] [--keep] [--exec=git-receive-pack] <remote> [<head>...]\n"
10 " --all and explicit <head> specification are mutually exclusive.";
11 static const char *exec = "git-receive-pack";
12 static int verbose;
13 static int send_all;
14 static int force_update;
15 static int use_thin_pack;
16 +static int keep_pack;
17
18 static int is_zero_sha1(const unsigned char *sha1)
19 {
@@ -270,6 +271,7 @@ static int send_pack(int in, int out, int nr_refspec, char **refspec)
271 int new_refs;
272 int ret = 0;
273 int ask_for_status_report = 0;
274 + int ask_to_keep_pack = 0;
275 int expect_status_report = 0;
276
277 /* No funny business with the matcher */
@@ -279,6 +281,8 @@ static int send_pack(int in, int out, int nr_refspec, char **refspec)
281 /* Does the other end support the reporting? */
282 if (server_supports("report-status"))
283 ask_for_status_report = 1;
284 + if (server_supports("keep-pack") && keep_pack)
285 + ask_to_keep_pack = 1;
286
287 /* match them up */
288 if (!remote_tail)
@@ -355,12 +359,17 @@ static int send_pack(int in, int out, int nr_refspec, char **refspec)
359 strcpy(old_hex, sha1_to_hex(ref->old_sha1));
360 new_hex = sha1_to_hex(ref->new_sha1);
361
358 - if (ask_for_status_report) {
359 - packet_write(out, "%s %s %s%c%s",
362 + if (ask_for_status_report || ask_to_keep_pack) {
363 + packet_write(out, "%s %s %s%c%s%s",
364 old_hex, new_hex, ref->name, 0,
361 - "report-status");
365 + ask_for_status_report
366 + ? " report-status" : "",
367 + ask_to_keep_pack
368 + ? " keep-pack" : "");
369 + if (ask_for_status_report)
370 + expect_status_report = 1;
371 ask_for_status_report = 0;
363 - expect_status_report = 1;
372 + ask_to_keep_pack = 0;
373 }
374 else
375 packet_write(out, "%s %s %s",
@@ -419,6 +428,10 @@ int main(int argc, char **argv)
428 verbose = 1;
429 continue;
430 }
431 + if (!strcmp(arg, "--keep")) {
432 + keep_pack = 1;
433 + continue;
434 + }
435 if (!strcmp(arg, "--thin")) {
436 use_thin_pack = 1;
437 continue;
sha1_file.c
+5 -2
@@ -1292,7 +1292,7 @@ static void *read_packed_sha1(const unsigned char *sha1, char *type, unsigned lo
1292 return unpack_entry(&e, type, size);
1293 }
1294
1295 -void * read_sha1_file(const unsigned char *sha1, char *type, unsigned long *size)
1295 +void *read_sha1_file(const unsigned char *sha1, char *type, unsigned long *size)
1296 {
1297 unsigned long mapsize;
1298 void *map, *buf;
@@ -1757,7 +1757,10 @@ int has_sha1_file(const unsigned char *sha1)
1757
1758 if (find_pack_entry(sha1, &e, NULL))
1759 return 1;
1760 - return find_sha1_file(sha1, &st) ? 1 : 0;
1760 + if (find_sha1_file(sha1, &st))
1761 + return 1;
1762 + reprepare_packed_git();
1763 + return find_pack_entry(sha1, &e, NULL);
1764 }
1765
1766 /*
t/t5400-send-pack.sh
+9
@@ -78,4 +78,13 @@ test_expect_success \
78 ! diff -u .git/refs/heads/master victim/.git/refs/heads/master
79 '
80
81 +test_expect_success 'push with --keep' '
82 + t=`cd victim && git-rev-parse --verify refs/heads/master` &&
83 + git-update-ref refs/heads/master $t &&
84 + : > foo &&
85 + git add foo &&
86 + git commit -m "one more" &&
87 + git-send-pack --keep ./victim/.git/ master
88 +'
89 +
90 test_done