Commit 7bb206a7 by Yoichi Nakayama

Merge branch 'main' into better-compatiblity-for-at-time-notation

Conflicts:
	src/revparse.c
parents 540b02f3 f9c4dc10
...@@ -91,7 +91,7 @@ jobs: ...@@ -91,7 +91,7 @@ jobs:
env: env:
CC: gcc CC: gcc
CMAKE_GENERATOR: Ninja CMAKE_GENERATOR: Ninja
CMAKE_OPTIONS: -DUSE_HTTPS=OpenSSL -DREGEX_BACKEND=builtin -DDEPRECATE_HARD=ON -DUSE_LEAK_CHECKER=valgrind -DUSE_GSSAPI=ON -DDEBUG_STRICT_ALLOC=ON -DDEBUG_STRICT_OPEN=ON CMAKE_OPTIONS: -DUSE_HTTPS=OpenSSL -DREGEX_BACKEND=builtin -DDEPRECATE_HARD=ON -DUSE_LEAK_CHECKER=valgrind -DUSE_GSSAPI=ON -DUSE_SSH=ON -DDEBUG_STRICT_ALLOC=ON -DDEBUG_STRICT_OPEN=ON
os: ubuntu-latest os: ubuntu-latest
- # Xenial, GCC, mbedTLS - # Xenial, GCC, mbedTLS
container: container:
...@@ -99,7 +99,7 @@ jobs: ...@@ -99,7 +99,7 @@ jobs:
env: env:
CC: gcc CC: gcc
CMAKE_GENERATOR: Ninja CMAKE_GENERATOR: Ninja
CMAKE_OPTIONS: -DUSE_HTTPS=mbedTLS -DUSE_SHA1=HTTPS -DDEPRECATE_HARD=ON -DUSE_LEAK_CHECKER=valgrind -DUSE_GSSAPI=ON CMAKE_OPTIONS: -DUSE_HTTPS=mbedTLS -DUSE_SHA1=HTTPS -DDEPRECATE_HARD=ON -DUSE_LEAK_CHECKER=valgrind -DUSE_GSSAPI=ON -DUSE_SSH=ON
os: ubuntu-latest os: ubuntu-latest
- # Xenial, Clang, OpenSSL - # Xenial, Clang, OpenSSL
container: container:
...@@ -107,14 +107,14 @@ jobs: ...@@ -107,14 +107,14 @@ jobs:
env: env:
CC: clang CC: clang
CMAKE_GENERATOR: Ninja CMAKE_GENERATOR: Ninja
CMAKE_OPTIONS: -DUSE_HTTPS=OpenSSL -DDEPRECATE_HARD=ON -DUSE_LEAK_CHECKER=valgrind -DUSE_GSSAPI=ON CMAKE_OPTIONS: -DUSE_HTTPS=OpenSSL -DDEPRECATE_HARD=ON -DUSE_LEAK_CHECKER=valgrind -DUSE_GSSAPI=ON -DUSE_SSH=ON
os: ubuntu-latest os: ubuntu-latest
- # Xenial, Clang, mbedTLS - # Xenial, Clang, mbedTLS
container: container:
name: xenial name: xenial
env: env:
CC: clang CC: clang
CMAKE_OPTIONS: -DUSE_HTTPS=mbedTLS -DUSE_SHA1=HTTPS -DREGEX_BACKEND=pcre -DDEPRECATE_HARD=ON -DUSE_LEAK_CHECKER=valgrind -DUSE_GSSAPI=ON CMAKE_OPTIONS: -DUSE_HTTPS=mbedTLS -DUSE_SHA1=HTTPS -DREGEX_BACKEND=pcre -DDEPRECATE_HARD=ON -DUSE_LEAK_CHECKER=valgrind -DUSE_GSSAPI=ON -DUSE_SSH=ON
CMAKE_GENERATOR: Ninja CMAKE_GENERATOR: Ninja
os: ubuntu-latest os: ubuntu-latest
- # Focal, Clang 10, mbedTLS, MemorySanitizer - # Focal, Clang 10, mbedTLS, MemorySanitizer
...@@ -123,7 +123,7 @@ jobs: ...@@ -123,7 +123,7 @@ jobs:
env: env:
CC: clang-10 CC: clang-10
CFLAGS: -fsanitize=memory -fsanitize-memory-track-origins=2 -fsanitize-blacklist=/home/libgit2/source/script/sanitizers.supp -fno-optimize-sibling-calls -fno-omit-frame-pointer CFLAGS: -fsanitize=memory -fsanitize-memory-track-origins=2 -fsanitize-blacklist=/home/libgit2/source/script/sanitizers.supp -fno-optimize-sibling-calls -fno-omit-frame-pointer
CMAKE_OPTIONS: -DCMAKE_PREFIX_PATH=/usr/local/msan -DUSE_HTTPS=mbedTLS -DUSE_SHA1=HTTPS -DREGEX_BACKEND=pcre -DDEPRECATE_HARD=ON -DUSE_BUNDLED_ZLIB=ON CMAKE_OPTIONS: -DCMAKE_PREFIX_PATH=/usr/local/msan -DUSE_HTTPS=mbedTLS -DUSE_SHA1=HTTPS -DREGEX_BACKEND=pcre -DDEPRECATE_HARD=ON -DUSE_BUNDLED_ZLIB=ON -DUSE_SSH=ON
CMAKE_GENERATOR: Ninja CMAKE_GENERATOR: Ninja
SKIP_SSH_TESTS: true SKIP_SSH_TESTS: true
SKIP_NEGOTIATE_TESTS: true SKIP_NEGOTIATE_TESTS: true
...@@ -136,7 +136,7 @@ jobs: ...@@ -136,7 +136,7 @@ jobs:
env: env:
CC: clang-10 CC: clang-10
CFLAGS: -fsanitize=undefined,nullability -fno-sanitize-recover=undefined,nullability -fsanitize-blacklist=/home/libgit2/source/script/sanitizers.supp -fno-optimize-sibling-calls -fno-omit-frame-pointer CFLAGS: -fsanitize=undefined,nullability -fno-sanitize-recover=undefined,nullability -fsanitize-blacklist=/home/libgit2/source/script/sanitizers.supp -fno-optimize-sibling-calls -fno-omit-frame-pointer
CMAKE_OPTIONS: -DCMAKE_PREFIX_PATH=/usr/local -DUSE_HTTPS=OpenSSL -DUSE_SHA1=HTTPS -DREGEX_BACKEND=pcre -DDEPRECATE_HARD=ON -DUSE_BUNDLED_ZLIB=ON CMAKE_OPTIONS: -DCMAKE_PREFIX_PATH=/usr/local -DUSE_HTTPS=OpenSSL -DUSE_SHA1=HTTPS -DREGEX_BACKEND=pcre -DDEPRECATE_HARD=ON -DUSE_BUNDLED_ZLIB=ON -DUSE_SSH=ON
CMAKE_GENERATOR: Ninja CMAKE_GENERATOR: Ninja
SKIP_SSH_TESTS: true SKIP_SSH_TESTS: true
SKIP_NEGOTIATE_TESTS: true SKIP_NEGOTIATE_TESTS: true
...@@ -149,7 +149,7 @@ jobs: ...@@ -149,7 +149,7 @@ jobs:
env: env:
CC: clang-10 CC: clang-10
CFLAGS: -fsanitize=thread -fno-optimize-sibling-calls -fno-omit-frame-pointer CFLAGS: -fsanitize=thread -fno-optimize-sibling-calls -fno-omit-frame-pointer
CMAKE_OPTIONS: -DCMAKE_PREFIX_PATH=/usr/local -DUSE_HTTPS=OpenSSL -DUSE_SHA1=HTTPS -DREGEX_BACKEND=pcre -DDEPRECATE_HARD=ON -DUSE_BUNDLED_ZLIB=ON CMAKE_OPTIONS: -DCMAKE_PREFIX_PATH=/usr/local -DUSE_HTTPS=OpenSSL -DUSE_SHA1=HTTPS -DREGEX_BACKEND=pcre -DDEPRECATE_HARD=ON -DUSE_BUNDLED_ZLIB=ON -DUSE_SSH=ON
CMAKE_GENERATOR: Ninja CMAKE_GENERATOR: Ninja
SKIP_SSH_TESTS: true SKIP_SSH_TESTS: true
SKIP_NEGOTIATE_TESTS: true SKIP_NEGOTIATE_TESTS: true
...@@ -300,4 +300,4 @@ jobs: ...@@ -300,4 +300,4 @@ jobs:
- name: Push documentation branch - name: Push documentation branch
working-directory: source working-directory: source
run: git push origin gh-pages run: git push origin gh-pages
if: github.event_name != 'pull_request' && github.repository == 'libgit2/libgit2' if: github.event_name == 'push' && github.repository == 'libgit2/libgit2'
...@@ -25,7 +25,7 @@ jobs: ...@@ -25,7 +25,7 @@ jobs:
env: env:
CC: gcc CC: gcc
CMAKE_GENERATOR: Ninja CMAKE_GENERATOR: Ninja
CMAKE_OPTIONS: -DUSE_HTTPS=OpenSSL -DREGEX_BACKEND=builtin -DDEPRECATE_HARD=ON -DUSE_LEAK_CHECKER=valgrind -DUSE_GSSAPI=ON CMAKE_OPTIONS: -DUSE_HTTPS=OpenSSL -DREGEX_BACKEND=builtin -DDEPRECATE_HARD=ON -DUSE_LEAK_CHECKER=valgrind -DUSE_GSSAPI=ON -DUSE_SSH=ON
os: ubuntu-latest os: ubuntu-latest
- # Xenial, GCC, mbedTLS - # Xenial, GCC, mbedTLS
container: container:
...@@ -33,7 +33,7 @@ jobs: ...@@ -33,7 +33,7 @@ jobs:
env: env:
CC: gcc CC: gcc
CMAKE_GENERATOR: Ninja CMAKE_GENERATOR: Ninja
CMAKE_OPTIONS: -DUSE_HTTPS=mbedTLS -DUSE_SHA1=HTTPS -DDEPRECATE_HARD=ON -DUSE_LEAK_CHECKER=valgrind -DUSE_GSSAPI=ON CMAKE_OPTIONS: -DUSE_HTTPS=mbedTLS -DUSE_SHA1=HTTPS -DDEPRECATE_HARD=ON -DUSE_LEAK_CHECKER=valgrind -DUSE_GSSAPI=ON -DUSE_SSH=ON
os: ubuntu-latest os: ubuntu-latest
- # Xenial, Clang, OpenSSL - # Xenial, Clang, OpenSSL
container: container:
...@@ -41,14 +41,14 @@ jobs: ...@@ -41,14 +41,14 @@ jobs:
env: env:
CC: clang CC: clang
CMAKE_GENERATOR: Ninja CMAKE_GENERATOR: Ninja
CMAKE_OPTIONS: -DUSE_HTTPS=OpenSSL -DDEPRECATE_HARD=ON -DUSE_LEAK_CHECKER=valgrind -DUSE_GSSAPI=ON CMAKE_OPTIONS: -DUSE_HTTPS=OpenSSL -DDEPRECATE_HARD=ON -DUSE_LEAK_CHECKER=valgrind -DUSE_GSSAPI=ON -DUSE_SSH=ON
os: ubuntu-latest os: ubuntu-latest
- # Xenial, Clang, mbedTLS - # Xenial, Clang, mbedTLS
container: container:
name: xenial name: xenial
env: env:
CC: clang CC: clang
CMAKE_OPTIONS: -DUSE_HTTPS=mbedTLS -DUSE_SHA1=HTTPS -DREGEX_BACKEND=pcre -DDEPRECATE_HARD=ON -DUSE_LEAK_CHECKER=valgrind -DUSE_GSSAPI=ON CMAKE_OPTIONS: -DUSE_HTTPS=mbedTLS -DUSE_SHA1=HTTPS -DREGEX_BACKEND=pcre -DDEPRECATE_HARD=ON -DUSE_LEAK_CHECKER=valgrind -DUSE_GSSAPI=ON -DUSE_SSH=ON
CMAKE_GENERATOR: Ninja CMAKE_GENERATOR: Ninja
os: ubuntu-latest os: ubuntu-latest
- # Xenial, GCC, thread-free - # Xenial, GCC, thread-free
...@@ -56,7 +56,7 @@ jobs: ...@@ -56,7 +56,7 @@ jobs:
name: xenial name: xenial
env: env:
CC: gcc CC: gcc
CMAKE_OPTIONS: -DTHREADSAFE=OFF -DDEPRECATE_HARD=ON -DUSE_LEAK_CHECKER=valgrind -DUSE_GSSAPI=ON CMAKE_OPTIONS: -DTHREADSAFE=OFF -DDEPRECATE_HARD=ON -DUSE_LEAK_CHECKER=valgrind -DUSE_GSSAPI=ON -DUSE_SSH=ON
CMAKE_GENERATOR: Ninja CMAKE_GENERATOR: Ninja
os: ubuntu-latest os: ubuntu-latest
- # Xenial, Clang, OpenSSL (dynamically loaded) - # Xenial, Clang, OpenSSL (dynamically loaded)
...@@ -64,7 +64,7 @@ jobs: ...@@ -64,7 +64,7 @@ jobs:
name: xenial name: xenial
env: env:
CC: clang CC: clang
CMAKE_OPTIONS: -DUSE_HTTPS=OpenSSL-Dynamic -DDEPRECATE_HARD=ON -DUSE_LEAK_CHECKER=valgrind -DUSE_GSSAPI=ON CMAKE_OPTIONS: -DUSE_HTTPS=OpenSSL-Dynamic -DDEPRECATE_HARD=ON -DUSE_LEAK_CHECKER=valgrind -DUSE_GSSAPI=ON -DUSE_SSH=ON
CMAKE_GENERATOR: Ninja CMAKE_GENERATOR: Ninja
os: ubuntu-latest os: ubuntu-latest
- # Focal, Clang 10, mbedTLS, MemorySanitizer - # Focal, Clang 10, mbedTLS, MemorySanitizer
...@@ -119,7 +119,7 @@ jobs: ...@@ -119,7 +119,7 @@ jobs:
container: container:
name: centos7 name: centos7
env: env:
CMAKE_OPTIONS: -DDEPRECATE_HARD=ON -DUSE_LEAK_CHECKER=valgrind -DUSE_GSSAPI=ON CMAKE_OPTIONS: -DDEPRECATE_HARD=ON -DUSE_LEAK_CHECKER=valgrind -DUSE_GSSAPI=ON -DUSE_SSH=ON
PKG_CONFIG_PATH: /usr/local/lib/pkgconfig PKG_CONFIG_PATH: /usr/local/lib/pkgconfig
SKIP_NEGOTIATE_TESTS: true SKIP_NEGOTIATE_TESTS: true
os: ubuntu-latest os: ubuntu-latest
...@@ -127,7 +127,7 @@ jobs: ...@@ -127,7 +127,7 @@ jobs:
container: container:
name: centos7 name: centos7
env: env:
CMAKE_OPTIONS: -DUSE_HTTPS=OpenSSL-Dynamic -DDEPRECATE_HARD=ON -DUSE_LEAK_CHECKER=valgrind -DUSE_GSSAPI=ON CMAKE_OPTIONS: -DUSE_HTTPS=OpenSSL-Dynamic -DDEPRECATE_HARD=ON -DUSE_LEAK_CHECKER=valgrind -DUSE_GSSAPI=ON -DUSE_SSH=ON
PKG_CONFIG_PATH: /usr/local/lib/pkgconfig PKG_CONFIG_PATH: /usr/local/lib/pkgconfig
SKIP_NEGOTIATE_TESTS: true SKIP_NEGOTIATE_TESTS: true
os: ubuntu-latest os: ubuntu-latest
...@@ -212,7 +212,7 @@ jobs: ...@@ -212,7 +212,7 @@ jobs:
env: env:
CC: gcc CC: gcc
CMAKE_GENERATOR: Ninja CMAKE_GENERATOR: Ninja
CMAKE_OPTIONS: -DUSE_HTTPS=OpenSSL-Dynamic -DDEPRECATE_HARD=ON -DUSE_LEAK_CHECKER=valgrind -DUSE_GSSAPI=ON CMAKE_OPTIONS: -DUSE_HTTPS=OpenSSL-Dynamic -DDEPRECATE_HARD=ON -DUSE_LEAK_CHECKER=valgrind -DUSE_GSSAPI=ON -DUSE_SSH=ON
RUN_INVASIVE_TESTS: true RUN_INVASIVE_TESTS: true
os: ubuntu-latest os: ubuntu-latest
- # Bionic, x86, Clang, OpenSSL - # Bionic, x86, Clang, OpenSSL
...@@ -223,7 +223,7 @@ jobs: ...@@ -223,7 +223,7 @@ jobs:
env: env:
CC: clang CC: clang
CMAKE_GENERATOR: Ninja CMAKE_GENERATOR: Ninja
CMAKE_OPTIONS: -DUSE_HTTPS=OpenSSL -DDEPRECATE_HARD=ON -DUSE_LEAK_CHECKER=valgrind -DUSE_GSSAPI=ON CMAKE_OPTIONS: -DUSE_HTTPS=OpenSSL -DDEPRECATE_HARD=ON -DUSE_LEAK_CHECKER=valgrind -DUSE_GSSAPI=ON -DUSE_SSH=ON
RUN_INVASIVE_TESTS: true RUN_INVASIVE_TESTS: true
os: ubuntu-latest os: ubuntu-latest
- # Bionic, x86, GCC, OpenSSL - # Bionic, x86, GCC, OpenSSL
...@@ -233,7 +233,7 @@ jobs: ...@@ -233,7 +233,7 @@ jobs:
env: env:
CC: gcc CC: gcc
CMAKE_GENERATOR: Ninja CMAKE_GENERATOR: Ninja
CMAKE_OPTIONS: -DUSE_HTTPS=OpenSSL -DDEPRECATE_HARD=ON -DUSE_LEAK_CHECKER=valgrind -DUSE_GSSAPI=ON CMAKE_OPTIONS: -DUSE_HTTPS=OpenSSL -DDEPRECATE_HARD=ON -DUSE_LEAK_CHECKER=valgrind -DUSE_GSSAPI=ON -DUSE_SSH=ON
RUN_INVASIVE_TESTS: true RUN_INVASIVE_TESTS: true
os: ubuntu-latest os: ubuntu-latest
- # Bionic, arm32, GCC, OpenSSL - # Bionic, arm32, GCC, OpenSSL
...@@ -244,7 +244,7 @@ jobs: ...@@ -244,7 +244,7 @@ jobs:
env: env:
CC: gcc CC: gcc
CMAKE_GENERATOR: Ninja CMAKE_GENERATOR: Ninja
CMAKE_OPTIONS: -DUSE_HTTPS=OpenSSL -DDEPRECATE_HARD=ON -DUSE_GSSAPI=ON CMAKE_OPTIONS: -DUSE_HTTPS=OpenSSL -DDEPRECATE_HARD=ON -DUSE_GSSAPI=ON -DUSE_SSH=ON
RUN_INVASIVE_TESTS: true RUN_INVASIVE_TESTS: true
SKIP_PROXY_TESTS: true SKIP_PROXY_TESTS: true
os: ubuntu-latest os: ubuntu-latest
...@@ -256,7 +256,7 @@ jobs: ...@@ -256,7 +256,7 @@ jobs:
env: env:
CC: gcc CC: gcc
CMAKE_GENERATOR: Ninja CMAKE_GENERATOR: Ninja
CMAKE_OPTIONS: -DUSE_HTTPS=OpenSSL -DDEPRECATE_HARD=ON -DUSE_GSSAPI=ON CMAKE_OPTIONS: -DUSE_HTTPS=OpenSSL -DDEPRECATE_HARD=ON -DUSE_GSSAPI=ON -DUSE_SSH=ON
RUN_INVASIVE_TESTS: true RUN_INVASIVE_TESTS: true
SKIP_PROXY_TESTS: true SKIP_PROXY_TESTS: true
os: ubuntu-latest os: ubuntu-latest
......
...@@ -8,7 +8,7 @@ ...@@ -8,7 +8,7 @@
"name": "(gdb) Launch", "name": "(gdb) Launch",
"type": "cppdbg", "type": "cppdbg",
"request": "launch", "request": "launch",
"program": "${workspaceFolder}/build/libgit2_clar", "program": "${workspaceFolder}/build/libgit2_tests",
"args": [], "args": [],
"stopAtEntry": false, "stopAtEntry": false,
"cwd": "${fileDirname}", "cwd": "${fileDirname}",
...@@ -24,4 +24,4 @@ ...@@ -24,4 +24,4 @@
] ]
} }
] ]
} }
\ No newline at end of file
...@@ -16,7 +16,7 @@ ...@@ -16,7 +16,7 @@
{ {
"label": "Run Tests", "label": "Run Tests",
"type": "shell", "type": "shell",
"command": "build/libgit2_clar -v", "command": "build/libgit2_tests -v",
"group": "test", "group": "test",
"presentation": { "presentation": {
"reveal": "always", "reveal": "always",
...@@ -24,4 +24,4 @@ ...@@ -24,4 +24,4 @@
} }
} }
] ]
} }
\ No newline at end of file
...@@ -236,18 +236,18 @@ Once built, you can run the tests from the `build` directory with the command ...@@ -236,18 +236,18 @@ Once built, you can run the tests from the `build` directory with the command
Alternatively you can run the test suite directly using, Alternatively you can run the test suite directly using,
$ ./libgit2_clar $ ./libgit2_tests
Invoking the test suite directly is useful because it allows you to execute Invoking the test suite directly is useful because it allows you to execute
individual tests, or groups of tests using the `-s` flag. For example, to individual tests, or groups of tests using the `-s` flag. For example, to
run the index tests: run the index tests:
$ ./libgit2_clar -sindex $ ./libgit2_tests -sindex
To run a single test named `index::racy::diff`, which corresponds to the test To run a single test named `index::racy::diff`, which corresponds to the test
function [`test_index_racy__diff`](https://github.com/libgit2/libgit2/blob/main/tests/index/racy.c#L23): function [`test_index_racy__diff`](https://github.com/libgit2/libgit2/blob/main/tests/index/racy.c#L23):
$ ./libgit2_clar -sindex::racy::diff $ ./libgit2_tests -sindex::racy::diff
The test suite will print a `.` for every passing test, and an `F` for any The test suite will print a `.` for every passing test, and an `F` for any
failing test. An `S` indicates that a test was skipped because it is not failing test. An `S` indicates that a test was skipped because it is not
...@@ -279,7 +279,7 @@ The following CMake variables are declared: ...@@ -279,7 +279,7 @@ The following CMake variables are declared:
- `CMAKE_INSTALL_INCLUDEDIR`: Where to install headers to. - `CMAKE_INSTALL_INCLUDEDIR`: Where to install headers to.
- `BUILD_SHARED_LIBS`: Build libgit2 as a Shared Library (defaults to ON) - `BUILD_SHARED_LIBS`: Build libgit2 as a Shared Library (defaults to ON)
- `BUILD_TESTS`: Build the unit and integration test suites (defaults to ON) - `BUILD_TESTS`: Build the unit and integration test suites (defaults to ON)
- `THREADSAFE`: Build libgit2 with threading support (defaults to ON) - `USE_THREADS`: Build libgit2 with threading support (defaults to ON)
To list all build options and their current value, you can do the To list all build options and their current value, you can do the
following: following:
......
...@@ -3,28 +3,28 @@ ...@@ -3,28 +3,28 @@
# <flag> - the compiler flag to test # <flag> - the compiler flag to test
# This internally calls the CHECK_C_COMPILER_FLAG macro. # This internally calls the CHECK_C_COMPILER_FLAG macro.
INCLUDE(CheckCCompilerFlag) include(CheckCCompilerFlag)
MACRO(ADD_C_FLAG _FLAG) macro(ADD_C_FLAG _FLAG)
STRING(TOUPPER ${_FLAG} UPCASE) string(TOUPPER ${_FLAG} UPCASE)
STRING(REGEX REPLACE "[-=]" "_" UPCASE_PRETTY ${UPCASE}) string(REGEX REPLACE "[-=]" "_" UPCASE_PRETTY ${UPCASE})
STRING(REGEX REPLACE "^_+" "" UPCASE_PRETTY ${UPCASE_PRETTY}) string(REGEX REPLACE "^_+" "" UPCASE_PRETTY ${UPCASE_PRETTY})
CHECK_C_COMPILER_FLAG(${_FLAG} IS_${UPCASE_PRETTY}_SUPPORTED) check_c_compiler_flag(${_FLAG} IS_${UPCASE_PRETTY}_SUPPORTED)
IF(IS_${UPCASE_PRETTY}_SUPPORTED) if(IS_${UPCASE_PRETTY}_SUPPORTED)
SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${_FLAG}") set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${_FLAG}")
ELSE() else()
MESSAGE(FATAL_ERROR "Required flag ${_FLAG} is not supported") message(FATAL_ERROR "Required flag ${_FLAG} is not supported")
ENDIF() endif()
ENDMACRO() endmacro()
MACRO(ADD_C_FLAG_IF_SUPPORTED _FLAG) macro(ADD_C_FLAG_IF_SUPPORTED _FLAG)
STRING(TOUPPER ${_FLAG} UPCASE) string(TOUPPER ${_FLAG} UPCASE)
STRING(REGEX REPLACE "[-=]" "_" UPCASE_PRETTY ${UPCASE}) string(REGEX REPLACE "[-=]" "_" UPCASE_PRETTY ${UPCASE})
STRING(REGEX REPLACE "^_+" "" UPCASE_PRETTY ${UPCASE_PRETTY}) string(REGEX REPLACE "^_+" "" UPCASE_PRETTY ${UPCASE_PRETTY})
CHECK_C_COMPILER_FLAG(${_FLAG} IS_${UPCASE_PRETTY}_SUPPORTED) check_c_compiler_flag(${_FLAG} IS_${UPCASE_PRETTY}_SUPPORTED)
IF(IS_${UPCASE_PRETTY}_SUPPORTED) if(IS_${UPCASE_PRETTY}_SUPPORTED)
SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${_FLAG}") set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${_FLAG}")
ENDIF() endif()
ENDMACRO() endmacro()
# Platform specific compilation flags
if(MSVC)
add_definitions(-D_SCL_SECURE_NO_WARNINGS)
add_definitions(-D_CRT_SECURE_NO_DEPRECATE)
add_definitions(-D_CRT_NONSTDC_NO_DEPRECATE)
string(REPLACE "/Zm1000" " " CMAKE_C_FLAGS "${CMAKE_C_FLAGS}")
# /GF - String pooling
# /MP - Parallel build
set(CMAKE_C_FLAGS "/GF /MP /nologo ${CMAKE_C_FLAGS}")
# /Gd - explicitly set cdecl calling convention
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} /Gd")
if(NOT (MSVC_VERSION LESS 1900))
# /guard:cf - Enable Control Flow Guard
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} /guard:cf")
endif()
if(STATIC_CRT)
set(CRT_FLAG_DEBUG "/MTd")
set(CRT_FLAG_RELEASE "/MT")
else()
set(CRT_FLAG_DEBUG "/MDd")
set(CRT_FLAG_RELEASE "/MD")
endif()
if(WIN32_LEAKCHECK)
set(GIT_WIN32_LEAKCHECK 1)
set(CRT_FLAG_DEBUG "${CRT_FLAG_DEBUG}")
set(CMAKE_C_STANDARD_LIBRARIES "${CMAKE_C_STANDARD_LIBRARIES} Dbghelp.lib")
endif()
# /Zi - Create debugging information
# /Od - Disable optimization
# /D_DEBUG - #define _DEBUG
# /MTd - Statically link the multithreaded debug version of the CRT
# /MDd - Dynamically link the multithreaded debug version of the CRT
# /RTC1 - Run time checks
set(CMAKE_C_FLAGS_DEBUG "${CMAKE_C_FLAGS_DEBUG} /Zi /Od /D_DEBUG /RTC1 ${CRT_FLAG_DEBUG}")
# /DNDEBUG - Disables asserts
# /MT - Statically link the multithreaded release version of the CRT
# /MD - Dynamically link the multithreaded release version of the CRT
# /O2 - Optimize for speed
# /Oy - Enable frame pointer omission (FPO) (otherwise CMake will automatically turn it off)
# /GL - Link time code generation (whole program optimization)
# /Gy - Function-level linking
set(CMAKE_C_FLAGS_RELEASE "/DNDEBUG /O2 /Oy /GL /Gy ${CRT_FLAG_RELEASE}")
# /Oy- - Disable frame pointer omission (FPO)
set(CMAKE_C_FLAGS_RELWITHDEBINFO "/DNDEBUG /Zi /O2 /Oy- /GL /Gy ${CRT_FLAG_RELEASE}")
# /O1 - Optimize for size
set(CMAKE_C_FLAGS_MINSIZEREL "/DNDEBUG /O1 /Oy /GL /Gy ${CRT_FLAG_RELEASE}")
# /IGNORE:4221 - Ignore empty compilation units
set(CMAKE_STATIC_LINKER_FLAGS "/IGNORE:4221")
# /DYNAMICBASE - Address space load randomization (ASLR)
# /NXCOMPAT - Data execution prevention (DEP)
# /LARGEADDRESSAWARE - >2GB user address space on x86
# /VERSION - Embed version information in PE header
set(CMAKE_EXE_LINKER_FLAGS "/DYNAMICBASE /NXCOMPAT /LARGEADDRESSAWARE /VERSION:${libgit2_VERSION_MAJOR}.${libgit2_VERSION_MINOR}")
if(NOT (MSVC_VERSION LESS 1900))
# /GUARD:CF - Enable Control Flow Guard
set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} /GUARD:CF")
endif()
# /DEBUG - Create a PDB
# /LTCG - Link time code generation (whole program optimization)
# /OPT:REF /OPT:ICF - Fold out duplicate code at link step
# /INCREMENTAL:NO - Required to use /LTCG
# /DEBUGTYPE:cv,fixup - Additional data embedded in the PDB (requires /INCREMENTAL:NO, so not on for Debug)
set(CMAKE_EXE_LINKER_FLAGS_DEBUG "/DEBUG")
set(CMAKE_EXE_LINKER_FLAGS_RELEASE "/RELEASE /LTCG /OPT:REF /OPT:ICF /INCREMENTAL:NO")
set(CMAKE_EXE_LINKER_FLAGS_RELWITHDEBINFO "/DEBUG /RELEASE /LTCG /OPT:REF /OPT:ICF /INCREMENTAL:NO /DEBUGTYPE:cv,fixup")
set(CMAKE_EXE_LINKER_FLAGS_MINSIZEREL "/RELEASE /LTCG /OPT:REF /OPT:ICF /INCREMENTAL:NO")
# Same linker settings for DLL as EXE
set(CMAKE_SHARED_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS}")
set(CMAKE_SHARED_LINKER_FLAGS_DEBUG "${CMAKE_EXE_LINKER_FLAGS_DEBUG}")
set(CMAKE_SHARED_LINKER_FLAGS_RELEASE "${CMAKE_EXE_LINKER_FLAGS_RELEASE}")
set(CMAKE_SHARED_LINKER_FLAGS_RELWITHDEBINFO "${CMAKE_EXE_LINKER_FLAGS_RELWITHDEBINFO}")
set(CMAKE_SHARED_LINKER_FLAGS_MINSIZEREL "${CMAKE_EXE_LINKER_FLAGS_MINSIZEREL}")
else()
if(ENABLE_REPRODUCIBLE_BUILDS)
set(CMAKE_C_ARCHIVE_CREATE "<CMAKE_AR> Dqc <TARGET> <LINK_FLAGS> <OBJECTS>")
set(CMAKE_C_ARCHIVE_APPEND "<CMAKE_AR> Dq <TARGET> <LINK_FLAGS> <OBJECTS>")
set(CMAKE_C_ARCHIVE_FINISH "<CMAKE_RANLIB> -D <TARGET>")
endif()
if(NOT BUILD_SHARED_LIBS)
set(CMAKE_FIND_LIBRARY_SUFFIXES ".a")
endif()
set(CMAKE_C_FLAGS "-D_GNU_SOURCE ${CMAKE_C_FLAGS}")
enable_warnings(all)
enable_warnings(extra)
if(CMAKE_SYSTEM_NAME MATCHES "(Solaris|SunOS)")
set(CMAKE_C_FLAGS "-D_POSIX_C_SOURCE=200112L -D__EXTENSIONS__ -D_POSIX_PTHREAD_SEMANTICS ${CMAKE_C_FLAGS}")
endif()
set(CMAKE_C_FLAGS_DEBUG "${CMAKE_C_FLAGS_DEBUG} -D_DEBUG -O0")
if(MINGW OR MSYS) # MinGW and MSYS always do PIC and complain if we tell them to
string(REGEX REPLACE "-fPIC" "" CMAKE_SHARED_LIBRARY_C_FLAGS "${CMAKE_SHARED_LIBRARY_C_FLAGS}")
elseif(BUILD_SHARED_LIBS)
add_c_flag_IF_SUPPORTED(-fvisibility=hidden)
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fPIC")
endif()
if(MINGW)
# MinGW >= 3.14 uses the C99-style stdio functions
# automatically, but forks like mingw-w64 still want
# us to define this in order to use them
add_definitions(-D__USE_MINGW_ANSI_STDIO=1)
endif()
enable_warnings(documentation)
disable_warnings(documentation-deprecated-sync)
disable_warnings(missing-field-initializers)
enable_warnings(missing-declarations)
enable_warnings(strict-aliasing)
enable_warnings(strict-prototypes)
enable_warnings(declaration-after-statement)
enable_warnings(shift-count-overflow)
enable_warnings(unused-const-variable)
enable_warnings(unused-function)
enable_warnings(int-conversion)
enable_warnings(c11-extensions)
enable_warnings(c99-c11-compat)
# MinGW uses gcc, which expects POSIX formatting for printf, but
# uses the Windows C library, which uses its own format specifiers.
# Disable format specifier warnings.
if(MINGW)
disable_warnings(format)
disable_warnings(format-security)
else()
enable_warnings(format)
enable_warnings(format-security)
endif()
endif()
# Ensure that MinGW provides the correct header files.
if(WIN32 AND NOT CYGWIN)
add_definitions(-DWIN32 -D_WIN32_WINNT=0x0600)
endif()
MACRO(ENABLE_WARNINGS flag) macro(ENABLE_WARNINGS flag)
ADD_C_FLAG_IF_SUPPORTED(-W${flag}) add_c_flag_if_supported(-W${flag})
ENDMACRO() endmacro()
MACRO(DISABLE_WARNINGS flag) macro(DISABLE_WARNINGS flag)
ADD_C_FLAG_IF_SUPPORTED(-Wno-${flag}) add_c_flag_if_supported(-Wno-${flag})
ENDMACRO() endmacro()
IF(ENABLE_WERROR) if(ENABLE_WERROR)
IF(MSVC) if(MSVC)
ADD_COMPILE_OPTIONS(-WX) add_compile_options(-WX)
ELSE() else()
ADD_C_FLAG_IF_SUPPORTED(-Werror) add_c_flag_if_supported(-Werror)
ENDIF() endif()
ENDIF() endif()
...@@ -6,21 +6,21 @@ ...@@ -6,21 +6,21 @@
# COREFOUNDATION_LDFLAGS # COREFOUNDATION_LDFLAGS
# #
FIND_PATH(COREFOUNDATION_INCLUDE_DIR NAMES CoreFoundation.h) find_path(COREFOUNDATION_INCLUDE_DIR NAMES CoreFoundation.h)
FIND_LIBRARY(COREFOUNDATION_LIBRARIES NAMES CoreFoundation) find_library(COREFOUNDATION_LIBRARIES NAMES CoreFoundation)
IF (COREFOUNDATION_INCLUDE_DIR AND COREFOUNDATION_LIBRARIES) if(COREFOUNDATION_INCLUDE_DIR AND COREFOUNDATION_LIBRARIES)
IF (NOT CoreFoundation_FIND_QUIETLY) if(NOT CoreFoundation_FIND_QUIETLY)
MESSAGE(STATUS "Found CoreFoundation ${COREFOUNDATION_LIBRARIES}") message(STATUS "Found CoreFoundation ${COREFOUNDATION_LIBRARIES}")
ENDIF() endif()
SET(COREFOUNDATION_FOUND TRUE) set(COREFOUNDATION_FOUND TRUE)
SET(COREFOUNDATION_LDFLAGS "-framework CoreFoundation") set(COREFOUNDATION_LDFLAGS "-framework CoreFoundation")
ENDIF () endif()
IF (CoreFoundation_FIND_REQUIRED AND NOT COREFOUNDATION_FOUND) if(CoreFoundation_FIND_REQUIRED AND NOT COREFOUNDATION_FOUND)
MESSAGE(FATAL_ERROR "CoreFoundation not found") message(FATAL_ERROR "CoreFoundation not found")
ENDIF() endif()
MARK_AS_ADVANCED( mark_as_advanced(
COREFOUNDATION_INCLUDE_DIR COREFOUNDATION_INCLUDE_DIR
COREFOUNDATION_LIBRARIES COREFOUNDATION_LIBRARIES
) )
...@@ -7,21 +7,21 @@ ...@@ -7,21 +7,21 @@
# GSSFRAMEWORK_LDFLAGS # GSSFRAMEWORK_LDFLAGS
# #
FIND_PATH(GSSFRAMEWORK_INCLUDE_DIR NAMES GSS.h) find_path(GSSFRAMEWORK_INCLUDE_DIR NAMES GSS.h)
FIND_LIBRARY(GSSFRAMEWORK_LIBRARIES NAMES GSS) find_library(GSSFRAMEWORK_LIBRARIES NAMES GSS)
IF (GSSFRAMEWORK_INCLUDE_DIR AND GSSFRAMEWORK_LIBRARIES) if(GSSFRAMEWORK_INCLUDE_DIR AND GSSFRAMEWORK_LIBRARIES)
IF (NOT CoreFoundation_FIND_QUIETLY) if(NOT CoreFoundation_FIND_QUIETLY)
MESSAGE(STATUS "Found GSS.framework ${GSSFRAMEWORK_LIBRARIES}") message(STATUS "Found GSS.framework ${GSSFRAMEWORK_LIBRARIES}")
ENDIF() endif()
SET(GSSFRAMEWORK_FOUND TRUE) set(GSSFRAMEWORK_FOUND TRUE)
SET(GSSFRAMEWORK_LDFLAGS "-framework GSS") set(GSSFRAMEWORK_LDFLAGS "-framework GSS")
ENDIF () endif()
IF (GSS_FIND_REQUIRED AND NOT GSSFRAMEWORK_FOUND) if(GSS_FIND_REQUIRED AND NOT GSSFRAMEWORK_FOUND)
MESSAGE(FATAL_ERROR "CoreFoundation not found") message(FATAL_ERROR "CoreFoundation not found")
ENDIF() endif()
MARK_AS_ADVANCED( mark_as_advanced(
GSSFRAMEWORK_INCLUDE_DIR GSSFRAMEWORK_INCLUDE_DIR
GSSFRAMEWORK_LIBRARIES GSSFRAMEWORK_LIBRARIES
GSSFRAMEWORK_LDFLAGS GSSFRAMEWORK_LDFLAGS
......
...@@ -10,30 +10,30 @@ ...@@ -10,30 +10,30 @@
# HTTP_PARSER_VERSION_STRING - the version of http-parser found # HTTP_PARSER_VERSION_STRING - the version of http-parser found
# Find the header and library # Find the header and library
FIND_PATH(HTTP_PARSER_INCLUDE_DIR NAMES http_parser.h) find_path(HTTP_PARSER_INCLUDE_DIR NAMES http_parser.h)
FIND_LIBRARY(HTTP_PARSER_LIBRARY NAMES http_parser libhttp_parser) find_library(HTTP_PARSER_LIBRARY NAMES http_parser libhttp_parser)
# Found the header, read version # Found the header, read version
if (HTTP_PARSER_INCLUDE_DIR AND EXISTS "${HTTP_PARSER_INCLUDE_DIR}/http_parser.h") if(HTTP_PARSER_INCLUDE_DIR AND EXISTS "${HTTP_PARSER_INCLUDE_DIR}/http_parser.h")
FILE(READ "${HTTP_PARSER_INCLUDE_DIR}/http_parser.h" HTTP_PARSER_H) file(READ "${HTTP_PARSER_INCLUDE_DIR}/http_parser.h" HTTP_PARSER_H)
IF (HTTP_PARSER_H) if(HTTP_PARSER_H)
STRING(REGEX REPLACE ".*#define[\t ]+HTTP_PARSER_VERSION_MAJOR[\t ]+([0-9]+).*" "\\1" HTTP_PARSER_VERSION_MAJOR "${HTTP_PARSER_H}") string(REGEX REPLACE ".*#define[\t ]+HTTP_PARSER_VERSION_MAJOR[\t ]+([0-9]+).*" "\\1" HTTP_PARSER_VERSION_MAJOR "${HTTP_PARSER_H}")
STRING(REGEX REPLACE ".*#define[\t ]+HTTP_PARSER_VERSION_MINOR[\t ]+([0-9]+).*" "\\1" HTTP_PARSER_VERSION_MINOR "${HTTP_PARSER_H}") string(REGEX REPLACE ".*#define[\t ]+HTTP_PARSER_VERSION_MINOR[\t ]+([0-9]+).*" "\\1" HTTP_PARSER_VERSION_MINOR "${HTTP_PARSER_H}")
SET(HTTP_PARSER_VERSION_STRING "${HTTP_PARSER_VERSION_MAJOR}.${HTTP_PARSER_VERSION_MINOR}") set(HTTP_PARSER_VERSION_STRING "${HTTP_PARSER_VERSION_MAJOR}.${HTTP_PARSER_VERSION_MINOR}")
ENDIF() endif()
UNSET(HTTP_PARSER_H) unset(HTTP_PARSER_H)
ENDIF() endif()
# Handle the QUIETLY and REQUIRED arguments and set HTTP_PARSER_FOUND # Handle the QUIETLY and REQUIRED arguments and set HTTP_PARSER_FOUND
# to TRUE if all listed variables are TRUE # to TRUE if all listed variables are TRUE
INCLUDE(FindPackageHandleStandardArgs) include(FindPackageHandleStandardArgs)
FIND_PACKAGE_HANDLE_STANDARD_ARGS(HTTP_Parser REQUIRED_VARS HTTP_PARSER_INCLUDE_DIR HTTP_PARSER_LIBRARY) find_package_handle_standard_args(HTTP_Parser REQUIRED_VARS HTTP_PARSER_INCLUDE_DIR HTTP_PARSER_LIBRARY)
# Hide advanced variables # Hide advanced variables
MARK_AS_ADVANCED(HTTP_PARSER_INCLUDE_DIR HTTP_PARSER_LIBRARY) mark_as_advanced(HTTP_PARSER_INCLUDE_DIR HTTP_PARSER_LIBRARY)
# Set standard variables # Set standard variables
IF (HTTP_PARSER_FOUND) if(HTTP_PARSER_FOUND)
SET(HTTP_PARSER_LIBRARIES ${HTTP_PARSER_LIBRARY}) set(HTTP_PARSER_LIBRARIES ${HTTP_PARSER_LIBRARY})
set(HTTP_PARSER_INCLUDE_DIRS ${HTTP_PARSER_INCLUDE_DIR}) set(HTTP_PARSER_INCLUDE_DIRS ${HTTP_PARSER_INCLUDE_DIR})
ENDIF() endif()
...@@ -6,40 +6,40 @@ ...@@ -6,40 +6,40 @@
# ICONV_LIBRARIES - Link these to use Iconv # ICONV_LIBRARIES - Link these to use Iconv
# #
IF(ICONV_INCLUDE_DIR AND ICONV_LIBRARIES) if(ICONV_INCLUDE_DIR AND ICONV_LIBRARIES)
# Already in cache, be silent # Already in cache, be silent
SET(ICONV_FIND_QUIETLY TRUE) set(ICONV_FIND_QUIETLY TRUE)
ENDIF() endif()
FIND_PATH(ICONV_INCLUDE_DIR iconv.h) find_path(ICONV_INCLUDE_DIR iconv.h)
CHECK_FUNCTION_EXISTS(iconv_open libc_has_iconv) check_function_exists(iconv_open libc_has_iconv)
FIND_LIBRARY(iconv_lib NAMES iconv libiconv libiconv-2 c) find_library(iconv_lib NAMES iconv libiconv libiconv-2 c)
IF(ICONV_INCLUDE_DIR AND libc_has_iconv) if(ICONV_INCLUDE_DIR AND libc_has_iconv)
SET(ICONV_FOUND TRUE) set(ICONV_FOUND TRUE)
SET(ICONV_LIBRARIES "") set(ICONV_LIBRARIES "")
IF(NOT ICONV_FIND_QUIETLY) if(NOT ICONV_FIND_QUIETLY)
MESSAGE(STATUS "Found Iconv: provided by libc") message(STATUS "Found Iconv: provided by libc")
ENDIF(NOT ICONV_FIND_QUIETLY) endif(NOT ICONV_FIND_QUIETLY)
ELSEIF(ICONV_INCLUDE_DIR AND iconv_lib) elseif(ICONV_INCLUDE_DIR AND iconv_lib)
SET(ICONV_FOUND TRUE) set(ICONV_FOUND TRUE)
# split iconv into -L and -l linker options, so we can # split iconv into -L and -l linker options, so we can
# set them for pkg-config # set them for pkg-config
GET_FILENAME_COMPONENT(iconv_path ${iconv_lib} PATH) get_filename_component(iconv_path ${iconv_lib} PATH)
GET_FILENAME_COMPONENT(iconv_name ${iconv_lib} NAME_WE) get_filename_component(iconv_name ${iconv_lib} NAME_WE)
STRING(REGEX REPLACE "^lib" "" iconv_name ${iconv_name}) string(REGEX REPLACE "^lib" "" iconv_name ${iconv_name})
SET(ICONV_LIBRARIES "-L${iconv_path} -l${iconv_name}") set(ICONV_LIBRARIES "-L${iconv_path} -l${iconv_name}")
IF(NOT ICONV_FIND_QUIETLY) if(NOT ICONV_FIND_QUIETLY)
MESSAGE(STATUS "Found Iconv: ${ICONV_LIBRARIES}") message(STATUS "Found Iconv: ${ICONV_LIBRARIES}")
ENDIF(NOT ICONV_FIND_QUIETLY) endif()
ELSE() else()
IF(Iconv_FIND_REQUIRED) if(Iconv_FIND_REQUIRED)
MESSAGE(FATAL_ERROR "Could not find Iconv") message(FATAL_ERROR "Could not find Iconv")
ENDIF(Iconv_FIND_REQUIRED) endif(Iconv_FIND_REQUIRED)
ENDIF() endif()
MARK_AS_ADVANCED( mark_as_advanced(
ICONV_INCLUDE_DIR ICONV_INCLUDE_DIR
ICONV_LIBRARIES ICONV_LIBRARIES
) )
...@@ -2,12 +2,12 @@ ...@@ -2,12 +2,12 @@
# LIBSSH2_INCLUDE_DIR - the libssh2 include directory # LIBSSH2_INCLUDE_DIR - the libssh2 include directory
# LIBSSH2_LIBRARY - the libssh2 library name # LIBSSH2_LIBRARY - the libssh2 library name
FIND_PATH(LIBSSH2_INCLUDE_DIR libssh2.h) find_path(LIBSSH2_INCLUDE_DIR libssh2.h)
FIND_LIBRARY(LIBSSH2_LIBRARY NAMES ssh2 libssh2) find_library(LIBSSH2_LIBRARY NAMES ssh2 libssh2)
INCLUDE(FindPackageHandleStandardArgs) include(FindPackageHandleStandardArgs)
find_package_handle_standard_args(LibSSH2 find_package_handle_standard_args(LibSSH2
REQUIRED_VARS LIBSSH2_LIBRARY LIBSSH2_INCLUDE_DIR) REQUIRED_VARS LIBSSH2_LIBRARY LIBSSH2_INCLUDE_DIR)
MARK_AS_ADVANCED(LIBSSH2_INCLUDE_DIR LIBSSH2_LIBRARY) mark_as_advanced(LIBSSH2_INCLUDE_DIR LIBSSH2_LIBRARY)
...@@ -16,23 +16,23 @@ ...@@ -16,23 +16,23 @@
# PCRE_FOUND - True if pcre found. # PCRE_FOUND - True if pcre found.
# Look for the header file. # Look for the header file.
FIND_PATH(PCRE_INCLUDE_DIR NAMES pcreposix.h) find_path(PCRE_INCLUDE_DIR NAMES pcreposix.h)
# Look for the library. # Look for the library.
FIND_LIBRARY(PCRE_LIBRARY NAMES pcre) find_library(PCRE_LIBRARY NAMES pcre)
FIND_LIBRARY(PCRE_POSIX_LIBRARY NAMES pcreposix) find_library(PCRE_POSIX_LIBRARY NAMES pcreposix)
# Handle the QUIETLY and REQUIRED arguments and set PCRE_FOUND to TRUE if all listed variables are TRUE. # Handle the QUIETLY and REQUIRED arguments and set PCRE_FOUND to TRUE if all listed variables are TRUE.
INCLUDE(FindPackageHandleStandardArgs) include(FindPackageHandleStandardArgs)
FIND_PACKAGE_HANDLE_STANDARD_ARGS(PCRE DEFAULT_MSG PCRE_LIBRARY PCRE_POSIX_LIBRARY PCRE_INCLUDE_DIR) find_package_handle_standard_args(PCRE DEFAULT_MSG PCRE_LIBRARY PCRE_POSIX_LIBRARY PCRE_INCLUDE_DIR)
# Copy the results to the output variables. # Copy the results to the output variables.
IF(PCRE_FOUND) if(PCRE_FOUND)
SET(PCRE_LIBRARIES ${PCRE_LIBRARY} ${PCRE_POSIX_LIBRARY}) set(PCRE_LIBRARIES ${PCRE_LIBRARY} ${PCRE_POSIX_LIBRARY})
SET(PCRE_INCLUDE_DIRS ${PCRE_INCLUDE_DIR}) set(PCRE_INCLUDE_DIRS ${PCRE_INCLUDE_DIR})
ELSE(PCRE_FOUND) else(PCRE_FOUND)
SET(PCRE_LIBRARIES) set(PCRE_LIBRARIES)
SET(PCRE_INCLUDE_DIRS) set(PCRE_INCLUDE_DIRS)
ENDIF(PCRE_FOUND) endif()
MARK_AS_ADVANCED(PCRE_INCLUDE_DIRS PCRE_LIBRARIES) mark_as_advanced(PCRE_INCLUDE_DIRS PCRE_LIBRARIES)
...@@ -16,22 +16,22 @@ ...@@ -16,22 +16,22 @@
# PCRE2_FOUND - True if pcre found. # PCRE2_FOUND - True if pcre found.
# Look for the header file. # Look for the header file.
FIND_PATH(PCRE2_INCLUDE_DIR NAMES pcre2posix.h) find_path(PCRE2_INCLUDE_DIR NAMES pcre2posix.h)
# Look for the library. # Look for the library.
FIND_LIBRARY(PCRE2_LIBRARY NAMES pcre2-8) find_library(PCRE2_LIBRARY NAMES pcre2-8)
# Handle the QUIETLY and REQUIRED arguments and set PCRE2_FOUND to TRUE if all listed variables are TRUE. # Handle the QUIETLY and REQUIRED arguments and set PCRE2_FOUND to TRUE if all listed variables are TRUE.
INCLUDE(FindPackageHandleStandardArgs) include(FindPackageHandleStandardArgs)
FIND_PACKAGE_HANDLE_STANDARD_ARGS(PCRE2 DEFAULT_MSG PCRE2_LIBRARY PCRE2_INCLUDE_DIR) find_package_handle_standard_args(PCRE2 DEFAULT_MSG PCRE2_LIBRARY PCRE2_INCLUDE_DIR)
# Copy the results to the output variables. # Copy the results to the output variables.
IF(PCRE2_FOUND) if(PCRE2_FOUND)
SET(PCRE2_LIBRARIES ${PCRE2_LIBRARY}) set(PCRE2_LIBRARIES ${PCRE2_LIBRARY})
SET(PCRE2_INCLUDE_DIRS ${PCRE2_INCLUDE_DIR}) set(PCRE2_INCLUDE_DIRS ${PCRE2_INCLUDE_DIR})
ELSE(PCRE2_FOUND) else(PCRE2_FOUND)
SET(PCRE2_LIBRARIES) set(PCRE2_LIBRARIES)
SET(PCRE2_INCLUDE_DIRS) set(PCRE2_INCLUDE_DIRS)
ENDIF(PCRE2_FOUND) endif()
MARK_AS_ADVANCED(PCRE2_INCLUDE_DIRS PCRE2_LIBRARIES) mark_as_advanced(PCRE2_INCLUDE_DIRS PCRE2_LIBRARIES)
INCLUDE(FindPkgConfig) include(FindPkgConfig)
# This function will find and set up a pkg-config based module. # This function will find and set up a pkg-config based module.
# If a pc-file was found, it will resolve library paths to # If a pc-file was found, it will resolve library paths to
# absolute paths. Furthermore, the function will automatically # absolute paths. Furthermore, the function will automatically
# fall back to use static libraries in case no dynamic libraries # fall back to use static libraries in case no dynamic libraries
# were found. # were found.
FUNCTION(FIND_PKGLIBRARIES prefix package) function(FIND_PKGLIBRARIES prefix package)
PKG_CHECK_MODULES(${prefix} ${package}) pkg_check_modules(${prefix} ${package})
IF(NOT ${prefix}_FOUND) if(NOT ${prefix}_FOUND)
RETURN() return()
ENDIF() endif()
FOREACH(LIBRARY ${${prefix}_LIBRARIES}) foreach(LIBRARY ${${prefix}_LIBRARIES})
FIND_LIBRARY(${LIBRARY}_RESOLVED ${LIBRARY} PATHS ${${prefix}_LIBRARY_DIRS}) find_library(${LIBRARY}_RESOLVED ${LIBRARY} PATHS ${${prefix}_LIBRARY_DIRS})
IF(${${LIBRARY}_RESOLVED} STREQUAL "${LIBRARY}_RESOLVED-NOTFOUND") if(${${LIBRARY}_RESOLVED} STREQUAL "${LIBRARY}_RESOLVED-NOTFOUND")
MESSAGE(FATAL_ERROR "could not resolve ${LIBRARY}") message(FATAL_ERROR "could not resolve ${LIBRARY}")
ENDIF() endif()
LIST(APPEND RESOLVED_LIBRARIES ${${LIBRARY}_RESOLVED}) list(APPEND RESOLVED_LIBRARIES ${${LIBRARY}_RESOLVED})
ENDFOREACH(LIBRARY) endforeach()
SET(${prefix}_FOUND 1 PARENT_SCOPE) set(${prefix}_FOUND 1 PARENT_SCOPE)
SET(${prefix}_LIBRARIES ${RESOLVED_LIBRARIES} PARENT_SCOPE) set(${prefix}_LIBRARIES ${RESOLVED_LIBRARIES} PARENT_SCOPE)
SET(${prefix}_INCLUDE_DIRS ${${prefix}_INCLUDE_DIRS} PARENT_SCOPE) set(${prefix}_INCLUDE_DIRS ${${prefix}_INCLUDE_DIRS} PARENT_SCOPE)
SET(${prefix}_LDFLAGS ${${prefix}_LDFLAGS} PARENT_SCOPE) set(${prefix}_LDFLAGS ${${prefix}_LDFLAGS} PARENT_SCOPE)
MESSAGE(STATUS " Resolved libraries: ${RESOLVED_LIBRARIES}") message(STATUS " Resolved libraries: ${RESOLVED_LIBRARIES}")
ENDFUNCTION() endfunction()
...@@ -7,22 +7,22 @@ ...@@ -7,22 +7,22 @@
# SECURITY_HAS_SSLCREATECONTEXT # SECURITY_HAS_SSLCREATECONTEXT
# #
FIND_PATH(SECURITY_INCLUDE_DIR NAMES Security/Security.h) find_path(SECURITY_INCLUDE_DIR NAMES Security/Security.h)
FIND_LIBRARY(SECURITY_LIBRARIES NAMES Security) find_library(SECURITY_LIBRARIES NAMES Security)
IF (SECURITY_INCLUDE_DIR AND SECURITY_LIBRARIES) if(SECURITY_INCLUDE_DIR AND SECURITY_LIBRARIES)
IF (NOT Security_FIND_QUIETLY) if(NOT Security_FIND_QUIETLY)
MESSAGE(STATUS "Found Security ${SECURITY_LIBRARIES}") message(STATUS "Found Security ${SECURITY_LIBRARIES}")
ENDIF() endif()
SET(SECURITY_FOUND TRUE) set(SECURITY_FOUND TRUE)
SET(SECURITY_LDFLAGS "-framework Security") set(SECURITY_LDFLAGS "-framework Security")
CHECK_LIBRARY_EXISTS("${SECURITY_LIBRARIES}" SSLCreateContext "Security/SecureTransport.h" SECURITY_HAS_SSLCREATECONTEXT) check_library_exists("${SECURITY_LIBRARIES}" SSLCreateContext "Security/SecureTransport.h" SECURITY_HAS_SSLCREATECONTEXT)
ENDIF () endif()
IF (Security_FIND_REQUIRED AND NOT SECURITY_FOUND) if(Security_FIND_REQUIRED AND NOT SECURITY_FOUND)
MESSAGE(FATAL_ERROR "Security not found") message(FATAL_ERROR "Security not found")
ENDIF() endif()
MARK_AS_ADVANCED( mark_as_advanced(
SECURITY_INCLUDE_DIR SECURITY_INCLUDE_DIR
SECURITY_LIBRARIES SECURITY_LIBRARIES
) )
INCLUDE(FeatureSummary) include(FeatureSummary)
CHECK_STRUCT_HAS_MEMBER ("struct stat" st_mtim "sys/types.h;sys/stat.h" check_struct_has_member("struct stat" st_mtim "sys/types.h;sys/stat.h"
HAVE_STRUCT_STAT_ST_MTIM LANGUAGE C) HAVE_STRUCT_STAT_ST_MTIM LANGUAGE C)
CHECK_STRUCT_HAS_MEMBER ("struct stat" st_mtimespec "sys/types.h;sys/stat.h" check_struct_has_member("struct stat" st_mtimespec "sys/types.h;sys/stat.h"
HAVE_STRUCT_STAT_ST_MTIMESPEC LANGUAGE C) HAVE_STRUCT_STAT_ST_MTIMESPEC LANGUAGE C)
CHECK_STRUCT_HAS_MEMBER("struct stat" st_mtime_nsec sys/stat.h check_struct_has_member("struct stat" st_mtime_nsec sys/stat.h
HAVE_STRUCT_STAT_MTIME_NSEC LANGUAGE C) HAVE_STRUCT_STAT_MTIME_NSEC LANGUAGE C)
IF (HAVE_STRUCT_STAT_ST_MTIM) if(HAVE_STRUCT_STAT_ST_MTIM)
CHECK_STRUCT_HAS_MEMBER("struct stat" st_mtim.tv_nsec sys/stat.h check_struct_has_member("struct stat" st_mtim.tv_nsec sys/stat.h
HAVE_STRUCT_STAT_NSEC LANGUAGE C) HAVE_STRUCT_STAT_NSEC LANGUAGE C)
ELSEIF (HAVE_STRUCT_STAT_ST_MTIMESPEC) elseif(HAVE_STRUCT_STAT_ST_MTIMESPEC)
CHECK_STRUCT_HAS_MEMBER("struct stat" st_mtimespec.tv_nsec sys/stat.h check_struct_has_member("struct stat" st_mtimespec.tv_nsec sys/stat.h
HAVE_STRUCT_STAT_NSEC LANGUAGE C) HAVE_STRUCT_STAT_NSEC LANGUAGE C)
ELSE () else()
SET( HAVE_STRUCT_STAT_NSEC ON ) set(HAVE_STRUCT_STAT_NSEC ON )
ENDIF() endif()
IF (HAVE_STRUCT_STAT_NSEC OR WIN32) add_feature_info(nanoseconds USE_NSEC "support nanosecond precision file mtimes and ctimes")
OPTION( USE_NSEC "Care about sub-second file mtimes and ctimes" ON )
ELSE()
SET(USE_NSEC OFF)
ENDIF()
ADD_FEATURE_INFO(nanoseconds USE_NSEC "whether to use sub-second file mtimes and ctimes")
INCLUDE(EnableWarnings) include(EnableWarnings)
IF (APPLE) if(APPLE)
# We cannot simply CHECK_FUNCTION_EXISTS on macOS because # We cannot simply CHECK_FUNCTION_EXISTS on macOS because
# MACOSX_DEPLOYMENT_TARGET may be set to a version in the past # MACOSX_DEPLOYMENT_TARGET may be set to a version in the past
# that doesn't have futimens. Instead we need to enable warnings # that doesn't have futimens. Instead we need to enable warnings
# as errors, then check for the symbol existing in `sys/stat.h`, # as errors, then check for the symbol existing in `sys/stat.h`,
# then reset warnings as errors. # then reset warnings as errors.
ENABLE_WARNINGS(error) enable_warnings(error)
CHECK_SYMBOL_EXISTS(futimens sys/stat.h HAVE_FUTIMENS) check_symbol_exists(futimens sys/stat.h HAVE_FUTIMENS)
DISABLE_WARNINGS(error) disable_warnings(error)
ELSE () else()
CHECK_FUNCTION_EXISTS(futimens HAVE_FUTIMENS) check_function_exists(futimens HAVE_FUTIMENS)
ENDIF () endif()
...@@ -13,81 +13,74 @@ ...@@ -13,81 +13,74 @@
# Hint # Hint
# MBEDTLS_ROOT_DIR can be pointed to a local mbedTLS installation. # MBEDTLS_ROOT_DIR can be pointed to a local mbedTLS installation.
SET(_MBEDTLS_ROOT_HINTS set(_MBEDTLS_ROOT_HINTS
${MBEDTLS_ROOT_DIR} ${MBEDTLS_ROOT_DIR}
ENV MBEDTLS_ROOT_DIR ENV MBEDTLS_ROOT_DIR)
)
SET(_MBEDTLS_ROOT_HINTS_AND_PATHS set(_MBEDTLS_ROOT_HINTS_AND_PATHS
HINTS ${_MBEDTLS_ROOT_HINTS} HINTS ${_MBEDTLS_ROOT_HINTS}
PATHS ${_MBEDTLS_ROOT_PATHS} PATHS ${_MBEDTLS_ROOT_PATHS})
)
FIND_PATH(MBEDTLS_INCLUDE_DIR find_path(MBEDTLS_INCLUDE_DIR
NAMES mbedtls/version.h NAMES mbedtls/version.h
${_MBEDTLS_ROOT_HINTS_AND_PATHS} ${_MBEDTLS_ROOT_HINTS_AND_PATHS}
PATH_SUFFIXES include PATH_SUFFIXES include)
)
IF(MBEDTLS_INCLUDE_DIR AND MBEDTLS_LIBRARIES) if(MBEDTLS_INCLUDE_DIR AND MBEDTLS_LIBRARIES)
# Already in cache, be silent # Already in cache, be silent
SET(MBEDTLS_FIND_QUIETLY TRUE) set(MBEDTLS_FIND_QUIETLY TRUE)
ENDIF() endif()
FIND_LIBRARY(MBEDTLS_LIBRARY find_library(MBEDTLS_LIBRARY
NAMES mbedtls libmbedtls NAMES mbedtls libmbedtls
${_MBEDTLS_ROOT_HINTS_AND_PATHS} ${_MBEDTLS_ROOT_HINTS_AND_PATHS}
PATH_SUFFIXES library PATH_SUFFIXES library)
) find_library(MBEDX509_LIBRARY
FIND_LIBRARY(MBEDX509_LIBRARY NAMES mbedx509 libmbedx509
NAMES mbedx509 libmbedx509 ${_MBEDTLS_ROOT_HINTS_AND_PATHS}
${_MBEDTLS_ROOT_HINTS_AND_PATHS} PATH_SUFFIXES library)
PATH_SUFFIXES library find_library(MBEDCRYPTO_LIBRARY
) NAMES mbedcrypto libmbedcrypto
FIND_LIBRARY(MBEDCRYPTO_LIBRARY ${_MBEDTLS_ROOT_HINTS_AND_PATHS}
NAMES mbedcrypto libmbedcrypto PATH_SUFFIXES library)
${_MBEDTLS_ROOT_HINTS_AND_PATHS}
PATH_SUFFIXES library
)
IF(MBEDTLS_INCLUDE_DIR AND MBEDTLS_LIBRARY AND MBEDX509_LIBRARY AND MBEDCRYPTO_LIBRARY) if(MBEDTLS_INCLUDE_DIR AND MBEDTLS_LIBRARY AND MBEDX509_LIBRARY AND MBEDCRYPTO_LIBRARY)
SET(MBEDTLS_FOUND TRUE) set(MBEDTLS_FOUND TRUE)
ENDIF() endif()
IF(MBEDTLS_FOUND) if(MBEDTLS_FOUND)
# split mbedTLS into -L and -l linker options, so we can set them for pkg-config # split mbedTLS into -L and -l linker options, so we can set them for pkg-config
GET_FILENAME_COMPONENT(MBEDTLS_LIBRARY_DIR ${MBEDTLS_LIBRARY} PATH) get_filename_component(MBEDTLS_LIBRARY_DIR ${MBEDTLS_LIBRARY} PATH)
GET_FILENAME_COMPONENT(MBEDTLS_LIBRARY_FILE ${MBEDTLS_LIBRARY} NAME_WE) get_filename_component(MBEDTLS_LIBRARY_FILE ${MBEDTLS_LIBRARY} NAME_WE)
GET_FILENAME_COMPONENT(MBEDX509_LIBRARY_FILE ${MBEDX509_LIBRARY} NAME_WE) get_filename_component(MBEDX509_LIBRARY_FILE ${MBEDX509_LIBRARY} NAME_WE)
GET_FILENAME_COMPONENT(MBEDCRYPTO_LIBRARY_FILE ${MBEDCRYPTO_LIBRARY} NAME_WE) get_filename_component(MBEDCRYPTO_LIBRARY_FILE ${MBEDCRYPTO_LIBRARY} NAME_WE)
STRING(REGEX REPLACE "^lib" "" MBEDTLS_LIBRARY_FILE ${MBEDTLS_LIBRARY_FILE}) string(REGEX REPLACE "^lib" "" MBEDTLS_LIBRARY_FILE ${MBEDTLS_LIBRARY_FILE})
STRING(REGEX REPLACE "^lib" "" MBEDX509_LIBRARY_FILE ${MBEDX509_LIBRARY_FILE}) string(REGEX REPLACE "^lib" "" MBEDX509_LIBRARY_FILE ${MBEDX509_LIBRARY_FILE})
STRING(REGEX REPLACE "^lib" "" MBEDCRYPTO_LIBRARY_FILE ${MBEDCRYPTO_LIBRARY_FILE}) string(REGEX REPLACE "^lib" "" MBEDCRYPTO_LIBRARY_FILE ${MBEDCRYPTO_LIBRARY_FILE})
SET(MBEDTLS_LIBRARIES "-L${MBEDTLS_LIBRARY_DIR} -l${MBEDTLS_LIBRARY_FILE} -l${MBEDX509_LIBRARY_FILE} -l${MBEDCRYPTO_LIBRARY_FILE}") set(MBEDTLS_LIBRARIES "-L${MBEDTLS_LIBRARY_DIR} -l${MBEDTLS_LIBRARY_FILE} -l${MBEDX509_LIBRARY_FILE} -l${MBEDCRYPTO_LIBRARY_FILE}")
IF(NOT MBEDTLS_FIND_QUIETLY) if(NOT MBEDTLS_FIND_QUIETLY)
MESSAGE(STATUS "Found mbedTLS:") message(STATUS "Found mbedTLS:")
FILE(READ ${MBEDTLS_INCLUDE_DIR}/mbedtls/version.h MBEDTLSCONTENT) file(READ ${MBEDTLS_INCLUDE_DIR}/mbedtls/version.h MBEDTLSCONTENT)
STRING(REGEX MATCH "MBEDTLS_VERSION_STRING +\"[0-9|.]+\"" MBEDTLSMATCH ${MBEDTLSCONTENT}) string(REGEX MATCH "MBEDTLS_VERSION_STRING +\"[0-9|.]+\"" MBEDTLSMATCH ${MBEDTLSCONTENT})
IF (MBEDTLSMATCH) if(MBEDTLSMATCH)
STRING(REGEX REPLACE "MBEDTLS_VERSION_STRING +\"([0-9|.]+)\"" "\\1" MBEDTLS_VERSION ${MBEDTLSMATCH}) string(REGEX REPLACE "MBEDTLS_VERSION_STRING +\"([0-9|.]+)\"" "\\1" MBEDTLS_VERSION ${MBEDTLSMATCH})
MESSAGE(STATUS " version ${MBEDTLS_VERSION}") message(STATUS " version ${MBEDTLS_VERSION}")
ENDIF(MBEDTLSMATCH) endif()
MESSAGE(STATUS " TLS: ${MBEDTLS_LIBRARY}") message(STATUS " TLS: ${MBEDTLS_LIBRARY}")
MESSAGE(STATUS " X509: ${MBEDX509_LIBRARY}") message(STATUS " X509: ${MBEDX509_LIBRARY}")
MESSAGE(STATUS " Crypto: ${MBEDCRYPTO_LIBRARY}") message(STATUS " Crypto: ${MBEDCRYPTO_LIBRARY}")
ENDIF(NOT MBEDTLS_FIND_QUIETLY) endif()
ELSE(MBEDTLS_FOUND) else(MBEDTLS_FOUND)
IF(MBEDTLS_FIND_REQUIRED) if(MBEDTLS_FIND_REQUIRED)
MESSAGE(FATAL_ERROR "Could not find mbedTLS") message(FATAL_ERROR "Could not find mbedTLS")
ENDIF(MBEDTLS_FIND_REQUIRED) endif()
ENDIF(MBEDTLS_FOUND) endif()
MARK_AS_ADVANCED( mark_as_advanced(
MBEDTLS_INCLUDE_DIR MBEDTLS_INCLUDE_DIR
MBEDTLS_LIBRARY_DIR MBEDTLS_LIBRARY_DIR
MBEDTLS_LIBRARIES MBEDTLS_LIBRARIES
MBEDTLS_LIBRARY MBEDTLS_LIBRARY
MBEDX509_LIBRARY MBEDX509_LIBRARY
MBEDCRYPTO_LIBRARY MBEDCRYPTO_LIBRARY)
)
# This function splits the sources files up into their appropriate # This function splits the sources files up into their appropriate
# subdirectories. This is especially useful for IDEs like Xcode and # subdirectories. This is especially useful for IDEs like Xcode and
# Visual Studio, so that you can navigate into the libgit2_clar project, # Visual Studio, so that you can navigate into the libgit2_tests project,
# and see the folders within the tests folder (instead of just seeing all # and see the folders within the tests folder (instead of just seeing all
# source and tests in a single folder.) # source and tests in a single folder.)
FUNCTION(IDE_SPLIT_SOURCES target) function(IDE_SPLIT_SOURCES target)
IF(MSVC_IDE OR CMAKE_GENERATOR STREQUAL Xcode) if(MSVC_IDE OR CMAKE_GENERATOR STREQUAL Xcode)
GET_TARGET_PROPERTY(sources ${target} SOURCES) get_target_property(sources ${target} SOURCES)
FOREACH(source ${sources}) foreach(source ${sources})
IF(source MATCHES ".*/") if(source MATCHES ".*/")
STRING(REPLACE ${libgit2_SOURCE_DIR}/ "" rel ${source}) string(REPLACE ${libgit2_SOURCE_DIR}/ "" rel ${source})
IF(rel) if(rel)
STRING(REGEX REPLACE "/([^/]*)$" "" rel ${rel}) string(REGEX REPLACE "/([^/]*)$" "" rel ${rel})
IF(rel) if(rel)
STRING(REPLACE "/" "\\\\" rel ${rel}) string(REPLACE "/" "\\\\" rel ${rel})
SOURCE_GROUP(${rel} FILES ${source}) source_group(${rel} FILES ${source})
ENDIF() endif()
ENDIF() endif()
ENDIF() endif()
ENDFOREACH() endforeach()
ENDIF() endif()
ENDFUNCTION() endfunction()
...@@ -2,76 +2,76 @@ ...@@ -2,76 +2,76 @@
# #
function(pkg_build_config) function(pkg_build_config)
set(options) set(options)
set(oneValueArgs NAME DESCRIPTION VERSION FILENAME LIBS_SELF) set(oneValueArgs NAME DESCRIPTION VERSION FILENAME LIBS_SELF)
set(multiValueArgs LIBS PRIVATE_LIBS REQUIRES CFLAGS) set(multiValueArgs LIBS PRIVATE_LIBS REQUIRES CFLAGS)
cmake_parse_arguments(PKGCONFIG "${options}" "${oneValueArgs}" "${multiValueArgs}" ${ARGN}) cmake_parse_arguments(PKGCONFIG "${options}" "${oneValueArgs}" "${multiValueArgs}" ${ARGN})
if (NOT DEFINED PKGCONFIG_FILENAME AND DEFINED PKGCONFIG_NAME) if (NOT DEFINED PKGCONFIG_FILENAME AND DEFINED PKGCONFIG_NAME)
set(PKGCONFIG_FILENAME ${PKGCONFIG_NAME}) set(PKGCONFIG_FILENAME ${PKGCONFIG_NAME})
endif() endif()
if (NOT DEFINED PKGCONFIG_FILENAME) if (NOT DEFINED PKGCONFIG_FILENAME)
message(FATAL_ERROR "Missing FILENAME argument") message(FATAL_ERROR "Missing FILENAME argument")
endif() endif()
set(PKGCONFIG_FILE "${PROJECT_BINARY_DIR}/${PKGCONFIG_FILENAME}.pc") set(PKGCONFIG_FILE "${PROJECT_BINARY_DIR}/${PKGCONFIG_FILENAME}.pc")
if (NOT DEFINED PKGCONFIG_DESCRIPTION) if (NOT DEFINED PKGCONFIG_DESCRIPTION)
message(FATAL_ERROR "Missing DESCRIPTION argument") message(FATAL_ERROR "Missing DESCRIPTION argument")
endif() endif()
if (NOT DEFINED PKGCONFIG_VERSION) if (NOT DEFINED PKGCONFIG_VERSION)
message(FATAL_ERROR "Missing VERSION argument") message(FATAL_ERROR "Missing VERSION argument")
endif() endif()
# Write .pc "header" # Write .pc "header"
file(WRITE "${PKGCONFIG_FILE}" file(WRITE "${PKGCONFIG_FILE}"
"prefix=\"${CMAKE_INSTALL_PREFIX}\"\n" "prefix=\"${CMAKE_INSTALL_PREFIX}\"\n"
"libdir=\"${CMAKE_INSTALL_FULL_LIBDIR}\"\n" "libdir=\"${CMAKE_INSTALL_FULL_LIBDIR}\"\n"
"includedir=\"${CMAKE_INSTALL_FULL_INCLUDEDIR}\"\n" "includedir=\"${CMAKE_INSTALL_FULL_INCLUDEDIR}\"\n"
"\n" "\n"
"Name: ${PKGCONFIG_NAME}\n" "Name: ${PKGCONFIG_NAME}\n"
"Description: ${PKGCONFIG_DESCRIPTION}\n" "Description: ${PKGCONFIG_DESCRIPTION}\n"
"Version: ${PKGCONFIG_VERSION}\n" "Version: ${PKGCONFIG_VERSION}\n"
) )
# Prepare Libs # Prepare Libs
if(NOT DEFINED PKGCONFIG_LIBS_SELF) if(NOT DEFINED PKGCONFIG_LIBS_SELF)
set(PKGCONFIG_LIBS_SELF "${PKGCONFIG_FILE}") set(PKGCONFIG_LIBS_SELF "${PKGCONFIG_FILE}")
endif() endif()
if(NOT DEFINED PKGCONFIG_LIBS) if(NOT DEFINED PKGCONFIG_LIBS)
set(PKGCONFIG_LIBS "-l${PKGCONFIG_LIBS_SELF}") set(PKGCONFIG_LIBS "-l${PKGCONFIG_LIBS_SELF}")
else() else()
list(INSERT PKGCONFIG_LIBS 0 "-l${PKGCONFIG_LIBS_SELF}") list(INSERT PKGCONFIG_LIBS 0 "-l${PKGCONFIG_LIBS_SELF}")
endif() endif()
list(REMOVE_DUPLICATES PKGCONFIG_LIBS) list(REMOVE_DUPLICATES PKGCONFIG_LIBS)
string(REPLACE ";" " " PKGCONFIG_LIBS "${PKGCONFIG_LIBS}") string(REPLACE ";" " " PKGCONFIG_LIBS "${PKGCONFIG_LIBS}")
file(APPEND "${PKGCONFIG_FILE}" "Libs: -L\${libdir} ${PKGCONFIG_LIBS}\n") file(APPEND "${PKGCONFIG_FILE}" "Libs: -L\${libdir} ${PKGCONFIG_LIBS}\n")
# Prepare Libs.private # Prepare Libs.private
if(DEFINED PKGCONFIG_PRIVATE_LIBS) if(DEFINED PKGCONFIG_PRIVATE_LIBS)
list(REMOVE_DUPLICATES PKGCONFIG_PRIVATE_LIBS) list(REMOVE_DUPLICATES PKGCONFIG_PRIVATE_LIBS)
string(REPLACE ";" " " PKGCONFIG_PRIVATE_LIBS "${PKGCONFIG_PRIVATE_LIBS}") string(REPLACE ";" " " PKGCONFIG_PRIVATE_LIBS "${PKGCONFIG_PRIVATE_LIBS}")
file(APPEND "${PKGCONFIG_FILE}" "Libs.private: ${PKGCONFIG_PRIVATE_LIBS}\n") file(APPEND "${PKGCONFIG_FILE}" "Libs.private: ${PKGCONFIG_PRIVATE_LIBS}\n")
endif() endif()
# Prepare Requires.private # Prepare Requires.private
if(DEFINED PKGCONFIG_REQUIRES) if(DEFINED PKGCONFIG_REQUIRES)
list(REMOVE_DUPLICATES PKGCONFIG_REQUIRES) list(REMOVE_DUPLICATES PKGCONFIG_REQUIRES)
string(REPLACE ";" " " PKGCONFIG_REQUIRES "${PKGCONFIG_REQUIRES}") string(REPLACE ";" " " PKGCONFIG_REQUIRES "${PKGCONFIG_REQUIRES}")
file(APPEND "${PKGCONFIG_FILE}" "Requires.private: ${PKGCONFIG_REQUIRES}\n") file(APPEND "${PKGCONFIG_FILE}" "Requires.private: ${PKGCONFIG_REQUIRES}\n")
endif() endif()
# Prepare Cflags # Prepare Cflags
if(DEFINED PKGCONFIG_CFLAGS) if(DEFINED PKGCONFIG_CFLAGS)
string(REPLACE ";" " " PKGCONFIG_CFLAGS "${PKGCONFIG_CFLAGS}") string(REPLACE ";" " " PKGCONFIG_CFLAGS "${PKGCONFIG_CFLAGS}")
else() else()
set(PKGCONFIG_CFLAGS "") set(PKGCONFIG_CFLAGS "")
endif() endif()
file(APPEND "${PKGCONFIG_FILE}" "Cflags: -I\${includedir} ${PKGCONFIG_CFLAGS}\n") file(APPEND "${PKGCONFIG_FILE}" "Cflags: -I\${includedir} ${PKGCONFIG_CFLAGS}\n")
# Install .pc file # Install .pc file
install(FILES "${PKGCONFIG_FILE}" DESTINATION "${CMAKE_INSTALL_LIBDIR}/pkgconfig") install(FILES "${PKGCONFIG_FILE}" DESTINATION "${CMAKE_INSTALL_LIBDIR}/pkgconfig")
endfunction() endfunction()
FUNCTION(SanitizeBool VAR) function(SanitizeBool VAR)
STRING(TOLOWER "${${VAR}}" VALUE) string(TOLOWER "${${VAR}}" VALUE)
IF(VALUE STREQUAL "on") if(VALUE STREQUAL "on")
SET(${VAR} "ON" PARENT_SCOPE) set(${VAR} "ON" PARENT_SCOPE)
ELSEIF(VALUE STREQUAL "yes") elseif(VALUE STREQUAL "yes")
SET(${VAR} "ON" PARENT_SCOPE) set(${VAR} "ON" PARENT_SCOPE)
ELSEIF(VALUE STREQUAL "true") elseif(VALUE STREQUAL "true")
SET(${VAR} "ON" PARENT_SCOPE) set(${VAR} "ON" PARENT_SCOPE)
ELSEIF(VALUE STREQUAL "1") elseif(VALUE STREQUAL "1")
SET(${VAR} "ON" PARENT_SCOPE) set(${VAR} "ON" PARENT_SCOPE)
ELSEIF(VALUE STREQUAL "off") elseif(VALUE STREQUAL "off")
SET(${VAR} "OFF" PARENT_SCOPE) set(${VAR} "OFF" PARENT_SCOPE)
ELSEIF(VALUE STREQUAL "no") elseif(VALUE STREQUAL "no")
SET(${VAR} "OFF" PARENT_SCOPE) set(${VAR} "OFF" PARENT_SCOPE)
ELSEIF(VALUE STREQUAL "false") elseif(VALUE STREQUAL "false")
SET(${VAR} "OFF" PARENT_SCOPE) set(${VAR} "OFF" PARENT_SCOPE)
ELSEIF(VALUE STREQUAL "0") elseif(VALUE STREQUAL "0")
SET(${VAR} "OFF" PARENT_SCOPE) set(${VAR} "OFF" PARENT_SCOPE)
ENDIF() endif()
ENDFUNCTION() endfunction()
INCLUDE(SanitizeBool) include(SanitizeBool)
# We try to find any packages our backends might use # We try to find any packages our backends might use
FIND_PACKAGE(GSSAPI) find_package(GSSAPI)
IF (CMAKE_SYSTEM_NAME MATCHES "Darwin") if(CMAKE_SYSTEM_NAME MATCHES "Darwin")
INCLUDE(FindGSSFramework) include(FindGSSFramework)
ENDIF() endif()
IF(USE_GSSAPI) if(USE_GSSAPI)
# Auto-select GSS backend # Auto-select GSS backend
SanitizeBool(USE_GSSAPI) sanitizebool(USE_GSSAPI)
IF (USE_GSSAPI STREQUAL ON) if(USE_GSSAPI STREQUAL ON)
IF (GSSFRAMEWORK_FOUND) if(GSSFRAMEWORK_FOUND)
SET(USE_GSSAPI "GSS.framework") set(USE_GSSAPI "GSS.framework")
ELSEIF(GSSAPI_FOUND) elseif(GSSAPI_FOUND)
SET(USE_GSSAPI "gssapi") set(USE_GSSAPI "gssapi")
ELSE() else()
MESSAGE(FATAL_ERROR "Unable to autodetect a usable GSS backend." message(FATAL_ERROR "Unable to autodetect a usable GSS backend."
"Please pass the backend name explicitly (-DUSE_GSS=backend)") "Please pass the backend name explicitly (-DUSE_GSS=backend)")
ENDIF() endif()
ENDIF() endif()
# Check that we can find what's required for the selected backend # Check that we can find what's required for the selected backend
IF (USE_GSSAPI STREQUAL "GSS.framework") if(USE_GSSAPI STREQUAL "GSS.framework")
IF (NOT GSSFRAMEWORK_FOUND) if(NOT GSSFRAMEWORK_FOUND)
MESSAGE(FATAL_ERROR "Asked for GSS.framework backend, but it wasn't found") message(FATAL_ERROR "Asked for GSS.framework backend, but it wasn't found")
ENDIF() endif()
LIST(APPEND LIBGIT2_LIBS ${GSSFRAMEWORK_LIBRARIES}) list(APPEND LIBGIT2_SYSTEM_LIBS ${GSSFRAMEWORK_LIBRARIES})
SET(GIT_GSSFRAMEWORK 1) set(GIT_GSSFRAMEWORK 1)
ADD_FEATURE_INFO(SPNEGO GIT_GSSFRAMEWORK "SPNEGO authentication support (${USE_GSSAPI})") add_feature_info(SPNEGO GIT_GSSFRAMEWORK "SPNEGO authentication support (${USE_GSSAPI})")
ELSEIF (USE_GSSAPI STREQUAL "gssapi") elseif(USE_GSSAPI STREQUAL "gssapi")
IF (NOT GSSAPI_FOUND) if(NOT GSSAPI_FOUND)
MESSAGE(FATAL_ERROR "Asked for gssapi GSS backend, but it wasn't found") message(FATAL_ERROR "Asked for gssapi GSS backend, but it wasn't found")
ENDIF() endif()
LIST(APPEND LIBGIT2_LIBS ${GSSAPI_LIBRARIES}) list(APPEND LIBGIT2_SYSTEM_LIBS ${GSSAPI_LIBRARIES})
SET(GIT_GSSAPI 1) set(GIT_GSSAPI 1)
ADD_FEATURE_INFO(SPNEGO GIT_GSSAPI "SPNEGO authentication support (${USE_GSSAPI})") add_feature_info(SPNEGO GIT_GSSAPI "SPNEGO authentication support (${USE_GSSAPI})")
ELSE() else()
MESSAGE(FATAL_ERROR "Asked for backend ${USE_GSSAPI} but it wasn't found") message(FATAL_ERROR "Asked for backend ${USE_GSSAPI} but it wasn't found")
ENDIF() endif()
ELSE() else()
SET(GIT_GSSAPI 0) set(GIT_GSSAPI 0)
ADD_FEATURE_INFO(SPNEGO NO "SPNEGO authentication support") add_feature_info(SPNEGO NO "SPNEGO authentication support")
ENDIF() endif()
# 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_DEPENDENCY_INCLUDES "${libgit2_SOURCE_DIR}/deps/http-parser")
list(APPEND LIBGIT2_DEPENDENCY_OBJECTS "$<TARGET_OBJECTS:http-parser>")
add_feature_info(http-parser ON "http-parser support (bundled)")
endif()
INCLUDE(SanitizeBool) include(SanitizeBool)
# We try to find any packages our backends might use # We try to find any packages our backends might use
FIND_PACKAGE(OpenSSL) find_package(OpenSSL)
FIND_PACKAGE(mbedTLS) find_package(mbedTLS)
IF (CMAKE_SYSTEM_NAME MATCHES "Darwin") if(CMAKE_SYSTEM_NAME MATCHES "Darwin")
FIND_PACKAGE(Security) find_package(Security)
FIND_PACKAGE(CoreFoundation) find_package(CoreFoundation)
ENDIF() endif()
IF(USE_HTTPS) if(USE_HTTPS)
# Auto-select TLS backend # Auto-select TLS backend
SanitizeBool(USE_HTTPS) sanitizebool(USE_HTTPS)
IF (USE_HTTPS STREQUAL ON) if(USE_HTTPS STREQUAL ON)
IF (SECURITY_FOUND) if(SECURITY_FOUND)
IF (SECURITY_HAS_SSLCREATECONTEXT) if(SECURITY_HAS_SSLCREATECONTEXT)
SET(USE_HTTPS "SecureTransport") set(USE_HTTPS "SecureTransport")
ELSE() else()
MESSAGE(STATUS "Security framework is too old, falling back to OpenSSL") message(STATUS "Security framework is too old, falling back to OpenSSL")
SET(USE_HTTPS "OpenSSL") set(USE_HTTPS "OpenSSL")
ENDIF() endif()
ELSEIF (WINHTTP) elseif(USE_WINHTTP)
SET(USE_HTTPS "WinHTTP") set(USE_HTTPS "WinHTTP")
ELSEIF(OPENSSL_FOUND) elseif(OPENSSL_FOUND)
SET(USE_HTTPS "OpenSSL") set(USE_HTTPS "OpenSSL")
ELSEIF(MBEDTLS_FOUND) elseif(MBEDTLS_FOUND)
SET(USE_HTTPS "mbedTLS") set(USE_HTTPS "mbedTLS")
ELSE() else()
MESSAGE(FATAL_ERROR "Unable to autodetect a usable HTTPS backend." message(FATAL_ERROR "Unable to autodetect a usable HTTPS backend."
"Please pass the backend name explicitly (-DUSE_HTTPS=backend)") "Please pass the backend name explicitly (-DUSE_HTTPS=backend)")
ENDIF() endif()
ENDIF() endif()
# Check that we can find what's required for the selected backend # Check that we can find what's required for the selected backend
IF (USE_HTTPS STREQUAL "SecureTransport") if(USE_HTTPS STREQUAL "SecureTransport")
IF (NOT COREFOUNDATION_FOUND) if(NOT COREFOUNDATION_FOUND)
MESSAGE(FATAL_ERROR "Cannot use SecureTransport backend, CoreFoundation.framework not found") message(FATAL_ERROR "Cannot use SecureTransport backend, CoreFoundation.framework not found")
ENDIF() endif()
IF (NOT SECURITY_FOUND) if(NOT SECURITY_FOUND)
MESSAGE(FATAL_ERROR "Cannot use SecureTransport backend, Security.framework not found") message(FATAL_ERROR "Cannot use SecureTransport backend, Security.framework not found")
ENDIF() endif()
IF (NOT SECURITY_HAS_SSLCREATECONTEXT) if(NOT SECURITY_HAS_SSLCREATECONTEXT)
MESSAGE(FATAL_ERROR "Cannot use SecureTransport backend, SSLCreateContext not supported") message(FATAL_ERROR "Cannot use SecureTransport backend, SSLCreateContext not supported")
ENDIF() endif()
SET(GIT_SECURE_TRANSPORT 1) set(GIT_SECURE_TRANSPORT 1)
LIST(APPEND LIBGIT2_SYSTEM_INCLUDES ${SECURITY_INCLUDE_DIR}) list(APPEND LIBGIT2_SYSTEM_INCLUDES ${SECURITY_INCLUDE_DIR})
LIST(APPEND LIBGIT2_LIBS ${COREFOUNDATION_LDFLAGS} ${SECURITY_LDFLAGS}) list(APPEND LIBGIT2_SYSTEM_LIBS ${COREFOUNDATION_LDFLAGS} ${SECURITY_LDFLAGS})
LIST(APPEND LIBGIT2_PC_LIBS ${COREFOUNDATION_LDFLAGS} ${SECURITY_LDFLAGS}) list(APPEND LIBGIT2_PC_LIBS ${COREFOUNDATION_LDFLAGS} ${SECURITY_LDFLAGS})
ELSEIF (USE_HTTPS STREQUAL "OpenSSL") elseif(USE_HTTPS STREQUAL "OpenSSL")
IF (NOT OPENSSL_FOUND) if(NOT OPENSSL_FOUND)
MESSAGE(FATAL_ERROR "Asked for OpenSSL TLS backend, but it wasn't found") message(FATAL_ERROR "Asked for OpenSSL TLS backend, but it wasn't found")
ENDIF() endif()
SET(GIT_OPENSSL 1) set(GIT_OPENSSL 1)
LIST(APPEND LIBGIT2_SYSTEM_INCLUDES ${OPENSSL_INCLUDE_DIR}) list(APPEND LIBGIT2_SYSTEM_INCLUDES ${OPENSSL_INCLUDE_DIR})
LIST(APPEND LIBGIT2_LIBS ${OPENSSL_LIBRARIES}) list(APPEND LIBGIT2_SYSTEM_LIBS ${OPENSSL_LIBRARIES})
LIST(APPEND LIBGIT2_PC_LIBS ${OPENSSL_LDFLAGS}) list(APPEND LIBGIT2_PC_LIBS ${OPENSSL_LDFLAGS})
LIST(APPEND LIBGIT2_PC_REQUIRES "openssl") list(APPEND LIBGIT2_PC_REQUIRES "openssl")
ELSEIF(USE_HTTPS STREQUAL "mbedTLS") elseif(USE_HTTPS STREQUAL "mbedTLS")
IF (NOT MBEDTLS_FOUND) if(NOT MBEDTLS_FOUND)
MESSAGE(FATAL_ERROR "Asked for mbedTLS backend, but it wasn't found") message(FATAL_ERROR "Asked for mbedTLS backend, but it wasn't found")
ENDIF() endif()
IF(NOT CERT_LOCATION) if(NOT CERT_LOCATION)
MESSAGE(STATUS "Auto-detecting default certificates location") message(STATUS "Auto-detecting default certificates location")
IF(CMAKE_SYSTEM_NAME MATCHES Darwin) if(CMAKE_SYSTEM_NAME MATCHES Darwin)
# Check for an Homebrew installation # Check for an Homebrew installation
SET(OPENSSL_CMD "/usr/local/opt/openssl/bin/openssl") set(OPENSSL_CMD "/usr/local/opt/openssl/bin/openssl")
ELSE() else()
SET(OPENSSL_CMD "openssl") set(OPENSSL_CMD "openssl")
ENDIF() endif()
EXECUTE_PROCESS(COMMAND ${OPENSSL_CMD} version -d OUTPUT_VARIABLE OPENSSL_DIR OUTPUT_STRIP_TRAILING_WHITESPACE) execute_process(COMMAND ${OPENSSL_CMD} version -d OUTPUT_VARIABLE OPENSSL_DIR OUTPUT_STRIP_TRAILING_WHITESPACE)
IF(OPENSSL_DIR) if(OPENSSL_DIR)
STRING(REGEX REPLACE "^OPENSSLDIR: \"(.*)\"$" "\\1/" OPENSSL_DIR ${OPENSSL_DIR}) string(REGEX REPLACE "^OPENSSLDIR: \"(.*)\"$" "\\1/" OPENSSL_DIR ${OPENSSL_DIR})
SET(OPENSSL_CA_LOCATIONS set(OPENSSL_CA_LOCATIONS
"ca-bundle.pem" # OpenSUSE Leap 42.1 "ca-bundle.pem" # OpenSUSE Leap 42.1
"cert.pem" # Ubuntu 14.04, FreeBSD "cert.pem" # Ubuntu 14.04, FreeBSD
"certs/ca-certificates.crt" # Ubuntu 16.04 "certs/ca-certificates.crt" # Ubuntu 16.04
"certs/ca.pem" # Debian 7 "certs/ca.pem" # Debian 7
) )
FOREACH(SUFFIX IN LISTS OPENSSL_CA_LOCATIONS) foreach(SUFFIX IN LISTS OPENSSL_CA_LOCATIONS)
SET(LOC "${OPENSSL_DIR}${SUFFIX}") set(LOC "${OPENSSL_DIR}${SUFFIX}")
IF(NOT CERT_LOCATION AND EXISTS "${OPENSSL_DIR}${SUFFIX}") if(NOT CERT_LOCATION AND EXISTS "${OPENSSL_DIR}${SUFFIX}")
SET(CERT_LOCATION ${LOC}) set(CERT_LOCATION ${LOC})
ENDIF() endif()
ENDFOREACH() endforeach()
ELSE() else()
MESSAGE(FATAL_ERROR "Unable to find OpenSSL executable. Please provide default certificate location via CERT_LOCATION") message(FATAL_ERROR "Unable to find OpenSSL executable. Please provide default certificate location via CERT_LOCATION")
ENDIF() endif()
ENDIF() endif()
IF(CERT_LOCATION) if(CERT_LOCATION)
IF(NOT EXISTS ${CERT_LOCATION}) if(NOT EXISTS ${CERT_LOCATION})
MESSAGE(FATAL_ERROR "Cannot use CERT_LOCATION=${CERT_LOCATION} as it doesn't exist") message(FATAL_ERROR "Cannot use CERT_LOCATION=${CERT_LOCATION} as it doesn't exist")
ENDIF() endif()
ADD_FEATURE_INFO(CERT_LOCATION ON "using certificates from ${CERT_LOCATION}") add_feature_info(CERT_LOCATION ON "using certificates from ${CERT_LOCATION}")
ADD_DEFINITIONS(-DGIT_DEFAULT_CERT_LOCATION="${CERT_LOCATION}") add_definitions(-DGIT_DEFAULT_CERT_LOCATION="${CERT_LOCATION}")
ENDIF() endif()
SET(GIT_MBEDTLS 1) set(GIT_MBEDTLS 1)
LIST(APPEND LIBGIT2_SYSTEM_INCLUDES ${MBEDTLS_INCLUDE_DIR}) list(APPEND LIBGIT2_SYSTEM_INCLUDES ${MBEDTLS_INCLUDE_DIR})
LIST(APPEND LIBGIT2_LIBS ${MBEDTLS_LIBRARIES}) list(APPEND LIBGIT2_SYSTEM_LIBS ${MBEDTLS_LIBRARIES})
# mbedTLS has no pkgconfig file, hence we can't require it # mbedTLS has no pkgconfig file, hence we can't require it
# https://github.com/ARMmbed/mbedtls/issues/228 # https://github.com/ARMmbed/mbedtls/issues/228
# For now, pass its link flags as our own # For now, pass its link flags as our own
LIST(APPEND LIBGIT2_PC_LIBS ${MBEDTLS_LIBRARIES}) list(APPEND LIBGIT2_PC_LIBS ${MBEDTLS_LIBRARIES})
ELSEIF (USE_HTTPS STREQUAL "WinHTTP") elseif(USE_HTTPS STREQUAL "WinHTTP")
# WinHTTP setup was handled in the WinHTTP-specific block above # WinHTTP setup was handled in the WinHTTP-specific block above
ELSEIF (USE_HTTPS STREQUAL "OpenSSL-Dynamic") elseif(USE_HTTPS STREQUAL "OpenSSL-Dynamic")
SET(GIT_OPENSSL 1) set(GIT_OPENSSL 1)
SET(GIT_OPENSSL_DYNAMIC 1) set(GIT_OPENSSL_DYNAMIC 1)
LIST(APPEND LIBGIT2_LIBS dl) list(APPEND LIBGIT2_SYSTEM_LIBS dl)
ELSE() else()
MESSAGE(FATAL_ERROR "Asked for backend ${USE_HTTPS} but it wasn't found") message(FATAL_ERROR "Asked for backend ${USE_HTTPS} but it wasn't found")
ENDIF() endif()
SET(GIT_HTTPS 1) set(GIT_HTTPS 1)
ADD_FEATURE_INFO(HTTPS GIT_HTTPS "using ${USE_HTTPS}") add_feature_info(HTTPS GIT_HTTPS "using ${USE_HTTPS}")
ELSE() else()
SET(GIT_HTTPS 0) set(GIT_HTTPS 0)
ADD_FEATURE_INFO(HTTPS NO "") add_feature_info(HTTPS NO "")
ENDIF() endif()
# Select a hash backend # Select a hash backend
INCLUDE(SanitizeBool) include(SanitizeBool)
# USE_SHA1=CollisionDetection(ON)/HTTPS/Generic/OFF # USE_SHA1=CollisionDetection(ON)/HTTPS/Generic/OFF
sanitizebool(USE_SHA1)
SanitizeBool(USE_SHA1) if(USE_SHA1 STREQUAL ON)
IF(USE_SHA1 STREQUAL ON)
SET(USE_SHA1 "CollisionDetection") SET(USE_SHA1 "CollisionDetection")
ELSEIF(USE_SHA1 STREQUAL "HTTPS") elseif(USE_SHA1 STREQUAL "HTTPS")
IF(USE_HTTPS STREQUAL "SecureTransport") if(USE_HTTPS STREQUAL "SecureTransport")
SET(USE_SHA1 "CommonCrypto") set(USE_SHA1 "CommonCrypto")
ELSEIF(USE_HTTPS STREQUAL "WinHTTP") elseif(USE_HTTPS STREQUAL "WinHTTP")
SET(USE_SHA1 "Win32") set(USE_SHA1 "Win32")
ELSEIF(USE_HTTPS) elseif(USE_HTTPS)
SET(USE_SHA1 ${USE_HTTPS}) set(USE_SHA1 ${USE_HTTPS})
ELSE() else()
SET(USE_SHA1 "CollisionDetection") set(USE_SHA1 "CollisionDetection")
ENDIF() endif()
ENDIF() endif()
IF(USE_SHA1 STREQUAL "CollisionDetection") if(USE_SHA1 STREQUAL "CollisionDetection")
SET(GIT_SHA1_COLLISIONDETECT 1) set(GIT_SHA1_COLLISIONDETECT 1)
ADD_DEFINITIONS(-DSHA1DC_NO_STANDARD_INCLUDES=1) add_definitions(-DSHA1DC_NO_STANDARD_INCLUDES=1)
ADD_DEFINITIONS(-DSHA1DC_CUSTOM_INCLUDE_SHA1_C=\"common.h\") add_definitions(-DSHA1DC_CUSTOM_INCLUDE_SHA1_C=\"common.h\")
ADD_DEFINITIONS(-DSHA1DC_CUSTOM_INCLUDE_UBC_CHECK_C=\"common.h\") add_definitions(-DSHA1DC_CUSTOM_INCLUDE_UBC_CHECK_C=\"common.h\")
FILE(GLOB SRC_SHA1 hash/sha1/collisiondetect.* hash/sha1/sha1dc/*) elseif(USE_SHA1 STREQUAL "OpenSSL")
ELSEIF(USE_SHA1 STREQUAL "OpenSSL")
# OPENSSL_FOUND should already be set, we're checking USE_HTTPS # OPENSSL_FOUND should already be set, we're checking USE_HTTPS
SET(GIT_SHA1_OPENSSL 1) set(GIT_SHA1_OPENSSL 1)
IF(CMAKE_SYSTEM_NAME MATCHES "FreeBSD") if(CMAKE_SYSTEM_NAME MATCHES "FreeBSD")
LIST(APPEND LIBGIT2_PC_LIBS "-lssl") list(APPEND LIBGIT2_PC_LIBS "-lssl")
ELSE() else()
LIST(APPEND LIBGIT2_PC_REQUIRES "openssl") list(APPEND LIBGIT2_PC_REQUIRES "openssl")
ENDIF() endif()
FILE(GLOB SRC_SHA1 hash/sha1/openssl.*) elseif(USE_SHA1 STREQUAL "CommonCrypto")
ELSEIF(USE_SHA1 STREQUAL "CommonCrypto") set(GIT_SHA1_COMMON_CRYPTO 1)
SET(GIT_SHA1_COMMON_CRYPTO 1) elseif(USE_SHA1 STREQUAL "mbedTLS")
FILE(GLOB SRC_SHA1 hash/sha1/common_crypto.*) set(GIT_SHA1_MBEDTLS 1)
ELSEIF(USE_SHA1 STREQUAL "mbedTLS") list(APPEND LIBGIT2_SYSTEM_INCLUDES ${MBEDTLS_INCLUDE_DIR})
SET(GIT_SHA1_MBEDTLS 1) list(APPEND LIBGIT2_SYSTEM_LIBS ${MBEDTLS_LIBRARIES})
FILE(GLOB SRC_SHA1 hash/sha1/mbedtls.*)
LIST(APPEND LIBGIT2_SYSTEM_INCLUDES ${MBEDTLS_INCLUDE_DIR})
LIST(APPEND LIBGIT2_LIBS ${MBEDTLS_LIBRARIES})
# mbedTLS has no pkgconfig file, hence we can't require it # mbedTLS has no pkgconfig file, hence we can't require it
# https://github.com/ARMmbed/mbedtls/issues/228 # https://github.com/ARMmbed/mbedtls/issues/228
# For now, pass its link flags as our own # For now, pass its link flags as our own
LIST(APPEND LIBGIT2_PC_LIBS ${MBEDTLS_LIBRARIES}) list(APPEND LIBGIT2_PC_LIBS ${MBEDTLS_LIBRARIES})
ELSEIF(USE_SHA1 STREQUAL "Win32") elseif(USE_SHA1 STREQUAL "Win32")
SET(GIT_SHA1_WIN32 1) set(GIT_SHA1_WIN32 1)
FILE(GLOB SRC_SHA1 hash/sha1/win32.*) elseif(NOT (USE_SHA1 STREQUAL "Generic"))
ELSEIF(USE_SHA1 STREQUAL "Generic") message(FATAL_ERROR "Asked for unknown SHA1 backend: ${USE_SHA1}")
FILE(GLOB SRC_SHA1 hash/sha1/generic.*) endif()
ELSE()
MESSAGE(FATAL_ERROR "Asked for unknown SHA1 backend: ${USE_SHA1}")
ENDIF()
list(APPEND SRC_SHA1 "hash/sha1.h") add_feature_info(SHA ON "using ${USE_SHA1}")
list(SORT SRC_SHA1)
ADD_FEATURE_INFO(SHA ON "using ${USE_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()
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_DEPENDENCY_INCLUDES "${libgit2_SOURCE_DIR}/deps/pcre")
list(APPEND LIBGIT2_DEPENDENCY_OBJECTS $<TARGET_OBJECTS:pcre>)
else()
message(FATAL_ERROR "The REGEX_BACKEND option provided is not supported")
endif()
# 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()
if(NOT LIBSSH2_FOUND)
message(FATAL_ERROR "LIBSSH2 not found. Set CMAKE_PREFIX_PATH if it is installed outside of the default search path.")
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)
endif()
else()
message(STATUS "LIBSSH2 not found. Set CMAKE_PREFIX_PATH if it is installed outside of the default search path.")
endif()
if(WIN32 AND EMBED_SSH_PATH)
file(GLOB SSH_SRC "${EMBED_SSH_PATH}/src/*.c")
list(SORT SSH_SRC)
list(APPEND LIBGIT2_DEPENDENCY_OBJECTS ${SSH_SRC})
list(APPEND LIBGIT2_DEPENDENCY_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()
add_feature_info(SSH GIT_SSH "SSH transport support")
if(WIN32 AND USE_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_DEPENDENCY_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()
# Optional external dependency: zlib
include(SanitizeBool)
SanitizeBool(USE_BUNDLED_ZLIB)
if(USE_BUNDLED_ZLIB STREQUAL ON)
set(USE_BUNDLED_ZLIB "Bundled")
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_DEPENDENCY_INCLUDES "${libgit2_SOURCE_DIR}/deps/chromium-zlib")
list(APPEND LIBGIT2_DEPENDENCY_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_DEPENDENCY_INCLUDES "${libgit2_SOURCE_DIR}/deps/zlib")
list(APPEND LIBGIT2_DEPENDENCY_OBJECTS $<TARGET_OBJECTS:zlib>)
add_feature_info(zlib ON "using bundled zlib")
endif()
...@@ -30,7 +30,7 @@ typedef enum { ...@@ -30,7 +30,7 @@ typedef enum {
NTLM_STATE_CHALLENGE = 1, NTLM_STATE_CHALLENGE = 1,
NTLM_STATE_RESPONSE = 2, NTLM_STATE_RESPONSE = 2,
NTLM_STATE_ERROR = 3, NTLM_STATE_ERROR = 3,
NTLM_STATE_COMPLETE = 4, NTLM_STATE_COMPLETE = 4
} ntlm_state; } ntlm_state;
typedef struct { typedef struct {
...@@ -122,7 +122,7 @@ struct ntlm_client { ...@@ -122,7 +122,7 @@ struct ntlm_client {
}; };
typedef enum { typedef enum {
NTLM_ENABLE_HOSTVERSION = (1 << 31), NTLM_ENABLE_HOSTVERSION = (1 << 31)
} ntlm_client_internal_flags; } ntlm_client_internal_flags;
typedef enum { typedef enum {
...@@ -130,7 +130,7 @@ typedef enum { ...@@ -130,7 +130,7 @@ typedef enum {
NTLM_TARGET_INFO_SERVER = 1, NTLM_TARGET_INFO_SERVER = 1,
NTLM_TARGET_INFO_DOMAIN = 2, NTLM_TARGET_INFO_DOMAIN = 2,
NTLM_TARGET_INFO_SERVER_DNS = 3, NTLM_TARGET_INFO_SERVER_DNS = 3,
NTLM_TARGET_INFO_DOMAIN_DNS = 4, NTLM_TARGET_INFO_DOMAIN_DNS = 4
} ntlm_target_info_type_t; } ntlm_target_info_type_t;
typedef enum { typedef enum {
...@@ -168,7 +168,7 @@ typedef enum { ...@@ -168,7 +168,7 @@ typedef enum {
NTLM_NEGOTIATE_TARGET_INFO = 0x00800000, NTLM_NEGOTIATE_TARGET_INFO = 0x00800000,
/* Version information should be provided */ /* Version information should be provided */
NTLM_NEGOTIATE_VERSION = 0x01000000, NTLM_NEGOTIATE_VERSION = 0x01000000
} ntlm_negotiate_t; } ntlm_negotiate_t;
extern int ntlm_client_set_nonce(ntlm_client *ntlm, uint64_t nonce); extern int ntlm_client_set_nonce(ntlm_client *ntlm, uint64_t nonce);
......
...@@ -32,7 +32,7 @@ typedef enum { ...@@ -32,7 +32,7 @@ typedef enum {
/** /**
* The input provided to the function is missing or invalid. * The input provided to the function is missing or invalid.
*/ */
NTLM_CLIENT_ERROR_INVALID_INPUT = -2, NTLM_CLIENT_ERROR_INVALID_INPUT = -2
} ntlm_error_code; } ntlm_error_code;
/* /*
...@@ -98,7 +98,7 @@ typedef enum { ...@@ -98,7 +98,7 @@ typedef enum {
* its idea of its hostname in the challenge message. You may * its idea of its hostname in the challenge message. You may
* then set the authentication target based on it. * then set the authentication target based on it.
*/ */
NTLM_CLIENT_DISABLE_REQUEST_TARGET = (1 << 4), NTLM_CLIENT_DISABLE_REQUEST_TARGET = (1 << 4)
} ntlm_client_flags; } ntlm_client_flags;
......
...@@ -120,15 +120,15 @@ In addition to new tests, please ensure that your changes do not cause ...@@ -120,15 +120,15 @@ In addition to new tests, please ensure that your changes do not cause
any other test failures. Running the entire test suite is helpful any other test failures. Running the entire test suite is helpful
before you submit a pull request. When you build libgit2, the test before you submit a pull request. When you build libgit2, the test
suite will also be built. You can run most of the tests by simply running suite will also be built. You can run most of the tests by simply running
the resultant `libgit2_clar` binary. If you want to run a specific the resultant `libgit2_tests` binary. If you want to run a specific
unit test, you can name it with the `-s` option. For example: unit test, you can name it with the `-s` option. For example:
libgit2_clar -sstatus::worktree::long_filenames libgit2_tests -sstatus::worktree::long_filenames
Or you can run an entire class of tests. For example, to run all the Or you can run an entire class of tests. For example, to run all the
worktree status tests: worktree status tests:
libgit2_clar -sstatus::worktree libgit2_tests -sstatus::worktree
The default test run is fairly exhaustive, but it will exclude some The default test run is fairly exhaustive, but it will exclude some
unit tests by default: in particular, those that talk to network unit tests by default: in particular, those that talk to network
...@@ -136,7 +136,7 @@ servers and the tests that manipulate the filesystem in onerous ...@@ -136,7 +136,7 @@ servers and the tests that manipulate the filesystem in onerous
ways (and may need to have special privileges to run). To run the ways (and may need to have special privileges to run). To run the
network tests: network tests:
libgit2_clar -ionline libgit2_tests -ionline
In addition, various tests may be enabled by environment variables, In addition, various tests may be enabled by environment variables,
like the ones that write exceptionally large repositories or manipulate like the ones that write exceptionally large repositories or manipulate
......
...@@ -21,7 +21,7 @@ critical failures (such as a packfile being corrupted, a loose object ...@@ -21,7 +21,7 @@ critical failures (such as a packfile being corrupted, a loose object
having the wrong access permissions, etc.) all of which will return -1. having the wrong access permissions, etc.) all of which will return -1.
When the object lookup is successful, it will return 0. When the object lookup is successful, it will return 0.
If libgit2 was compiled with threads enabled (`-DTHREADSAFE=ON` when using If libgit2 was compiled with threads enabled (`-DUSE_THREADS=ON` when using
CMake), then the error message will be kept in thread-local storage, so it CMake), then the error message will be kept in thread-local storage, so it
will not be modified by other threads. If threads are not enabled, then will not be modified by other threads. If threads are not enabled, then
the error message is in global data. the error message is in global data.
......
...@@ -21,6 +21,9 @@ There are some objects which are read-only/immutable and are thus safe ...@@ -21,6 +21,9 @@ There are some objects which are read-only/immutable and are thus safe
to share across threads, such as references and configuration to share across threads, such as references and configuration
snapshots. snapshots.
The `git_odb` object uses locking internally, and is thread-safe to use from
multiple threads simultaneously.
Error messages Error messages
-------------- --------------
......
include_directories(${LIBGIT2_INCLUDES}) file(GLOB SRC_EXAMPLES *.c *.h)
include_directories(SYSTEM ${LIBGIT2_SYSTEM_INCLUDES})
file(GLOB LG2_SOURCES *.c *.h) add_executable(lg2 ${SRC_EXAMPLES})
add_executable(lg2 ${LG2_SOURCES})
set_target_properties(lg2 PROPERTIES C_STANDARD 90) set_target_properties(lg2 PROPERTIES C_STANDARD 90)
# Ensure that we do not use deprecated functions internally # Ensure that we do not use deprecated functions internally
add_definitions(-DGIT_DEPRECATE_HARD) add_definitions(-DGIT_DEPRECATE_HARD)
target_include_directories(lg2 PRIVATE ${LIBGIT2_INCLUDES} ${LIBGIT2_DEPENDENCY_INCLUDES})
target_include_directories(lg2 SYSTEM PRIVATE ${LIBGIT2_SYSTEM_INCLUDES})
if(WIN32 OR ANDROID) if(WIN32 OR ANDROID)
target_link_libraries(lg2 git2) target_link_libraries(lg2 git2)
else() else()
......
...@@ -28,7 +28,7 @@ ...@@ -28,7 +28,7 @@
enum index_mode { enum index_mode {
INDEX_NONE, INDEX_NONE,
INDEX_ADD, INDEX_ADD
}; };
struct index_options { struct index_options {
...@@ -110,22 +110,7 @@ int print_matched_cb(const char *path, const char *matched_pathspec, void *paylo ...@@ -110,22 +110,7 @@ int print_matched_cb(const char *path, const char *matched_pathspec, void *paylo
return ret; return ret;
} }
void init_array(git_strarray *array, int argc, char **argv) static void print_usage(void)
{
unsigned int i;
array->count = argc;
array->strings = calloc(array->count, sizeof(char *));
assert(array->strings != NULL);
for (i = 0; i < array->count; i++) {
array->strings[i] = argv[i];
}
return;
}
void print_usage(void)
{ {
fprintf(stderr, "usage: add [options] [--] file-spec [file-spec] [...]\n\n"); fprintf(stderr, "usage: add [options] [--] file-spec [file-spec] [...]\n\n");
fprintf(stderr, "\t-n, --dry-run dry run\n"); fprintf(stderr, "\t-n, --dry-run dry run\n");
......
...@@ -27,7 +27,7 @@ enum subcmd { ...@@ -27,7 +27,7 @@ enum subcmd {
subcmd_remove, subcmd_remove,
subcmd_rename, subcmd_rename,
subcmd_seturl, subcmd_seturl,
subcmd_show, subcmd_show
}; };
struct remote_opts { struct remote_opts {
......
...@@ -38,7 +38,7 @@ enum { ...@@ -38,7 +38,7 @@ enum {
FORMAT_DEFAULT = 0, FORMAT_DEFAULT = 0,
FORMAT_LONG = 1, FORMAT_LONG = 1,
FORMAT_SHORT = 2, FORMAT_SHORT = 2,
FORMAT_PORCELAIN = 3, FORMAT_PORCELAIN = 3
}; };
#define MAX_PATHSPEC 8 #define MAX_PATHSPEC 8
......
link_directories(${LIBGIT2_LIBDIRS})
include_directories(${LIBGIT2_INCLUDES})
include_directories(SYSTEM ${LIBGIT2_SYSTEM_INCLUDES})
if(BUILD_FUZZERS AND NOT USE_STANDALONE_FUZZERS) if(BUILD_FUZZERS AND NOT USE_STANDALONE_FUZZERS)
set(CMAKE_REQUIRED_FLAGS "-fsanitize=fuzzer-no-link")
add_c_flag(-fsanitize=fuzzer) add_c_flag(-fsanitize=fuzzer)
add_c_flag(-fsanitize=fuzzer-no-link)
unset(CMAKE_REQUIRED_FLAGS)
endif() endif()
file(GLOB SRC_FUZZ RELATIVE ${CMAKE_CURRENT_SOURCE_DIR} *_fuzzer.c) file(GLOB SRC_FUZZERS RELATIVE ${CMAKE_CURRENT_SOURCE_DIR} *_fuzzer.c)
foreach(fuzz_target_src ${SRC_FUZZ}) foreach(fuzz_target_src ${SRC_FUZZERS})
string(REPLACE ".c" "" fuzz_target_name ${fuzz_target_src}) string(REPLACE ".c" "" fuzz_target_name ${fuzz_target_src})
string(REPLACE "_fuzzer" "" fuzz_name ${fuzz_target_name}) string(REPLACE "_fuzzer" "" fuzz_name ${fuzz_target_name})
...@@ -17,7 +16,11 @@ foreach(fuzz_target_src ${SRC_FUZZ}) ...@@ -17,7 +16,11 @@ foreach(fuzz_target_src ${SRC_FUZZ})
endif() endif()
add_executable(${fuzz_target_name} ${${fuzz_target_name}_SOURCES}) add_executable(${fuzz_target_name} ${${fuzz_target_name}_SOURCES})
set_target_properties(${fuzz_target_name} PROPERTIES C_STANDARD 90) set_target_properties(${fuzz_target_name} PROPERTIES C_STANDARD 90)
target_link_libraries(${fuzz_target_name} ${LIBGIT2_LIBS})
target_include_directories(${fuzz_target_name} PRIVATE ${LIBGIT2_INCLUDES} ${LIBGIT2_DEPENDENCY_INCLUDES})
target_include_directories(${fuzz_target_name} SYSTEM PRIVATE ${LIBGIT2_SYSTEM_INCLUDES})
target_link_libraries(${fuzz_target_name} ${LIBGIT2_SYSTEM_LIBS})
add_test(${fuzz_target_name} "${CMAKE_CURRENT_BINARY_DIR}/${fuzz_target_name}" "${CMAKE_CURRENT_SOURCE_DIR}/corpora/${fuzz_name}") add_test(${fuzz_target_name} "${CMAKE_CURRENT_BINARY_DIR}/${fuzz_target_name}" "${CMAKE_CURRENT_SOURCE_DIR}/corpora/${fuzz_name}")
endforeach() endforeach()
...@@ -17,6 +17,8 @@ ...@@ -17,6 +17,8 @@
#include "hash.h" #include "hash.h"
#include "commit_graph.h" #include "commit_graph.h"
#include "standalone_driver.h"
int LLVMFuzzerInitialize(int *argc, char ***argv) int LLVMFuzzerInitialize(int *argc, char ***argv)
{ {
GIT_UNUSED(argc); GIT_UNUSED(argc);
......
...@@ -10,9 +10,11 @@ ...@@ -10,9 +10,11 @@
#include "git2.h" #include "git2.h"
#include "config_backend.h" #include "config_backend.h"
#include "standalone_driver.h"
#define UNUSED(x) (void)(x) #define UNUSED(x) (void)(x)
int foreach_cb(const git_config_entry *entry, void *payload) static int foreach_cb(const git_config_entry *entry, void *payload)
{ {
UNUSED(entry); UNUSED(entry);
UNUSED(payload); UNUSED(payload);
......
...@@ -187,18 +187,18 @@ Once built, you can run the tests from the `build` directory with the command ...@@ -187,18 +187,18 @@ Once built, you can run the tests from the `build` directory with the command
Alternatively you can run the test suite directly using, Alternatively you can run the test suite directly using,
$ ./libgit2_clar $ ./libgit2_tests
Invoking the test suite directly is useful because it allows you to execute Invoking the test suite directly is useful because it allows you to execute
individual tests, or groups of tests using the `-s` flag. For example, to individual tests, or groups of tests using the `-s` flag. For example, to
run the index tests: run the index tests:
$ ./libgit2_clar -sindex $ ./libgit2_tests -sindex
To run a single test named `index::racy::diff`, which corresponds to the test To run a single test named `index::racy::diff`, which corresponds to the test
function (`test_index_racy__diff`)[https://github.com/libgit2/libgit2/blob/master/tests/index/racy.c#L23]: function (`test_index_racy__diff`)[https://github.com/libgit2/libgit2/blob/master/tests/index/racy.c#L23]:
$ ./libgit2_clar -sindex::racy::diff $ ./libgit2_tests -sindex::racy::diff
The test suite will print a `.` for every passing test, and an `F` for any The test suite will print a `.` for every passing test, and an `F` for any
failing test. An `S` indicates that a test was skipped because it is not failing test. An `S` indicates that a test was skipped because it is not
......
...@@ -15,6 +15,8 @@ ...@@ -15,6 +15,8 @@
#include "git2/sys/transport.h" #include "git2/sys/transport.h"
#include "futils.h" #include "futils.h"
#include "standalone_driver.h"
#define UNUSED(x) (void)(x) #define UNUSED(x) (void)(x)
struct fuzzer_buffer { struct fuzzer_buffer {
...@@ -130,7 +132,7 @@ static int fuzzer_subtransport_new( ...@@ -130,7 +132,7 @@ static int fuzzer_subtransport_new(
return 0; return 0;
} }
int fuzzer_subtransport_cb( static int fuzzer_subtransport_cb(
git_smart_subtransport **out, git_smart_subtransport **out,
git_transport *owner, git_transport *owner,
void *payload) void *payload)
...@@ -145,7 +147,7 @@ int fuzzer_subtransport_cb( ...@@ -145,7 +147,7 @@ int fuzzer_subtransport_cb(
return 0; return 0;
} }
int fuzzer_transport_cb(git_transport **out, git_remote *owner, void *param) static int fuzzer_transport_cb(git_transport **out, git_remote *owner, void *param)
{ {
git_smart_subtransport_definition def = { git_smart_subtransport_definition def = {
fuzzer_subtransport_cb, fuzzer_subtransport_cb,
...@@ -155,7 +157,7 @@ int fuzzer_transport_cb(git_transport **out, git_remote *owner, void *param) ...@@ -155,7 +157,7 @@ int fuzzer_transport_cb(git_transport **out, git_remote *owner, void *param)
return git_transport_smart(out, owner, &def); return git_transport_smart(out, owner, &def);
} }
void fuzzer_git_abort(const char *op) static void fuzzer_git_abort(const char *op)
{ {
const git_error *err = git_error_last(); const git_error *err = git_error_last();
fprintf(stderr, "unexpected libgit error: %s: %s\n", fprintf(stderr, "unexpected libgit error: %s: %s\n",
......
...@@ -16,6 +16,8 @@ ...@@ -16,6 +16,8 @@
#include "hash.h" #include "hash.h"
#include "midx.h" #include "midx.h"
#include "standalone_driver.h"
int LLVMFuzzerInitialize(int *argc, char ***argv) int LLVMFuzzerInitialize(int *argc, char ***argv)
{ {
GIT_UNUSED(argc); GIT_UNUSED(argc);
......
...@@ -10,6 +10,8 @@ ...@@ -10,6 +10,8 @@
#include "git2.h" #include "git2.h"
#include "object.h" #include "object.h"
#include "standalone_driver.h"
#define UNUSED(x) (void)(x) #define UNUSED(x) (void)(x)
int LLVMFuzzerInitialize(int *argc, char ***argv) int LLVMFuzzerInitialize(int *argc, char ***argv)
......
...@@ -14,6 +14,8 @@ ...@@ -14,6 +14,8 @@
#include "common.h" #include "common.h"
#include "str.h" #include "str.h"
#include "standalone_driver.h"
static git_odb *odb = NULL; static git_odb *odb = NULL;
static git_odb_backend *mempack = NULL; static git_odb_backend *mempack = NULL;
......
...@@ -11,6 +11,8 @@ ...@@ -11,6 +11,8 @@
#include "patch.h" #include "patch.h"
#include "patch_parse.h" #include "patch_parse.h"
#include "standalone_driver.h"
#define UNUSED(x) (void)(x) #define UNUSED(x) (void)(x)
int LLVMFuzzerInitialize(int *argc, char ***argv) int LLVMFuzzerInitialize(int *argc, char ***argv)
......
...@@ -11,8 +11,7 @@ ...@@ -11,8 +11,7 @@
#include "futils.h" #include "futils.h"
#include "path.h" #include "path.h"
extern int LLVMFuzzerTestOneInput(const unsigned char *data, size_t size); #include "standalone_driver.h"
extern int LLVMFuzzerInitialize(int *argc, char ***argv);
static int run_one_file(const char *filename) static int run_one_file(const char *filename)
{ {
...@@ -52,7 +51,7 @@ int main(int argc, char **argv) ...@@ -52,7 +51,7 @@ int main(int argc, char **argv)
fprintf(stderr, "Running %s against %s\n", argv[0], argv[1]); fprintf(stderr, "Running %s against %s\n", argv[0], argv[1]);
LLVMFuzzerInitialize(&argc, &argv); LLVMFuzzerInitialize(&argc, &argv);
if (git_path_dirload(&corpus_files, argv[1], 0, 0x0) < 0) { if (git_fs_path_dirload(&corpus_files, argv[1], 0, 0x0) < 0) {
fprintf(stderr, "Failed to scan corpus directory '%s': %s\n", fprintf(stderr, "Failed to scan corpus directory '%s': %s\n",
argv[1], git_error_last()->message); argv[1], git_error_last()->message);
error = -1; error = -1;
......
/*
* 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_standalone_driver_h__
#define INCLUDE_standalone_driver_h__
extern int LLVMFuzzerTestOneInput(const unsigned char *data, size_t size);
extern int LLVMFuzzerInitialize(int *argc, char ***argv);
#endif
...@@ -59,7 +59,7 @@ typedef enum { ...@@ -59,7 +59,7 @@ typedef enum {
* Don't actually make changes, just test that the patch applies. * Don't actually make changes, just test that the patch applies.
* This is the equivalent of `git apply --check`. * This is the equivalent of `git apply --check`.
*/ */
GIT_APPLY_CHECK = (1 << 0), GIT_APPLY_CHECK = (1 << 0)
} git_apply_flags_t; } git_apply_flags_t;
/** /**
...@@ -127,7 +127,7 @@ typedef enum { ...@@ -127,7 +127,7 @@ typedef enum {
* Apply the patch to both the working directory and the index. * Apply the patch to both the working directory and the index.
* This is the equivalent of `git apply --index`. * This is the equivalent of `git apply --index`.
*/ */
GIT_APPLY_LOCATION_BOTH = 2, GIT_APPLY_LOCATION_BOTH = 2
} git_apply_location_t; } git_apply_location_t;
/** /**
......
...@@ -83,7 +83,7 @@ typedef enum { ...@@ -83,7 +83,7 @@ typedef enum {
GIT_ATTR_VALUE_UNSPECIFIED = 0, /**< The attribute has been left unspecified */ GIT_ATTR_VALUE_UNSPECIFIED = 0, /**< The attribute has been left unspecified */
GIT_ATTR_VALUE_TRUE, /**< The attribute has been set */ GIT_ATTR_VALUE_TRUE, /**< The attribute has been set */
GIT_ATTR_VALUE_FALSE, /**< The attribute has been unset */ GIT_ATTR_VALUE_FALSE, /**< The attribute has been unset */
GIT_ATTR_VALUE_STRING, /**< This attribute has a value */ GIT_ATTR_VALUE_STRING /**< This attribute has a value */
} git_attr_value_t; } git_attr_value_t;
/** /**
......
...@@ -73,7 +73,7 @@ typedef enum { ...@@ -73,7 +73,7 @@ typedef enum {
GIT_BLAME_USE_MAILMAP = (1<<5), GIT_BLAME_USE_MAILMAP = (1<<5),
/** Ignore whitespace differences */ /** Ignore whitespace differences */
GIT_BLAME_IGNORE_WHITESPACE = (1<<6), GIT_BLAME_IGNORE_WHITESPACE = (1<<6)
} git_blame_flag_t; } git_blame_flag_t;
/** /**
......
...@@ -119,7 +119,7 @@ typedef enum { ...@@ -119,7 +119,7 @@ typedef enum {
* When set, filters will be loaded from a `.gitattributes` file * When set, filters will be loaded from a `.gitattributes` file
* in the specified commit. * in the specified commit.
*/ */
GIT_BLOB_FILTER_ATTRIBUTES_FROM_COMMIT = (1 << 3), GIT_BLOB_FILTER_ATTRIBUTES_FROM_COMMIT = (1 << 3)
} git_blob_filter_flag_t; } git_blob_filter_flag_t;
/** /**
......
...@@ -44,7 +44,7 @@ typedef enum git_cert_t { ...@@ -44,7 +44,7 @@ typedef enum git_cert_t {
* information about the certificate. This is used when using * information about the certificate. This is used when using
* curl. * curl.
*/ */
GIT_CERT_STRARRAY, GIT_CERT_STRARRAY
} git_cert_t; } git_cert_t;
/** /**
...@@ -82,7 +82,7 @@ typedef enum { ...@@ -82,7 +82,7 @@ typedef enum {
/** SHA-256 is available */ /** SHA-256 is available */
GIT_CERT_SSH_SHA256 = (1 << 2), GIT_CERT_SSH_SHA256 = (1 << 2),
/** Raw hostkey is available */ /** Raw hostkey is available */
GIT_CERT_SSH_RAW = (1 << 3), GIT_CERT_SSH_RAW = (1 << 3)
} git_cert_ssh_t; } git_cert_ssh_t;
typedef enum { typedef enum {
......
...@@ -190,7 +190,7 @@ typedef enum { ...@@ -190,7 +190,7 @@ typedef enum {
/** Recursively checkout submodules with same options (NOT IMPLEMENTED) */ /** Recursively checkout submodules with same options (NOT IMPLEMENTED) */
GIT_CHECKOUT_UPDATE_SUBMODULES = (1u << 16), GIT_CHECKOUT_UPDATE_SUBMODULES = (1u << 16),
/** Recursively checkout submodules if HEAD moved in super repo (NOT IMPLEMENTED) */ /** Recursively checkout submodules if HEAD moved in super repo (NOT IMPLEMENTED) */
GIT_CHECKOUT_UPDATE_SUBMODULES_IF_CHANGED = (1u << 17), GIT_CHECKOUT_UPDATE_SUBMODULES_IF_CHANGED = (1u << 17)
} git_checkout_strategy_t; } git_checkout_strategy_t;
......
...@@ -49,7 +49,7 @@ typedef enum { ...@@ -49,7 +49,7 @@ typedef enum {
* Bypass the git-aware transport, but do not try to use * Bypass the git-aware transport, but do not try to use
* hardlinks. * hardlinks.
*/ */
GIT_CLONE_LOCAL_NO_LINKS, GIT_CLONE_LOCAL_NO_LINKS
} git_clone_local_t; } git_clone_local_t;
/** /**
......
...@@ -147,7 +147,7 @@ typedef enum { ...@@ -147,7 +147,7 @@ typedef enum {
* If set, libgit2 was built with support for sub-second resolution in file * If set, libgit2 was built with support for sub-second resolution in file
* modification times. * modification times.
*/ */
GIT_FEATURE_NSEC = (1 << 3), GIT_FEATURE_NSEC = (1 << 3)
} git_feature_t; } git_feature_t;
/** /**
......
...@@ -55,7 +55,7 @@ typedef enum { ...@@ -55,7 +55,7 @@ typedef enum {
/** Represents the highest level available config file (i.e. the most /** Represents the highest level available config file (i.e. the most
* specific config file available that actually is loaded) * specific config file available that actually is loaded)
*/ */
GIT_CONFIG_HIGHEST_LEVEL = -1, GIT_CONFIG_HIGHEST_LEVEL = -1
} git_config_level_t; } git_config_level_t;
/** /**
......
...@@ -75,7 +75,7 @@ typedef enum { ...@@ -75,7 +75,7 @@ typedef enum {
* *
* @see git_credential_ssh_key_memory_new * @see git_credential_ssh_key_memory_new
*/ */
GIT_CREDENTIAL_SSH_MEMORY = (1u << 6), GIT_CREDENTIAL_SSH_MEMORY = (1u << 6)
} git_credential_t; } git_credential_t;
/** /**
......
...@@ -313,7 +313,7 @@ typedef enum { ...@@ -313,7 +313,7 @@ typedef enum {
GIT_DIFF_FORMAT_EMAIL_NONE = 0, GIT_DIFF_FORMAT_EMAIL_NONE = 0,
/** Don't insert "[PATCH]" in the subject header*/ /** Don't insert "[PATCH]" in the subject header*/
GIT_DIFF_FORMAT_EMAIL_EXCLUDE_SUBJECT_PATCH_MARKER = (1 << 0), GIT_DIFF_FORMAT_EMAIL_EXCLUDE_SUBJECT_PATCH_MARKER = (1 << 0)
} git_diff_format_email_flags_t; } git_diff_format_email_flags_t;
......
...@@ -30,7 +30,7 @@ GIT_BEGIN_DECL ...@@ -30,7 +30,7 @@ GIT_BEGIN_DECL
typedef enum { typedef enum {
GIT_DESCRIBE_DEFAULT, GIT_DESCRIBE_DEFAULT,
GIT_DESCRIBE_TAGS, GIT_DESCRIBE_TAGS,
GIT_DESCRIBE_ALL, GIT_DESCRIBE_ALL
} git_describe_strategy_t; } git_describe_strategy_t;
/** /**
......
...@@ -170,7 +170,7 @@ typedef enum { ...@@ -170,7 +170,7 @@ typedef enum {
/** Include the necessary deflate / delta information so that `git-apply` /** Include the necessary deflate / delta information so that `git-apply`
* can apply given diff information to binary files. * can apply given diff information to binary files.
*/ */
GIT_DIFF_SHOW_BINARY = (1u << 30), GIT_DIFF_SHOW_BINARY = (1u << 30)
} git_diff_option_t; } git_diff_option_t;
/** /**
...@@ -207,7 +207,7 @@ typedef enum { ...@@ -207,7 +207,7 @@ typedef enum {
GIT_DIFF_FLAG_BINARY = (1u << 0), /**< file(s) treated as binary data */ GIT_DIFF_FLAG_BINARY = (1u << 0), /**< file(s) treated as binary data */
GIT_DIFF_FLAG_NOT_BINARY = (1u << 1), /**< file(s) treated as text data */ GIT_DIFF_FLAG_NOT_BINARY = (1u << 1), /**< file(s) treated as text data */
GIT_DIFF_FLAG_VALID_ID = (1u << 2), /**< `id` value is known correct */ GIT_DIFF_FLAG_VALID_ID = (1u << 2), /**< `id` value is known correct */
GIT_DIFF_FLAG_EXISTS = (1u << 3), /**< file exists at this side of the delta */ GIT_DIFF_FLAG_EXISTS = (1u << 3) /**< file exists at this side of the delta */
} git_diff_flag_t; } git_diff_flag_t;
/** /**
...@@ -231,7 +231,7 @@ typedef enum { ...@@ -231,7 +231,7 @@ typedef enum {
GIT_DELTA_UNTRACKED = 7, /**< entry is untracked item in workdir */ GIT_DELTA_UNTRACKED = 7, /**< entry is untracked item in workdir */
GIT_DELTA_TYPECHANGE = 8, /**< type of entry changed between old and new */ GIT_DELTA_TYPECHANGE = 8, /**< type of entry changed between old and new */
GIT_DELTA_UNREADABLE = 9, /**< entry is unreadable */ GIT_DELTA_UNREADABLE = 9, /**< entry is unreadable */
GIT_DELTA_CONFLICTED = 10, /**< entry in the index is conflicted */ GIT_DELTA_CONFLICTED = 10 /**< entry in the index is conflicted */
} git_delta_t; } git_delta_t;
/** /**
...@@ -497,7 +497,7 @@ typedef enum { ...@@ -497,7 +497,7 @@ typedef enum {
GIT_DIFF_BINARY_LITERAL, GIT_DIFF_BINARY_LITERAL,
/** The binary data is the delta from one side to the other. */ /** The binary data is the delta from one side to the other. */
GIT_DIFF_BINARY_DELTA, GIT_DIFF_BINARY_DELTA
} git_diff_binary_t; } git_diff_binary_t;
/** The contents of one of the files in a binary diff. */ /** The contents of one of the files in a binary diff. */
...@@ -706,7 +706,7 @@ typedef enum { ...@@ -706,7 +706,7 @@ typedef enum {
* GIT_DIFF_INCLUDE_UNMODIFIED flag. If you do not want UNMODIFIED * GIT_DIFF_INCLUDE_UNMODIFIED flag. If you do not want UNMODIFIED
* records in the final result, pass this flag to have them removed. * records in the final result, pass this flag to have them removed.
*/ */
GIT_DIFF_FIND_REMOVE_UNMODIFIED = (1u << 16), GIT_DIFF_FIND_REMOVE_UNMODIFIED = (1u << 16)
} git_diff_find_t; } git_diff_find_t;
/** /**
...@@ -1107,7 +1107,7 @@ typedef enum { ...@@ -1107,7 +1107,7 @@ typedef enum {
GIT_DIFF_FORMAT_RAW = 3u, /**< like git diff --raw */ GIT_DIFF_FORMAT_RAW = 3u, /**< like git diff --raw */
GIT_DIFF_FORMAT_NAME_ONLY = 4u, /**< like git diff --name-only */ GIT_DIFF_FORMAT_NAME_ONLY = 4u, /**< like git diff --name-only */
GIT_DIFF_FORMAT_NAME_STATUS = 5u, /**< like git diff --name-status */ GIT_DIFF_FORMAT_NAME_STATUS = 5u, /**< like git diff --name-status */
GIT_DIFF_FORMAT_PATCH_ID = 6u, /**< git diff as used by git patch-id */ GIT_DIFF_FORMAT_PATCH_ID = 6u /**< git diff as used by git patch-id */
} git_diff_format_t; } git_diff_format_t;
/** /**
...@@ -1311,7 +1311,7 @@ typedef enum { ...@@ -1311,7 +1311,7 @@ typedef enum {
GIT_DIFF_STATS_NUMBER = (1u << 2), GIT_DIFF_STATS_NUMBER = (1u << 2),
/** Extended header information such as creations, renames and mode changes, equivalent of `--summary` */ /** Extended header information such as creations, renames and mode changes, equivalent of `--summary` */
GIT_DIFF_STATS_INCLUDE_SUMMARY = (1u << 3), GIT_DIFF_STATS_INCLUDE_SUMMARY = (1u << 3)
} git_diff_stats_format_t; } git_diff_stats_format_t;
/** /**
......
...@@ -34,7 +34,7 @@ typedef enum { ...@@ -34,7 +34,7 @@ typedef enum {
GIT_EMAIL_CREATE_ALWAYS_NUMBER = (1u << 1), GIT_EMAIL_CREATE_ALWAYS_NUMBER = (1u << 1),
/** Do not perform rename or similarity detection. */ /** Do not perform rename or similarity detection. */
GIT_EMAIL_CREATE_NO_RENAMES = (1u << 2), GIT_EMAIL_CREATE_NO_RENAMES = (1u << 2)
} git_email_create_flags_t; } git_email_create_flags_t;
/** /**
......
...@@ -57,7 +57,7 @@ typedef enum { ...@@ -57,7 +57,7 @@ typedef enum {
GIT_RETRY = -32, /**< Internal only */ GIT_RETRY = -32, /**< Internal only */
GIT_EMISMATCH = -33, /**< Hashsum mismatch in object */ GIT_EMISMATCH = -33, /**< Hashsum mismatch in object */
GIT_EINDEXDIRTY = -34, /**< Unsaved changes in the index would be overwritten */ GIT_EINDEXDIRTY = -34, /**< Unsaved changes in the index would be overwritten */
GIT_EAPPLYFAIL = -35, /**< Patch application failed */ GIT_EAPPLYFAIL = -35 /**< Patch application failed */
} git_error_code; } git_error_code;
/** /**
......
...@@ -32,7 +32,7 @@ typedef enum { ...@@ -32,7 +32,7 @@ typedef enum {
GIT_FILTER_TO_WORKTREE = 0, GIT_FILTER_TO_WORKTREE = 0,
GIT_FILTER_SMUDGE = GIT_FILTER_TO_WORKTREE, GIT_FILTER_SMUDGE = GIT_FILTER_TO_WORKTREE,
GIT_FILTER_TO_ODB = 1, GIT_FILTER_TO_ODB = 1,
GIT_FILTER_CLEAN = GIT_FILTER_TO_ODB, GIT_FILTER_CLEAN = GIT_FILTER_TO_ODB
} git_filter_mode_t; } git_filter_mode_t;
/** /**
...@@ -54,7 +54,7 @@ typedef enum { ...@@ -54,7 +54,7 @@ typedef enum {
* Load attributes from `.gitattributes` in a given commit. * Load attributes from `.gitattributes` in a given commit.
* This can only be specified in a `git_filter_options`. * This can only be specified in a `git_filter_options`.
*/ */
GIT_FILTER_ATTRIBUTES_FROM_COMMIT = (1u << 3), GIT_FILTER_ATTRIBUTES_FROM_COMMIT = (1u << 3)
} git_filter_flag_t; } git_filter_flag_t;
/** /**
......
...@@ -86,7 +86,7 @@ typedef struct git_index_entry { ...@@ -86,7 +86,7 @@ typedef struct git_index_entry {
*/ */
typedef enum { typedef enum {
GIT_INDEX_ENTRY_EXTENDED = (0x4000), GIT_INDEX_ENTRY_EXTENDED = (0x4000),
GIT_INDEX_ENTRY_VALID = (0x8000), GIT_INDEX_ENTRY_VALID = (0x8000)
} git_index_entry_flag_t; } git_index_entry_flag_t;
#define GIT_INDEX_ENTRY_STAGE(E) \ #define GIT_INDEX_ENTRY_STAGE(E) \
...@@ -119,7 +119,7 @@ typedef enum { ...@@ -119,7 +119,7 @@ typedef enum {
GIT_INDEX_ENTRY_EXTENDED_FLAGS = (GIT_INDEX_ENTRY_INTENT_TO_ADD | GIT_INDEX_ENTRY_SKIP_WORKTREE), GIT_INDEX_ENTRY_EXTENDED_FLAGS = (GIT_INDEX_ENTRY_INTENT_TO_ADD | GIT_INDEX_ENTRY_SKIP_WORKTREE),
GIT_INDEX_ENTRY_UPTODATE = (1 << 2), GIT_INDEX_ENTRY_UPTODATE = (1 << 2)
} git_index_entry_extended_flag_t; } git_index_entry_extended_flag_t;
/** Capabilities of system that affect index actions. */ /** Capabilities of system that affect index actions. */
...@@ -127,7 +127,7 @@ typedef enum { ...@@ -127,7 +127,7 @@ typedef enum {
GIT_INDEX_CAPABILITY_IGNORE_CASE = 1, GIT_INDEX_CAPABILITY_IGNORE_CASE = 1,
GIT_INDEX_CAPABILITY_NO_FILEMODE = 2, GIT_INDEX_CAPABILITY_NO_FILEMODE = 2,
GIT_INDEX_CAPABILITY_NO_SYMLINKS = 4, GIT_INDEX_CAPABILITY_NO_SYMLINKS = 4,
GIT_INDEX_CAPABILITY_FROM_OWNER = -1, GIT_INDEX_CAPABILITY_FROM_OWNER = -1
} git_index_capability_t; } git_index_capability_t;
...@@ -140,7 +140,7 @@ typedef enum { ...@@ -140,7 +140,7 @@ typedef enum {
GIT_INDEX_ADD_DEFAULT = 0, GIT_INDEX_ADD_DEFAULT = 0,
GIT_INDEX_ADD_FORCE = (1u << 0), GIT_INDEX_ADD_FORCE = (1u << 0),
GIT_INDEX_ADD_DISABLE_PATHSPEC_MATCH = (1u << 1), GIT_INDEX_ADD_DISABLE_PATHSPEC_MATCH = (1u << 1),
GIT_INDEX_ADD_CHECK_PATHSPEC = (1u << 2), GIT_INDEX_ADD_CHECK_PATHSPEC = (1u << 2)
} git_index_add_option_t; } git_index_add_option_t;
/** Git index stage states */ /** Git index stage states */
...@@ -163,7 +163,7 @@ typedef enum { ...@@ -163,7 +163,7 @@ typedef enum {
GIT_INDEX_STAGE_OURS = 2, GIT_INDEX_STAGE_OURS = 2,
/** The "theirs" side of a conflict. */ /** The "theirs" side of a conflict. */
GIT_INDEX_STAGE_THEIRS = 3, GIT_INDEX_STAGE_THEIRS = 3
} git_index_stage_t; } git_index_stage_t;
/** /**
......
...@@ -91,7 +91,7 @@ typedef enum { ...@@ -91,7 +91,7 @@ typedef enum {
* instead simply use the first base. This flag provides a similar * instead simply use the first base. This flag provides a similar
* merge base to `git-merge-resolve`. * merge base to `git-merge-resolve`.
*/ */
GIT_MERGE_NO_RECURSIVE = (1 << 3), GIT_MERGE_NO_RECURSIVE = (1 << 3)
} git_merge_flag_t; } git_merge_flag_t;
/** /**
...@@ -127,7 +127,7 @@ typedef enum { ...@@ -127,7 +127,7 @@ typedef enum {
* which has the result of combining both files. The index will not * which has the result of combining both files. The index will not
* record a conflict. * record a conflict.
*/ */
GIT_MERGE_FILE_FAVOR_UNION = 3, GIT_MERGE_FILE_FAVOR_UNION = 3
} git_merge_file_favor_t; } git_merge_file_favor_t;
/** /**
...@@ -159,7 +159,7 @@ typedef enum { ...@@ -159,7 +159,7 @@ typedef enum {
GIT_MERGE_FILE_DIFF_PATIENCE = (1 << 6), GIT_MERGE_FILE_DIFF_PATIENCE = (1 << 6),
/** Take extra time to find minimal diff */ /** Take extra time to find minimal diff */
GIT_MERGE_FILE_DIFF_MINIMAL = (1 << 7), GIT_MERGE_FILE_DIFF_MINIMAL = (1 << 7)
} git_merge_file_flag_t; } git_merge_file_flag_t;
#define GIT_MERGE_CONFLICT_MARKER_SIZE 7 #define GIT_MERGE_CONFLICT_MARKER_SIZE 7
...@@ -341,7 +341,7 @@ typedef enum { ...@@ -341,7 +341,7 @@ typedef enum {
* a valid commit. No merge can be performed, but the caller may wish * a valid commit. No merge can be performed, but the caller may wish
* to simply set HEAD to the target commit(s). * to simply set HEAD to the target commit(s).
*/ */
GIT_MERGE_ANALYSIS_UNBORN = (1 << 3), GIT_MERGE_ANALYSIS_UNBORN = (1 << 3)
} git_merge_analysis_t; } git_merge_analysis_t;
/** /**
...@@ -364,7 +364,7 @@ typedef enum { ...@@ -364,7 +364,7 @@ typedef enum {
* There is a `merge.ff=only` configuration setting, suggesting that * There is a `merge.ff=only` configuration setting, suggesting that
* the user only wants fast-forward merges. * the user only wants fast-forward merges.
*/ */
GIT_MERGE_PREFERENCE_FASTFORWARD_ONLY = (1 << 1), GIT_MERGE_PREFERENCE_FASTFORWARD_ONLY = (1 << 1)
} git_merge_preference_t; } git_merge_preference_t;
/** /**
......
...@@ -22,6 +22,17 @@ ...@@ -22,6 +22,17 @@
*/ */
GIT_BEGIN_DECL GIT_BEGIN_DECL
/** Flags controlling the behavior of ODB lookup operations */
typedef enum {
/**
* Don't call `git_odb_refresh` if the lookup fails. Useful when doing
* a batch of lookup operations for objects that may legitimately not
* exist. When using this flag, you may wish to manually call
* `git_odb_refresh` before processing a batch of objects.
*/
GIT_ODB_LOOKUP_NO_REFRESH = (1 << 0)
} git_odb_lookup_flags_t;
/** /**
* Function type for callbacks from git_odb_foreach. * Function type for callbacks from git_odb_foreach.
*/ */
...@@ -156,6 +167,17 @@ GIT_EXTERN(int) git_odb_read_header(size_t *len_out, git_object_t *type_out, git ...@@ -156,6 +167,17 @@ GIT_EXTERN(int) git_odb_read_header(size_t *len_out, git_object_t *type_out, git
GIT_EXTERN(int) git_odb_exists(git_odb *db, const git_oid *id); GIT_EXTERN(int) git_odb_exists(git_odb *db, const git_oid *id);
/** /**
* Determine if the given object can be found in the object database, with
* extended options.
*
* @param db database to be searched for the given object.
* @param id the object to search for.
* @param flags flags affecting the lookup (see `git_odb_lookup_flags_t`)
* @return 1 if the object was found, 0 otherwise
*/
GIT_EXTERN(int) git_odb_exists_ext(git_odb *db, const git_oid *id, unsigned int flags);
/**
* Determine if an object can be found in the object database by an * Determine if an object can be found in the object database by an
* abbreviated object ID. * abbreviated object ID.
* *
......
...@@ -71,7 +71,7 @@ GIT_EXTERN(int) git_odb_backend_one_pack(git_odb_backend **out, const char *inde ...@@ -71,7 +71,7 @@ GIT_EXTERN(int) git_odb_backend_one_pack(git_odb_backend **out, const char *inde
typedef enum { typedef enum {
GIT_STREAM_RDONLY = (1 << 1), GIT_STREAM_RDONLY = (1 << 1),
GIT_STREAM_WRONLY = (1 << 2), GIT_STREAM_WRONLY = (1 << 2),
GIT_STREAM_RW = (GIT_STREAM_RDONLY | GIT_STREAM_WRONLY), GIT_STREAM_RW = (GIT_STREAM_RDONLY | GIT_STREAM_WRONLY)
} git_odb_stream_t; } git_odb_stream_t;
/** /**
......
...@@ -51,7 +51,7 @@ GIT_BEGIN_DECL ...@@ -51,7 +51,7 @@ GIT_BEGIN_DECL
*/ */
typedef enum { typedef enum {
GIT_PACKBUILDER_ADDING_OBJECTS = 0, GIT_PACKBUILDER_ADDING_OBJECTS = 0,
GIT_PACKBUILDER_DELTAFICATION = 1, GIT_PACKBUILDER_DELTAFICATION = 1
} git_packbuilder_stage_t; } git_packbuilder_stage_t;
/** /**
......
...@@ -69,7 +69,7 @@ typedef enum { ...@@ -69,7 +69,7 @@ typedef enum {
* just test if there were any matches at all or in combination with * just test if there were any matches at all or in combination with
* GIT_PATHSPEC_FIND_FAILURES to validate a pathspec. * GIT_PATHSPEC_FIND_FAILURES to validate a pathspec.
*/ */
GIT_PATHSPEC_FAILURES_ONLY = (1u << 5), GIT_PATHSPEC_FAILURES_ONLY = (1u << 5)
} git_pathspec_flag_t; } git_pathspec_flag_t;
/** /**
......
...@@ -32,7 +32,7 @@ typedef enum { ...@@ -32,7 +32,7 @@ typedef enum {
/** /**
* Connect via the URL given in the options * Connect via the URL given in the options
*/ */
GIT_PROXY_SPECIFIED, GIT_PROXY_SPECIFIED
} git_proxy_t; } git_proxy_t;
/** /**
......
...@@ -152,7 +152,7 @@ typedef enum { ...@@ -152,7 +152,7 @@ typedef enum {
* No commit will be cherry-picked. The client should run the given * No commit will be cherry-picked. The client should run the given
* command and (if successful) continue. * command and (if successful) continue.
*/ */
GIT_REBASE_OPERATION_EXEC, GIT_REBASE_OPERATION_EXEC
} git_rebase_operation_t; } git_rebase_operation_t;
#define GIT_REBASE_OPTIONS_VERSION 1 #define GIT_REBASE_OPTIONS_VERSION 1
......
...@@ -686,7 +686,7 @@ typedef enum { ...@@ -686,7 +686,7 @@ typedef enum {
* so the `ONELEVEL` naming rules aren't enforced and 'master' * so the `ONELEVEL` naming rules aren't enforced and 'master'
* becomes a valid name. * becomes a valid name.
*/ */
GIT_REFERENCE_FORMAT_REFSPEC_SHORTHAND = (1u << 2), GIT_REFERENCE_FORMAT_REFSPEC_SHORTHAND = (1u << 2)
} git_reference_format_t; } git_reference_format_t;
/** /**
......
...@@ -49,7 +49,7 @@ typedef enum { ...@@ -49,7 +49,7 @@ typedef enum {
GIT_REMOTE_CREATE_SKIP_INSTEADOF = (1 << 0), GIT_REMOTE_CREATE_SKIP_INSTEADOF = (1 << 0),
/** Don't build a fetchspec from the name if none is set */ /** Don't build a fetchspec from the name if none is set */
GIT_REMOTE_CREATE_SKIP_DEFAULT_FETCHSPEC = (1 << 1), GIT_REMOTE_CREATE_SKIP_DEFAULT_FETCHSPEC = (1 << 1)
} git_remote_create_flags; } git_remote_create_flags;
/** /**
...@@ -443,7 +443,7 @@ GIT_EXTERN(int) git_remote_list(git_strarray *out, git_repository *repo); ...@@ -443,7 +443,7 @@ GIT_EXTERN(int) git_remote_list(git_strarray *out, git_repository *repo);
typedef enum git_remote_completion_t { typedef enum git_remote_completion_t {
GIT_REMOTE_COMPLETION_DOWNLOAD, GIT_REMOTE_COMPLETION_DOWNLOAD,
GIT_REMOTE_COMPLETION_INDEXING, GIT_REMOTE_COMPLETION_INDEXING,
GIT_REMOTE_COMPLETION_ERROR, GIT_REMOTE_COMPLETION_ERROR
} git_remote_completion_t; } git_remote_completion_t;
/** Push network progress notification function */ /** Push network progress notification function */
...@@ -665,7 +665,7 @@ typedef enum { ...@@ -665,7 +665,7 @@ typedef enum {
/** /**
* Force pruning off * Force pruning off
*/ */
GIT_FETCH_NO_PRUNE, GIT_FETCH_NO_PRUNE
} git_fetch_prune_t; } git_fetch_prune_t;
/** /**
...@@ -690,7 +690,7 @@ typedef enum { ...@@ -690,7 +690,7 @@ typedef enum {
/** /**
* Ask for the all the tags. * Ask for the all the tags.
*/ */
GIT_REMOTE_DOWNLOAD_TAGS_ALL, GIT_REMOTE_DOWNLOAD_TAGS_ALL
} git_remote_autotag_option_t; } git_remote_autotag_option_t;
/** /**
......
...@@ -141,7 +141,7 @@ typedef enum { ...@@ -141,7 +141,7 @@ typedef enum {
* `git_repository_open_ext` with this flag will error out if either * `git_repository_open_ext` with this flag will error out if either
* $GIT_WORK_TREE or $GIT_COMMON_DIR is set. * $GIT_WORK_TREE or $GIT_COMMON_DIR is set.
*/ */
GIT_REPOSITORY_OPEN_FROM_ENV = (1 << 4), GIT_REPOSITORY_OPEN_FROM_ENV = (1 << 4)
} git_repository_open_flag_t; } git_repository_open_flag_t;
/** /**
...@@ -267,7 +267,7 @@ typedef enum { ...@@ -267,7 +267,7 @@ typedef enum {
* If an alternate workdir is specified, use relative paths for the gitdir * If an alternate workdir is specified, use relative paths for the gitdir
* and core.worktree. * and core.worktree.
*/ */
GIT_REPOSITORY_INIT_RELATIVE_GITLINK = (1u << 6), GIT_REPOSITORY_INIT_RELATIVE_GITLINK = (1u << 6)
} git_repository_init_flag_t; } git_repository_init_flag_t;
/** /**
...@@ -292,7 +292,7 @@ typedef enum { ...@@ -292,7 +292,7 @@ typedef enum {
/** /**
* Use "--shared=all" behavior, adding world readability. * Use "--shared=all" behavior, adding world readability.
*/ */
GIT_REPOSITORY_INIT_SHARED_ALL = 0002777, GIT_REPOSITORY_INIT_SHARED_ALL = 0002777
} git_repository_init_mode_t; } git_repository_init_mode_t;
/** /**
...@@ -876,7 +876,7 @@ typedef enum { ...@@ -876,7 +876,7 @@ typedef enum {
GIT_REPOSITORY_STATE_REBASE_INTERACTIVE, GIT_REPOSITORY_STATE_REBASE_INTERACTIVE,
GIT_REPOSITORY_STATE_REBASE_MERGE, GIT_REPOSITORY_STATE_REBASE_MERGE,
GIT_REPOSITORY_STATE_APPLY_MAILBOX, GIT_REPOSITORY_STATE_APPLY_MAILBOX,
GIT_REPOSITORY_STATE_APPLY_MAILBOX_OR_REBASE, GIT_REPOSITORY_STATE_APPLY_MAILBOX_OR_REBASE
} git_repository_state_t; } git_repository_state_t;
/** /**
......
...@@ -26,7 +26,7 @@ GIT_BEGIN_DECL ...@@ -26,7 +26,7 @@ GIT_BEGIN_DECL
typedef enum { typedef enum {
GIT_RESET_SOFT = 1, /**< Move the head to the given commit */ GIT_RESET_SOFT = 1, /**< Move the head to the given commit */
GIT_RESET_MIXED = 2, /**< SOFT plus reset index to the commit */ GIT_RESET_MIXED = 2, /**< SOFT plus reset index to the commit */
GIT_RESET_HARD = 3, /**< MIXED plus changes in working tree discarded */ GIT_RESET_HARD = 3 /**< MIXED plus changes in working tree discarded */
} git_reset_t; } git_reset_t;
/** /**
......
...@@ -74,7 +74,7 @@ typedef enum { ...@@ -74,7 +74,7 @@ typedef enum {
/** The spec targeted a range of commits. */ /** The spec targeted a range of commits. */
GIT_REVSPEC_RANGE = 1 << 1, GIT_REVSPEC_RANGE = 1 << 1,
/** The spec used the '...' operator, which invokes special semantics. */ /** The spec used the '...' operator, which invokes special semantics. */
GIT_REVSPEC_MERGE_BASE = 1 << 2, GIT_REVSPEC_MERGE_BASE = 1 << 2
} git_revspec_t; } git_revspec_t;
/** /**
......
...@@ -49,7 +49,7 @@ typedef enum { ...@@ -49,7 +49,7 @@ typedef enum {
* order; this sorting mode can be combined with * order; this sorting mode can be combined with
* any of the above. * any of the above.
*/ */
GIT_SORT_REVERSE = 1 << 2, GIT_SORT_REVERSE = 1 << 2
} git_sort_t; } git_sort_t;
/** /**
......
...@@ -44,7 +44,7 @@ typedef enum { ...@@ -44,7 +44,7 @@ typedef enum {
* All ignored files are also stashed and then cleaned up from * All ignored files are also stashed and then cleaned up from
* the working directory * the working directory
*/ */
GIT_STASH_INCLUDE_IGNORED = (1 << 2), GIT_STASH_INCLUDE_IGNORED = (1 << 2)
} git_stash_flags; } git_stash_flags;
/** /**
...@@ -78,7 +78,7 @@ typedef enum { ...@@ -78,7 +78,7 @@ typedef enum {
/* Try to reinstate not only the working tree's changes, /* Try to reinstate not only the working tree's changes,
* but also the index's changes. * but also the index's changes.
*/ */
GIT_STASH_APPLY_REINSTATE_INDEX = (1 << 0), GIT_STASH_APPLY_REINSTATE_INDEX = (1 << 0)
} git_stash_apply_flags; } git_stash_apply_flags;
/** Stash apply progression states */ /** Stash apply progression states */
...@@ -104,7 +104,7 @@ typedef enum { ...@@ -104,7 +104,7 @@ typedef enum {
GIT_STASH_APPLY_PROGRESS_CHECKOUT_MODIFIED, GIT_STASH_APPLY_PROGRESS_CHECKOUT_MODIFIED,
/** The stash was applied successfully. */ /** The stash was applied successfully. */
GIT_STASH_APPLY_PROGRESS_DONE, GIT_STASH_APPLY_PROGRESS_DONE
} git_stash_apply_progress_t; } git_stash_apply_progress_t;
/** /**
......
...@@ -48,7 +48,7 @@ typedef enum { ...@@ -48,7 +48,7 @@ typedef enum {
GIT_STATUS_WT_UNREADABLE = (1u << 12), GIT_STATUS_WT_UNREADABLE = (1u << 12),
GIT_STATUS_IGNORED = (1u << 14), GIT_STATUS_IGNORED = (1u << 14),
GIT_STATUS_CONFLICTED = (1u << 15), GIT_STATUS_CONFLICTED = (1u << 15)
} git_status_t; } git_status_t;
/** /**
...@@ -87,7 +87,7 @@ typedef enum { ...@@ -87,7 +87,7 @@ typedef enum {
* Only gives status based on index to working directory comparison, * Only gives status based on index to working directory comparison,
* not comparing the index to the HEAD. * not comparing the index to the HEAD.
*/ */
GIT_STATUS_SHOW_WORKDIR_ONLY = 2, GIT_STATUS_SHOW_WORKDIR_ONLY = 2
} git_status_show_t; } git_status_show_t;
/** /**
...@@ -204,7 +204,7 @@ typedef enum { ...@@ -204,7 +204,7 @@ typedef enum {
* Unreadable files will be detected and given the status * Unreadable files will be detected and given the status
* untracked instead of unreadable. * untracked instead of unreadable.
*/ */
GIT_STATUS_OPT_INCLUDE_UNREADABLE_AS_UNTRACKED = (1u << 15), GIT_STATUS_OPT_INCLUDE_UNREADABLE_AS_UNTRACKED = (1u << 15)
} git_status_opt_t; } git_status_opt_t;
#define GIT_STATUS_OPT_DEFAULTS \ #define GIT_STATUS_OPT_DEFAULTS \
......
...@@ -85,7 +85,7 @@ typedef enum { ...@@ -85,7 +85,7 @@ typedef enum {
GIT_SUBMODULE_STATUS_WD_MODIFIED = (1u << 10), GIT_SUBMODULE_STATUS_WD_MODIFIED = (1u << 10),
GIT_SUBMODULE_STATUS_WD_INDEX_MODIFIED = (1u << 11), GIT_SUBMODULE_STATUS_WD_INDEX_MODIFIED = (1u << 11),
GIT_SUBMODULE_STATUS_WD_WD_MODIFIED = (1u << 12), GIT_SUBMODULE_STATUS_WD_WD_MODIFIED = (1u << 12),
GIT_SUBMODULE_STATUS_WD_UNTRACKED = (1u << 13), GIT_SUBMODULE_STATUS_WD_UNTRACKED = (1u << 13)
} git_submodule_status_t; } git_submodule_status_t;
#define GIT_SUBMODULE_STATUS__IN_FLAGS 0x000Fu #define GIT_SUBMODULE_STATUS__IN_FLAGS 0x000Fu
......
...@@ -94,7 +94,7 @@ typedef enum { ...@@ -94,7 +94,7 @@ typedef enum {
* Do not split commit-graph files. The other split strategy-related option * Do not split commit-graph files. The other split strategy-related option
* fields are ignored. * fields are ignored.
*/ */
GIT_COMMIT_GRAPH_SPLIT_STRATEGY_SINGLE_FILE = 0, GIT_COMMIT_GRAPH_SPLIT_STRATEGY_SINGLE_FILE = 0
} git_commit_graph_split_strategy_t; } git_commit_graph_split_strategy_t;
/** /**
......
...@@ -69,11 +69,8 @@ struct git_odb_backend { ...@@ -69,11 +69,8 @@ struct git_odb_backend {
* If the backend implements a refreshing mechanism, it should be exposed * If the backend implements a refreshing mechanism, it should be exposed
* through this endpoint. Each call to `git_odb_refresh()` will invoke it. * through this endpoint. Each call to `git_odb_refresh()` will invoke it.
* *
* However, the backend implementation should try to stay up-to-date as much * The odb layer will automatically call this when needed on failed
* as possible by itself as libgit2 will not automatically invoke * lookups (ie. `exists()`, `read()`, `read_header()`).
* `git_odb_refresh()`. For instance, a potential strategy for the backend
* implementation to achieve this could be to internally invoke this
* endpoint on failed lookups (ie. `exists()`, `read()`, `read_header()`).
*/ */
int GIT_CALLBACK(refresh)(git_odb_backend *); int GIT_CALLBACK(refresh)(git_odb_backend *);
......
...@@ -79,7 +79,7 @@ typedef enum { ...@@ -79,7 +79,7 @@ typedef enum {
GIT_STREAM_STANDARD = 1, GIT_STREAM_STANDARD = 1,
/** A TLS-encrypted socket. */ /** A TLS-encrypted socket. */
GIT_STREAM_TLS = 2, GIT_STREAM_TLS = 2
} git_stream_t; } git_stream_t;
/** /**
......
...@@ -30,7 +30,7 @@ GIT_BEGIN_DECL ...@@ -30,7 +30,7 @@ GIT_BEGIN_DECL
* Currently unused. * Currently unused.
*/ */
typedef enum { typedef enum {
GIT_TRANSPORTFLAGS_NONE = 0, GIT_TRANSPORTFLAGS_NONE = 0
} git_transport_flags_t; } git_transport_flags_t;
struct git_transport { struct git_transport {
...@@ -289,7 +289,7 @@ typedef enum { ...@@ -289,7 +289,7 @@ typedef enum {
GIT_SERVICE_UPLOADPACK_LS = 1, GIT_SERVICE_UPLOADPACK_LS = 1,
GIT_SERVICE_UPLOADPACK = 2, GIT_SERVICE_UPLOADPACK = 2,
GIT_SERVICE_RECEIVEPACK_LS = 3, GIT_SERVICE_RECEIVEPACK_LS = 3,
GIT_SERVICE_RECEIVEPACK = 4, GIT_SERVICE_RECEIVEPACK = 4
} git_smart_service_t; } git_smart_service_t;
typedef struct git_smart_subtransport git_smart_subtransport; typedef struct git_smart_subtransport git_smart_subtransport;
......
...@@ -386,7 +386,7 @@ typedef int GIT_CALLBACK(git_treewalk_cb)( ...@@ -386,7 +386,7 @@ typedef int GIT_CALLBACK(git_treewalk_cb)(
/** Tree traversal modes */ /** Tree traversal modes */
typedef enum { typedef enum {
GIT_TREEWALK_PRE = 0, /* Pre-order */ GIT_TREEWALK_PRE = 0, /* Pre-order */
GIT_TREEWALK_POST = 1, /* Post-order */ GIT_TREEWALK_POST = 1 /* Post-order */
} git_treewalk_mode; } git_treewalk_mode;
/** /**
...@@ -428,7 +428,7 @@ typedef enum { ...@@ -428,7 +428,7 @@ typedef enum {
/** Update or insert an entry at the specified path */ /** Update or insert an entry at the specified path */
GIT_TREE_UPDATE_UPSERT, GIT_TREE_UPDATE_UPSERT,
/** Remove an entry from the specified path */ /** Remove an entry from the specified path */
GIT_TREE_UPDATE_REMOVE, GIT_TREE_UPDATE_REMOVE
} git_tree_update_t; } git_tree_update_t;
/** /**
......
...@@ -78,7 +78,7 @@ typedef enum { ...@@ -78,7 +78,7 @@ typedef enum {
GIT_OBJECT_BLOB = 3, /**< A file revision object. */ GIT_OBJECT_BLOB = 3, /**< A file revision object. */
GIT_OBJECT_TAG = 4, /**< An annotated tag object. */ GIT_OBJECT_TAG = 4, /**< An annotated tag object. */
GIT_OBJECT_OFS_DELTA = 6, /**< A delta, base is given by an offset. */ GIT_OBJECT_OFS_DELTA = 6, /**< A delta, base is given by an offset. */
GIT_OBJECT_REF_DELTA = 7, /**< A delta, base is given by object id. */ GIT_OBJECT_REF_DELTA = 7 /**< A delta, base is given by object id. */
} git_object_t; } git_object_t;
/** An open object database handle. */ /** An open object database handle. */
...@@ -208,14 +208,14 @@ typedef enum { ...@@ -208,14 +208,14 @@ typedef enum {
GIT_REFERENCE_INVALID = 0, /**< Invalid reference */ GIT_REFERENCE_INVALID = 0, /**< Invalid reference */
GIT_REFERENCE_DIRECT = 1, /**< A reference that points at an object id */ GIT_REFERENCE_DIRECT = 1, /**< A reference that points at an object id */
GIT_REFERENCE_SYMBOLIC = 2, /**< A reference that points at another reference */ GIT_REFERENCE_SYMBOLIC = 2, /**< A reference that points at another reference */
GIT_REFERENCE_ALL = GIT_REFERENCE_DIRECT | GIT_REFERENCE_SYMBOLIC, GIT_REFERENCE_ALL = GIT_REFERENCE_DIRECT | GIT_REFERENCE_SYMBOLIC
} git_reference_t; } git_reference_t;
/** Basic type of any Git branch. */ /** Basic type of any Git branch. */
typedef enum { typedef enum {
GIT_BRANCH_LOCAL = 1, GIT_BRANCH_LOCAL = 1,
GIT_BRANCH_REMOTE = 2, GIT_BRANCH_REMOTE = 2,
GIT_BRANCH_ALL = GIT_BRANCH_LOCAL|GIT_BRANCH_REMOTE, GIT_BRANCH_ALL = GIT_BRANCH_LOCAL|GIT_BRANCH_REMOTE
} git_branch_t; } git_branch_t;
/** Valid modes for index and tree entries. */ /** Valid modes for index and tree entries. */
...@@ -225,7 +225,7 @@ typedef enum { ...@@ -225,7 +225,7 @@ typedef enum {
GIT_FILEMODE_BLOB = 0100644, GIT_FILEMODE_BLOB = 0100644,
GIT_FILEMODE_BLOB_EXECUTABLE = 0100755, GIT_FILEMODE_BLOB_EXECUTABLE = 0100755,
GIT_FILEMODE_LINK = 0120000, GIT_FILEMODE_LINK = 0120000,
GIT_FILEMODE_COMMIT = 0160000, GIT_FILEMODE_COMMIT = 0160000
} git_filemode_t; } git_filemode_t;
/** /**
...@@ -334,7 +334,7 @@ typedef enum { ...@@ -334,7 +334,7 @@ typedef enum {
GIT_SUBMODULE_IGNORE_NONE = 1, /**< any change or untracked == dirty */ GIT_SUBMODULE_IGNORE_NONE = 1, /**< any change or untracked == dirty */
GIT_SUBMODULE_IGNORE_UNTRACKED = 2, /**< dirty if tracked files change */ GIT_SUBMODULE_IGNORE_UNTRACKED = 2, /**< dirty if tracked files change */
GIT_SUBMODULE_IGNORE_DIRTY = 3, /**< only dirty if HEAD moved */ GIT_SUBMODULE_IGNORE_DIRTY = 3, /**< only dirty if HEAD moved */
GIT_SUBMODULE_IGNORE_ALL = 4, /**< never dirty */ GIT_SUBMODULE_IGNORE_ALL = 4 /**< never dirty */
} git_submodule_ignore_t; } git_submodule_ignore_t;
/** /**
...@@ -350,7 +350,7 @@ typedef enum { ...@@ -350,7 +350,7 @@ typedef enum {
typedef enum { typedef enum {
GIT_SUBMODULE_RECURSE_NO = 0, GIT_SUBMODULE_RECURSE_NO = 0,
GIT_SUBMODULE_RECURSE_YES = 1, GIT_SUBMODULE_RECURSE_YES = 1,
GIT_SUBMODULE_RECURSE_ONDEMAND = 2, GIT_SUBMODULE_RECURSE_ONDEMAND = 2
} git_submodule_recurse_t; } git_submodule_recurse_t;
typedef struct git_writestream git_writestream; typedef struct git_writestream git_writestream;
......
...@@ -185,7 +185,7 @@ typedef enum { ...@@ -185,7 +185,7 @@ typedef enum {
/* Prune working tree even if it is locked */ /* Prune working tree even if it is locked */
GIT_WORKTREE_PRUNE_LOCKED = 1u << 1, GIT_WORKTREE_PRUNE_LOCKED = 1u << 1,
/* Prune checked out working tree */ /* Prune checked out working tree */
GIT_WORKTREE_PRUNE_WORKING_TREE = 1u << 2, GIT_WORKTREE_PRUNE_WORKING_TREE = 1u << 2
} git_worktree_prune_t; } git_worktree_prune_t;
/** /**
......
...@@ -15,7 +15,7 @@ ...@@ -15,7 +15,7 @@
typedef enum { typedef enum {
GIT_ANNOTATED_COMMIT_REAL = 1, GIT_ANNOTATED_COMMIT_REAL = 1,
GIT_ANNOTATED_COMMIT_VIRTUAL = 2, GIT_ANNOTATED_COMMIT_VIRTUAL = 2
} git_annotated_commit_t; } git_annotated_commit_t;
/** /**
......
...@@ -629,7 +629,7 @@ static int collect_attr_files( ...@@ -629,7 +629,7 @@ static int collect_attr_files(
const char *workdir = git_repository_workdir(repo); const char *workdir = git_repository_workdir(repo);
attr_walk_up_info info = { NULL }; attr_walk_up_info info = { NULL };
GIT_ASSERT(!git_path_is_absolute(path)); GIT_ASSERT(!git_fs_path_is_absolute(path));
if ((error = attr_setup(repo, attr_session, opts)) < 0) if ((error = attr_setup(repo, attr_session, opts)) < 0)
return error; return error;
...@@ -637,10 +637,10 @@ static int collect_attr_files( ...@@ -637,10 +637,10 @@ static int collect_attr_files(
/* Resolve path in a non-bare repo */ /* Resolve path in a non-bare repo */
if (workdir != NULL) { if (workdir != NULL) {
if (!(error = git_repository_workdir_path(&dir, repo, path))) if (!(error = git_repository_workdir_path(&dir, repo, path)))
error = git_path_find_dir(&dir); error = git_fs_path_find_dir(&dir);
} }
else { else {
error = git_path_dirname_r(&dir, path); error = git_fs_path_dirname_r(&dir, path);
} }
if (error < 0) if (error < 0)
...@@ -670,7 +670,7 @@ static int collect_attr_files( ...@@ -670,7 +670,7 @@ static int collect_attr_files(
if (!strcmp(dir.ptr, ".")) if (!strcmp(dir.ptr, "."))
error = push_one_attr(&info, ""); error = push_one_attr(&info, "");
else else
error = git_path_walk_up(&dir, workdir, push_one_attr, &info); error = git_fs_path_walk_up(&dir, workdir, push_one_attr, &info);
if (error < 0) if (error < 0)
goto cleanup; goto cleanup;
......
...@@ -345,7 +345,7 @@ int git_attr_file__parse_buffer( ...@@ -345,7 +345,7 @@ int git_attr_file__parse_buffer(
int error = 0; int error = 0;
/* If subdir file path, convert context for file paths */ /* If subdir file path, convert context for file paths */
if (attrs->entry && git_path_root(attrs->entry->path) < 0 && if (attrs->entry && git_fs_path_root(attrs->entry->path) < 0 &&
!git__suffixcmp(attrs->entry->path, "/" GIT_ATTR_FILE)) !git__suffixcmp(attrs->entry->path, "/" GIT_ATTR_FILE))
context = attrs->entry->path; context = attrs->entry->path;
...@@ -560,7 +560,7 @@ int git_attr_path__init( ...@@ -560,7 +560,7 @@ int git_attr_path__init(
/* build full path as best we can */ /* build full path as best we can */
git_str_init(&info->full, 0); git_str_init(&info->full, 0);
if (git_path_join_unrooted(&info->full, path, base, &root) < 0) if (git_fs_path_join_unrooted(&info->full, path, base, &root) < 0)
return -1; return -1;
info->path = info->full.ptr + root; info->path = info->full.ptr + root;
...@@ -596,7 +596,7 @@ int git_attr_path__init( ...@@ -596,7 +596,7 @@ int git_attr_path__init(
case GIT_DIR_FLAG_UNKNOWN: case GIT_DIR_FLAG_UNKNOWN:
default: default:
info->is_dir = (int)git_path_isdir(info->full.ptr); info->is_dir = (int)git_fs_path_isdir(info->full.ptr);
break; break;
} }
......
...@@ -12,6 +12,7 @@ ...@@ -12,6 +12,7 @@
#include "config.h" #include "config.h"
#include "sysdir.h" #include "sysdir.h"
#include "ignore.h" #include "ignore.h"
#include "path.h"
GIT_INLINE(int) attr_cache_lock(git_attr_cache *cache) GIT_INLINE(int) attr_cache_lock(git_attr_cache *cache)
{ {
...@@ -43,11 +44,12 @@ int git_attr_cache__alloc_file_entry( ...@@ -43,11 +44,12 @@ int git_attr_cache__alloc_file_entry(
const char *path, const char *path,
git_pool *pool) git_pool *pool)
{ {
git_str fullpath_str = GIT_STR_INIT;
size_t baselen = 0, pathlen = strlen(path); size_t baselen = 0, pathlen = strlen(path);
size_t cachesize = sizeof(git_attr_file_entry) + pathlen + 1; size_t cachesize = sizeof(git_attr_file_entry) + pathlen + 1;
git_attr_file_entry *ce; git_attr_file_entry *ce;
if (base != NULL && git_path_root(path) < 0) { if (base != NULL && git_fs_path_root(path) < 0) {
baselen = strlen(base); baselen = strlen(base);
cachesize += baselen; cachesize += baselen;
...@@ -66,7 +68,10 @@ int git_attr_cache__alloc_file_entry( ...@@ -66,7 +68,10 @@ int git_attr_cache__alloc_file_entry(
} }
memcpy(&ce->fullpath[baselen], path, pathlen); memcpy(&ce->fullpath[baselen], path, pathlen);
if (git_path_validate_workdir_with_len(repo, ce->fullpath, pathlen + baselen) < 0) fullpath_str.ptr = ce->fullpath;
fullpath_str.size = pathlen + baselen;
if (git_path_validate_str_length(repo, &fullpath_str) < 0)
return -1; return -1;
ce->path = &ce->fullpath[baselen]; ce->path = &ce->fullpath[baselen];
...@@ -169,11 +174,11 @@ static int attr_cache_lookup( ...@@ -169,11 +174,11 @@ static int attr_cache_lookup(
git_attr_file *file = NULL; git_attr_file *file = NULL;
/* join base and path as needed */ /* join base and path as needed */
if (source->base != NULL && git_path_root(source->filename) < 0) { if (source->base != NULL && git_fs_path_root(source->filename) < 0) {
git_str *p = attr_session ? &attr_session->tmp : &path; git_str *p = attr_session ? &attr_session->tmp : &path;
if (git_str_joinpath(p, source->base, source->filename) < 0 || if (git_str_joinpath(p, source->base, source->filename) < 0 ||
git_path_validate_workdir_buf(repo, p) < 0) git_path_validate_str_length(repo, p) < 0)
return -1; return -1;
filename = p->ptr; filename = p->ptr;
......
...@@ -205,7 +205,7 @@ int git_blob__create_from_paths( ...@@ -205,7 +205,7 @@ int git_blob__create_from_paths(
content_path = path.ptr; content_path = path.ptr;
} }
if ((error = git_path_lstat(content_path, &st)) < 0 || if ((error = git_fs_path_lstat(content_path, &st)) < 0 ||
(error = git_repository_odb(&odb, repo)) < 0) (error = git_repository_odb(&odb, repo)) < 0)
goto done; goto done;
...@@ -280,7 +280,7 @@ int git_blob_create_from_disk( ...@@ -280,7 +280,7 @@ int git_blob_create_from_disk(
git_str full_path = GIT_STR_INIT; git_str full_path = GIT_STR_INIT;
const char *workdir, *hintpath = NULL; const char *workdir, *hintpath = NULL;
if ((error = git_path_prettify(&full_path, path, NULL)) < 0) { if ((error = git_fs_path_prettify(&full_path, path, NULL)) < 0) {
git_str_dispose(&full_path); git_str_dispose(&full_path);
return error; return error;
} }
......
...@@ -27,10 +27,11 @@ ...@@ -27,10 +27,11 @@
#include "diff_generate.h" #include "diff_generate.h"
#include "pathspec.h" #include "pathspec.h"
#include "diff_xdiff.h" #include "diff_xdiff.h"
#include "path.h" #include "fs_path.h"
#include "attr.h" #include "attr.h"
#include "pool.h" #include "pool.h"
#include "strmap.h" #include "strmap.h"
#include "path.h"
/* See docs/checkout-internals.md for more information */ /* See docs/checkout-internals.md for more information */
...@@ -44,7 +45,7 @@ enum { ...@@ -44,7 +45,7 @@ enum {
CHECKOUT_ACTION__UPDATE_CONFLICT = 32, CHECKOUT_ACTION__UPDATE_CONFLICT = 32,
CHECKOUT_ACTION__MAX = 32, CHECKOUT_ACTION__MAX = 32,
CHECKOUT_ACTION__REMOVE_AND_UPDATE = CHECKOUT_ACTION__REMOVE_AND_UPDATE =
(CHECKOUT_ACTION__UPDATE_BLOB | CHECKOUT_ACTION__REMOVE), (CHECKOUT_ACTION__UPDATE_BLOB | CHECKOUT_ACTION__REMOVE)
}; };
typedef struct { typedef struct {
...@@ -328,7 +329,7 @@ static int checkout_target_fullpath( ...@@ -328,7 +329,7 @@ static int checkout_target_fullpath(
if (path && git_str_puts(&data->target_path, path) < 0) if (path && git_str_puts(&data->target_path, path) < 0)
return -1; return -1;
if (git_path_validate_workdir_buf(data->repo, &data->target_path) < 0) if (git_path_validate_str_length(data->repo, &data->target_path) < 0)
return -1; return -1;
*out = &data->target_path; *out = &data->target_path;
...@@ -347,7 +348,7 @@ static bool wd_item_is_removable( ...@@ -347,7 +348,7 @@ static bool wd_item_is_removable(
if (checkout_target_fullpath(&full, data, wd->path) < 0) if (checkout_target_fullpath(&full, data, wd->path) < 0)
return false; return false;
return !full || !git_path_contains(full, DOT_GIT); return !full || !git_fs_path_contains(full, DOT_GIT);
} }
static int checkout_queue_remove(checkout_data *data, const char *path) static int checkout_queue_remove(checkout_data *data, const char *path)
...@@ -481,7 +482,7 @@ static bool checkout_is_empty_dir(checkout_data *data, const char *path) ...@@ -481,7 +482,7 @@ static bool checkout_is_empty_dir(checkout_data *data, const char *path)
if (checkout_target_fullpath(&fullpath, data, path) < 0) if (checkout_target_fullpath(&fullpath, data, path) < 0)
return false; return false;
return git_path_is_empty_dir(fullpath->ptr); return git_fs_path_is_empty_dir(fullpath->ptr);
} }
static int checkout_action_with_wd( static int checkout_action_with_wd(
...@@ -1201,12 +1202,12 @@ static int checkout_conflicts_mark_directoryfile( ...@@ -1201,12 +1202,12 @@ static int checkout_conflicts_mark_directoryfile(
goto done; goto done;
} }
prefixed = git_path_equal_or_prefixed(path, entry->path, NULL); prefixed = git_fs_path_equal_or_prefixed(path, entry->path, NULL);
if (prefixed == GIT_PATH_EQUAL) if (prefixed == GIT_FS_PATH_EQUAL)
continue; continue;
if (prefixed == GIT_PATH_PREFIX) if (prefixed == GIT_FS_PATH_PREFIX)
conflict->directoryfile = 1; conflict->directoryfile = 1;
break; break;
...@@ -1280,14 +1281,14 @@ static int checkout_verify_paths( ...@@ -1280,14 +1281,14 @@ static int checkout_verify_paths(
unsigned int flags = GIT_PATH_REJECT_WORKDIR_DEFAULTS; unsigned int flags = GIT_PATH_REJECT_WORKDIR_DEFAULTS;
if (action & CHECKOUT_ACTION__REMOVE) { if (action & CHECKOUT_ACTION__REMOVE) {
if (!git_path_validate(repo, delta->old_file.path, delta->old_file.mode, flags)) { if (!git_path_is_valid(repo, delta->old_file.path, delta->old_file.mode, flags)) {
git_error_set(GIT_ERROR_CHECKOUT, "cannot remove invalid path '%s'", delta->old_file.path); git_error_set(GIT_ERROR_CHECKOUT, "cannot remove invalid path '%s'", delta->old_file.path);
return -1; return -1;
} }
} }
if (action & ~CHECKOUT_ACTION__REMOVE) { if (action & ~CHECKOUT_ACTION__REMOVE) {
if (!git_path_validate(repo, delta->new_file.path, delta->new_file.mode, flags)) { if (!git_path_is_valid(repo, delta->new_file.path, delta->new_file.mode, flags)) {
git_error_set(GIT_ERROR_CHECKOUT, "cannot checkout to invalid path '%s'", delta->new_file.path); git_error_set(GIT_ERROR_CHECKOUT, "cannot checkout to invalid path '%s'", delta->new_file.path);
return -1; return -1;
} }
...@@ -1949,7 +1950,7 @@ static int checkout_path_suffixed(git_str *path, const char *suffix) ...@@ -1949,7 +1950,7 @@ static int checkout_path_suffixed(git_str *path, const char *suffix)
path_len = git_str_len(path); path_len = git_str_len(path);
while (git_path_exists(git_str_cstr(path)) && i < INT_MAX) { while (git_fs_path_exists(git_str_cstr(path)) && i < INT_MAX) {
git_str_truncate(path, path_len); git_str_truncate(path, path_len);
if ((error = git_str_putc(path, '_')) < 0 || if ((error = git_str_putc(path, '_')) < 0 ||
...@@ -2034,7 +2035,7 @@ static int checkout_merge_path( ...@@ -2034,7 +2035,7 @@ static int checkout_merge_path(
int error = 0; int error = 0;
if ((error = git_str_joinpath(out, data->opts.target_directory, result->path)) < 0 || if ((error = git_str_joinpath(out, data->opts.target_directory, result->path)) < 0 ||
(error = git_path_validate_workdir_buf(data->repo, out)) < 0) (error = git_path_validate_str_length(data->repo, out)) < 0)
return error; return error;
/* Most conflicts simply use the filename in the index */ /* Most conflicts simply use the filename in the index */
...@@ -2337,10 +2338,10 @@ static int validate_target_directory(checkout_data *data) ...@@ -2337,10 +2338,10 @@ static int validate_target_directory(checkout_data *data)
{ {
int error; int error;
if ((error = git_path_validate_workdir(data->repo, data->opts.target_directory)) < 0) if ((error = git_path_validate_length(data->repo, data->opts.target_directory)) < 0)
return error; return error;
if (git_path_isdir(data->opts.target_directory)) if (git_fs_path_isdir(data->opts.target_directory))
return 0; return 0;
error = checkout_mkdir(data, data->opts.target_directory, NULL, error = checkout_mkdir(data, data->opts.target_directory, NULL,
...@@ -2507,7 +2508,7 @@ static int checkout_data_init( ...@@ -2507,7 +2508,7 @@ static int checkout_data_init(
(error = git_vector_init(&data->remove_conflicts, 0, NULL)) < 0 || (error = git_vector_init(&data->remove_conflicts, 0, NULL)) < 0 ||
(error = git_vector_init(&data->update_conflicts, 0, NULL)) < 0 || (error = git_vector_init(&data->update_conflicts, 0, NULL)) < 0 ||
(error = git_str_puts(&data->target_path, data->opts.target_directory)) < 0 || (error = git_str_puts(&data->target_path, data->opts.target_directory)) < 0 ||
(error = git_path_to_dir(&data->target_path)) < 0 || (error = git_fs_path_to_dir(&data->target_path)) < 0 ||
(error = git_strmap_new(&data->mkdir_map)) < 0) (error = git_strmap_new(&data->mkdir_map)) < 0)
goto cleanup; goto cleanup;
......
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment