summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorEdward Thomson <ethomson@edwardthomson.com>2021-11-08 22:04:51 -0500
committerEdward Thomson <ethomson@edwardthomson.com>2021-11-11 23:37:51 -0500
commite491c6e7e4c6bceb3e5b5455e5e99effb8991026 (patch)
tree42966a38a78883050fd5e8c2ebb99cac893a1dd8
parent538e4610bee6a91e468a8dbe4530bb7446243491 (diff)
downloadlibgit2-ethomson/util5.tar.gz
refactor: make util an object libraryethomson/util5
Instead of simply including the utility files directly, make them a cmake object library for easy reusability between other projects within libgit2.
-rw-r--r--CMakeLists.txt3
-rw-r--r--cmake/SelectHashes.cmake4
-rw-r--r--src/CMakeLists.txt463
-rw-r--r--src/libgit2/CMakeLists.txt103
-rw-r--r--src/libgit2/common.h178
-rw-r--r--src/libgit2/diff_xdiff.c1
-rw-r--r--src/libgit2/netops.c1
-rw-r--r--src/libgit2/path.c1
-rw-r--r--src/libgit2/win32/git2.rc (renamed from src/util/win32/git2.rc)0
-rw-r--r--src/util/CMakeLists.txt70
-rw-r--r--src/util/allocators/failalloc.h2
-rw-r--r--src/util/allocators/stdalloc.h2
-rw-r--r--src/util/allocators/win32_leakcheck.h2
-rw-r--r--src/util/array.h2
-rw-r--r--src/util/fs_path.c18
-rw-r--r--src/util/fs_path.h2
-rw-r--r--src/util/futils.h2
-rw-r--r--src/util/git2_util.h182
-rw-r--r--src/util/hash.h2
-rw-r--r--src/util/hash/sha1.h2
-rw-r--r--src/util/map.h2
-rw-r--r--src/util/net.c1
-rw-r--r--src/util/net.h2
-rw-r--r--src/util/pool.h2
-rw-r--r--src/util/posix.h2
-rw-r--r--src/util/regexp.h2
-rw-r--r--src/util/runtime.c2
-rw-r--r--src/util/runtime.h2
-rw-r--r--src/util/str.h2
-rw-r--r--src/util/strmap.h2
-rw-r--r--src/util/strnlen.h (renamed from src/libgit2/strnlen.h)0
-rw-r--r--src/util/thread.c2
-rw-r--r--src/util/tsort.c2
-rw-r--r--src/util/unix/map.c2
-rw-r--r--src/util/unix/realpath.c2
-rw-r--r--src/util/utf8.c2
-rw-r--r--src/util/utf8.h2
-rw-r--r--src/util/util.c2
-rw-r--r--src/util/util.h2
-rw-r--r--src/util/varint.h2
-rw-r--r--src/util/vector.h2
-rw-r--r--src/util/win32/dir.h2
-rw-r--r--src/util/win32/error.h2
-rw-r--r--src/util/win32/findfile.h2
-rw-r--r--src/util/win32/map.c2
-rw-r--r--src/util/win32/path_w32.h2
-rw-r--r--src/util/win32/posix.h2
-rw-r--r--src/util/win32/posix_w32.c2
-rw-r--r--src/util/win32/precompiled.h2
-rw-r--r--src/util/win32/thread.h2
-rw-r--r--src/util/win32/utf-conv.h2
-rw-r--r--src/util/win32/w32_buffer.h2
-rw-r--r--src/util/win32/w32_leakcheck.h2
-rw-r--r--src/util/win32/w32_util.h2
-rw-r--r--src/util/zstream.h2
-rw-r--r--tests/CMakeLists.txt101
-rw-r--r--tests/core/utf8.c1
57 files changed, 574 insertions, 635 deletions
diff --git a/CMakeLists.txt b/CMakeLists.txt
index 664abc0d2..d16b306b9 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -97,12 +97,13 @@ include(FindPkgLibraries)
include(FindThreads)
include(FindStatNsec)
include(Findfutimens)
+include(SelectHashes)
include(GNUInstallDirs)
include(IdeSplitSources)
include(FeatureSummary)
include(EnableWarnings)
include(DefaultCFlags)
-
+include(PkgBuildConfig)
#
# Subdirectories
diff --git a/cmake/SelectHashes.cmake b/cmake/SelectHashes.cmake
index bedd8c4e3..3bddaddae 100644
--- a/cmake/SelectHashes.cmake
+++ b/cmake/SelectHashes.cmake
@@ -22,8 +22,8 @@ endif()
if(USE_SHA1 STREQUAL "CollisionDetection")
set(GIT_SHA1_COLLISIONDETECT 1)
add_definitions(-DSHA1DC_NO_STANDARD_INCLUDES=1)
- add_definitions(-DSHA1DC_CUSTOM_INCLUDE_SHA1_C=\"common.h\")
- add_definitions(-DSHA1DC_CUSTOM_INCLUDE_UBC_CHECK_C=\"common.h\")
+ add_definitions(-DSHA1DC_CUSTOM_INCLUDE_SHA1_C=\"git2_util.h\")
+ add_definitions(-DSHA1DC_CUSTOM_INCLUDE_UBC_CHECK_C=\"git2_util.h\")
elseif(USE_SHA1 STREQUAL "OpenSSL")
# OPENSSL_FOUND should already be set, we're checking USE_HTTPS
diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt
index 108b0587a..e46f00926 100644
--- a/src/CMakeLists.txt
+++ b/src/CMakeLists.txt
@@ -1,10 +1,6 @@
-add_library(git2internal OBJECT)
-set_target_properties(git2internal PROPERTIES C_STANDARD 90)
-
-
-if(DEPRECATE_HARD)
- add_definitions(-DGIT_DEPRECATE_HARD)
-endif()
+#
+# Optional debugging functionality
+#
if(DEBUG_POOL)
set(GIT_DEBUG_POOL 1)
@@ -21,343 +17,83 @@ if(DEBUG_STRICT_OPEN)
endif()
add_feature_info(debugopen GIT_DEBUG_STRICT_OPEN "path validation in open")
+#
+# Optional feature enablement
+#
-include(PkgBuildConfig)
-include(SanitizeBool)
-
-# This variable will contain the libraries we need to put into
-# libgit2.pc's Requires.private. That is, what we're linking to or
-# what someone who's statically linking us needs to link to.
-set(LIBGIT2_PC_REQUIRES "")
-# This will be set later if we use the system's http-parser library or
-# use iconv (OSX) and will be written to the Libs.private field in the
-# pc file.
-set(LIBGIT2_PC_LIBS "")
-
-set(LIBGIT2_INCLUDES
- "${CMAKE_CURRENT_BINARY_DIR}"
- "${libgit2_SOURCE_DIR}/src/libgit2"
- "${libgit2_SOURCE_DIR}/src/util"
- "${libgit2_SOURCE_DIR}/include")
-set(LIBGIT2_SYSTEM_INCLUDES "")
-set(LIBGIT2_SYSTEM_LIBS "")
-
-if(HAVE_FUTIMENS)
- set(GIT_USE_FUTIMENS 1)
-endif ()
-add_feature_info(futimens GIT_USE_FUTIMENS "futimens support")
-
-check_prototype_definition(qsort_r
- "void qsort_r(void *base, size_t nmemb, size_t size, void *thunk, int (*compar)(void *, const void *, const void *))"
- "" "stdlib.h" GIT_QSORT_R_BSD)
-
-check_prototype_definition(qsort_r
- "void qsort_r(void *base, size_t nmemb, size_t size, int (*compar)(const void *, const void *, void *), void *arg)"
- "" "stdlib.h" GIT_QSORT_R_GNU)
-
-check_function_exists(qsort_s GIT_QSORT_S)
-
-# Find required dependencies
-
-if(WIN32)
- list(APPEND LIBGIT2_SYSTEM_LIBS ws2_32)
-elseif(CMAKE_SYSTEM_NAME MATCHES "(Solaris|SunOS)")
- list(APPEND LIBGIT2_SYSTEM_LIBS socket nsl)
- list(APPEND LIBGIT2_PC_LIBS "-lsocket" "-lnsl")
-elseif(CMAKE_SYSTEM_NAME MATCHES "Haiku")
- list(APPEND LIBGIT2_SYSTEM_LIBS network)
- list(APPEND LIBGIT2_PC_LIBS "-lnetwork")
-endif()
-
-check_library_exists(rt clock_gettime "time.h" NEED_LIBRT)
-if(NEED_LIBRT)
- list(APPEND LIBGIT2_SYSTEM_LIBS rt)
- list(APPEND LIBGIT2_PC_LIBS "-lrt")
-endif()
-
-if(USE_THREADS)
- list(APPEND LIBGIT2_SYSTEM_LIBS ${CMAKE_THREAD_LIBS_INIT})
- list(APPEND LIBGIT2_PC_LIBS ${CMAKE_THREAD_LIBS_INIT})
-endif()
-add_feature_info(threadsafe USE_THREADS "threadsafe support")
-
-
-if(WIN32 AND EMBED_SSH_PATH)
- file(GLOB SRC_SSH "${EMBED_SSH_PATH}/src/*.c")
- list(SORT SRC_SSH)
- target_sources(git2internal PRIVATE ${SRC_SSH})
-
- list(APPEND LIBGIT2_SYSTEM_INCLUDES "${EMBED_SSH_PATH}/include")
- file(WRITE "${EMBED_SSH_PATH}/src/libssh2_config.h" "#define HAVE_WINCNG\n#define LIBSSH2_WINCNG\n#include \"../win32/libssh2_config.h\"")
- set(GIT_SSH 1)
-endif()
-
-if(WIN32 AND WINHTTP)
- set(GIT_WINHTTP 1)
-
- # Since MinGW does not come with headers or an import library for winhttp,
- # we have to include a private header and generate our own import library
- if(MINGW)
- add_subdirectory("${libgit2_SOURCE_DIR}/deps/winhttp" "${libgit2_BINARY_DIR}/deps/winhttp")
- list(APPEND LIBGIT2_SYSTEM_LIBS winhttp)
- list(APPEND LIBGIT2_INCLUDES "${libgit2_SOURCE_DIR}/deps/winhttp")
- else()
- list(APPEND LIBGIT2_SYSTEM_LIBS "winhttp")
- list(APPEND LIBGIT2_PC_LIBS "-lwinhttp")
- endif()
-
- list(APPEND LIBGIT2_SYSTEM_LIBS "rpcrt4" "crypt32" "ole32")
- list(APPEND LIBGIT2_PC_LIBS "-lrpcrt4" "-lcrypt32" "-lole32")
-endif()
-
+include(SelectGSSAPI)
include(SelectHTTPSBackend)
-include(SelectHashes)
-
-
-if(USE_SHA1 STREQUAL "CollisionDetection")
- file(GLOB SRC_SHA1 util/hash/sha1/collisiondetect.* util/hash/sha1/sha1dc/*)
-elseif(USE_SHA1 STREQUAL "OpenSSL")
- file(GLOB SRC_SHA1 util/hash/sha1/openssl.*)
-elseif(USE_SHA1 STREQUAL "CommonCrypto")
- file(GLOB SRC_SHA1 util/hash/sha1/common_crypto.*)
-elseif(USE_SHA1 STREQUAL "Win32")
- file(GLOB SRC_SHA1 util/hash/sha1/win32.*)
-elseif(USE_SHA1 STREQUAL "Generic")
- file(GLOB SRC_SHA1 util/hash/sha1/generic.*)
-endif()
-list(APPEND SRC_SHA1 "util/hash/sha1.h")
-target_sources(git2internal PRIVATE ${SRC_SHA1})
-
-# Specify regular expression implementation
-find_package(PCRE)
-
-if(REGEX_BACKEND STREQUAL "")
- check_symbol_exists(regcomp_l "regex.h;xlocale.h" HAVE_REGCOMP_L)
-
- if(HAVE_REGCOMP_L)
- set(REGEX_BACKEND "regcomp_l")
- elseif(PCRE_FOUND)
- set(REGEX_BACKEND "pcre")
- else()
- set(REGEX_BACKEND "builtin")
- endif()
-endif()
-
-if(REGEX_BACKEND STREQUAL "regcomp_l")
- add_feature_info(regex ON "using system regcomp_l")
- set(GIT_REGEX_REGCOMP_L 1)
-elseif(REGEX_BACKEND STREQUAL "pcre2")
- find_package(PCRE2)
-
- if(NOT PCRE2_FOUND)
- MESSAGE(FATAL_ERROR "PCRE2 support was requested but not found")
- endif()
+include(SelectRegex)
+include(SelectZlib)
+include(SelectSSH)
+include(SelectHTTPParser)
+include(SelectWinHTTP)
- add_feature_info(regex ON "using system PCRE2")
- set(GIT_REGEX_PCRE2 1)
-
- list(APPEND LIBGIT2_SYSTEM_INCLUDES ${PCRE2_INCLUDE_DIRS})
- list(APPEND LIBGIT2_SYSTEM_LIBS ${PCRE2_LIBRARIES})
- list(APPEND LIBGIT2_PC_REQUIRES "libpcre2-8")
-elseif(REGEX_BACKEND STREQUAL "pcre")
- add_feature_info(regex ON "using system PCRE")
- set(GIT_REGEX_PCRE 1)
-
- list(APPEND LIBGIT2_SYSTEM_INCLUDES ${PCRE_INCLUDE_DIRS})
- list(APPEND LIBGIT2_SYSTEM_LIBS ${PCRE_LIBRARIES})
- list(APPEND LIBGIT2_PC_REQUIRES "libpcre")
-elseif(REGEX_BACKEND STREQUAL "regcomp")
- add_feature_info(regex ON "using system regcomp")
- set(GIT_REGEX_REGCOMP 1)
-elseif(REGEX_BACKEND STREQUAL "builtin")
- add_feature_info(regex ON "using bundled PCRE")
- set(GIT_REGEX_BUILTIN 1)
-
- add_subdirectory("${libgit2_SOURCE_DIR}/deps/pcre" "${libgit2_BINARY_DIR}/deps/pcre")
- list(APPEND LIBGIT2_INCLUDES "${libgit2_SOURCE_DIR}/deps/pcre")
- list(APPEND LIBGIT2_OBJECTS $<TARGET_OBJECTS:pcre>)
-else()
- message(FATAL_ERROR "The REGEX_BACKEND option provided is not supported")
-endif()
+# nanosecond support in index
-# Optional external dependency: http-parser
-if(USE_HTTP_PARSER STREQUAL "system")
- find_package(HTTP_Parser)
-
- if(HTTP_PARSER_FOUND AND HTTP_PARSER_VERSION_MAJOR EQUAL 2)
- list(APPEND LIBGIT2_SYSTEM_INCLUDES ${HTTP_PARSER_INCLUDE_DIRS})
- list(APPEND LIBGIT2_SYSTEM_LIBS ${HTTP_PARSER_LIBRARIES})
- list(APPEND LIBGIT2_PC_LIBS "-lhttp_parser")
- add_feature_info(http-parser ON "http-parser support (system)")
- else()
- message(FATAL_ERROR "http-parser support was requested but not found")
- endif()
-else()
- message(STATUS "http-parser version 2 was not found or disabled; using bundled 3rd-party sources.")
- add_subdirectory("${libgit2_SOURCE_DIR}/deps/http-parser" "${libgit2_BINARY_DIR}/deps/http-parser")
- list(APPEND LIBGIT2_INCLUDES "${libgit2_SOURCE_DIR}/deps/http-parser")
- list(APPEND LIBGIT2_OBJECTS "$<TARGET_OBJECTS:http-parser>")
- add_feature_info(http-parser ON "http-parser support (bundled)")
-endif()
-
-# Optional external dependency: zlib
-SanitizeBool(USE_BUNDLED_ZLIB)
-if(USE_BUNDLED_ZLIB STREQUAL ON)
- set(USE_BUNDLED_ZLIB "Bundled")
+if(USE_NSEC)
+ set(GIT_USE_NSEC 1)
+ add_feature_info(nsec GIT_USE_NSEC "nanosecond resolution in file times")
endif()
-if(USE_BUNDLED_ZLIB STREQUAL "OFF")
- find_package(ZLIB)
- if(ZLIB_FOUND)
- list(APPEND LIBGIT2_SYSTEM_INCLUDES ${ZLIB_INCLUDE_DIRS})
- list(APPEND LIBGIT2_SYSTEM_LIBS ${ZLIB_LIBRARIES})
- if(APPLE OR CMAKE_SYSTEM_NAME MATCHES "FreeBSD")
- list(APPEND LIBGIT2_PC_LIBS "-lz")
- else()
- list(APPEND LIBGIT2_PC_REQUIRES "zlib")
- endif()
- add_feature_info(zlib ON "using system zlib")
- else()
- message(STATUS "zlib was not found; using bundled 3rd-party sources." )
- endif()
-endif()
-if(USE_BUNDLED_ZLIB STREQUAL "Chromium")
- add_subdirectory("${libgit2_SOURCE_DIR}/deps/chromium-zlib" "${libgit2_BINARY_DIR}/deps/chromium-zlib")
- list(APPEND LIBGIT2_INCLUDES "${libgit2_SOURCE_DIR}/deps/chromium-zlib")
- list(APPEND LIBGIT2_OBJECTS $<TARGET_OBJECTS:chromium_zlib>)
- add_feature_info(zlib ON "using (Chromium) bundled zlib")
-elseif(USE_BUNDLED_ZLIB OR NOT ZLIB_FOUND)
- add_subdirectory("${libgit2_SOURCE_DIR}/deps/zlib" "${libgit2_BINARY_DIR}/deps/zlib")
- list(APPEND LIBGIT2_INCLUDES "${libgit2_SOURCE_DIR}/deps/zlib")
- list(APPEND LIBGIT2_OBJECTS $<TARGET_OBJECTS:zlib>)
- add_feature_info(zlib ON "using bundled zlib")
-endif()
+# optional external dependency: pthreads
-# Optional external dependency: libssh2
-if(USE_SSH)
- find_pkglibraries(LIBSSH2 libssh2)
- if(NOT LIBSSH2_FOUND)
- find_package(LibSSH2)
- set(LIBSSH2_INCLUDE_DIRS ${LIBSSH2_INCLUDE_DIR})
- get_filename_component(LIBSSH2_LIBRARY_DIRS "${LIBSSH2_LIBRARY}" DIRECTORY)
- set(LIBSSH2_LIBRARIES ${LIBSSH2_LIBRARY})
- set(LIBSSH2_LDFLAGS "-lssh2")
- endif()
-endif()
-if(LIBSSH2_FOUND)
- set(GIT_SSH 1)
- list(APPEND LIBGIT2_SYSTEM_INCLUDES ${LIBSSH2_INCLUDE_DIRS})
- list(APPEND LIBGIT2_SYSTEM_LIBS ${LIBSSH2_LIBRARIES})
- list(APPEND LIBGIT2_PC_LIBS ${LIBSSH2_LDFLAGS})
-
- check_library_exists("${LIBSSH2_LIBRARIES}" libssh2_userauth_publickey_frommemory "${LIBSSH2_LIBRARY_DIRS}" HAVE_LIBSSH2_MEMORY_CREDENTIALS)
- if(HAVE_LIBSSH2_MEMORY_CREDENTIALS)
- set(GIT_SSH_MEMORY_CREDENTIALS 1)
+if(USE_THREADS)
+ if(NOT WIN32)
+ find_package(Threads REQUIRED)
+ list(APPEND LIBGIT2_SYSTEM_LIBS ${CMAKE_THREAD_LIBS_INIT})
+ list(APPEND LIBGIT2_PC_LIBS ${CMAKE_THREAD_LIBS_INIT})
endif()
-else()
- message(STATUS "LIBSSH2 not found. Set CMAKE_PREFIX_PATH if it is installed outside of the default search path.")
-endif()
-add_feature_info(SSH GIT_SSH "SSH transport support")
-# Optional external dependency: ntlmclient
-if(USE_NTLMCLIENT)
- set(GIT_NTLM 1)
- add_subdirectory("${libgit2_SOURCE_DIR}/deps/ntlmclient" "${libgit2_BINARY_DIR}/deps/ntlmclient")
- list(APPEND LIBGIT2_INCLUDES "${libgit2_SOURCE_DIR}/deps/ntlmclient")
- list(APPEND LIBGIT2_OBJECTS "$<TARGET_OBJECTS:ntlmclient>")
+ set(GIT_THREADS 1)
endif()
-add_feature_info(ntlmclient GIT_NTLM "NTLM authentication support for Unix")
+add_feature_info(threadsafe GIT_THREADS "threadsafe support")
-# Optional external dependency: GSSAPI
+# optional external dependency: iconv
-include(SelectGSSAPI)
-
-# Optional external dependency: iconv
if(USE_ICONV)
- find_package(Iconv)
-endif()
-if(ICONV_FOUND)
- set(GIT_USE_ICONV 1)
+ find_package(Iconv REQUIRED)
list(APPEND LIBGIT2_SYSTEM_INCLUDES ${ICONV_INCLUDE_DIR})
list(APPEND LIBGIT2_SYSTEM_LIBS ${ICONV_LIBRARIES})
list(APPEND LIBGIT2_PC_LIBS ${ICONV_LIBRARIES})
+ set(GIT_USE_ICONV 1)
endif()
add_feature_info(iconv GIT_USE_ICONV "iconv encoding conversion support")
+# optional bundled dependency: ntlmclient
-if(USE_THREADS)
- if(NOT WIN32)
- find_package(Threads REQUIRED)
- endif()
-
- set(GIT_THREADS 1)
-endif()
-
-if(USE_NSEC)
- set(GIT_USE_NSEC 1)
+if(USE_NTLMCLIENT)
+ set(GIT_NTLM 1)
+ add_subdirectory("${libgit2_SOURCE_DIR}/deps/ntlmclient" "${libgit2_BINARY_DIR}/deps/ntlmclient")
+ list(APPEND LIBGIT2_DEPENDENCY_INCLUDES "${libgit2_SOURCE_DIR}/deps/ntlmclient")
+ list(APPEND LIBGIT2_DEPENDENCY_OBJECTS "$<TARGET_OBJECTS:ntlmclient>")
endif()
+add_feature_info(ntlmclient GIT_NTLM "NTLM authentication support for Unix")
-if(HAVE_STRUCT_STAT_ST_MTIM)
- set(GIT_USE_STAT_MTIM 1)
-elseif(HAVE_STRUCT_STAT_ST_MTIMESPEC)
- set(GIT_USE_STAT_MTIMESPEC 1)
-elseif(HAVE_STRUCT_STAT_ST_MTIME_NSEC)
- set(GIT_USE_STAT_MTIME_NSEC 1)
-endif()
+#
+# Platform support identification
+#
-target_compile_definitions(git2internal PRIVATE _FILE_OFFSET_BITS=64)
-
-# Collect sourcefiles
-file(GLOB SRC_H
- "${libgit2_SOURCE_DIR}/include/git2.h"
- "${libgit2_SOURCE_DIR}/include/git2/*.h"
- "${libgit2_SOURCE_DIR}/include/git2/sys/*.h")
-list(SORT SRC_H)
-target_sources(git2internal PRIVATE ${SRC_H})
-
-# On Windows use specific platform sources
-if(WIN32 AND NOT CYGWIN)
- set(WIN_RC "util/win32/git2.rc")
-
- file(GLOB SRC_OS util/win32/*.c util/win32/*.h)
- list(SORT SRC_OS)
- target_sources(git2internal PRIVATE ${SRC_OS})
-elseif(AMIGA)
- target_compile_definitions(git2internal PRIVATE NO_ADDRINFO NO_READDIR_R NO_MMAP)
-else()
- file(GLOB SRC_OS util/unix/*.c util/unix/*.h)
- list(SORT SRC_OS)
- target_sources(git2internal PRIVATE ${SRC_OS})
-endif()
+# futimes/futimens
-if(USE_LEAK_CHECKER STREQUAL "valgrind")
- target_compile_definitions(git2internal PRIVATE VALGRIND)
+if(HAVE_FUTIMENS)
+ set(GIT_USE_FUTIMENS 1)
endif()
-file(GLOB SRC_GIT2 libgit2/*.c libgit2/*.h
- libgit2/streams/*.c libgit2/streams/*.h
- libgit2/transports/*.c libgit2/transports/*.h
- libgit2/xdiff/*.c libgit2/xdiff/*.h)
-list(SORT SRC_GIT2)
-target_sources(git2internal PRIVATE ${SRC_GIT2})
+# qsort
-file(GLOB SRC_UTIL util/*.c util/*.h util/allocators/*.c util/allocators/*.h)
-list(SORT SRC_UTIL)
-target_sources(git2internal PRIVATE ${SRC_UTIL})
+check_prototype_definition(qsort_r
+ "void qsort_r(void *base, size_t nmemb, size_t size, void *thunk, int (*compar)(void *, const void *, const void *))"
+ "" "stdlib.h" GIT_QSORT_R_BSD)
-if(APPLE)
- # The old Secure Transport API has been deprecated in macOS 10.15.
- set_source_files_properties(libgit2/streams/stransport.c PROPERTIES COMPILE_FLAGS -Wno-deprecated)
-endif()
+check_prototype_definition(qsort_r
+ "void qsort_r(void *base, size_t nmemb, size_t size, int (*compar)(const void *, const void *, void *), void *arg)"
+ "" "stdlib.h" GIT_QSORT_R_GNU)
-# the xdiff dependency is not (yet) warning-free, disable warnings as
-# errors for the xdiff sources until we've sorted them out
-if(MSVC)
- set_source_files_properties(libgit2/xdiff/xdiffi.c PROPERTIES COMPILE_FLAGS -WX-)
- set_source_files_properties(libgit2/xdiff/xutils.c PROPERTIES COMPILE_FLAGS -WX-)
-endif()
+check_function_exists(qsort_s GIT_QSORT_S)
# Determine architecture of the machine
+
if(CMAKE_SIZEOF_VOID_P EQUAL 8)
set(GIT_ARCH_64 1)
elseif(CMAKE_SIZEOF_VOID_P EQUAL 4)
@@ -368,81 +104,54 @@ else()
message(FATAL_ERROR "Unsupported architecture (CMAKE_SIZEOF_VOID_P is unset)")
endif()
-configure_file(libgit2/features.h.in git2/sys/features.h)
-
-ide_split_sources(git2internal)
-list(APPEND LIBGIT2_OBJECTS $<TARGET_OBJECTS:git2internal>)
+# High-resolution stat support
-target_include_directories(git2internal PRIVATE ${LIBGIT2_INCLUDES} PUBLIC ${libgit2_SOURCE_DIR}/include)
-target_include_directories(git2internal SYSTEM PRIVATE ${LIBGIT2_SYSTEM_INCLUDES})
+if(HAVE_STRUCT_STAT_ST_MTIM)
+ set(GIT_USE_STAT_MTIM 1)
+elseif(HAVE_STRUCT_STAT_ST_MTIMESPEC)
+ set(GIT_USE_STAT_MTIMESPEC 1)
+elseif(HAVE_STRUCT_STAT_ST_MTIME_NSEC)
+ set(GIT_USE_STAT_MTIME_NSEC 1)
+endif()
-set(LIBGIT2_OBJECTS ${LIBGIT2_OBJECTS} PARENT_SCOPE)
-set(LIBGIT2_INCLUDES ${LIBGIT2_INCLUDES} PARENT_SCOPE)
-set(LIBGIT2_SYSTEM_INCLUDES ${LIBGIT2_SYSTEM_INCLUDES} PARENT_SCOPE)
-set(LIBGIT2_SYSTEM_LIBS ${LIBGIT2_SYSTEM_LIBS} PARENT_SCOPE)
+# realtime support
-if(XCODE_VERSION)
- # This is required for Xcode to actually link the libgit2 library
- # when using only object libraries.
- file(WRITE ${CMAKE_CURRENT_BINARY_DIR}/dummy.c "")
- list(APPEND LIBGIT2_OBJECTS ${CMAKE_CURRENT_BINARY_DIR}/dummy.c)
+check_library_exists(rt clock_gettime "time.h" NEED_LIBRT)
+if(NEED_LIBRT)
+ list(APPEND LIBGIT2_SYSTEM_LIBS rt)
+ list(APPEND LIBGIT2_PC_LIBS "-lrt")
endif()
-# Compile and link libgit2
-add_library(git2 ${WIN_RC} ${LIBGIT2_OBJECTS})
-target_link_libraries(git2 ${LIBGIT2_SYSTEM_LIBS})
-
-set_target_properties(git2 PROPERTIES C_STANDARD 90)
-set_target_properties(git2 PROPERTIES LIBRARY_OUTPUT_DIRECTORY ${libgit2_BINARY_DIR})
-set_target_properties(git2 PROPERTIES RUNTIME_OUTPUT_DIRECTORY ${libgit2_BINARY_DIR})
-set_target_properties(git2 PROPERTIES ARCHIVE_OUTPUT_DIRECTORY ${libgit2_BINARY_DIR})
+# platform libraries
-# Workaround for Cmake bug #0011240 (see http://public.kitware.com/Bug/view.php?id=11240)
-# Win64+MSVC+static libs = linker error
-if(MSVC AND GIT_ARCH_64 AND NOT BUILD_SHARED_LIBS)
- set_target_properties(git2 PROPERTIES STATIC_LIBRARY_FLAGS "/MACHINE:x64")
+if(WIN32)
+ list(APPEND LIBGIT2_SYSTEM_LIBS ws2_32)
endif()
-ide_split_sources(git2)
-
-if(SONAME)
- set_target_properties(git2 PROPERTIES VERSION ${libgit2_VERSION})
- set_target_properties(git2 PROPERTIES SOVERSION "${libgit2_VERSION_MAJOR}.${libgit2_VERSION_MINOR}")
- if(LIBGIT2_FILENAME)
- target_compile_definitions(git2 PRIVATE LIBGIT2_FILENAME=\"${LIBGIT2_FILENAME}\")
- set_target_properties(git2 PROPERTIES OUTPUT_NAME ${LIBGIT2_FILENAME})
- elseif(DEFINED LIBGIT2_PREFIX)
- set_target_properties(git2 PROPERTIES PREFIX "${LIBGIT2_PREFIX}")
- endif()
+if(CMAKE_SYSTEM_NAME MATCHES "(Solaris|SunOS)")
+ list(APPEND LIBGIT2_SYSTEM_LIBS socket nsl)
+ list(APPEND LIBGIT2_PC_LIBS "-lsocket" "-lnsl")
endif()
-pkg_build_config(NAME libgit2
- VERSION ${libgit2_VERSION}
- DESCRIPTION "The git library, take 2"
- LIBS_SELF git2
- PRIVATE_LIBS ${LIBGIT2_PC_LIBS}
- REQUIRES ${LIBGIT2_PC_REQUIRES}
-)
-
-if(MSVC_IDE)
- # Precompiled headers
- set_target_properties(git2 PROPERTIES COMPILE_FLAGS "/Yuprecompiled.h /FIprecompiled.h")
- set_source_files_properties(libgit2/win32/precompiled.c COMPILE_FLAGS "/Ycprecompiled.h")
+if(CMAKE_SYSTEM_NAME MATCHES "Haiku")
+ list(APPEND LIBGIT2_SYSTEM_LIBS network)
+ list(APPEND LIBGIT2_PC_LIBS "-lnetwork")
endif()
-# Install
-install(TARGETS git2
- RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}
- LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
- ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}
-)
-install(DIRECTORY ${libgit2_SOURCE_DIR}/include/git2 DESTINATION ${CMAKE_INSTALL_INCLUDEDIR})
-install(FILES ${libgit2_SOURCE_DIR}/include/git2.h DESTINATION ${CMAKE_INSTALL_INCLUDEDIR})
-
-# export these variables for the test framework; it links our object
-# files directly (instead of linking to libgit2.so) so that it can
-# test private and internal functions.
-set_property(GLOBAL PROPERTY libgit2_objects ${LIBGIT2_OBJECTS})
-set_property(GLOBAL PROPERTY libgit2_includes ${LIBGIT2_INCLUDES})
+#
+# Configuration summary
+#
+
+configure_file(libgit2/features.h.in git2/sys/features.h)
+
+#
+# Exports for peer projects (tests)
+#
+
+set_property(GLOBAL PROPERTY libgit2_dependency_includes ${LIBGIT2_DEPENDENCY_INCLUDES})
+set_property(GLOBAL PROPERTY libgit2_dependency_objects ${LIBGIT2_DEPENDENCY_OBJECTS})
set_property(GLOBAL PROPERTY libgit2_system_includes ${LIBGIT2_SYSTEM_INCLUDES})
set_property(GLOBAL PROPERTY libgit2_system_libs ${LIBGIT2_SYSTEM_LIBS})
+
+add_subdirectory(libgit2)
+add_subdirectory(util)
diff --git a/src/libgit2/CMakeLists.txt b/src/libgit2/CMakeLists.txt
new file mode 100644
index 000000000..594feb69f
--- /dev/null
+++ b/src/libgit2/CMakeLists.txt
@@ -0,0 +1,103 @@
+# libgit2: the git library
+
+#
+# An object library so that our tests can link to the objects directly and
+# test internal state, instead of linking with libgit2.so and testing only
+# the public interfaces.
+#
+
+add_library(libgit2 OBJECT)
+set_target_properties(libgit2 PROPERTIES C_STANDARD 90)
+
+set(LIBGIT2_INCLUDES
+ "${CMAKE_BINARY_DIR}/src"
+ "${libgit2_SOURCE_DIR}/src/libgit2"
+ "${libgit2_SOURCE_DIR}/src/util"
+ "${libgit2_SOURCE_DIR}/include")
+
+file(GLOB LIBGIT2_SRC *.c *.h
+ streams/*.c streams/*.h
+ transports/*.c transports/*.h
+ xdiff/*.c xdiff/*.h)
+list(SORT LIBGIT2_SRC)
+
+#
+# Platform specific options
+#
+
+target_compile_definitions(libgit2 PRIVATE _FILE_OFFSET_BITS=64)
+
+if(AMIGA)
+ target_compile_definitions(libgit2 PRIVATE NO_ADDRINFO NO_READDIR_R NO_MMAP)
+endif()
+
+if(MSVC)
+ # the xdiff dependency is not (yet) warning-free, disable warnings as
+ # errors for the xdiff sources until we've sorted them out
+ set_source_files_properties(xdiff/xdiffi.c PROPERTIES COMPILE_FLAGS -WX-)
+ set_source_files_properties(xdiff/xutils.c PROPERTIES COMPILE_FLAGS -WX-)
+endif()
+
+if(MSVC_IDE)
+ # precompiled headers
+ set_target_properties(git2 PROPERTIES COMPILE_FLAGS "/Yuprecompiled.h /FIprecompiled.h")
+ set_source_files_properties(libgit2/win32/precompiled.c COMPILE_FLAGS "/Ycprecompiled.h")
+endif()
+
+if(APPLE)
+ # the old Secure Transport API has been deprecated in macOS 10.15.
+ set_source_files_properties(streams/stransport.c PROPERTIES COMPILE_FLAGS -Wno-deprecated)
+endif()
+
+#
+# Preprocessor definitions
+#
+
+if(DEPRECATE_HARD)
+ target_compile_definitions(libgit2 PRIVATE GIT_DEPRECATE_HARD)
+endif()
+
+if(USE_LEAK_CHECKER STREQUAL "valgrind")
+ target_compile_definitions(util PRIVATE VALGRIND)
+endif()
+
+target_sources(libgit2 PRIVATE ${LIBGIT2_SRC})
+
+target_include_directories(libgit2 PRIVATE ${LIBGIT2_INCLUDES} ${LIBGIT2_DEPENDENCY_INCLUDES} PUBLIC ${libgit2_SOURCE_DIR}/include)
+target_include_directories(libgit2 SYSTEM PRIVATE ${LIBGIT2_SYSTEM_INCLUDES})
+
+#
+# The actual libgit2 public consumable (libgit2.so/git2.dll)
+#
+
+add_library(libgit2public $<TARGET_OBJECTS:libgit2> $<TARGET_OBJECTS:util> ${LIBGIT2_DEPENDENCY_OBJECTS})
+target_link_libraries(libgit2public ${LIBGIT2_SYSTEM_LIBS})
+
+set_target_properties(libgit2public PROPERTIES OUTPUT_NAME ${LIBGIT2_FILENAME})
+
+set_target_properties(libgit2public PROPERTIES LIBRARY_OUTPUT_DIRECTORY ${libgit2_BINARY_DIR})
+set_target_properties(libgit2public PROPERTIES RUNTIME_OUTPUT_DIRECTORY ${libgit2_BINARY_DIR})
+set_target_properties(libgit2public PROPERTIES ARCHIVE_OUTPUT_DIRECTORY ${libgit2_BINARY_DIR})
+
+if(SONAME)
+ set_target_properties(libgit2public PROPERTIES VERSION ${libgit2_VERSION})
+ set_target_properties(libgit2public PROPERTIES SOVERSION "${libgit2_VERSION_MAJOR}.${libgit2_VERSION_MINOR}")
+endif()
+
+pkg_build_config(NAME libgit2
+ VERSION ${libgit2_VERSION}
+ DESCRIPTION "A cross-platform linkable library implementation of Git"
+ LIBS_SELF ${LIBGIT2_FILENAME}
+ PRIVATE_LIBS ${LIBGIT2_PC_LIBS}
+ REQUIRES ${LIBGIT2_PC_REQUIRES})
+
+#
+# Installation
+#
+
+install(TARGETS libgit2public
+ RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}
+ LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
+ ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR})
+install(DIRECTORY ${libgit2_SOURCE_DIR}/include/git2 DESTINATION ${CMAKE_INSTALL_INCLUDEDIR})
+install(FILES ${libgit2_SOURCE_DIR}/include/git2.h DESTINATION ${CMAKE_INSTALL_INCLUDEDIR})
diff --git a/src/libgit2/common.h b/src/libgit2/common.h
index 640f94806..fb55f20c1 100644
--- a/src/libgit2/common.h
+++ b/src/libgit2/common.h
@@ -7,133 +7,17 @@
#ifndef INCLUDE_common_h__
#define INCLUDE_common_h__
-#ifndef LIBGIT2_NO_FEATURES_H
-# include "git2/sys/features.h"
-#endif
-
-#include "git2/common.h"
-#include "cc-compat.h"
-
-/** Declare a function as always inlined. */
-#if defined(_MSC_VER)
-# define GIT_INLINE(type) static __inline type
-#elif defined(__GNUC__)
-# define GIT_INLINE(type) static __inline__ type
-#elif defined(__STDC_VERSION__) && (__STDC_VERSION__ >= 199901L)
-# define GIT_INLINE(type) static inline type
-#else
-# define GIT_INLINE(type) static type
-#endif
-
-/** Support for gcc/clang __has_builtin intrinsic */
-#ifndef __has_builtin
-# define __has_builtin(x) 0
-#endif
-
-/**
- * Declare that a function's return value must be used.
- *
- * Used mostly to guard against potential silent bugs at runtime. This is
- * recommended to be added to functions that:
- *
- * - Allocate / reallocate memory. This prevents memory leaks or errors where
- * buffers are expected to have grown to a certain size, but could not be
- * resized.
- * - Acquire locks. When a lock cannot be acquired, that will almost certainly
- * cause a data race / undefined behavior.
- */
-#if defined(__GNUC__)
-# define GIT_WARN_UNUSED_RESULT __attribute__((warn_unused_result))
-#else
-# define GIT_WARN_UNUSED_RESULT
-#endif
-
-#include <assert.h>
-#include <errno.h>
-#include <limits.h>
-#include <stdlib.h>
-#include <stdio.h>
-#include <string.h>
-
-#include <sys/types.h>
-#include <sys/stat.h>
-
-#ifdef GIT_WIN32
-
-# include <io.h>
-# include <direct.h>
-# include <winsock2.h>
-# include <windows.h>
-# include <ws2tcpip.h>
-# include "win32/msvc-compat.h"
-# include "win32/mingw-compat.h"
-# include "win32/w32_common.h"
-# include "win32/win32-compat.h"
-# include "win32/error.h"
-# include "win32/version.h"
-# ifdef GIT_THREADS
-# include "win32/thread.h"
-# endif
-
-#else
-
-# include <unistd.h>
-# include <strings.h>
-# ifdef GIT_THREADS
-# include <pthread.h>
-# include <sched.h>
-# endif
-
-#define GIT_LIBGIT2_CALL
-#define GIT_SYSTEM_CALL
-
-#ifdef GIT_USE_STAT_ATIMESPEC
-# define st_atim st_atimespec
-# define st_ctim st_ctimespec
-# define st_mtim st_mtimespec
-#endif
-
-# include <arpa/inet.h>
-
-#endif
-
-#include "git2/types.h"
-#include "git2/errors.h"
+#include "git2_util.h"
#include "errors.h"
-#include "thread.h"
-#include "integer.h"
-#include "assert_safe.h"
-#include "utf8.h"
/*
- * Include the declarations for deprecated functions; this ensures
- * that they're decorated with the proper extern/visibility attributes.
- */
+* Include the declarations for deprecated functions; this ensures
+* that they're decorated with the proper extern/visibility attributes.
+*/
#include "git2/deprecated.h"
#include "posix.h"
-#define DEFAULT_BUFSIZE 65536
-#define FILEIO_BUFSIZE DEFAULT_BUFSIZE
-#define FILTERIO_BUFSIZE DEFAULT_BUFSIZE
-#define NETIO_BUFSIZE DEFAULT_BUFSIZE
-
-/**
- * Check a pointer allocation result, returning -1 if it failed.
- */
-#define GIT_ERROR_CHECK_ALLOC(ptr) if (ptr == NULL) { return -1; }
-
-/**
- * Check a string buffer allocation result, returning -1 if it failed.
- */
-#define GIT_ERROR_CHECK_ALLOC_STR(buf) if ((void *)(buf) == NULL || git_str_oom(buf)) { return -1; }
-
-/**
- * Check a return value and propagate result if non-zero.
- */
-#define GIT_ERROR_CHECK_ERROR(code) \
- do { int _err = (code); if (_err) return _err; } while (0)
-
/**
* Check a versioned structure for validity
*/
@@ -153,58 +37,4 @@ GIT_INLINE(int) git_error__check_version(const void *structure, unsigned int exp
}
#define GIT_ERROR_CHECK_VERSION(S,V,N) if (git_error__check_version(S,V,N) < 0) return -1
-/**
- * Initialize a structure with a version.
- */
-GIT_INLINE(void) git__init_structure(void *structure, size_t len, unsigned int version)
-{
- memset(structure, 0, len);
- *((int*)structure) = version;
-}
-#define GIT_INIT_STRUCTURE(S,V) git__init_structure(S, sizeof(*S), V)
-
-#define GIT_INIT_STRUCTURE_FROM_TEMPLATE(PTR,VERSION,TYPE,TPL) do { \
- TYPE _tmpl = TPL; \
- GIT_ERROR_CHECK_VERSION(&(VERSION), _tmpl.version, #TYPE); \
- memcpy((PTR), &_tmpl, sizeof(_tmpl)); } while (0)
-
-
-/** Check for additive overflow, setting an error if would occur. */
-#define GIT_ADD_SIZET_OVERFLOW(out, one, two) \
- (git__add_sizet_overflow(out, one, two) ? (git_error_set_oom(), 1) : 0)
-
-/** Check for additive overflow, setting an error if would occur. */
-#define GIT_MULTIPLY_SIZET_OVERFLOW(out, nelem, elsize) \
- (git__multiply_sizet_overflow(out, nelem, elsize) ? (git_error_set_oom(), 1) : 0)
-
-/** Check for additive overflow, failing if it would occur. */
-#define GIT_ERROR_CHECK_ALLOC_ADD(out, one, two) \
- if (GIT_ADD_SIZET_OVERFLOW(out, one, two)) { return -1; }
-
-#define GIT_ERROR_CHECK_ALLOC_ADD3(out, one, two, three) \
- if (GIT_ADD_SIZET_OVERFLOW(out, one, two) || \
- GIT_ADD_SIZET_OVERFLOW(out, *(out), three)) { return -1; }
-
-#define GIT_ERROR_CHECK_ALLOC_ADD4(out, one, two, three, four) \
- if (GIT_ADD_SIZET_OVERFLOW(out, one, two) || \
- GIT_ADD_SIZET_OVERFLOW(out, *(out), three) || \
- GIT_ADD_SIZET_OVERFLOW(out, *(out), four)) { return -1; }
-
-#define GIT_ERROR_CHECK_ALLOC_ADD5(out, one, two, three, four, five) \
- if (GIT_ADD_SIZET_OVERFLOW(out, one, two) || \
- GIT_ADD_SIZET_OVERFLOW(out, *(out), three) || \
- GIT_ADD_SIZET_OVERFLOW(out, *(out), four) || \
- GIT_ADD_SIZET_OVERFLOW(out, *(out), five)) { return -1; }
-
-/** Check for multiplicative overflow, failing if it would occur. */
-#define GIT_ERROR_CHECK_ALLOC_MULTIPLY(out, nelem, elsize) \
- if (GIT_MULTIPLY_SIZET_OVERFLOW(out, nelem, elsize)) { return -1; }
-
-/* NOTE: other git_error functions are in the public errors.h header file */
-
-/* Forward declare git_str */
-typedef struct git_str git_str;
-
-#include "util.h"
-
#endif
diff --git a/src/libgit2/diff_xdiff.c b/src/libgit2/diff_xdiff.c
index 278e2be36..77c181e32 100644
--- a/src/libgit2/diff_xdiff.c
+++ b/src/libgit2/diff_xdiff.c
@@ -11,6 +11,7 @@
#include "diff.h"
#include "diff_driver.h"
#include "patch_generate.h"
+#include "utf8.h"
static int git_xdiff_scan_int(const char **str, int *value)
{
diff --git a/src/libgit2/netops.c b/src/libgit2/netops.c
index 0a27365b8..00640c600 100644
--- a/src/libgit2/netops.c
+++ b/src/libgit2/netops.c
@@ -12,7 +12,6 @@
#include "posix.h"
#include "str.h"
-#include "http_parser.h"
#include "runtime.h"
int gitno_recv(gitno_buffer *buf)
diff --git a/src/libgit2/path.c b/src/libgit2/path.c
index 05a3dc2cf..a19340efe 100644
--- a/src/libgit2/path.c
+++ b/src/libgit2/path.c
@@ -9,6 +9,7 @@
#include "repository.h"
#include "fs_path.h"
+#include "utf8.h"
typedef struct {
git_repository *repo;
diff --git a/src/util/win32/git2.rc b/src/libgit2/win32/git2.rc
index d273afd70..d273afd70 100644
--- a/src/util/win32/git2.rc
+++ b/src/libgit2/win32/git2.rc
diff --git a/src/util/CMakeLists.txt b/src/util/CMakeLists.txt
new file mode 100644
index 000000000..23ec0131b
--- /dev/null
+++ b/src/util/CMakeLists.txt
@@ -0,0 +1,70 @@
+# util: a shared library for common utility functions for libgit2 projects
+
+add_library(util OBJECT)
+set_target_properties(util PROPERTIES C_STANDARD 90)
+
+set(UTIL_INCLUDES
+ "${CMAKE_BINARY_DIR}/src"
+ "${libgit2_SOURCE_DIR}/src/util"
+ "${libgit2_SOURCE_DIR}/include")
+
+file(GLOB UTIL_SRC *.c *.h allocators/*.c allocators/*.h)
+list(SORT UTIL_SRC)
+
+#
+# Platform specific sources
+#
+
+if(WIN32 AND NOT CYGWIN)
+ file(GLOB UTIL_SRC_OS win32/*.c win32/*.h)
+ list(SORT UTIL_SRC_OS)
+elseif(NOT AMIGA)
+ file(GLOB UTIL_SRC_OS unix/*.c unix/*.h)
+ list(SORT UTIL_SRC_OS)
+endif()
+
+target_compile_definitions(util PRIVATE _FILE_OFFSET_BITS=64)
+
+if(AMIGA)
+ target_compile_definitions(util PRIVATE NO_ADDRINFO NO_READDIR_R NO_MMAP)
+endif()
+
+#
+# Hash backend selection
+#
+
+if(USE_SHA1 STREQUAL "CollisionDetection")
+ file(GLOB UTIL_SRC_HASH hash/sha1/collisiondetect.* hash/sha1/sha1dc/*)
+elseif(USE_SHA1 STREQUAL "OpenSSL")
+ file(GLOB UTIL_SRC_HASH hash/sha1/openssl.*)
+elseif(USE_SHA1 STREQUAL "CommonCrypto")
+ file(GLOB UTIL_SRC_HASH hash/sha1/common_crypto.*)
+elseif(USE_SHA1 STREQUAL "mbedTLS")
+ file(GLOB UTIL_SRC_HASH hash/sha1/mbedtls.*)
+elseif(USE_SHA1 STREQUAL "Win32")
+ file(GLOB UTIL_SRC_HASH hash/sha1/win32.*)
+elseif(USE_SHA1 STREQUAL "Generic")
+ file(GLOB UTIL_SRC_HASH hash/sha1/generic.*)
+else()
+ message(FATAL_ERROR "Asked for unknown SHA1 backend: ${USE_SHA1}")
+endif()
+
+list(APPEND UTIL_SRC_HASH "hash/sha1.h")
+list(SORT UTIL_SRC_HASH)
+
+#
+# Preprocessor definitions
+#
+
+if(DEPRECATE_HARD)
+ target_compile_definitions(util PRIVATE GIT_DEPRECATE_HARD)
+endif()
+
+if(USE_LEAK_CHECKER STREQUAL "valgrind")
+ target_compile_definitions(util PRIVATE VALGRIND)
+endif()
+
+target_sources(util PRIVATE ${UTIL_SRC} ${UTIL_SRC_OS} ${UTIL_SRC_HASH})
+
+target_include_directories(util PRIVATE ${UTIL_INCLUDES} ${LIBGIT2_DEPENDENCY_INCLUDES} PUBLIC ${libgit2_SOURCE_DIR}/include)
+target_include_directories(util SYSTEM PRIVATE ${LIBGIT2_SYSTEM_INCLUDES})
diff --git a/src/util/allocators/failalloc.h b/src/util/allocators/failalloc.h
index 6115e51e7..91264a0bb 100644
--- a/src/util/allocators/failalloc.h
+++ b/src/util/allocators/failalloc.h
@@ -8,7 +8,7 @@
#ifndef INCLUDE_allocators_failalloc_h__
#define INCLUDE_allocators_failalloc_h__
-#include "common.h"
+#include "git2_util.h"
extern void *git_failalloc_malloc(size_t len, const char *file, int line);
extern void *git_failalloc_calloc(size_t nelem, size_t elsize, const char *file, int line);
diff --git a/src/util/allocators/stdalloc.h b/src/util/allocators/stdalloc.h
index fa23fe6e3..955038cb0 100644
--- a/src/util/allocators/stdalloc.h
+++ b/src/util/allocators/stdalloc.h
@@ -8,7 +8,7 @@
#ifndef INCLUDE_allocators_stdalloc_h__
#define INCLUDE_allocators_stdalloc_h__
-#include "common.h"
+#include "git2_util.h"
#include "alloc.h"
diff --git a/src/util/allocators/win32_leakcheck.h b/src/util/allocators/win32_leakcheck.h
index 089690f90..edcd9307f 100644
--- a/src/util/allocators/win32_leakcheck.h
+++ b/src/util/allocators/win32_leakcheck.h
@@ -8,7 +8,7 @@
#ifndef INCLUDE_allocators_win32_leakcheck_h
#define INCLUDE_allocators_win32_leakcheck_h
-#include "common.h"
+#include "git2_util.h"
#include "alloc.h"
diff --git a/src/util/array.h b/src/util/array.h
index e97688b36..cbab52ad1 100644
--- a/src/util/array.h
+++ b/src/util/array.h
@@ -7,7 +7,7 @@
#ifndef INCLUDE_array_h__
#define INCLUDE_array_h__
-#include "common.h"
+#include "git2_util.h"
/*
* Use this to declare a typesafe resizable array of items, a la:
diff --git a/src/util/fs_path.c b/src/util/fs_path.c
index 957f389cc..004745398 100644
--- a/src/util/fs_path.c
+++ b/src/util/fs_path.c
@@ -7,8 +7,9 @@
#include "fs_path.h"
+#include "git2_util.h"
+#include "futils.h"
#include "posix.h"
-#include "repository.h"
#ifdef GIT_WIN32
#include "win32/posix.h"
#include "win32/w32_buffer.h"
@@ -21,6 +22,13 @@
#include <stdio.h>
#include <ctype.h>
+#define ensure_error_set(code) do { \
+ const git_error *e = git_error_last(); \
+ if (!e || !e->message) \
+ git_error_set(e ? e->klass : GIT_ERROR_CALLBACK, \
+ "filesystem callback returned %d", code); \
+ } while(0)
+
static int dos_drive_prefix_length(const char *path)
{
int i;
@@ -530,7 +538,7 @@ int git_fs_path_walk_up(
if (!scan) {
error = cb(data, "");
if (error)
- git_error_set_after_callback(error);
+ ensure_error_set(error);
return error;
}
@@ -543,7 +551,7 @@ int git_fs_path_walk_up(
iter.ptr[scan] = oldc;
if (error) {
- git_error_set_after_callback(error);
+ ensure_error_set(error);
break;
}
@@ -563,7 +571,7 @@ int git_fs_path_walk_up(
if (!error && stop == 0 && iter.ptr[0] != '/') {
error = cb(data, "");
if (error)
- git_error_set_after_callback(error);
+ ensure_error_set(error);
}
return error;
@@ -1164,7 +1172,7 @@ int git_fs_path_direach(
/* Only set our own error if the callback did not set one already */
if (error != 0) {
if (!git_error_last())
- git_error_set_after_callback(error);
+ ensure_error_set(error);
break;
}
diff --git a/src/util/fs_path.h b/src/util/fs_path.h
index 188dcf303..db869f34c 100644
--- a/src/util/fs_path.h
+++ b/src/util/fs_path.h
@@ -7,7 +7,7 @@
#ifndef INCLUDE_fs_path_h__
#define INCLUDE_fs_path_h__
-#include "common.h"
+#include "git2_util.h"
#include "posix.h"
#include "str.h"
diff --git a/src/util/futils.h b/src/util/futils.h
index 22098addf..ff5ea27a2 100644
--- a/src/util/futils.h
+++ b/src/util/futils.h
@@ -7,7 +7,7 @@
#ifndef INCLUDE_futils_h__
#define INCLUDE_futils_h__
-#include "common.h"
+#include "git2_util.h"
#include "map.h"
#include "posix.h"
diff --git a/src/util/git2_util.h b/src/util/git2_util.h
new file mode 100644
index 000000000..74da18544
--- /dev/null
+++ b/src/util/git2_util.h
@@ -0,0 +1,182 @@
+/*
+ * Copyright (C) the libgit2 contributors. All rights reserved.
+ *
+ * This file is part of libgit2, distributed under the GNU GPL v2 with
+ * a Linking Exception. For full terms see the included COPYING file.
+ */
+#ifndef INCLUDE_git2_util_h__
+#define INCLUDE_git2_util_h__
+
+#ifndef LIBGIT2_NO_FEATURES_H
+# include "git2/sys/features.h"
+#endif
+
+#include "git2/common.h"
+#include "cc-compat.h"
+
+typedef struct git_str git_str;
+
+/** Declare a function as always inlined. */
+#if defined(_MSC_VER)
+# define GIT_INLINE(type) static __inline type
+#elif defined(__GNUC__)
+# define GIT_INLINE(type) static __inline__ type
+#else
+# define GIT_INLINE(type) static type
+#endif
+
+/** Support for gcc/clang __has_builtin intrinsic */
+#ifndef __has_builtin
+# define __has_builtin(x) 0
+#endif
+
+/**
+ * Declare that a function's return value must be used.
+ *
+ * Used mostly to guard against potential silent bugs at runtime. This is
+ * recommended to be added to functions that:
+ *
+ * - Allocate / reallocate memory. This prevents memory leaks or errors where
+ * buffers are expected to have grown to a certain size, but could not be
+ * resized.
+ * - Acquire locks. When a lock cannot be acquired, that will almost certainly
+ * cause a data race / undefined behavior.
+ */
+#if defined(__GNUC__)
+# define GIT_WARN_UNUSED_RESULT __attribute__((warn_unused_result))
+#else
+# define GIT_WARN_UNUSED_RESULT
+#endif
+
+#include <assert.h>
+#include <errno.h>
+#include <limits.h>
+#include <stdlib.h>
+#include <stdio.h>
+#include <string.h>
+
+#include <sys/types.h>
+#include <sys/stat.h>
+
+#ifdef GIT_WIN32
+
+# include <io.h>
+# include <direct.h>
+# include <winsock2.h>
+# include <windows.h>
+# include <ws2tcpip.h>
+# include "win32/msvc-compat.h"
+# include "win32/mingw-compat.h"
+# include "win32/win32-compat.h"
+# include "win32/w32_common.h"
+# include "win32/version.h"
+# include "win32/error.h"
+# ifdef GIT_THREADS
+# include "win32/thread.h"
+# endif
+
+#else
+
+# include <unistd.h>
+# include <strings.h>
+# ifdef GIT_THREADS
+# include <pthread.h>
+# include <sched.h>
+# endif
+
+#define GIT_LIBGIT2_CALL
+#define GIT_SYSTEM_CALL
+
+#ifdef GIT_USE_STAT_ATIMESPEC
+# define st_atim st_atimespec
+# define st_ctim st_ctimespec
+# define st_mtim st_mtimespec
+#endif
+
+# include <arpa/inet.h>
+
+#endif
+
+#include "git2/types.h"
+#include "git2/errors.h"
+#include "thread.h"
+#include "integer.h"
+#include "assert_safe.h"
+
+#include "posix.h"
+
+#define DEFAULT_BUFSIZE 65536
+#define FILEIO_BUFSIZE DEFAULT_BUFSIZE
+#define FILTERIO_BUFSIZE DEFAULT_BUFSIZE
+#define NETIO_BUFSIZE DEFAULT_BUFSIZE
+
+/**
+ * Check a pointer allocation result, returning -1 if it failed.
+ */
+#define GIT_ERROR_CHECK_ALLOC(ptr) if (ptr == NULL) { return -1; }
+
+/**
+ * Check a buffer allocation result, returning -1 if it failed.
+ */
+#define GIT_ERROR_CHECK_ALLOC_STR(buf) if ((void *)(buf) == NULL || git_str_oom(buf)) { return -1; }
+
+/**
+ * Check a return value and propagate result if non-zero.
+ */
+#define GIT_ERROR_CHECK_ERROR(code) \
+ do { int _err = (code); if (_err) return _err; } while (0)
+
+/**
+ * Initialize a structure with a version.
+ */
+GIT_INLINE(void) git__init_structure(void *structure, size_t len, unsigned int version)
+{
+ memset(structure, 0, len);
+ *((int*)structure) = version;
+}
+#define GIT_INIT_STRUCTURE(S,V) git__init_structure(S, sizeof(*S), V)
+
+#define GIT_INIT_STRUCTURE_FROM_TEMPLATE(PTR,VERSION,TYPE,TPL) do { \
+ TYPE _tmpl = TPL; \
+ GIT_ERROR_CHECK_VERSION(&(VERSION), _tmpl.version, #TYPE); \
+ memcpy((PTR), &_tmpl, sizeof(_tmpl)); } while (0)
+
+
+/** Check for additive overflow, setting an error if would occur. */
+#define GIT_ADD_SIZET_OVERFLOW(out, one, two) \
+ (git__add_sizet_overflow(out, one, two) ? (git_error_set_oom(), 1) : 0)
+
+/** Check for additive overflow, setting an error if would occur. */
+#define GIT_MULTIPLY_SIZET_OVERFLOW(out, nelem, elsize) \
+ (git__multiply_sizet_overflow(out, nelem, elsize) ? (git_error_set_oom(), 1) : 0)
+
+/** Check for additive overflow, failing if it would occur. */
+#define GIT_ERROR_CHECK_ALLOC_ADD(out, one, two) \
+ if (GIT_ADD_SIZET_OVERFLOW(out, one, two)) { return -1; }
+
+#define GIT_ERROR_CHECK_ALLOC_ADD3(out, one, two, three) \
+ if (GIT_ADD_SIZET_OVERFLOW(out, one, two) || \
+ GIT_ADD_SIZET_OVERFLOW(out, *(out), three)) { return -1; }
+
+#define GIT_ERROR_CHECK_ALLOC_ADD4(out, one, two, three, four) \
+ if (GIT_ADD_SIZET_OVERFLOW(out, one, two) || \
+ GIT_ADD_SIZET_OVERFLOW(out, *(out), three) || \
+ GIT_ADD_SIZET_OVERFLOW(out, *(out), four)) { return -1; }
+
+#define GIT_ERROR_CHECK_ALLOC_ADD5(out, one, two, three, four, five) \
+ if (GIT_ADD_SIZET_OVERFLOW(out, one, two) || \
+ GIT_ADD_SIZET_OVERFLOW(out, *(out), three) || \
+ GIT_ADD_SIZET_OVERFLOW(out, *(out), four) || \
+ GIT_ADD_SIZET_OVERFLOW(out, *(out), five)) { return -1; }
+
+/** Check for multiplicative overflow, failing if it would occur. */
+#define GIT_ERROR_CHECK_ALLOC_MULTIPLY(out, nelem, elsize) \
+ if (GIT_MULTIPLY_SIZET_OVERFLOW(out, nelem, elsize)) { return -1; }
+
+#include "util.h"
+
+// TODO TODO TODO
+extern void git_error_set(int, const char *, ...);
+extern const git_error * git_error_last(void);
+
+#endif
diff --git a/src/util/hash.h b/src/util/hash.h
index 10b14a904..a53a107c8 100644
--- a/src/util/hash.h
+++ b/src/util/hash.h
@@ -8,7 +8,7 @@
#ifndef INCLUDE_hash_h__
#define INCLUDE_hash_h__
-#include "common.h"
+#include "git2_util.h"
#include "git2/oid.h"
#include "hash/sha1.h"
diff --git a/src/util/hash/sha1.h b/src/util/hash/sha1.h
index 4b4dae3f8..9d32bce42 100644
--- a/src/util/hash/sha1.h
+++ b/src/util/hash/sha1.h
@@ -8,7 +8,7 @@
#ifndef INCLUDE_hash_sha1_h__
#define INCLUDE_hash_sha1_h__
-#include "common.h"
+#include "git2_util.h"
typedef struct git_hash_sha1_ctx git_hash_sha1_ctx;
diff --git a/src/util/map.h b/src/util/map.h
index 01931d199..c101e46f6 100644
--- a/src/util/map.h
+++ b/src/util/map.h
@@ -7,7 +7,7 @@
#ifndef INCLUDE_map_h__
#define INCLUDE_map_h__
-#include "common.h"
+#include "git2_util.h"
/* p_mmap() prot values */
diff --git a/src/util/net.c b/src/util/net.c
index 58792ee7d..752e07e5a 100644
--- a/src/util/net.c
+++ b/src/util/net.c
@@ -6,7 +6,6 @@
*/
#include "net.h"
-#include "netops.h"
#include <ctype.h>
#include "git2/errors.h"
diff --git a/src/util/net.h b/src/util/net.h
index 728add3d0..314780ec7 100644
--- a/src/util/net.h
+++ b/src/util/net.h
@@ -7,7 +7,7 @@
#ifndef INCLUDE_net_h__
#define INCLUDE_net_h__
-#include "common.h"
+#include "git2_util.h"
typedef struct git_net_url {
char *scheme;
diff --git a/src/util/pool.h b/src/util/pool.h
index cecb84665..0238431b0 100644
--- a/src/util/pool.h
+++ b/src/util/pool.h
@@ -7,7 +7,7 @@
#ifndef INCLUDE_pool_h__
#define INCLUDE_pool_h__
-#include "common.h"
+#include "git2_util.h"
#include "vector.h"
diff --git a/src/util/posix.h b/src/util/posix.h
index d98bc82ca..0223b4146 100644
--- a/src/util/posix.h
+++ b/src/util/posix.h
@@ -7,7 +7,7 @@
#ifndef INCLUDE_posix_h__
#define INCLUDE_posix_h__
-#include "common.h"
+#include "git2_util.h"
#include <fcntl.h>
#include <time.h>
diff --git a/src/util/regexp.h b/src/util/regexp.h
index 2592ef383..d0862b107 100644
--- a/src/util/regexp.h
+++ b/src/util/regexp.h
@@ -8,7 +8,7 @@
#ifndef INCLUDE_regexp_h__
#define INCLUDE_regexp_h__
-#include "common.h"
+#include "git2_util.h"
#if defined(GIT_REGEX_BUILTIN) || defined(GIT_REGEX_PCRE)
# include "pcre.h"
diff --git a/src/util/runtime.c b/src/util/runtime.c
index c05dee8b9..a7711ffc4 100644
--- a/src/util/runtime.c
+++ b/src/util/runtime.c
@@ -5,7 +5,7 @@
* a Linking Exception. For full terms see the included COPYING file.
*/
-#include "common.h"
+#include "git2_util.h"
#include "runtime.h"
static git_runtime_shutdown_fn shutdown_callback[32];
diff --git a/src/util/runtime.h b/src/util/runtime.h
index 24ac58ee9..6cbfd6043 100644
--- a/src/util/runtime.h
+++ b/src/util/runtime.h
@@ -7,7 +7,7 @@
#ifndef INCLUDE_runtime_h__
#define INCLUDE_runtime_h__
-#include "common.h"
+#include "git2_util.h"
typedef int (*git_runtime_init_fn)(void);
typedef void (*git_runtime_shutdown_fn)(void);
diff --git a/src/util/str.h b/src/util/str.h
index af7acc21f..15e9b3304 100644
--- a/src/util/str.h
+++ b/src/util/str.h
@@ -7,7 +7,7 @@
#ifndef INCLUDE_str_h__
#define INCLUDE_str_h__
-#include "common.h"
+#include "git2_util.h"
struct git_str {
char *ptr;
diff --git a/src/util/strmap.h b/src/util/strmap.h
index 9f5e4cc8b..b64d3dcb5 100644
--- a/src/util/strmap.h
+++ b/src/util/strmap.h
@@ -7,7 +7,7 @@
#ifndef INCLUDE_strmap_h__
#define INCLUDE_strmap_h__
-#include "common.h"
+#include "git2_util.h"
/** A map with C strings as key. */
typedef struct kh_str_s git_strmap;
diff --git a/src/libgit2/strnlen.h b/src/util/strnlen.h
index eecfe3c02..eecfe3c02 100644
--- a/src/libgit2/strnlen.h
+++ b/src/util/strnlen.h
diff --git a/src/util/thread.c b/src/util/thread.c
index 3171771d7..bc7364f8c 100644
--- a/src/util/thread.c
+++ b/src/util/thread.c
@@ -5,7 +5,7 @@
* a Linking Exception. For full terms see the included COPYING file.
*/
-#include "common.h"
+#include "git2_util.h"
#if !defined(GIT_THREADS)
diff --git a/src/util/tsort.c b/src/util/tsort.c
index 045efad23..2ef03d03a 100644
--- a/src/util/tsort.c
+++ b/src/util/tsort.c
@@ -5,7 +5,7 @@
* a Linking Exception. For full terms see the included COPYING file.
*/
-#include "common.h"
+#include "git2_util.h"
/**
* An array-of-pointers implementation of Python's Timsort
diff --git a/src/util/unix/map.c b/src/util/unix/map.c
index 88f283ce8..b45859b1b 100644
--- a/src/util/unix/map.c
+++ b/src/util/unix/map.c
@@ -5,7 +5,7 @@
* a Linking Exception. For full terms see the included COPYING file.
*/
-#include "common.h"
+#include "git2_util.h"
#include "git2/common.h"
diff --git a/src/util/unix/realpath.c b/src/util/unix/realpath.c
index 893bac87b..41321f604 100644
--- a/src/util/unix/realpath.c
+++ b/src/util/unix/realpath.c
@@ -5,7 +5,7 @@
* a Linking Exception. For full terms see the included COPYING file.
*/
-#include "common.h"
+#include "git2_util.h"
#include "git2/common.h"
diff --git a/src/util/utf8.c b/src/util/utf8.c
index 77065cb71..c566fdf20 100644
--- a/src/util/utf8.c
+++ b/src/util/utf8.c
@@ -7,7 +7,7 @@
#include "utf8.h"
-#include "common.h"
+#include "git2_util.h"
/*
* git_utf8_iterate is taken from the utf8proc project,
diff --git a/src/util/utf8.h b/src/util/utf8.h
index dff91b294..753ab07e2 100644
--- a/src/util/utf8.h
+++ b/src/util/utf8.h
@@ -7,7 +7,7 @@
#ifndef INCLUDE_utf8_h__
#define INCLUDE_utf8_h__
-#include "common.h"
+#include "git2_util.h"
/*
* Iterate through an UTF-8 string, yielding one codepoint at a time.
diff --git a/src/util/util.c b/src/util/util.c
index e06d4ca09..aee95fddf 100644
--- a/src/util/util.c
+++ b/src/util/util.c
@@ -7,7 +7,7 @@
#include "util.h"
-#include "common.h"
+#include "git2_util.h"
#ifdef GIT_WIN32
# include "win32/utf-conv.h"
diff --git a/src/util/util.h b/src/util/util.h
index 30cdd0ddf..933b92794 100644
--- a/src/util/util.h
+++ b/src/util/util.h
@@ -12,7 +12,7 @@
#endif
#include "str.h"
-#include "common.h"
+#include "git2_util.h"
#include "strnlen.h"
#include "thread.h"
diff --git a/src/util/varint.h b/src/util/varint.h
index 652e22486..79b8f5548 100644
--- a/src/util/varint.h
+++ b/src/util/varint.h
@@ -7,7 +7,7 @@
#ifndef INCLUDE_varint_h__
#define INCLUDE_varint_h__
-#include "common.h"
+#include "git2_util.h"
#include <stdint.h>
diff --git a/src/util/vector.h b/src/util/vector.h
index 3dcec3d13..0a62f9005 100644
--- a/src/util/vector.h
+++ b/src/util/vector.h
@@ -7,7 +7,7 @@
#ifndef INCLUDE_vector_h__
#define INCLUDE_vector_h__
-#include "common.h"
+#include "git2_util.h"
typedef int (*git_vector_cmp)(const void *, const void *);
diff --git a/src/util/win32/dir.h b/src/util/win32/dir.h
index acd64729e..810111534 100644
--- a/src/util/win32/dir.h
+++ b/src/util/win32/dir.h
@@ -7,7 +7,7 @@
#ifndef INCLUDE_win32_dir_h__
#define INCLUDE_win32_dir_h__
-#include "common.h"
+#include "git2_util.h"
#include "w32_util.h"
diff --git a/src/util/win32/error.h b/src/util/win32/error.h
index 9e81141ce..fd53b7f99 100644
--- a/src/util/win32/error.h
+++ b/src/util/win32/error.h
@@ -8,7 +8,7 @@
#ifndef INCLUDE_win32_error_h__
#define INCLUDE_win32_error_h__
-#include "common.h"
+#include "git2_util.h"
extern char *git_win32_get_error_message(DWORD error_code);
diff --git a/src/util/win32/findfile.h b/src/util/win32/findfile.h
index e11ccebc5..41590f898 100644
--- a/src/util/win32/findfile.h
+++ b/src/util/win32/findfile.h
@@ -8,7 +8,7 @@
#ifndef INCLUDE_win32_findfile_h__
#define INCLUDE_win32_findfile_h__
-#include "common.h"
+#include "git2_util.h"
extern int git_win32__find_system_dirs(git_str *out, const wchar_t *subpath);
extern int git_win32__find_global_dirs(git_str *out);
diff --git a/src/util/win32/map.c b/src/util/win32/map.c
index 2aabc9b15..52e1363ea 100644
--- a/src/util/win32/map.c
+++ b/src/util/win32/map.c
@@ -5,7 +5,7 @@
* a Linking Exception. For full terms see the included COPYING file.
*/
-#include "common.h"
+#include "git2_util.h"
#include "map.h"
#include <errno.h>
diff --git a/src/util/win32/path_w32.h b/src/util/win32/path_w32.h
index 4fadf8d08..3ec603851 100644
--- a/src/util/win32/path_w32.h
+++ b/src/util/win32/path_w32.h
@@ -7,7 +7,7 @@
#ifndef INCLUDE_win32_path_w32_h__
#define INCLUDE_win32_path_w32_h__
-#include "common.h"
+#include "git2_util.h"
/**
* Create a Win32 path (in UCS-2 format) from a UTF-8 string. If the given
diff --git a/src/util/win32/posix.h b/src/util/win32/posix.h
index 87c6b436a..6c1a0a32e 100644
--- a/src/util/win32/posix.h
+++ b/src/util/win32/posix.h
@@ -7,7 +7,7 @@
#ifndef INCLUDE_win32_posix_h__
#define INCLUDE_win32_posix_h__
-#include "common.h"
+#include "git2_util.h"
#include "../posix.h"
#include "win32-compat.h"
#include "path_w32.h"
diff --git a/src/util/win32/posix_w32.c b/src/util/win32/posix_w32.c
index ba46b5ea9..b387ac7fb 100644
--- a/src/util/win32/posix_w32.c
+++ b/src/util/win32/posix_w32.c
@@ -5,7 +5,7 @@
* a Linking Exception. For full terms see the included COPYING file.
*/
-#include "common.h"
+#include "git2_util.h"
#include "../posix.h"
#include "../futils.h"
diff --git a/src/util/win32/precompiled.h b/src/util/win32/precompiled.h
index 806b1698a..1163c3d63 100644
--- a/src/util/win32/precompiled.h
+++ b/src/util/win32/precompiled.h
@@ -1,4 +1,4 @@
-#include "common.h"
+#include "git2_util.h"
#include <errno.h>
#include <limits.h>
diff --git a/src/util/win32/thread.h b/src/util/win32/thread.h
index 8305036b4..184762e2a 100644
--- a/src/util/win32/thread.h
+++ b/src/util/win32/thread.h
@@ -8,7 +8,7 @@
#ifndef INCLUDE_win32_thread_h__
#define INCLUDE_win32_thread_h__
-#include "common.h"
+#include "git2_util.h"
#if defined (_MSC_VER)
# define GIT_RESTRICT __restrict
diff --git a/src/util/win32/utf-conv.h b/src/util/win32/utf-conv.h
index 6090a4b35..120d647ef 100644
--- a/src/util/win32/utf-conv.h
+++ b/src/util/win32/utf-conv.h
@@ -7,7 +7,7 @@
#ifndef INCLUDE_win32_utf_conv_h__
#define INCLUDE_win32_utf_conv_h__
-#include "common.h"
+#include "git2_util.h"
#include <wchar.h>
diff --git a/src/util/win32/w32_buffer.h b/src/util/win32/w32_buffer.h
index 4227296d8..68ea96035 100644
--- a/src/util/win32/w32_buffer.h
+++ b/src/util/win32/w32_buffer.h
@@ -7,7 +7,7 @@
#ifndef INCLUDE_win32_w32_buffer_h__
#define INCLUDE_win32_w32_buffer_h__
-#include "common.h"
+#include "git2_util.h"
#include "str.h"
/**
diff --git a/src/util/win32/w32_leakcheck.h b/src/util/win32/w32_leakcheck.h
index cb45e3675..82d863851 100644
--- a/src/util/win32/w32_leakcheck.h
+++ b/src/util/win32/w32_leakcheck.h
@@ -8,7 +8,7 @@
#ifndef INCLUDE_win32_leakcheck_h__
#define INCLUDE_win32_leakcheck_h__
-#include "common.h"
+#include "git2_util.h"
/* Initialize the win32 leak checking system. */
int git_win32_leakcheck_global_init(void);
diff --git a/src/util/win32/w32_util.h b/src/util/win32/w32_util.h
index 1321d30e6..519663720 100644
--- a/src/util/win32/w32_util.h
+++ b/src/util/win32/w32_util.h
@@ -8,7 +8,7 @@
#ifndef INCLUDE_win32_w32_util_h__
#define INCLUDE_win32_w32_util_h__
-#include "common.h"
+#include "git2_util.h"
#include "utf-conv.h"
#include "posix.h"
diff --git a/src/util/zstream.h b/src/util/zstream.h
index 3a59d9a36..0afe6ee17 100644
--- a/src/util/zstream.h
+++ b/src/util/zstream.h
@@ -7,7 +7,7 @@
#ifndef INCLUDE_zstream_h__
#define INCLUDE_zstream_h__
-#include "common.h"
+#include "git2_util.h"
#include <zlib.h>
diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt
index 5b9e3c198..6a2984a08 100644
--- a/tests/CMakeLists.txt
+++ b/tests/CMakeLists.txt
@@ -1,57 +1,77 @@
+# libgit2_tests
+
+add_executable(libgit2_tests)
+
+set(TEST_INCLUDES
+ "${CMAKE_BINARY_DIR}/src"
+ "${libgit2_SOURCE_DIR}/src/libgit2"
+ "${libgit2_SOURCE_DIR}/src/util"
+ "${libgit2_SOURCE_DIR}/include")
+
+file(GLOB_RECURSE TEST_SRC */*.c */*.h)
+
+#
+# Locate python so that we can generate the clar test data
+#
+
set(Python_ADDITIONAL_VERSIONS 3 2.7)
find_package(PythonInterp)
if(NOT PYTHONINTERP_FOUND)
message(FATAL_ERROR "Could not find a python interpeter, which is needed to build the tests. "
- "Make sure python is available, or pass -DBUILD_TESTS=OFF to skip building the tests")
-ENDIF()
+ "Make sure python is available, or pass -DBUILD_TESTS=OFF to skip building the tests.")
+endif()
-get_property(LIBGIT2_DEPENDENCY_OBJECTS GLOBAL PROPERTY libgit2_objects)
-get_property(LIBGIT2_DEPENDENCY_INCLUDES GLOBAL PROPERTY libgit2_includes)
+#
+# Load dependency information
+#
+
+get_property(LIBGIT2_DEPENDENCY_INCLUDES GLOBAL PROPERTY libgit2_dependency_includes)
+get_property(LIBGIT2_DEPENDENCY_OBJECTS GLOBAL PROPERTY libgit2_dependency_objects)
get_property(LIBGIT2_SYSTEM_INCLUDES GLOBAL PROPERTY libgit2_system_includes)
get_property(LIBGIT2_SYSTEM_LIBS GLOBAL PROPERTY libgit2_system_libs)
-set(CLAR_FIXTURES "${CMAKE_CURRENT_SOURCE_DIR}/resources/")
-set(CLAR_PATH "${CMAKE_CURRENT_SOURCE_DIR}")
-add_definitions(-DCLAR_FIXTURE_PATH=\"${CLAR_FIXTURES}\")
-add_definitions(-DCLAR_TMPDIR=\"libgit2_tests\")
-add_definitions(-DCLAR_WIN32_LONGPATHS)
-add_definitions(-D_FILE_OFFSET_BITS=64)
-
-# Ensure that we do not use deprecated functions internally
-add_definitions(-DGIT_DEPRECATE_HARD)
+#
+# Include clar
+#
-include_directories(${CLAR_PATH} ${libgit2_BINARY_DIR}/src)
-file(GLOB_RECURSE SRC_TEST ${CLAR_PATH}/*/*.c ${CLAR_PATH}/*/*.h)
-set(SRC_CLAR "main.c" "clar_libgit2.c" "clar_libgit2_trace.c" "clar_libgit2_timer.c" "clar.c")
+set(CLAR_PATH "${CMAKE_CURRENT_SOURCE_DIR}")
+set(CLAR_FIXTURES "${CLAR_PATH}/resources")
+set(CLAR_SUITE_PATH "${CMAKE_CURRENT_BINARY_DIR}")
-if(MSVC_IDE)
- list(APPEND SRC_CLAR "precompiled.c")
-endif()
+include_directories(${CLAR_PATH})
+set(TEST_SRC_CLAR "main.c" "clar.c" "clar_libgit2.c" "clar_libgit2_trace.c" "clar_libgit2_timer.c")
add_custom_command(
- OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/clar.suite ${CMAKE_CURRENT_BINARY_DIR}/clar_suite.h
- COMMAND ${PYTHON_EXECUTABLE} generate.py -o "${CMAKE_CURRENT_BINARY_DIR}" -f -xonline -xstress -xperf .
- DEPENDS ${SRC_TEST}
+ OUTPUT ${CLAR_SUITE_PATH}/clar.suite ${CLAR_SUITE_PATH}/clar_suite.h
+ COMMAND ${PYTHON_EXECUTABLE} generate.py -o "${CLAR_SUITE_PATH}" -f -xonline -xstress -xperf .
+ DEPENDS ${TEST_SRC}
WORKING_DIRECTORY ${CLAR_PATH}
)
-include_directories(${CMAKE_CURRENT_BINARY_DIR})
set_source_files_properties(
${CLAR_PATH}/clar.c
- PROPERTIES OBJECT_DEPENDS ${CMAKE_CURRENT_BINARY_DIR}/clar.suite)
+ PROPERTIES OBJECT_DEPENDS ${CLAR_SUITE_PATH}/clar.suite)
-include_directories(${LIBGIT2_DEPENDENCY_INCLUDES})
-include_directories(SYSTEM ${LIBGIT2_SYSTEM_INCLUDES})
+#
+# Preprocessor definitions
+#
-add_executable(libgit2_tests ${SRC_CLAR} ${SRC_TEST} ${LIBGIT2_OBJECTS})
+if(USE_LEAK_CHECKER STREQUAL "valgrind")
+ target_compile_definitions(libgit2_tests PRIVATE VALGRIND)
+endif()
-set_target_properties(libgit2_tests PROPERTIES C_STANDARD 90)
-set_target_properties(libgit2_tests PROPERTIES RUNTIME_OUTPUT_DIRECTORY ${libgit2_BINARY_DIR})
+target_compile_definitions(libgit2_tests PRIVATE CLAR_FIXTURE_PATH=\"${CLAR_FIXTURES}\")
+target_compile_definitions(libgit2_tests PRIVATE CLAR_TMPDIR=\"libgit2_tests\")
+target_compile_definitions(libgit2_tests PRIVATE CLAR_WIN32_LONGPATHS)
+target_compile_definitions(libgit2_tests PRIVATE _FILE_OFFSET_BITS=64)
-target_include_directories(libgit2_tests PRIVATE ../src/libgit2 ../src/util PUBLIC ../include)
-target_link_libraries(libgit2_tests ${LIBGIT2_SYSTEM_LIBS})
-ide_split_sources(libgit2_tests)
+# ensure that we do not use deprecated functions internally
+target_compile_definitions(libgit2_tests PRIVATE GIT_DEPRECATE_HARD)
+
+#
+# Platform specific options
+#
#
# Old versions of gcc require us to declare our test functions; don't do
@@ -62,11 +82,26 @@ if(CMAKE_COMPILER_IS_GNUCC AND CMAKE_CXX_COMPILER_VERSION VERSION_LESS 6.0)
endif()
if(MSVC_IDE)
- # Precompiled headers
+ list(APPEND TEST_SRC_CLAR "precompiled.c")
set_target_properties(libgit2_tests PROPERTIES COMPILE_FLAGS "/Yuprecompiled.h /FIprecompiled.h")
set_source_files_properties("precompiled.c" COMPILE_FLAGS "/Ycprecompiled.h")
endif()
+#
+# The test runner binary
+#
+
+target_sources(libgit2_tests PRIVATE ${TEST_SRC_CLAR} ${TEST_SRC} $<TARGET_OBJECTS:libgit2> $<TARGET_OBJECTS:util> ${LIBGIT2_DEPENDENCY_OBJECTS})
+
+target_include_directories(libgit2_tests PRIVATE ${CLAR_SUITE_PATH} ${TEST_INCLUDES})
+target_link_libraries(libgit2_tests ${LIBGIT2_SYSTEM_LIBS})
+
+set_target_properties(libgit2_tests PROPERTIES RUNTIME_OUTPUT_DIRECTORY ${libgit2_BINARY_DIR})
+
+#
+# Add tests
+#
+
function(ADD_CLAR_TEST name)
if(NOT USE_LEAK_CHECKER STREQUAL "OFF")
add_test(${name} "${libgit2_SOURCE_DIR}/script/${USE_LEAK_CHECKER}.sh" "${libgit2_BINARY_DIR}/libgit2_tests" ${ARGN})
diff --git a/tests/core/utf8.c b/tests/core/utf8.c
index 021828e9e..e1987b8d6 100644
--- a/tests/core/utf8.c
+++ b/tests/core/utf8.c
@@ -1,4 +1,5 @@
#include "clar_libgit2.h"
+#include "utf8.h"
void test_core_utf8__char_length(void)
{