receive-pack: allow using --strict mode for unpacking objects
When a configuration variable receive.fsckobjects is set, receive-pack runs unpack-objects with --strict mode to check all received 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
20dc0016eebdfabbbffe8fc98364fed855ce59a4
2 files changed
+29
-13
Documentation/config.txt
+6
@@ -939,6 +939,12 @@ imap::
939
The configuration variables in the 'imap' section are described
940
in linkgit:git-imap-send[1].
941
942
+receive.fsckObjects::
943
+ If it is set to true, git-receive-pack will check all received
944
+ objects. It will abort in the case of a malformed object or a
945
+ broken link. The result of an abort are only dangling objects.
946
+ Defaults to false.
947
+
948
receive.unpackLimit::
949
If the number of objects received in a push is below this
950
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;
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
@@ -368,11 +374,13 @@ static const char *unpack(void)
374
ntohl(hdr.hdr_version), ntohl(hdr.hdr_entries));
375
376
if (ntohl(hdr.hdr_entries) < unpack_limit) {
371
- int code;
372
- const char *unpacker[3];
373
- unpacker[0] = "unpack-objects";
374
- unpacker[1] = hdr_arg;
375
- unpacker[2] = NULL;
377
+ int code, i = 0;
378
+ const char *unpacker[4];
379
+ unpacker[i++] = "unpack-objects";
380
+ if (receive_fsck_objects)
381
+ unpacker[i++] = "--strict";
382
+ unpacker[i++] = hdr_arg;
383
+ unpacker[i++] = NULL;
384
code = run_command_v_opt(unpacker, RUN_GIT_CMD);
385
switch (code) {
386
case 0:
@@ -393,8 +401,8 @@ static const char *unpack(void)
401
return "unpacker exited with error code";
402
}
403
} else {
396
- const char *keeper[6];
397
- int s, status;
404
+ const char *keeper[7];
405
+ int s, status, i = 0;
406
char keep_arg[256];
407
struct child_process ip;
408
@@ -402,12 +410,14 @@ static const char *unpack(void)
410
if (gethostname(keep_arg + s, sizeof(keep_arg) - s))
411
strcpy(keep_arg + s, "localhost");
412
405
- keeper[0] = "index-pack";
406
- keeper[1] = "--stdin";
407
- keeper[2] = "--fix-thin";
408
- keeper[3] = hdr_arg;
409
- keeper[4] = keep_arg;
410
- keeper[5] = NULL;
413
+ keeper[i++] = "index-pack";
414
+ keeper[i++] = "--stdin";
415
+ if (receive_fsck_objects)
416
+ keeper[i++] = "--strict";
417
+ keeper[i++] = "--fix-thin";
418
+ keeper[i++] = hdr_arg;
419
+ keeper[i++] = keep_arg;
420
+ keeper[i++] = NULL;
421
memset(&ip, 0, sizeof(ip));
422
ip.argv = keeper;
423
ip.out = -1;