@matheusbsbs / matheus-bagliano / commits / 28f72a0f23
Fork 0

receive-pack: use strict mode for unpacking objects

Signed-off-by: Martin Koegler <mkoegler@auto.tuwien.ac.at> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Martin Koegler committed Feb 25, 2008 at 22:46 UTC 28f72a0f232dfc71b3be726e7e71d0a6d5f9ebba
2 files changed +29 -13
Documentation/config.txt
+6
@@ -860,6 +860,12 @@ imap::
860 The configuration variables in the 'imap' section are described
861 in linkgit:git-imap-send[1].
862
863 +receive.fsckObjects::
864 + If it is set to true, git-receive-pack will check all received
865 + objects. It will abort in the case of a malformed object or a
866 + broken link. The result of an abort are only dangling objects.
867 + The default value is true.
868 +
869 receive.unpackLimit::
870 If the number of objects received in a push is below this
871 limit then the objects will be unpacked into loose object
receive-pack.c
+23 -13
@@ -10,6 +10,7 @@
10 static const char receive_pack_usage[] = "git-receive-pack <git-dir>";
11
12 static int deny_non_fast_forwards = 0;
13 +static int receive_fsck_objects = 1;
14 static int receive_unpack_limit = -1;
15 static int transfer_unpack_limit = -1;
16 static int unpack_limit = 100;
@@ -35,6 +36,11 @@ static int receive_pack_config(const char *var, const char *value)
36 return 0;
37 }
38
39 + if (strcmp(var, "receive.fsckobjects") == 0) {
40 + receive_fsck_objects = git_config_bool(var, value);
41 + return 0;
42 + }
43 +
44 return git_default_config(var, value);
45 }
46
@@ -367,11 +373,13 @@ static const char *unpack(void)
373 ntohl(hdr.hdr_version), ntohl(hdr.hdr_entries));
374
375 if (ntohl(hdr.hdr_entries) < unpack_limit) {
370 - int code;
371 - const char *unpacker[3];
372 - unpacker[0] = "unpack-objects";
373 - unpacker[1] = hdr_arg;
374 - unpacker[2] = NULL;
376 + int code, i = 0;
377 + const char *unpacker[4];
378 + unpacker[i++] = "unpack-objects";
379 + if (receive_fsck_objects)
380 + unpacker[i++] = "--strict";
381 + unpacker[i++] = hdr_arg;
382 + unpacker[i++] = NULL;
383 code = run_command_v_opt(unpacker, RUN_GIT_CMD);
384 switch (code) {
385 case 0:
@@ -392,8 +400,8 @@ static const char *unpack(void)
400 return "unpacker exited with error code";
401 }
402 } else {
395 - const char *keeper[6];
396 - int s, status;
403 + const char *keeper[7];
404 + int s, status, i = 0;
405 char keep_arg[256];
406 struct child_process ip;
407
@@ -401,12 +409,14 @@ static const char *unpack(void)
409 if (gethostname(keep_arg + s, sizeof(keep_arg) - s))
410 strcpy(keep_arg + s, "localhost");
411
404 - keeper[0] = "index-pack";
405 - keeper[1] = "--stdin";
406 - keeper[2] = "--fix-thin";
407 - keeper[3] = hdr_arg;
408 - keeper[4] = keep_arg;
409 - keeper[5] = NULL;
412 + keeper[i++] = "index-pack";
413 + keeper[i++] = "--stdin";
414 + if (receive_fsck_objects)
415 + keeper[i++] = "--strict";
416 + keeper[i++] = "--fix-thin";
417 + keeper[i++] = hdr_arg;
418 + keeper[i++] = keep_arg;
419 + keeper[i++] = NULL;
420 memset(&ip, 0, sizeof(ip));
421 ip.argv = keeper;
422 ip.out = -1;