Skip to content

Commit 20dc001

Browse files
Martin Koeglergitster
authored andcommitted
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 <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent f2898cf commit 20dc001

File tree

2 files changed

+29
-13
lines changed

2 files changed

+29
-13
lines changed

Documentation/config.txt

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -939,6 +939,12 @@ imap::
939939
The configuration variables in the 'imap' section are described
940940
in linkgit:git-imap-send[1].
941941

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+
942948
receive.unpackLimit::
943949
If the number of objects received in a push is below this
944950
limit then the objects will be unpacked into loose object

receive-pack.c

Lines changed: 23 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
static const char receive_pack_usage[] = "git-receive-pack <git-dir>";
1111

1212
static int deny_non_fast_forwards = 0;
13+
static int receive_fsck_objects;
1314
static int receive_unpack_limit = -1;
1415
static int transfer_unpack_limit = -1;
1516
static int unpack_limit = 100;
@@ -35,6 +36,11 @@ static int receive_pack_config(const char *var, const char *value)
3536
return 0;
3637
}
3738

39+
if (strcmp(var, "receive.fsckobjects") == 0) {
40+
receive_fsck_objects = git_config_bool(var, value);
41+
return 0;
42+
}
43+
3844
return git_default_config(var, value);
3945
}
4046

@@ -368,11 +374,13 @@ static const char *unpack(void)
368374
ntohl(hdr.hdr_version), ntohl(hdr.hdr_entries));
369375

370376
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;
376384
code = run_command_v_opt(unpacker, RUN_GIT_CMD);
377385
switch (code) {
378386
case 0:
@@ -393,21 +401,23 @@ static const char *unpack(void)
393401
return "unpacker exited with error code";
394402
}
395403
} else {
396-
const char *keeper[6];
397-
int s, status;
404+
const char *keeper[7];
405+
int s, status, i = 0;
398406
char keep_arg[256];
399407
struct child_process ip;
400408

401409
s = sprintf(keep_arg, "--keep=receive-pack %i on ", getpid());
402410
if (gethostname(keep_arg + s, sizeof(keep_arg) - s))
403411
strcpy(keep_arg + s, "localhost");
404412

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;
411421
memset(&ip, 0, sizeof(ip));
412422
ip.argv = keeper;
413423
ip.out = -1;

0 commit comments

Comments
 (0)