Commit 760a5acc by yuangli

Merge branch 'main' into fix-invalid-branch-name

parents 1912f145 92ffdd2c

Too many changes to show.

To preserve performance only 1000 of 1000+ files are displayed.

# This file is an example configuration for clang-format 5.0.
#
# Note that this style definition should only be understood as a hint
# for writing new code. The rules are still work-in-progress and does
# not yet exactly match the style we have in the existing code.
# C Language specifics
Language: Cpp
# Use tabs whenever we need to fill whitespace that spans at least from one tab
# stop to the next one.
#
# These settings are mirrored in .editorconfig. Keep them in sync.
UseTab: ForIndentation
TabWidth: 8
IndentWidth: 8
ContinuationIndentWidth: 8
ColumnLimit: 80
AlignAfterOpenBracket: AlwaysBreak
AlignEscapedNewlines: Left
AlignTrailingComments: false
# Allow putting parameters onto the next line
AllowAllArgumentsOnNextLine: false
AllowAllParametersOfDeclarationOnNextLine: false
# Don't allow short braced statements to be on a single line
# if (a) not if (a) return;
# return;
AllowShortBlocksOnASingleLine: false
AllowShortFunctionsOnASingleLine: None
AllowShortLoopsOnASingleLine: false
AllowShortLambdasOnASingleLine: None
# Pack as many parameters or arguments onto the same line as possible
# int myFunction(int aaaaaaaaaaaa, int bbbbbbbb,
# int cccc);
BinPackArguments: true
BinPackParameters: false
BreakBeforeBraces: Linux
BreakBeforeBinaryOperators: None
BreakBeforeTernaryOperators: false
BreakStringLiterals: false
# The number of spaces before trailing line comments (// - comments).
# This does not affect trailing block comments (/* - comments).
SpacesBeforeTrailingComments: 1
# Don't insert spaces in casts
# x = (int32) y; not x = ( int32 ) y;
SpacesInCStyleCastParentheses: false
# Don't insert spaces inside container literals
# var arr = [1, 2, 3]; not var arr = [ 1, 2, 3 ];
SpacesInContainerLiterals: false
# Don't insert spaces after '(' or before ')'
# f(arg); not f( arg );
SpacesInParentheses: false
# Don't insert spaces after '[' or before ']'
# int a[5]; not int a[ 5 ];
SpacesInSquareBrackets: false
# Insert a space after '{' and before '}' in struct initializers
Cpp11BracedListStyle: false
# A list of macros that should be interpreted as foreach loops instead of as
# function calls.
ForEachMacros:
- 'git_array_foreach'
- 'git_vector_foreach'
# The maximum number of consecutive empty lines to keep.
MaxEmptyLinesToKeep: 1
# No empty line at the start of a block.
KeepEmptyLinesAtTheStartOfBlocks: false
# Penalties
# This decides what order things should be done if a line is too long
PenaltyBreakAssignment: 10
PenaltyBreakBeforeFirstCallParameter: 30
PenaltyBreakComment: 10
PenaltyBreakFirstLessLess: 0
PenaltyBreakString: 10
PenaltyExcessCharacter: 100
PenaltyReturnTypeOnItsOwnLine: 60
SortIncludes: false
changelog:
categories:
- title: New features
labels:
- feature
- title: Bug fixes
labels:
- bug
- title: Code cleanups
labels:
- cleanup
- title: CI improvements
labels:
- build
- title: Documentation improvements
labels:
- documentation
- title: Other changes
labels:
- '*'
# Benchmark libgit2 against the git reference implementation.
name: Benchmark
on:
workflow_dispatch:
schedule:
- cron: '15 4 * * *'
jobs:
# Run our nightly builds. We build a matrix with the various build
# targets and their details. Then we build either in a docker container
# (Linux) or on the actual hosts (macOS, Windows).
build:
# Only run scheduled workflows on the main repository; prevents people
# from using build minutes on their forks.
if: github.repository == 'libgit2/libgit2'
strategy:
matrix:
platform:
- name: "Linux (clang, OpenSSL)"
env:
CC: clang
CMAKE_OPTIONS: -DUSE_HTTPS=OpenSSL -DREGEX_BACKEND=builtin -DDEPRECATE_HARD=ON -DUSE_GSSAPI=ON -DBUILD_TESTS=OFF -DBUILD_EXAMPLES=OFF -DBUILD_CLI=ON -DCMAKE_BUILD_TYPE=Release
CMAKE_BUILD_OPTIONS: --config Release
id: linux
os: ubuntu-latest
setup-script: ubuntu
- name: "macOS"
os: macos-10.15
env:
CC: clang
CMAKE_OPTIONS: -DREGEX_BACKEND=regcomp_l -DDEPRECATE_HARD=ON -DUSE_GSSAPI=ON -DBUILD_TESTS=OFF -DBUILD_EXAMPLES=OFF -DBUILD_CLI=ON -DCMAKE_BUILD_TYPE=Release
CMAKE_BUILD_OPTIONS: --config Release
PKG_CONFIG_PATH: /usr/local/opt/openssl/lib/pkgconfig
id: macos
setup-script: osx
- name: "Windows (amd64, Visual Studio)"
os: windows-2019
env:
ARCH: amd64
CMAKE_GENERATOR: Visual Studio 16 2019
CMAKE_OPTIONS: -A x64 -DDEPRECATE_HARD=ON -DBUILD_TESTS=OFF -DBUILD_EXAMPLES=OFF -DBUILD_CLI=ON -DCMAKE_BUILD_TYPE=Release
CMAKE_BUILD_OPTIONS: --config Release
id: windows
setup-script: win32
fail-fast: false
name: "Build ${{ matrix.platform.name }}"
env: ${{ matrix.platform.env }}
runs-on: ${{ matrix.platform.os }}
steps:
- name: Check out repository
uses: actions/checkout@v2
with:
path: source
fetch-depth: 0
- name: Set up benchmark environment
run: source/ci/setup-${{ matrix.platform.setup-script }}-benchmark.sh
shell: bash
if: matrix.platform.setup-script != ''
- name: Build
run: |
mkdir build && cd build
../source/ci/build.sh
shell: bash
- name: Benchmark
run: |
if [[ "$(uname -s)" == MINGW* ]]; then
GIT2_CLI="$(cygpath -w $(pwd))\\build\\Release\\git2_cli"
else
GIT2_CLI="$(pwd)/build/git2_cli"
fi
mkdir benchmark && cd benchmark
../source/tests/benchmarks/benchmark.sh --baseline-cli "git" --cli "${GIT2_CLI}" --json benchmarks.json --zip benchmarks.zip
shell: bash
- name: Upload results
uses: actions/upload-artifact@v2
with:
name: benchmark-${{ matrix.platform.id }}
path: benchmark
if: always()
name: "CodeQL"
on:
workflow_dispatch:
schedule:
- cron: '21 3 * * 1'
env:
docker-registry: docker.pkg.github.com
jobs:
analyze:
name: Analyze
runs-on: ubuntu-latest
steps:
- name: Check out repository
uses: actions/checkout@v2
with:
fetch-depth: 0
# Initializes the CodeQL tools for scanning.
- name: Initialize CodeQL
uses: github/codeql-action/init@v1
with:
languages: 'cpp'
- name: Build
run: |
mkdir build
cd build
cmake .. -DREGEX_BACKEND=pcre -DDEPRECATE_HARD=ON -DUSE_BUNDLED_ZLIB=ON
cmake --build .
- name: Perform CodeQL Analysis
uses: github/codeql-action/analyze@v1
...@@ -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
...@@ -406,30 +406,35 @@ OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. ...@@ -406,30 +406,35 @@ OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
---------------------------------------------------------------------- ----------------------------------------------------------------------
The regex library (deps/regex/) is licensed under the GNU LGPL The bundled PCRE implementation (deps/pcre/) is licensed under the BSD
(available at the end of this file). license.
Definitions for data structures and routines for the regular Redistribution and use in source and binary forms, with or without
expression library. modification, are permitted provided that the following conditions are met:
Copyright (C) 1985,1989-93,1995-98,2000,2001,2002,2003,2005,2006,2008 * Redistributions of source code must retain the above copyright notice,
Free Software Foundation, Inc. this list of conditions and the following disclaimer.
This file is part of the GNU C Library.
The GNU C Library is free software; you can redistribute it and/or * Redistributions in binary form must reproduce the above copyright
modify it under the terms of the GNU Lesser General Public notice, this list of conditions and the following disclaimer in the
License as published by the Free Software Foundation; either documentation and/or other materials provided with the distribution.
version 2.1 of the License, or (at your option) any later version.
The GNU C Library is distributed in the hope that it will be useful, * Neither the name of the University of Cambridge nor the name of Google
but WITHOUT ANY WARRANTY; without even the implied warranty of Inc. nor the names of their contributors may be used to endorse or
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU promote products derived from this software without specific prior
Lesser General Public License for more details. written permission.
You should have received a copy of the GNU Lesser General Public THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
License along with the GNU C Library; if not, write to the Free AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
02110-1301 USA. ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
POSSIBILITY OF SUCH DAMAGE.
---------------------------------------------------------------------- ----------------------------------------------------------------------
...@@ -1127,3 +1132,55 @@ STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ...@@ -1127,3 +1132,55 @@ STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
OF THE POSSIBILITY OF SUCH DAMAGE. OF THE POSSIBILITY OF SUCH DAMAGE.
----------------------------------------------------------------------
The xoroshiro256** implementation is licensed in the public domain:
Written in 2018 by David Blackman and Sebastiano Vigna (vigna@acm.org)
To the extent possible under law, the author has dedicated all copyright
and related and neighboring rights to this software to the public domain
worldwide. This software is distributed without any warranty.
See <http://creativecommons.org/publicdomain/zero/1.0/>.
----------------------------------------------------------------------
The built-in SHA256 support (src/hash/rfc6234) is taken from RFC 6234
under the following license:
Copyright (c) 2011 IETF Trust and the persons identified as
authors of the code. All rights reserved.
Redistribution and use in source and binary forms, with or
without modification, are permitted provided that the following
conditions are met:
- Redistributions of source code must retain the above
copyright notice, this list of conditions and
the following disclaimer.
- Redistributions in binary form must reproduce the above
copyright notice, this list of conditions and the following
disclaimer in the documentation and/or other materials provided
with the distribution.
- Neither the name of Internet Society, IETF or IETF Trust, nor
the names of specific contributors, may be used to endorse or
promote products derived from this software without specific
prior written permission.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND
CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES,
INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
...@@ -4,8 +4,8 @@ libgit2 - the Git linkable library ...@@ -4,8 +4,8 @@ libgit2 - the Git linkable library
| Build Status | | | Build Status | |
| ------------ | - | | ------------ | - |
| **main** branch CI builds | [![CI Build](https://github.com/libgit2/libgit2/workflows/CI%20Build/badge.svg?event=push)](https://github.com/libgit2/libgit2/actions?query=workflow%3A%22CI+Build%22+event%3Apush) | | **main** branch CI builds | [![CI Build](https://github.com/libgit2/libgit2/workflows/CI%20Build/badge.svg?event=push)](https://github.com/libgit2/libgit2/actions?query=workflow%3A%22CI+Build%22+event%3Apush) |
| **v1.2 branch** CI builds | [![CI Build](https://github.com/libgit2/libgit2/workflows/CI%20Build/badge.svg?branch=maint%2Fv1.2&event=push)](https://github.com/libgit2/libgit2/actions?query=workflow%3A%22CI+Build%22+event%3Apush+branch%3Amaint%2Fv1.2) | | **v1.4 branch** CI builds | [![CI Build](https://github.com/libgit2/libgit2/workflows/CI%20Build/badge.svg?branch=maint%2Fv1.4&event=push)](https://github.com/libgit2/libgit2/actions?query=workflow%3A%22CI+Build%22+event%3Apush+branch%3Amaint%2Fv1.4) |
| **v1.1 branch** CI builds | [![CI Build](https://github.com/libgit2/libgit2/workflows/CI%20Build/badge.svg?branch=maint%2Fv1.1&event=push)](https://github.com/libgit2/libgit2/actions?query=workflow%3A%22CI+Build%22+event%3Apush+branch%3Amaint%2Fv1.1) | | **v1.3 branch** CI builds | [![CI Build](https://github.com/libgit2/libgit2/workflows/CI%20Build/badge.svg?branch=maint%2Fv1.3&event=push)](https://github.com/libgit2/libgit2/actions?query=workflow%3A%22CI+Build%22+event%3Apush+branch%3Amaint%2Fv1.3) |
| **Nightly** builds | [![Nightly Build](https://github.com/libgit2/libgit2/workflows/Nightly%20Build/badge.svg)](https://github.com/libgit2/libgit2/actions?query=workflow%3A%22Nightly+Build%22) [![Coverity Scan Status](https://scan.coverity.com/projects/639/badge.svg)](https://scan.coverity.com/projects/639) | | **Nightly** builds | [![Nightly Build](https://github.com/libgit2/libgit2/workflows/Nightly%20Build/badge.svg)](https://github.com/libgit2/libgit2/actions?query=workflow%3A%22Nightly+Build%22) [![Coverity Scan Status](https://scan.coverity.com/projects/639/badge.svg)](https://scan.coverity.com/projects/639) |
`libgit2` is a portable, pure C implementation of the Git core methods `libgit2` is a portable, pure C implementation of the Git core methods
...@@ -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
...@@ -278,8 +278,8 @@ The following CMake variables are declared: ...@@ -278,8 +278,8 @@ The following CMake variables are declared:
- `CMAKE_INSTALL_LIBDIR`: Where to install libraries to. - `CMAKE_INSTALL_LIBDIR`: Where to install libraries to.
- `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_CLAR`: Build [Clar](https://github.com/vmg/clar)-based test suite (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:
...@@ -301,6 +301,8 @@ compiler and linker. These flags are rarely used but can be useful for ...@@ -301,6 +301,8 @@ compiler and linker. These flags are rarely used but can be useful for
- `CMAKE_FIND_ROOT_PATH`: Override the search path for libraries - `CMAKE_FIND_ROOT_PATH`: Override the search path for libraries
- `ZLIB_LIBRARY`, `OPENSSL_SSL_LIBRARY` AND `OPENSSL_CRYPTO_LIBRARY`: - `ZLIB_LIBRARY`, `OPENSSL_SSL_LIBRARY` AND `OPENSSL_CRYPTO_LIBRARY`:
Tell CMake where to find those specific libraries Tell CMake where to find those specific libraries
- `LINK_WITH_STATIC_LIBRARIES`: Link only with static versions of
system libraries
MacOS X MacOS X
------- -------
...@@ -390,10 +392,10 @@ Here are the bindings to libgit2 that are currently available: ...@@ -390,10 +392,10 @@ Here are the bindings to libgit2 that are currently available:
* parrot-libgit2 <https://github.com/letolabs/parrot-libgit2> * parrot-libgit2 <https://github.com/letolabs/parrot-libgit2>
* Perl * Perl
* Git-Raw <https://github.com/jacquesg/p5-Git-Raw> * Git-Raw <https://github.com/jacquesg/p5-Git-Raw>
* Pharo Smalltalk
* libgit2-pharo-bindings <https://github.com/pharo-vcs/libgit2-pharo-bindings>
* PHP * PHP
* php-git <https://github.com/libgit2/php-git> * php-git <https://github.com/libgit2/php-git>
* PowerShell
* PSGit <https://github.com/PoshCode/PSGit>
* Python * Python
* pygit2 <https://github.com/libgit2/pygit2> * pygit2 <https://github.com/libgit2/pygit2>
* R * R
...@@ -405,6 +407,8 @@ Here are the bindings to libgit2 that are currently available: ...@@ -405,6 +407,8 @@ Here are the bindings to libgit2 that are currently available:
* git2-rs <https://github.com/rust-lang/git2-rs> * git2-rs <https://github.com/rust-lang/git2-rs>
* Swift * Swift
* SwiftGit2 <https://github.com/SwiftGit2/SwiftGit2> * SwiftGit2 <https://github.com/SwiftGit2/SwiftGit2>
* Tcl
* lg2 <https://github.com/apnadkarni/tcl-libgit2>
* Vala * Vala
* libgit2.vapi <https://github.com/apmasell/vapis/blob/master/libgit2.vapi> * libgit2.vapi <https://github.com/apmasell/vapis/blob/master/libgit2.vapi>
......
...@@ -59,7 +59,7 @@ echo "########################################################################## ...@@ -59,7 +59,7 @@ echo "##########################################################################
echo "## Configuring build environment" echo "## Configuring build environment"
echo "##############################################################################" echo "##############################################################################"
echo cmake -DENABLE_WERROR=ON -DBUILD_EXAMPLES=ON -DBUILD_FUZZERS=ON -DUSE_STANDALONE_FUZZERS=ON -G \"${CMAKE_GENERATOR}\" ${CMAKE_OPTIONS} -S \"${SOURCE_DIR}\" echo "${CMAKE}" -DENABLE_WERROR=ON -DBUILD_EXAMPLES=ON -DBUILD_FUZZERS=ON -DUSE_STANDALONE_FUZZERS=ON -G \"${CMAKE_GENERATOR}\" ${CMAKE_OPTIONS} -S \"${SOURCE_DIR}\"
env PATH="${BUILD_PATH}" "${CMAKE}" -DENABLE_WERROR=ON -DBUILD_EXAMPLES=ON -DBUILD_FUZZERS=ON -DUSE_STANDALONE_FUZZERS=ON -G "${CMAKE_GENERATOR}" ${CMAKE_OPTIONS} -S "${SOURCE_DIR}" env PATH="${BUILD_PATH}" "${CMAKE}" -DENABLE_WERROR=ON -DBUILD_EXAMPLES=ON -DBUILD_FUZZERS=ON -DUSE_STANDALONE_FUZZERS=ON -G "${CMAKE_GENERATOR}" ${CMAKE_OPTIONS} -S "${SOURCE_DIR}"
echo "" echo ""
...@@ -69,10 +69,11 @@ echo "########################################################################## ...@@ -69,10 +69,11 @@ echo "##########################################################################
# Determine parallelism; newer cmake supports `--build --parallel` but # Determine parallelism; newer cmake supports `--build --parallel` but
# we cannot yet rely on that. # we cannot yet rely on that.
if [ "${CMAKE_GENERATOR}" = "Unix Makefiles" -a "${CORES}" != "" ]; then if [ "${CMAKE_GENERATOR}" = "Unix Makefiles" -a "${CORES}" != "" -a "${CMAKE_BUILD_OPTIONS}" = "" ]; then
BUILDER=(make -j ${CORES}) BUILDER=(make -j ${CORES})
else else
BUILDER=("${CMAKE}" --build .) BUILDER=("${CMAKE}" --build . ${CMAKE_BUILD_OPTIONS})
fi fi
echo "${BUILDER[@]}"
env PATH="${BUILD_PATH}" "${BUILDER[@]}" env PATH="${BUILD_PATH}" "${BUILDER[@]}"
...@@ -28,17 +28,22 @@ RUN apt-get update && \ ...@@ -28,17 +28,22 @@ RUN apt-get update && \
FROM apt AS mbedtls FROM apt AS mbedtls
RUN cd /tmp && \ RUN cd /tmp && \
curl --location --silent --show-error https://tls.mbed.org/download/mbedtls-2.16.2-apache.tgz | \ curl --location --silent --show-error https://github.com/Mbed-TLS/mbedtls/archive/refs/tags/mbedtls-2.16.2.tar.gz | \
tar -xz && \ tar -xz && \
cd mbedtls-2.16.2 && \ cd mbedtls-mbedtls-2.16.2 && \
scripts/config.pl set MBEDTLS_MD4_C 1 && \ scripts/config.pl set MBEDTLS_MD4_C 1 && \
CFLAGS=-fPIC cmake -G Ninja -DENABLE_PROGRAMS=OFF -DENABLE_TESTING=OFF -DUSE_SHARED_MBEDTLS_LIBRARY=OFF -DUSE_STATIC_MBEDTLS_LIBRARY=ON . && \ CFLAGS=-fPIC cmake -G Ninja -DENABLE_PROGRAMS=OFF -DENABLE_TESTING=OFF -DUSE_SHARED_MBEDTLS_LIBRARY=OFF -DUSE_STATIC_MBEDTLS_LIBRARY=ON . && \
ninja install && \ ninja install && \
cd .. && \ cd .. && \
rm -rf mbedtls-2.16.2 rm -rf mbedtls-mbedtls-2.16.2
FROM mbedtls AS adduser FROM mbedtls AS adduser
RUN useradd --shell /bin/bash libgit2 --create-home ARG UID=""
ARG GID=""
RUN if [ "${UID}" != "" ]; then USER_ARG="--uid ${UID}"; fi && \
if [ "${GID}" != "" ]; then GROUP_ARG="--gid ${GID}"; fi && \
groupadd ${GROUP_ARG} libgit2 && \
useradd ${USER_ARG} --gid libgit2 --shell /bin/bash --create-home libgit2
FROM adduser AS configure FROM adduser AS configure
RUN mkdir /var/run/sshd RUN mkdir /var/run/sshd
...@@ -48,7 +48,12 @@ RUN cd /tmp && \ ...@@ -48,7 +48,12 @@ RUN cd /tmp && \
rm -rf cmake-3.21.1 rm -rf cmake-3.21.1
FROM cmake AS adduser FROM cmake AS adduser
RUN useradd --shell /bin/bash libgit2 --create-home ARG UID=""
ARG GID=""
RUN if [ "${UID}" != "" ]; then USER_ARG="--uid ${UID}"; fi && \
if [ "${GID}" != "" ]; then GROUP_ARG="--gid ${GID}"; fi && \
groupadd ${GROUP_ARG} libgit2 && \
useradd ${USER_ARG} --gid libgit2 --shell /bin/bash --create-home libgit2
FROM adduser AS configure FROM adduser AS configure
ENV PKG_CONFIG_PATH /usr/local/lib/pkgconfig ENV PKG_CONFIG_PATH /usr/local/lib/pkgconfig
......
ARG BASE=centos:8 ARG BASE=centos:8
FROM ${BASE} AS yum FROM ${BASE} AS stream
RUN dnf -y --disablerepo '*' --enablerepo=extras swap centos-linux-repos centos-stream-repos && \
dnf -y distro-sync
FROM stream AS yum
RUN yum install -y \ RUN yum install -y \
which \ which \
bzip2 \ bzip2 \
...@@ -40,7 +44,12 @@ RUN cd /tmp && \ ...@@ -40,7 +44,12 @@ RUN cd /tmp && \
rm -rf valgrind-3.15.0 rm -rf valgrind-3.15.0
FROM valgrind AS adduser FROM valgrind AS adduser
RUN useradd --shell /bin/bash libgit2 --create-home ARG UID=""
ARG GID=""
RUN if [ "${UID}" != "" ]; then USER_ARG="--uid ${UID}"; fi && \
if [ "${GID}" != "" ]; then GROUP_ARG="--gid ${GID}"; fi && \
groupadd ${GROUP_ARG} libgit2 && \
useradd ${USER_ARG} --gid libgit2 --shell /bin/bash --create-home libgit2
FROM adduser AS configure FROM adduser AS configure
ENV PKG_CONFIG_PATH /usr/local/lib/pkgconfig ENV PKG_CONFIG_PATH /usr/local/lib/pkgconfig
......
...@@ -32,9 +32,9 @@ RUN apt-get update && \ ...@@ -32,9 +32,9 @@ RUN apt-get update && \
FROM apt AS mbedtls FROM apt AS mbedtls
RUN cd /tmp && \ RUN cd /tmp && \
curl --location --silent --show-error https://tls.mbed.org/download/mbedtls-2.16.2-apache.tgz | \ curl --location --silent --show-error https://github.com/Mbed-TLS/mbedtls/archive/refs/tags/mbedtls-2.16.2.tar.gz | \
tar -xz && \ tar -xz && \
cd mbedtls-2.16.2 && \ cd mbedtls-mbedtls-2.16.2 && \
scripts/config.pl unset MBEDTLS_AESNI_C && \ scripts/config.pl unset MBEDTLS_AESNI_C && \
scripts/config.pl set MBEDTLS_MD4_C 1 && \ scripts/config.pl set MBEDTLS_MD4_C 1 && \
mkdir build build-msan && \ mkdir build build-msan && \
...@@ -45,7 +45,7 @@ RUN cd /tmp && \ ...@@ -45,7 +45,7 @@ RUN cd /tmp && \
CC=clang-10 CFLAGS="-fPIC" cmake -G Ninja -DENABLE_PROGRAMS=OFF -DENABLE_TESTING=OFF -DUSE_SHARED_MBEDTLS_LIBRARY=ON -DUSE_STATIC_MBEDTLS_LIBRARY=OFF -DCMAKE_BUILD_TYPE=MemSanDbg -DCMAKE_INSTALL_PREFIX=/usr/local/msan .. && \ CC=clang-10 CFLAGS="-fPIC" cmake -G Ninja -DENABLE_PROGRAMS=OFF -DENABLE_TESTING=OFF -DUSE_SHARED_MBEDTLS_LIBRARY=ON -DUSE_STATIC_MBEDTLS_LIBRARY=OFF -DCMAKE_BUILD_TYPE=MemSanDbg -DCMAKE_INSTALL_PREFIX=/usr/local/msan .. && \
ninja install && \ ninja install && \
cd .. && \ cd .. && \
rm -rf mbedtls-2.16.2 rm -rf mbedtls-mbedtls-2.16.2
FROM mbedtls AS libssh2 FROM mbedtls AS libssh2
RUN cd /tmp && \ RUN cd /tmp && \
...@@ -73,7 +73,13 @@ RUN cd /tmp && \ ...@@ -73,7 +73,13 @@ RUN cd /tmp && \
rm -rf valgrind-3.15.0 rm -rf valgrind-3.15.0
FROM valgrind AS adduser FROM valgrind AS adduser
RUN useradd --shell /bin/bash libgit2 --create-home ARG UID=""
ARG GID=""
RUN if [ "${UID}" != "" ]; then USER_ARG="--uid ${UID}"; fi && \
if [ "${GID}" != "" ]; then GROUP_ARG="--gid ${GID}"; fi && \
groupadd ${GROUP_ARG} libgit2 && \
useradd ${USER_ARG} --gid libgit2 --shell /bin/bash --create-home libgit2
FROM adduser AS configure FROM adduser AS configure
RUN mkdir /var/run/sshd RUN mkdir /var/run/sshd
...@@ -30,14 +30,14 @@ RUN apt-get update && \ ...@@ -30,14 +30,14 @@ RUN apt-get update && \
FROM apt AS mbedtls FROM apt AS mbedtls
RUN cd /tmp && \ RUN cd /tmp && \
curl --location --silent --show-error https://tls.mbed.org/download/mbedtls-2.16.2-apache.tgz | \ curl --location --silent --show-error https://github.com/Mbed-TLS/mbedtls/archive/refs/tags/mbedtls-2.16.2.tar.gz | \
tar -xz && \ tar -xz && \
cd mbedtls-2.16.2 && \ cd mbedtls-mbedtls-2.16.2 && \
scripts/config.pl set MBEDTLS_MD4_C 1 && \ scripts/config.pl set MBEDTLS_MD4_C 1 && \
CFLAGS=-fPIC cmake -G Ninja -DENABLE_PROGRAMS=OFF -DENABLE_TESTING=OFF -DUSE_SHARED_MBEDTLS_LIBRARY=OFF -DUSE_STATIC_MBEDTLS_LIBRARY=ON . && \ CFLAGS=-fPIC cmake -G Ninja -DENABLE_PROGRAMS=OFF -DENABLE_TESTING=OFF -DUSE_SHARED_MBEDTLS_LIBRARY=OFF -DUSE_STATIC_MBEDTLS_LIBRARY=ON . && \
ninja install && \ ninja install && \
cd .. && \ cd .. && \
rm -rf mbedtls-2.16.2 rm -rf mbedtls-mbedtls-2.16.2
FROM mbedtls AS libssh2 FROM mbedtls AS libssh2
RUN cd /tmp && \ RUN cd /tmp && \
...@@ -60,7 +60,13 @@ RUN cd /tmp && \ ...@@ -60,7 +60,13 @@ RUN cd /tmp && \
rm -rf valgrind-3.15.0 rm -rf valgrind-3.15.0
FROM valgrind AS adduser FROM valgrind AS adduser
RUN useradd --shell /bin/bash libgit2 --create-home ARG UID=""
ARG GID=""
RUN if [ "${UID}" != "" ]; then USER_ARG="--uid ${UID}"; fi && \
if [ "${GID}" != "" ]; then GROUP_ARG="--gid ${GID}"; fi && \
groupadd ${GROUP_ARG} libgit2 && \
useradd ${USER_ARG} --gid libgit2 --shell /bin/bash --create-home libgit2
FROM adduser AS configure FROM adduser AS configure
RUN mkdir /var/run/sshd RUN mkdir /var/run/sshd
...@@ -37,9 +37,13 @@ DOCKER_REGISTRY_CONTAINER_SHA="${DOCKER_REGISTRY_CONTAINER}:${DOCKER_SHA}" ...@@ -37,9 +37,13 @@ DOCKER_REGISTRY_CONTAINER_SHA="${DOCKER_REGISTRY_CONTAINER}:${DOCKER_SHA}"
echo "docker-registry-container-sha=${DOCKER_REGISTRY_CONTAINER_SHA}" >> $GITHUB_ENV echo "docker-registry-container-sha=${DOCKER_REGISTRY_CONTAINER_SHA}" >> $GITHUB_ENV
echo "docker-registry-container-latest=${DOCKER_REGISTRY_CONTAINER}:latest" >> $GITHUB_ENV echo "docker-registry-container-latest=${DOCKER_REGISTRY_CONTAINER}:latest" >> $GITHUB_ENV
echo "::: logging in to ${DOCKER_REGISTRY} as ${GITHUB_ACTOR}"
exists="true" exists="true"
docker login https://${DOCKER_REGISTRY} -u ${GITHUB_ACTOR} -p ${GITHUB_TOKEN} || exists="false" docker login https://${DOCKER_REGISTRY} -u ${GITHUB_ACTOR} -p ${GITHUB_TOKEN} || exists="false"
echo "::: pulling ${DOCKER_REGISTRY_CONTAINER_SHA}"
if [ "${exists}" != "false" ]; then if [ "${exists}" != "false" ]; then
docker pull ${DOCKER_REGISTRY_CONTAINER_SHA} || exists="false" docker pull ${DOCKER_REGISTRY_CONTAINER_SHA} || exists="false"
fi fi
......
#!/bin/sh -e #!/bin/sh
set -ex
echo "##############################################################################" echo "##############################################################################"
echo "## Downloading mingw" echo "## Downloading mingw"
......
#!/bin/sh
set -ex
brew update
brew install hyperfine
#!/bin/sh #!/bin/sh
set -x set -ex
brew update brew update
brew install pkgconfig zlib curl openssl libssh2 ninja brew install pkgconfig zlib curl openssl libssh2 ninja
......
#!/bin/sh
set -ex
sudo apt-get update
sudo apt-get install -y --no-install-recommends \
cargo \
cmake \
gcc \
git \
krb5-user \
libkrb5-dev \
libssl-dev \
libz-dev \
make \
ninja-build \
pkgconf
wget https://github.com/sharkdp/hyperfine/releases/download/v1.12.0/hyperfine_1.12.0_amd64.deb
sudo dpkg -i hyperfine_1.12.0_amd64.deb
#!/bin/sh
set -ex
choco install hyperfine zip
CHOCO_PATH=$(mktemp -d)
curl -L https://github.com/ethomson/PurgeStandbyList/releases/download/v1.0/purgestandbylist.1.0.0.nupkg -o "${CHOCO_PATH}/purgestandbylist.1.0.0.nupkg"
choco install purgestandbylist -s $(cygpath -w "${CHOCO_PATH}")
...@@ -83,7 +83,7 @@ echo "########################################################################## ...@@ -83,7 +83,7 @@ echo "##########################################################################
if [ -z "$SKIP_GITDAEMON_TESTS" ]; then if [ -z "$SKIP_GITDAEMON_TESTS" ]; then
echo "Starting git daemon..." echo "Starting git daemon..."
GITDAEMON_DIR=`mktemp -d ${TMPDIR}/gitdaemon.XXXXXXXX` GITDAEMON_DIR=`mktemp -d ${TMPDIR}/gitdaemon.XXXXXXXX`
git init --bare "${GITDAEMON_DIR}/test.git" git init --bare "${GITDAEMON_DIR}/test.git" >/dev/null
git daemon --listen=localhost --export-all --enable=receive-pack --base-path="${GITDAEMON_DIR}" "${GITDAEMON_DIR}" 2>/dev/null & git daemon --listen=localhost --export-all --enable=receive-pack --base-path="${GITDAEMON_DIR}" "${GITDAEMON_DIR}" 2>/dev/null &
GITDAEMON_PID=$! GITDAEMON_PID=$!
disown $GITDAEMON_PID disown $GITDAEMON_PID
...@@ -101,8 +101,8 @@ if [ -z "$SKIP_PROXY_TESTS" ]; then ...@@ -101,8 +101,8 @@ if [ -z "$SKIP_PROXY_TESTS" ]; then
java -jar poxyproxy.jar --address 127.0.0.1 --port 8090 --credentials foo:bar --auth-type ntlm --quiet & java -jar poxyproxy.jar --address 127.0.0.1 --port 8090 --credentials foo:bar --auth-type ntlm --quiet &
fi fi
if [ -z "$SKIP_NTLM_TESTS" ]; then if [ -z "$SKIP_NTLM_TESTS" -o -z "$SKIP_ONLINE_TESTS" ]; then
curl --location --silent --show-error https://github.com/ethomson/poxygit/releases/download/v0.4.0/poxygit-0.4.0.jar >poxygit.jar curl --location --silent --show-error https://github.com/ethomson/poxygit/releases/download/v0.5.1/poxygit-0.5.1.jar >poxygit.jar
echo "" echo ""
echo "Starting HTTP server..." echo "Starting HTTP server..."
...@@ -112,10 +112,11 @@ if [ -z "$SKIP_NTLM_TESTS" ]; then ...@@ -112,10 +112,11 @@ if [ -z "$SKIP_NTLM_TESTS" ]; then
fi fi
if [ -z "$SKIP_SSH_TESTS" ]; then if [ -z "$SKIP_SSH_TESTS" ]; then
echo ""
echo "Starting ssh daemon..." echo "Starting ssh daemon..."
HOME=`mktemp -d ${TMPDIR}/home.XXXXXXXX` HOME=`mktemp -d ${TMPDIR}/home.XXXXXXXX`
SSHD_DIR=`mktemp -d ${TMPDIR}/sshd.XXXXXXXX` SSHD_DIR=`mktemp -d ${TMPDIR}/sshd.XXXXXXXX`
git init --bare "${SSHD_DIR}/test.git" git init --bare "${SSHD_DIR}/test.git" >/dev/null
cat >"${SSHD_DIR}/sshd_config" <<-EOF cat >"${SSHD_DIR}/sshd_config" <<-EOF
Port 2222 Port 2222
ListenAddress 0.0.0.0 ListenAddress 0.0.0.0
...@@ -158,10 +159,18 @@ fi ...@@ -158,10 +159,18 @@ fi
if [ -z "$SKIP_OFFLINE_TESTS" ]; then if [ -z "$SKIP_OFFLINE_TESTS" ]; then
echo "" echo ""
echo "##############################################################################" echo "##############################################################################"
echo "## Running (offline) tests" echo "## Running core tests"
echo "##############################################################################" echo "##############################################################################"
echo ""
echo "Running libgit2 integration (offline) tests"
echo ""
run_test offline run_test offline
echo ""
echo "Running utility tests"
echo ""
run_test util
fi fi
if [ -n "$RUN_INVASIVE_TESTS" ]; then if [ -n "$RUN_INVASIVE_TESTS" ]; then
...@@ -185,19 +194,21 @@ if [ -z "$SKIP_ONLINE_TESTS" ]; then ...@@ -185,19 +194,21 @@ if [ -z "$SKIP_ONLINE_TESTS" ]; then
echo "" echo ""
echo "##############################################################################" echo "##############################################################################"
echo "## Running (online) tests" echo "## Running networking (online) tests"
echo "##############################################################################" echo "##############################################################################"
export GITTEST_FLAKY_RETRY=5 export GITTEST_REMOTE_REDIRECT_INITIAL="http://localhost:9000/initial-redirect/libgit2/TestGitRepository"
export GITTEST_REMOTE_REDIRECT_SUBSEQUENT="http://localhost:9000/subsequent-redirect/libgit2/TestGitRepository"
run_test online run_test online
unset GITTEST_FLAKY_RETRY unset GITTEST_REMOTE_REDIRECT_INITIAL
unset GITTEST_REMOTE_REDIRECT_SUBSEQUENT
# Run the online tests that immutably change global state separately # Run the online tests that immutably change global state separately
# to avoid polluting the test environment. # to avoid polluting the test environment.
echo "" echo ""
echo "##############################################################################" echo "Running custom certificate (online_customcert) tests"
echo "## Running (online_customcert) tests" echo ""
echo "##############################################################################"
run_test online_customcert run_test online_customcert
fi fi
...@@ -231,9 +242,7 @@ if [ -z "$SKIP_PROXY_TESTS" ]; then ...@@ -231,9 +242,7 @@ if [ -z "$SKIP_PROXY_TESTS" ]; then
export GITTEST_REMOTE_PROXY_HOST="localhost:8090" export GITTEST_REMOTE_PROXY_HOST="localhost:8090"
export GITTEST_REMOTE_PROXY_USER="foo" export GITTEST_REMOTE_PROXY_USER="foo"
export GITTEST_REMOTE_PROXY_PASS="bar" export GITTEST_REMOTE_PROXY_PASS="bar"
export GITTEST_FLAKY_RETRY=5
run_test proxy run_test proxy
unset GITTEST_FLAKY_RETRY
unset GITTEST_REMOTE_PROXY_HOST unset GITTEST_REMOTE_PROXY_HOST
unset GITTEST_REMOTE_PROXY_USER unset GITTEST_REMOTE_PROXY_USER
unset GITTEST_REMOTE_PROXY_PASS unset GITTEST_REMOTE_PROXY_PASS
...@@ -299,18 +308,28 @@ if [ -z "$SKIP_NEGOTIATE_TESTS" -a -n "$GITTEST_NEGOTIATE_PASSWORD" ]; then ...@@ -299,18 +308,28 @@ if [ -z "$SKIP_NEGOTIATE_TESTS" -a -n "$GITTEST_NEGOTIATE_PASSWORD" ]; then
fi fi
if [ -z "$SKIP_SSH_TESTS" ]; then if [ -z "$SKIP_SSH_TESTS" ]; then
echo ""
echo "Running ssh tests"
echo ""
export GITTEST_REMOTE_URL="ssh://localhost:2222/$SSHD_DIR/test.git"
export GITTEST_REMOTE_USER=$USER export GITTEST_REMOTE_USER=$USER
export GITTEST_REMOTE_SSH_KEY="${HOME}/.ssh/id_rsa" export GITTEST_REMOTE_SSH_KEY="${HOME}/.ssh/id_rsa"
export GITTEST_REMOTE_SSH_PUBKEY="${HOME}/.ssh/id_rsa.pub" export GITTEST_REMOTE_SSH_PUBKEY="${HOME}/.ssh/id_rsa.pub"
export GITTEST_REMOTE_SSH_PASSPHRASE="" export GITTEST_REMOTE_SSH_PASSPHRASE=""
export GITTEST_REMOTE_SSH_FINGERPRINT="${SSH_FINGERPRINT}" export GITTEST_REMOTE_SSH_FINGERPRINT="${SSH_FINGERPRINT}"
echo ""
echo "Running ssh tests"
echo ""
export GITTEST_REMOTE_URL="ssh://localhost:2222/$SSHD_DIR/test.git"
run_test ssh run_test ssh
unset GITTEST_REMOTE_URL unset GITTEST_REMOTE_URL
echo ""
echo "Running ssh tests (scp-style paths)"
echo ""
export GITTEST_REMOTE_URL="[localhost:2222]:$SSHD_DIR/test.git"
run_test ssh
unset GITTEST_REMOTE_URL
unset GITTEST_REMOTE_USER unset GITTEST_REMOTE_USER
unset GITTEST_REMOTE_SSH_KEY unset GITTEST_REMOTE_SSH_KEY
unset GITTEST_REMOTE_SSH_PUBKEY unset GITTEST_REMOTE_SSH_PUBKEY
......
...@@ -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()
function(ADD_CLAR_TEST project name)
if(NOT USE_LEAK_CHECKER STREQUAL "OFF")
add_test(${name} "${PROJECT_SOURCE_DIR}/script/${USE_LEAK_CHECKER}.sh" "${PROJECT_BINARY_DIR}/${project}" ${ARGN})
else()
add_test(${name} "${PROJECT_BINARY_DIR}/${project}" ${ARGN})
endif()
endfunction(ADD_CLAR_TEST)
# 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 AND LINK_WITH_STATIC_LIBRARIES)
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,22 @@ ...@@ -16,23 +16,22 @@
# 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 pcre.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)
# 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_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})
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 pcre2.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 ${PROJECT_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(HTTPParser)
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("${PROJECT_SOURCE_DIR}/deps/http-parser" "${PROJECT_BINARY_DIR}/deps/http-parser")
list(APPEND LIBGIT2_DEPENDENCY_INCLUDES "${PROJECT_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(EXISTS "/usr/local/opt/openssl/bin/openssl")
# 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_SHA256)
SanitizeBool(USE_SHA1) # 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) elseif(USE_SHA1 STREQUAL "OpenSSL")
ADD_DEFINITIONS(-DSHA1DC_CUSTOM_INCLUDE_SHA1_C=\"common.h\") set(GIT_SHA1_OPENSSL 1)
ADD_DEFINITIONS(-DSHA1DC_CUSTOM_INCLUDE_UBC_CHECK_C=\"common.h\") elseif(USE_SHA1 STREQUAL "OpenSSL-Dynamic")
FILE(GLOB SRC_SHA1 hash/sha1/collisiondetect.* hash/sha1/sha1dc/*) set(GIT_SHA1_OPENSSL 1)
ELSEIF(USE_SHA1 STREQUAL "OpenSSL") set(GIT_SHA1_OPENSSL_DYNAMIC 1)
# OPENSSL_FOUND should already be set, we're checking USE_HTTPS list(APPEND LIBGIT2_SYSTEM_LIBS dl)
elseif(USE_SHA1 STREQUAL "CommonCrypto")
SET(GIT_SHA1_OPENSSL 1) set(GIT_SHA1_COMMON_CRYPTO 1)
IF(CMAKE_SYSTEM_NAME MATCHES "FreeBSD") elseif(USE_SHA1 STREQUAL "mbedTLS")
LIST(APPEND LIBGIT2_PC_LIBS "-lssl") set(GIT_SHA1_MBEDTLS 1)
ELSE() elseif(USE_SHA1 STREQUAL "Win32")
LIST(APPEND LIBGIT2_PC_REQUIRES "openssl") set(GIT_SHA1_WIN32 1)
ENDIF() else()
FILE(GLOB SRC_SHA1 hash/sha1/openssl.*) message(FATAL_ERROR "Asked for unknown SHA1 backend: ${USE_SHA1}")
ELSEIF(USE_SHA1 STREQUAL "CommonCrypto") endif()
SET(GIT_SHA1_COMMON_CRYPTO 1)
FILE(GLOB SRC_SHA1 hash/sha1/common_crypto.*) # sha256
ELSEIF(USE_SHA1 STREQUAL "mbedTLS")
SET(GIT_SHA1_MBEDTLS 1) if(USE_SHA256 STREQUAL ON AND USE_HTTPS)
FILE(GLOB SRC_SHA1 hash/sha1/mbedtls.*) SET(USE_SHA256 "HTTPS")
LIST(APPEND LIBGIT2_SYSTEM_INCLUDES ${MBEDTLS_INCLUDE_DIR}) elseif(USE_SHA256 STREQUAL ON)
LIST(APPEND LIBGIT2_LIBS ${MBEDTLS_LIBRARIES}) SET(USE_SHA256 "Builtin")
endif()
if(USE_SHA256 STREQUAL "HTTPS")
if(USE_HTTPS STREQUAL "SecureTransport")
set(USE_SHA256 "CommonCrypto")
elseif(USE_HTTPS STREQUAL "WinHTTP")
set(USE_SHA256 "Win32")
elseif(USE_HTTPS)
set(USE_SHA256 ${USE_HTTPS})
endif()
endif()
if(USE_SHA256 STREQUAL "Builtin")
set(GIT_SHA256_BUILTIN 1)
elseif(USE_SHA256 STREQUAL "OpenSSL")
set(GIT_SHA256_OPENSSL 1)
elseif(USE_SHA256 STREQUAL "OpenSSL-Dynamic")
set(GIT_SHA256_OPENSSL 1)
set(GIT_SHA256_OPENSSL_DYNAMIC 1)
list(APPEND LIBGIT2_SYSTEM_LIBS dl)
elseif(USE_SHA256 STREQUAL "CommonCrypto")
set(GIT_SHA256_COMMON_CRYPTO 1)
elseif(USE_SHA256 STREQUAL "mbedTLS")
set(GIT_SHA256_MBEDTLS 1)
elseif(USE_SHA256 STREQUAL "Win32")
set(GIT_SHA256_WIN32 1)
else()
message(FATAL_ERROR "Asked for unknown SHA256 backend: ${USE_SHA256}")
endif()
# add library requirements
if(USE_SHA1 STREQUAL "OpenSSL" OR USE_SHA256 STREQUAL "OpenSSL")
if(CMAKE_SYSTEM_NAME MATCHES "FreeBSD")
list(APPEND LIBGIT2_PC_LIBS "-lssl")
else()
list(APPEND LIBGIT2_PC_REQUIRES "openssl")
endif()
endif()
if(USE_SHA1 STREQUAL "mbedTLS" OR USE_SHA256 STREQUAL "mbedTLS")
list(APPEND LIBGIT2_SYSTEM_INCLUDES ${MBEDTLS_INCLUDE_DIR})
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_SHA1 STREQUAL "Win32") endif()
SET(GIT_SHA1_WIN32 1)
FILE(GLOB SRC_SHA1 hash/sha1/win32.*) # notify feature enablement
ELSEIF(USE_SHA1 STREQUAL "Generic")
FILE(GLOB SRC_SHA1 hash/sha1/generic.*) add_feature_info(SHA1 ON "using ${USE_SHA1}")
ELSE() add_feature_info(SHA256 ON "using ${USE_SHA256}")
MESSAGE(FATAL_ERROR "Asked for unknown SHA1 backend: ${USE_SHA1}")
ENDIF()
list(APPEND SRC_SHA1 "hash/sha1.h")
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("${PROJECT_SOURCE_DIR}/deps/pcre" "${PROJECT_BINARY_DIR}/deps/pcre")
list(APPEND LIBGIT2_DEPENDENCY_INCLUDES "${PROJECT_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("${PROJECT_SOURCE_DIR}/deps/winhttp" "${PROJECT_BINARY_DIR}/deps/winhttp")
list(APPEND LIBGIT2_SYSTEM_LIBS winhttp)
list(APPEND LIBGIT2_DEPENDENCY_INCLUDES "${PROJECT_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("${PROJECT_SOURCE_DIR}/deps/chromium-zlib" "${PROJECT_BINARY_DIR}/deps/chromium-zlib")
list(APPEND LIBGIT2_DEPENDENCY_INCLUDES "${PROJECT_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("${PROJECT_SOURCE_DIR}/deps/zlib" "${PROJECT_BINARY_DIR}/deps/zlib")
list(APPEND LIBGIT2_DEPENDENCY_INCLUDES "${PROJECT_SOURCE_DIR}/deps/zlib")
list(APPEND LIBGIT2_DEPENDENCY_OBJECTS $<TARGET_OBJECTS:zlib>)
add_feature_info(zlib ON "using bundled zlib")
endif()
...@@ -4,18 +4,18 @@ ...@@ -4,18 +4,18 @@
# TODO: The Chromium build file (in deps/chromium-zlib/zlib/BUILD.gn) supports # TODO: The Chromium build file (in deps/chromium-zlib/zlib/BUILD.gn) supports
# more platforms (like ARM with NEON), more can be enabled as needed. # more platforms (like ARM with NEON), more can be enabled as needed.
CMAKE_MINIMUM_REQUIRED(VERSION 3.11) cmake_minimum_required(VERSION 3.11)
include(FetchContent) include(FetchContent)
include(FindGit) include(FindGit)
# Ensure that the git binary is present to download the sources. # Ensure that the git binary is present to download the sources.
find_package(Git) find_package(Git)
IF(NOT Git_FOUND) if(NOT Git_FOUND)
message(FATAL_ERROR "git is required to download the Chromium zlib sources") message(FATAL_ERROR "git is required to download the Chromium zlib sources")
ENDIF() endif()
FetchContent_Populate(chromium_zlib_src fetchcontent_populate(chromium_zlib_src
GIT_REPOSITORY https://chromium.googlesource.com/chromium/src/third_party/zlib.git GIT_REPOSITORY https://chromium.googlesource.com/chromium/src/third_party/zlib.git
GIT_TAG 2c183c9f93a328bfb3121284da13cf89a0f7e64a GIT_TAG 2c183c9f93a328bfb3121284da13cf89a0f7e64a
QUIET QUIET
...@@ -31,8 +31,8 @@ disable_warnings(missing-declarations) ...@@ -31,8 +31,8 @@ disable_warnings(missing-declarations)
# -O3 is also set by the Chromium configuration and has been deemed safe enough # -O3 is also set by the Chromium configuration and has been deemed safe enough
# for them. # for them.
SET(CMAKE_C_FLAGS_RELWITHDEBINFO "-O3 -g -DNDEBUG") set(CMAKE_C_FLAGS_RELWITHDEBINFO "-O3 -g -DNDEBUG")
SET(CMAKE_C_FLAGS_RELEASE "-O3 -DNDEBUG") set(CMAKE_C_FLAGS_RELEASE "-O3 -DNDEBUG")
# Common definitions. # Common definitions.
add_definitions( add_definitions(
......
FILE(GLOB SRC_NTLMCLIENT "ntlm.c" "ntlm.h" "util.c" "util.h") file(GLOB SRC_NTLMCLIENT "ntlm.c" "ntlm.h" "util.c" "util.h")
LIST(SORT SRC_NTLMCLIENT) list(SORT SRC_NTLMCLIENT)
ADD_DEFINITIONS(-DNTLM_STATIC=1) add_definitions(-DNTLM_STATIC=1)
DISABLE_WARNINGS(implicit-fallthrough) disable_warnings(implicit-fallthrough)
IF(USE_ICONV) if(USE_ICONV)
ADD_DEFINITIONS(-DUNICODE_ICONV=1) add_definitions(-DUNICODE_ICONV=1)
FILE(GLOB SRC_NTLMCLIENT_UNICODE "unicode_iconv.c" "unicode_iconv.h") file(GLOB SRC_NTLMCLIENT_UNICODE "unicode_iconv.c" "unicode_iconv.h")
ELSE() else()
ADD_DEFINITIONS(-DUNICODE_BUILTIN=1) add_definitions(-DUNICODE_BUILTIN=1)
FILE(GLOB SRC_NTLMCLIENT_UNICODE "unicode_builtin.c" "unicode_builtin.h") file(GLOB SRC_NTLMCLIENT_UNICODE "unicode_builtin.c" "unicode_builtin.h")
ENDIF() endif()
IF(USE_HTTPS STREQUAL "SecureTransport") if(USE_HTTPS STREQUAL "SecureTransport")
ADD_DEFINITIONS(-DCRYPT_COMMONCRYPTO) add_definitions(-DCRYPT_COMMONCRYPTO)
SET(SRC_NTLMCLIENT_CRYPTO "crypt_commoncrypto.c" "crypt_commoncrypto.h") set(SRC_NTLMCLIENT_CRYPTO "crypt_commoncrypto.c" "crypt_commoncrypto.h")
# CC_MD4 has been deprecated in macOS 10.15. # CC_MD4 has been deprecated in macOS 10.15.
SET_SOURCE_FILES_PROPERTIES("crypt_commoncrypto.c" COMPILE_FLAGS "-Wno-deprecated") set_source_files_properties("crypt_commoncrypto.c" COMPILE_FLAGS "-Wno-deprecated")
ELSEIF(USE_HTTPS STREQUAL "OpenSSL") elseif(USE_HTTPS STREQUAL "OpenSSL")
ADD_DEFINITIONS(-DCRYPT_OPENSSL) add_definitions(-DCRYPT_OPENSSL)
INCLUDE_DIRECTORIES(${OPENSSL_INCLUDE_DIR}) include_directories(${OPENSSL_INCLUDE_DIR})
SET(SRC_NTLMCLIENT_CRYPTO "crypt_openssl.c" "crypt_openssl.h") set(SRC_NTLMCLIENT_CRYPTO "crypt_openssl.c" "crypt_openssl.h")
ELSEIF(USE_HTTPS STREQUAL "OpenSSL-Dynamic") elseif(USE_HTTPS STREQUAL "OpenSSL-Dynamic")
ADD_DEFINITIONS(-DCRYPT_OPENSSL) add_definitions(-DCRYPT_OPENSSL)
ADD_DEFINITIONS(-DCRYPT_OPENSSL_DYNAMIC) add_definitions(-DCRYPT_OPENSSL_DYNAMIC)
SET(SRC_NTLMCLIENT_CRYPTO "crypt_openssl.c" "crypt_openssl.h") set(SRC_NTLMCLIENT_CRYPTO "crypt_openssl.c" "crypt_openssl.h")
ELSEIF(USE_HTTPS STREQUAL "mbedTLS") elseif(USE_HTTPS STREQUAL "mbedTLS")
ADD_DEFINITIONS(-DCRYPT_MBEDTLS) add_definitions(-DCRYPT_MBEDTLS)
INCLUDE_DIRECTORIES(${MBEDTLS_INCLUDE_DIR}) include_directories(${MBEDTLS_INCLUDE_DIR})
SET(SRC_NTLMCLIENT_CRYPTO "crypt_mbedtls.c" "crypt_mbedtls.h") set(SRC_NTLMCLIENT_CRYPTO "crypt_mbedtls.c" "crypt_mbedtls.h")
ELSE() else()
MESSAGE(FATAL_ERROR "Unable to use libgit2's HTTPS backend (${USE_HTTPS}) for NTLM crypto") message(FATAL_ERROR "Unable to use libgit2's HTTPS backend (${USE_HTTPS}) for NTLM crypto")
ENDIF() endif()
ADD_LIBRARY(ntlmclient OBJECT ${SRC_NTLMCLIENT} ${SRC_NTLMCLIENT_UNICODE} ${SRC_NTLMCLIENT_CRYPTO}) add_library(ntlmclient OBJECT ${SRC_NTLMCLIENT} ${SRC_NTLMCLIENT_UNICODE} ${SRC_NTLMCLIENT_CRYPTO})
...@@ -44,7 +44,9 @@ static inline void HMAC_CTX_free(HMAC_CTX *ctx) ...@@ -44,7 +44,9 @@ static inline void HMAC_CTX_free(HMAC_CTX *ctx)
#endif #endif
#if OPENSSL_VERSION_NUMBER >= 0x10100000L || defined(CRYPT_OPENSSL_DYNAMIC) #if (OPENSSL_VERSION_NUMBER >= 0x10100000L && !defined(LIBRESSL_VERSION_NUMBER)) || \
(defined(LIBRESSL_VERSION_NUMBER) && LIBRESSL_VERSION_NUMBER >= 0x03050000fL) || \
defined(CRYPT_OPENSSL_DYNAMIC)
static inline void HMAC_CTX_cleanup(HMAC_CTX *ctx) static inline void HMAC_CTX_cleanup(HMAC_CTX *ctx)
{ {
......
...@@ -930,10 +930,10 @@ const char *ntlm_client_target_domain_dns(ntlm_client *ntlm) ...@@ -930,10 +930,10 @@ const char *ntlm_client_target_domain_dns(ntlm_client *ntlm)
} }
#define EVEN_PARITY(a) \ #define EVEN_PARITY(a) \
(!!((a) & 0x01ll) ^ !!((a) & 0x02ll) ^ \ (!!((a) & INT64_C(0x01)) ^ !!((a) & INT64_C(0x02)) ^ \
!!((a) & 0x04ll) ^ !!((a) & 0x08ll) ^ \ !!((a) & INT64_C(0x04)) ^ !!((a) & INT64_C(0x08)) ^ \
!!((a) & 0x10ll) ^ !!((a) & 0x20ll) ^ \ !!((a) & INT64_C(0x10)) ^ !!((a) & INT64_C(0x20)) ^ \
!!((a) & 0x40ll) ^ !!((a) & 0x80ll)) !!((a) & INT64_C(0x40)) ^ !!((a) & INT64_C(0x80)))
static void generate_odd_parity(ntlm_des_block *block) static void generate_odd_parity(ntlm_des_block *block)
{ {
......
...@@ -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;
......
INCLUDE(CheckIncludeFile) include(CheckIncludeFile)
INCLUDE(CheckFunctionExists) include(CheckFunctionExists)
INCLUDE(CheckTypeSize) include(CheckTypeSize)
CHECK_INCLUDE_FILE(dirent.h HAVE_DIRENT_H) check_include_file(dirent.h HAVE_DIRENT_H)
CHECK_INCLUDE_FILE(stdint.h HAVE_STDINT_H) check_include_file(stdint.h HAVE_STDINT_H)
CHECK_INCLUDE_FILE(inttypes.h HAVE_INTTYPES_H) check_include_file(inttypes.h HAVE_INTTYPES_H)
CHECK_INCLUDE_FILE(sys/stat.h HAVE_SYS_STAT_H) check_include_file(sys/stat.h HAVE_SYS_STAT_H)
CHECK_INCLUDE_FILE(sys/types.h HAVE_SYS_TYPES_H) check_include_file(sys/types.h HAVE_SYS_TYPES_H)
CHECK_INCLUDE_FILE(unistd.h HAVE_UNISTD_H) check_include_file(unistd.h HAVE_UNISTD_H)
CHECK_INCLUDE_FILE(windows.h HAVE_WINDOWS_H) check_include_file(windows.h HAVE_WINDOWS_H)
CHECK_FUNCTION_EXISTS(bcopy HAVE_BCOPY) check_function_exists(bcopy HAVE_BCOPY)
CHECK_FUNCTION_EXISTS(memmove HAVE_MEMMOVE) check_function_exists(memmove HAVE_MEMMOVE)
CHECK_FUNCTION_EXISTS(strerror HAVE_STRERROR) check_function_exists(strerror HAVE_STRERROR)
CHECK_FUNCTION_EXISTS(strtoll HAVE_STRTOLL) check_function_exists(strtoll HAVE_STRTOLL)
CHECK_FUNCTION_EXISTS(strtoq HAVE_STRTOQ) check_function_exists(strtoq HAVE_STRTOQ)
CHECK_FUNCTION_EXISTS(_strtoi64 HAVE__STRTOI64) check_function_exists(_strtoi64 HAVE__STRTOI64)
CHECK_TYPE_SIZE("long long" LONG_LONG) check_type_size("long long" LONG_LONG)
CHECK_TYPE_SIZE("unsigned long long" UNSIGNED_LONG_LONG) check_type_size("unsigned long long" UNSIGNED_LONG_LONG)
DISABLE_WARNINGS(unused-function) disable_warnings(unused-function)
DISABLE_WARNINGS(implicit-fallthrough) disable_warnings(implicit-fallthrough)
# User-configurable options # User-configurable options
SET(SUPPORT_PCRE8 1) set(SUPPORT_PCRE8 1)
SET(PCRE_LINK_SIZE "2") set(PCRE_LINK_SIZE "2")
SET(PCRE_PARENS_NEST_LIMIT "250") set(PCRE_PARENS_NEST_LIMIT "250")
SET(PCRE_MATCH_LIMIT "10000000") set(PCRE_MATCH_LIMIT "10000000")
SET(PCRE_MATCH_LIMIT_RECURSION "MATCH_LIMIT") set(PCRE_MATCH_LIMIT_RECURSION "MATCH_LIMIT")
SET(PCRE_NEWLINE "LF") set(PCRE_NEWLINE "LF")
SET(NO_RECURSE 1) set(NO_RECURSE 1)
SET(PCRE_POSIX_MALLOC_THRESHOLD "10") set(PCRE_POSIX_MALLOC_THRESHOLD "10")
SET(BSR_ANYCRLF 0) set(BSR_ANYCRLF 0)
IF (MINGW) if(MINGW)
OPTION(NON_STANDARD_LIB_PREFIX option(NON_STANDARD_LIB_PREFIX
"ON=Shared libraries built in mingw will be named pcre.dll, etc., instead of libpcre.dll, etc." "ON=Shared libraries built in mingw will be named pcre.dll, etc., instead of libpcre.dll, etc."
OFF) OFF)
OPTION(NON_STANDARD_LIB_SUFFIX option(NON_STANDARD_LIB_SUFFIX
"ON=Shared libraries built in mingw will be named libpcre-0.dll, etc., instead of libpcre.dll, etc." "ON=Shared libraries built in mingw will be named libpcre-0.dll, etc., instead of libpcre.dll, etc."
OFF) OFF)
ENDIF(MINGW) endif(MINGW)
# Prepare build configuration # Prepare build configuration
SET(pcre_have_long_long 0) set(pcre_have_long_long 0)
SET(pcre_have_ulong_long 0) set(pcre_have_ulong_long 0)
IF(HAVE_LONG_LONG) if(HAVE_LONG_LONG)
SET(pcre_have_long_long 1) set(pcre_have_long_long 1)
ENDIF(HAVE_LONG_LONG) endif(HAVE_LONG_LONG)
IF(HAVE_UNSIGNED_LONG_LONG) if(HAVE_UNSIGNED_LONG_LONG)
SET(pcre_have_ulong_long 1) set(pcre_have_ulong_long 1)
ENDIF(HAVE_UNSIGNED_LONG_LONG) endif(HAVE_UNSIGNED_LONG_LONG)
SET(NEWLINE "") set(NEWLINE "")
IF(PCRE_NEWLINE STREQUAL "LF") if(PCRE_NEWLINE STREQUAL "LF")
SET(NEWLINE "10") set(NEWLINE "10")
ENDIF(PCRE_NEWLINE STREQUAL "LF") endif(PCRE_NEWLINE STREQUAL "LF")
IF(PCRE_NEWLINE STREQUAL "CR") if(PCRE_NEWLINE STREQUAL "CR")
SET(NEWLINE "13") set(NEWLINE "13")
ENDIF(PCRE_NEWLINE STREQUAL "CR") endif(PCRE_NEWLINE STREQUAL "CR")
IF(PCRE_NEWLINE STREQUAL "CRLF") if(PCRE_NEWLINE STREQUAL "CRLF")
SET(NEWLINE "3338") set(NEWLINE "3338")
ENDIF(PCRE_NEWLINE STREQUAL "CRLF") endif(PCRE_NEWLINE STREQUAL "CRLF")
IF(PCRE_NEWLINE STREQUAL "ANY") if(PCRE_NEWLINE STREQUAL "ANY")
SET(NEWLINE "-1") set(NEWLINE "-1")
ENDIF(PCRE_NEWLINE STREQUAL "ANY") endif(PCRE_NEWLINE STREQUAL "ANY")
IF(PCRE_NEWLINE STREQUAL "ANYCRLF") if(PCRE_NEWLINE STREQUAL "ANYCRLF")
SET(NEWLINE "-2") set(NEWLINE "-2")
ENDIF(PCRE_NEWLINE STREQUAL "ANYCRLF") endif(PCRE_NEWLINE STREQUAL "ANYCRLF")
IF(NEWLINE STREQUAL "") if(NEWLINE STREQUAL "")
MESSAGE(FATAL_ERROR "The PCRE_NEWLINE variable must be set to one of the following values: \"LF\", \"CR\", \"CRLF\", \"ANY\", \"ANYCRLF\".") message(FATAL_ERROR "The PCRE_NEWLINE variable must be set to one of the following values: \"LF\", \"CR\", \"CRLF\", \"ANY\", \"ANYCRLF\".")
ENDIF(NEWLINE STREQUAL "") endif(NEWLINE STREQUAL "")
# Output files # Output files
CONFIGURE_FILE(config.h.in configure_file(config.h.in
${PROJECT_BINARY_DIR}/src/pcre/config.h ${PROJECT_BINARY_DIR}/src/pcre/config.h
@ONLY) @ONLY)
# Source code # Source code
SET(PCRE_HEADERS ${PROJECT_BINARY_DIR}/src/pcre/config.h) set(PCRE_HEADERS ${PROJECT_BINARY_DIR}/src/pcre/config.h)
SET(PCRE_SOURCES set(PCRE_SOURCES
pcre_byte_order.c pcre_byte_order.c
pcre_chartables.c pcre_chartables.c
pcre_compile.c pcre_compile.c
...@@ -113,28 +113,28 @@ SET(PCRE_SOURCES ...@@ -113,28 +113,28 @@ SET(PCRE_SOURCES
pcre_xclass.c pcre_xclass.c
) )
SET(PCREPOSIX_HEADERS pcreposix.h) set(PCREPOSIX_HEADERS pcreposix.h)
SET(PCREPOSIX_SOURCES pcreposix.c) set(PCREPOSIX_SOURCES pcreposix.c)
# Fix static compilation with MSVC: https://bugs.exim.org/show_bug.cgi?id=1681 # Fix static compilation with MSVC: https://bugs.exim.org/show_bug.cgi?id=1681
# This code was taken from the CMake wiki, not from WebM. # This code was taken from the CMake wiki, not from WebM.
# Build setup # Build setup
ADD_DEFINITIONS(-DHAVE_CONFIG_H) add_definitions(-DHAVE_CONFIG_H)
IF(MSVC) if(MSVC)
ADD_DEFINITIONS(-D_CRT_SECURE_NO_DEPRECATE -D_CRT_SECURE_NO_WARNINGS) add_definitions(-D_CRT_SECURE_NO_DEPRECATE -D_CRT_SECURE_NO_WARNINGS)
ENDIF(MSVC) endif(MSVC)
SET(CMAKE_INCLUDE_CURRENT_DIR 1) set(CMAKE_INCLUDE_CURRENT_DIR 1)
SET(targets) set(targets)
# Libraries # Libraries
# pcre # pcre
INCLUDE_DIRECTORIES(${PROJECT_BINARY_DIR}/src/pcre) include_directories(${PROJECT_BINARY_DIR}/src/pcre)
ADD_LIBRARY(pcre OBJECT ${PCRE_HEADERS} ${PCRE_SOURCES} ${PCREPOSIX_SOURCES}) add_library(pcre OBJECT ${PCRE_HEADERS} ${PCRE_SOURCES} ${PCREPOSIX_SOURCES})
# end CMakeLists.txt # end CMakeLists.txt
FIND_PROGRAM(DLLTOOL dlltool CMAKE_FIND_ROOT_PATH_BOTH) find_program(DLLTOOL dlltool CMAKE_FIND_ROOT_PATH_BOTH)
IF (NOT DLLTOOL) if(NOT DLLTOOL)
MESSAGE(FATAL_ERROR "Could not find dlltool command") message(FATAL_ERROR "Could not find dlltool command")
ENDIF () endif()
SET(LIBWINHTTP_PATH "${libgit2_BINARY_DIR}/deps/winhttp") set(LIBWINHTTP_PATH "${PROJECT_BINARY_DIR}/deps/winhttp")
SET(LIBWINHTTP_PATH ${LIBWINHTTP_PATH} PARENT_SCOPE) set(LIBWINHTTP_PATH ${LIBWINHTTP_PATH} PARENT_SCOPE)
FILE(MAKE_DIRECTORY ${LIBWINHTTP_PATH}) file(MAKE_DIRECTORY ${LIBWINHTTP_PATH})
IF (CMAKE_SIZEOF_VOID_P EQUAL 8) if(CMAKE_SIZEOF_VOID_P EQUAL 8)
set(WINHTTP_DEF "winhttp64.def") set(WINHTTP_DEF "winhttp64.def")
ELSE() else()
set(WINHTTP_DEF "winhttp.def") set(WINHTTP_DEF "winhttp.def")
ENDIF() endif()
ADD_CUSTOM_COMMAND( add_custom_command(
OUTPUT ${LIBWINHTTP_PATH}/libwinhttp.a OUTPUT ${LIBWINHTTP_PATH}/libwinhttp.a
COMMAND ${DLLTOOL} -d ${WINHTTP_DEF} -k -D winhttp.dll -l libwinhttp.a COMMAND ${DLLTOOL} -d ${WINHTTP_DEF} -k -D winhttp.dll -l libwinhttp.a
DEPENDS ${WINHTTP_DEF} DEPENDS ${WINHTTP_DEF}
WORKING_DIRECTORY ${LIBWINHTTP_PATH} WORKING_DIRECTORY ${LIBWINHTTP_PATH})
)
SET_SOURCE_FILES_PROPERTIES( set_source_files_properties(
${CMAKE_CURRENT_SOURCE_DIR}/src/transports/winhttp.c ${CMAKE_CURRENT_SOURCE_DIR}/src/transports/winhttp.c
PROPERTIES OBJECT_DEPENDS ${LIBWINHTTP_PATH}/libwinhttp.a PROPERTIES OBJECT_DEPENDS ${LIBWINHTTP_PATH}/libwinhttp.a)
)
The maintainers of the libgit2 project believe that having a stable API
to program against is important for our users and the ecosystem - whether
you're building against the libgit2 C APIs directly, creating a wrapper to
a managed language, or programming against one of those managed wrappers
like LibGit2Sharp or Rugged.
Our API stability considerations are:
* Our standard API is considered stable through a major release.
* We define our "standard API" to be anything included in the "git2.h"
header - in other words, anything defined in a header in the `git2`
directory.
* APIs will maintain their signature and will not be removed within a
major release, but new APIs may be added.
* Any APIs may be marked as deprecated within a major release, but will
not be removed until the next major release (at the earliest). You
may define `GIT_DEPRECATE_HARD` to produce compiler warnings if you
target these deprecated APIs.
* We consider API compatibility to be against the C APIs. That means
that we may use macros to keep API compatibility - for example, if we
rename a structure from `git_widget_options` to `git_foobar_options`
then we would `#define git_widget_options git_foobar_options` to retain
API compatibility. Note that this does _not_ provide ABI compatibility.
* Our systems API is only considered stable through a _minor_ release.
* We define our "systems API" to be anything included in the `git2/sys`
directory. These are not "standard" APIs but are mechanisms to extend
libgit2 by adding new extensions - for example, a custom HTTPS transport,
TLS engine, or merge strategy.
* Additionally, the cmake options and the resulting constants that it
produces to be "systems API".
* Generally these mechanism are well defined and will not need significant
changes, but are considered a part of the library itself and may need
* Systems API changes will be noted specially within a release's changelog.
* Our ABI is only considered stable through a _minor_ release.
* Our ABI consists of actual symbol names in the library, the function
signatures, and the actual layout of structures. These are only
stable within minor releases, they are not stable within major releases
(yet).
* Since many FFIs use ABIs directly (for example, .NET P/Invoke or Rust),
this instability is unfortunate.
* In a future major release, we will begin providing ABI stability
throughout the major release cycle.
* ABI changes will be noted specially within a release's changelog.
* Point releases are _generally_ only for bugfixes, and generally do _not_
include new features. This means that point releases generally do _not_
include new APIs. Point releases will never break API, systems API or
ABI compatibility.
Memory allocation and ownership
-------------------------------
Any library needs to _take_ data from users, and then _return_ data to
users. With some types this is simple - integer parameters and return
types are trivial. But with more complex data types, things are more
complicated. Even something seemingly simple, like a C string, requires
discipline: we cannot simple return an allocated hunk of memory for
callers to `free`, since some systems have multiple allocators and users
cannot necessarily reason about the allocator used and which corresponding
deallocation function to call to free the memory.
## Objects
Most types in libgit2 are "opaque" types, which we treat as "objects" (even
though C is "not an object oriented language"). You may create an object -
for example, with `git_odb_new`, or libgit2 may return you an object as an
"out" parameter - for example, with `git_repository_open`. With any of
these objects, you should call their corresponding `_free` function (for
example, `git_odb_free` or `git_repository_free`) when you are done using
them.
## Structures
libgit2 will often take _input_ as structures (for example, options
structures like `git_merge_options`). Rarely, libgit2 will return data in
a structure. This is typically used for simpler data types, like `git_buf`
and `git_strarray`. Users should allocate the structure themselves (either
on the stack or the heap) and pass a pointer to it. Since libgit2 does not
allocate the structure itself, only the data inside of it, the deallocation
functions are suffixed with `_dispose` instead of `_free`, since they only
free the data _inside_ the structure.
## Strings or continuous memory buffers (`git_buf`)
libgit2 typically _takes_ NUL-terminated strings ("C strings") with a
`const char *`, and typically _takes_ raw data with a `const char *` and a
corresponding `size_t` for its size. libgit2 typically _returns_ strings
or raw data in a `git_buf` structure. The given data buffer will always be
NUL terminated (even if it contains binary data) and the `size` member will
always contain the size (in bytes) of the contents of the pointer (excluding
the NUL terminator).
In other words, if a `git_buf` contains the string `foo` then the memory
buffer will be { `f`, `o`, `o`, `\0` } and the size will be `3`.
Callers _must_ initialize the buffer with `GIT_BUF_INIT` (or by setting
all the members to `0`) when it is created, before passing a pointer
to the buffer to libgit2 for the first time.
Subsequent calls to libgit2 APIs that take a buffer can re-use a
buffer that was previously used. The buffer will be cleared and grown
to accommodate the new contents (if necessary). The new data will
written into the buffer, overwriting the previous contents. This
allows callers to reduce the number of allocations performed by the
library.
Callers must call `git_buf_dispose` when they have finished.
Note that the deprecated `git_diff_format_email` API does not follow
this behavior; subsequent calls will concatenate data to the buffer
instead of rewriting it. Users should move to the new `git_email`
APIs that follow the `git_buf` standards.
v1.4
----
This is release v1.4.0, "Fisematenten". This release includes several new features and bugfixes, improves compatibility with git, and begins preparation for SHA256 support in a future release.
## What's Changed
### New features
* diff: update rename limit to 1000 to match git's behavior by @ethomson in https://github.com/libgit2/libgit2/pull/6092
* odb: support checking for object existence without refresh by @joshtriplett in https://github.com/libgit2/libgit2/pull/6107
* object: provide a low-level mechanism to validate whether a raw object is valid (`git_object_rawcontent_is_valid`) by @ethomson in https://github.com/libgit2/libgit2/pull/6128
* blob: provide a function to identify binary content by @ethomson in https://github.com/libgit2/libgit2/pull/6142
* status: add `rename_threshold` to `git_status_options`. by @arroz in https://github.com/libgit2/libgit2/pull/6158
* remote: support `http.followRedirects` (`false` and `initial`) and follow initial redirects by default by @ethomson in https://github.com/libgit2/libgit2/pull/6175
* remote: support scp style paths with ports (`[git@github.com:22]:libgit2/libgit2`) by @ethomson in https://github.com/libgit2/libgit2/pull/6167
* win32: update git for windows configuration file location compatibility by @csware in https://github.com/libgit2/libgit2/pull/6151 and @ethomson in https://github.com/libgit2/libgit2/pull/6180
* refs: speed up packed reference lookups when packed refs are sorted by @ccstolley in https://github.com/libgit2/libgit2/pull/6138
* merge: support zdiff3 conflict styles by @ethomson in https://github.com/libgit2/libgit2/pull/6195
* remote: support fetching by object id (using "+oid:ref" refspec syntax) by @ethomson in https://github.com/libgit2/libgit2/pull/6203
* merge: callers can specify virtual-base building behavior and to optionally accept conflict markers as a resolution by @boretrk in https://github.com/libgit2/libgit2/pull/6204
### Bug fixes
* Fix a gcc 11 warning in src/threadstate.c by @lhchavez in https://github.com/libgit2/libgit2/pull/6115
* Fix a gcc 11 warning in src/thread.h by @lhchavez in https://github.com/libgit2/libgit2/pull/6116
* cmake: re-enable WinHTTP by @ethomson in https://github.com/libgit2/libgit2/pull/6120
* Fix repo init when template dir is non-existent by @ammgws in https://github.com/libgit2/libgit2/pull/6106
* cmake: use project-specific root variable instead of CMAKE_SOURCE_DIR by @Qix- in https://github.com/libgit2/libgit2/pull/6146
* Better revparse compatibility for at time notation by @yoichi in https://github.com/libgit2/libgit2/pull/6095
* remotes: fix insteadOf/pushInsteadOf handling by @mkhl in https://github.com/libgit2/libgit2/pull/6101
* git_commit_summary: ignore lines with spaces by @stforek in https://github.com/libgit2/libgit2/pull/6125
* Config parsing by @csware in https://github.com/libgit2/libgit2/pull/6124
* config: handle empty conditional in includeIf by @ethomson in https://github.com/libgit2/libgit2/pull/6165
* #6154 git_status_list_new case insensitive fix by @arroz in https://github.com/libgit2/libgit2/pull/6159
* futils_mktmp: don't use umask by @boretrk in https://github.com/libgit2/libgit2/pull/6178
* revparse: support bare '@' by @ethomson in https://github.com/libgit2/libgit2/pull/6196
* odb: check for write failures by @ethomson in https://github.com/libgit2/libgit2/pull/6206
* push: Prepare pack before sending pack header. by @ccstolley in https://github.com/libgit2/libgit2/pull/6205
* mktmp: improve our temp file creation by @ethomson in https://github.com/libgit2/libgit2/pull/6207
* diff_file: fix crash if size of diffed file changes in workdir by @jorio in https://github.com/libgit2/libgit2/pull/6208
* merge: comment conflicts lines in MERGE_MSG by @ethomson in https://github.com/libgit2/libgit2/pull/6197
* Fix crashes in example programs on Windows (sprintf_s not compatible with snprintf) by @apnadkarni in https://github.com/libgit2/libgit2/pull/6212
### Code cleanups
* Introduce `git_remote_connect_options` by @ethomson in https://github.com/libgit2/libgit2/pull/6161
* hash: separate hashes and git_oid by @ethomson in https://github.com/libgit2/libgit2/pull/6082
* `git_buf`: now a public-only API (`git_str` is our internal API) by @ethomson in https://github.com/libgit2/libgit2/pull/6078
* cmake: cleanups and consistency by @ethomson in https://github.com/libgit2/libgit2/pull/6084
* path: refactor utility path functions by @ethomson in https://github.com/libgit2/libgit2/pull/6104
* str: git_str_free is never a function by @ethomson in https://github.com/libgit2/libgit2/pull/6111
* cmake refactorings by @ethomson in https://github.com/libgit2/libgit2/pull/6112
* Add missing-declarations warning globally by @ethomson in https://github.com/libgit2/libgit2/pull/6113
* cmake: further refactorings by @ethomson in https://github.com/libgit2/libgit2/pull/6114
* tag: set validity to 0 by default by @ethomson in https://github.com/libgit2/libgit2/pull/6119
* util: minor cleanup and refactoring to the date class by @ethomson in https://github.com/libgit2/libgit2/pull/6121
* Minor code cleanups by @ethomson in https://github.com/libgit2/libgit2/pull/6122
* Fix a long long that crept past by @NattyNarwhal in https://github.com/libgit2/libgit2/pull/6094
* remote: refactor insteadof application by @ethomson in https://github.com/libgit2/libgit2/pull/6147
* ntmlclient: fix linking with libressl by @boretrk in https://github.com/libgit2/libgit2/pull/6157
* c99: change single bit flags to unsigned by @boretrk in https://github.com/libgit2/libgit2/pull/6179
* Fix typos by @rex4539 in https://github.com/libgit2/libgit2/pull/6164
* diff_driver: split global_drivers array into separate elements by @boretrk in https://github.com/libgit2/libgit2/pull/6184
* cmake: disable some gnu extensions by @boretrk in https://github.com/libgit2/libgit2/pull/6185
* Disabling setting `CMAKE_FIND_LIBRARY_SUFFIXES` on Apple platforms. by @arroz in https://github.com/libgit2/libgit2/pull/6153
* C90: add inline macro to xdiff and mbedtls by @boretrk in https://github.com/libgit2/libgit2/pull/6200
* SHA256: early preparation by @ethomson in https://github.com/libgit2/libgit2/pull/6192
### CI improvements
* tests: rename test runner to `libgit2_tests`, build option to `BUILD_TESTS`. by @ethomson in https://github.com/libgit2/libgit2/pull/6083
* ci: only update docs on push by @ethomson in https://github.com/libgit2/libgit2/pull/6108
* Pedantic header test by @boretrk in https://github.com/libgit2/libgit2/pull/6086
* ci: build with ssh on nightly by @ethomson in https://github.com/libgit2/libgit2/pull/6148
* ci: improve the name in CI runs by @ethomson in https://github.com/libgit2/libgit2/pull/6198
### Documentation improvements
* Document that `git_odb` is thread-safe by @joshtriplett in https://github.com/libgit2/libgit2/pull/6109
* Improve documentation by @punkymaniac in https://github.com/libgit2/libgit2/pull/6168
### Other changes
* libgit2_clar is now libgit2_tests by @mkhl in https://github.com/libgit2/libgit2/pull/6100
* Remove PSGit from Language Bindings section of README by @cestrand in https://github.com/libgit2/libgit2/pull/6150
* COPYING: remove regex copyright, add PCRE copyright by @ethomson in https://github.com/libgit2/libgit2/pull/6187
* meta: add a release configuration file by @ethomson in https://github.com/libgit2/libgit2/pull/6211
## New Contributors
* @mkhl made their first contribution in https://github.com/libgit2/libgit2/pull/6100
* @ammgws made their first contribution in https://github.com/libgit2/libgit2/pull/6106
* @yoichi made their first contribution in https://github.com/libgit2/libgit2/pull/6095
* @stforek made their first contribution in https://github.com/libgit2/libgit2/pull/6125
* @cestrand made their first contribution in https://github.com/libgit2/libgit2/pull/6150
* @rex4539 made their first contribution in https://github.com/libgit2/libgit2/pull/6164
* @jorio made their first contribution in https://github.com/libgit2/libgit2/pull/6208
**Full Changelog**: https://github.com/libgit2/libgit2/compare/v1.3.0...v1.4.0
v1.3 v1.3
---- ----
...@@ -1963,3 +2056,8 @@ v0.22 ...@@ -1963,3 +2056,8 @@ v0.22
functions. This is not something which we can know to do. A functions. This is not something which we can know to do. A
last-resort convenience function is provided in sys/openssl.h, last-resort convenience function is provided in sys/openssl.h,
`git_openssl_set_locking()` which can be used to set the locking. `git_openssl_set_locking()` which can be used to set the locking.
* `git_reference_*()` functions use mmap() + binary search for packed
refs lookups when using the fs backend. Previously all entries were
read into a hashtable, which could be slow for repositories with a
large number of refs.
...@@ -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.
......
...@@ -19,7 +19,7 @@ automated fuzz testing. libFuzzer only works with clang. ...@@ -19,7 +19,7 @@ automated fuzz testing. libFuzzer only works with clang.
and [`leak`/`address,leak`](https://clang.llvm.org/docs/LeakSanitizer.html). and [`leak`/`address,leak`](https://clang.llvm.org/docs/LeakSanitizer.html).
3. Create the cmake build environment and configure the build with the 3. Create the cmake build environment and configure the build with the
sanitizer chosen: `CC=/usr/bin/clang-6.0 CFLAGS="-fsanitize=address" cmake sanitizer chosen: `CC=/usr/bin/clang-6.0 CFLAGS="-fsanitize=address" cmake
-DBUILD_CLAR=OFF -DBUILD_FUZZERS=ON -DCMAKE_BUILD_TYPE=RelWithDebInfo ..`. -DBUILD_TESTS=OFF -DBUILD_FUZZERS=ON -DCMAKE_BUILD_TYPE=RelWithDebInfo ..`.
Note that building the fuzzer targets is incompatible with the Note that building the fuzzer targets is incompatible with the
tests and examples. tests and examples.
4. Build libgit2: `cmake --build .` 4. Build libgit2: `cmake --build .`
......
...@@ -80,4 +80,4 @@ and run it against our description file with the tip of `main` checked out. ...@@ -80,4 +80,4 @@ and run it against our description file with the tip of `main` checked out.
cm doc api.docurium cm doc api.docurium
It will start up a few proceses and write out the results as a new commit onto the `gh-pages` branch. That can be pushed to GitHub to update what will show up on our documentation reference site. It will start up a few processes and write out the results as a new commit onto the `gh-pages` branch. That can be pushed to GitHub to update what will show up on our documentation reference site.
...@@ -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}) # examples: code usage examples of libgit2
INCLUDE_DIRECTORIES(SYSTEM ${LIBGIT2_SYSTEM_INCLUDES})
FILE(GLOB LG2_SOURCES *.c *.h) file(GLOB SRC_EXAMPLES *.c *.h)
ADD_EXECUTABLE(lg2 ${LG2_SOURCES})
SET_TARGET_PROPERTIES(lg2 PROPERTIES C_STANDARD 90) add_executable(lg2 ${SRC_EXAMPLES})
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 libgit2package)
ELSE() else()
TARGET_LINK_LIBRARIES(lg2 git2 pthread) target_link_libraries(lg2 libgit2package pthread)
ENDIF() endif()
...@@ -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");
......
...@@ -49,7 +49,7 @@ int lg2_blame(git_repository *repo, int argc, char *argv[]) ...@@ -49,7 +49,7 @@ int lg2_blame(git_repository *repo, int argc, char *argv[])
if (o.F) blameopts.flags |= GIT_BLAME_FIRST_PARENT; if (o.F) blameopts.flags |= GIT_BLAME_FIRST_PARENT;
/** /**
* The commit range comes in "commitish" form. Use the rev-parse API to * The commit range comes in "committish" form. Use the rev-parse API to
* nail down the end points. * nail down the end points.
*/ */
if (o.commitspec) { if (o.commitspec) {
...@@ -70,7 +70,7 @@ int lg2_blame(git_repository *repo, int argc, char *argv[]) ...@@ -70,7 +70,7 @@ int lg2_blame(git_repository *repo, int argc, char *argv[])
/** /**
* Get the raw data inside the blob for output. We use the * Get the raw data inside the blob for output. We use the
* `commitish:path/to/file.txt` format to find it. * `committish:path/to/file.txt` format to find it.
*/ */
if (git_oid_is_zero(&blameopts.newest_commit)) if (git_oid_is_zero(&blameopts.newest_commit))
strcpy(spec, "HEAD"); strcpy(spec, "HEAD");
......
...@@ -26,7 +26,7 @@ ...@@ -26,7 +26,7 @@
* This does have: * This does have:
* *
* - Example of performing a git commit with a comment * - Example of performing a git commit with a comment
* *
*/ */
int lg2_commit(git_repository *repo, int argc, char **argv) int lg2_commit(git_repository *repo, int argc, char **argv)
{ {
...@@ -36,10 +36,10 @@ int lg2_commit(git_repository *repo, int argc, char **argv) ...@@ -36,10 +36,10 @@ int lg2_commit(git_repository *repo, int argc, char **argv)
git_oid commit_oid,tree_oid; git_oid commit_oid,tree_oid;
git_tree *tree; git_tree *tree;
git_index *index; git_index *index;
git_object *parent = NULL; git_object *parent = NULL;
git_reference *ref = NULL; git_reference *ref = NULL;
git_signature *signature; git_signature *signature;
/* Validate args */ /* Validate args */
if (argc < 3 || strcmp(opt, "-m") != 0) { if (argc < 3 || strcmp(opt, "-m") != 0) {
...@@ -62,9 +62,9 @@ int lg2_commit(git_repository *repo, int argc, char **argv) ...@@ -62,9 +62,9 @@ int lg2_commit(git_repository *repo, int argc, char **argv)
check_lg2(git_index_write(index), "Could not write index", NULL);; check_lg2(git_index_write(index), "Could not write index", NULL);;
check_lg2(git_tree_lookup(&tree, repo, &tree_oid), "Error looking up tree", NULL); check_lg2(git_tree_lookup(&tree, repo, &tree_oid), "Error looking up tree", NULL);
check_lg2(git_signature_default(&signature, repo), "Error creating signature", NULL); check_lg2(git_signature_default(&signature, repo), "Error creating signature", NULL);
check_lg2(git_commit_create_v( check_lg2(git_commit_create_v(
&commit_oid, &commit_oid,
repo, repo,
...@@ -78,7 +78,9 @@ int lg2_commit(git_repository *repo, int argc, char **argv) ...@@ -78,7 +78,9 @@ int lg2_commit(git_repository *repo, int argc, char **argv)
git_index_free(index); git_index_free(index);
git_signature_free(signature); git_signature_free(signature);
git_tree_free(tree); git_tree_free(tree);
git_object_free(parent);
git_reference_free(ref);
return error; return error;
} }
...@@ -45,7 +45,7 @@ ...@@ -45,7 +45,7 @@
#endif #endif
#ifdef _MSC_VER #ifdef _MSC_VER
#define snprintf sprintf_s #define snprintf _snprintf
#define strcasecmp strcmpi #define strcasecmp strcmpi
#endif #endif
......
...@@ -344,7 +344,7 @@ static void parse_opts(struct diff_options *o, int argc, char *argv[]) ...@@ -344,7 +344,7 @@ static void parse_opts(struct diff_options *o, int argc, char *argv[])
static void diff_print_stats(git_diff *diff, struct diff_options *o) static void diff_print_stats(git_diff *diff, struct diff_options *o)
{ {
git_diff_stats *stats; git_diff_stats *stats;
git_buf b = GIT_BUF_INIT_CONST(NULL, 0); git_buf b = GIT_BUF_INIT;
git_diff_stats_format_t format = 0; git_diff_stats_format_t format = 0;
check_lg2( check_lg2(
......
...@@ -17,7 +17,6 @@ int lg2_index_pack(git_repository *repo, int argc, char **argv) ...@@ -17,7 +17,6 @@ int lg2_index_pack(git_repository *repo, int argc, char **argv)
git_indexer *idx; git_indexer *idx;
git_indexer_progress stats = {0, 0}; git_indexer_progress stats = {0, 0};
int error; int error;
char hash[GIT_OID_HEXSZ + 1] = {0};
int fd; int fd;
ssize_t read_bytes; ssize_t read_bytes;
char buf[512]; char buf[512];
...@@ -61,8 +60,7 @@ int lg2_index_pack(git_repository *repo, int argc, char **argv) ...@@ -61,8 +60,7 @@ int lg2_index_pack(git_repository *repo, int argc, char **argv)
printf("\rIndexing %u of %u\n", stats.indexed_objects, stats.total_objects); printf("\rIndexing %u of %u\n", stats.indexed_objects, stats.total_objects);
git_oid_fmt(hash, git_indexer_hash(idx)); puts(git_indexer_name(idx));
puts(hash);
cleanup: cleanup:
close(fd); close(fd);
......
...@@ -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}) # fuzzers: libFuzzer and standalone fuzzing utilities
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)
ADD_C_FLAG(-fsanitize=fuzzer) set(CMAKE_REQUIRED_FLAGS "-fsanitize=fuzzer-no-link")
ENDIF () add_c_flag(-fsanitize=fuzzer)
add_c_flag(-fsanitize=fuzzer-no-link)
unset(CMAKE_REQUIRED_FLAGS)
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})
SET(${fuzz_target_name}_SOURCES ${fuzz_target_src} ${LIBGIT2_OBJECTS}) set(${fuzz_target_name}_SOURCES ${fuzz_target_src} ${LIBGIT2_OBJECTS})
IF(USE_STANDALONE_FUZZERS) if(USE_STANDALONE_FUZZERS)
LIST(APPEND ${fuzz_target_name}_SOURCES "standalone_driver.c") list(APPEND ${fuzz_target_name}_SOURCES "standalone_driver.c")
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})
ADD_TEST(${fuzz_target_name} "${CMAKE_CURRENT_BINARY_DIR}/${fuzz_target_name}" "${CMAKE_CURRENT_SOURCE_DIR}/corpora/${fuzz_name}") target_include_directories(${fuzz_target_name} PRIVATE ${LIBGIT2_INCLUDES} ${LIBGIT2_DEPENDENCY_INCLUDES})
ENDFOREACH() 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}")
endforeach()
...@@ -11,12 +11,14 @@ ...@@ -11,12 +11,14 @@
#include "git2.h" #include "git2.h"
#include "buffer.h"
#include "common.h" #include "common.h"
#include "str.h"
#include "futils.h" #include "futils.h"
#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);
...@@ -33,7 +35,8 @@ int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size) ...@@ -33,7 +35,8 @@ int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size)
{ {
git_commit_graph_file file = {{0}}; git_commit_graph_file file = {{0}};
git_commit_graph_entry e; git_commit_graph_entry e;
git_buf commit_graph_buf = GIT_BUF_INIT; git_str commit_graph_buf = GIT_STR_INIT;
unsigned char hash[GIT_HASH_SHA1_SIZE];
git_oid oid = {{0}}; git_oid oid = {{0}};
bool append_hash = false; bool append_hash = false;
...@@ -50,22 +53,24 @@ int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size) ...@@ -50,22 +53,24 @@ int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size)
size -= 4; size -= 4;
if (append_hash) { if (append_hash) {
if (git_buf_init(&commit_graph_buf, size + sizeof(oid)) < 0) if (git_str_init(&commit_graph_buf, size + GIT_HASH_SHA1_SIZE) < 0)
goto cleanup; goto cleanup;
if (git_hash_buf(&oid, data, size) < 0) { if (git_hash_buf(hash, data, size, GIT_HASH_ALGORITHM_SHA1) < 0) {
fprintf(stderr, "Failed to compute the SHA1 hash\n"); fprintf(stderr, "Failed to compute the SHA1 hash\n");
abort(); abort();
} }
memcpy(commit_graph_buf.ptr, data, size); memcpy(commit_graph_buf.ptr, data, size);
memcpy(commit_graph_buf.ptr + size, &oid, sizeof(oid)); memcpy(commit_graph_buf.ptr + size, hash, GIT_HASH_SHA1_SIZE);
memcpy(oid.id, hash, GIT_OID_RAWSZ);
} else { } else {
git_buf_attach_notowned(&commit_graph_buf, (char *)data, size); git_str_attach_notowned(&commit_graph_buf, (char *)data, size);
} }
if (git_commit_graph_file_parse( if (git_commit_graph_file_parse(
&file, &file,
(const unsigned char *)git_buf_cstr(&commit_graph_buf), (const unsigned char *)git_str_cstr(&commit_graph_buf),
git_buf_len(&commit_graph_buf)) git_str_len(&commit_graph_buf))
< 0) < 0)
goto cleanup; goto cleanup;
...@@ -75,6 +80,6 @@ int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size) ...@@ -75,6 +80,6 @@ int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size)
cleanup: cleanup:
git_commit_graph_file_close(&file); git_commit_graph_file_close(&file);
git_buf_dispose(&commit_graph_buf); git_str_dispose(&commit_graph_buf);
return 0; return 0;
} }
...@@ -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);
......
...@@ -64,7 +64,7 @@ slack channel once you've registered. ...@@ -64,7 +64,7 @@ slack channel once you've registered.
If you have questions about the library, please be sure to check out the If you have questions about the library, please be sure to check out the
[API documentation](http://libgit2.github.com/libgit2/). If you still have [API documentation](http://libgit2.github.com/libgit2/). If you still have
questions, reach out to us on Slack or post a question on questions, reach out to us on Slack or post a question on
[StackOverflow](http://stackoverflow.com/questions/tagged/libgit2) (with the `libgit2` tag). [StackOverflow](http://stackoverflow.com/questions/tagged/libgit2) (with the `libgit2` tag).
**Reporting Bugs** **Reporting Bugs**
...@@ -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
...@@ -229,7 +229,7 @@ The following CMake variables are declared: ...@@ -229,7 +229,7 @@ The following CMake variables are declared:
- `LIB_INSTALL_DIR`: Where to install libraries to. - `LIB_INSTALL_DIR`: Where to install libraries to.
- `INCLUDE_INSTALL_DIR`: Where to install headers to. - `INCLUDE_INSTALL_DIR`: 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_CLAR`: Build [Clar](https://github.com/vmg/clar)-based test suite (defaults to ON) - `BUILD_TESTS`: Build [Clar](https://github.com/vmg/clar)-based test suite (defaults to ON)
- `THREADSAFE`: Build libgit2 with threading support (defaults to ON) - `THREADSAFE`: Build libgit2 with threading support (defaults to ON)
- `STDCALL`: Build libgit2 as `stdcall`. Turn off for `cdecl` (Windows; defaults to ON) - `STDCALL`: Build libgit2 as `stdcall`. Turn off for `cdecl` (Windows; defaults to ON)
......
...@@ -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",
......
...@@ -11,12 +11,13 @@ ...@@ -11,12 +11,13 @@
#include "git2.h" #include "git2.h"
#include "buffer.h"
#include "common.h" #include "common.h"
#include "futils.h" #include "futils.h"
#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);
...@@ -33,7 +34,8 @@ int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size) ...@@ -33,7 +34,8 @@ int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size)
{ {
git_midx_file idx = {{0}}; git_midx_file idx = {{0}};
git_midx_entry e; git_midx_entry e;
git_buf midx_buf = GIT_BUF_INIT; git_str midx_buf = GIT_STR_INIT;
unsigned char hash[GIT_HASH_SHA1_SIZE];
git_oid oid = {{0}}; git_oid oid = {{0}};
bool append_hash = false; bool append_hash = false;
...@@ -50,19 +52,21 @@ int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size) ...@@ -50,19 +52,21 @@ int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size)
size -= 4; size -= 4;
if (append_hash) { if (append_hash) {
if (git_buf_init(&midx_buf, size + sizeof(oid)) < 0) if (git_str_init(&midx_buf, size + GIT_HASH_SHA1_SIZE) < 0)
goto cleanup; goto cleanup;
if (git_hash_buf(&oid, data, size) < 0) { if (git_hash_buf(hash, data, size, GIT_HASH_ALGORITHM_SHA1) < 0) {
fprintf(stderr, "Failed to compute the SHA1 hash\n"); fprintf(stderr, "Failed to compute the SHA1 hash\n");
abort(); abort();
} }
memcpy(midx_buf.ptr, data, size); memcpy(midx_buf.ptr, data, size);
memcpy(midx_buf.ptr + size, &oid, sizeof(oid)); memcpy(midx_buf.ptr + size, hash, GIT_HASH_SHA1_SIZE);
memcpy(oid.id, hash, GIT_OID_RAWSZ);
} else { } else {
git_buf_attach_notowned(&midx_buf, (char *)data, size); git_str_attach_notowned(&midx_buf, (char *)data, size);
} }
if (git_midx_parse(&idx, (const unsigned char *)git_buf_cstr(&midx_buf), git_buf_len(&midx_buf)) < 0) if (git_midx_parse(&idx, (const unsigned char *)git_str_cstr(&midx_buf), git_str_len(&midx_buf)) < 0)
goto cleanup; goto cleanup;
/* Search for any oid, just to exercise that codepath. */ /* Search for any oid, just to exercise that codepath. */
...@@ -71,6 +75,6 @@ int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size) ...@@ -71,6 +75,6 @@ int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size)
cleanup: cleanup:
git_midx_close(&idx); git_midx_close(&idx);
git_buf_dispose(&midx_buf); git_str_dispose(&midx_buf);
return 0; return 0;
} }
...@@ -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)
......
...@@ -12,7 +12,9 @@ ...@@ -12,7 +12,9 @@
#include "git2.h" #include "git2.h"
#include "git2/sys/mempack.h" #include "git2/sys/mempack.h"
#include "common.h" #include "common.h"
#include "buffer.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;
...@@ -53,7 +55,7 @@ int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size) ...@@ -53,7 +55,7 @@ int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size)
{ {
git_indexer_progress stats = {0, 0}; git_indexer_progress stats = {0, 0};
git_indexer *indexer = NULL; git_indexer *indexer = NULL;
git_buf path = GIT_BUF_INIT; git_str path = GIT_STR_INIT;
git_oid oid; git_oid oid;
bool append_hash = false; bool append_hash = false;
...@@ -92,26 +94,26 @@ int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size) ...@@ -92,26 +94,26 @@ int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size)
fprintf(stderr, "Failed to compute the SHA1 hash\n"); fprintf(stderr, "Failed to compute the SHA1 hash\n");
abort(); abort();
} }
if (git_indexer_append(indexer, &oid, sizeof(oid), &stats) < 0) { if (git_indexer_append(indexer, &oid.id, GIT_OID_RAWSZ, &stats) < 0) {
goto cleanup; goto cleanup;
} }
} }
if (git_indexer_commit(indexer, &stats) < 0) if (git_indexer_commit(indexer, &stats) < 0)
goto cleanup; goto cleanup;
if (git_buf_printf(&path, "pack-%s.idx", git_oid_tostr_s(git_indexer_hash(indexer))) < 0) if (git_str_printf(&path, "pack-%s.idx", git_indexer_name(indexer)) < 0)
goto cleanup; goto cleanup;
p_unlink(git_buf_cstr(&path)); p_unlink(git_str_cstr(&path));
git_buf_clear(&path); git_str_clear(&path);
if (git_buf_printf(&path, "pack-%s.pack", git_oid_tostr_s(git_indexer_hash(indexer))) < 0) if (git_str_printf(&path, "pack-%s.pack", git_indexer_name(indexer)) < 0)
goto cleanup; goto cleanup;
p_unlink(git_buf_cstr(&path)); p_unlink(git_str_cstr(&path));
cleanup: cleanup:
git_mempack_reset(mempack); git_mempack_reset(mempack);
git_indexer_free(indexer); git_indexer_free(indexer);
git_buf_dispose(&path); git_str_dispose(&path);
return 0; return 0;
} }
...@@ -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,12 +11,11 @@ ...@@ -11,12 +11,11 @@
#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)
{ {
git_buf buf = GIT_BUF_INIT; git_str buf = GIT_STR_INIT;
int error = 0; int error = 0;
if (git_futils_readbuffer(&buf, filename) < 0) { if (git_futils_readbuffer(&buf, filename) < 0) {
...@@ -27,7 +26,7 @@ static int run_one_file(const char *filename) ...@@ -27,7 +26,7 @@ static int run_one_file(const char *filename)
LLVMFuzzerTestOneInput((const unsigned char *)buf.ptr, buf.size); LLVMFuzzerTestOneInput((const unsigned char *)buf.ptr, buf.size);
exit: exit:
git_buf_dispose(&buf); git_str_dispose(&buf);
return error; return error;
} }
...@@ -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;
......
...@@ -4,14 +4,11 @@ ...@@ -4,14 +4,11 @@
* This file is part of libgit2, distributed under the GNU GPL v2 with * This file is part of libgit2, distributed under the GNU GPL v2 with
* a Linking Exception. For full terms see the included COPYING file. * a Linking Exception. For full terms see the included COPYING file.
*/ */
#ifndef INCLUDE_message_h__
#define INCLUDE_message_h__
#include "common.h" #ifndef INCLUDE_standalone_driver_h__
#define INCLUDE_standalone_driver_h__
#include "git2/message.h" extern int LLVMFuzzerTestOneInput(const unsigned char *data, size_t size);
#include "buffer.h" extern int LLVMFuzzerInitialize(int *argc, char ***argv);
int git_message__prettify(git_buf *message_out, const char *message, int strip_comments);
#endif #endif
...@@ -32,6 +32,8 @@ GIT_BEGIN_DECL ...@@ -32,6 +32,8 @@ GIT_BEGIN_DECL
* *
* @param delta The delta to be applied * @param delta The delta to be applied
* @param payload User-specified payload * @param payload User-specified payload
* @return 0 if the delta is applied, < 0 if the apply process will be aborted
* or > 0 if the delta will not be applied.
*/ */
typedef int GIT_CALLBACK(git_apply_delta_cb)( typedef int GIT_CALLBACK(git_apply_delta_cb)(
const git_diff_delta *delta, const git_diff_delta *delta,
...@@ -48,6 +50,8 @@ typedef int GIT_CALLBACK(git_apply_delta_cb)( ...@@ -48,6 +50,8 @@ typedef int GIT_CALLBACK(git_apply_delta_cb)(
* *
* @param hunk The hunk to be applied * @param hunk The hunk to be applied
* @param payload User-specified payload * @param payload User-specified payload
* @return 0 if the hunk is applied, < 0 if the apply process will be aborted
* or > 0 if the hunk will not be applied.
*/ */
typedef int GIT_CALLBACK(git_apply_hunk_cb)( typedef int GIT_CALLBACK(git_apply_hunk_cb)(
const git_diff_hunk *hunk, const git_diff_hunk *hunk,
...@@ -59,7 +63,7 @@ typedef enum { ...@@ -59,7 +63,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;
/** /**
...@@ -89,6 +93,16 @@ typedef struct { ...@@ -89,6 +93,16 @@ typedef struct {
#define GIT_APPLY_OPTIONS_VERSION 1 #define GIT_APPLY_OPTIONS_VERSION 1
#define GIT_APPLY_OPTIONS_INIT {GIT_APPLY_OPTIONS_VERSION} #define GIT_APPLY_OPTIONS_INIT {GIT_APPLY_OPTIONS_VERSION}
/**
* Initialize git_apply_options structure
*
* Initialize a `git_apply_options` with default values. Equivalent to creating
* an instance with GIT_APPLY_OPTIONS_INIT.
*
* @param opts The `git_apply_options` struct to initialize.
* @param version The struct version; pass `GIT_APPLY_OPTIONS_VERSION`
* @return 0 on success or -1 on failure.
*/
GIT_EXTERN(int) git_apply_options_init(git_apply_options *opts, unsigned int version); GIT_EXTERN(int) git_apply_options_init(git_apply_options *opts, unsigned int version);
/** /**
...@@ -127,7 +141,7 @@ typedef enum { ...@@ -127,7 +141,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;
/** /**
...@@ -177,6 +177,7 @@ typedef struct { ...@@ -177,6 +177,7 @@ typedef struct {
* not have to exist, but if it does not, then it will be * not have to exist, but if it does not, then it will be
* treated as a plain file (not a directory). * treated as a plain file (not a directory).
* @param name The name of the attribute to look up. * @param name The name of the attribute to look up.
* @return 0 or an error code.
*/ */
GIT_EXTERN(int) git_attr_get( GIT_EXTERN(int) git_attr_get(
const char **value_out, const char **value_out,
...@@ -199,6 +200,7 @@ GIT_EXTERN(int) git_attr_get( ...@@ -199,6 +200,7 @@ GIT_EXTERN(int) git_attr_get(
* not have to exist, but if it does not, then it will be * not have to exist, but if it does not, then it will be
* treated as a plain file (not a directory). * treated as a plain file (not a directory).
* @param name The name of the attribute to look up. * @param name The name of the attribute to look up.
* @return 0 or an error code.
*/ */
GIT_EXTERN(int) git_attr_get_ext( GIT_EXTERN(int) git_attr_get_ext(
const char **value_out, const char **value_out,
...@@ -235,6 +237,7 @@ GIT_EXTERN(int) git_attr_get_ext( ...@@ -235,6 +237,7 @@ GIT_EXTERN(int) git_attr_get_ext(
* it will be treated as a plain file (i.e. not a directory). * it will be treated as a plain file (i.e. not a directory).
* @param num_attr The number of attributes being looked up * @param num_attr The number of attributes being looked up
* @param names An array of num_attr strings containing attribute names. * @param names An array of num_attr strings containing attribute names.
* @return 0 or an error code.
*/ */
GIT_EXTERN(int) git_attr_get_many( GIT_EXTERN(int) git_attr_get_many(
const char **values_out, const char **values_out,
...@@ -259,6 +262,7 @@ GIT_EXTERN(int) git_attr_get_many( ...@@ -259,6 +262,7 @@ GIT_EXTERN(int) git_attr_get_many(
* it will be treated as a plain file (i.e. not a directory). * it will be treated as a plain file (i.e. not a directory).
* @param num_attr The number of attributes being looked up * @param num_attr The number of attributes being looked up
* @param names An array of num_attr strings containing attribute names. * @param names An array of num_attr strings containing attribute names.
* @return 0 or an error code.
*/ */
GIT_EXTERN(int) git_attr_get_many_ext( GIT_EXTERN(int) git_attr_get_many_ext(
const char **values_out, const char **values_out,
...@@ -344,11 +348,16 @@ GIT_EXTERN(int) git_attr_cache_flush( ...@@ -344,11 +348,16 @@ GIT_EXTERN(int) git_attr_cache_flush(
* Add a macro definition. * Add a macro definition.
* *
* Macros will automatically be loaded from the top level `.gitattributes` * Macros will automatically be loaded from the top level `.gitattributes`
* file of the repository (plus the build-in "binary" macro). This * file of the repository (plus the built-in "binary" macro). This
* function allows you to add others. For example, to add the default * function allows you to add others. For example, to add the default
* macro, you would call: * macro, you would call:
* *
* git_attr_add_macro(repo, "binary", "-diff -crlf"); * git_attr_add_macro(repo, "binary", "-diff -crlf");
*
* @param repo The repository to add the macro in.
* @param name The name of the macro.
* @param values The value for the macro.
* @return 0 or an error code.
*/ */
GIT_EXTERN(int) git_attr_add_macro( GIT_EXTERN(int) git_attr_add_macro(
git_repository *repo, git_repository *repo,
......
...@@ -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;
/** /**
...@@ -203,6 +203,9 @@ typedef struct git_blame git_blame; ...@@ -203,6 +203,9 @@ typedef struct git_blame git_blame;
/** /**
* Gets the number of hunks that exist in the blame structure. * Gets the number of hunks that exist in the blame structure.
*
* @param blame The blame structure to query.
* @return The number of hunks.
*/ */
GIT_EXTERN(uint32_t) git_blame_get_hunk_count(git_blame *blame); GIT_EXTERN(uint32_t) git_blame_get_hunk_count(git_blame *blame);
......
...@@ -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;
/** /**
...@@ -285,11 +285,24 @@ GIT_EXTERN(int) git_blob_create_from_buffer( ...@@ -285,11 +285,24 @@ GIT_EXTERN(int) git_blob_create_from_buffer(
GIT_EXTERN(int) git_blob_is_binary(const git_blob *blob); GIT_EXTERN(int) git_blob_is_binary(const git_blob *blob);
/** /**
* Determine if the given content is most certainly binary or not;
* this is the same mechanism used by `git_blob_is_binary` but only
* looking at raw data.
*
* @param data The blob data which content should be analyzed
* @param len The length of the data
* @return 1 if the content of the blob is detected
* as binary; 0 otherwise.
*/
GIT_EXTERN(int) git_blob_data_is_binary(const char *data, size_t len);
/**
* Create an in-memory copy of a blob. The copy must be explicitly * Create an in-memory copy of a blob. The copy must be explicitly
* free'd or it will leak. * free'd or it will leak.
* *
* @param out Pointer to store the copy of the object * @param out Pointer to store the copy of the object
* @param source Original object to copy * @param source Original object to copy
* @return 0.
*/ */
GIT_EXTERN(int) git_blob_dup(git_blob **out, git_blob *source); GIT_EXTERN(int) git_blob_dup(git_blob **out, git_blob *source);
......
...@@ -34,6 +34,8 @@ GIT_BEGIN_DECL ...@@ -34,6 +34,8 @@ GIT_BEGIN_DECL
* *
* @param out Pointer where to store the underlying reference. * @param out Pointer where to store the underlying reference.
* *
* @param repo the repository to create the branch in.
*
* @param branch_name Name for the branch; this name is * @param branch_name Name for the branch; this name is
* validated for consistency. It should also not conflict with * validated for consistency. It should also not conflict with
* an already existing branch name. * an already existing branch name.
...@@ -127,8 +129,8 @@ GIT_EXTERN(void) git_branch_iterator_free(git_branch_iterator *iter); ...@@ -127,8 +129,8 @@ GIT_EXTERN(void) git_branch_iterator_free(git_branch_iterator *iter);
* See `git_tag_create()` for rules about valid names. * See `git_tag_create()` for rules about valid names.
* *
* Note that if the move succeeds, the old reference object will not * Note that if the move succeeds, the old reference object will not
+ be valid anymore, and should be freed immediately by the user using * be valid anymore, and should be freed immediately by the user using
+ `git_reference_free()`. * `git_reference_free()`.
* *
* @param out New reference object for the updated name. * @param out New reference object for the updated name.
* *
......
...@@ -23,110 +23,50 @@ GIT_BEGIN_DECL ...@@ -23,110 +23,50 @@ GIT_BEGIN_DECL
* *
* Sometimes libgit2 wants to return an allocated data buffer to the * Sometimes libgit2 wants to return an allocated data buffer to the
* caller and have the caller take responsibility for freeing that memory. * caller and have the caller take responsibility for freeing that memory.
* This can be awkward if the caller does not have easy access to the same * To make ownership clear in these cases, libgit2 uses `git_buf` to
* allocation functions that libgit2 is using. In those cases, libgit2 * return this data. Callers should use `git_buf_dispose()` to release
* will fill in a `git_buf` and the caller can use `git_buf_dispose()` to * the memory when they are done.
* release it when they are done.
* *
* A `git_buf` may also be used for the caller to pass in a reference to * A `git_buf` contains a pointer to a NUL-terminated C string, and
* a block of memory they hold. In this case, libgit2 will not resize or * the length of the string (not including the NUL terminator).
* free the memory, but will read from it as needed.
*
* Some APIs may occasionally do something slightly unusual with a buffer,
* such as setting `ptr` to a value that was passed in by the user. In
* those cases, the behavior will be clearly documented by the API.
*/ */
typedef struct { typedef struct {
/** /**
* The buffer contents. * The buffer contents. `ptr` points to the start of the buffer
* * being returned. The buffer's length (in bytes) is specified
* `ptr` points to the start of the allocated memory. If it is NULL, * by the `size` member of the structure, and contains a NUL
* then the `git_buf` is considered empty and libgit2 will feel free * terminator at position `(size + 1)`.
* to overwrite it with new data.
*/ */
char *ptr; char *ptr;
/** /**
* `asize` holds the known total amount of allocated memory if the `ptr` * This field is reserved and unused.
* was allocated by libgit2. It may be larger than `size`. If `ptr`
* was not allocated by libgit2 and should not be resized and/or freed,
* then `asize` will be set to zero.
*/ */
size_t asize; size_t reserved;
/** /**
* `size` holds the size (in bytes) of the data that is actually used. * The length (in bytes) of the buffer pointed to by `ptr`,
* not including a NUL terminator.
*/ */
size_t size; size_t size;
} git_buf; } git_buf;
/** /**
* Static initializer for git_buf from static buffer * Use to initialize a `git_buf` before passing it to a function that
* will populate it.
*/ */
#define GIT_BUF_INIT_CONST(STR,LEN) { (char *)(STR), 0, (size_t)(LEN) } #define GIT_BUF_INIT { NULL, 0, 0 }
/** /**
* Free the memory referred to by the git_buf. * Free the memory referred to by the git_buf.
* *
* Note that this does not free the `git_buf` itself, just the memory * Note that this does not free the `git_buf` itself, just the memory
* pointed to by `buffer->ptr`. This will not free the memory if it looks * pointed to by `buffer->ptr`.
* like it was not allocated internally, but it will clear the buffer back
* to the empty state.
* *
* @param buffer The buffer to deallocate * @param buffer The buffer to deallocate
*/ */
GIT_EXTERN(void) git_buf_dispose(git_buf *buffer); GIT_EXTERN(void) git_buf_dispose(git_buf *buffer);
/**
* Resize the buffer allocation to make more space.
*
* This will attempt to grow the buffer to accommodate the target size.
*
* If the buffer refers to memory that was not allocated by libgit2 (i.e.
* the `asize` field is zero), then `ptr` will be replaced with a newly
* allocated block of data. Be careful so that memory allocated by the
* caller is not lost. As a special variant, if you pass `target_size` as
* 0 and the memory is not allocated by libgit2, this will allocate a new
* buffer of size `size` and copy the external data into it.
*
* Currently, this will never shrink a buffer, only expand it.
*
* If the allocation fails, this will return an error and the buffer will be
* marked as invalid for future operations, invaliding the contents.
*
* @param buffer The buffer to be resized; may or may not be allocated yet
* @param target_size The desired available size
* @return 0 on success, -1 on allocation failure
*/
GIT_EXTERN(int) git_buf_grow(git_buf *buffer, size_t target_size);
/**
* Set buffer to a copy of some raw data.
*
* @param buffer The buffer to set
* @param data The data to copy into the buffer
* @param datalen The length of the data to copy into the buffer
* @return 0 on success, -1 on allocation failure
*/
GIT_EXTERN(int) git_buf_set(
git_buf *buffer, const void *data, size_t datalen);
/**
* Check quickly if buffer looks like it contains binary data
*
* @param buf Buffer to check
* @return 1 if buffer looks like non-text data
*/
GIT_EXTERN(int) git_buf_is_binary(const git_buf *buf);
/**
* Check quickly if buffer contains a NUL byte
*
* @param buf Buffer to check
* @return 1 if buffer contains a NUL byte
*/
GIT_EXTERN(int) git_buf_contains_nul(const git_buf *buf);
GIT_END_DECL GIT_END_DECL
/** @} */ /** @} */
......
...@@ -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 {
......
...@@ -182,7 +182,10 @@ typedef enum { ...@@ -182,7 +182,10 @@ typedef enum {
* notifications; don't update the working directory or index. * notifications; don't update the working directory or index.
*/ */
GIT_CHECKOUT_DRY_RUN = (1u << 24), GIT_CHECKOUT_DRY_RUN = (1u << 24),
/** Include common ancestor data in zdiff3 format for conflicts */
GIT_CHECKOUT_CONFLICT_STYLE_ZDIFF3 = (1u << 25),
/** /**
* THE FOLLOWING OPTIONS ARE NOT YET IMPLEMENTED * THE FOLLOWING OPTIONS ARE NOT YET IMPLEMENTED
*/ */
...@@ -190,7 +193,7 @@ typedef enum { ...@@ -190,7 +193,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;
/** /**
...@@ -74,8 +74,8 @@ typedef int GIT_CALLBACK(git_remote_create_cb)( ...@@ -74,8 +74,8 @@ typedef int GIT_CALLBACK(git_remote_create_cb)(
void *payload); void *payload);
/** /**
* The signature of a function matchin git_repository_init, with an * The signature of a function matching git_repository_init, with an
* aditional void * as callback payload. * additional void * as callback payload.
* *
* Callers of git_clone my provide a function matching this signature * Callers of git_clone my provide a function matching this signature
* to override the repository creation and customization process * to override the repository creation and customization process
......
...@@ -479,6 +479,7 @@ GIT_EXTERN(int) git_commit_create_buffer( ...@@ -479,6 +479,7 @@ GIT_EXTERN(int) git_commit_create_buffer(
* to the commit and write it into the given repository. * to the commit and write it into the given repository.
* *
* @param out the resulting commit id * @param out the resulting commit id
* @param repo the repository to create the commit in.
* @param commit_content the content of the unsigned commit object * @param commit_content the content of the unsigned commit object
* @param signature the signature to add to the commit. Leave `NULL` * @param signature the signature to add to the commit. Leave `NULL`
* to create a commit without adding a signature field. * to create a commit without adding a signature field.
...@@ -499,6 +500,7 @@ GIT_EXTERN(int) git_commit_create_with_signature( ...@@ -499,6 +500,7 @@ GIT_EXTERN(int) git_commit_create_with_signature(
* *
* @param out Pointer to store the copy of the commit * @param out Pointer to store the copy of the commit
* @param source Original commit to copy * @param source Original commit to copy
* @return 0
*/ */
GIT_EXTERN(int) git_commit_dup(git_commit **out, git_commit *source); GIT_EXTERN(int) git_commit_dup(git_commit **out, git_commit *source);
......
...@@ -122,6 +122,17 @@ GIT_BEGIN_DECL ...@@ -122,6 +122,17 @@ GIT_BEGIN_DECL
GIT_EXTERN(int) git_libgit2_version(int *major, int *minor, int *rev); GIT_EXTERN(int) git_libgit2_version(int *major, int *minor, int *rev);
/** /**
* Return the prerelease state of the libgit2 library currently being
* used. For nightly builds during active development, this will be
* "alpha". Releases may have a "beta" or release candidate ("rc1",
* "rc2", etc) prerelease. For a final release, this function returns
* NULL.
*
* @return the name of the prerelease state or NULL
*/
GIT_EXTERN(const char *) git_libgit2_prerelease(void);
/**
* Combinations of these values describe the features with which libgit2 * Combinations of these values describe the features with which libgit2
* was compiled * was compiled
*/ */
...@@ -147,7 +158,7 @@ typedef enum { ...@@ -147,7 +158,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;
/** /**
...@@ -167,6 +178,9 @@ typedef enum { ...@@ -167,6 +178,9 @@ typedef enum {
* - GIT_FEATURE_SSH * - GIT_FEATURE_SSH
* Libgit2 supports the SSH protocol for network operations. This requires * Libgit2 supports the SSH protocol for network operations. This requires
* the libssh2 library to be found when compiling libgit2 * the libssh2 library to be found when compiling libgit2
*
* - GIT_FEATURE_NSEC
* Libgit2 supports the sub-second resolution in file modification times.
*/ */
GIT_EXTERN(int) git_libgit2_features(void); GIT_EXTERN(int) git_libgit2_features(void);
...@@ -211,7 +225,9 @@ typedef enum { ...@@ -211,7 +225,9 @@ typedef enum {
GIT_OPT_SET_ODB_PACKED_PRIORITY, GIT_OPT_SET_ODB_PACKED_PRIORITY,
GIT_OPT_SET_ODB_LOOSE_PRIORITY, GIT_OPT_SET_ODB_LOOSE_PRIORITY,
GIT_OPT_GET_EXTENSIONS, GIT_OPT_GET_EXTENSIONS,
GIT_OPT_SET_EXTENSIONS GIT_OPT_SET_EXTENSIONS,
GIT_OPT_GET_OWNER_VALIDATION,
GIT_OPT_SET_OWNER_VALIDATION
} git_libgit2_opt_t; } git_libgit2_opt_t;
/** /**
...@@ -449,6 +465,14 @@ typedef enum { ...@@ -449,6 +465,14 @@ typedef enum {
* > to support repositories with the `noop` extension but does want * > to support repositories with the `noop` extension but does want
* > to support repositories with the `newext` extension. * > to support repositories with the `newext` extension.
* *
* opts(GIT_OPT_GET_OWNER_VALIDATION, int *enabled)
* > Gets the owner validation setting for repository
* > directories.
*
* opts(GIT_OPT_SET_OWNER_VALIDATION, int enabled)
* > Set that repository directories should be owned by the current
* > user. The default is to validate ownership.
*
* @param option Option key * @param option Option key
* @param ... value to set the option * @param ... value to set the option
* @return 0 on success, <0 on failure * @return 0 on success, <0 on failure
......
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
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