Skip to content

Commit ca0c976

Browse files
committed
Merge branch 'jc/fetch-pack-fsck-objects'
* jc/fetch-pack-fsck-objects: test: fetch/receive with fsckobjects transfer.fsckobjects: unify fetch/receive.fsckobjects fetch.fsckobjects: verify downloaded objects Conflicts: Documentation/config.txt builtin/fetch-pack.c
2 parents f817f2f + b10a535 commit ca0c976

File tree

4 files changed

+151
-5
lines changed

4 files changed

+151
-5
lines changed

Documentation/config.txt

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -857,6 +857,13 @@ fetch.recurseSubmodules::
857857
when its superproject retrieves a commit that updates the submodule's
858858
reference.
859859

860+
fetch.fsckObjects::
861+
If it is set to true, git-fetch-pack will check all fetched
862+
objects. It will abort in the case of a malformed object or a
863+
broken link. The result of an abort are only dangling objects.
864+
Defaults to false. If not set, the value of `transfer.fsckObjects`
865+
is used instead.
866+
860867
fetch.unpackLimit::
861868
If the number of objects fetched over the git native
862869
transfer is below this
@@ -1595,7 +1602,8 @@ receive.fsckObjects::
15951602
If it is set to true, git-receive-pack will check all received
15961603
objects. It will abort in the case of a malformed object or a
15971604
broken link. The result of an abort are only dangling objects.
1598-
Defaults to false.
1605+
Defaults to false. If not set, the value of `transfer.fsckObjects`
1606+
is used instead.
15991607

16001608
receive.unpackLimit::
16011609
If the number of objects received in a push is below this
@@ -1830,6 +1838,11 @@ tar.umask::
18301838
archiving user's umask will be used instead. See umask(2) and
18311839
linkgit:git-archive[1].
18321840

1841+
transfer.fsckObjects::
1842+
When `fetch.fsckObjects` or `receive.fsckObjects` are
1843+
not set, the value of this variable is used instead.
1844+
Defaults to false.
1845+
18331846
transfer.unpackLimit::
18341847
When `fetch.unpackLimit` or `receive.unpackLimit` are
18351848
not set, the value of this variable is used instead.

builtin/fetch-pack.c

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,9 @@ static int transfer_unpack_limit = -1;
1515
static int fetch_unpack_limit = -1;
1616
static int unpack_limit = 100;
1717
static int prefer_ofs_delta = 1;
18-
static int no_done = 0;
18+
static int no_done;
19+
static int fetch_fsck_objects = -1;
20+
static int transfer_fsck_objects = -1;
1921
static struct fetch_pack_args args = {
2022
/* .uploadpack = */ "git-upload-pack",
2123
};
@@ -734,6 +736,12 @@ static int get_pack(int xd[2], char **pack_lockfile)
734736
}
735737
if (*hdr_arg)
736738
*av++ = hdr_arg;
739+
if (fetch_fsck_objects >= 0
740+
? fetch_fsck_objects
741+
: transfer_fsck_objects >= 0
742+
? transfer_fsck_objects
743+
: 0)
744+
*av++ = "--strict";
737745
*av++ = NULL;
738746

739747
cmd.in = demux.out;
@@ -853,6 +861,16 @@ static int fetch_pack_config(const char *var, const char *value, void *cb)
853861
return 0;
854862
}
855863

864+
if (!strcmp(var, "fetch.fsckobjects")) {
865+
fetch_fsck_objects = git_config_bool(var, value);
866+
return 0;
867+
}
868+
869+
if (!strcmp(var, "transfer.fsckobjects")) {
870+
transfer_fsck_objects = git_config_bool(var, value);
871+
return 0;
872+
}
873+
856874
return git_default_config(var, value, cb);
857875
}
858876

builtin/receive-pack.c

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,8 @@ static int deny_deletes;
2525
static int deny_non_fast_forwards;
2626
static enum deny_action deny_current_branch = DENY_UNCONFIGURED;
2727
static enum deny_action deny_delete_current = DENY_UNCONFIGURED;
28-
static int receive_fsck_objects;
28+
static int receive_fsck_objects = -1;
29+
static int transfer_fsck_objects = -1;
2930
static int receive_unpack_limit = -1;
3031
static int transfer_unpack_limit = -1;
3132
static int unpack_limit = 100;
@@ -79,6 +80,11 @@ static int receive_pack_config(const char *var, const char *value, void *cb)
7980
return 0;
8081
}
8182

83+
if (strcmp(var, "transfer.fsckobjects") == 0) {
84+
transfer_fsck_objects = git_config_bool(var, value);
85+
return 0;
86+
}
87+
8288
if (!strcmp(var, "receive.denycurrentbranch")) {
8389
deny_current_branch = parse_deny_action(var, value);
8490
return 0;
@@ -674,6 +680,11 @@ static const char *unpack(void)
674680
struct pack_header hdr;
675681
const char *hdr_err;
676682
char hdr_arg[38];
683+
int fsck_objects = (receive_fsck_objects >= 0
684+
? receive_fsck_objects
685+
: transfer_fsck_objects >= 0
686+
? transfer_fsck_objects
687+
: 0);
677688

678689
hdr_err = parse_pack_header(&hdr);
679690
if (hdr_err)
@@ -686,7 +697,7 @@ static const char *unpack(void)
686697
int code, i = 0;
687698
const char *unpacker[4];
688699
unpacker[i++] = "unpack-objects";
689-
if (receive_fsck_objects)
700+
if (fsck_objects)
690701
unpacker[i++] = "--strict";
691702
unpacker[i++] = hdr_arg;
692703
unpacker[i++] = NULL;
@@ -706,7 +717,7 @@ static const char *unpack(void)
706717

707718
keeper[i++] = "index-pack";
708719
keeper[i++] = "--stdin";
709-
if (receive_fsck_objects)
720+
if (fsck_objects)
710721
keeper[i++] = "--strict";
711722
keeper[i++] = "--fix-thin";
712723
keeper[i++] = hdr_arg;

t/t5504-fetch-receive-strict.sh

Lines changed: 104 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,104 @@
1+
#!/bin/sh
2+
3+
test_description='fetch/receive strict mode'
4+
. ./test-lib.sh
5+
6+
test_expect_success setup '
7+
echo hello >greetings &&
8+
git add greetings &&
9+
git commit -m greetings &&
10+
11+
S=$(git rev-parse :greetings | sed -e "s|^..|&/|") &&
12+
X=$(echo bye | git hash-object -w --stdin | sed -e "s|^..|&/|") &&
13+
mv -f .git/objects/$X .git/objects/$S &&
14+
15+
test_must_fail git fsck
16+
'
17+
18+
test_expect_success 'fetch without strict' '
19+
rm -rf dst &&
20+
git init dst &&
21+
(
22+
cd dst &&
23+
git config fetch.fsckobjects false &&
24+
git config transfer.fsckobjects false &&
25+
git fetch ../.git master
26+
)
27+
'
28+
29+
test_expect_success 'fetch with !fetch.fsckobjects' '
30+
rm -rf dst &&
31+
git init dst &&
32+
(
33+
cd dst &&
34+
git config fetch.fsckobjects false &&
35+
git config transfer.fsckobjects true &&
36+
git fetch ../.git master
37+
)
38+
'
39+
40+
test_expect_success 'fetch with fetch.fsckobjects' '
41+
rm -rf dst &&
42+
git init dst &&
43+
(
44+
cd dst &&
45+
git config fetch.fsckobjects true &&
46+
git config transfer.fsckobjects false &&
47+
test_must_fail git fetch ../.git master
48+
)
49+
'
50+
51+
test_expect_success 'fetch with transfer.fsckobjects' '
52+
rm -rf dst &&
53+
git init dst &&
54+
(
55+
cd dst &&
56+
git config transfer.fsckobjects true &&
57+
test_must_fail git fetch ../.git master
58+
)
59+
'
60+
61+
test_expect_success 'push without strict' '
62+
rm -rf dst &&
63+
git init dst &&
64+
(
65+
cd dst &&
66+
git config fetch.fsckobjects false &&
67+
git config transfer.fsckobjects false
68+
) &&
69+
git push dst master:refs/heads/test
70+
'
71+
72+
test_expect_success 'push with !receive.fsckobjects' '
73+
rm -rf dst &&
74+
git init dst &&
75+
(
76+
cd dst &&
77+
git config receive.fsckobjects false &&
78+
git config transfer.fsckobjects true
79+
) &&
80+
git push dst master:refs/heads/test
81+
'
82+
83+
test_expect_success 'push with receive.fsckobjects' '
84+
rm -rf dst &&
85+
git init dst &&
86+
(
87+
cd dst &&
88+
git config receive.fsckobjects true &&
89+
git config transfer.fsckobjects false
90+
) &&
91+
test_must_fail git push dst master:refs/heads/test
92+
'
93+
94+
test_expect_success 'push with transfer.fsckobjects' '
95+
rm -rf dst &&
96+
git init dst &&
97+
(
98+
cd dst &&
99+
git config transfer.fsckobjects true
100+
) &&
101+
test_must_fail git push dst master:refs/heads/test
102+
'
103+
104+
test_done

0 commit comments

Comments
 (0)