Skip to content

Commit 09ca613

Browse files
committed
Merge branch 'jt/tags-to-promised-blobs-fix'
The lazy clone support had a few places where missing but promised objects were not correctly tolerated, which have been fixed. * jt/tags-to-promised-blobs-fix: tag: don't warn if target is missing but promised revision: tolerate promised targets of tags
2 parents 7c85ee6 + 8c4cc32 commit 09ca613

File tree

3 files changed

+57
-3
lines changed

3 files changed

+57
-3
lines changed

revision.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -251,6 +251,9 @@ static struct commit *handle_commit(struct rev_info *revs,
251251
if (!object) {
252252
if (revs->ignore_missing_links || (flags & UNINTERESTING))
253253
return NULL;
254+
if (revs->exclude_promisor_objects &&
255+
is_promisor_object(&tag->tagged->oid))
256+
return NULL;
254257
die("bad object %s", oid_to_hex(&tag->tagged->oid));
255258
}
256259
object->flags |= flags;

t/t5616-partial-clone.sh

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -216,6 +216,50 @@ test_expect_success 'upon cloning, check that all refs point to objects' '
216216
! test -e "$HTTPD_ROOT_PATH/one-time-sed"
217217
'
218218

219+
test_expect_success 'when partial cloning, tolerate server not sending target of tag' '
220+
SERVER="$HTTPD_DOCUMENT_ROOT_PATH/server" &&
221+
rm -rf "$SERVER" repo &&
222+
test_create_repo "$SERVER" &&
223+
test_commit -C "$SERVER" foo &&
224+
test_config -C "$SERVER" uploadpack.allowfilter 1 &&
225+
test_config -C "$SERVER" uploadpack.allowanysha1inwant 1 &&
226+
227+
# Create an annotated tag pointing to a blob.
228+
BLOB=$(echo blob-contents | git -C "$SERVER" hash-object --stdin -w) &&
229+
git -C "$SERVER" tag -m message -a myblob "$BLOB" &&
230+
231+
# Craft a packfile including the tag, but not the blob it points to.
232+
# Also, omit objects referenced from HEAD in order to force a second
233+
# fetch (to fetch missing objects) upon the automatic checkout that
234+
# happens after a clone.
235+
printf "%s\n%s\n--not\n%s\n%s\n" \
236+
$(git -C "$SERVER" rev-parse HEAD) \
237+
$(git -C "$SERVER" rev-parse myblob) \
238+
$(git -C "$SERVER" rev-parse HEAD^{tree}) \
239+
$(git -C "$SERVER" rev-parse myblob^{blob}) |
240+
git -C "$SERVER" pack-objects --thin --stdout >incomplete.pack &&
241+
242+
# Replace the existing packfile with the crafted one. The protocol
243+
# requires that the packfile be sent in sideband 1, hence the extra
244+
# \x01 byte at the beginning.
245+
printf "1,/packfile/!c %04x\\\\x01%s0000" \
246+
"$(($(wc -c <incomplete.pack) + 5))" \
247+
"$(sed_escape <incomplete.pack)" \
248+
>"$HTTPD_ROOT_PATH/one-time-sed" &&
249+
250+
# Use protocol v2 because the sed command looks for the "packfile"
251+
# section header.
252+
test_config -C "$SERVER" protocol.version 2 &&
253+
254+
# Exercise to make sure it works.
255+
git -c protocol.version=2 clone \
256+
--filter=blob:none $HTTPD_URL/one_time_sed/server repo 2> err &&
257+
! grep "missing object referenced by" err &&
258+
259+
# Ensure that the one-time-sed script was used.
260+
! test -e "$HTTPD_ROOT_PATH/one-time-sed"
261+
'
262+
219263
stop_httpd
220264

221265
test_done

tag.c

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
#include "blob.h"
77
#include "alloc.h"
88
#include "gpg-interface.h"
9+
#include "packfile.h"
910

1011
const char *tag_type = "tag";
1112

@@ -66,12 +67,18 @@ int gpg_verify_tag(const struct object_id *oid, const char *name_to_report,
6667

6768
struct object *deref_tag(struct repository *r, struct object *o, const char *warn, int warnlen)
6869
{
70+
struct object_id *last_oid = NULL;
6971
while (o && o->type == OBJ_TAG)
70-
if (((struct tag *)o)->tagged)
71-
o = parse_object(r, &((struct tag *)o)->tagged->oid);
72-
else
72+
if (((struct tag *)o)->tagged) {
73+
last_oid = &((struct tag *)o)->tagged->oid;
74+
o = parse_object(r, last_oid);
75+
} else {
76+
last_oid = NULL;
7377
o = NULL;
78+
}
7479
if (!o && warn) {
80+
if (last_oid && is_promisor_object(last_oid))
81+
return NULL;
7582
if (!warnlen)
7683
warnlen = strlen(warn);
7784
error("missing object referenced by '%.*s'", warnlen, warn);

0 commit comments

Comments
 (0)