Skip to content

Commit a7e1eb2

Browse files
authored
Merge pull request libgit2#7245 from mrdimidium/main
2 parents 8a94cd5 + dac34ee commit a7e1eb2

13 files changed

Lines changed: 102 additions & 14 deletions

File tree

CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ option(BUILD_FUZZERS "Build the fuzz targets"
2929
# Feature enablement and backend selection
3030
set(USE_THREADS "" CACHE STRING "Use threads for parallel processing when possible. One of ON, OFF, or a specific provider: pthreads or win32. (Defaults to ON.)")
3131
set(USE_SSH "" CACHE STRING "Enables SSH support and optionally selects provider. One of ON, OFF, or a specific provider: libssh2 or exec. (Defaults to OFF.)")
32+
set(USE_HTTP "" CACHE STRING "Enable HTTP transport support (covers both http:// and https:// remotes). One of ON or OFF. When OFF, HTTPS is also disabled. (Defaults to ON.)")
3233
set(USE_HTTPS "" CACHE STRING "Enable HTTPS support and optionally selects the provider. One of ON, OFF, or a specific provider: OpenSSL, OpenSSL-FIPS, OpenSSL-Dynamic, mbedTLS, SecureTransport, Schannel, or WinHTTP. (Defaults to ON.)")
3334
set(USE_SHA1 "" CACHE STRING "Selects SHA1 provider. One of builtin, HTTPS, or a specific provider. (Defaults to builtin.)")
3435
set(USE_SHA256 "" CACHE STRING "Selects SHA256 provider. One of Builtin, HTTPS, or a specific provider. (Defaults to HTTPS.)")

cmake/SelectHTTP.cmake

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
include(SanitizeInput)
2+
3+
if(USE_HTTP STREQUAL "")
4+
set(USE_HTTP ON)
5+
endif()
6+
7+
sanitizeinput(USE_HTTP)
8+
9+
if(USE_HTTP STREQUAL ON)
10+
set(GIT_HTTP 1)
11+
add_feature_info(HTTP ON "HTTP transport support")
12+
elseif(USE_HTTP STREQUAL OFF)
13+
# Several features only have meaning over HTTP: HTTPS, NTLM and
14+
# Negotiate auth. If the user did not request them explicitly, silently
15+
# disable them to keep configurations consistent. If they were requested
16+
# explicitly, error out: they cannot be built without the HTTP transport.
17+
foreach(_dep USE_HTTPS USE_AUTH_NTLM USE_AUTH_NEGOTIATE)
18+
if(${_dep} STREQUAL "")
19+
set(${_dep} OFF)
20+
else()
21+
set(_dep_check "${${_dep}}")
22+
sanitizeinput(_dep_check)
23+
if(_dep_check)
24+
message(FATAL_ERROR "${_dep}=${${_dep}} requires USE_HTTP=ON; this feature depends on the HTTP transport")
25+
endif()
26+
endif()
27+
endforeach()
28+
29+
add_feature_info(HTTP OFF "HTTP transport support is disabled")
30+
else()
31+
message(FATAL_ERROR "unknown HTTP option: ${USE_HTTP}")
32+
endif()

include/git2/common.h

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -173,7 +173,10 @@ typedef enum {
173173
GIT_FEATURE_SHA1 = (1 << 10),
174174

175175
/** SHA256 object support */
176-
GIT_FEATURE_SHA256 = (1 << 11)
176+
GIT_FEATURE_SHA256 = (1 << 11),
177+
178+
/** HTTP remotes */
179+
GIT_FEATURE_HTTP = (1 << 12)
177180
} git_feature_t;
178181

179182
/**

src/CMakeLists.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ add_feature_info("Debug open" GIT_DEBUG_STRICT_OPEN "strict path validation in o
3838

3939
include(SelectThreads)
4040
include(SelectNsec)
41+
include(SelectHTTP)
4142
include(SelectHTTPSBackend)
4243
include(SelectHashes)
4344
include(SelectHTTPParser)
@@ -172,3 +173,4 @@ set(LIBGIT2_DEPENDENCY_INCLUDES ${LIBGIT2_DEPENDENCY_INCLUDES} PARENT_SCOPE)
172173
set(LIBGIT2_DEPENDENCY_OBJECTS ${LIBGIT2_DEPENDENCY_OBJECTS} PARENT_SCOPE)
173174
set(LIBGIT2_SYSTEM_INCLUDES ${LIBGIT2_SYSTEM_INCLUDES} PARENT_SCOPE)
174175
set(LIBGIT2_SYSTEM_LIBS ${LIBGIT2_SYSTEM_LIBS} PARENT_SCOPE)
176+
set(GIT_HTTP ${GIT_HTTP} PARENT_SCOPE)

src/libgit2/libgit2.c

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,9 @@ int git_libgit2_features(void)
8686
#ifdef GIT_THREADS
8787
| GIT_FEATURE_THREADS
8888
#endif
89+
#ifdef GIT_HTTP
90+
| GIT_FEATURE_HTTP
91+
#endif
8992
#ifdef GIT_HTTPS
9093
| GIT_FEATURE_HTTPS
9194
#endif
@@ -127,6 +130,10 @@ const char *git_libgit2_feature_backend(git_feature_t feature)
127130
#endif
128131
break;
129132

133+
case GIT_FEATURE_HTTP:
134+
/* HTTP has no backend selection; presence is reported via git_libgit2_features() */
135+
break;
136+
130137
case GIT_FEATURE_HTTPS:
131138
#if defined(GIT_HTTPS_OPENSSL)
132139
return "openssl";

src/libgit2/transport.c

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,9 +20,12 @@ typedef struct transport_definition {
2020
void *param;
2121
} transport_definition;
2222

23-
static git_smart_subtransport_definition http_subtransport_definition = { git_smart_subtransport_http, 1, NULL };
2423
static git_smart_subtransport_definition git_subtransport_definition = { git_smart_subtransport_git, 0, NULL };
2524

25+
#ifdef GIT_HTTP
26+
static git_smart_subtransport_definition http_subtransport_definition = { git_smart_subtransport_http, 1, NULL };
27+
#endif
28+
2629
#ifdef GIT_SSH
2730
static git_smart_subtransport_definition ssh_subtransport_definition = { git_smart_subtransport_ssh, 0, NULL };
2831
#endif
@@ -31,8 +34,10 @@ static transport_definition local_transport_definition = { "file://", git_transp
3134

3235
static transport_definition transports[] = {
3336
{ "git://", git_transport_smart, &git_subtransport_definition },
37+
#ifdef GIT_HTTP
3438
{ "http://", git_transport_smart, &http_subtransport_definition },
3539
{ "https://", git_transport_smart, &http_subtransport_definition },
40+
#endif
3641
{ "file://", git_transport_local, NULL },
3742

3843
#ifdef GIT_SSH

src/libgit2/transports/http.c

Lines changed: 19 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,14 +6,16 @@
66
*/
77

88
#include "common.h"
9+
#include "http.h"
10+
11+
bool git_http__expect_continue = false;
912

10-
#ifndef GIT_HTTPS_WINHTTP
13+
#if defined(GIT_HTTP) && !defined(GIT_HTTPS_WINHTTP)
1114

1215
#include "net.h"
1316
#include "remote.h"
1417
#include "smart.h"
1518
#include "auth.h"
16-
#include "http.h"
1719
#include "auth_negotiate.h"
1820
#include "auth_ntlm.h"
1921
#include "trace.h"
@@ -22,8 +24,6 @@
2224
#include "httpclient.h"
2325
#include "git2/sys/credential.h"
2426

25-
bool git_http__expect_continue = false;
26-
2727
typedef enum {
2828
HTTP_STATE_NONE = 0,
2929
HTTP_STATE_SENDING_REQUEST,
@@ -762,4 +762,18 @@ int git_smart_subtransport_http(git_smart_subtransport **out, git_transport *own
762762
return 0;
763763
}
764764

765-
#endif /* !GIT_HTTPS_WINHTTP */
765+
#elif !defined(GIT_HTTP)
766+
767+
#include "git2/sys/transport.h"
768+
769+
int git_smart_subtransport_http(git_smart_subtransport **out, git_transport *owner, void *param)
770+
{
771+
GIT_UNUSED(out);
772+
GIT_UNUSED(owner);
773+
GIT_UNUSED(param);
774+
775+
git_error_set(GIT_ERROR_INVALID, "cannot create HTTP transport; library was built without HTTP support");
776+
return -1;
777+
}
778+
779+
#endif /* GIT_HTTP && !GIT_HTTPS_WINHTTP */

src/libgit2/transports/httpclient.c

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,9 @@
66
*/
77

88
#include "common.h"
9+
10+
#ifdef GIT_HTTP
11+
912
#include "git2.h"
1013

1114
#include "vector.h"
@@ -1634,3 +1637,5 @@ void git_http_client_free(git_http_client *client)
16341637
git_str_dispose(&client->read_buf);
16351638
git__free(client);
16361639
}
1640+
1641+
#endif /* GIT_HTTP */

src/libgit2/transports/httpparser.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@
99

1010
#include <string.h>
1111

12+
#ifdef GIT_HTTP
13+
1214
#if defined(GIT_HTTPPARSER_HTTPPARSER)
1315

1416
#include "http_parser.h"
@@ -126,3 +128,5 @@ size_t git_http_parser_execute(
126128
#else
127129
# error unknown http-parser
128130
#endif
131+
132+
#endif /* GIT_HTTP */

src/libgit2/transports/winhttp.c

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -63,8 +63,6 @@
6363
# define DWORD_MAX 0xffffffff
6464
#endif
6565

66-
bool git_http__expect_continue = false;
67-
6866
static const char *prefix_https = "https://";
6967
static const char *upload_pack_service = "upload-pack";
7068
static const char *upload_pack_ls_service_url = "/info/refs?service=git-upload-pack";

0 commit comments

Comments
 (0)