git.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Elia Pinto <gitter.spiros@gmail.com>
To: git@vger.kernel.org
Cc: gitster@pobox.com, avarab@gmail.com,
	Elia Pinto <gitter.spiros@gmail.com>
Subject: [PATCH 1/2] curl: streamline conditional compilation
Date: Wed, 16 Mar 2022 14:01:05 +0000	[thread overview]
Message-ID: <20220316140106.14678-2-gitter.spiros@gmail.com> (raw)
In-Reply-To: <20220316140106.14678-1-gitter.spiros@gmail.com>

Earlier we introduced git-curl-compat.h that defines bunch of
GIT_CURL_HAVE_X where X is a feature of cURL library we care about,
to make it easily manageable to conditionally compile code against
the version of cURL library we are given.

There however are two oddball macros.  Instead of checking
GIT_CURL_HAVE_CURL_SOCKOPT_OK and using a fallback definition for
CURL_SOCKOPT_OK macro, we just defined CURL_SOCKOPT_OK to a safe
value when compiling against an old version that lack the symbol.
Also, the macro to check CURLOPT_TCP_KEEPALIVE (alone) was named
GITCURL_HAVE_CURLOPT_TCP_KEEPALIVE.

Introduce GIT_CURL_HAVE_CURL_SOCKOPT_OK and define it for the
versions of cURL where we used to use our fallback definition for
CURL_SOCKOPT_OK, and use the fallback definition based on the new
GIT_CURL_HAVE_CURL_SOCKOPT_OK symbol at its sole use site.

To better conform the naming convention of other symbols, rename
GITCURL_HAVE_CURLOPT_TCP_KEEPALIVE to GIT_CURL_HAVE_CURL_SOCKOPT_OK
and update its sole use site.

After this, conditional compilation with cURL library is all
controlled uniformly with GIT_CURL_HAVE_X mechanism.

Co-authored-by: Junio C Hamano <gitster@pobox.com>
Helped-by: Ævar Arnfjörð Bjarmason <avarab@gmail.com>
Signed-off-by: Elia Pinto <gitter.spiros@gmail.com>
---
 git-curl-compat.h | 6 +++---
 http.c            | 6 ++++--
 2 files changed, 7 insertions(+), 5 deletions(-)

diff --git a/git-curl-compat.h b/git-curl-compat.h
index 56a83b6bbd..b14234f9e7 100644
--- a/git-curl-compat.h
+++ b/git-curl-compat.h
@@ -31,15 +31,15 @@
 /**
  * CURL_SOCKOPT_OK was added in 7.21.5, released in April 2011.
  */
-#if LIBCURL_VERSION_NUM < 0x071505
-#define CURL_SOCKOPT_OK 0
+#if LIBCURL_VERSION_NUM >= 0x071505
+#define GIT_CURL_HAVE_CURL_SOCKOPT_OK 1
 #endif
 
 /**
  * CURLOPT_TCP_KEEPALIVE was added in 7.25.0, released in March 2012.
  */
 #if LIBCURL_VERSION_NUM >= 0x071900
-#define GITCURL_HAVE_CURLOPT_TCP_KEEPALIVE 1
+#define GIT_CURL_HAVE_CURLOPT_TCP_KEEPALIVE 1
 #endif
 
 
diff --git a/http.c b/http.c
index 229da4d148..d7ad7db1d6 100644
--- a/http.c
+++ b/http.c
@@ -517,7 +517,7 @@ static int has_proxy_cert_password(void)
 }
 #endif
 
-#ifdef GITCURL_HAVE_CURLOPT_TCP_KEEPALIVE
+#ifdef GIT_CURL_HAVE_CURLOPT_TCP_KEEPALIVE
 static void set_curl_keepalive(CURL *c)
 {
 	curl_easy_setopt(c, CURLOPT_TCP_KEEPALIVE, 1);
@@ -536,7 +536,9 @@ static int sockopt_callback(void *client, curl_socket_t fd, curlsocktype type)
 	rc = setsockopt(fd, SOL_SOCKET, SO_KEEPALIVE, (void *)&ka, len);
 	if (rc < 0)
 		warning_errno("unable to set SO_KEEPALIVE on socket");
-
+#ifndef GIT_CURL_HAVE_CURL_SOCKOPT_OK
+#define CURL_SOCKOPT_OK 0
+#endif
 	return CURL_SOCKOPT_OK;
 }
 
-- 
2.35.1


  reply	other threads:[~2022-03-16 14:01 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-03-16 14:01 [PATCH 0/2] addition of all symbols defined by curl Elia Pinto
2022-03-16 14:01 ` Elia Pinto [this message]
2022-03-16 14:43   ` [PATCH 1/2] curl: streamline conditional compilation Ævar Arnfjörð Bjarmason
2022-03-16 18:04     ` Junio C Hamano
2022-03-16 14:01 ` [PATCH 2/2] git-curl-compat.h: addition of all symbols defined by curl Elia Pinto
2022-03-16 14:47   ` Ævar Arnfjörð Bjarmason
2022-03-16 22:24     ` Elia Pinto

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20220316140106.14678-2-gitter.spiros@gmail.com \
    --to=gitter.spiros@gmail.com \
    --cc=avarab@gmail.com \
    --cc=git@vger.kernel.org \
    --cc=gitster@pobox.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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 NNTP newsgroup(s).