From 5e838ea7aa74dfbc9820bcf798c0f118e91532f9 Mon Sep 17 00:00:00 2001 From: Junio C Hamano Date: Sun, 4 Sep 2011 12:26:14 -0700 Subject: [PATCH 1/3] fetch.fsckobjects: verify downloaded objects This corresponds to receive.fsckobjects configuration variable added (a lot) earlier in 20dc001 (receive-pack: allow using --strict mode for unpacking objects, 2008-02-25). Signed-off-by: Junio C Hamano --- Documentation/config.txt | 6 ++++++ builtin/fetch-pack.c | 8 ++++++++ 2 files changed, 14 insertions(+) diff --git a/Documentation/config.txt b/Documentation/config.txt index 664de6b1ab..4cbc4b928e 100644 --- a/Documentation/config.txt +++ b/Documentation/config.txt @@ -820,6 +820,12 @@ diff.wordRegex:: sequences that match the regular expression are "words", all other characters are *ignorable* whitespace. +fetch.fsckObjects:: + If it is set to true, git-fetch-pack will check all fetched + objects. It will abort in the case of a malformed object or a + broken link. The result of an abort are only dangling objects. + Defaults to false. + fetch.unpackLimit:: If the number of objects fetched over the git native transfer is below this diff --git a/builtin/fetch-pack.c b/builtin/fetch-pack.c index dbd8b7bcc8..df6a8dc277 100644 --- a/builtin/fetch-pack.c +++ b/builtin/fetch-pack.c @@ -14,6 +14,7 @@ static int transfer_unpack_limit = -1; static int fetch_unpack_limit = -1; static int unpack_limit = 100; static int prefer_ofs_delta = 1; +static int fetch_fsck_objects; static struct fetch_pack_args args = { /* .uploadpack = */ "git-upload-pack", }; @@ -663,6 +664,8 @@ static int get_pack(int xd[2], char **pack_lockfile) } if (*hdr_arg) *av++ = hdr_arg; + if (fetch_fsck_objects) + *av++ = "--strict"; *av++ = NULL; cmd.in = demux.out; @@ -776,6 +779,11 @@ static int fetch_pack_config(const char *var, const char *value, void *cb) return 0; } + if (!strcmp(var, "fetch.fsckobjects")) { + fetch_fsck_objects = git_config_bool(var, value); + return 0; + } + return git_default_config(var, value, cb); } From dab76d3aa682a340e886df84da33326368c38633 Mon Sep 17 00:00:00 2001 From: Junio C Hamano Date: Sun, 4 Sep 2011 12:37:45 -0700 Subject: [PATCH 2/3] transfer.fsckobjects: unify fetch/receive.fsckobjects This single variable can be used to set instead of setting fsckobjects variable for fetch & receive independently. Signed-off-by: Junio C Hamano --- Documentation/config.txt | 11 +++++++++-- builtin/fetch-pack.c | 14 ++++++++++++-- builtin/receive-pack.c | 17 ++++++++++++++--- 3 files changed, 35 insertions(+), 7 deletions(-) diff --git a/Documentation/config.txt b/Documentation/config.txt index 4cbc4b928e..d944403f7e 100644 --- a/Documentation/config.txt +++ b/Documentation/config.txt @@ -824,7 +824,8 @@ fetch.fsckObjects:: If it is set to true, git-fetch-pack will check all fetched objects. It will abort in the case of a malformed object or a broken link. The result of an abort are only dangling objects. - Defaults to false. + Defaults to false. If not set, the value of `transfer.fsckObjects` + is used instead. fetch.unpackLimit:: If the number of objects fetched over the git native @@ -1427,7 +1428,8 @@ receive.fsckObjects:: If it is set to true, git-receive-pack will check all received objects. It will abort in the case of a malformed object or a broken link. The result of an abort are only dangling objects. - Defaults to false. + Defaults to false. If not set, the value of `transfer.fsckObjects` + is used instead. receive.unpackLimit:: If the number of objects received in a push is below this @@ -1616,6 +1618,11 @@ tar.umask:: archiving user's umask will be used instead. See umask(2) and linkgit:git-archive[1]. +transfer.fsckObjects:: + When `fetch.fsckObjects` or `receive.fsckObjects` are + not set, the value of this variable is used instead. + Defaults to false. + transfer.unpackLimit:: When `fetch.unpackLimit` or `receive.unpackLimit` are not set, the value of this variable is used instead. diff --git a/builtin/fetch-pack.c b/builtin/fetch-pack.c index df6a8dc277..dac3038e90 100644 --- a/builtin/fetch-pack.c +++ b/builtin/fetch-pack.c @@ -14,7 +14,8 @@ static int transfer_unpack_limit = -1; static int fetch_unpack_limit = -1; static int unpack_limit = 100; static int prefer_ofs_delta = 1; -static int fetch_fsck_objects; +static int fetch_fsck_objects = -1; +static int transfer_fsck_objects = -1; static struct fetch_pack_args args = { /* .uploadpack = */ "git-upload-pack", }; @@ -664,7 +665,11 @@ static int get_pack(int xd[2], char **pack_lockfile) } if (*hdr_arg) *av++ = hdr_arg; - if (fetch_fsck_objects) + if (fetch_fsck_objects >= 0 + ? fetch_fsck_objects + : transfer_fsck_objects >= 0 + ? transfer_fsck_objects + : 0) *av++ = "--strict"; *av++ = NULL; @@ -784,6 +789,11 @@ static int fetch_pack_config(const char *var, const char *value, void *cb) return 0; } + if (!strcmp(var, "transfer.fsckobjects")) { + transfer_fsck_objects = git_config_bool(var, value); + return 0; + } + return git_default_config(var, value, cb); } diff --git a/builtin/receive-pack.c b/builtin/receive-pack.c index 0559fcc871..021ea65f07 100644 --- a/builtin/receive-pack.c +++ b/builtin/receive-pack.c @@ -23,7 +23,8 @@ static int deny_deletes; static int deny_non_fast_forwards; static enum deny_action deny_current_branch = DENY_UNCONFIGURED; static enum deny_action deny_delete_current = DENY_UNCONFIGURED; -static int receive_fsck_objects; +static int receive_fsck_objects = -1; +static int transfer_fsck_objects = -1; static int receive_unpack_limit = -1; static int transfer_unpack_limit = -1; static int unpack_limit = 100; @@ -77,6 +78,11 @@ static int receive_pack_config(const char *var, const char *value, void *cb) return 0; } + if (strcmp(var, "transfer.fsckobjects") == 0) { + transfer_fsck_objects = git_config_bool(var, value); + return 0; + } + if (!strcmp(var, "receive.denycurrentbranch")) { deny_current_branch = parse_deny_action(var, value); return 0; @@ -586,6 +592,11 @@ static const char *unpack(void) struct pack_header hdr; const char *hdr_err; char hdr_arg[38]; + int fsck_objects = (receive_fsck_objects >= 0 + ? receive_fsck_objects + : transfer_fsck_objects >= 0 + ? transfer_fsck_objects + : 0); hdr_err = parse_pack_header(&hdr); if (hdr_err) @@ -598,7 +609,7 @@ static const char *unpack(void) int code, i = 0; const char *unpacker[4]; unpacker[i++] = "unpack-objects"; - if (receive_fsck_objects) + if (fsck_objects) unpacker[i++] = "--strict"; unpacker[i++] = hdr_arg; unpacker[i++] = NULL; @@ -618,7 +629,7 @@ static const char *unpack(void) keeper[i++] = "index-pack"; keeper[i++] = "--stdin"; - if (receive_fsck_objects) + if (fsck_objects) keeper[i++] = "--strict"; keeper[i++] = "--fix-thin"; keeper[i++] = hdr_arg; From b10a53583f5725b796de630c946e41bbd48fcfe2 Mon Sep 17 00:00:00 2001 From: Junio C Hamano Date: Sun, 4 Sep 2011 18:19:36 -0700 Subject: [PATCH 3/3] test: fetch/receive with fsckobjects Add tests for the new fetch.fsckobjects, and also tests for receive.fsckobjects we have had for quite some time. Signed-off-by: Junio C Hamano --- t/t5504-fetch-receive-strict.sh | 104 ++++++++++++++++++++++++++++++++ 1 file changed, 104 insertions(+) create mode 100755 t/t5504-fetch-receive-strict.sh diff --git a/t/t5504-fetch-receive-strict.sh b/t/t5504-fetch-receive-strict.sh new file mode 100755 index 0000000000..66100124a9 --- /dev/null +++ b/t/t5504-fetch-receive-strict.sh @@ -0,0 +1,104 @@ +#!/bin/sh + +test_description='fetch/receive strict mode' +. ./test-lib.sh + +test_expect_success setup ' + echo hello >greetings && + git add greetings && + git commit -m greetings && + + S=$(git rev-parse :greetings | sed -e "s|^..|&/|") && + X=$(echo bye | git hash-object -w --stdin | sed -e "s|^..|&/|") && + mv -f .git/objects/$X .git/objects/$S && + + test_must_fail git fsck +' + +test_expect_success 'fetch without strict' ' + rm -rf dst && + git init dst && + ( + cd dst && + git config fetch.fsckobjects false && + git config transfer.fsckobjects false && + git fetch ../.git master + ) +' + +test_expect_success 'fetch with !fetch.fsckobjects' ' + rm -rf dst && + git init dst && + ( + cd dst && + git config fetch.fsckobjects false && + git config transfer.fsckobjects true && + git fetch ../.git master + ) +' + +test_expect_success 'fetch with fetch.fsckobjects' ' + rm -rf dst && + git init dst && + ( + cd dst && + git config fetch.fsckobjects true && + git config transfer.fsckobjects false && + test_must_fail git fetch ../.git master + ) +' + +test_expect_success 'fetch with transfer.fsckobjects' ' + rm -rf dst && + git init dst && + ( + cd dst && + git config transfer.fsckobjects true && + test_must_fail git fetch ../.git master + ) +' + +test_expect_success 'push without strict' ' + rm -rf dst && + git init dst && + ( + cd dst && + git config fetch.fsckobjects false && + git config transfer.fsckobjects false + ) && + git push dst master:refs/heads/test +' + +test_expect_success 'push with !receive.fsckobjects' ' + rm -rf dst && + git init dst && + ( + cd dst && + git config receive.fsckobjects false && + git config transfer.fsckobjects true + ) && + git push dst master:refs/heads/test +' + +test_expect_success 'push with receive.fsckobjects' ' + rm -rf dst && + git init dst && + ( + cd dst && + git config receive.fsckobjects true && + git config transfer.fsckobjects false + ) && + test_must_fail git push dst master:refs/heads/test +' + +test_expect_success 'push with transfer.fsckobjects' ' + rm -rf dst && + git init dst && + ( + cd dst && + git config transfer.fsckobjects true + ) && + test_must_fail git push dst master:refs/heads/test +' + +test_done