summaryrefslogtreecommitdiff
path: root/upload-pack.c
diff options
context:
space:
mode:
authorJeff King <peff@peff.net>2019-04-13 05:53:34 (GMT)
committerJunio C Hamano <gitster@pobox.com>2019-04-15 05:00:51 (GMT)
commit014ade748420b074a06dbb7f5fb974b5e6184f43 (patch)
treede88773d89989f44f355aa5c5070e19087b2b4a6 /upload-pack.c
parent6963a4e4e1fe7b4668a954eeb05feab98d625ddc (diff)
downloadgit-014ade748420b074a06dbb7f5fb974b5e6184f43.zip
git-014ade748420b074a06dbb7f5fb974b5e6184f43.tar.gz
git-014ade748420b074a06dbb7f5fb974b5e6184f43.tar.bz2
upload-pack: send ERR packet for non-tip objects
Commit bdb31eada7 (upload-pack: report "not our ref" to client, 2017-02-23) catches the case where a client asks for an object we don't have, and issues a message that the client can show to the user (in addition to dying and writing to stderr). There's a similar case (with the same message) when the client asks for an object which we _do_ have, but which isn't a ref tip (or isn't reachable, when uploadpack.allowReachableSHA1InWant is true). Let's give that one the same treatment, for the same reason (namely that it's more informative to the client than just hanging up, since they won't see our stderr over some protocols). There are two tests here. We cover it most directly in t5530 by invoking upload-pack, which matches the existing "not our ref" test. But a more end-to-end check is that "git fetch" actually shows the message to the client. We're already checking in t5516 that this case fails, so we can just check stderr there, too. Note that even after we started ignoring SIGPIPE in 8bf4becf0c, this could in theory still be racy as described in that commit (because we die() on write failures before pumping the connection for any ERR packets). In practice this should be OK for this case. The server will not actually check reachability until it has received our whole group of "want" lines. And since we have no objects in the repository, we won't send any "have" lines, meaning we're always waiting to read the server response. Note also that this case cannot happen in the v2 protocol, since it allows any available object to be requested. However, we don't have to take any steps to protect against the upcoming GIT_TEST_PROTOCOL_VERSION in our tests: - the tests in t5516 would already need to be skipped under v2, and that is covered by ab0c5f5096 (tests: always test fetch of unreachable with v0, 2019-02-25) - the tests in t5530 invoke upload-pack directly, which will continue to default to v0. Eventually we may have a test setting which uses v2 even for bare upload-pack calls, but we can't override it here until we know what the setting looks like. Signed-off-by: Jeff King <peff@peff.net> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Diffstat (limited to 'upload-pack.c')
-rw-r--r--upload-pack.c11
1 files changed, 8 insertions, 3 deletions
diff --git a/upload-pack.c b/upload-pack.c
index d098ef5..cb603a6 100644
--- a/upload-pack.c
+++ b/upload-pack.c
@@ -592,7 +592,8 @@ error:
return 1;
}
-static void check_non_tip(struct object_array *want_obj)
+static void check_non_tip(struct object_array *want_obj,
+ struct packet_writer *writer)
{
int i;
@@ -611,9 +612,13 @@ error:
/* Pick one of them (we know there at least is one) */
for (i = 0; i < want_obj->nr; i++) {
struct object *o = want_obj->objects[i].item;
- if (!is_our_ref(o))
+ if (!is_our_ref(o)) {
+ packet_writer_error(writer,
+ "upload-pack: not our ref %s",
+ oid_to_hex(&o->oid));
die("git upload-pack: not our ref %s",
oid_to_hex(&o->oid));
+ }
}
}
@@ -936,7 +941,7 @@ static void receive_needs(struct packet_reader *reader, struct object_array *wan
* by another process that handled the initial request.
*/
if (has_non_tip)
- check_non_tip(want_obj);
+ check_non_tip(want_obj, &writer);
if (!use_sideband && daemon_mode)
no_progress = 1;