Skip to content

Commit 3fccf74

Browse files
committed
ssh: GIT_SSH_LIBSSH2 is now distinct from GIT_SSH
We may want to support SSH but with a different provider that is not libssh2. Add GIT_SSH to indicate that we have some inbuilt SSH support and GIT_SSH_LIBSSH2 to indicate that support is via libssh2. This is similar to how we support GIT_HTTPS and GIT_OPENSSL, for example.
1 parent 67ab8f0 commit 3fccf74

File tree

9 files changed

+32
-29
lines changed

9 files changed

+32
-29
lines changed

CMakeLists.txt

+1-1
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ option(USE_THREADS "Use threads for parallel processing when possibl
3030
option(USE_NSEC "Support nanosecond precision file mtimes and ctimes" ON)
3131

3232
# Backend selection
33-
option(USE_SSH "Link with libssh2 to enable SSH support" OFF)
33+
option(USE_SSH "Enable SSH support. Can be set to a specific backend" OFF)
3434
option(USE_HTTPS "Enable HTTPS support. Can be set to a specific backend" ON)
3535
option(USE_SHA1 "Enable SHA1. Can be set to CollisionDetection(ON)/HTTPS" ON)
3636
option(USE_SHA256 "Enable SHA256. Can be set to HTTPS/Builtin" ON)

cmake/SelectSSH.cmake

+16-17
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
1-
# Optional external dependency: libssh2
2-
if(USE_SSH)
1+
# find libssh2
2+
if(USE_SSH STREQUAL ON OR USE_SSH STREQUAL "libssh2")
33
find_pkglibraries(LIBSSH2 libssh2)
4+
45
if(NOT LIBSSH2_FOUND)
56
find_package(LibSSH2)
67
set(LIBSSH2_INCLUDE_DIRS ${LIBSSH2_INCLUDE_DIR})
@@ -12,30 +13,28 @@ if(USE_SSH)
1213
if(NOT LIBSSH2_FOUND)
1314
message(FATAL_ERROR "LIBSSH2 not found. Set CMAKE_PREFIX_PATH if it is installed outside of the default search path.")
1415
endif()
15-
endif()
1616

17-
if(LIBSSH2_FOUND)
18-
set(GIT_SSH 1)
1917
list(APPEND LIBGIT2_SYSTEM_INCLUDES ${LIBSSH2_INCLUDE_DIRS})
2018
list(APPEND LIBGIT2_SYSTEM_LIBS ${LIBSSH2_LIBRARIES})
2119
list(APPEND LIBGIT2_PC_LIBS ${LIBSSH2_LDFLAGS})
2220

2321
check_library_exists("${LIBSSH2_LIBRARIES}" libssh2_userauth_publickey_frommemory "${LIBSSH2_LIBRARY_DIRS}" HAVE_LIBSSH2_MEMORY_CREDENTIALS)
2422
if(HAVE_LIBSSH2_MEMORY_CREDENTIALS)
25-
set(GIT_SSH_MEMORY_CREDENTIALS 1)
23+
set(GIT_SSH_LIBSSH2_MEMORY_CREDENTIALS 1)
2624
endif()
27-
else()
28-
message(STATUS "LIBSSH2 not found. Set CMAKE_PREFIX_PATH if it is installed outside of the default search path.")
29-
endif()
3025

31-
if(WIN32 AND EMBED_SSH_PATH)
32-
file(GLOB SSH_SRC "${EMBED_SSH_PATH}/src/*.c")
33-
list(SORT SSH_SRC)
34-
list(APPEND LIBGIT2_DEPENDENCY_OBJECTS ${SSH_SRC})
26+
if(WIN32 AND EMBED_SSH_PATH)
27+
file(GLOB SSH_SRC "${EMBED_SSH_PATH}/src/*.c")
28+
list(SORT SSH_SRC)
29+
list(APPEND LIBGIT2_DEPENDENCY_OBJECTS ${SSH_SRC})
30+
31+
list(APPEND LIBGIT2_DEPENDENCY_INCLUDES "${EMBED_SSH_PATH}/include")
32+
file(WRITE "${EMBED_SSH_PATH}/src/libssh2_config.h" "#define HAVE_WINCNG\n#define LIBSSH2_WINCNG\n#include \"../win32/libssh2_config.h\"")
33+
endif()
3534

36-
list(APPEND LIBGIT2_DEPENDENCY_INCLUDES "${EMBED_SSH_PATH}/include")
37-
file(WRITE "${EMBED_SSH_PATH}/src/libssh2_config.h" "#define HAVE_WINCNG\n#define LIBSSH2_WINCNG\n#include \"../win32/libssh2_config.h\"")
3835
set(GIT_SSH 1)
36+
set(GIT_SSH_LIBSSH2 1)
37+
add_feature_info(SSH ON "using libssh2")
38+
else()
39+
add_feature_info(SSH OFF "SSH transport support")
3940
endif()
40-
41-
add_feature_info(SSH GIT_SSH "SSH transport support")

src/libgit2/libgit2.c

+2-2
Original file line numberDiff line numberDiff line change
@@ -126,10 +126,10 @@ int git_libgit2_features(void)
126126
#ifdef GIT_HTTPS
127127
| GIT_FEATURE_HTTPS
128128
#endif
129-
#if defined(GIT_SSH)
129+
#ifdef GIT_SSH
130130
| GIT_FEATURE_SSH
131131
#endif
132-
#if defined(GIT_USE_NSEC)
132+
#ifdef GIT_USE_NSEC
133133
| GIT_FEATURE_NSEC
134134
#endif
135135
;

src/libgit2/transport.c

+3
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ typedef struct transport_definition {
2222

2323
static git_smart_subtransport_definition http_subtransport_definition = { git_smart_subtransport_http, 1, NULL };
2424
static git_smart_subtransport_definition git_subtransport_definition = { git_smart_subtransport_git, 0, NULL };
25+
2526
#ifdef GIT_SSH
2627
static git_smart_subtransport_definition ssh_subtransport_definition = { git_smart_subtransport_ssh, 0, NULL };
2728
#endif
@@ -33,11 +34,13 @@ static transport_definition transports[] = {
3334
{ "http://", git_transport_smart, &http_subtransport_definition },
3435
{ "https://", git_transport_smart, &http_subtransport_definition },
3536
{ "file://", git_transport_local, NULL },
37+
3638
#ifdef GIT_SSH
3739
{ "ssh://", git_transport_smart, &ssh_subtransport_definition },
3840
{ "ssh+git://", git_transport_smart, &ssh_subtransport_definition },
3941
{ "git+ssh://", git_transport_smart, &ssh_subtransport_definition },
4042
#endif
43+
4144
{ NULL, 0, 0 }
4245
};
4346

src/libgit2/transports/credential.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -204,7 +204,7 @@ int git_credential_ssh_key_memory_new(
204204
const char *privatekey,
205205
const char *passphrase)
206206
{
207-
#ifdef GIT_SSH_MEMORY_CREDENTIALS
207+
#ifdef GIT_SSH_LIBSSH2_MEMORY_CREDENTIALS
208208
return git_credential_ssh_key_type_new(
209209
cred,
210210
username,

src/libgit2/transports/ssh.c

+2-2
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ int git_smart_subtransport_ssh(
1414
git_transport *owner,
1515
void *param)
1616
{
17-
#ifdef GIT_SSH
17+
#ifdef GIT_SSH_LIBSSH2
1818
return git_smart_subtransport_ssh_libssh2(out, owner, param);
1919
#else
2020
GIT_UNUSED(out);
@@ -31,7 +31,7 @@ int git_transport_ssh_with_paths(
3131
git_remote *owner,
3232
void *payload)
3333
{
34-
#ifdef GIT_SSH
34+
#ifdef GIT_SSH_LIBSSH2
3535
git_strarray *paths = (git_strarray *) payload;
3636
git_transport *transport;
3737
transport_smart *smart;

src/libgit2/transports/ssh_libssh2.c

+3-3
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77

88
#include "ssh_libssh2.h"
99

10-
#ifdef GIT_SSH
10+
#ifdef GIT_SSH_LIBSSH2
1111

1212
#include <libssh2.h>
1313

@@ -342,7 +342,7 @@ static int _git_ssh_authenticate_session(
342342
session, c->username, c->prompt_callback);
343343
break;
344344
}
345-
#ifdef GIT_SSH_MEMORY_CREDENTIALS
345+
#ifdef GIT_SSH_LIBSSH2_MEMORY_CREDENTIALS
346346
case GIT_CREDENTIAL_SSH_MEMORY: {
347347
git_credential_ssh_key *c = (git_credential_ssh_key *)cred;
348348

@@ -1020,7 +1020,7 @@ static int list_auth_methods(int *out, LIBSSH2_SESSION *session, const char *use
10201020
if (!git__prefixcmp(ptr, SSH_AUTH_PUBLICKEY)) {
10211021
*out |= GIT_CREDENTIAL_SSH_KEY;
10221022
*out |= GIT_CREDENTIAL_SSH_CUSTOM;
1023-
#ifdef GIT_SSH_MEMORY_CREDENTIALS
1023+
#ifdef GIT_SSH_LIBSSH2_MEMORY_CREDENTIALS
10241024
*out |= GIT_CREDENTIAL_SSH_MEMORY;
10251025
#endif
10261026
ptr += strlen(SSH_AUTH_PUBLICKEY);

src/util/git2_features.h.in

+2-1
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,8 @@
3030
#cmakedefine GIT_QSORT_MSC
3131

3232
#cmakedefine GIT_SSH 1
33-
#cmakedefine GIT_SSH_MEMORY_CREDENTIALS 1
33+
#cmakedefine GIT_SSH_LIBSSH2 1
34+
#cmakedefine GIT_SSH_LIBSSH2_MEMORY_CREDENTIALS 1
3435

3536
#cmakedefine GIT_NTLM 1
3637
#cmakedefine GIT_GSSAPI 1

tests/libgit2/online/clone.c

+2-2
Original file line numberDiff line numberDiff line change
@@ -675,7 +675,7 @@ void test_online_clone__ssh_auth_methods(void)
675675
*/
676676
void test_online_clone__ssh_certcheck_accepts_unknown(void)
677677
{
678-
#if !defined(GIT_SSH) || !defined(GIT_SSH_MEMORY_CREDENTIALS)
678+
#if !defined(GIT_SSH_LIBSSH2) || !defined(GIT_SSH_MEMORY_CREDENTIALS)
679679
clar__skip();
680680
#endif
681681

@@ -793,7 +793,7 @@ static int cred_foo_bar(git_credential **cred, const char *url, const char *user
793793

794794
void test_online_clone__ssh_cannot_change_username(void)
795795
{
796-
#ifndef GIT_SSH
796+
#ifndef GIT_SSH_LIBSSH2
797797
clar__skip();
798798
#endif
799799
g_options.fetch_opts.callbacks.credentials = cred_foo_bar;

0 commit comments

Comments
 (0)