git@vger.kernel.org mailing list mirror (one of many)
 help / color / mirror / code / Atom feed
* [PATCH] protocol: treat unrecognized protocol.version setting as 0
@ 2018-02-28  0:50 Jonathan Nieder
  2018-02-28  1:02 ` Brandon Williams
  2018-02-28 17:53 ` Junio C Hamano
  0 siblings, 2 replies; 9+ messages in thread
From: Jonathan Nieder @ 2018-02-28  0:50 UTC (permalink / raw)
  To: git; +Cc: Brandon Williams, Jeff King

If I share my .gitconfig or .git/config file between multiple machines
(or between multiple Git versions on a single machine) and set

	[protocol]
		version = 2

then running "git fetch" with a Git version that does not support
protocol v2 errors out with

	fatal: unknown value for config 'protocol.version': 2

In the spirit of v1.7.6-rc0~77^2~1 (Improve error handling when
parsing dirstat parameters, 2011-04-29), it is better to (perhaps
after warning the user) ignore the unrecognized protocol version.
After all, future Git versions might add even more protocol versions,
and using two different Git versions with the same Git repo, machine,
or home directory should not cripple the older Git version just
because of a parameter that is only understood by a more recent Git
version.

So ignore the unrecognized value.  It may be useful for spell checking
(for instance, if I put "version = v1" intending "version = 1") to
warn about such settings, but this patch does not, since at least in
these early days for protocol v2 it is expected for configurations
that want to opportunistically use protocol v2 if available not to be
unusual.

Signed-off-by: Jonathan Nieder <jrnieder@gmail.com>
---
Google has been running with a patch like this internally for a while,
since we have been changing the protocol.version number to a new value
like 20180226 each time a minor tweak to the protocolv2 RFC occured.

The bit I have doubts about is whether to warn.  What do you think?

Thanks,
Jonathan

 protocol.c             |  8 ++------
 t/t5700-protocol-v1.sh | 12 ++++++++++++
 2 files changed, 14 insertions(+), 6 deletions(-)

diff --git a/protocol.c b/protocol.c
index 43012b7eb6..ce9c634a3a 100644
--- a/protocol.c
+++ b/protocol.c
@@ -17,12 +17,8 @@ enum protocol_version get_protocol_version_config(void)
 	const char *value;
 	if (!git_config_get_string_const("protocol.version", &value)) {
 		enum protocol_version version = parse_protocol_version(value);
-
-		if (version == protocol_unknown_version)
-			die("unknown value for config 'protocol.version': %s",
-			    value);
-
-		return version;
+		if (version != protocol_unknown_version)
+			return version;
 	}
 
 	return protocol_v0;
diff --git a/t/t5700-protocol-v1.sh b/t/t5700-protocol-v1.sh
index ba86a44eb1..c35767ab01 100755
--- a/t/t5700-protocol-v1.sh
+++ b/t/t5700-protocol-v1.sh
@@ -31,6 +31,18 @@ test_expect_success 'clone with git:// using protocol v1' '
 	grep "clone< version 1" log
 '
 
+test_expect_success 'unrecognized protocol versions fall back to v0' '
+	GIT_TRACE_PACKET=1 git -c protocol.version=9999 \
+		clone "$GIT_DAEMON_URL/parent" v9999 2>log &&
+
+	git -C daemon_child log -1 --format=%s >actual &&
+	git -C "$daemon_parent" log -1 --format=%s >expect &&
+	test_cmp expect actual &&
+
+	# Client requested and server responded using protocol v0
+	! grep version log
+'
+
 test_expect_success 'fetch with git:// using protocol v1' '
 	test_commit -C "$daemon_parent" two &&
 
-- 
2.16.2.395.g2e18187dfd


^ permalink raw reply related	[flat|nested] 9+ messages in thread

end of thread, other threads:[~2018-02-28 18:07 UTC | newest]

Thread overview: 9+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2018-02-28  0:50 [PATCH] protocol: treat unrecognized protocol.version setting as 0 Jonathan Nieder
2018-02-28  1:02 ` Brandon Williams
2018-02-28  1:10   ` Duy Nguyen
2018-02-28  1:16     ` Brandon Williams
2018-02-28  1:22     ` Jonathan Nieder
2018-02-28 17:55       ` Junio C Hamano
2018-02-28 18:06         ` Junio C Hamano
2018-02-28 17:53 ` Junio C Hamano
2018-02-28 18:07   ` Jonathan Nieder

Code repositories for project(s) associated with this public inbox

	https://80x24.org/mirrors/git.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).