{"thread":{"id":"9918","subject":"[PATCH 4/5] Avoid printing unnecessary warnings during fetch and push","startedAt":"2007-09-18T08:54:57Z","lastAt":"2007-09-18T08:54:57Z","messageCount":1,"participants":["Shawn O. Pearce"],"isPatch":true,"patchVersion":1,"patchTotal":5},"messages":[{"id":"53424","messageId":"20070918085457.GD5390@spearce.org","threadId":"9918","inReplyTo":null,"subject":"[PATCH 4/5] Avoid printing unnecessary warnings during fetch and push","fromName":"Shawn O. Pearce","fromEmail":"spearce@spearce.org","sentAt":"2007-09-18T08:54:57Z","receivedAt":"2007-09-18T08:54:57Z","isPatch":true,"sender":{"key":"spearce@spearce.org","avatar":"https://avatars.githubusercontent.com/u/34844?v=4"},"body":"If a transport doesn't support an option we already are telling\nthe higher level application (fetch or push) that the option is not\nvalid by sending back a >0 return value from transport_set_option\nso there's not a strong motivation to have the function perform the\noutput itself.  Instead we should let the higher level application\ndo the output if it is necessary.  This avoids always telling the\nuser that depth isn't supported on HTTP urls even when they did\nnot pass a --depth option to git-fetch.\n\nIf the user passes an option and the option value is invalid we now\nproperly die in git-fetch instead of just spitting out a message\nand running anyway.  This mimics prior behavior better where\nincorrect/malformed options are not accepted by the process.\n\nSigned-off-by: Shawn O. Pearce <spearce@spearce.org>\n---\n builtin-fetch.c |   18 +++++++++++++++---\n transport.c     |   11 ++---------\n 2 files changed, 17 insertions(+), 12 deletions(-)\n\ndiff --git a/builtin-fetch.c b/builtin-fetch.c\nindex 670af0b..b9722e5 100644\n--- a/builtin-fetch.c\n+++ b/builtin-fetch.c\n@@ -430,6 +430,17 @@ static int do_fetch(struct transport *transport,\n \treturn 0;\n }\n \n+static void set_option(const char *name, const char *value)\n+{\n+\tint r = transport_set_option(transport, name, value);\n+\tif (r < 0)\n+\t\tdie(\"Option \\\"%s\\\" value \\\"%s\\\" is not valid for %s\\n\",\n+\t\t\tname, value, transport->url);\n+\tif (r > 0)\n+\t\twarning(\"Option \\\"%s\\\" is ignored for %s\\n\",\n+\t\t\tname, transport->url);\n+}\n+\n int cmd_fetch(int argc, const char **argv, const char *prefix)\n {\n \tstruct remote *remote;\n@@ -525,10 +536,11 @@ int cmd_fetch(int argc, const char **argv, const char *prefix)\n \tif (quiet)\n \t\ttransport->verbose = 0;\n \tif (upload_pack)\n-\t\ttransport_set_option(transport, TRANS_OPT_UPLOADPACK, upload_pack);\n+\t\tset_option(TRANS_OPT_UPLOADPACK, upload_pack);\n \tif (keep)\n-\t\ttransport_set_option(transport, TRANS_OPT_KEEP, \"yes\");\n-\ttransport_set_option(transport, TRANS_OPT_DEPTH, depth);\n+\t\tset_option(TRANS_OPT_KEEP, \"yes\");\n+\tif (depth)\n+\t\tset_option(TRANS_OPT_DEPTH, depth);\n \n \tif (!transport->url)\n \t\tdie(\"Where do you want to fetch from today?\");\ndiff --git a/transport.c b/transport.c\nindex 7f94d30..cc76e3f 100644\n--- a/transport.c\n+++ b/transport.c\n@@ -460,16 +460,9 @@ struct transport *transport_get(struct remote *remote, const char *url)\n int transport_set_option(struct transport *transport,\n \t\t\t const char *name, const char *value)\n {\n-\tint ret = 1;\n \tif (transport->ops->set_option)\n-\t\tret = transport->ops->set_option(transport, name, value);\n-\tif (ret < 0)\n-\t\tfprintf(stderr, \"For '%s' option %s cannot be set to '%s'\\n\",\n-\t\t\ttransport->url, name, value);\n-\tif (ret > 0)\n-\t\tfprintf(stderr, \"For '%s' option %s is ignored\\n\",\n-\t\t\ttransport->url, name);\n-\treturn ret;\n+\t\treturn transport->ops->set_option(transport, name, value);\n+\treturn 1;\n }\n \n int transport_push(struct transport *transport,\n-- \n1.5.3.1.1000.g7319b\n"}]}