tag: don't warn if target is missing but promised

deref_tag() prints a warning if the object that a tag refers to does not exist. However, when a partial clone has an annotated tag from its promisor remote, but not the object that it refers to, printing a warning on such a tag is incorrect. This occurs, for example, when the checkout that happens after a partial clone causes some objects to be fetched - and as part of the fetch, all local refs are read. The test included in this patch demonstrates this situation. Therefore, do not print a warning in this case. Signed-off-by: Jonathan Tan <jonathantanmy@google.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Jonathan Tan committed Jul 12, 2018 at 17:03 UTC 8c4cc326896de1a1501135c529b0596fa6327969
2 files changed +17 -5
t/t5616-partial-clone.sh
+7 -2
@@ -229,9 +229,13 @@ test_expect_success 'when partial cloning, tolerate server not sending target of
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 - printf "%s\n%s\n--not\n%s\n" \
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
@@ -249,7 +253,8 @@ test_expect_success 'when partial cloning, tolerate server not sending target of
253
254 # Exercise to make sure it works.
255 git -c protocol.version=2 clone \
252 - --filter=blob:none $HTTPD_URL/one_time_sed/server repo &&
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"
tag.c
+10 -3
@@ -4,6 +4,7 @@
4 #include "tree.h"
5 #include "blob.h"
6 #include "gpg-interface.h"
7 +#include "packfile.h"
8
9 const char *tag_type = "tag";
10
@@ -64,12 +65,18 @@ int gpg_verify_tag(const struct object_id *oid, const char *name_to_report,
65
66 struct object *deref_tag(struct object *o, const char *warn, int warnlen)
67 {
68 + struct object_id *last_oid = NULL;
69 while (o && o->type == OBJ_TAG)
68 - if (((struct tag *)o)->tagged)
69 - o = parse_object(&((struct tag *)o)->tagged->oid);
70 - else
70 + if (((struct tag *)o)->tagged) {
71 + last_oid = &((struct tag *)o)->tagged->oid;
72 + o = parse_object(last_oid);
73 + } else {
74 + last_oid = NULL;
75 o = NULL;
76 + }
77 if (!o && warn) {
78 + if (last_oid && is_promisor_object(last_oid))
79 + return NULL;
80 if (!warnlen)
81 warnlen = strlen(warn);
82 error("missing object referenced by '%.*s'", warnlen, warn);