fsck: support referenced promisor objects

Teach fsck to not treat missing promisor objects indirectly pointed to by refs as an error when extensions.partialclone is set. Signed-off-by: Jonathan Tan <jonathantanmy@google.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Jonathan Tan committed Dec 5, 2017 at 16:58 UTC caba7fc31a0e2b5fd362577dd20c85a577c9f4e4
2 files changed +34
builtin/fsck.c
+11
@@ -149,6 +149,15 @@ static int mark_object(struct object *obj, int type, void *data, struct fsck_opt
149 if (obj->flags & REACHABLE)
150 return 0;
151 obj->flags |= REACHABLE;
152 +
153 + if (is_promisor_object(&obj->oid))
154 + /*
155 + * Further recursion does not need to be performed on this
156 + * object since it is a promisor object (so it does not need to
157 + * be added to "pending").
158 + */
159 + return 0;
160 +
161 if (!(obj->flags & HAS_OBJ)) {
162 if (parent && !has_object_file(&obj->oid)) {
163 printf("broken link from %7s %s\n",
@@ -208,6 +217,8 @@ static void check_reachable_object(struct object *obj)
217 * do a full fsck
218 */
219 if (!(obj->flags & HAS_OBJ)) {
220 + if (is_promisor_object(&obj->oid))
221 + return;
222 if (has_sha1_pack(obj->oid.hash))
223 return; /* it is in pack - forget about it */
224 printf("missing %s %s\n", printable_type(obj),
t/t0410-partial-clone.sh
+23
@@ -102,4 +102,27 @@ test_expect_success 'missing ref object, but promised, passes fsck' '
102 git -C repo fsck
103 '
104
105 +test_expect_success 'missing object, but promised, passes fsck' '
106 + rm -rf repo &&
107 + test_create_repo repo &&
108 + test_commit -C repo 1 &&
109 + test_commit -C repo 2 &&
110 + test_commit -C repo 3 &&
111 + git -C repo tag -a annotated_tag -m "annotated tag" &&
112 +
113 + C=$(git -C repo rev-parse 1) &&
114 + T=$(git -C repo rev-parse 2^{tree}) &&
115 + B=$(git hash-object repo/3.t) &&
116 + AT=$(git -C repo rev-parse annotated_tag) &&
117 +
118 + promise_and_delete "$C" &&
119 + promise_and_delete "$T" &&
120 + promise_and_delete "$B" &&
121 + promise_and_delete "$AT" &&
122 +
123 + git -C repo config core.repositoryformatversion 1 &&
124 + git -C repo config extensions.partialclone "arbitrary string" &&
125 + git -C repo fsck
126 +'
127 +
128 test_done