diff --git a/.github/workflows/benchmark.yml b/.github/workflows/benchmark.yml index 285c273b1..bf2167464 100644 --- a/.github/workflows/benchmark.yml +++ b/.github/workflows/benchmark.yml @@ -27,7 +27,7 @@ jobs: os: ubuntu-latest setup-script: ubuntu - name: "macOS" - os: macos-10.15 + os: macos-11 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 @@ -50,7 +50,7 @@ jobs: runs-on: ${{ matrix.platform.os }} steps: - name: Check out repository - uses: actions/checkout@v2 + uses: actions/checkout@v3 with: path: source fetch-depth: 0 @@ -66,9 +66,9 @@ jobs: - name: Benchmark run: | if [[ "$(uname -s)" == MINGW* ]]; then - GIT2_CLI="$(cygpath -w $(pwd))\\build\\Release\\git2_cli" + GIT2_CLI="$(cygpath -w $(pwd))\\build\\Release\\git2" else - GIT2_CLI="$(pwd)/build/git2_cli" + GIT2_CLI="$(pwd)/build/git2" fi mkdir benchmark && cd benchmark diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index bcad84b8b..0eedab87a 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -48,7 +48,7 @@ jobs: name: "Create container: ${{ matrix.container.name }}" steps: - name: Check out repository - uses: actions/checkout@v2 + uses: actions/checkout@v3 with: path: source fetch-depth: 0 @@ -120,52 +120,9 @@ jobs: CMAKE_OPTIONS: -DUSE_HTTPS=mbedTLS -DUSE_SHA1=HTTPS -DREGEX_BACKEND=pcre -DDEPRECATE_HARD=ON -DUSE_LEAK_CHECKER=valgrind -DUSE_GSSAPI=ON -DUSE_SSH=ON CMAKE_GENERATOR: Ninja os: ubuntu-latest - - name: "Linux (MemorySanitizer)" - id: memorysanitizer - container: - name: focal - env: - CC: clang-10 - CFLAGS: -fsanitize=memory -fsanitize-memory-track-origins=2 -fsanitize-blacklist=/home/libgit2/source/script/sanitizers.supp -fno-optimize-sibling-calls -fno-omit-frame-pointer - CMAKE_OPTIONS: -DCMAKE_PREFIX_PATH=/usr/local/msan -DUSE_HTTPS=mbedTLS -DUSE_SHA1=HTTPS -DREGEX_BACKEND=pcre -DDEPRECATE_HARD=ON -DUSE_BUNDLED_ZLIB=ON -DUSE_SSH=ON - CMAKE_GENERATOR: Ninja - SKIP_SSH_TESTS: true - SKIP_NEGOTIATE_TESTS: true - ASAN_SYMBOLIZER_PATH: /usr/bin/llvm-symbolizer-10 - UBSAN_OPTIONS: print_stacktrace=1 - os: ubuntu-latest - - name: "Linux (UndefinedBehaviorSanitizer)" - id: ubsanitizer - container: - name: focal - env: - CC: clang-10 - CFLAGS: -fsanitize=undefined,nullability -fno-sanitize-recover=undefined,nullability -fsanitize-blacklist=/home/libgit2/source/script/sanitizers.supp -fno-optimize-sibling-calls -fno-omit-frame-pointer - CMAKE_OPTIONS: -DCMAKE_PREFIX_PATH=/usr/local -DUSE_HTTPS=OpenSSL -DUSE_SHA1=HTTPS -DREGEX_BACKEND=pcre -DDEPRECATE_HARD=ON -DUSE_BUNDLED_ZLIB=ON -DUSE_SSH=ON - CMAKE_GENERATOR: Ninja - SKIP_SSH_TESTS: true - SKIP_NEGOTIATE_TESTS: true - ASAN_SYMBOLIZER_PATH: /usr/bin/llvm-symbolizer-10 - UBSAN_OPTIONS: print_stacktrace=1 - os: ubuntu-latest - - name: "Linux (ThreadSanitizer)" - id: threadsanitizer - container: - name: focal - env: - CC: clang-10 - CFLAGS: -fsanitize=thread -fno-optimize-sibling-calls -fno-omit-frame-pointer - CMAKE_OPTIONS: -DCMAKE_PREFIX_PATH=/usr/local -DUSE_HTTPS=OpenSSL -DUSE_SHA1=HTTPS -DREGEX_BACKEND=pcre -DDEPRECATE_HARD=ON -DUSE_BUNDLED_ZLIB=ON -DUSE_SSH=ON - CMAKE_GENERATOR: Ninja - SKIP_SSH_TESTS: true - SKIP_NEGOTIATE_TESTS: true - ASAN_SYMBOLIZER_PATH: /usr/bin/llvm-symbolizer-10 - UBSAN_OPTIONS: print_stacktrace=1 - TSAN_OPTIONS: suppressions=/home/libgit2/source/script/thread-sanitizer.supp second_deadlock_stack=1 - os: ubuntu-latest - name: "macOS" id: macos - os: macos-10.15 + os: macos-11 env: CC: clang CMAKE_OPTIONS: -DREGEX_BACKEND=regcomp_l -DDEPRECATE_HARD=ON -DUSE_LEAK_CHECKER=leaks -DUSE_GSSAPI=ON @@ -176,19 +133,25 @@ jobs: - name: "Windows (amd64, Visual Studio)" id: windows-amd64-vs os: windows-2019 + setup-script: win32 env: ARCH: amd64 CMAKE_GENERATOR: Visual Studio 16 2019 - CMAKE_OPTIONS: -A x64 -DWIN32_LEAKCHECK=ON -DDEPRECATE_HARD=ON + CMAKE_OPTIONS: -A x64 -DWIN32_LEAKCHECK=ON -DDEPRECATE_HARD=ON -DUSE_SSH=ON -DCMAKE_PREFIX_PATH=D:\Temp\libssh2 + BUILD_PATH: C:\Windows\system32;C:\Windows;C:\Windows\System32\Wbem;C:\Program Files (x86)\CMake\bin;D:\Temp\libssh2\bin + BUILD_TEMP: D:\Temp SKIP_SSH_TESTS: true SKIP_NEGOTIATE_TESTS: true - name: "Windows (x86, Visual Studio)" id: windows-x86-vs os: windows-2019 + setup-script: win32 env: ARCH: x86 CMAKE_GENERATOR: Visual Studio 16 2019 - CMAKE_OPTIONS: -A Win32 -DWIN32_LEAKCHECK=ON -DDEPRECATE_HARD=ON -DUSE_SHA1=HTTPS -DUSE_BUNDLED_ZLIB=ON + CMAKE_OPTIONS: -A Win32 -DWIN32_LEAKCHECK=ON -DDEPRECATE_HARD=ON -DUSE_SHA1=HTTPS -DUSE_BUNDLED_ZLIB=ON -DUSE_SSH=ON -DCMAKE_PREFIX_PATH=D:\Temp\libssh2 + BUILD_PATH: C:\Windows\system32;C:\Windows;C:\Windows\System32\Wbem;C:\Program Files (x86)\CMake\bin;D:\Temp\libssh2\bin + BUILD_TEMP: D:\Temp SKIP_SSH_TESTS: true SKIP_NEGOTIATE_TESTS: true - name: "Windows (amd64, mingw)" @@ -215,13 +178,88 @@ jobs: BUILD_PATH: D:\Temp\mingw32\bin;C:\Windows\system32;C:\Windows;C:\Windows\System32\Wbem;C:\Program Files (x86)\CMake\bin SKIP_SSH_TESTS: true SKIP_NEGOTIATE_TESTS: true + + # Sanitizers + - name: "Sanitizer (Memory)" + id: memorysanitizer + container: + name: focal + env: + CC: clang-10 + CFLAGS: -fsanitize=memory -fsanitize-memory-track-origins=2 -fsanitize-blacklist=/home/libgit2/source/script/sanitizers.supp -fno-optimize-sibling-calls -fno-omit-frame-pointer + CMAKE_OPTIONS: -DCMAKE_PREFIX_PATH=/usr/local/msan -DUSE_HTTPS=mbedTLS -DUSE_SHA1=HTTPS -DREGEX_BACKEND=pcre -DDEPRECATE_HARD=ON -DUSE_BUNDLED_ZLIB=ON -DUSE_SSH=ON + CMAKE_GENERATOR: Ninja + SKIP_SSH_TESTS: true + SKIP_NEGOTIATE_TESTS: true + ASAN_SYMBOLIZER_PATH: /usr/bin/llvm-symbolizer-10 + UBSAN_OPTIONS: print_stacktrace=1 + os: ubuntu-latest + - name: "Sanitizer (UndefinedBehavior)" + id: ubsanitizer + container: + name: focal + env: + CC: clang-10 + CFLAGS: -fsanitize=undefined,nullability -fno-sanitize-recover=undefined,nullability -fsanitize-blacklist=/home/libgit2/source/script/sanitizers.supp -fno-optimize-sibling-calls -fno-omit-frame-pointer + CMAKE_OPTIONS: -DCMAKE_PREFIX_PATH=/usr/local -DUSE_HTTPS=OpenSSL -DUSE_SHA1=HTTPS -DREGEX_BACKEND=pcre -DDEPRECATE_HARD=ON -DUSE_BUNDLED_ZLIB=ON -DUSE_SSH=ON + CMAKE_GENERATOR: Ninja + SKIP_SSH_TESTS: true + SKIP_NEGOTIATE_TESTS: true + ASAN_SYMBOLIZER_PATH: /usr/bin/llvm-symbolizer-10 + UBSAN_OPTIONS: print_stacktrace=1 + os: ubuntu-latest + - name: "Sanitizer (Thread)" + id: threadsanitizer + container: + name: focal + env: + CC: clang-10 + CFLAGS: -fsanitize=thread -fno-optimize-sibling-calls -fno-omit-frame-pointer + CMAKE_OPTIONS: -DCMAKE_PREFIX_PATH=/usr/local -DUSE_HTTPS=OpenSSL -DUSE_SHA1=HTTPS -DREGEX_BACKEND=pcre -DDEPRECATE_HARD=ON -DUSE_BUNDLED_ZLIB=ON -DUSE_SSH=ON + CMAKE_GENERATOR: Ninja + SKIP_SSH_TESTS: true + SKIP_NEGOTIATE_TESTS: true + ASAN_SYMBOLIZER_PATH: /usr/bin/llvm-symbolizer-10 + UBSAN_OPTIONS: print_stacktrace=1 + TSAN_OPTIONS: suppressions=/home/libgit2/source/script/thread-sanitizer.supp second_deadlock_stack=1 + os: ubuntu-latest + + # Experimental: SHA256 support + - name: "Linux (SHA256, Xenial, Clang, OpenSSL)" + id: xenial-clang-openssl + container: + name: xenial + env: + CC: clang + CMAKE_GENERATOR: Ninja + CMAKE_OPTIONS: -DUSE_HTTPS=OpenSSL -DDEPRECATE_HARD=ON -DUSE_LEAK_CHECKER=valgrind -DUSE_GSSAPI=ON -DUSE_SSH=ON -DEXPERIMENTAL_SHA256=ON + os: ubuntu-latest + - name: "macOS (SHA256)" + id: macos + os: macos-11 + env: + CC: clang + CMAKE_OPTIONS: -DREGEX_BACKEND=regcomp_l -DDEPRECATE_HARD=ON -DUSE_LEAK_CHECKER=leaks -DUSE_GSSAPI=ON -DEXPERIMENTAL_SHA256=ON + PKG_CONFIG_PATH: /usr/local/opt/openssl/lib/pkgconfig + SKIP_SSH_TESTS: true + SKIP_NEGOTIATE_TESTS: true + setup-script: osx + - name: "Windows (SHA256, amd64, Visual Studio)" + id: windows-amd64-vs + os: windows-2019 + env: + ARCH: amd64 + CMAKE_GENERATOR: Visual Studio 16 2019 + CMAKE_OPTIONS: -A x64 -DWIN32_LEAKCHECK=ON -DDEPRECATE_HARD=ON -DEXPERIMENTAL_SHA256=ON + SKIP_SSH_TESTS: true + SKIP_NEGOTIATE_TESTS: true fail-fast: false env: ${{ matrix.platform.env }} runs-on: ${{ matrix.platform.os }} name: "Build: ${{ matrix.platform.name }}" steps: - name: Check out repository - uses: actions/checkout@v2 + uses: actions/checkout@v3 with: path: source fetch-depth: 0 @@ -251,6 +289,10 @@ jobs: - name: Build and test run: | export GITTEST_NEGOTIATE_PASSWORD="${{ secrets.GITTEST_NEGOTIATE_PASSWORD }}" + export GITTEST_GITHUB_SSH_KEY="${{ secrets.GITTEST_GITHUB_SSH_KEY }}" + export GITTEST_GITHUB_SSH_PUBKEY="${{ secrets.GITTEST_GITHUB_SSH_PUBKEY }}" + export GITTEST_GITHUB_SSH_PASSPHRASE="${{ secrets.GITTEST_GITHUB_SSH_PASSPHRASE }}" + export GITTEST_GITHUB_SSH_REMOTE_HOSTKEY="${{ secrets.GITTEST_GITHUB_SSH_REMOTE_HOSTKEY }}" if [ -n "${{ matrix.platform.container.name }}" ]; then mkdir build @@ -291,12 +333,13 @@ jobs: test_results: name: Test results needs: [ build ] + if: always() runs-on: ubuntu-latest steps: - name: Download test results uses: actions/download-artifact@v3 - name: Generate test summary - uses: test-summary/action@v1 + uses: test-summary/action@v2 with: paths: 'test-results-*/*.xml' @@ -313,7 +356,7 @@ jobs: runs-on: ubuntu-latest steps: - name: Check out repository - uses: actions/checkout@v2 + uses: actions/checkout@v3 with: path: source fetch-depth: 0 @@ -332,7 +375,7 @@ jobs: cm doc api.docurium git checkout gh-pages zip --exclude .git/\* --exclude .gitignore --exclude .gitattributes -r api-documentation.zip . - - uses: actions/upload-artifact@v2 + - uses: actions/upload-artifact@v3 name: Upload artifact with: name: api-documentation diff --git a/.github/workflows/nightly.yml b/.github/workflows/nightly.yml index 856da28a3..5a0b7d12b 100644 --- a/.github/workflows/nightly.yml +++ b/.github/workflows/nightly.yml @@ -154,7 +154,7 @@ jobs: SKIP_SSH_TESTS: true os: ubuntu-latest - name: "macOS" - os: macos-10.15 + os: macos-11 env: CC: clang CMAKE_OPTIONS: -DREGEX_BACKEND=regcomp_l -DDEPRECATE_HARD=ON -DUSE_LEAK_CHECKER=leaks -DUSE_GSSAPI=ON @@ -265,13 +265,43 @@ jobs: RUN_INVASIVE_TESTS: true SKIP_PROXY_TESTS: true os: ubuntu-latest + + # Experimental: SHA256 support + - name: "Linux (SHA256, Xenial, Clang, OpenSSL)" + id: xenial-clang-openssl + container: + name: xenial + env: + CC: clang + CMAKE_GENERATOR: Ninja + CMAKE_OPTIONS: -DUSE_HTTPS=OpenSSL -DDEPRECATE_HARD=ON -DUSE_LEAK_CHECKER=valgrind -DUSE_GSSAPI=ON -DUSE_SSH=ON + os: ubuntu-latest + - name: "macOS (SHA256)" + id: macos + os: macos-10.15 + env: + CC: clang + CMAKE_OPTIONS: -DREGEX_BACKEND=regcomp_l -DDEPRECATE_HARD=ON -DUSE_LEAK_CHECKER=leaks -DUSE_GSSAPI=ON -DEXPERIMENTAL_SHA256=ON + PKG_CONFIG_PATH: /usr/local/opt/openssl/lib/pkgconfig + SKIP_SSH_TESTS: true + SKIP_NEGOTIATE_TESTS: true + setup-script: osx + - name: "Windows (SHA256, amd64, Visual Studio)" + id: windows-amd64-vs + os: windows-2019 + env: + ARCH: amd64 + CMAKE_GENERATOR: Visual Studio 16 2019 + CMAKE_OPTIONS: -A x64 -DWIN32_LEAKCHECK=ON -DDEPRECATE_HARD=ON -DEXPERIMENTAL_SHA256=ON + SKIP_SSH_TESTS: true + SKIP_NEGOTIATE_TESTS: true fail-fast: false - name: "Build ${{ matrix.platform.name }}" env: ${{ matrix.platform.env }} runs-on: ${{ matrix.platform.os }} + name: "Build ${{ matrix.platform.name }}" steps: - name: Check out repository - uses: actions/checkout@v2 + uses: actions/checkout@v3 with: path: source fetch-depth: 0 @@ -333,7 +363,7 @@ jobs: runs-on: ubuntu-latest steps: - name: Check out repository - uses: actions/checkout@v2 + uses: actions/checkout@v3 with: path: source fetch-depth: 0 @@ -358,13 +388,13 @@ jobs: runs-on: ubuntu-latest steps: - name: Check out repository - uses: actions/checkout@v2 + uses: actions/checkout@v3 with: fetch-depth: 0 # Initializes the CodeQL tools for scanning. - name: Initialize CodeQL - uses: github/codeql-action/init@v1 + uses: github/codeql-action/init@v2 with: languages: 'cpp' @@ -376,4 +406,4 @@ jobs: cmake --build . - name: Perform CodeQL Analysis - uses: github/codeql-action/analyze@v1 + uses: github/codeql-action/analyze@v2 diff --git a/CMakeLists.txt b/CMakeLists.txt index e76fc129a..1f2e02367 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -6,7 +6,7 @@ cmake_minimum_required(VERSION 3.5.1) -project(libgit2 VERSION "1.5.1" LANGUAGES C) +project(libgit2 VERSION "1.6.4" LANGUAGES C) # Add find modules to the path set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${PROJECT_SOURCE_DIR}/cmake") @@ -15,6 +15,9 @@ set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${PROJECT_SOURCE_DIR}/cmake") # Build options # +# Experimental features +option(EXPERIMENTAL_SHA256 "Enable experimental SHA256 support (for R&D/testing)" OFF) + # Optional subsystems option(BUILD_SHARED_LIBS "Build Shared Library (OFF for Static)" ON) option(BUILD_TESTS "Build Tests using the Clar suite" ON) @@ -107,6 +110,7 @@ include(IdeSplitSources) include(FeatureSummary) include(EnableWarnings) include(DefaultCFlags) +include(ExperimentalFeatures) # diff --git a/COPYING b/COPYING index 28226696d..25c8d8c6b 100644 --- a/COPYING +++ b/COPYING @@ -1184,3 +1184,33 @@ 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. +---------------------------------------------------------------------- + +The built-in git_fs_path_basename_r() function is based on the +Android implementation, BSD licensed: + +Copyright (C) 2008 The Android Open Source Project +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. + +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. diff --git a/README.md b/README.md index a9deaa01d..93476f9c0 100644 --- a/README.md +++ b/README.md @@ -4,8 +4,8 @@ libgit2 - the Git linkable library | 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) | -| **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.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) | +| **v1.6 branch** CI builds | [![CI Build](https://github.com/libgit2/libgit2/workflows/CI%20Build/badge.svg?branch=maint%2Fv1.6&event=push)](https://github.com/libgit2/libgit2/actions?query=workflow%3A%22CI+Build%22+event%3Apush+branch%3Amaint%2Fv1.6) | +| **v1.5 branch** CI builds | [![CI Build](https://github.com/libgit2/libgit2/workflows/CI%20Build/badge.svg?branch=maint%2Fv1.5&event=push)](https://github.com/libgit2/libgit2/actions?query=workflow%3A%22CI+Build%22+event%3Apush+branch%3Amaint%2Fv1.5) | | **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 @@ -25,8 +25,9 @@ and on Git hosting providers like [GitHub](https://github.com/), We perform the merge every time you click "merge pull request". `libgit2` is licensed under a **very permissive license** (GPLv2 with a special -Linking Exception). This basically means that you can link it (unmodified) -with any kind of software without having to release its source code. +Linking Exception). This means that you can link against the library with any +kind of software without making that software fall under the GPL. +Changes to libgit2 would still be covered under its GPL license. Additionally, the example code has been released to the public domain (see the [separate license](examples/COPYING) for more information). @@ -395,7 +396,7 @@ Here are the bindings to libgit2 that are currently available: * Pharo Smalltalk * libgit2-pharo-bindings * PHP - * php-git + * php-git2 * Python * pygit2 * R diff --git a/ci/build.sh b/ci/build.sh index 21a45af5f..80e7a61ae 100755 --- a/ci/build.sh +++ b/ci/build.sh @@ -13,16 +13,30 @@ BUILD_PATH=${BUILD_PATH:=$PATH} CMAKE=$(which cmake) CMAKE_GENERATOR=${CMAKE_GENERATOR:-Unix Makefiles} +indent() { sed "s/^/ /"; } + +cygfullpath() { + result=$(echo "${1}" | tr \; \\n | while read -r element; do + if [ "${last}" != "" ]; then echo -n ":"; fi + echo -n $(cygpath "${element}") + last="${element}" + done) + if [ "${result}" = "" ]; then exit 1; fi + echo "${result}" +} + if [[ "$(uname -s)" == MINGW* ]]; then - BUILD_PATH=$(cygpath "$BUILD_PATH") + BUILD_PATH=$(cygfullpath "${BUILD_PATH}") fi -indent() { sed "s/^/ /"; } echo "Source directory: ${SOURCE_DIR}" echo "Build directory: ${BUILD_DIR}" echo "" +echo "Platform:" +uname -s | indent + if [ "$(uname -s)" = "Darwin" ]; then echo "macOS version:" sw_vers | indent @@ -40,7 +54,7 @@ echo "Kernel version:" uname -a 2>&1 | indent echo "CMake version:" -env PATH="${BUILD_PATH}" "${CMAKE}" --version 2>&1 | indent +env PATH="${BUILD_PATH}" "${CMAKE}" --version | head -1 2>&1 | indent if test -n "${CC}"; then echo "Compiler version:" diff --git a/ci/docker/xenial b/ci/docker/xenial index f5fa5a315..578f0a962 100644 --- a/ci/docker/xenial +++ b/ci/docker/xenial @@ -7,11 +7,13 @@ RUN apt-get update && \ clang \ cmake \ curl \ + gettext \ gcc \ - git \ krb5-user \ libcurl4-gnutls-dev \ + libexpat1-dev \ libgcrypt20-dev \ + libintl-perl \ libkrb5-dev \ libpcre3-dev \ libssl-dev \ @@ -28,7 +30,17 @@ RUN apt-get update && \ && \ rm -rf /var/lib/apt/lists/* -FROM apt AS mbedtls +FROM apt AS git +RUN cd /tmp && \ + curl --location --silent --show-error https://github.com/git/git/archive/refs/tags/v2.39.1.tar.gz | \ + tar -xz && \ + cd git-2.39.1 && \ + make && \ + make prefix=/usr install && \ + cd .. && \ + rm -rf git-2.39.1 + +FROM git AS mbedtls RUN cd /tmp && \ curl --location --silent --show-error https://github.com/Mbed-TLS/mbedtls/archive/refs/tags/mbedtls-2.16.2.tar.gz | \ tar -xz && \ diff --git a/ci/setup-mingw-build.sh b/ci/setup-mingw-build.sh index 3d72b24eb..6c444f584 100755 --- a/ci/setup-mingw-build.sh +++ b/ci/setup-mingw-build.sh @@ -11,9 +11,9 @@ BUILD_TEMP=$(cygpath $BUILD_TEMP) case "$ARCH" in amd64) - MINGW_URI="https://github.com/libgit2/ci-dependencies/releases/download/2021-05-04/mingw-x86_64-8.1.0-release-win32-sjlj-rt_v6-rev0.zip";; + MINGW_URI="https://github.com/libgit2/ci-dependencies/releases/download/2023-01-23/mingw-x86_64-8.1.0-release-win32-sjlj-rt_v6-rev0.zip";; x86) - MINGW_URI="https://github.com/libgit2/ci-dependencies/releases/download/2021-05-04/mingw-i686-8.1.0-release-win32-sjlj-rt_v6-rev0.zip";; + MINGW_URI="https://github.com/libgit2/ci-dependencies/releases/download/2023-01-23/mingw-i686-8.1.0-release-win32-sjlj-rt_v6-rev0.zip";; esac if [ -z "$MINGW_URI" ]; then diff --git a/ci/setup-win32-build.sh b/ci/setup-win32-build.sh new file mode 100755 index 000000000..a8b81e5ef --- /dev/null +++ b/ci/setup-win32-build.sh @@ -0,0 +1,27 @@ +#!/bin/sh + +set -ex + +echo "##############################################################################" +echo "## Downloading libssh2" +echo "##############################################################################" + +BUILD_TEMP=${BUILD_TEMP:=$TEMP} +BUILD_TEMP=$(cygpath $BUILD_TEMP) + +case "$ARCH" in + amd64) + LIBSSH2_URI="https://github.com/libgit2/ci-dependencies/releases/download/2023-02-01/libssh2-20230201-amd64.zip";; + x86) + LIBSSH2_URI="https://github.com/libgit2/ci-dependencies/releases/download/2023-02-01-v2/libssh2-20230201-x86.zip";; +esac + +if [ -z "$LIBSSH2_URI" ]; then + echo "No URL" + exit 1 +fi + +mkdir -p "$BUILD_TEMP" + +curl -s -L "$LIBSSH2_URI" -o "$BUILD_TEMP"/libssh2-"$ARCH".zip +unzip -q "$BUILD_TEMP"/libssh2-"$ARCH".zip -d "$BUILD_TEMP" diff --git a/ci/test.sh b/ci/test.sh index 60d94caf8..c46cf0dc4 100755 --- a/ci/test.sh +++ b/ci/test.sh @@ -13,22 +13,52 @@ fi SOURCE_DIR=${SOURCE_DIR:-$( cd "$( dirname "${BASH_SOURCE[0]}" )" && dirname $( pwd ) )} BUILD_DIR=$(pwd) +BUILD_PATH=${BUILD_PATH:=$PATH} +CTEST=$(which ctest) TMPDIR=${TMPDIR:-/tmp} USER=${USER:-$(whoami)} +HOME=`mktemp -d ${TMPDIR}/home.XXXXXXXX` +export CLAR_HOMEDIR=${HOME} + SUCCESS=1 CONTINUE_ON_FAILURE=0 cleanup() { echo "Cleaning up..." - if [ ! -z "$GITDAEMON_PID" ]; then - echo "Stopping git daemon..." - kill $GITDAEMON_PID + if [ ! -z "$GIT_STANDARD_PID" ]; then + echo "Stopping git daemon (standard)..." + kill $GIT_STANDARD_PID + fi + + if [ ! -z "$GIT_NAMESPACE_PID" ]; then + echo "Stopping git daemon (namespace)..." + kill $GIT_NAMESPACE_PID + fi + + if [ ! -z "$GIT_SHA256_PID" ]; then + echo "Stopping git daemon (sha256)..." + kill $GIT_SHA256_PID + fi + + if [ ! -z "$PROXY_BASIC_PID" ]; then + echo "Stopping proxy (Basic)..." + kill $PROXY_BASIC_PID + fi + + if [ ! -z "$PROXY_NTLM_PID" ]; then + echo "Stopping proxy (NTLM)..." + kill $PROXY_NTLM_PID + fi + + if [ ! -z "$HTTP_PID" ]; then + echo "Stopping HTTP server..." + kill $HTTP_PID fi if [ ! -z "$SSHD_DIR" -a -f "${SSHD_DIR}/pid" ]; then - echo "Stopping SSH..." + echo "Stopping SSH server..." kill $(cat "${SSHD_DIR}/pid") fi @@ -52,7 +82,11 @@ run_test() { RETURN_CODE=0 - CLAR_SUMMARY="${BUILD_DIR}/results_${1}.xml" ctest -V -R "^${1}$" || RETURN_CODE=$? && true + ( + export PATH="${BUILD_PATH}" + export CLAR_SUMMARY="${BUILD_DIR}/results_${1}.xml" + "${CTEST}" -V -R "^${1}$" + ) || RETURN_CODE=$? && true if [ "$RETURN_CODE" -eq 0 ]; then FAILED=0 @@ -73,48 +107,81 @@ run_test() { fi } +indent() { sed "s/^/ /"; } + +cygfullpath() { + result=$(echo "${1}" | tr \; \\n | while read -r element; do + if [ "${last}" != "" ]; then echo -n ":"; fi + echo -n $(cygpath "${element}") + last="${element}" + done) + if [ "${result}" = "" ]; then exit 1; fi + echo "${result}" +} + +if [[ "$(uname -s)" == MINGW* ]]; then + BUILD_PATH=$(cygfullpath "$BUILD_PATH") +fi + + # Configure the test environment; run them early so that we're certain # that they're started by the time we need them. +echo "CTest version:" +env PATH="${BUILD_PATH}" "${CTEST}" --version | head -1 2>&1 | indent + +echo "" + echo "##############################################################################" echo "## Configuring test environment" echo "##############################################################################" +echo "" + if [ -z "$SKIP_GITDAEMON_TESTS" ]; then - echo "Starting git daemon..." - GITDAEMON_DIR=`mktemp -d ${TMPDIR}/gitdaemon.XXXXXXXX` - 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 & - GITDAEMON_PID=$! - disown $GITDAEMON_PID + echo "Starting git daemon (standard)..." + GIT_STANDARD_DIR=`mktemp -d ${TMPDIR}/git_standard.XXXXXXXX` + git init --bare "${GIT_STANDARD_DIR}/test.git" >/dev/null + git daemon --listen=localhost --export-all --enable=receive-pack --base-path="${GIT_STANDARD_DIR}" "${GIT_STANDARD_DIR}" 2>/dev/null & + GIT_STANDARD_PID=$! + + echo "Starting git daemon (namespace)..." + GIT_NAMESPACE_DIR=`mktemp -d ${TMPDIR}/git_namespace.XXXXXXXX` + cp -R "${SOURCE_DIR}/tests/resources/namespace.git" "${GIT_NAMESPACE_DIR}/namespace.git" + GIT_NAMESPACE="name1" git daemon --listen=localhost --port=9419 --export-all --enable=receive-pack --base-path="${GIT_NAMESPACE_DIR}" "${GIT_NAMESPACE_DIR}" & + GIT_NAMESPACE_PID=$! + + echo "Starting git daemon (sha256)..." + GIT_SHA256_DIR=`mktemp -d ${TMPDIR}/git_sha256.XXXXXXXX` + cp -R "${SOURCE_DIR}/tests/resources/testrepo_256.git" "${GIT_SHA256_DIR}/testrepo_256.git" + git daemon --listen=localhost --port=9420 --export-all --enable=receive-pack --base-path="${GIT_SHA256_DIR}" "${GIT_SHA256_DIR}" & + GIT_SHA256_PID=$! fi if [ -z "$SKIP_PROXY_TESTS" ]; then curl --location --silent --show-error https://github.com/ethomson/poxyproxy/releases/download/v0.7.0/poxyproxy-0.7.0.jar >poxyproxy.jar - echo "" echo "Starting HTTP proxy (Basic)..." java -jar poxyproxy.jar --address 127.0.0.1 --port 8080 --credentials foo:bar --auth-type basic --quiet & + PROXY_BASIC_PID=$! - echo "" echo "Starting HTTP proxy (NTLM)..." java -jar poxyproxy.jar --address 127.0.0.1 --port 8090 --credentials foo:bar --auth-type ntlm --quiet & + PROXY_NTLM_PID=$! fi if [ -z "$SKIP_NTLM_TESTS" -o -z "$SKIP_ONLINE_TESTS" ]; then curl --location --silent --show-error https://github.com/ethomson/poxygit/releases/download/v0.5.1/poxygit-0.5.1.jar >poxygit.jar - echo "" echo "Starting HTTP server..." - NTLM_DIR=`mktemp -d ${TMPDIR}/ntlm.XXXXXXXX` - git init --bare "${NTLM_DIR}/test.git" - java -jar poxygit.jar --address 127.0.0.1 --port 9000 --credentials foo:baz --quiet "${NTLM_DIR}" & + HTTP_DIR=`mktemp -d ${TMPDIR}/http.XXXXXXXX` + git init --bare "${HTTP_DIR}/test.git" + java -jar poxygit.jar --address 127.0.0.1 --port 9000 --credentials foo:baz --quiet "${HTTP_DIR}" & + HTTP_PID=$! fi if [ -z "$SKIP_SSH_TESTS" ]; then - echo "" - echo "Starting ssh daemon..." - HOME=`mktemp -d ${TMPDIR}/home.XXXXXXXX` + echo "Starting SSH server..." SSHD_DIR=`mktemp -d ${TMPDIR}/sshd.XXXXXXXX` git init --bare "${SSHD_DIR}/test.git" >/dev/null cat >"${SSHD_DIR}/sshd_config" <<-EOF @@ -219,12 +286,30 @@ fi if [ -z "$SKIP_GITDAEMON_TESTS" ]; then echo "" - echo "Running gitdaemon tests" + echo "Running gitdaemon (standard) tests" echo "" export GITTEST_REMOTE_URL="git://localhost/test.git" run_test gitdaemon unset GITTEST_REMOTE_URL + + echo "" + echo "Running gitdaemon (namespace) tests" + echo "" + + export GITTEST_REMOTE_URL="git://localhost:9419/namespace.git" + export GITTEST_REMOTE_BRANCH="four" + run_test gitdaemon_namespace + unset GITTEST_REMOTE_URL + unset GITTEST_REMOTE_BRANCH + + echo "" + echo "Running gitdaemon (sha256) tests" + echo "" + + export GITTEST_REMOTE_URL="git://localhost:9420/testrepo_256.git" + run_test gitdaemon_sha256 + unset GITTEST_REMOTE_URL fi if [ -z "$SKIP_PROXY_TESTS" ]; then @@ -348,7 +433,7 @@ if [ -z "$SKIP_FUZZERS" ]; then echo "## Running fuzzers" echo "##############################################################################" - ctest -V -R 'fuzzer' + env PATH="${BUILD_PATH}" "${CTEST}" -V -R 'fuzzer' fi cleanup diff --git a/cmake/ExperimentalFeatures.cmake b/cmake/ExperimentalFeatures.cmake new file mode 100644 index 000000000..7eff40bdb --- /dev/null +++ b/cmake/ExperimentalFeatures.cmake @@ -0,0 +1,23 @@ +# Experimental feature support for libgit2 - developers can opt in to +# experimental functionality, like sha256 support. When experimental +# functionality is enabled, we set both a cmake flag *and* a compile +# definition. The cmake flag is used to generate `experimental.h`, +# which will be installed by a `make install`. But the compile definition +# is used by the libgit2 sources to detect the functionality at library +# build time. This allows us to have an in-tree `experimental.h` with +# *no* experiments enabled. This lets us support users who build without +# cmake and cannot generate the `experimental.h` file. + +if(EXPERIMENTAL_SHA256) + add_feature_info("SHA256 API" ON "experimental SHA256 APIs") + + set(EXPERIMENTAL 1) + set(GIT_EXPERIMENTAL_SHA256 1) + add_definitions(-DGIT_EXPERIMENTAL_SHA256=1) +else() + add_feature_info("SHA256 API" OFF "experimental SHA256 APIs") +endif() + +if(EXPERIMENTAL) + set(LIBGIT2_FILENAME "${LIBGIT2_FILENAME}-experimental") +endif() diff --git a/docs/changelog.md b/docs/changelog.md index 448a8a0ff..d970b48e9 100644 --- a/docs/changelog.md +++ b/docs/changelog.md @@ -1,13 +1,154 @@ -v1.5.1 +v1.6.4 ------ -🔒 This is a security release to address CVE-2023-22742: when compiled using the optional, included libssh2 backend, libgit2 fails to verify SSH keys by default. +## What's Changed -When using an SSH remote with the optional, included libssh2 backend, libgit2 does not perform certificate checking by default. Prior versions of libgit2 require the caller to set the `certificate_check` field of libgit2's `git_remote_callbacks` structure - if a certificate check callback is not set, libgit2 does not perform any certificate checking. This means that by default - without configuring a certificate check callback, clients will not perform validation on the server SSH keys and may be subject to a man-in-the-middle attack. +### Bug fixes +* config: return `GIT_ENOTFOUND` for missing programdata by @ethomson in https://github.com/libgit2/libgit2/pull/6547 -The libgit2 security team would like to thank the Julia and Rust security teams for responsibly disclosing this vulnerability and assisting with fixing the vulnerability. +**Full Changelog**: https://github.com/libgit2/libgit2/compare/v1.6.3...v1.6.4 -All users of the v1.5 release line are recommended to upgrade. +v1.6.3 +------ + +## What's Changed + +### Bug fixes + +* odb: restore `git_odb_open` by @ethomson in https://github.com/libgit2/libgit2/pull/6520 +* Ensure that `git_index_add_all` handles ignored directories by @ethomson in https://github.com/libgit2/libgit2/pull/6521 +* pack: use 64 bits for the number of objects by @carlosmn in https://github.com/libgit2/libgit2/pull/6530 + +### Build and CI improvements + +* Remove unused wditer variable by @georgthegreat in https://github.com/libgit2/libgit2/pull/6518 +* fs_path: let root run the ownership tests by @ethomson in https://github.com/libgit2/libgit2/pull/6513 +* sysdir: Do not declare win32 functions on non-win32 platforms by @Batchyx in https://github.com/libgit2/libgit2/pull/6527 +* cmake: don't include `include/git2` by @ethomson in https://github.com/libgit2/libgit2/pull/6529 + +## New Contributors +* @georgthegreat made their first contribution in https://github.com/libgit2/libgit2/pull/6518 + +**Full Changelog**: https://github.com/libgit2/libgit2/compare/v1.6.2...v1.6.3 + +v1.6.2 +------ + +## What's Changed +### Bug fixes + +* remote: always populate old id in update tips by @ethomson in https://github.com/libgit2/libgit2/pull/6506 + The update tips callback would not always be properly provided with an empty (`0000000...`) OID for new refs. + +* Revert #6503 by @ethomson in https://github.com/libgit2/libgit2/pull/6511 + The certificate callback added port information for callbacks in #6503, but the format was ambiguous with IPv6 addresses. Revert this change temporarily. + +* Add `git_odb_backend_loose` back by @ethomson in https://github.com/libgit2/libgit2/pull/6512 + During SHA256 refactoring, the `git_odb_backend_loose` API was accidentally removed. Add it back. + +* meta: configure pkg-config .pc correctly by @ethomson in https://github.com/libgit2/libgit2/pull/6514 + During SHA256 refactoring, the pkg-config `.pc` file was erroneously renamed to `git2` instead of `libgit2`. Repair this. + +**Full Changelog**: https://github.com/libgit2/libgit2/compare/v1.6.1...v1.6.2 + +v1.6 +---- + +This is release v1.6.1, "Hubbeliges Krokodil". This release adds experimental SHA256 support and includes many new features and bugfixes. This release replaces libgit2 v1.6.0, which did not correctly update its version number(s). + +## What's Changed + +### New features + +* **Support for bare repositories with SHA256 support (experimental)** by @ethomson in https://github.com/libgit2/libgit2/pull/6191 + You can configure experimental SHA256 support in libgit2 with `cmake -DEXPERIMENTAL_SHA256=ON` during project setup. This is useful for considering future integrations, work on clients, and work on language bindings. At present, working with bare repositories should largely work, including remote operations. But many pieces of functionality - including working with the index - are not yet supported. As a result, **libgit2 with SHA256 support should not be used in production or released with package distribution.** + +* **Support the notion of a home directory separately from global configuration directory** by @ethomson in https://github.com/libgit2/libgit2/pull/6455 and https://github.com/libgit2/libgit2/pull/6456 + Callers and language bindings can now configure the home directory that libgit2 uses for file lookups (eg, the `.ssh` directory). This configuration is separate from the git global configuration path. + +* **stash: partial stash specific files** by @gitkraken-jacobw in https://github.com/libgit2/libgit2/pull/6330 + A stash can be created with only specific files, using a pathspec. This is similar to the `git stash push` command. + +* **push: revparse refspec source, so you can push things that are not refs** by @sven-of-cord in https://github.com/libgit2/libgit2/pull/6362 + Pushes can be performed using refspecs instead of only references. + +* **Support OpenSSL3** by @ethomson in https://github.com/libgit2/libgit2/pull/6464 and https://github.com/libgit2/libgit2/pull/6471 + OpenSSL 3 is now supported, both when compiled directly and dynamically loaded. + +### Bug fixes +* winhttp: support long custom headers by @kcsaul in https://github.com/libgit2/libgit2/pull/6363 +* Fix memory leak by @csware in https://github.com/libgit2/libgit2/pull/6382 +* Don't fail the whole clone if you can't find a default branch by @torvalds in https://github.com/libgit2/libgit2/pull/6369 +* #6366: When a worktree is missing, return `GIT_ENOTFOUND`. by @arroz in https://github.com/libgit2/libgit2/pull/6395 +* commit-graph: only verify csum on `git_commit_graph_open()`. by @derrickstolee in https://github.com/libgit2/libgit2/pull/6420 +* Ignore missing 'safe.directory' config during ownership checks by @kcsaul in https://github.com/libgit2/libgit2/pull/6408 +* Fix leak in `git_tag_create_from_buffer` by @julianmesa-gitkraken in https://github.com/libgit2/libgit2/pull/6421 +* http: Update httpclient options when reusing an existing connection. by @slackner in https://github.com/libgit2/libgit2/pull/6416 +* Add support for `safe.directory *` by @csware in https://github.com/libgit2/libgit2/pull/6429 +* URL parsing for google-compatible URLs by @ethomson in https://github.com/libgit2/libgit2/pull/6326 +* Fixes #6433: `git_submodule_update` fails to update configured but missing submodule by @tagesuhu in https://github.com/libgit2/libgit2/pull/6434 +* transport: fix capabilities calculation by @russell in https://github.com/libgit2/libgit2/pull/6435 +* push: use resolved oid as the source by @ethomson in https://github.com/libgit2/libgit2/pull/6452 +* Use `git_clone__submodule` to avoid file checks in workdir by @abizjak in https://github.com/libgit2/libgit2/pull/6444 +* #6422: handle dangling symbolic refs gracefully by @arroz in https://github.com/libgit2/libgit2/pull/6423 +* `diff_file`: Fix crash when freeing a patch representing an empty untracked file by @jorio in https://github.com/libgit2/libgit2/pull/6475 +* clone: clean up options on failure by @ethomson in https://github.com/libgit2/libgit2/pull/6479 +* stash: update strarray usage by @ethomson in https://github.com/libgit2/libgit2/pull/6487 +* #6491: Sets `oid_type` on repos open with `git_repository_open_bare` by @arroz in https://github.com/libgit2/libgit2/pull/6492 +* Handle Win32 shares by @ethomson in https://github.com/libgit2/libgit2/pull/6493 +* Make failure to connect to ssh-agent non-fatal by @fxcoudert in https://github.com/libgit2/libgit2/pull/6497 +* odb: don't unconditionally add `oid_type` to stream by @ethomson in https://github.com/libgit2/libgit2/pull/6499 +* Pass hostkey & port to host verify callback by @fxcoudert in https://github.com/libgit2/libgit2/pull/6503 + +### Code cleanups +* meta: update version number to v1.6.0-alpha by @ethomson in https://github.com/libgit2/libgit2/pull/6352 +* sha256: indirection for experimental functions by @ethomson in https://github.com/libgit2/libgit2/pull/6354 +* Delete `create.c.bak` by @lrm29 in https://github.com/libgit2/libgit2/pull/6398 +* Support non-cmake builds with an in-tree `experimental.h` by @ethomson in https://github.com/libgit2/libgit2/pull/6405 + +### Build and CI improvements +* tests: skip flaky-ass googlesource tests by @ethomson in https://github.com/libgit2/libgit2/pull/6353 +* clar: remove ftrunacte from libgit2 tests by @boretrk in https://github.com/libgit2/libgit2/pull/6357 +* CI Improvements by @ethomson in https://github.com/libgit2/libgit2/pull/6403 +* fix compile on Windows with `-DWIN32_LEAN_AND_MEAN` by @christoph-cullmann in https://github.com/libgit2/libgit2/pull/6373 +* Fixes #6365 : Uppercase windows.h include fails build in case-sensitive OS by @Vinz2008 in https://github.com/libgit2/libgit2/pull/6377 +* ci: update version numbers of actions by @ethomson in https://github.com/libgit2/libgit2/pull/6448 +* thread: avoid warnings when building without threads by @ethomson in https://github.com/libgit2/libgit2/pull/6432 +* src: hide unused hmac() prototype by @0-wiz-0 in https://github.com/libgit2/libgit2/pull/6458 +* tests: update clar test runner by @ethomson in https://github.com/libgit2/libgit2/pull/6459 +* ci: always create test summaries, even on failure by @ethomson in https://github.com/libgit2/libgit2/pull/6460 +* Fix build failure with `-DEMBED_SSH_PATH` by @vicr123 in https://github.com/libgit2/libgit2/pull/6374 +* Define correct `off64_t` for AIX by @bzEq in https://github.com/libgit2/libgit2/pull/6376 +* Fix some warnings in main by @ethomson in https://github.com/libgit2/libgit2/pull/6480 +* strarray: remove deprecated declaration by @ethomson in https://github.com/libgit2/libgit2/pull/6486 +* tests: always unset `HTTP_PROXY` before starting tests by @ethomson in https://github.com/libgit2/libgit2/pull/6498 + +### Documentation improvements +* add 2-clause BSD license to COPYING by @martinvonz in https://github.com/libgit2/libgit2/pull/6413 +* Add new PHP bindings project to language bindings section of README.md by @RogerGee in https://github.com/libgit2/libgit2/pull/6473 +* README: clarify the linking exception by @ethomson in https://github.com/libgit2/libgit2/pull/6494 +* Correct the definition of "empty" in the docs for `git_repository_is_empty` by @timrogers in https://github.com/libgit2/libgit2/pull/6500 + +## New Contributors +* @christoph-cullmann made their first contribution in https://github.com/libgit2/libgit2/pull/6373 +* @Vinz2008 made their first contribution in https://github.com/libgit2/libgit2/pull/6377 +* @torvalds made their first contribution in https://github.com/libgit2/libgit2/pull/6369 +* @derrickstolee made their first contribution in https://github.com/libgit2/libgit2/pull/6420 +* @julianmesa-gitkraken made their first contribution in https://github.com/libgit2/libgit2/pull/6421 +* @slackner made their first contribution in https://github.com/libgit2/libgit2/pull/6416 +* @martinvonz made their first contribution in https://github.com/libgit2/libgit2/pull/6413 +* @tagesuhu made their first contribution in https://github.com/libgit2/libgit2/pull/6434 +* @russell made their first contribution in https://github.com/libgit2/libgit2/pull/6435 +* @sven-of-cord made their first contribution in https://github.com/libgit2/libgit2/pull/6362 +* @0-wiz-0 made their first contribution in https://github.com/libgit2/libgit2/pull/6458 +* @abizjak made their first contribution in https://github.com/libgit2/libgit2/pull/6444 +* @vicr123 made their first contribution in https://github.com/libgit2/libgit2/pull/6374 +* @bzEq made their first contribution in https://github.com/libgit2/libgit2/pull/6376 +* @gitkraken-jacobw made their first contribution in https://github.com/libgit2/libgit2/pull/6330 +* @fxcoudert made their first contribution in https://github.com/libgit2/libgit2/pull/6497 +* @timrogers made their first contribution in https://github.com/libgit2/libgit2/pull/6500 + +**Full Changelog**: https://github.com/libgit2/libgit2/compare/v1.5.0...v1.6.0 v1.5 ---- diff --git a/examples/cat-file.c b/examples/cat-file.c index b81e9a8da..741edb484 100644 --- a/examples/cat-file.c +++ b/examples/cat-file.c @@ -49,7 +49,7 @@ static void show_blob(const git_blob *blob) static void show_tree(const git_tree *tree) { size_t i, max_i = (int)git_tree_entrycount(tree); - char oidstr[GIT_OID_HEXSZ + 1]; + char oidstr[GIT_OID_SHA1_HEXSIZE + 1]; const git_tree_entry *te; for (i = 0; i < max_i; ++i) { @@ -70,7 +70,7 @@ static void show_tree(const git_tree *tree) static void show_commit(const git_commit *commit) { unsigned int i, max_i; - char oidstr[GIT_OID_HEXSZ + 1]; + char oidstr[GIT_OID_SHA1_HEXSIZE + 1]; git_oid_tostr(oidstr, sizeof(oidstr), git_commit_tree_id(commit)); printf("tree %s\n", oidstr); @@ -90,7 +90,7 @@ static void show_commit(const git_commit *commit) static void show_tag(const git_tag *tag) { - char oidstr[GIT_OID_HEXSZ + 1]; + char oidstr[GIT_OID_SHA1_HEXSIZE + 1]; git_oid_tostr(oidstr, sizeof(oidstr), git_tag_target_id(tag));; printf("object %s\n", oidstr); @@ -125,7 +125,7 @@ int lg2_cat_file(git_repository *repo, int argc, char *argv[]) { struct catfile_options o = { ".", NULL, 0, 0 }; git_object *obj = NULL; - char oidstr[GIT_OID_HEXSZ + 1]; + char oidstr[GIT_OID_SHA1_HEXSIZE + 1]; parse_opts(&o, argc, argv); @@ -133,7 +133,7 @@ int lg2_cat_file(git_repository *repo, int argc, char *argv[]) "Could not resolve", o.rev); if (o.verbose) { - char oidstr[GIT_OID_HEXSZ + 1]; + char oidstr[GIT_OID_SHA1_HEXSIZE + 1]; git_oid_tostr(oidstr, sizeof(oidstr), git_object_id(obj)); printf("%s %s\n--\n", diff --git a/examples/fetch.c b/examples/fetch.c index 2b5ed1112..bbd882cfb 100644 --- a/examples/fetch.c +++ b/examples/fetch.c @@ -15,17 +15,17 @@ static int progress_cb(const char *str, int len, void *data) */ static int update_cb(const char *refname, const git_oid *a, const git_oid *b, void *data) { - char a_str[GIT_OID_HEXSZ+1], b_str[GIT_OID_HEXSZ+1]; + char a_str[GIT_OID_SHA1_HEXSIZE+1], b_str[GIT_OID_SHA1_HEXSIZE+1]; (void)data; git_oid_fmt(b_str, b); - b_str[GIT_OID_HEXSZ] = '\0'; + b_str[GIT_OID_SHA1_HEXSIZE] = '\0'; if (git_oid_is_zero(a)) { printf("[new] %.20s %s\n", b_str, refname); } else { git_oid_fmt(a_str, a); - a_str[GIT_OID_HEXSZ] = '\0'; + a_str[GIT_OID_SHA1_HEXSIZE] = '\0'; printf("[updated] %.10s..%.10s %s\n", a_str, b_str, refname); } diff --git a/examples/for-each-ref.c b/examples/for-each-ref.c index 020dab474..a0706741a 100644 --- a/examples/for-each-ref.c +++ b/examples/for-each-ref.c @@ -5,7 +5,7 @@ static int show_ref(git_reference *ref, void *data) { git_repository *repo = data; git_reference *resolved = NULL; - char hex[GIT_OID_HEXSZ+1]; + char hex[GIT_OID_SHA1_HEXSIZE+1]; const git_oid *oid; git_object *obj; @@ -16,7 +16,7 @@ static int show_ref(git_reference *ref, void *data) oid = git_reference_target(resolved ? resolved : ref); git_oid_fmt(hex, oid); - hex[GIT_OID_HEXSZ] = 0; + hex[GIT_OID_SHA1_HEXSIZE] = 0; check_lg2(git_object_lookup(&obj, repo, oid, GIT_OBJECT_ANY), "Unable to lookup object", hex); diff --git a/examples/general.c b/examples/general.c index 2127ec0e1..7f44cd786 100644 --- a/examples/general.c +++ b/examples/general.c @@ -129,7 +129,7 @@ int lg2_general(git_repository *repo, int argc, char** argv) */ static void oid_parsing(git_oid *oid) { - char out[GIT_OID_HEXSZ+1]; + char out[GIT_OID_SHA1_HEXSIZE+1]; char hex[] = "4a202b346bb0fb0db7eff3cffeb3c70babbd2045"; printf("*Hex to Raw*\n"); @@ -142,7 +142,11 @@ static void oid_parsing(git_oid *oid) * this throughout the example for storing the value of the current SHA * key we're working with. */ +#ifdef GIT_EXPERIMENTAL_SHA256 + git_oid_fromstr(oid, hex, GIT_OID_SHA1); +#else git_oid_fromstr(oid, hex); +#endif /* * Once we've converted the string into the oid value, we can get the raw @@ -152,7 +156,7 @@ static void oid_parsing(git_oid *oid) * char hex value. */ printf("\n*Raw to Hex*\n"); - out[GIT_OID_HEXSZ] = '\0'; + out[GIT_OID_SHA1_HEXSIZE] = '\0'; /** * If you have a oid, you can easily get the hex value of the SHA as well. @@ -173,7 +177,7 @@ static void oid_parsing(git_oid *oid) */ static void object_database(git_repository *repo, git_oid *oid) { - char oid_hex[GIT_OID_HEXSZ+1] = { 0 }; + char oid_hex[GIT_OID_SHA1_HEXSIZE+1] = { 0 }; const unsigned char *data; const char *str_type; int error; @@ -266,7 +270,7 @@ static void commit_writing(git_repository *repo) git_tree *tree; git_commit *parent; git_signature *author, *committer; - char oid_hex[GIT_OID_HEXSZ+1] = { 0 }; + char oid_hex[GIT_OID_SHA1_HEXSIZE+1] = { 0 }; printf("\n*Commit Writing*\n"); @@ -287,9 +291,14 @@ static void commit_writing(git_repository *repo) * parents. Here we're creating oid objects to create the commit with, * but you can also use */ +#ifdef GIT_EXPERIMENTAL_SHA256 + git_oid_fromstr(&tree_id, "f60079018b664e4e79329a7ef9559c8d9e0378d1", GIT_OID_SHA1); + git_oid_fromstr(&parent_id, "5b5b025afb0b4c913b4c338a42934a3863bf3644", GIT_OID_SHA1); +#else git_oid_fromstr(&tree_id, "f60079018b664e4e79329a7ef9559c8d9e0378d1"); - git_tree_lookup(&tree, repo, &tree_id); git_oid_fromstr(&parent_id, "5b5b025afb0b4c913b4c338a42934a3863bf3644"); +#endif + git_tree_lookup(&tree, repo, &tree_id); git_commit_lookup(&parent, repo, &parent_id); /** @@ -345,7 +354,7 @@ static void commit_parsing(git_repository *repo) const git_signature *author, *cmtter; git_commit *commit, *parent; git_oid oid; - char oid_hex[GIT_OID_HEXSZ+1]; + char oid_hex[GIT_OID_SHA1_HEXSIZE+1]; const char *message; unsigned int parents, p; int error; @@ -353,7 +362,11 @@ static void commit_parsing(git_repository *repo) printf("\n*Commit Parsing*\n"); +#ifdef GIT_EXPERIMENTAL_SHA256 + git_oid_fromstr(&oid, "8496071c1b46c854b31185ea97743be6a8774479", GIT_OID_SHA1); +#else git_oid_fromstr(&oid, "8496071c1b46c854b31185ea97743be6a8774479"); +#endif error = git_commit_lookup(&commit, repo, &oid); check_error(error, "looking up commit"); @@ -422,7 +435,11 @@ static void tag_parsing(git_repository *repo) * We create an oid for the tag object if we know the SHA and look it up * the same way that we would a commit (or any other object). */ +#ifdef GIT_EXPERIMENTAL_SHA256 + git_oid_fromstr(&oid, "b25fa35b38051e4ae45d4222e795f9df2e43f1d1", GIT_OID_SHA1); +#else git_oid_fromstr(&oid, "b25fa35b38051e4ae45d4222e795f9df2e43f1d1"); +#endif error = git_tag_lookup(&tag, repo, &oid); check_error(error, "looking up tag"); @@ -470,7 +487,11 @@ static void tree_parsing(git_repository *repo) /** * Create the oid and lookup the tree object just like the other objects. */ +#ifdef GIT_EXPERIMENTAL_SHA256 + git_oid_fromstr(&oid, "f60079018b664e4e79329a7ef9559c8d9e0378d1", GIT_OID_SHA1); +#else git_oid_fromstr(&oid, "f60079018b664e4e79329a7ef9559c8d9e0378d1"); +#endif git_tree_lookup(&tree, repo, &oid); /** @@ -524,7 +545,11 @@ static void blob_parsing(git_repository *repo) printf("\n*Blob Parsing*\n"); +#ifdef GIT_EXPERIMENTAL_SHA256 + git_oid_fromstr(&oid, "1385f264afb75a56a5bec74243be9b367ba4ca08", GIT_OID_SHA1); +#else git_oid_fromstr(&oid, "1385f264afb75a56a5bec74243be9b367ba4ca08"); +#endif git_blob_lookup(&blob, repo, &oid); /** @@ -566,7 +591,11 @@ static void revwalking(git_repository *repo) printf("\n*Revwalking*\n"); +#ifdef GIT_EXPERIMENTAL_SHA256 + git_oid_fromstr(&oid, "5b5b025afb0b4c913b4c338a42934a3863bf3644", GIT_OID_SHA1); +#else git_oid_fromstr(&oid, "5b5b025afb0b4c913b4c338a42934a3863bf3644"); +#endif /** * To use the revwalker, create a new walker, tell it how you want to sort @@ -679,7 +708,7 @@ static void reference_listing(git_repository *repo) for (i = 0; i < ref_list.count; ++i) { git_reference *ref; - char oid_hex[GIT_OID_HEXSZ+1] = GIT_OID_HEX_ZERO; + char oid_hex[GIT_OID_SHA1_HEXSIZE+1] = GIT_OID_SHA1_HEXZERO; const char *refname; refname = ref_list.strings[i]; diff --git a/examples/index-pack.c b/examples/index-pack.c index df37dd0c4..0f8234c75 100644 --- a/examples/index-pack.c +++ b/examples/index-pack.c @@ -28,11 +28,18 @@ int lg2_index_pack(git_repository *repo, int argc, char **argv) return EXIT_FAILURE; } - if (git_indexer_new(&idx, ".", 0, NULL, NULL) < 0) { +#ifdef GIT_EXPERIMENTAL_SHA256 + error = git_indexer_new(&idx, ".", git_repository_oid_type(repo), NULL); +#else + error = git_indexer_new(&idx, ".", 0, NULL, NULL); +#endif + + if (error < 0) { puts("bad idx"); return -1; } + if ((fd = open(argv[1], 0)) < 0) { perror("open"); return -1; diff --git a/examples/log.c b/examples/log.c index 9060f3f3e..4b0a95dcd 100644 --- a/examples/log.c +++ b/examples/log.c @@ -329,7 +329,7 @@ static void print_time(const git_time *intime, const char *prefix) /** Helper to print a commit object. */ static void print_commit(git_commit *commit, struct log_options *opts) { - char buf[GIT_OID_HEXSZ + 1]; + char buf[GIT_OID_SHA1_HEXSIZE + 1]; int i, count; const git_signature *sig; const char *scan, *eol; diff --git a/examples/ls-remote.c b/examples/ls-remote.c index 03ed887d1..24caae712 100644 --- a/examples/ls-remote.c +++ b/examples/ls-remote.c @@ -34,7 +34,7 @@ static int use_remote(git_repository *repo, char *name) goto cleanup; for (i = 0; i < refs_len; i++) { - char oid[GIT_OID_HEXSZ + 1] = {0}; + char oid[GIT_OID_SHA1_HEXSIZE + 1] = {0}; git_oid_fmt(oid, &refs[i]->oid); printf("%s\t%s\n", oid, refs[i]->name); } diff --git a/examples/rev-list.c b/examples/rev-list.c index d10f16690..cf8ac30c6 100644 --- a/examples/rev-list.c +++ b/examples/rev-list.c @@ -26,7 +26,7 @@ int lg2_rev_list(git_repository *repo, int argc, char **argv) git_revwalk *walk; git_oid oid; git_sort_t sort; - char buf[GIT_OID_HEXSZ+1]; + char buf[GIT_OID_SHA1_HEXSIZE+1]; check_lg2(revwalk_parse_options(&sort, &args), "parsing options", NULL); @@ -36,7 +36,7 @@ int lg2_rev_list(git_repository *repo, int argc, char **argv) while (!git_revwalk_next(&oid, walk)) { git_oid_fmt(buf, &oid); - buf[GIT_OID_HEXSZ] = '\0'; + buf[GIT_OID_SHA1_HEXSIZE] = '\0'; printf("%s\n", buf); } @@ -140,8 +140,14 @@ static int revwalk_parse_revs(git_repository *repo, git_revwalk *walk, struct ar if (push_spec(repo, walk, curr, hide) == 0) continue; +#ifdef GIT_EXPERIMENTAL_SHA256 + if ((error = git_oid_fromstr(&oid, curr, GIT_OID_SHA1))) + return error; +#else if ((error = git_oid_fromstr(&oid, curr))) return error; +#endif + if ((error = push_commit(walk, &oid, hide))) return error; } diff --git a/examples/rev-parse.c b/examples/rev-parse.c index 90258c101..3f68d79b7 100644 --- a/examples/rev-parse.c +++ b/examples/rev-parse.c @@ -65,7 +65,7 @@ static void parse_opts(struct parse_state *ps, int argc, char *argv[]) static int parse_revision(git_repository *repo, struct parse_state *ps) { git_revspec rs; - char str[GIT_OID_HEXSZ + 1]; + char str[GIT_OID_SHA1_HEXSIZE + 1]; check_lg2(git_revparse(&rs, repo, ps->spec), "Could not parse", ps->spec); diff --git a/examples/show-index.c b/examples/show-index.c index 7aaa45e65..fb797e04b 100644 --- a/examples/show-index.c +++ b/examples/show-index.c @@ -20,8 +20,8 @@ int lg2_show_index(git_repository *repo, int argc, char **argv) size_t i, ecount; char *dir = "."; size_t dirlen; - char out[GIT_OID_HEXSZ+1]; - out[GIT_OID_HEXSZ] = '\0'; + char out[GIT_OID_SHA1_HEXSIZE+1]; + out[GIT_OID_SHA1_HEXSIZE] = '\0'; if (argc > 2) fatal("usage: showindex []", NULL); diff --git a/fuzzers/commit_graph_fuzzer.c b/fuzzers/commit_graph_fuzzer.c index 1c46d78c7..9c1443e52 100644 --- a/fuzzers/commit_graph_fuzzer.c +++ b/fuzzers/commit_graph_fuzzer.c @@ -37,7 +37,7 @@ int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size) git_commit_graph_entry e; git_str commit_graph_buf = GIT_STR_INIT; unsigned char hash[GIT_HASH_SHA1_SIZE]; - git_oid oid = {{0}}; + git_oid oid = GIT_OID_NONE; bool append_hash = false; if (size < 4) @@ -62,7 +62,7 @@ int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size) memcpy(commit_graph_buf.ptr, data, size); memcpy(commit_graph_buf.ptr + size, hash, GIT_HASH_SHA1_SIZE); - memcpy(oid.id, hash, GIT_OID_RAWSZ); + memcpy(oid.id, hash, GIT_OID_SHA1_SIZE); } else { git_str_attach_notowned(&commit_graph_buf, (char *)data, size); } @@ -75,7 +75,7 @@ int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size) goto cleanup; /* Search for any oid, just to exercise that codepath. */ - if (git_commit_graph_entry_find(&e, &file, &oid, GIT_OID_HEXSZ) < 0) + if (git_commit_graph_entry_find(&e, &file, &oid, GIT_OID_SHA1_HEXSIZE) < 0) goto cleanup; cleanup: diff --git a/fuzzers/midx_fuzzer.c b/fuzzers/midx_fuzzer.c index 4c3124e47..21fb90361 100644 --- a/fuzzers/midx_fuzzer.c +++ b/fuzzers/midx_fuzzer.c @@ -36,7 +36,7 @@ int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size) git_midx_entry e; git_str midx_buf = GIT_STR_INIT; unsigned char hash[GIT_HASH_SHA1_SIZE]; - git_oid oid = {{0}}; + git_oid oid = GIT_OID_NONE; bool append_hash = false; if (size < 4) @@ -61,7 +61,7 @@ int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size) memcpy(midx_buf.ptr, data, size); memcpy(midx_buf.ptr + size, hash, GIT_HASH_SHA1_SIZE); - memcpy(oid.id, hash, GIT_OID_RAWSZ); + memcpy(oid.id, hash, GIT_OID_SHA1_SIZE); } else { git_str_attach_notowned(&midx_buf, (char *)data, size); } @@ -70,7 +70,7 @@ int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size) goto cleanup; /* Search for any oid, just to exercise that codepath. */ - if (git_midx_entry_find(&e, &idx, &oid, GIT_OID_HEXSZ) < 0) + if (git_midx_entry_find(&e, &idx, &oid, GIT_OID_SHA1_HEXSIZE) < 0) goto cleanup; cleanup: diff --git a/fuzzers/objects_fuzzer.c b/fuzzers/objects_fuzzer.c index 51b4a1ed4..7294e9b35 100644 --- a/fuzzers/objects_fuzzer.c +++ b/fuzzers/objects_fuzzer.c @@ -39,7 +39,7 @@ int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size) * to do. */ for (i = 0; i < ARRAY_SIZE(types); i++) { - if (git_object__from_raw(&object, (const char *) data, size, types[i]) < 0) + if (git_object__from_raw(&object, (const char *) data, size, types[i], GIT_OID_SHA1) < 0) continue; git_object_free(object); object = NULL; diff --git a/fuzzers/packfile_fuzzer.c b/fuzzers/packfile_fuzzer.c index 23ecaf80f..aeba9575c 100644 --- a/fuzzers/packfile_fuzzer.c +++ b/fuzzers/packfile_fuzzer.c @@ -36,10 +36,19 @@ int LLVMFuzzerInitialize(int *argc, char ***argv) fprintf(stderr, "Failed to limit maximum pack object count\n"); abort(); } + +#ifdef GIT_EXPERIMENTAL_SHA256 + if (git_odb_new(&odb, NULL) < 0) { + fprintf(stderr, "Failed to create the odb\n"); + abort(); + } +#else if (git_odb_new(&odb) < 0) { fprintf(stderr, "Failed to create the odb\n"); abort(); } +#endif + if (git_mempack_new(&mempack) < 0) { fprintf(stderr, "Failed to create the mempack\n"); abort(); @@ -58,6 +67,7 @@ int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size) git_str path = GIT_STR_INIT; git_oid oid; bool append_hash = false; + int error; if (size == 0) return 0; @@ -73,7 +83,13 @@ int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size) abort(); } - if (git_indexer_new(&indexer, ".", 0, odb, NULL) < 0) { +#ifdef GIT_EXPERIMENTAL_SHA256 + error = git_indexer_new(&indexer, ".", GIT_OID_SHA1, NULL); +#else + error = git_indexer_new(&indexer, ".", 0, odb, NULL); +#endif + + if (error < 0) { fprintf(stderr, "Failed to create the indexer: %s\n", git_error_last()->message); abort(); @@ -90,11 +106,19 @@ int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size) if (git_indexer_append(indexer, data, size, &stats) < 0) goto cleanup; if (append_hash) { +#ifdef GIT_EXPERIMENTAL_SHA256 + if (git_odb_hash(&oid, data, size, GIT_OBJECT_BLOB, GIT_OID_SHA1) < 0) { + fprintf(stderr, "Failed to compute the SHA1 hash\n"); + abort(); + } +#else if (git_odb_hash(&oid, data, size, GIT_OBJECT_BLOB) < 0) { fprintf(stderr, "Failed to compute the SHA1 hash\n"); abort(); } - if (git_indexer_append(indexer, &oid.id, GIT_OID_RAWSZ, &stats) < 0) { +#endif + + if (git_indexer_append(indexer, &oid.id, GIT_OID_SHA1_SIZE, &stats) < 0) { goto cleanup; } } diff --git a/include/git2.h b/include/git2.h index 2961cc3e5..3457e5f04 100644 --- a/include/git2.h +++ b/include/git2.h @@ -28,6 +28,7 @@ #include "git2/diff.h" #include "git2/email.h" #include "git2/errors.h" +#include "git2/experimental.h" #include "git2/filter.h" #include "git2/global.h" #include "git2/graph.h" diff --git a/include/git2/common.h b/include/git2/common.h index c3e3e7b4e..f968deb23 100644 --- a/include/git2/common.h +++ b/include/git2/common.h @@ -105,11 +105,6 @@ GIT_BEGIN_DECL */ #define GIT_PATH_MAX 4096 -/** - * The string representation of the null object ID. - */ -#define GIT_OID_HEX_ZERO "0000000000000000000000000000000000000000" - /** * Return the version of the libgit2 library * being currently used. @@ -227,7 +222,9 @@ typedef enum { GIT_OPT_GET_EXTENSIONS, GIT_OPT_SET_EXTENSIONS, GIT_OPT_GET_OWNER_VALIDATION, - GIT_OPT_SET_OWNER_VALIDATION + GIT_OPT_SET_OWNER_VALIDATION, + GIT_OPT_GET_HOMEDIR, + GIT_OPT_SET_HOMEDIR } git_libgit2_opt_t; /** @@ -473,6 +470,16 @@ typedef enum { * > Set that repository directories should be owned by the current * > user. The default is to validate ownership. * + * opts(GIT_OPT_GET_HOMEDIR, git_buf *out) + * > Gets the current user's home directory, as it will be used + * > for file lookups. The path is written to the `out` buffer. + * + * opts(GIT_OPT_SET_HOMEDIR, const char *path) + * > Sets the directory used as the current user's home directory, + * > for file lookups. + * > + * > - `path` directory of home directory. + * * @param option Option key * @param ... value to set the option * @return 0 on success, <0 on failure diff --git a/include/git2/deprecated.h b/include/git2/deprecated.h index c32abeeb7..52864ebe1 100644 --- a/include/git2/deprecated.h +++ b/include/git2/deprecated.h @@ -777,6 +777,12 @@ typedef git_trace_cb git_trace_callback; */ /**@{*/ +#ifndef GIT_EXPERIMENTAL_SHA256 +# define GIT_OID_RAWSZ GIT_OID_SHA1_SIZE +# define GIT_OID_HEXSZ GIT_OID_SHA1_HEXSIZE +# define GIT_OID_HEX_ZERO GIT_OID_SHA1_HEXZERO +#endif + GIT_EXTERN(int) git_oid_iszero(const git_oid *id); /**@}*/ diff --git a/include/git2/diff.h b/include/git2/diff.h index 3839f0033..850d215a6 100644 --- a/include/git2/diff.h +++ b/include/git2/diff.h @@ -274,7 +274,7 @@ typedef struct { /** * Represents the known length of the `id` field, when - * converted to a hex string. It is generally `GIT_OID_HEXSZ`, unless this + * converted to a hex string. It is generally `GIT_OID_SHA1_HEXSIZE`, unless this * delta was created from reading a patch file, in which case it may be * abbreviated to something reasonable, like 7 characters. */ diff --git a/include/git2/experimental.h b/include/git2/experimental.h new file mode 100644 index 000000000..06435f9a7 --- /dev/null +++ b/include/git2/experimental.h @@ -0,0 +1,20 @@ +/* + * Copyright (C) the libgit2 contributors. All rights reserved. + * + * This file is part of libgit2, distributed under the GNU GPL v2 with + * a Linking Exception. For full terms see the included COPYING file. + */ + +#ifndef INCLUDE_experimental_h__ +#define INCLUDE_experimental_h__ + +/* + * This file exists to support users who build libgit2 with a bespoke + * build system and do not use our cmake configuration. Normally, cmake + * will create `experimental.h` from the `experimental.h.in` file and + * will include the generated file instead of this one. For non-cmake + * users, we bundle this `experimental.h` file which will be used + * instead. + */ + +#endif diff --git a/include/git2/indexer.h b/include/git2/indexer.h index ffe9bf366..630eef934 100644 --- a/include/git2/indexer.h +++ b/include/git2/indexer.h @@ -62,6 +62,19 @@ typedef int GIT_CALLBACK(git_indexer_progress_cb)(const git_indexer_progress *st typedef struct git_indexer_options { unsigned int version; +#ifdef GIT_EXPERIMENTAL_SHA256 + /** permissions to use creating packfile or 0 for defaults */ + unsigned int mode; + + /** + * object database from which to read base objects when + * fixing thin packs. This can be NULL if there are no thin + * packs; if a thin pack is encountered, an error will be + * returned if there are bases missing. + */ + git_odb *odb; +#endif + /** progress_cb function to call with progress information */ git_indexer_progress_cb progress_cb; @@ -87,6 +100,21 @@ GIT_EXTERN(int) git_indexer_options_init( git_indexer_options *opts, unsigned int version); +#ifdef GIT_EXPERIMENTAL_SHA256 +/** + * Create a new indexer instance + * + * @param out where to store the indexer instance + * @param path to the directory where the packfile should be stored + * @param oid_type the oid type to use for objects + * @return 0 or an error code. + */ +GIT_EXTERN(int) git_indexer_new( + git_indexer **out, + const char *path, + git_oid_t oid_type, + git_indexer_options *opts); +#else /** * Create a new indexer instance * @@ -106,6 +134,7 @@ GIT_EXTERN(int) git_indexer_new( unsigned int mode, git_odb *odb, git_indexer_options *opts); +#endif /** * Add data to the indexer diff --git a/include/git2/object.h b/include/git2/object.h index 5610a476f..6384aaa6e 100644 --- a/include/git2/object.h +++ b/include/git2/object.h @@ -225,6 +225,7 @@ GIT_EXTERN(int) git_object_peel( */ GIT_EXTERN(int) git_object_dup(git_object **dest, git_object *source); +#ifdef GIT_EXPERIMENTAL_SHA256 /** * Analyzes a buffer of raw object content and determines its validity. * Tree, commit, and tag objects will be parsed and ensured that they @@ -238,14 +239,39 @@ GIT_EXTERN(int) git_object_dup(git_object **dest, git_object *source); * @param valid Output pointer to set with validity of the object content * @param buf The contents to validate * @param len The length of the buffer - * @param type The type of the object in the buffer + * @param object_type The type of the object in the buffer + * @param oid_type The object ID type for the OIDs in the given buffer * @return 0 on success or an error code */ GIT_EXTERN(int) git_object_rawcontent_is_valid( int *valid, const char *buf, size_t len, - git_object_t type); + git_object_t object_type, + git_oid_t oid_type); +#else +/** + * Analyzes a buffer of raw object content and determines its validity. + * Tree, commit, and tag objects will be parsed and ensured that they + * are valid, parseable content. (Blobs are always valid by definition.) + * An error message will be set with an informative message if the object + * is not valid. + * + * @warning This function is experimental and its signature may change in + * the future. + * + * @param valid Output pointer to set with validity of the object content + * @param buf The contents to validate + * @param len The length of the buffer + * @param object_type The type of the object in the buffer + * @return 0 on success or an error code + */ +GIT_EXTERN(int) git_object_rawcontent_is_valid( + int *valid, + const char *buf, + size_t len, + git_object_t object_type); +#endif /** @} */ GIT_END_DECL diff --git a/include/git2/odb.h b/include/git2/odb.h index 0ffe3f328..c7d6a894c 100644 --- a/include/git2/odb.h +++ b/include/git2/odb.h @@ -38,6 +38,25 @@ typedef enum { */ typedef int GIT_CALLBACK(git_odb_foreach_cb)(const git_oid *id, void *payload); +/** Options for configuring a loose object backend. */ +typedef struct { + unsigned int version; /**< version for the struct */ + + /** + * Type of object IDs to use for this object database, or + * 0 for default (currently SHA1). + */ + git_oid_t oid_type; +} git_odb_options; + +/* The current version of the diff options structure */ +#define GIT_ODB_OPTIONS_VERSION 1 + +/* Stack initializer for odb options. Alternatively use + * `git_odb_options_init` programmatic initialization. + */ +#define GIT_ODB_OPTIONS_INIT { GIT_ODB_OPTIONS_VERSION } + /** * Create a new object database with no backends. * @@ -46,9 +65,14 @@ typedef int GIT_CALLBACK(git_odb_foreach_cb)(const git_oid *id, void *payload); * * @param out location to store the database pointer, if opened. * Set to NULL if the open failed. + * @param opts the options for this object database or NULL for defaults * @return 0 or an error code */ +#ifdef GIT_EXPERIMENTAL_SHA256 +GIT_EXTERN(int) git_odb_new(git_odb **out, const git_odb_options *opts); +#else GIT_EXTERN(int) git_odb_new(git_odb **out); +#endif /** * Create a new object database and automatically add @@ -64,9 +88,17 @@ GIT_EXTERN(int) git_odb_new(git_odb **out); * @param out location to store the database pointer, if opened. * Set to NULL if the open failed. * @param objects_dir path of the backends' "objects" directory. + * @param opts the options for this object database or NULL for defaults * @return 0 or an error code */ +#ifdef GIT_EXPERIMENTAL_SHA256 +GIT_EXTERN(int) git_odb_open( + git_odb **out, + const char *objects_dir, + const git_odb_options *opts); +#else GIT_EXTERN(int) git_odb_open(git_odb **out, const char *objects_dir); +#endif /** * Add an on-disk alternate to an existing Object DB. @@ -117,7 +149,7 @@ GIT_EXTERN(int) git_odb_read(git_odb_object **out, git_odb *db, const git_oid *i * This method queries all available ODB backends * trying to match the 'len' first hexadecimal * characters of the 'short_id'. - * The remaining (GIT_OID_HEXSZ-len)*4 bits of + * The remaining (GIT_OID_SHA1_HEXSIZE-len)*4 bits of * 'short_id' must be 0s. * 'len' must be at least GIT_OID_MINPREFIXLEN, * and the prefix must be long enough to identify @@ -218,7 +250,7 @@ typedef struct git_odb_expand_id { * * The given array will be updated in place: for each abbreviated ID that is * unique in the database, and of the given type (if specified), - * the full object ID, object ID length (`GIT_OID_HEXSZ`) and type will be + * the full object ID, object ID length (`GIT_OID_SHA1_HEXSIZE`) and type will be * written back to the array. For IDs that are not found (or are ambiguous), * the array entry will be zeroed. * @@ -435,18 +467,28 @@ GIT_EXTERN(int) git_odb_write_multi_pack_index( git_odb *db); /** - * Determine the object-ID (sha1 hash) of a data buffer + * Determine the object-ID (sha1 or sha256 hash) of a data buffer * - * The resulting SHA-1 OID will be the identifier for the data - * buffer as if the data buffer it were to written to the ODB. + * The resulting OID will be the identifier for the data buffer as if + * the data buffer it were to written to the ODB. * * @param out the resulting object-ID. * @param data data to hash * @param len size of the data - * @param type of the data to hash + * @param object_type of the data to hash + * @param oid_type the oid type to hash to * @return 0 or an error code */ +#ifdef GIT_EXPERIMENTAL_SHA256 +GIT_EXTERN(int) git_odb_hash( + git_oid *out, + const void *data, + size_t len, + git_object_t object_type, + git_oid_t oid_type); +#else GIT_EXTERN(int) git_odb_hash(git_oid *out, const void *data, size_t len, git_object_t type); +#endif /** * Read a file from disk and fill a git_oid with the object id @@ -458,10 +500,19 @@ GIT_EXTERN(int) git_odb_hash(git_oid *out, const void *data, size_t len, git_obj * * @param out oid structure the result is written into. * @param path file to read and determine object id for - * @param type the type of the object that will be hashed + * @param object_type of the data to hash + * @param oid_type the oid type to hash to * @return 0 or an error code */ +#ifdef GIT_EXPERIMENTAL_SHA256 +GIT_EXTERN(int) git_odb_hashfile( + git_oid *out, + const char *path, + git_object_t object_type, + git_oid_t oid_type); +#else GIT_EXTERN(int) git_odb_hashfile(git_oid *out, const char *path, git_object_t type); +#endif /** * Create a copy of an odb_object diff --git a/include/git2/odb_backend.h b/include/git2/odb_backend.h index 5ad777b17..12dd0fd38 100644 --- a/include/git2/odb_backend.h +++ b/include/git2/odb_backend.h @@ -24,6 +24,26 @@ GIT_BEGIN_DECL * Constructors for in-box ODB backends. */ +/** Options for configuring a packfile object backend. */ +typedef struct { + unsigned int version; /**< version for the struct */ + + /** + * Type of object IDs to use for this object database, or + * 0 for default (currently SHA1). + */ + git_oid_t oid_type; +} git_odb_backend_pack_options; + +/* The current version of the diff options structure */ +#define GIT_ODB_BACKEND_PACK_OPTIONS_VERSION 1 + +/* Stack initializer for odb pack backend options. Alternatively use + * `git_odb_backend_pack_options_init` programmatic initialization. + */ +#define GIT_ODB_BACKEND_PACK_OPTIONS_INIT \ + { GIT_ODB_BACKEND_PACK_OPTIONS_VERSION } + /** * Create a backend for the packfiles. * @@ -32,27 +52,16 @@ GIT_BEGIN_DECL * * @return 0 or an error code */ -GIT_EXTERN(int) git_odb_backend_pack(git_odb_backend **out, const char *objects_dir); - -/** - * Create a backend for loose objects - * - * @param out location to store the odb backend pointer - * @param objects_dir the Git repository's objects directory - * @param compression_level zlib compression level to use - * @param do_fsync whether to do an fsync() after writing - * @param dir_mode permissions to use creating a directory or 0 for defaults - * @param file_mode permissions to use creating a file or 0 for defaults - * - * @return 0 or an error code - */ -GIT_EXTERN(int) git_odb_backend_loose( +#ifdef GIT_EXPERIMENTAL_SHA256 +GIT_EXTERN(int) git_odb_backend_pack( git_odb_backend **out, const char *objects_dir, - int compression_level, - int do_fsync, - unsigned int dir_mode, - unsigned int file_mode); + const git_odb_backend_pack_options *opts); +#else +GIT_EXTERN(int) git_odb_backend_pack( + git_odb_backend **out, + const char *objects_dir); +#endif /** * Create a backend out of a single packfile @@ -65,7 +74,82 @@ GIT_EXTERN(int) git_odb_backend_loose( * * @return 0 or an error code */ -GIT_EXTERN(int) git_odb_backend_one_pack(git_odb_backend **out, const char *index_file); +#ifdef GIT_EXPERIMENTAL_SHA256 +GIT_EXTERN(int) git_odb_backend_one_pack( + git_odb_backend **out, + const char *index_file, + const git_odb_backend_pack_options *opts); +#else +GIT_EXTERN(int) git_odb_backend_one_pack( + git_odb_backend **out, + const char *index_file); +#endif + +typedef enum { + GIT_ODB_BACKEND_LOOSE_FSYNC = (1 << 0) +} git_odb_backend_loose_flag_t; + +/** Options for configuring a loose object backend. */ +typedef struct { + unsigned int version; /**< version for the struct */ + + /** A combination of the `git_odb_backend_loose_flag_t` types. */ + uint32_t flags; + + /** + * zlib compression level to use (0-9), where 1 is the fastest + * at the expense of larger files, and 9 produces the best + * compression at the expense of speed. 0 indicates that no + * compression should be performed. -1 is the default (currently + * optimizing for speed). + */ + int compression_level; + + /** Permissions to use creating a directory or 0 for defaults */ + unsigned int dir_mode; + + /** Permissions to use creating a file or 0 for defaults */ + unsigned int file_mode; + + /** + * Type of object IDs to use for this object database, or + * 0 for default (currently SHA1). + */ + git_oid_t oid_type; +} git_odb_backend_loose_options; + +/* The current version of the diff options structure */ +#define GIT_ODB_BACKEND_LOOSE_OPTIONS_VERSION 1 + +/* Stack initializer for odb loose backend options. Alternatively use + * `git_odb_backend_loose_options_init` programmatic initialization. + */ +#define GIT_ODB_BACKEND_LOOSE_OPTIONS_INIT \ + { GIT_ODB_BACKEND_LOOSE_OPTIONS_VERSION, 0, -1 } + +/** + * Create a backend for loose objects + * + * @param out location to store the odb backend pointer + * @param objects_dir the Git repository's objects directory + * @param opts options for the loose object backend or NULL + * + * @return 0 or an error code + */ +#ifdef GIT_EXPERIMENTAL_SHA256 +GIT_EXTERN(int) git_odb_backend_loose( + git_odb_backend **out, + const char *objects_dir, + git_odb_backend_loose_options *opts); +#else +GIT_EXTERN(int) git_odb_backend_loose( + git_odb_backend **out, + const char *objects_dir, + int compression_level, + int do_fsync, + unsigned int dir_mode, + unsigned int file_mode); +#endif /** Streaming mode */ typedef enum { @@ -87,6 +171,10 @@ struct git_odb_stream { unsigned int mode; void *hash_ctx; +#ifdef GIT_EXPERIMENTAL_SHA256 + git_oid_t oid_type; +#endif + git_object_size_t declared_size; git_object_size_t received_bytes; diff --git a/include/git2/oid.h b/include/git2/oid.h index 549df4eab..399b7b907 100644 --- a/include/git2/oid.h +++ b/include/git2/oid.h @@ -9,6 +9,7 @@ #include "common.h" #include "types.h" +#include "experimental.h" /** * @file git2/oid.h @@ -19,11 +20,76 @@ */ GIT_BEGIN_DECL -/** Size (in bytes) of a raw/binary oid */ -#define GIT_OID_RAWSZ 20 +/** The type of object id. */ +typedef enum { -/** Size (in bytes) of a hex formatted oid */ -#define GIT_OID_HEXSZ (GIT_OID_RAWSZ * 2) +#ifdef GIT_EXPERIMENTAL_SHA256 + GIT_OID_SHA1 = 1, /**< SHA1 */ + GIT_OID_SHA256 = 2 /**< SHA256 */ +#else + GIT_OID_SHA1 = 1 /**< SHA1 */ +#endif + +} git_oid_t; + +/* + * SHA1 is currently the only supported object ID type. + */ + +/** SHA1 is currently libgit2's default oid type. */ +#define GIT_OID_DEFAULT GIT_OID_SHA1 + +/** Size (in bytes) of a raw/binary sha1 oid */ +#define GIT_OID_SHA1_SIZE 20 +/** Size (in bytes) of a hex formatted sha1 oid */ +#define GIT_OID_SHA1_HEXSIZE (GIT_OID_SHA1_SIZE * 2) + +/** + * The binary representation of the null sha1 object ID. + */ +#ifndef GIT_EXPERIMENTAL_SHA256 +# define GIT_OID_SHA1_ZERO { { 0 } } +#else +# define GIT_OID_SHA1_ZERO { GIT_OID_SHA1, { 0 } } +#endif + +/** + * The string representation of the null sha1 object ID. + */ +#define GIT_OID_SHA1_HEXZERO "0000000000000000000000000000000000000000" + +/* + * Experimental SHA256 support is a breaking change to the API. + * This exists for application compatibility testing. + */ + +#ifdef GIT_EXPERIMENTAL_SHA256 + +/** Size (in bytes) of a raw/binary sha256 oid */ +# define GIT_OID_SHA256_SIZE 32 +/** Size (in bytes) of a hex formatted sha256 oid */ +# define GIT_OID_SHA256_HEXSIZE (GIT_OID_SHA256_SIZE * 2) + +/** + * The binary representation of the null sha256 object ID. + */ +# define GIT_OID_SHA256_ZERO { GIT_OID_SHA256, { 0 } } + +/** + * The string representation of the null sha256 object ID. + */ +# define GIT_OID_SHA256_HEXZERO "0000000000000000000000000000000000000000000000000000000000000000" + +#endif + +/* Maximum possible object ID size in raw / hex string format. */ +#ifndef GIT_EXPERIMENTAL_SHA256 +# define GIT_OID_MAX_SIZE GIT_OID_SHA1_SIZE +# define GIT_OID_MAX_HEXSIZE GIT_OID_SHA1_HEXSIZE +#else +# define GIT_OID_MAX_SIZE GIT_OID_SHA256_SIZE +# define GIT_OID_MAX_HEXSIZE GIT_OID_SHA256_HEXSIZE +#endif /** Minimum length (in number of hex characters, * i.e. packets of 4 bits) of an oid prefix */ @@ -31,29 +97,50 @@ GIT_BEGIN_DECL /** Unique identity of any object (commit, tree, blob, tag). */ typedef struct git_oid { + +#ifdef GIT_EXPERIMENTAL_SHA256 + /** type of object id */ + unsigned char type; +#endif + /** raw binary formatted id */ - unsigned char id[GIT_OID_RAWSZ]; + unsigned char id[GIT_OID_MAX_SIZE]; } git_oid; /** * Parse a hex formatted object id into a git_oid. * + * The appropriate number of bytes for the given object ID type will + * be read from the string - 40 bytes for SHA1, 64 bytes for SHA256. + * The given string need not be NUL terminated. + * * @param out oid structure the result is written into. * @param str input hex string; must be pointing at the start of * the hex sequence and have at least the number of bytes - * needed for an oid encoded in hex (40 bytes). + * needed for an oid encoded in hex (40 bytes for sha1, + * 256 bytes for sha256). + * @param type the type of object id * @return 0 or an error code */ +#ifdef GIT_EXPERIMENTAL_SHA256 +GIT_EXTERN(int) git_oid_fromstr(git_oid *out, const char *str, git_oid_t type); +#else GIT_EXTERN(int) git_oid_fromstr(git_oid *out, const char *str); +#endif /** - * Parse a hex formatted null-terminated string into a git_oid. + * Parse a hex formatted NUL-terminated string into a git_oid. * * @param out oid structure the result is written into. * @param str input hex string; must be null-terminated. + * @param type the type of object id * @return 0 or an error code */ +#ifdef GIT_EXPERIMENTAL_SHA256 +GIT_EXTERN(int) git_oid_fromstrp(git_oid *out, const char *str, git_oid_t type); +#else GIT_EXTERN(int) git_oid_fromstrp(git_oid *out, const char *str); +#endif /** * Parse N characters of a hex formatted object id into a git_oid. @@ -64,9 +151,14 @@ GIT_EXTERN(int) git_oid_fromstrp(git_oid *out, const char *str); * @param out oid structure the result is written into. * @param str input hex string of at least size `length` * @param length length of the input string + * @param type the type of object id * @return 0 or an error code */ +#ifdef GIT_EXPERIMENTAL_SHA256 +GIT_EXTERN(int) git_oid_fromstrn(git_oid *out, const char *str, size_t length, git_oid_t type); +#else GIT_EXTERN(int) git_oid_fromstrn(git_oid *out, const char *str, size_t length); +#endif /** * Copy an already raw oid into a git_oid structure. @@ -75,16 +167,21 @@ GIT_EXTERN(int) git_oid_fromstrn(git_oid *out, const char *str, size_t length); * @param raw the raw input bytes to be copied. * @return 0 on success or error code */ +#ifdef GIT_EXPERIMENTAL_SHA256 +GIT_EXTERN(int) git_oid_fromraw(git_oid *out, const unsigned char *raw, git_oid_t type); +#else GIT_EXTERN(int) git_oid_fromraw(git_oid *out, const unsigned char *raw); +#endif /** * Format a git_oid into a hex string. * * @param out output hex string; must be pointing at the start of * the hex sequence and have at least the number of bytes - * needed for an oid encoded in hex (40 bytes). Only the - * oid digits are written; a '\\0' terminator must be added - * by the caller if it is required. + * needed for an oid encoded in hex (40 bytes for SHA1, + * 64 bytes for SHA256). Only the oid digits are written; + * a '\\0' terminator must be added by the caller if it is + * required. * @param id oid structure to format. * @return 0 on success or error code */ @@ -94,7 +191,7 @@ GIT_EXTERN(int) git_oid_fmt(char *out, const git_oid *id); * Format a git_oid into a partial hex string. * * @param out output hex string; you say how many bytes to write. - * If the number of bytes is > GIT_OID_HEXSZ, extra bytes + * If the number of bytes is > GIT_OID_SHA1_HEXSIZE, extra bytes * will be zeroed; if not, a '\0' terminator is NOT added. * @param n number of characters to write into out string * @param id oid structure to format. @@ -110,9 +207,10 @@ GIT_EXTERN(int) git_oid_nfmt(char *out, size_t n, const git_oid *id); * * @param out output hex string; must be pointing at the start of * the hex sequence and have at least the number of bytes - * needed for an oid encoded in hex (41 bytes). Only the - * oid digits are written; a '\\0' terminator must be added - * by the caller if it is required. + * needed for an oid encoded in hex (41 bytes for SHA1, + * 65 bytes for SHA256). Only the oid digits are written; + * a '\\0' terminator must be added by the caller if it + * is required. * @param id oid structure to format. * @return 0 on success, non-zero callback return value, or error code */ @@ -134,7 +232,9 @@ GIT_EXTERN(char *) git_oid_tostr_s(const git_oid *oid); /** * Format a git_oid into a buffer as a hex format c-string. * - * If the buffer is smaller than GIT_OID_HEXSZ+1, then the resulting + * If the buffer is smaller than the size of a hex-formatted oid string + * plus an additional byte (GIT_OID_SHA_HEXSIZE + 1 for SHA1 or + * GIT_OID_SHA256_HEXSIZE + 1 for SHA256), then the resulting * oid c-string will be truncated to n-1 characters (but will still be * NUL-byte terminated). * diff --git a/include/git2/repository.h b/include/git2/repository.h index c87f3c962..560e70ab6 100644 --- a/include/git2/repository.h +++ b/include/git2/repository.h @@ -351,6 +351,15 @@ typedef struct { * pointing to this URL. */ const char *origin_url; + +#ifdef GIT_EXPERIMENTAL_SHA256 + /** + * + * Type of object IDs to use for this repository, or 0 for + * default (currently SHA1). + */ + git_oid_t oid_type; +#endif } git_repository_init_options; #define GIT_REPOSITORY_INIT_OPTIONS_VERSION 1 @@ -456,7 +465,9 @@ GIT_EXTERN(int) git_repository_head_unborn(git_repository *repo); * Check if a repository is empty * * An empty repository has just been initialized and contains no references - * apart from HEAD, which must be pointing to the unborn master branch. + * apart from HEAD, which must be pointing to the unborn master branch, + * or the branch specified for the repository in the `init.defaultBranch` + * configuration variable. * * @param repo Repo to test * @return 1 if the repository is empty, 0 if it isn't, error code @@ -949,6 +960,14 @@ GIT_EXTERN(int) git_repository_ident(const char **name, const char **email, cons */ GIT_EXTERN(int) git_repository_set_ident(git_repository *repo, const char *name, const char *email); +/** + * Gets the object type used by this repository. + * + * @param repo the repository + * @return the object id type + */ +GIT_EXTERN(git_oid_t) git_repository_oid_type(git_repository *repo); + /** @} */ GIT_END_DECL #endif diff --git a/include/git2/stash.h b/include/git2/stash.h index 32e6f9576..dcfc013dc 100644 --- a/include/git2/stash.h +++ b/include/git2/stash.h @@ -44,7 +44,12 @@ typedef enum { * All ignored files are also stashed and then cleaned up from * the working directory */ - GIT_STASH_INCLUDE_IGNORED = (1 << 2) + GIT_STASH_INCLUDE_IGNORED = (1 << 2), + + /** + * All changes in the index and working directory are left intact + */ + GIT_STASH_KEEP_ALL = (1 << 3) } git_stash_flags; /** @@ -52,15 +57,10 @@ typedef enum { * * @param out Object id of the commit containing the stashed state. * This commit is also the target of the direct reference refs/stash. - * * @param repo The owning repository. - * * @param stasher The identity of the person performing the stashing. - * * @param message Optional description along with the stashed state. - * * @param flags Flags to control the stashing process. (see GIT_STASH_* above) - * * @return 0 on success, GIT_ENOTFOUND where there's nothing to stash, * or error code. */ @@ -71,6 +71,60 @@ GIT_EXTERN(int) git_stash_save( const char *message, uint32_t flags); +/** + * Stash save options structure + * + * Initialize with `GIT_STASH_SAVE_OPTIONS_INIT`. Alternatively, you can + * use `git_stash_save_options_init`. + * + */ +typedef struct git_stash_save_options { + unsigned int version; + + /** Flags to control the stashing process. (see GIT_STASH_* above) */ + uint32_t flags; + + /** The identity of the person performing the stashing. */ + const git_signature *stasher; + + /** Optional description along with the stashed state. */ + const char *message; + + /** Optional paths that control which files are stashed. */ + git_strarray paths; +} git_stash_save_options; + +#define GIT_STASH_SAVE_OPTIONS_VERSION 1 +#define GIT_STASH_SAVE_OPTIONS_INIT { GIT_STASH_SAVE_OPTIONS_VERSION } + +/** + * Initialize git_stash_save_options structure + * + * Initializes a `git_stash_save_options` with default values. Equivalent to + * creating an instance with `GIT_STASH_SAVE_OPTIONS_INIT`. + * + * @param opts The `git_stash_save_options` struct to initialize. + * @param version The struct version; pass `GIT_STASH_SAVE_OPTIONS_VERSION`. + * @return Zero on success; -1 on failure. + */ +GIT_EXTERN(int) git_stash_save_options_init( + git_stash_save_options *opts, unsigned int version); + +/** + * Save the local modifications to a new stash, with options. + * + * @param out Object id of the commit containing the stashed state. + * This commit is also the target of the direct reference refs/stash. + * @param repo The owning repository. + * @param opts The stash options. + * @return 0 on success, GIT_ENOTFOUND where there's nothing to stash, + * or error code. + */ +GIT_EXTERN(int) git_stash_save_with_opts( + git_oid *out, + git_repository *repo, + const git_stash_save_options *opts); + /** Stash application flags. */ typedef enum { GIT_STASH_APPLY_DEFAULT = 0, diff --git a/include/git2/strarray.h b/include/git2/strarray.h index 0f657e6c5..03d93f8fb 100644 --- a/include/git2/strarray.h +++ b/include/git2/strarray.h @@ -36,19 +36,6 @@ typedef struct git_strarray { */ GIT_EXTERN(void) git_strarray_dispose(git_strarray *array); -/** - * Copy a string array object from source to target. - * - * Note: target is overwritten and hence should be empty, otherwise its - * contents are leaked. Call git_strarray_free() if necessary. - * - * @param tgt target - * @param src source - * @return 0 on success, < 0 on allocation failure - */ -GIT_EXTERN(int) git_strarray_copy(git_strarray *tgt, const git_strarray *src); - - /** @} */ GIT_END_DECL diff --git a/include/git2/sys/odb_backend.h b/include/git2/sys/odb_backend.h index 8598f94e5..c42abd370 100644 --- a/include/git2/sys/odb_backend.h +++ b/include/git2/sys/odb_backend.h @@ -36,7 +36,7 @@ struct git_odb_backend { void **, size_t *, git_object_t *, git_odb_backend *, const git_oid *); /* To find a unique object given a prefix of its oid. The oid given - * must be so that the remaining (GIT_OID_HEXSZ - len)*4 bits are 0s. + * must be so that the remaining (GIT_OID_SHA1_HEXSIZE - len)*4 bits are 0s. */ int GIT_CALLBACK(read_prefix)( git_oid *, void **, size_t *, git_object_t *, diff --git a/include/git2/sys/transport.h b/include/git2/sys/transport.h index 06ae7079f..b70582188 100644 --- a/include/git2/sys/transport.h +++ b/include/git2/sys/transport.h @@ -57,6 +57,18 @@ struct git_transport { unsigned int *capabilities, git_transport *transport); +#ifdef GIT_EXPERIMENTAL_SHA256 + /** + * Gets the object type for the remote repository. + * + * This function may be called after a successful call to + * `connect()`. + */ + int GIT_CALLBACK(oid_type)( + git_oid_t *object_type, + git_transport *transport); +#endif + /** * Get the list of available references in the remote repository. * diff --git a/include/git2/version.h b/include/git2/version.h index 944d74365..97221e459 100644 --- a/include/git2/version.h +++ b/include/git2/version.h @@ -11,16 +11,16 @@ * The version string for libgit2. This string follows semantic * versioning (v2) guidelines. */ -#define LIBGIT2_VERSION "1.5.1" +#define LIBGIT2_VERSION "1.6.4" /** The major version number for this version of libgit2. */ #define LIBGIT2_VER_MAJOR 1 /** The minor version number for this version of libgit2. */ -#define LIBGIT2_VER_MINOR 5 +#define LIBGIT2_VER_MINOR 6 /** The revision ("teeny") version number for this version of libgit2. */ -#define LIBGIT2_VER_REVISION 1 +#define LIBGIT2_VER_REVISION 4 /** The Windows DLL patch number for this version of libgit2. */ #define LIBGIT2_VER_PATCH 0 @@ -34,6 +34,6 @@ #define LIBGIT2_VER_PRERELEASE NULL /** The library ABI soversion for this version of libgit2. */ -#define LIBGIT2_SOVERSION "1.5" +#define LIBGIT2_SOVERSION "1.6" #endif diff --git a/package.json b/package.json index 8e8176f22..9695f90d9 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "libgit2", - "version": "1.5.1", + "version": "1.6.4", "repo": "https://github.com/libgit2/libgit2", "description": " A cross-platform, linkable library implementation of Git that you can use in your application.", "install": "mkdir build && cd build && cmake .. && cmake --build ." diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index d16cfe538..e108b2e79 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -170,12 +170,6 @@ if(ICONV_FOUND) endif() add_feature_info(iconv GIT_USE_ICONV "iconv encoding conversion support") -# -# Configure support -# - -configure_file(features.h.in git2/sys/features.h) - # # Include child projects # diff --git a/src/cli/CMakeLists.txt b/src/cli/CMakeLists.txt index 4f347e93f..84b6c1901 100644 --- a/src/cli/CMakeLists.txt +++ b/src/cli/CMakeLists.txt @@ -1,8 +1,10 @@ set(CLI_INCLUDES - "${libgit2_BINARY_DIR}/src" + "${libgit2_BINARY_DIR}/src/util" + "${libgit2_BINARY_DIR}/include" "${libgit2_SOURCE_DIR}/src/util" "${libgit2_SOURCE_DIR}/src/cli" - "${libgit2_SOURCE_DIR}/include") + "${libgit2_SOURCE_DIR}/include" + "${LIBGIT2_DEPENDENCY_INCLUDES}") if(WIN32 AND NOT CYGWIN) file(GLOB CLI_SRC_OS win32/*.c) @@ -39,6 +41,7 @@ target_link_libraries(git2_cli ${CLI_LIBGIT2_LIBRARY} ${LIBGIT2_SYSTEM_LIBS}) set_target_properties(git2_cli PROPERTIES C_STANDARD 90) set_target_properties(git2_cli PROPERTIES RUNTIME_OUTPUT_DIRECTORY ${libgit2_BINARY_DIR}) +set_target_properties(git2_cli PROPERTIES OUTPUT_NAME ${LIBGIT2_FILENAME}) ide_split_sources(git2_cli) diff --git a/src/cli/cmd_hash_object.c b/src/cli/cmd_hash_object.c index 5cfe9146a..93b980d66 100644 --- a/src/cli/cmd_hash_object.c +++ b/src/cli/cmd_hash_object.c @@ -49,23 +49,39 @@ static void print_help(void) cli_opt_help_fprint(stdout, opts); } -static int hash_buf(git_odb *odb, git_str *buf, git_object_t type) +static int hash_buf( + git_odb *odb, + git_str *buf, + git_object_t object_type, + git_oid_t oid_type) { git_oid oid; if (!literally) { int valid = 0; - if (git_object_rawcontent_is_valid(&valid, buf->ptr, buf->size, type) < 0 || !valid) +#ifdef GIT_EXPERIMENTAL_SHA256 + if (git_object_rawcontent_is_valid(&valid, buf->ptr, buf->size, object_type, oid_type) < 0 || !valid) return cli_error_git(); +#else + GIT_UNUSED(oid_type); + + if (git_object_rawcontent_is_valid(&valid, buf->ptr, buf->size, object_type) < 0 || !valid) + return cli_error_git(); +#endif } if (write_object) { - if (git_odb_write(&oid, odb, buf->ptr, buf->size, type) < 0) + if (git_odb_write(&oid, odb, buf->ptr, buf->size, object_type) < 0) return cli_error_git(); } else { - if (git_odb_hash(&oid, buf->ptr, buf->size, type) < 0) +#ifdef GIT_EXPERIMENTAL_SHA256 + if (git_odb_hash(&oid, buf->ptr, buf->size, object_type, GIT_OID_SHA1) < 0) return cli_error_git(); +#else + if (git_odb_hash(&oid, buf->ptr, buf->size, object_type) < 0) + return cli_error_git(); +#endif } if (printf("%s\n", git_oid_tostr_s(&oid)) < 0) @@ -78,9 +94,10 @@ int cmd_hash_object(int argc, char **argv) { git_repository *repo = NULL; git_odb *odb = NULL; + git_oid_t oid_type; git_str buf = GIT_STR_INIT; cli_opt invalid_opt; - git_object_t type = GIT_OBJECT_BLOB; + git_object_t object_type = GIT_OBJECT_BLOB; char **filename; int ret = 0; @@ -92,7 +109,7 @@ int cmd_hash_object(int argc, char **argv) return 0; } - if (type_name && (type = git_object_string2type(type_name)) == GIT_OBJECT_INVALID) + if (type_name && (object_type = git_object_string2type(type_name)) == GIT_OBJECT_INVALID) return cli_error_usage("invalid object type '%s'", type_name); if (write_object && @@ -102,6 +119,8 @@ int cmd_hash_object(int argc, char **argv) goto done; } + oid_type = git_repository_oid_type(repo); + /* * TODO: we're reading blobs, we shouldn't pull them all into main * memory, we should just stream them into the odb instead. @@ -113,7 +132,7 @@ int cmd_hash_object(int argc, char **argv) goto done; } - if ((ret = hash_buf(odb, &buf, type)) != 0) + if ((ret = hash_buf(odb, &buf, object_type, oid_type)) != 0) goto done; } else { for (filename = filenames; *filename; filename++) { @@ -122,7 +141,7 @@ int cmd_hash_object(int argc, char **argv) goto done; } - if ((ret = hash_buf(odb, &buf, type)) != 0) + if ((ret = hash_buf(odb, &buf, object_type, oid_type)) != 0) goto done; } } diff --git a/src/cli/opt.c b/src/cli/opt.c index 72df5877f..62a3430d1 100644 --- a/src/cli/opt.c +++ b/src/cli/opt.c @@ -23,7 +23,7 @@ #include "opt.h" #ifdef _WIN32 -# include +# include #else # include # include diff --git a/src/libgit2/CMakeLists.txt b/src/libgit2/CMakeLists.txt index 0c7ddddba..dcb4279c1 100644 --- a/src/libgit2/CMakeLists.txt +++ b/src/libgit2/CMakeLists.txt @@ -8,21 +8,12 @@ set_target_properties(libgit2 PROPERTIES C_EXTENSIONS OFF) include(PkgBuildConfig) set(LIBGIT2_INCLUDES - "${PROJECT_BINARY_DIR}/src" + "${PROJECT_BINARY_DIR}/src/util" + "${PROJECT_BINARY_DIR}/include" "${PROJECT_SOURCE_DIR}/src/libgit2" "${PROJECT_SOURCE_DIR}/src/util" "${PROJECT_SOURCE_DIR}/include") -if(WIN32 AND EMBED_SSH_PATH) - file(GLOB SRC_SSH "${EMBED_SSH_PATH}/src/*.c") - list(SORT SRC_SSH) - target_sources(libgit2 PRIVATE ${SRC_SSH}) - - list(APPEND LIBGIT2_SYSTEM_INCLUDES "${EMBED_SSH_PATH}/include") - file(WRITE "${EMBED_SSH_PATH}/src/libssh2_config.h" "#define HAVE_WINCNG\n#define LIBSSH2_WINCNG\n#include \"../win32/libssh2_config.h\"") - set(GIT_SSH 1) -endif() - # Collect sourcefiles file(GLOB SRC_H "${PROJECT_SOURCE_DIR}/include/git2.h" @@ -67,6 +58,7 @@ endif() ide_split_sources(libgit2) list(APPEND LIBGIT2_OBJECTS $ $ ${LIBGIT2_DEPENDENCY_OBJECTS}) +list(APPEND LIBGIT2_INCLUDES ${LIBGIT2_DEPENDENCY_INCLUDES}) target_include_directories(libgit2 PRIVATE ${LIBGIT2_INCLUDES} ${LIBGIT2_DEPENDENCY_INCLUDES} PUBLIC ${PROJECT_SOURCE_DIR}/include) target_include_directories(libgit2 SYSTEM PRIVATE ${LIBGIT2_SYSTEM_INCLUDES}) @@ -84,6 +76,7 @@ set(LIBGIT2_SYSTEM_LIBS ${LIBGIT2_SYSTEM_LIBS} PARENT_SCOPE) add_library(libgit2package ${SRC_RC} ${LIBGIT2_OBJECTS}) target_link_libraries(libgit2package ${LIBGIT2_SYSTEM_LIBS}) +target_include_directories(libgit2package SYSTEM PRIVATE ${LIBGIT2_INCLUDES}) set_target_properties(libgit2package PROPERTIES C_STANDARD 90) set_target_properties(libgit2package PROPERTIES LIBRARY_OUTPUT_DIRECTORY ${PROJECT_BINARY_DIR}) @@ -109,10 +102,10 @@ if(SONAME) endif() endif() -pkg_build_config(NAME libgit2 +pkg_build_config(NAME "lib${LIBGIT2_FILENAME}" VERSION ${libgit2_VERSION} DESCRIPTION "The git library, take 2" - LIBS_SELF git2 + LIBS_SELF ${LIBGIT2_FILENAME} PRIVATE_LIBS ${LIBGIT2_PC_LIBS} REQUIRES ${LIBGIT2_PC_REQUIRES}) @@ -122,10 +115,26 @@ if(MSVC_IDE) set_source_files_properties(win32/precompiled.c COMPILE_FLAGS "/Ycprecompiled.h") endif() +# support experimental features and functionality + +configure_file(experimental.h.in "${PROJECT_BINARY_DIR}/include/git2/experimental.h") + +# translate filenames in the git2.h so that they match the install directory +# (allows for side-by-side installs of libgit2 and libgit2-experimental.) + +FILE(READ "${PROJECT_SOURCE_DIR}/include/git2.h" LIBGIT2_INCLUDE) +STRING(REGEX REPLACE "#include \"git2\/" "#include \"${LIBGIT2_FILENAME}/" LIBGIT2_INCLUDE "${LIBGIT2_INCLUDE}") +FILE(WRITE "${PROJECT_BINARY_DIR}/include/${LIBGIT2_FILENAME}.h" ${LIBGIT2_INCLUDE}) + # Install + install(TARGETS libgit2package RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR} LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR} ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}) -install(DIRECTORY ${PROJECT_SOURCE_DIR}/include/git2 DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}) -install(FILES ${PROJECT_SOURCE_DIR}/include/git2.h DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}) +install(DIRECTORY ${PROJECT_SOURCE_DIR}/include/git2/ + DESTINATION "${CMAKE_INSTALL_INCLUDEDIR}/${LIBGIT2_FILENAME}") +install(FILES ${PROJECT_BINARY_DIR}/include/git2/experimental.h + DESTINATION "${CMAKE_INSTALL_INCLUDEDIR}/${LIBGIT2_FILENAME}") +install(FILES "${PROJECT_BINARY_DIR}/include/${LIBGIT2_FILENAME}.h" + DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}) diff --git a/src/libgit2/annotated_commit.c b/src/libgit2/annotated_commit.c index e48947679..7bd8b6077 100644 --- a/src/libgit2/annotated_commit.c +++ b/src/libgit2/annotated_commit.c @@ -40,7 +40,7 @@ static int annotated_commit_init( goto done; git_oid_fmt(annotated_commit->id_str, git_commit_id(commit)); - annotated_commit->id_str[GIT_OID_HEXSZ] = '\0'; + annotated_commit->id_str[GIT_OID_SHA1_HEXSIZE] = '\0'; if (!description) description = annotated_commit->id_str; diff --git a/src/libgit2/annotated_commit.h b/src/libgit2/annotated_commit.h index 444a2ed10..c87eaa805 100644 --- a/src/libgit2/annotated_commit.h +++ b/src/libgit2/annotated_commit.h @@ -41,7 +41,7 @@ struct git_annotated_commit { const char *ref_name; const char *remote_url; - char id_str[GIT_OID_HEXSZ+1]; + char id_str[GIT_OID_SHA1_HEXSIZE+1]; }; extern int git_annotated_commit_from_head(git_annotated_commit **out, diff --git a/src/libgit2/attr_file.c b/src/libgit2/attr_file.c index 0eb881a9b..afa8ec7b3 100644 --- a/src/libgit2/attr_file.c +++ b/src/libgit2/attr_file.c @@ -135,7 +135,7 @@ int git_attr_file__load( break; case GIT_ATTR_FILE_SOURCE_INDEX: { if ((error = attr_file_oid_from_index(&id, repo, entry->path)) < 0 || - (error = git_blob_lookup(&blob, repo, &id)) < 0) + (error = git_blob_lookup(&blob, repo, &id)) < 0) return error; /* Do not assume that data straight from the ODB is NULL-terminated; diff --git a/src/libgit2/attrcache.c b/src/libgit2/attrcache.c index b16d95c3c..405944ed1 100644 --- a/src/libgit2/attrcache.c +++ b/src/libgit2/attrcache.c @@ -300,7 +300,7 @@ static int attr_cache__lookup_path( /* expand leading ~/ as needed */ if (cfgval && cfgval[0] == '~' && cfgval[1] == '/') { - if (! (error = git_sysdir_expand_global_file(&buf, &cfgval[2]))) + if (! (error = git_sysdir_expand_homedir_file(&buf, &cfgval[2]))) *out = git_str_detach(&buf); } else if (cfgval) { *out = git__strdup(cfgval); diff --git a/src/libgit2/blame.c b/src/libgit2/blame.c index a6ab43efd..b70cd615e 100644 --- a/src/libgit2/blame.c +++ b/src/libgit2/blame.c @@ -72,6 +72,8 @@ static git_blame_hunk *new_hunk( hunk->final_start_line_number = start; hunk->orig_start_line_number = orig_start; hunk->orig_path = path ? git__strdup(path) : NULL; + git_oid_clear(&hunk->orig_commit_id, GIT_OID_SHA1); + git_oid_clear(&hunk->final_commit_id, GIT_OID_SHA1); return hunk; } diff --git a/src/libgit2/blob.c b/src/libgit2/blob.c index b1680d3a8..5cfd7474b 100644 --- a/src/libgit2/blob.c +++ b/src/libgit2/blob.c @@ -52,11 +52,12 @@ void git_blob__free(void *_blob) git__free(blob); } -int git_blob__parse_raw(void *_blob, const char *data, size_t size) +int git_blob__parse_raw(void *_blob, const char *data, size_t size, git_oid_t oid_type) { git_blob *blob = (git_blob *) _blob; GIT_ASSERT_ARG(blob); + GIT_UNUSED(oid_type); blob->raw = 1; blob->data.raw.data = data; @@ -64,11 +65,12 @@ int git_blob__parse_raw(void *_blob, const char *data, size_t size) return 0; } -int git_blob__parse(void *_blob, git_odb_object *odb_obj) +int git_blob__parse(void *_blob, git_odb_object *odb_obj, git_oid_t oid_type) { git_blob *blob = (git_blob *) _blob; GIT_ASSERT_ARG(blob); + GIT_UNUSED(oid_type); git_cached_obj_incref((git_cached_obj *)odb_obj); blob->raw = 0; diff --git a/src/libgit2/blob.h b/src/libgit2/blob.h index 9a5dda225..d6c9dd99b 100644 --- a/src/libgit2/blob.h +++ b/src/libgit2/blob.h @@ -36,8 +36,8 @@ struct git_blob { } while(0) void git_blob__free(void *blob); -int git_blob__parse(void *blob, git_odb_object *obj); -int git_blob__parse_raw(void *blob, const char *data, size_t size); +int git_blob__parse(void *blob, git_odb_object *obj, git_oid_t oid_type); +int git_blob__parse_raw(void *blob, const char *data, size_t size, git_oid_t oid_type); int git_blob__getbuf(git_str *buffer, git_blob *blob); extern int git_blob__create_from_paths( diff --git a/src/libgit2/branch.c b/src/libgit2/branch.c index 2dd7d2bb4..4cbd1e26f 100644 --- a/src/libgit2/branch.c +++ b/src/libgit2/branch.c @@ -134,9 +134,9 @@ int git_branch_create( const git_commit *commit, int force) { - char commit_id[GIT_OID_HEXSZ + 1]; + char commit_id[GIT_OID_SHA1_HEXSIZE + 1]; - git_oid_tostr(commit_id, GIT_OID_HEXSZ + 1, git_commit_id(commit)); + git_oid_tostr(commit_id, GIT_OID_SHA1_HEXSIZE + 1, git_commit_id(commit)); return create_branch(ref_out, repository, branch_name, commit, commit_id, force); } diff --git a/src/libgit2/cherrypick.c b/src/libgit2/cherrypick.c index 9ec4962b9..04812b1c6 100644 --- a/src/libgit2/cherrypick.c +++ b/src/libgit2/cherrypick.c @@ -106,10 +106,10 @@ static int cherrypick_state_cleanup(git_repository *repo) static int cherrypick_seterr(git_commit *commit, const char *fmt) { - char commit_oidstr[GIT_OID_HEXSZ + 1]; + char commit_oidstr[GIT_OID_SHA1_HEXSIZE + 1]; git_error_set(GIT_ERROR_CHERRYPICK, fmt, - git_oid_tostr(commit_oidstr, GIT_OID_HEXSZ + 1, git_commit_id(commit))); + git_oid_tostr(commit_oidstr, GIT_OID_SHA1_HEXSIZE + 1, git_commit_id(commit))); return -1; } @@ -173,7 +173,7 @@ int git_cherrypick( git_cherrypick_options opts; git_reference *our_ref = NULL; git_commit *our_commit = NULL; - char commit_oidstr[GIT_OID_HEXSZ + 1]; + char commit_oidstr[GIT_OID_SHA1_HEXSIZE + 1]; const char *commit_msg, *commit_summary; git_str their_label = GIT_STR_INIT; git_index *index = NULL; diff --git a/src/libgit2/clone.c b/src/libgit2/clone.c index 1843875f8..b73880e44 100644 --- a/src/libgit2/clone.c +++ b/src/libgit2/clone.c @@ -282,7 +282,11 @@ static int update_head_to_branch( reflog_message)) < 0) goto cleanup; - if ((retcode = git_remote__default_branch(&default_branch, remote)) < 0) + retcode = git_remote__default_branch(&default_branch, remote); + + if (retcode == GIT_ENOTFOUND) + retcode = 0; + else if (retcode) goto cleanup; if (!git_remote__matching_refspec(remote, git_str_cstr(&default_branch))) @@ -389,12 +393,19 @@ static int checkout_branch(git_repository *repo, git_remote *remote, const git_c return error; } -static int clone_into(git_repository *repo, git_remote *_remote, const git_fetch_options *opts, const git_checkout_options *co_opts, const char *branch) +static int clone_into( + git_repository *repo, + git_remote *_remote, + const git_fetch_options *opts, + const git_checkout_options *co_opts, + const char *branch) { int error; git_str reflog_message = GIT_STR_INIT; + git_remote_connect_options connect_opts = GIT_REMOTE_CONNECT_OPTIONS_INIT; git_fetch_options fetch_opts; git_remote *remote; + git_oid_t oid_type; GIT_ASSERT_ARG(repo); GIT_ASSERT_ARG(_remote); @@ -410,8 +421,25 @@ static int clone_into(git_repository *repo, git_remote *_remote, const git_fetch memcpy(&fetch_opts, opts, sizeof(git_fetch_options)); fetch_opts.update_fetchhead = 0; fetch_opts.download_tags = GIT_REMOTE_DOWNLOAD_TAGS_ALL; + + if ((error = git_remote_connect_options__from_fetch_opts(&connect_opts, remote, &fetch_opts)) < 0) + goto cleanup; + git_str_printf(&reflog_message, "clone: from %s", git_remote_url(remote)); + /* + * Connect to the server so that we can identify the remote + * object format. + */ + + if ((error = git_remote_connect_ext(remote, GIT_DIRECTION_FETCH, + &connect_opts)) < 0) + goto cleanup; + + if ((error = git_remote_oid_type(&oid_type, remote)) < 0 || + (error = git_repository__set_objectformat(repo, oid_type)) < 0) + goto cleanup; + if ((error = git_remote_fetch(remote, NULL, &fetch_opts, git_str_cstr(&reflog_message))) != 0) goto cleanup; @@ -419,6 +447,7 @@ static int clone_into(git_repository *repo, git_remote *_remote, const git_fetch cleanup: git_remote_free(remote); + git_remote_connect_options_dispose(&connect_opts); git_str_dispose(&reflog_message); return error; diff --git a/src/libgit2/commit.c b/src/libgit2/commit.c index b137463f3..d85fefb3d 100644 --- a/src/libgit2/commit.c +++ b/src/libgit2/commit.c @@ -56,11 +56,13 @@ static int git_commit__create_buffer_internal( GIT_ASSERT_ARG(out); GIT_ASSERT_ARG(tree); - git_oid__writebuf(out, "tree ", tree); + if (git_object__write_oid_header(out, "tree ", tree) < 0) + goto on_error; for (i = 0; i < git_array_size(*parents); i++) { parent = git_array_get(*parents, i); - git_oid__writebuf(out, "parent ", parent); + if (git_object__write_oid_header(out, "parent ", parent) < 0) + goto on_error; } git_signature__writebuf(out, "author ", author); @@ -388,7 +390,11 @@ int git_commit_amend( return error; } -static int commit_parse(git_commit *commit, const char *data, size_t size, unsigned int flags) +static int commit_parse( + git_commit *commit, + const char *data, + size_t size, + git_commit__parse_options *opts) { const char *buffer_start = data, *buffer; const char *buffer_end = buffer_start + size; @@ -399,6 +405,7 @@ static int commit_parse(git_commit *commit, const char *data, size_t size, unsig GIT_ASSERT_ARG(commit); GIT_ASSERT_ARG(data); + GIT_ASSERT_ARG(opts); buffer = buffer_start; @@ -407,11 +414,14 @@ static int commit_parse(git_commit *commit, const char *data, size_t size, unsig GIT_ERROR_CHECK_ARRAY(commit->parent_ids); /* The tree is always the first field */ - if (!(flags & GIT_COMMIT_PARSE_QUICK)) { - if (git_oid__parse(&commit->tree_id, &buffer, buffer_end, "tree ") < 0) + if (!(opts->flags & GIT_COMMIT_PARSE_QUICK)) { + if (git_object__parse_oid_header(&commit->tree_id, + &buffer, buffer_end, "tree ", + opts->oid_type) < 0) goto bad_buffer; } else { - size_t tree_len = strlen("tree ") + GIT_OID_HEXSZ + 1; + size_t tree_len = strlen("tree ") + git_oid_hexsize(opts->oid_type) + 1; + if (buffer + tree_len > buffer_end) goto bad_buffer; buffer += tree_len; @@ -421,14 +431,16 @@ static int commit_parse(git_commit *commit, const char *data, size_t size, unsig * TODO: commit grafts! */ - while (git_oid__parse(&parent_id, &buffer, buffer_end, "parent ") == 0) { + while (git_object__parse_oid_header(&parent_id, + &buffer, buffer_end, "parent ", + opts->oid_type) == 0) { git_oid *new_id = git_array_alloc(commit->parent_ids); GIT_ERROR_CHECK_ALLOC(new_id); git_oid_cpy(new_id, &parent_id); } - if (!(flags & GIT_COMMIT_PARSE_QUICK)) { + if (!opts || !(opts->flags & GIT_COMMIT_PARSE_QUICK)) { commit->author = git__malloc(sizeof(git_signature)); GIT_ERROR_CHECK_ALLOC(commit->author); @@ -452,7 +464,7 @@ static int commit_parse(git_commit *commit, const char *data, size_t size, unsig if ((error = git_signature__parse(commit->committer, &buffer, buffer_end, "committer ", '\n')) < 0) return error; - if (flags & GIT_COMMIT_PARSE_QUICK) + if (opts && opts->flags & GIT_COMMIT_PARSE_QUICK) return 0; /* Parse add'l header entries */ @@ -497,19 +509,39 @@ bad_buffer: return GIT_EINVALID; } -int git_commit__parse_raw(void *commit, const char *data, size_t size) +int git_commit__parse( + void *commit, + git_odb_object *odb_obj, + git_oid_t oid_type) { - return commit_parse(commit, data, size, 0); + git_commit__parse_options parse_options = {0}; + parse_options.oid_type = oid_type; + + return git_commit__parse_ext(commit, odb_obj, &parse_options); } -int git_commit__parse_ext(git_commit *commit, git_odb_object *odb_obj, unsigned int flags) +int git_commit__parse_raw( + void *commit, + const char *data, + size_t size, + git_oid_t oid_type) { - return commit_parse(commit, git_odb_object_data(odb_obj), git_odb_object_size(odb_obj), flags); + git_commit__parse_options parse_options = {0}; + parse_options.oid_type = oid_type; + + return commit_parse(commit, data, size, &parse_options); } -int git_commit__parse(void *_commit, git_odb_object *odb_obj) +int git_commit__parse_ext( + git_commit *commit, + git_odb_object *odb_obj, + git_commit__parse_options *parse_opts) { - return git_commit__parse_ext(_commit, odb_obj, 0); + return commit_parse( + commit, + git_odb_object_data(odb_obj), + git_odb_object_size(odb_obj), + parse_opts); } #define GIT_COMMIT_GETTER(_rvalue, _name, _return, _invalid) \ @@ -566,7 +598,7 @@ const char *git_commit_summary(git_commit *commit) while (*next && git__isspace_nonlf(*next)) { ++next; } - if (!*next || *next == '\n') + if (!*next || *next == '\n') break; } /* record the beginning of contiguous whitespace runs */ @@ -979,11 +1011,14 @@ int git_commit_create_with_signature( git_str commit = GIT_STR_INIT; git_commit *parsed; git_array_oid_t parents = GIT_ARRAY_INIT; + git_commit__parse_options parse_opts = {0}; + + parse_opts.oid_type = repo->oid_type; /* The first step is to verify that all the tree and parents exist */ parsed = git__calloc(1, sizeof(git_commit)); GIT_ERROR_CHECK_ALLOC(parsed); - if (commit_parse(parsed, commit_content, strlen(commit_content), 0) < 0) { + if (commit_parse(parsed, commit_content, strlen(commit_content), &parse_opts) < 0) { error = -1; goto cleanup; } diff --git a/src/libgit2/commit.h b/src/libgit2/commit.h index 7a2454e61..c25fee327 100644 --- a/src/libgit2/commit.h +++ b/src/libgit2/commit.h @@ -33,6 +33,16 @@ struct git_commit { char *body; }; +typedef struct { + git_oid_t oid_type; + unsigned int flags; +} git_commit__parse_options; + +typedef enum { + /** Only parse parents and committer info */ + GIT_COMMIT_PARSE_QUICK = (1 << 0) +} git_commit__parse_flags; + int git_commit__header_field( git_str *out, const git_commit *commit, @@ -56,14 +66,22 @@ int git_commit__create_buffer( size_t parent_count, const git_commit *parents[]); +int git_commit__parse( + void *commit, + git_odb_object *obj, + git_oid_t oid_type); + +int git_commit__parse_raw( + void *commit, + const char *data, + size_t size, + git_oid_t oid_type); + +int git_commit__parse_ext( + git_commit *commit, + git_odb_object *odb_obj, + git_commit__parse_options *parse_opts); + void git_commit__free(void *commit); -int git_commit__parse(void *commit, git_odb_object *obj); -int git_commit__parse_raw(void *commit, const char *data, size_t size); - -typedef enum { - GIT_COMMIT_PARSE_QUICK = (1 << 0) /**< Only parse parents and committer info */ -} git_commit__parse_flags; - -int git_commit__parse_ext(git_commit *commit, git_odb_object *odb_obj, unsigned int flags); #endif diff --git a/src/libgit2/commit_graph.c b/src/libgit2/commit_graph.c index 10947acec..bf557f7ad 100644 --- a/src/libgit2/commit_graph.c +++ b/src/libgit2/commit_graph.c @@ -138,19 +138,19 @@ static int commit_graph_parse_oid_lookup( struct git_commit_graph_chunk *chunk_oid_lookup) { uint32_t i; - unsigned char *oid, *prev_oid, zero_oid[GIT_OID_RAWSZ] = {0}; + unsigned char *oid, *prev_oid, zero_oid[GIT_OID_SHA1_SIZE] = {0}; if (chunk_oid_lookup->offset == 0) return commit_graph_error("missing OID Lookup chunk"); if (chunk_oid_lookup->length == 0) return commit_graph_error("empty OID Lookup chunk"); - if (chunk_oid_lookup->length != file->num_commits * GIT_OID_RAWSZ) + if (chunk_oid_lookup->length != file->num_commits * GIT_OID_SHA1_SIZE) return commit_graph_error("OID Lookup chunk has wrong length"); file->oid_lookup = oid = (unsigned char *)(data + chunk_oid_lookup->offset); prev_oid = zero_oid; - for (i = 0; i < file->num_commits; ++i, oid += GIT_OID_RAWSZ) { - if (git_oid_raw_cmp(prev_oid, oid) >= 0) + for (i = 0; i < file->num_commits; ++i, oid += GIT_OID_SHA1_SIZE) { + if (git_oid_raw_cmp(prev_oid, oid, GIT_OID_SHA1_SIZE) >= 0) return commit_graph_error("OID Lookup index is non-monotonic"); prev_oid = oid; } @@ -167,7 +167,7 @@ static int commit_graph_parse_commit_data( return commit_graph_error("missing Commit Data chunk"); if (chunk_commit_data->length == 0) return commit_graph_error("empty Commit Data chunk"); - if (chunk_commit_data->length != file->num_commits * (GIT_OID_RAWSZ + 16)) + if (chunk_commit_data->length != file->num_commits * (GIT_OID_SHA1_SIZE + 16)) return commit_graph_error("Commit Data chunk has wrong length"); file->commit_data = data + chunk_commit_data->offset; @@ -200,8 +200,7 @@ int git_commit_graph_file_parse( const unsigned char *chunk_hdr; struct git_commit_graph_chunk *last_chunk; uint32_t i; - off64_t last_chunk_offset, chunk_offset, trailer_offset; - unsigned char checksum[GIT_HASH_SHA1_SIZE]; + uint64_t last_chunk_offset, chunk_offset, trailer_offset; size_t checksum_size; int error; struct git_commit_graph_chunk chunk_oid_fanout = {0}, chunk_oid_lookup = {0}, @@ -210,7 +209,7 @@ int git_commit_graph_file_parse( GIT_ASSERT_ARG(file); - if (size < sizeof(struct git_commit_graph_header) + GIT_OID_RAWSZ) + if (size < sizeof(struct git_commit_graph_header) + GIT_OID_SHA1_SIZE) return commit_graph_error("commit-graph is too short"); hdr = ((struct git_commit_graph_header *)data); @@ -227,23 +226,18 @@ int git_commit_graph_file_parse( * headers, and a special zero chunk. */ last_chunk_offset = sizeof(struct git_commit_graph_header) + (1 + hdr->chunks) * 12; - trailer_offset = size - GIT_OID_RAWSZ; + trailer_offset = size - GIT_OID_SHA1_SIZE; checksum_size = GIT_HASH_SHA1_SIZE; if (trailer_offset < last_chunk_offset) return commit_graph_error("wrong commit-graph size"); memcpy(file->checksum, (data + trailer_offset), checksum_size); - if (git_hash_buf(checksum, data, (size_t)trailer_offset, GIT_HASH_ALGORITHM_SHA1) < 0) - return commit_graph_error("could not calculate signature"); - if (memcmp(checksum, file->checksum, checksum_size) != 0) - return commit_graph_error("index signature mismatch"); - chunk_hdr = data + sizeof(struct git_commit_graph_header); last_chunk = NULL; for (i = 0; i < hdr->chunks; ++i, chunk_hdr += 12) { - chunk_offset = ((off64_t)ntohl(*((uint32_t *)(chunk_hdr + 4)))) << 32 - | ((off64_t)ntohl(*((uint32_t *)(chunk_hdr + 8)))); + chunk_offset = ((uint64_t)ntohl(*((uint32_t *)(chunk_hdr + 4)))) << 32 + | ((uint64_t)ntohl(*((uint32_t *)(chunk_hdr + 8)))); if (chunk_offset < last_chunk_offset) return commit_graph_error("chunks are non-monotonic"); if (chunk_offset >= trailer_offset) @@ -331,9 +325,29 @@ error: return error; } +int git_commit_graph_validate(git_commit_graph *cgraph) { + unsigned char checksum[GIT_HASH_SHA1_SIZE]; + size_t checksum_size = GIT_HASH_SHA1_SIZE; + size_t trailer_offset = cgraph->file->graph_map.len - checksum_size; + + if (cgraph->file->graph_map.len < checksum_size) + return commit_graph_error("map length too small"); + + if (git_hash_buf(checksum, cgraph->file->graph_map.data, trailer_offset, GIT_HASH_ALGORITHM_SHA1) < 0) + return commit_graph_error("could not calculate signature"); + if (memcmp(checksum, cgraph->file->checksum, checksum_size) != 0) + return commit_graph_error("index signature mismatch"); + + return 0; +} + int git_commit_graph_open(git_commit_graph **cgraph_out, const char *objects_dir) { - return git_commit_graph_new(cgraph_out, objects_dir, true); + int error = git_commit_graph_new(cgraph_out, objects_dir, true); + if (!error) { + return git_commit_graph_validate(*cgraph_out); + } + return error; } int git_commit_graph_file_open(git_commit_graph_file **file_out, const char *path) @@ -436,15 +450,15 @@ static int git_commit_graph_entry_get_byindex( return GIT_ENOTFOUND; } - commit_data = file->commit_data + pos * (GIT_OID_RAWSZ + 4 * sizeof(uint32_t)); - git_oid_fromraw(&e->tree_oid, commit_data); - e->parent_indices[0] = ntohl(*((uint32_t *)(commit_data + GIT_OID_RAWSZ))); + commit_data = file->commit_data + pos * (GIT_OID_SHA1_SIZE + 4 * sizeof(uint32_t)); + git_oid__fromraw(&e->tree_oid, commit_data, GIT_OID_SHA1); + e->parent_indices[0] = ntohl(*((uint32_t *)(commit_data + GIT_OID_SHA1_SIZE))); e->parent_indices[1] = ntohl( - *((uint32_t *)(commit_data + GIT_OID_RAWSZ + sizeof(uint32_t)))); + *((uint32_t *)(commit_data + GIT_OID_SHA1_SIZE + sizeof(uint32_t)))); e->parent_count = (e->parent_indices[0] != GIT_COMMIT_GRAPH_MISSING_PARENT) + (e->parent_indices[1] != GIT_COMMIT_GRAPH_MISSING_PARENT); - e->generation = ntohl(*((uint32_t *)(commit_data + GIT_OID_RAWSZ + 2 * sizeof(uint32_t)))); - e->commit_time = ntohl(*((uint32_t *)(commit_data + GIT_OID_RAWSZ + 3 * sizeof(uint32_t)))); + e->generation = ntohl(*((uint32_t *)(commit_data + GIT_OID_SHA1_SIZE + 2 * sizeof(uint32_t)))); + e->commit_time = ntohl(*((uint32_t *)(commit_data + GIT_OID_SHA1_SIZE + 3 * sizeof(uint32_t)))); e->commit_time |= (e->generation & UINT64_C(0x3)) << UINT64_C(32); e->generation >>= 2u; @@ -471,7 +485,7 @@ static int git_commit_graph_entry_get_byindex( } } - git_oid_fromraw(&e->sha1, &file->oid_lookup[pos * GIT_OID_RAWSZ]); + git_oid__fromraw(&e->sha1, &file->oid_lookup[pos * GIT_OID_SHA1_SIZE], GIT_OID_SHA1); return 0; } @@ -524,27 +538,27 @@ int git_commit_graph_entry_find( hi = ntohl(file->oid_fanout[(int)short_oid->id[0]]); lo = ((short_oid->id[0] == 0x0) ? 0 : ntohl(file->oid_fanout[(int)short_oid->id[0] - 1])); - pos = git_pack__lookup_sha1(file->oid_lookup, GIT_OID_RAWSZ, lo, hi, short_oid->id); + pos = git_pack__lookup_id(file->oid_lookup, GIT_OID_SHA1_SIZE, lo, hi, short_oid->id, GIT_OID_SHA1); if (pos >= 0) { /* An object matching exactly the oid was found */ found = 1; - current = file->oid_lookup + (pos * GIT_OID_RAWSZ); + current = file->oid_lookup + (pos * GIT_OID_SHA1_SIZE); } else { /* No object was found */ /* pos refers to the object with the "closest" oid to short_oid */ pos = -1 - pos; if (pos < (int)file->num_commits) { - current = file->oid_lookup + (pos * GIT_OID_RAWSZ); + current = file->oid_lookup + (pos * GIT_OID_SHA1_SIZE); if (!git_oid_raw_ncmp(short_oid->id, current, len)) found = 1; } } - if (found && len != GIT_OID_HEXSZ && pos + 1 < (int)file->num_commits) { + if (found && len != GIT_OID_SHA1_HEXSIZE && pos + 1 < (int)file->num_commits) { /* Check for ambiguousity */ - const unsigned char *next = current + GIT_OID_RAWSZ; + const unsigned char *next = current + GIT_OID_SHA1_SIZE; if (!git_oid_raw_ncmp(short_oid->id, next, len)) found = 2; @@ -712,7 +726,8 @@ int git_commit_graph_writer_add_index_file( if (error < 0) goto cleanup; - error = git_mwindow_get_pack(&p, idx_path); + /* TODO: SHA256 */ + error = git_mwindow_get_pack(&p, idx_path, 0); if (error < 0) goto cleanup; @@ -1020,7 +1035,7 @@ static int commit_graph_write( git_vector_foreach (&w->commits, i, packed_commit) { error = git_str_put(&oid_lookup, (const char *)&packed_commit->sha1.id, - GIT_OID_RAWSZ); + GIT_OID_SHA1_SIZE); if (error < 0) goto cleanup; @@ -1037,7 +1052,7 @@ static int commit_graph_write( error = git_str_put(&commit_data, (const char *)&packed_commit->tree_oid.id, - GIT_OID_RAWSZ); + GIT_OID_SHA1_SIZE); if (error < 0) goto cleanup; diff --git a/src/libgit2/commit_graph.h b/src/libgit2/commit_graph.h index b78ab8177..517abb239 100644 --- a/src/libgit2/commit_graph.h +++ b/src/libgit2/commit_graph.h @@ -106,6 +106,9 @@ struct git_commit_graph { /** Create a new commit-graph, optionally opening the underlying file. */ int git_commit_graph_new(git_commit_graph **cgraph_out, const char *objects_dir, bool open_file); +/** Validate the checksum of a commit graph */ +int git_commit_graph_validate(git_commit_graph *cgraph); + /** Open and validate a commit-graph file. */ int git_commit_graph_file_open(git_commit_graph_file **file_out, const char *path); diff --git a/src/libgit2/commit_list.c b/src/libgit2/commit_list.c index 4585508bc..12b329b25 100644 --- a/src/libgit2/commit_list.c +++ b/src/libgit2/commit_list.c @@ -124,13 +124,17 @@ static int commit_quick_parse( { git_oid *parent_oid; git_commit *commit; + git_commit__parse_options parse_opts = { + GIT_OID_SHA1, + GIT_COMMIT_PARSE_QUICK + }; size_t i; commit = git__calloc(1, sizeof(*commit)); GIT_ERROR_CHECK_ALLOC(commit); commit->object.repo = walk->repo; - if (git_commit__parse_ext(commit, obj, GIT_COMMIT_PARSE_QUICK) < 0) { + if (git_commit__parse_ext(commit, obj, &parse_opts) < 0) { git__free(commit); return -1; } @@ -172,7 +176,7 @@ int git_commit_list_parse(git_revwalk *walk, git_commit_list_node *commit) if (cgraph_file) { git_commit_graph_entry e; - error = git_commit_graph_entry_find(&e, cgraph_file, &commit->oid, GIT_OID_RAWSZ); + error = git_commit_graph_entry_find(&e, cgraph_file, &commit->oid, GIT_OID_SHA1_SIZE); if (error == 0 && git__is_uint16(e.parent_count)) { size_t i; commit->generation = (uint32_t)e.generation; diff --git a/src/libgit2/config.c b/src/libgit2/config.c index 5c366e221..23a8f9ffa 100644 --- a/src/libgit2/config.c +++ b/src/libgit2/config.c @@ -860,7 +860,7 @@ static int git_config__parse_path(git_str *out, const char *value) return -1; } - return git_sysdir_expand_global_file(out, value[1] ? &value[2] : NULL); + return git_sysdir_expand_homedir_file(out, value[1] ? &value[2] : NULL); } return git_str_sets(out, value); @@ -1174,9 +1174,12 @@ int git_config__find_programdata(git_str *path) GIT_FS_PATH_OWNER_CURRENT_USER | GIT_FS_PATH_OWNER_ADMINISTRATOR; bool is_safe; + int error; - if (git_sysdir_find_programdata_file(path, GIT_CONFIG_FILENAME_PROGRAMDATA) < 0 || - git_fs_path_owner_is(&is_safe, path->ptr, owner_level) < 0) + if ((error = git_sysdir_find_programdata_file(path, GIT_CONFIG_FILENAME_PROGRAMDATA)) < 0) + return error; + + if (git_fs_path_owner_is(&is_safe, path->ptr, owner_level) < 0) return -1; if (!is_safe) { diff --git a/src/libgit2/config_file.c b/src/libgit2/config_file.c index 66fcb8ae2..932ca7601 100644 --- a/src/libgit2/config_file.c +++ b/src/libgit2/config_file.c @@ -528,7 +528,7 @@ static int included_path(git_str *out, const char *dir, const char *path) { /* From the user's home */ if (path[0] == '~' && path[1] == '/') - return git_sysdir_expand_global_file(out, &path[1]); + return git_sysdir_expand_homedir_file(out, &path[1]); return git_fs_path_join_unrooted(out, path, dir, NULL); } @@ -616,7 +616,7 @@ static int do_match_gitdir( git_fs_path_dirname_r(&pattern, cfg_file); git_str_joinpath(&pattern, pattern.ptr, condition + 2); } else if (condition[0] == '~' && git_fs_path_is_dirsep(condition[1])) - git_sysdir_expand_global_file(&pattern, condition + 1); + git_sysdir_expand_homedir_file(&pattern, condition + 1); else if (!git_fs_path_is_absolute(condition)) git_str_joinpath(&pattern, "**", condition); else diff --git a/src/libgit2/describe.c b/src/libgit2/describe.c index 1033eac50..3f73d87d6 100644 --- a/src/libgit2/describe.c +++ b/src/libgit2/describe.c @@ -8,7 +8,6 @@ #include "common.h" #include "git2/describe.h" -#include "git2/strarray.h" #include "git2/diff.h" #include "git2/status.h" @@ -19,6 +18,7 @@ #include "refs.h" #include "repository.h" #include "revwalk.h" +#include "strarray.h" #include "tag.h" #include "vector.h" #include "wildmatch.h" @@ -368,7 +368,7 @@ static int find_unique_abbrev_size( if ((error = git_repository_odb__weakptr(&odb, repo)) < 0) return error; - while (size < GIT_OID_HEXSZ) { + while (size < GIT_OID_SHA1_HEXSIZE) { if ((error = git_odb_exists_prefix(&dummy, odb, oid_in, size)) == 0) { *out = (int) size; return 0; @@ -383,7 +383,7 @@ static int find_unique_abbrev_size( } /* If we didn't find any shorter prefix, we have to do the whole thing */ - *out = GIT_OID_HEXSZ; + *out = GIT_OID_SHA1_HEXSIZE; return 0; } @@ -397,7 +397,7 @@ static int show_suffix( { int error, size = 0; - char hex_oid[GIT_OID_HEXSZ]; + char hex_oid[GIT_OID_SHA1_HEXSIZE]; if ((error = find_unique_abbrev_size(&size, repo, id, abbrev_size)) < 0) return error; @@ -414,7 +414,7 @@ static int show_suffix( #define MAX_CANDIDATES_TAGS FLAG_BITS - 1 static int describe_not_found(const git_oid *oid, const char *message_format) { - char oid_str[GIT_OID_HEXSZ + 1]; + char oid_str[GIT_OID_SHA1_HEXSIZE + 1]; git_oid_tostr(oid_str, sizeof(oid_str), oid); git_error_set(GIT_ERROR_DESCRIBE, message_format, oid_str); @@ -525,7 +525,7 @@ static int describe( if (annotated_cnt && (git_pqueue_size(&list) == 0)) { /* if (debug) { - char oid_str[GIT_OID_HEXSZ + 1]; + char oid_str[GIT_OID_SHA1_HEXSIZE + 1]; git_oid_tostr(oid_str, sizeof(oid_str), &c->oid); fprintf(stderr, "finished search at %s\n", oid_str); @@ -592,7 +592,7 @@ static int describe( "head", "lightweight", "annotated", }; - char oid_str[GIT_OID_HEXSZ + 1]; + char oid_str[GIT_OID_SHA1_HEXSIZE + 1]; if (debug) { for (cur_match = 0; cur_match < match_cnt; cur_match++) { @@ -816,7 +816,7 @@ static int git_describe__format( /* If we didn't find *any* tags, we fall back to the commit's id */ if (result->fallback_to_id) { - char hex_oid[GIT_OID_HEXSZ + 1] = {0}; + char hex_oid[GIT_OID_SHA1_HEXSIZE + 1] = {0}; int size = 0; if ((error = find_unique_abbrev_size( diff --git a/src/libgit2/diff.c b/src/libgit2/diff.c index 9840d6050..20a18c4b9 100644 --- a/src/libgit2/diff.c +++ b/src/libgit2/diff.c @@ -290,7 +290,7 @@ static int flush_hunk(git_oid *result, git_hash_ctx *ctx) (error = git_hash_init(ctx)) < 0) return error; - for (i = 0; i < GIT_OID_RAWSZ; i++) { + for (i = 0; i < GIT_OID_SHA1_SIZE; i++) { carry += result->id[i] + hash.id[i]; result->id[i] = (unsigned char)carry; carry >>= 8; @@ -381,6 +381,10 @@ int git_diff_patchid(git_oid *out, git_diff *diff, git_diff_patchid_options *opt if ((error = (flush_hunk(&args.result, &args.ctx))) < 0) goto out; +#ifdef GIT_EXPERIMENTAL_SHA256 + args.result.type = GIT_OID_SHA1; +#endif + git_oid_cpy(out, &args.result); out: diff --git a/src/libgit2/diff_file.c b/src/libgit2/diff_file.c index c7e9fbeee..c2d08675a 100644 --- a/src/libgit2/diff_file.c +++ b/src/libgit2/diff_file.c @@ -144,6 +144,7 @@ int git_diff_file_content__init_from_src( if (!src->blob && !src->buf) { fc->flags |= GIT_DIFF_FLAG__NO_DATA; + git_oid_clear(&fc->file->id, GIT_OID_SHA1); } else { fc->flags |= GIT_DIFF_FLAG__LOADED; fc->file->flags |= GIT_DIFF_FLAG_VALID_ID; @@ -153,7 +154,7 @@ int git_diff_file_content__init_from_src( git_blob_dup((git_blob **)&fc->blob, (git_blob *) src->blob); fc->file->size = git_blob_rawsize(src->blob); git_oid_cpy(&fc->file->id, git_blob_id(src->blob)); - fc->file->id_abbrev = GIT_OID_HEXSZ; + fc->file->id_abbrev = GIT_OID_SHA1_HEXSIZE; fc->map.len = (size_t)fc->file->size; fc->map.data = (char *)git_blob_rawcontent(src->blob); @@ -161,10 +162,10 @@ int git_diff_file_content__init_from_src( fc->flags |= GIT_DIFF_FLAG__FREE_BLOB; } else { int error; - if ((error = git_odb_hash(&fc->file->id, src->buf, src->buflen, GIT_OBJECT_BLOB)) < 0) + if ((error = git_odb__hash(&fc->file->id, src->buf, src->buflen, GIT_OBJECT_BLOB, GIT_OID_SHA1)) < 0) return error; fc->file->size = src->buflen; - fc->file->id_abbrev = GIT_OID_HEXSZ; + fc->file->id_abbrev = GIT_OID_SHA1_HEXSIZE; fc->map.len = src->buflen; fc->map.data = (char *)src->buf; @@ -177,7 +178,7 @@ int git_diff_file_content__init_from_src( static int diff_file_content_commit_to_str( git_diff_file_content *fc, bool check_status) { - char oid[GIT_OID_HEXSZ+1]; + char oid[GIT_OID_SHA1_HEXSIZE+1]; git_str content = GIT_STR_INIT; const char *status = ""; @@ -347,6 +348,13 @@ static int diff_file_content_load_workdir_file( goto cleanup; } + /* if file is empty, don't attempt to mmap or readbuffer */ + if (fc->file->size == 0) { + fc->map.len = 0; + fc->map.data = git_str__initstr; + goto cleanup; + } + if ((diff_opts->flags & GIT_DIFF_SHOW_BINARY) == 0 && diff_file_content_binary_by_size(fc)) goto cleanup; @@ -410,8 +418,9 @@ static int diff_file_content_load_workdir( /* once data is loaded, update OID if we didn't have it previously */ if (!error && (fc->file->flags & GIT_DIFF_FLAG_VALID_ID) == 0) { - error = git_odb_hash( - &fc->file->id, fc->map.data, fc->map.len, GIT_OBJECT_BLOB); + error = git_odb__hash( + &fc->file->id, fc->map.data, fc->map.len, + GIT_OBJECT_BLOB, GIT_OID_SHA1); fc->file->flags |= GIT_DIFF_FLAG_VALID_ID; } diff --git a/src/libgit2/diff_generate.c b/src/libgit2/diff_generate.c index cfaefba66..a88ce8c32 100644 --- a/src/libgit2/diff_generate.c +++ b/src/libgit2/diff_generate.c @@ -61,6 +61,9 @@ static git_diff_delta *diff_delta__alloc( } delta->status = status; + git_oid_clear(&delta->old_file.id, GIT_OID_SHA1); + git_oid_clear(&delta->new_file.id, GIT_OID_SHA1); + return delta; } @@ -188,13 +191,15 @@ static int diff_delta__from_one( delta->old_file.size = entry->file_size; delta->old_file.flags |= GIT_DIFF_FLAG_EXISTS; git_oid_cpy(&delta->old_file.id, &entry->id); - delta->old_file.id_abbrev = GIT_OID_HEXSZ; + git_oid_clear(&delta->new_file.id, GIT_OID_SHA1); + delta->old_file.id_abbrev = GIT_OID_SHA1_HEXSIZE; } else /* ADDED, IGNORED, UNTRACKED */ { delta->new_file.mode = entry->mode; delta->new_file.size = entry->file_size; delta->new_file.flags |= GIT_DIFF_FLAG_EXISTS; + git_oid_clear(&delta->old_file.id, GIT_OID_SHA1); git_oid_cpy(&delta->new_file.id, &entry->id); - delta->new_file.id_abbrev = GIT_OID_HEXSZ; + delta->new_file.id_abbrev = GIT_OID_SHA1_HEXSIZE; } delta->old_file.flags |= GIT_DIFF_FLAG_VALID_ID; @@ -249,14 +254,14 @@ static int diff_delta__from_two( delta->old_file.size = old_entry->file_size; delta->old_file.mode = old_mode; git_oid_cpy(&delta->old_file.id, old_id); - delta->old_file.id_abbrev = GIT_OID_HEXSZ; + delta->old_file.id_abbrev = GIT_OID_SHA1_HEXSIZE; delta->old_file.flags |= GIT_DIFF_FLAG_VALID_ID | GIT_DIFF_FLAG_EXISTS; } if (!git_index_entry_is_conflict(new_entry)) { git_oid_cpy(&delta->new_file.id, new_id); - delta->new_file.id_abbrev = GIT_OID_HEXSZ; + delta->new_file.id_abbrev = GIT_OID_SHA1_HEXSIZE; delta->new_file.size = new_entry->file_size; delta->new_file.mode = new_mode; delta->old_file.flags |= GIT_DIFF_FLAG_EXISTS; @@ -598,6 +603,7 @@ int git_diff__oid_for_file( entry.mode = mode; entry.file_size = (uint32_t)size; entry.path = (char *)path; + git_oid_clear(&entry.id, GIT_OID_SHA1); return git_diff__oid_for_entry(out, diff, &entry, mode, NULL); } @@ -618,7 +624,7 @@ int git_diff__oid_for_entry( GIT_ASSERT(d->type == GIT_DIFF_TYPE_GENERATED); diff = (git_diff_generated *)d; - memset(out, 0, sizeof(*out)); + git_oid_clear(out, GIT_OID_SHA1); if (git_repository_workdir_path(&full_path, diff->base.repo, entry.path) < 0) return -1; @@ -654,7 +660,7 @@ int git_diff__oid_for_entry( git_error_clear(); } } else if (S_ISLNK(mode)) { - error = git_odb__hashlink(out, full_path.ptr); + error = git_odb__hashlink(out, full_path.ptr, GIT_OID_SHA1); diff->base.perf.oid_calculations++; } else if (!git__is_sizet(entry.file_size)) { git_error_set(GIT_ERROR_NOMEMORY, "file size overflow (for 32-bits) on '%s'", @@ -669,7 +675,8 @@ int git_diff__oid_for_entry( error = fd; else { error = git_odb__hashfd_filtered( - out, fd, (size_t)entry.file_size, GIT_OBJECT_BLOB, fl); + out, fd, (size_t)entry.file_size, + GIT_OBJECT_BLOB, GIT_OID_SHA1, fl); p_close(fd); diff->base.perf.oid_calculations++; } @@ -778,7 +785,7 @@ static int maybe_modified( git_diff_generated *diff, diff_in_progress *info) { - git_oid noid; + git_oid noid = GIT_OID_SHA1_ZERO; git_delta_t status = GIT_DELTA_MODIFIED; const git_index_entry *oitem = info->oitem; const git_index_entry *nitem = info->nitem; @@ -792,8 +799,6 @@ static int maybe_modified( if (!diff_pathspec_match(&matched_pathspec, diff, oitem)) return 0; - memset(&noid, 0, sizeof(noid)); - /* on platforms with no symlinks, preserve mode of existing symlinks */ if (S_ISLNK(omode) && S_ISREG(nmode) && new_is_workdir && !(diff->diffcaps & GIT_DIFFCAPS_HAS_SYMLINKS)) @@ -1695,11 +1700,11 @@ int git_diff__commit( *out = NULL; if ((parents = git_commit_parentcount(commit)) > 1) { - char commit_oidstr[GIT_OID_HEXSZ + 1]; + char commit_oidstr[GIT_OID_SHA1_HEXSIZE + 1]; error = -1; git_error_set(GIT_ERROR_INVALID, "commit %s is a merge commit", - git_oid_tostr(commit_oidstr, GIT_OID_HEXSZ + 1, git_commit_id(commit))); + git_oid_tostr(commit_oidstr, GIT_OID_SHA1_HEXSIZE + 1, git_commit_id(commit))); goto on_error; } diff --git a/src/libgit2/diff_print.c b/src/libgit2/diff_print.c index 6c5a2cdc8..3077e11e1 100644 --- a/src/libgit2/diff_print.c +++ b/src/libgit2/diff_print.c @@ -53,8 +53,8 @@ static int diff_print_info_init__common( return -1; } - if (pi->id_strlen > GIT_OID_HEXSZ) - pi->id_strlen = GIT_OID_HEXSZ; + if (pi->id_strlen > GIT_OID_SHA1_HEXSIZE) + pi->id_strlen = GIT_OID_SHA1_HEXSIZE; memset(&pi->line, 0, sizeof(pi->line)); pi->line.old_lineno = -1; @@ -212,7 +212,7 @@ static int diff_print_one_raw( git_str *out = pi->buf; int id_abbrev; char code = git_diff_status_char(delta->status); - char start_oid[GIT_OID_HEXSZ+1], end_oid[GIT_OID_HEXSZ+1]; + char start_oid[GIT_OID_SHA1_HEXSIZE+1], end_oid[GIT_OID_SHA1_HEXSIZE+1]; GIT_UNUSED(progress); @@ -235,7 +235,7 @@ static int diff_print_one_raw( git_oid_tostr(end_oid, pi->id_strlen + 1, &delta->new_file.id); git_str_printf( - out, (pi->id_strlen <= GIT_OID_HEXSZ) ? + out, (pi->id_strlen <= GIT_OID_SHA1_HEXSIZE) ? ":%06o %06o %s... %s... %c" : ":%06o %06o %s %s %c", delta->old_file.mode, delta->new_file.mode, start_oid, end_oid, code); @@ -273,7 +273,7 @@ static int diff_print_oid_range( git_str *out, const git_diff_delta *delta, int id_strlen, bool print_index) { - char start_oid[GIT_OID_HEXSZ+1], end_oid[GIT_OID_HEXSZ+1]; + char start_oid[GIT_OID_SHA1_HEXSIZE+1], end_oid[GIT_OID_SHA1_HEXSIZE+1]; if (delta->old_file.mode && id_strlen > delta->old_file.id_abbrev) { diff --git a/src/libgit2/diff_tform.c b/src/libgit2/diff_tform.c index 913d649b0..8c0c1b7fc 100644 --- a/src/libgit2/diff_tform.c +++ b/src/libgit2/diff_tform.c @@ -364,6 +364,7 @@ static int insert_delete_side_of_split( memset(&deleted->new_file, 0, sizeof(deleted->new_file)); deleted->new_file.path = deleted->old_file.path; deleted->new_file.flags |= GIT_DIFF_FLAG_VALID_ID; + git_oid_clear(&deleted->new_file.id, GIT_OID_SHA1); return git_vector_insert(onto, deleted); } @@ -397,6 +398,7 @@ static int apply_splits_and_deletes( memset(&delta->old_file, 0, sizeof(delta->old_file)); delta->old_file.path = delta->new_file.path; delta->old_file.flags |= GIT_DIFF_FLAG_VALID_ID; + git_oid_clear(&delta->old_file.id, GIT_OID_SHA1); } /* clean up delta before inserting into new list */ @@ -995,6 +997,7 @@ find_best_matches: memset(&src->new_file, 0, sizeof(src->new_file)); src->new_file.path = src->old_file.path; src->new_file.flags |= GIT_DIFF_FLAG_VALID_ID; + git_oid_clear(&src->new_file.id, GIT_OID_SHA1); num_updates++; @@ -1020,6 +1023,7 @@ find_best_matches: memset(&src->old_file, 0, sizeof(src->old_file)); src->old_file.path = src->new_file.path; src->old_file.flags |= GIT_DIFF_FLAG_VALID_ID; + git_oid_clear(&src->old_file.id, GIT_OID_SHA1); src->flags &= ~GIT_DIFF_FLAG__TO_SPLIT; num_rewrites--; diff --git a/src/libgit2/email.c b/src/libgit2/email.c index e19a2928c..0a75021c8 100644 --- a/src/libgit2/email.c +++ b/src/libgit2/email.c @@ -130,11 +130,11 @@ static int append_header( const git_signature *author, git_email_create_options *opts) { - char id[GIT_OID_HEXSZ]; + char id[GIT_OID_SHA1_HEXSIZE]; int error; if ((error = git_oid_fmt(id, commit_id)) < 0 || - (error = git_str_printf(out, "From %.*s %s\n", GIT_OID_HEXSZ, id, EMAIL_TIMESTAMP)) < 0 || + (error = git_str_printf(out, "From %.*s %s\n", GIT_OID_SHA1_HEXSIZE, id, EMAIL_TIMESTAMP)) < 0 || (error = git_str_printf(out, "From: %s <%s>\n", author->name, author->email)) < 0 || (error = append_date(out, &author->when)) < 0 || (error = append_subject(out, patch_idx, patch_count, summary, opts)) < 0) diff --git a/src/libgit2/experimental.h.in b/src/libgit2/experimental.h.in new file mode 100644 index 000000000..25fb14b9d --- /dev/null +++ b/src/libgit2/experimental.h.in @@ -0,0 +1,13 @@ +/* + * Copyright (C) the libgit2 contributors. All rights reserved. + * + * This file is part of libgit2, distributed under the GNU GPL v2 with + * a Linking Exception. For full terms see the included COPYING file. + */ + +#ifndef INCLUDE_experimental_h__ +#define INCLUDE_experimental_h__ + +#cmakedefine GIT_EXPERIMENTAL_SHA256 1 + +#endif diff --git a/src/libgit2/fetch.c b/src/libgit2/fetch.c index e9f30d9bc..003b5198a 100644 --- a/src/libgit2/fetch.c +++ b/src/libgit2/fetch.c @@ -13,6 +13,7 @@ #include "git2/transport.h" #include "git2/sys/remote.h" +#include "oid.h" #include "remote.h" #include "refspec.h" #include "pack.h" @@ -75,7 +76,7 @@ static int maybe_want_oid(git_remote *remote, git_refspec *spec) oid_head = git__calloc(1, sizeof(git_remote_head)); GIT_ERROR_CHECK_ALLOC(oid_head); - git_oid_fromstr(&oid_head->oid, spec->src); + git_oid__fromstr(&oid_head->oid, spec->src, GIT_OID_SHA1); if (spec->dst) { oid_head->name = git__strdup(spec->dst); @@ -94,7 +95,6 @@ static int filter_wants(git_remote *remote, const git_fetch_options *opts) git_remote_head **heads; git_refspec tagspec, head, *spec; int error = 0; - git_odb *odb; size_t i, heads_len; unsigned int remote_caps; unsigned int oid_mask = GIT_REMOTE_CAPABILITY_TIP_OID | @@ -125,9 +125,6 @@ static int filter_wants(git_remote *remote, const git_fetch_options *opts) goto cleanup; } - if ((error = git_repository_odb__weakptr(&odb, remote->repo)) < 0) - goto cleanup; - if ((error = git_remote_ls((const git_remote_head ***)&heads, &heads_len, remote)) < 0 || (error = git_remote_capabilities(&remote_caps, remote)) < 0) goto cleanup; @@ -140,7 +137,7 @@ static int filter_wants(git_remote *remote, const git_fetch_options *opts) /* Handle explicitly specified OID specs */ git_vector_foreach(&remote->active_refspecs, i, spec) { - if (!git_oid__is_hexstr(spec->src)) + if (!git_oid__is_hexstr(spec->src, GIT_OID_SHA1)) continue; if (!(remote_caps & oid_mask)) { diff --git a/src/libgit2/fetchhead.c b/src/libgit2/fetchhead.c index 6511124ef..0ebfe5c43 100644 --- a/src/libgit2/fetchhead.c +++ b/src/libgit2/fetchhead.c @@ -105,7 +105,7 @@ static int fetchhead_ref_write( git_filebuf *file, git_fetchhead_ref *fetchhead_ref) { - char oid[GIT_OID_HEXSZ + 1]; + char oid[GIT_OID_SHA1_HEXSIZE + 1]; const char *type, *name; int head = 0; @@ -113,7 +113,7 @@ static int fetchhead_ref_write( GIT_ASSERT_ARG(fetchhead_ref); git_oid_fmt(oid, &fetchhead_ref->oid); - oid[GIT_OID_HEXSZ] = '\0'; + oid[GIT_OID_SHA1_HEXSIZE] = '\0'; if (git__prefixcmp(fetchhead_ref->ref_name, GIT_REFS_HEADS_DIR) == 0) { type = "branch "; @@ -196,13 +196,13 @@ static int fetchhead_ref_parse( *is_merge = 1; } - if (strlen(oid_str) != GIT_OID_HEXSZ) { + if (strlen(oid_str) != GIT_OID_SHA1_HEXSIZE) { git_error_set(GIT_ERROR_FETCHHEAD, "invalid object ID in FETCH_HEAD line %"PRIuZ, line_num); return -1; } - if (git_oid_fromstr(oid, oid_str) < 0) { + if (git_oid__fromstr(oid, oid_str, GIT_OID_SHA1) < 0) { const git_error *oid_err = git_error_last(); const char *err_msg = oid_err ? oid_err->message : "invalid object ID"; diff --git a/src/libgit2/ident.c b/src/libgit2/ident.c index 53095864e..bf9a4998e 100644 --- a/src/libgit2/ident.c +++ b/src/libgit2/ident.c @@ -42,7 +42,7 @@ static int ident_find_id( static int ident_insert_id( git_str *to, const git_str *from, const git_filter_source *src) { - char oid[GIT_OID_HEXSZ+1]; + char oid[GIT_OID_SHA1_HEXSIZE+1]; const char *id_start, *id_end, *from_end = from->ptr + from->size; size_t need_size; @@ -57,7 +57,7 @@ static int ident_insert_id( return GIT_PASSTHROUGH; need_size = (size_t)(id_start - from->ptr) + - 5 /* "$Id: " */ + GIT_OID_HEXSZ + 2 /* " $" */ + + 5 /* "$Id: " */ + GIT_OID_SHA1_HEXSIZE + 2 /* " $" */ + (size_t)(from_end - id_end); if (git_str_grow(to, need_size) < 0) @@ -65,7 +65,7 @@ static int ident_insert_id( git_str_set(to, from->ptr, (size_t)(id_start - from->ptr)); git_str_put(to, "$Id: ", 5); - git_str_put(to, oid, GIT_OID_HEXSZ); + git_str_put(to, oid, GIT_OID_SHA1_HEXSIZE); git_str_put(to, " $", 2); git_str_put(to, id_end, (size_t)(from_end - id_end)); diff --git a/src/libgit2/index.c b/src/libgit2/index.c index f44c507d3..d4532c005 100644 --- a/src/libgit2/index.c +++ b/src/libgit2/index.c @@ -74,7 +74,7 @@ struct entry_short { uint32_t uid; uint32_t gid; uint32_t file_size; - unsigned char oid[GIT_OID_RAWSZ]; + unsigned char oid[GIT_OID_SHA1_SIZE]; uint16_t flags; char path[1]; /* arbitrary length */ }; @@ -88,7 +88,7 @@ struct entry_long { uint32_t uid; uint32_t gid; uint32_t file_size; - unsigned char oid[GIT_OID_RAWSZ]; + unsigned char oid[GIT_OID_SHA1_SIZE]; uint16_t flags; uint16_t flags_extended; char path[1]; /* arbitrary length */ @@ -2354,14 +2354,16 @@ static int read_reuc(git_index *index, const char *buffer, size_t size) for (i = 0; i < 3; i++) { if (!lost->mode[i]) continue; - if (size < 20) { + if (size < GIT_OID_SHA1_SIZE) { index_entry_reuc_free(lost); return index_error_invalid("reading reuc entry oid"); } - git_oid_fromraw(&lost->oid[i], (const unsigned char *) buffer); - size -= 20; - buffer += 20; + if (git_oid__fromraw(&lost->oid[i], (const unsigned char *) buffer, GIT_OID_SHA1) < 0) + return -1; + + size -= GIT_OID_SHA1_SIZE; + buffer += GIT_OID_SHA1_SIZE; } /* entry was read successfully - insert into reuc vector */ @@ -2482,7 +2484,7 @@ static int read_entry( entry.file_size = ntohl(source.file_size); entry.flags = ntohs(source.flags); - if (git_oid_fromraw(&entry.id, source.oid) < 0) + if (git_oid__fromraw(&entry.id, source.oid, GIT_OID_SHA1) < 0) return -1; if (entry.flags & GIT_INDEX_ENTRY_EXTENDED) { @@ -2805,7 +2807,7 @@ static int write_disk_entry(git_filebuf *file, git_index_entry *entry, const cha ondisk.uid = htonl(entry->uid); ondisk.gid = htonl(entry->gid); ondisk.file_size = htonl((uint32_t)entry->file_size); - git_oid_raw_cpy(ondisk.oid, entry->id.id); + git_oid_raw_cpy(ondisk.oid, entry->id.id, GIT_OID_SHA1_SIZE); ondisk.flags = htons(entry->flags); if (entry->flags & GIT_INDEX_ENTRY_EXTENDED) { @@ -2968,7 +2970,7 @@ static int create_reuc_extension_data(git_str *reuc_buf, git_index_reuc_entry *r } for (i = 0; i < 3; i++) { - if (reuc->mode[i] && (error = git_str_put(reuc_buf, (char *)&reuc->oid[i].id, GIT_OID_RAWSZ)) < 0) + if (reuc->mode[i] && (error = git_str_put(reuc_buf, (char *)&reuc->oid[i].id, GIT_OID_SHA1_SIZE)) < 0) return error; } @@ -3395,7 +3397,6 @@ int git_index_add_all( { int error; git_repository *repo; - git_iterator *wditer = NULL; git_pathspec ps; bool no_fnmatch = (flags & GIT_INDEX_ADD_DISABLE_PATHSPEC_MATCH) != 0; @@ -3421,7 +3422,6 @@ int git_index_add_all( git_error_set_after_callback(error); cleanup: - git_iterator_free(wditer); git_pathspec__clear(&ps); return error; @@ -3509,7 +3509,8 @@ static int index_apply_to_wd_diff(git_index *index, int action, const git_strarr GIT_DIFF_RECURSE_UNTRACKED_DIRS; if (flags == GIT_INDEX_ADD_FORCE) - opts.flags |= GIT_DIFF_INCLUDE_IGNORED; + opts.flags |= GIT_DIFF_INCLUDE_IGNORED | + GIT_DIFF_RECURSE_IGNORED_DIRS; } if ((error = git_diff_index_to_workdir(&diff, repo, index, &opts)) < 0) diff --git a/src/libgit2/indexer.c b/src/libgit2/indexer.c index afb9ce81a..fa55fb5ea 100644 --- a/src/libgit2/indexer.c +++ b/src/libgit2/indexer.c @@ -42,6 +42,7 @@ struct git_indexer { have_delta :1, do_fsync :1, do_verify :1; + git_oid_t oid_type; struct git_pack_header hdr; struct git_pack_file *pack; unsigned int mode; @@ -55,8 +56,8 @@ struct git_indexer { git_vector deltas; unsigned int fanout[256]; git_hash_ctx hash_ctx; - unsigned char checksum[GIT_HASH_SHA1_SIZE]; - char name[(GIT_HASH_SHA1_SIZE * 2) + 1]; + unsigned char checksum[GIT_HASH_MAX_SIZE]; + char name[(GIT_HASH_MAX_SIZE * 2) + 1]; git_indexer_progress_cb progress_cb; void *progress_payload; char objbuf[8*1024]; @@ -68,7 +69,7 @@ struct git_indexer { git_odb *odb; /* Fields for calculating the packfile trailer (hash of everything before it) */ - char inbuf[GIT_OID_RAWSZ]; + char inbuf[GIT_HASH_MAX_SIZE]; size_t inbuf_len; git_hash_ctx trailer; }; @@ -136,17 +137,33 @@ int git_indexer_init_options(git_indexer_options *opts, unsigned int version) } #endif -int git_indexer_new( - git_indexer **out, - const char *prefix, - unsigned int mode, - git_odb *odb, - git_indexer_options *in_opts) +GIT_INLINE(git_hash_algorithm_t) indexer_hash_algorithm(git_indexer *idx) +{ + switch (idx->oid_type) { + case GIT_OID_SHA1: + return GIT_HASH_ALGORITHM_SHA1; +#ifdef GIT_EXPERIMENTAL_SHA256 + case GIT_OID_SHA256: + return GIT_HASH_ALGORITHM_SHA256; +#endif + } + + return GIT_HASH_ALGORITHM_NONE; +} + +static int indexer_new( + git_indexer **out, + const char *prefix, + git_oid_t oid_type, + unsigned int mode, + git_odb *odb, + git_indexer_options *in_opts) { git_indexer_options opts = GIT_INDEXER_OPTIONS_INIT; git_indexer *idx; git_str path = GIT_STR_INIT, tmp_path = GIT_STR_INIT; static const char suff[] = "/pack"; + git_hash_algorithm_t checksum_type; int error, fd = -1; if (in_opts) @@ -154,14 +171,17 @@ int git_indexer_new( idx = git__calloc(1, sizeof(git_indexer)); GIT_ERROR_CHECK_ALLOC(idx); + idx->oid_type = oid_type; idx->odb = odb; idx->progress_cb = opts.progress_cb; idx->progress_payload = opts.progress_cb_payload; idx->mode = mode ? mode : GIT_PACK_FILE_MODE; git_str_init(&idx->entry_data, 0); - if ((error = git_hash_ctx_init(&idx->hash_ctx, GIT_HASH_ALGORITHM_SHA1)) < 0 || - (error = git_hash_ctx_init(&idx->trailer, GIT_HASH_ALGORITHM_SHA1)) < 0 || + checksum_type = indexer_hash_algorithm(idx); + + if ((error = git_hash_ctx_init(&idx->hash_ctx, checksum_type)) < 0 || + (error = git_hash_ctx_init(&idx->trailer, checksum_type)) < 0 || (error = git_oidmap_new(&idx->expected_oids)) < 0) goto cleanup; @@ -179,7 +199,7 @@ int git_indexer_new( if (fd < 0) goto cleanup; - error = git_packfile_alloc(&idx->pack, git_str_cstr(&tmp_path)); + error = git_packfile_alloc(&idx->pack, git_str_cstr(&tmp_path), oid_type); git_str_dispose(&tmp_path); if (error < 0) @@ -208,6 +228,33 @@ cleanup: return -1; } +#ifdef GIT_EXPERIMENTAL_SHA256 +int git_indexer_new( + git_indexer **out, + const char *prefix, + git_oid_t oid_type, + git_indexer_options *opts) +{ + return indexer_new( + out, + prefix, + oid_type, + opts ? opts->mode : 0, + opts ? opts->odb : NULL, + opts); +} +#else +int git_indexer_new( + git_indexer **out, + const char *prefix, + unsigned int mode, + git_odb *odb, + git_indexer_options *opts) +{ + return indexer_new(out, prefix, GIT_OID_SHA1, mode, odb, opts); +} +#endif + void git_indexer__set_fsync(git_indexer *idx, int do_fsync) { idx->do_fsync = !!do_fsync; @@ -272,7 +319,7 @@ static int advance_delta_offset(git_indexer *idx, git_object_t type) GIT_ASSERT_ARG(type == GIT_OBJECT_REF_DELTA || type == GIT_OBJECT_OFS_DELTA); if (type == GIT_OBJECT_REF_DELTA) { - idx->off += GIT_OID_RAWSZ; + idx->off += git_oid_size(idx->oid_type); } else { off64_t base_off; int error = get_delta_base(&base_off, idx->pack, &w, &idx->off, type, idx->entry_start); @@ -356,7 +403,7 @@ static int check_object_connectivity(git_indexer *idx, const git_rawobj *obj) obj->type != GIT_OBJECT_TAG) return 0; - if (git_object__from_raw(&object, obj->data, obj->len, obj->type) < 0) { + if (git_object__from_raw(&object, obj->data, obj->len, obj->type, idx->oid_type) < 0) { /* * parse_raw returns EINVALID on invalid data; downgrade * that to a normal -1 error code. @@ -444,6 +491,11 @@ static int store_object(git_indexer *idx) git__free(pentry); goto on_error; } + +#ifdef GIT_EXPERIMENTAL_SHA256 + oid.type = idx->oid_type; +#endif + entry_size = idx->off - entry_start; if (entry_start > UINT31_MAX) { entry->offset = UINT32_MAX; @@ -463,16 +515,16 @@ static int store_object(git_indexer *idx) goto on_error; } - git_oid_cpy(&pentry->sha1, &oid); + git_oid_cpy(&pentry->id, &oid); pentry->offset = entry_start; - if (git_oidmap_exists(idx->pack->idx_cache, &pentry->sha1)) { - git_error_set(GIT_ERROR_INDEXER, "duplicate object %s found in pack", git_oid_tostr_s(&pentry->sha1)); + if (git_oidmap_exists(idx->pack->idx_cache, &pentry->id)) { + git_error_set(GIT_ERROR_INDEXER, "duplicate object %s found in pack", git_oid_tostr_s(&pentry->id)); git__free(pentry); goto on_error; } - if ((error = git_oidmap_set(idx->pack->idx_cache, &pentry->sha1, pentry)) < 0) { + if ((error = git_oidmap_set(idx->pack->idx_cache, &pentry->id, pentry)) < 0) { git__free(pentry); git_error_set_oom(); goto on_error; @@ -517,8 +569,8 @@ static int save_entry(git_indexer *idx, struct entry *entry, struct git_pack_ent pentry->offset = entry_start; - if (git_oidmap_exists(idx->pack->idx_cache, &pentry->sha1) || - git_oidmap_set(idx->pack->idx_cache, &pentry->sha1, pentry) < 0) { + if (git_oidmap_exists(idx->pack->idx_cache, &pentry->id) || + git_oidmap_set(idx->pack->idx_cache, &pentry->id, pentry) < 0) { git_error_set(GIT_ERROR_INDEXER, "cannot insert object into pack"); return -1; } @@ -544,7 +596,7 @@ static int hash_and_save(git_indexer *idx, git_rawobj *obj, off64_t entry_start) entry = git__calloc(1, sizeof(*entry)); GIT_ERROR_CHECK_ALLOC(entry); - if (git_odb__hashobj(&oid, obj) < 0) { + if (git_odb__hashobj(&oid, obj, idx->oid_type) < 0) { git_error_set(GIT_ERROR_INDEXER, "failed to hash object"); goto on_error; } @@ -552,7 +604,7 @@ static int hash_and_save(git_indexer *idx, git_rawobj *obj, off64_t entry_start) pentry = git__calloc(1, sizeof(struct git_pack_entry)); GIT_ERROR_CHECK_ALLOC(pentry); - git_oid_cpy(&pentry->sha1, &oid); + git_oid_cpy(&pentry->id, &oid); git_oid_cpy(&entry->oid, &oid); entry->crc = crc32(0L, Z_NULL, 0); @@ -578,34 +630,38 @@ static int do_progress_callback(git_indexer *idx, git_indexer_progress *stats) return 0; } -/* Hash everything but the last 20B of input */ +/* Hash everything but the checksum trailer */ static void hash_partially(git_indexer *idx, const uint8_t *data, size_t size) { size_t to_expell, to_keep; + size_t oid_size = git_oid_size(idx->oid_type); if (size == 0) return; - /* Easy case, dump the buffer and the data minus the last 20 bytes */ - if (size >= GIT_OID_RAWSZ) { + /* + * Easy case, dump the buffer and the data minus the trailing + * checksum (SHA1 or SHA256). + */ + if (size >= oid_size) { git_hash_update(&idx->trailer, idx->inbuf, idx->inbuf_len); - git_hash_update(&idx->trailer, data, size - GIT_OID_RAWSZ); + git_hash_update(&idx->trailer, data, size - oid_size); - data += size - GIT_OID_RAWSZ; - memcpy(idx->inbuf, data, GIT_OID_RAWSZ); - idx->inbuf_len = GIT_OID_RAWSZ; + data += size - oid_size; + memcpy(idx->inbuf, data, oid_size); + idx->inbuf_len = oid_size; return; } /* We can just append */ - if (idx->inbuf_len + size <= GIT_OID_RAWSZ) { + if (idx->inbuf_len + size <= oid_size) { memcpy(idx->inbuf + idx->inbuf_len, data, size); idx->inbuf_len += size; return; } /* We need to partially drain the buffer and then append */ - to_keep = GIT_OID_RAWSZ - size; + to_keep = oid_size - size; to_expell = idx->inbuf_len - to_keep; git_hash_update(&idx->trailer, idx->inbuf, to_expell); @@ -724,12 +780,14 @@ static int read_stream_object(git_indexer *idx, git_indexer_progress *stats) { git_packfile_stream *stream = &idx->stream; off64_t entry_start = idx->off; - size_t entry_size; + size_t oid_size, entry_size; git_object_t type; git_mwindow *w = NULL; int error; - if (idx->pack->mwf.size <= idx->off + 20) + oid_size = git_oid_size(idx->oid_type); + + if (idx->pack->mwf.size <= idx->off + (long long)oid_size) return GIT_EBUFS; if (!idx->have_stream) { @@ -900,7 +958,7 @@ static int index_path(git_str *path, git_indexer *idx, const char *suffix) slash--; if (git_str_grow(path, slash + 1 + strlen(prefix) + - GIT_OID_HEXSZ + strlen(suffix) + 1) < 0) + git_oid_hexsize(idx->oid_type) + strlen(suffix) + 1) < 0) return -1; git_str_truncate(path, slash); @@ -917,7 +975,7 @@ static int index_path(git_str *path, git_indexer *idx, const char *suffix) */ static int seek_back_trailer(git_indexer *idx) { - idx->pack->mwf.size -= GIT_OID_RAWSZ; + idx->pack->mwf.size -= git_oid_size(idx->oid_type); return git_mwindow_free_all(&idx->pack->mwf); } @@ -926,15 +984,17 @@ static int inject_object(git_indexer *idx, git_oid *id) git_odb_object *obj = NULL; struct entry *entry = NULL; struct git_pack_entry *pentry = NULL; - unsigned char empty_checksum[GIT_HASH_SHA1_SIZE] = {0}; + unsigned char empty_checksum[GIT_HASH_MAX_SIZE] = {0}; unsigned char hdr[64]; git_str buf = GIT_STR_INIT; off64_t entry_start; const void *data; size_t len, hdr_len; - size_t checksum_size = GIT_HASH_SHA1_SIZE; + size_t checksum_size; int error; + checksum_size = git_hash_size(indexer_hash_algorithm(idx)); + if ((error = seek_back_trailer(idx)) < 0) goto cleanup; @@ -977,12 +1037,12 @@ static int inject_object(git_indexer *idx, git_oid *id) if ((error = append_to_pack(idx, empty_checksum, checksum_size)) < 0) goto cleanup; - idx->pack->mwf.size += GIT_OID_RAWSZ; + idx->pack->mwf.size += git_oid_size(idx->oid_type); pentry = git__calloc(1, sizeof(struct git_pack_entry)); GIT_ERROR_CHECK_ALLOC(pentry); - git_oid_cpy(&pentry->sha1, id); + git_oid_cpy(&pentry->id, id); git_oid_cpy(&entry->oid, id); idx->off = entry_start + hdr_len + len; @@ -1040,13 +1100,13 @@ static int fix_thin_pack(git_indexer *idx, git_indexer_progress *stats) } /* curpos now points to the base information, which is an OID */ - base_info = git_mwindow_open(&idx->pack->mwf, &w, curpos, GIT_OID_RAWSZ, &left); + base_info = git_mwindow_open(&idx->pack->mwf, &w, curpos, git_oid_size(idx->oid_type), &left); if (base_info == NULL) { git_error_set(GIT_ERROR_INDEXER, "failed to map delta information"); return -1; } - git_oid_fromraw(&base, base_info); + git_oid__fromraw(&base, base_info, idx->oid_type); git_mwindow_close(&w); if (has_entry(idx, &base)) @@ -1168,10 +1228,10 @@ int git_indexer_commit(git_indexer *idx, git_indexer_progress *stats) struct git_pack_idx_header hdr; git_str filename = GIT_STR_INIT; struct entry *entry; - unsigned char checksum[GIT_HASH_SHA1_SIZE]; + unsigned char checksum[GIT_HASH_MAX_SIZE]; git_filebuf index_file = {0}; void *packfile_trailer; - size_t checksum_size = GIT_HASH_SHA1_SIZE; + size_t checksum_size; bool mismatch; if (!idx->parsed_header) { @@ -1179,6 +1239,9 @@ int git_indexer_commit(git_indexer *idx, git_indexer_progress *stats) return -1; } + checksum_size = git_hash_size(indexer_hash_algorithm(idx)); + GIT_ASSERT(checksum_size); + /* Test for this before resolve_deltas(), as it plays with idx->off */ if (idx->off + (ssize_t)checksum_size < idx->pack->mwf.size) { git_error_set(GIT_ERROR_INDEXER, "unexpected data at the end of the pack"); @@ -1269,7 +1332,7 @@ int git_indexer_commit(git_indexer *idx, git_indexer_progress *stats) /* Write out the object names (SHA-1 hashes) */ git_vector_foreach(&idx->objects, i, entry) { - git_filebuf_write(&index_file, &entry->oid.id, GIT_OID_RAWSZ); + git_filebuf_write(&index_file, &entry->oid.id, git_oid_size(idx->oid_type)); } /* Write out the CRC32 values */ diff --git a/src/libgit2/iterator.c b/src/libgit2/iterator.c index bc6f766ce..1ee8e25f5 100644 --- a/src/libgit2/iterator.c +++ b/src/libgit2/iterator.c @@ -1271,7 +1271,7 @@ static int filesystem_iterator_entry_hash( int error; if (S_ISDIR(entry->st.st_mode)) { - memset(&entry->id, 0, GIT_OID_RAWSZ); + memset(&entry->id, 0, GIT_OID_SHA1_SIZE); return 0; } @@ -1281,7 +1281,7 @@ static int filesystem_iterator_entry_hash( if (!(error = git_str_joinpath(&fullpath, iter->root, entry->path)) && !(error = git_path_validate_str_length(iter->base.repo, &fullpath))) - error = git_odb_hashfile(&entry->id, fullpath.ptr, GIT_OBJECT_BLOB); + error = git_odb__hashfile(&entry->id, fullpath.ptr, GIT_OBJECT_BLOB, GIT_OID_SHA1); git_str_dispose(&fullpath); return error; @@ -1529,6 +1529,8 @@ static void filesystem_iterator_set_current( if (iter->base.flags & GIT_ITERATOR_INCLUDE_HASH) git_oid_cpy(&iter->entry.id, &entry->id); + else + git_oid_clear(&iter->entry.id, GIT_OID_SHA1); iter->entry.path = entry->path; diff --git a/src/libgit2/libgit2.c b/src/libgit2/libgit2.c index 2fda0722e..f225122e5 100644 --- a/src/libgit2/libgit2.c +++ b/src/libgit2/libgit2.c @@ -414,6 +414,25 @@ int git_libgit2_opts(int key, ...) git_repository__validate_ownership = (va_arg(ap, int) != 0); break; + case GIT_OPT_GET_HOMEDIR: + { + git_buf *out = va_arg(ap, git_buf *); + git_str str = GIT_STR_INIT; + const git_str *tmp; + + if ((error = git_buf_tostr(&str, out)) < 0 || + (error = git_sysdir_get(&tmp, GIT_SYSDIR_HOME)) < 0 || + (error = git_str_put(&str, tmp->ptr, tmp->size)) < 0) + break; + + error = git_buf_fromstr(out, &str); + } + break; + + case GIT_OPT_SET_HOMEDIR: + error = git_sysdir_set(GIT_SYSDIR_HOME, va_arg(ap, const char *)); + break; + default: git_error_set(GIT_ERROR_INVALID, "invalid option key"); error = -1; diff --git a/src/libgit2/merge.c b/src/libgit2/merge.c index 641b32632..df2cefb29 100644 --- a/src/libgit2/merge.c +++ b/src/libgit2/merge.c @@ -611,13 +611,13 @@ int git_repository_mergehead_foreach( buffer = merge_head_file.ptr; while ((line = git__strsep(&buffer, "\n")) != NULL) { - if (strlen(line) != GIT_OID_HEXSZ) { + if (strlen(line) != GIT_OID_SHA1_HEXSIZE) { git_error_set(GIT_ERROR_INVALID, "unable to parse OID - invalid length"); error = -1; goto cleanup; } - if ((error = git_oid_fromstr(&oid, line)) < 0) + if ((error = git_oid__fromstr(&oid, line, GIT_OID_SHA1)) < 0) goto cleanup; if ((error = cb(&oid, payload)) != 0) { @@ -1061,7 +1061,7 @@ static int index_entry_similarity_calc( const git_merge_options *opts) { git_blob *blob; - git_diff_file diff_file = {{{0}}}; + git_diff_file diff_file = { GIT_OID_SHA1_ZERO }; git_object_size_t blobsize; int error; diff --git a/src/libgit2/midx.c b/src/libgit2/midx.c index 67eab9acb..b09055237 100644 --- a/src/libgit2/midx.c +++ b/src/libgit2/midx.c @@ -115,19 +115,19 @@ static int midx_parse_oid_lookup( struct git_midx_chunk *chunk_oid_lookup) { uint32_t i; - unsigned char *oid, *prev_oid, zero_oid[GIT_OID_RAWSZ] = {0}; + unsigned char *oid, *prev_oid, zero_oid[GIT_OID_SHA1_SIZE] = {0}; if (chunk_oid_lookup->offset == 0) return midx_error("missing OID Lookup chunk"); if (chunk_oid_lookup->length == 0) return midx_error("empty OID Lookup chunk"); - if (chunk_oid_lookup->length != idx->num_objects * GIT_OID_RAWSZ) + if (chunk_oid_lookup->length != idx->num_objects * GIT_OID_SHA1_SIZE) return midx_error("OID Lookup chunk has wrong length"); idx->oid_lookup = oid = (unsigned char *)(data + chunk_oid_lookup->offset); prev_oid = zero_oid; - for (i = 0; i < idx->num_objects; ++i, oid += GIT_OID_RAWSZ) { - if (git_oid_raw_cmp(prev_oid, oid) >= 0) + for (i = 0; i < idx->num_objects; ++i, oid += GIT_OID_SHA1_SIZE) { + if (git_oid_raw_cmp(prev_oid, oid, GIT_OID_SHA1_SIZE) >= 0) return midx_error("OID Lookup index is non-monotonic"); prev_oid = oid; } @@ -188,7 +188,7 @@ int git_midx_parse( GIT_ASSERT_ARG(idx); - if (size < sizeof(struct git_midx_header) + GIT_OID_RAWSZ) + if (size < sizeof(struct git_midx_header) + GIT_OID_SHA1_SIZE) return midx_error("multi-pack index is too short"); hdr = ((struct git_midx_header *)data); @@ -365,7 +365,7 @@ bool git_midx_needs_refresh( } checksum_size = GIT_HASH_SHA1_SIZE; - bytes_read = p_pread(fd, checksum, checksum_size, st.st_size - GIT_OID_RAWSZ); + bytes_read = p_pread(fd, checksum, checksum_size, st.st_size - GIT_OID_SHA1_SIZE); p_close(fd); if (bytes_read != (ssize_t)checksum_size) @@ -392,27 +392,27 @@ int git_midx_entry_find( hi = ntohl(idx->oid_fanout[(int)short_oid->id[0]]); lo = ((short_oid->id[0] == 0x0) ? 0 : ntohl(idx->oid_fanout[(int)short_oid->id[0] - 1])); - pos = git_pack__lookup_sha1(idx->oid_lookup, GIT_OID_RAWSZ, lo, hi, short_oid->id); + pos = git_pack__lookup_id(idx->oid_lookup, GIT_OID_SHA1_SIZE, lo, hi, short_oid->id, GIT_OID_SHA1); if (pos >= 0) { /* An object matching exactly the oid was found */ found = 1; - current = idx->oid_lookup + (pos * GIT_OID_RAWSZ); + current = idx->oid_lookup + (pos * GIT_OID_SHA1_SIZE); } else { /* No object was found */ /* pos refers to the object with the "closest" oid to short_oid */ pos = -1 - pos; if (pos < (int)idx->num_objects) { - current = idx->oid_lookup + (pos * GIT_OID_RAWSZ); + current = idx->oid_lookup + (pos * GIT_OID_SHA1_SIZE); if (!git_oid_raw_ncmp(short_oid->id, current, len)) found = 1; } } - if (found && len != GIT_OID_HEXSZ && pos + 1 < (int)idx->num_objects) { + if (found && len != GIT_OID_SHA1_HEXSIZE && pos + 1 < (int)idx->num_objects) { /* Check for ambiguousity */ - const unsigned char *next = current + GIT_OID_RAWSZ; + const unsigned char *next = current + GIT_OID_SHA1_SIZE; if (!git_oid_raw_ncmp(short_oid->id, next, len)) found = 2; @@ -443,7 +443,7 @@ int git_midx_entry_find( return midx_error("invalid index into the packfile names table"); e->pack_index = pack_index; e->offset = offset; - git_oid_fromraw(&e->sha1, current); + git_oid__fromraw(&e->sha1, current, GIT_OID_SHA1); return 0; } @@ -459,7 +459,7 @@ int git_midx_foreach_entry( GIT_ASSERT_ARG(idx); for (i = 0; i < idx->num_objects; ++i) { - if ((error = git_oid_fromraw(&oid, &idx->oid_lookup[i * GIT_OID_RAWSZ])) < 0) + if ((error = git_oid__fromraw(&oid, &idx->oid_lookup[i * GIT_OID_SHA1_SIZE], GIT_OID_SHA1)) < 0) return error; if ((error = cb(&oid, data)) != 0) @@ -549,7 +549,8 @@ int git_midx_writer_add( if (error < 0) return error; - error = git_mwindow_get_pack(&p, git_str_cstr(&idx_path_buf)); + /* TODO: SHA256 */ + error = git_mwindow_get_pack(&p, git_str_cstr(&idx_path_buf), 0); git_str_dispose(&idx_path_buf); if (error < 0) return error; @@ -748,7 +749,7 @@ static int midx_write( /* Fill the OID Lookup table. */ git_vector_foreach (&object_entries, i, entry) { - error = git_str_put(&oid_lookup, (char *)&entry->sha1.id, GIT_OID_RAWSZ); + error = git_str_put(&oid_lookup, (char *)&entry->sha1.id, GIT_OID_SHA1_SIZE); if (error < 0) goto cleanup; } diff --git a/src/libgit2/mwindow.c b/src/libgit2/mwindow.c index ad649490a..b8295d9d1 100644 --- a/src/libgit2/mwindow.c +++ b/src/libgit2/mwindow.c @@ -61,7 +61,10 @@ int git_mwindow_global_init(void) return git_runtime_shutdown_register(git_mwindow_global_shutdown); } -int git_mwindow_get_pack(struct git_pack_file **out, const char *path) +int git_mwindow_get_pack( + struct git_pack_file **out, + const char *path, + git_oid_t oid_type) { struct git_pack_file *pack; char *packname; @@ -86,7 +89,7 @@ int git_mwindow_get_pack(struct git_pack_file **out, const char *path) } /* If we didn't find it, we need to create it */ - if ((error = git_packfile_alloc(&pack, path)) < 0) { + if ((error = git_packfile_alloc(&pack, path, oid_type)) < 0) { git_mutex_unlock(&git__mwindow_mutex); return error; } diff --git a/src/libgit2/mwindow.h b/src/libgit2/mwindow.h index e32ab99d4..8e6df2613 100644 --- a/src/libgit2/mwindow.h +++ b/src/libgit2/mwindow.h @@ -48,7 +48,10 @@ void git_mwindow_close(git_mwindow **w_cursor); extern int git_mwindow_global_init(void); struct git_pack_file; /* just declaration to avoid cyclical includes */ -int git_mwindow_get_pack(struct git_pack_file **out, const char *path); +int git_mwindow_get_pack( + struct git_pack_file **out, + const char *path, + git_oid_t oid_type); int git_mwindow_put_pack(struct git_pack_file *pack); #endif diff --git a/src/libgit2/notes.c b/src/libgit2/notes.c index d1a2b0f64..1b1935330 100644 --- a/src/libgit2/notes.c +++ b/src/libgit2/notes.c @@ -460,7 +460,7 @@ int git_note_commit_read( { int error; git_tree *tree = NULL; - char target[GIT_OID_HEXSZ + 1]; + char target[GIT_OID_SHA1_HEXSIZE + 1]; git_oid_tostr(target, sizeof(target), oid); @@ -507,7 +507,7 @@ int git_note_commit_create( { int error; git_tree *tree = NULL; - char target[GIT_OID_HEXSZ + 1]; + char target[GIT_OID_SHA1_HEXSIZE + 1]; git_oid_tostr(target, sizeof(target), oid); @@ -578,7 +578,7 @@ int git_note_commit_remove( { int error; git_tree *tree = NULL; - char target[GIT_OID_HEXSZ + 1]; + char target[GIT_OID_SHA1_HEXSIZE + 1]; git_oid_tostr(target, sizeof(target), oid); @@ -698,12 +698,12 @@ static int process_entry_path( buf.ptr[j] = '\0'; buf.size = j; - if (j != GIT_OID_HEXSZ) { + if (j != GIT_OID_SHA1_HEXSIZE) { /* This is not a note entry */ goto cleanup; } - error = git_oid_fromstr(annotated_object_id, buf.ptr); + error = git_oid__fromstr(annotated_object_id, buf.ptr, GIT_OID_SHA1); cleanup: git_str_dispose(&buf); diff --git a/src/libgit2/object.c b/src/libgit2/object.c index b828f88f6..d87d40cf1 100644 --- a/src/libgit2/object.c +++ b/src/libgit2/object.c @@ -21,15 +21,14 @@ bool git_object__strict_input_validation = true; -extern int git_odb_hash(git_oid *out, const void *data, size_t len, git_object_t type); size_t git_object__size(git_object_t type); typedef struct { const char *str; /* type name string */ size_t size; /* size in bytes of the object structure */ - int (*parse)(void *self, git_odb_object *obj); - int (*parse_raw)(void *self, const char *data, size_t size); + int (*parse)(void *self, git_odb_object *obj, git_oid_t oid_type); + int (*parse_raw)(void *self, const char *data, size_t size, git_oid_t oid_type); void (*free)(void *self); } git_object_def; @@ -61,7 +60,8 @@ int git_object__from_raw( git_object **object_out, const char *data, size_t size, - git_object_t type) + git_object_t object_type, + git_oid_t oid_type) { git_object_def *def; git_object *object; @@ -72,12 +72,15 @@ int git_object__from_raw( *object_out = NULL; /* Validate type match */ - if (type != GIT_OBJECT_BLOB && type != GIT_OBJECT_TREE && type != GIT_OBJECT_COMMIT && type != GIT_OBJECT_TAG) { + if (object_type != GIT_OBJECT_BLOB && + object_type != GIT_OBJECT_TREE && + object_type != GIT_OBJECT_COMMIT && + object_type != GIT_OBJECT_TAG) { git_error_set(GIT_ERROR_INVALID, "the requested type is invalid"); return GIT_ENOTFOUND; } - if ((object_size = git_object__size(type)) == 0) { + if ((object_size = git_object__size(object_type)) == 0) { git_error_set(GIT_ERROR_INVALID, "the requested type is invalid"); return GIT_ENOTFOUND; } @@ -86,15 +89,15 @@ int git_object__from_raw( object = git__calloc(1, object_size); GIT_ERROR_CHECK_ALLOC(object); object->cached.flags = GIT_CACHE_STORE_PARSED; - object->cached.type = type; - if ((error = git_odb_hash(&object->cached.oid, data, size, type)) < 0) + object->cached.type = object_type; + if ((error = git_odb__hash(&object->cached.oid, data, size, object_type, oid_type)) < 0) return error; /* Parse raw object data */ - def = &git_objects_table[type]; + def = &git_objects_table[object_type]; GIT_ASSERT(def->free && def->parse_raw); - if ((error = def->parse_raw(object, data, size)) < 0) { + if ((error = def->parse_raw(object, data, size, oid_type)) < 0) { def->free(object); return error; } @@ -144,7 +147,7 @@ int git_object__from_odb_object( def = &git_objects_table[odb_obj->cached.type]; GIT_ASSERT(def->free && def->parse); - if ((error = def->parse(object, odb_obj)) < 0) { + if ((error = def->parse(object, odb_obj, repo->oid_type)) < 0) { /* * parse returns EINVALID on invalid data; downgrade * that to a normal -1 error code. @@ -193,10 +196,10 @@ int git_object_lookup_prefix( if (error < 0) return error; - if (len > GIT_OID_HEXSZ) - len = GIT_OID_HEXSZ; + if (len > GIT_OID_SHA1_HEXSIZE) + len = GIT_OID_SHA1_HEXSIZE; - if (len == GIT_OID_HEXSZ) { + if (len == GIT_OID_SHA1_HEXSIZE) { git_cached_obj *cached = NULL; /* We want to match the full id : we can first look up in the cache, @@ -230,11 +233,11 @@ int git_object_lookup_prefix( error = git_odb_read(&odb_obj, odb, id); } } else { - git_oid short_oid = {{ 0 }}; + git_oid short_oid = GIT_OID_SHA1_ZERO; git_oid__cpy_prefix(&short_oid, id, len); - /* If len < GIT_OID_HEXSZ (a strict short oid was given), we have + /* If len < GIT_OID_SHA1_HEXSIZE (a strict short oid was given), we have * 2 options : * - We always search in the cache first. If we find that short oid is * ambiguous, we can stop. But in all the other cases, we must then @@ -259,7 +262,7 @@ int git_object_lookup_prefix( } int git_object_lookup(git_object **object_out, git_repository *repo, const git_oid *id, git_object_t type) { - return git_object_lookup_prefix(object_out, repo, id, GIT_OID_HEXSZ, type); + return git_object_lookup_prefix(object_out, repo, id, GIT_OID_SHA1_HEXSIZE, type); } void git_object_free(git_object *object) @@ -358,12 +361,11 @@ static int dereference_object(git_object **dereferenced, git_object *obj) static int peel_error(int error, const git_oid *oid, git_object_t type) { const char *type_name; - char hex_oid[GIT_OID_HEXSZ + 1]; + char hex_oid[GIT_OID_MAX_HEXSIZE + 1]; type_name = git_object_type2string(type); - git_oid_fmt(hex_oid, oid); - hex_oid[GIT_OID_HEXSZ] = '\0'; + git_oid_nfmt(hex_oid, GIT_OID_MAX_HEXSIZE + 1, oid); git_error_set(GIT_ERROR_OBJECT, "the git_object of id '%s' can not be " "successfully peeled into a %s (git_object_t=%i).", hex_oid, type_name, type); @@ -502,7 +504,7 @@ static int git_object__short_id(git_str *out, const git_object *obj) { git_repository *repo; int len = GIT_ABBREV_DEFAULT, error; - git_oid id = {{0}}; + git_oid id = GIT_OID_SHA1_ZERO; git_odb *odb; GIT_ASSERT_ARG(out); @@ -516,12 +518,16 @@ static int git_object__short_id(git_str *out, const git_object *obj) if ((error = git_repository_odb(&odb, repo)) < 0) return error; - while (len < GIT_OID_HEXSZ) { + while (len < GIT_OID_SHA1_HEXSIZE) { /* set up short oid */ memcpy(&id.id, &obj->cached.oid.id, (len + 1) / 2); if (len & 1) id.id[len / 2] &= 0xf0; +#ifdef GIT_EXPERIMENTAL_SHA256 + id.type = GIT_OID_SHA1; +#endif + error = git_odb_exists_prefix(NULL, odb, &id, len); if (error != GIT_EAMBIGUOUS) break; @@ -573,21 +579,29 @@ int git_object_rawcontent_is_valid( int *valid, const char *buf, size_t len, - git_object_t type) + git_object_t object_type +#ifdef GIT_EXPERIMENTAL_SHA256 + , git_oid_t oid_type +#endif + ) { git_object *obj = NULL; int error; +#ifndef GIT_EXPERIMENTAL_SHA256 + git_oid_t oid_type = GIT_OID_SHA1; +#endif + GIT_ASSERT_ARG(valid); GIT_ASSERT_ARG(buf); /* Blobs are always valid; don't bother parsing. */ - if (type == GIT_OBJECT_BLOB) { + if (object_type == GIT_OBJECT_BLOB) { *valid = 1; return 0; } - error = git_object__from_raw(&obj, buf, len, type); + error = git_object__from_raw(&obj, buf, len, object_type, oid_type); git_object_free(obj); if (error == 0) { @@ -600,3 +614,53 @@ int git_object_rawcontent_is_valid( return error; } + +int git_object__parse_oid_header( + git_oid *oid, + const char **buffer_out, + const char *buffer_end, + const char *header, + git_oid_t oid_type) +{ + const size_t sha_len = git_oid_hexsize(oid_type); + const size_t header_len = strlen(header); + + const char *buffer = *buffer_out; + + if (buffer + (header_len + sha_len + 1) > buffer_end) + return -1; + + if (memcmp(buffer, header, header_len) != 0) + return -1; + + if (buffer[header_len + sha_len] != '\n') + return -1; + + if (git_oid__fromstr(oid, buffer + header_len, oid_type) < 0) + return -1; + + *buffer_out = buffer + (header_len + sha_len + 1); + + return 0; +} + +int git_object__write_oid_header( + git_str *buf, + const char *header, + const git_oid *oid) +{ + size_t hex_size = git_oid_hexsize(git_oid_type(oid)); + char hex_oid[GIT_OID_MAX_HEXSIZE]; + + if (!hex_size) { + git_error_set(GIT_ERROR_INVALID, "unknown type"); + return -1; + } + + git_oid_fmt(hex_oid, oid); + git_str_puts(buf, header); + git_str_put(buf, hex_oid, hex_size); + git_str_putc(buf, '\n'); + + return git_str_oom(buf) ? -1 : 0; +} diff --git a/src/libgit2/object.h b/src/libgit2/object.h index 66be57557..a29fdfbf3 100644 --- a/src/libgit2/object.h +++ b/src/libgit2/object.h @@ -33,7 +33,8 @@ int git_object__from_raw( git_object **object_out, const char *data, size_t size, - git_object_t type); + git_object_t object_type, + git_oid_t oid_type); int git_object__from_odb_object( git_object **object_out, @@ -45,9 +46,17 @@ int git_object__resolve_to_type(git_object **obj, git_object_t type); git_object_t git_object_stringn2type(const char *str, size_t len); -int git_oid__parse(git_oid *oid, const char **buffer_out, const char *buffer_end, const char *header); +int git_object__parse_oid_header( + git_oid *oid, + const char **buffer_out, + const char *buffer_end, + const char *header, + git_oid_t oid_type); -void git_oid__writebuf(git_str *buf, const char *header, const git_oid *oid); +int git_object__write_oid_header( + git_str *buf, + const char *header, + const git_oid *oid); bool git_object__is_valid( git_repository *repo, const git_oid *id, git_object_t expected_type); diff --git a/src/libgit2/odb.c b/src/libgit2/odb.c index 7b98c72ee..0fc48035a 100644 --- a/src/libgit2/odb.c +++ b/src/libgit2/odb.c @@ -105,11 +105,12 @@ int git_odb__format_object_header( return 0; } -int git_odb__hashobj(git_oid *id, git_rawobj *obj) +int git_odb__hashobj(git_oid *id, git_rawobj *obj, git_oid_t oid_type) { git_str_vec vec[2]; char header[64]; size_t hdrlen; + git_hash_algorithm_t algorithm; int error; GIT_ASSERT_ARG(id); @@ -120,6 +121,11 @@ int git_odb__hashobj(git_oid *id, git_rawobj *obj) return -1; } + if (!(algorithm = git_oid_algorithm(oid_type))) { + git_error_set(GIT_ERROR_INVALID, "unknown oid type"); + return -1; + } + if (!obj->data && obj->len != 0) { git_error_set(GIT_ERROR_INVALID, "invalid object"); return -1; @@ -134,7 +140,11 @@ int git_odb__hashobj(git_oid *id, git_rawobj *obj) vec[1].data = obj->data; vec[1].len = obj->len; - return git_hash_vec(id->id, vec, 2, GIT_HASH_ALGORITHM_SHA1); +#ifdef GIT_EXPERIMENTAL_SHA256 + id->type = oid_type; +#endif + + return git_hash_vec(id->id, vec, 2, algorithm); } @@ -195,24 +205,35 @@ void git_odb_object_free(git_odb_object *object) git_cached_obj_decref(object); } -int git_odb__hashfd(git_oid *out, git_file fd, size_t size, git_object_t type) +int git_odb__hashfd( + git_oid *out, + git_file fd, + size_t size, + git_object_t object_type, + git_oid_t oid_type) { size_t hdr_len; char hdr[64], buffer[GIT_BUFSIZE_FILEIO]; git_hash_ctx ctx; + git_hash_algorithm_t algorithm; ssize_t read_len = 0; int error = 0; - if (!git_object_typeisloose(type)) { + if (!git_object_typeisloose(object_type)) { git_error_set(GIT_ERROR_INVALID, "invalid object type for hash"); return -1; } - if ((error = git_hash_ctx_init(&ctx, GIT_HASH_ALGORITHM_SHA1)) < 0) + if (!(algorithm = git_oid_algorithm(oid_type))) { + git_error_set(GIT_ERROR_INVALID, "unknown oid type"); + return -1; + } + + if ((error = git_hash_ctx_init(&ctx, algorithm)) < 0) return error; if ((error = git_odb__format_object_header(&hdr_len, hdr, - sizeof(hdr), size, type)) < 0) + sizeof(hdr), size, object_type)) < 0) goto done; if ((error = git_hash_update(&ctx, hdr, hdr_len)) < 0) @@ -237,19 +258,28 @@ int git_odb__hashfd(git_oid *out, git_file fd, size_t size, git_object_t type) error = git_hash_final(out->id, &ctx); +#ifdef GIT_EXPERIMENTAL_SHA256 + out->type = oid_type; +#endif + done: git_hash_ctx_cleanup(&ctx); return error; } int git_odb__hashfd_filtered( - git_oid *out, git_file fd, size_t size, git_object_t type, git_filter_list *fl) + git_oid *out, + git_file fd, + size_t size, + git_object_t object_type, + git_oid_t oid_type, + git_filter_list *fl) { int error; git_str raw = GIT_STR_INIT; if (!fl) - return git_odb__hashfd(out, fd, size, type); + return git_odb__hashfd(out, fd, size, object_type, oid_type); /* size of data is used in header, so we have to read the whole file * into memory to apply filters before beginning to calculate the hash @@ -261,7 +291,7 @@ int git_odb__hashfd_filtered( error = git_filter_list__convert_buf(&post, fl, &raw); if (!error) - error = git_odb_hash(out, post.ptr, post.size, type); + error = git_odb__hash(out, post.ptr, post.size, object_type, oid_type); git_str_dispose(&post); } @@ -269,7 +299,7 @@ int git_odb__hashfd_filtered( return error; } -int git_odb__hashlink(git_oid *out, const char *path) +int git_odb__hashlink(git_oid *out, const char *path, git_oid_t oid_type) { struct stat st; int size; @@ -303,20 +333,24 @@ int git_odb__hashlink(git_oid *out, const char *path) GIT_ASSERT(read_len <= size); link_data[read_len] = '\0'; - result = git_odb_hash(out, link_data, read_len, GIT_OBJECT_BLOB); + result = git_odb__hash(out, link_data, read_len, GIT_OBJECT_BLOB, oid_type); git__free(link_data); } else { int fd = git_futils_open_ro(path); if (fd < 0) return -1; - result = git_odb__hashfd(out, fd, size, GIT_OBJECT_BLOB); + result = git_odb__hashfd(out, fd, size, GIT_OBJECT_BLOB, oid_type); p_close(fd); } return result; } -int git_odb_hashfile(git_oid *out, const char *path, git_object_t type) +int git_odb__hashfile( + git_oid *out, + const char *path, + git_object_t object_type, + git_oid_t oid_type) { uint64_t size; int fd, error = 0; @@ -333,14 +367,38 @@ int git_odb_hashfile(git_oid *out, const char *path, git_object_t type) goto done; } - error = git_odb__hashfd(out, fd, (size_t)size, type); + error = git_odb__hashfd(out, fd, (size_t)size, object_type, oid_type); done: p_close(fd); return error; } -int git_odb_hash(git_oid *id, const void *data, size_t len, git_object_t type) +#ifdef GIT_EXPERIMENTAL_SHA256 +int git_odb_hashfile( + git_oid *out, + const char *path, + git_object_t object_type, + git_oid_t oid_type) +{ + return git_odb__hashfile(out, path, object_type, oid_type); +} +#else +int git_odb_hashfile( + git_oid *out, + const char *path, + git_object_t object_type) +{ + return git_odb__hashfile(out, path, object_type, GIT_OID_SHA1); +} +#endif + +int git_odb__hash( + git_oid *id, + const void *data, + size_t len, + git_object_t object_type, + git_oid_t oid_type) { git_rawobj raw; @@ -348,11 +406,32 @@ int git_odb_hash(git_oid *id, const void *data, size_t len, git_object_t type) raw.data = (void *)data; raw.len = len; - raw.type = type; + raw.type = object_type; - return git_odb__hashobj(id, &raw); + return git_odb__hashobj(id, &raw, oid_type); } +#ifdef GIT_EXPERIMENTAL_SHA256 +int git_odb_hash( + git_oid *out, + const void *data, + size_t len, + git_object_t object_type, + git_oid_t oid_type) +{ + return git_odb__hash(out, data, len, object_type, oid_type); +} +#else +int git_odb_hash( + git_oid *out, + const void *data, + size_t len, + git_object_t type) +{ + return git_odb__hash(out, data, len, type, GIT_OID_SHA1); +} +#endif + /** * FAKE WSTREAM */ @@ -442,11 +521,28 @@ static int backend_sort_cmp(const void *a, const void *b) return (backend_b->priority - backend_a->priority); } -int git_odb_new(git_odb **out) +static void normalize_options( + git_odb_options *opts, + const git_odb_options *given_opts) +{ + git_odb_options init = GIT_ODB_OPTIONS_INIT; + + if (given_opts) + memcpy(opts, given_opts, sizeof(git_odb_options)); + else + memcpy(opts, &init, sizeof(git_odb_options)); + + if (!opts->oid_type) + opts->oid_type = GIT_OID_DEFAULT; +} + +int git_odb__new(git_odb **out, const git_odb_options *opts) { git_odb *db = git__calloc(1, sizeof(*db)); GIT_ERROR_CHECK_ALLOC(db); + normalize_options(&db->options, opts); + if (git_mutex_init(&db->lock) < 0) { git__free(db); return -1; @@ -468,6 +564,18 @@ int git_odb_new(git_odb **out) return 0; } +#ifdef GIT_EXPERIMENTAL_SHA256 +int git_odb_new(git_odb **out, const git_odb_options *opts) +{ + return git_odb__new(out, opts); +} +#else +int git_odb_new(git_odb **out) +{ + return git_odb__new(out, NULL); +} +#endif + static int add_backend_internal( git_odb *odb, git_odb_backend *backend, int priority, bool is_alternate, ino_t disk_inode) @@ -575,6 +683,8 @@ int git_odb__add_default_backends( struct stat st; ino_t inode; git_odb_backend *loose, *packed; + git_odb_backend_loose_options loose_opts = GIT_ODB_BACKEND_LOOSE_OPTIONS_INIT; + git_odb_backend_pack_options pack_opts = GIT_ODB_BACKEND_PACK_OPTIONS_INIT; /* TODO: inodes are not really relevant on Win32, so we need to find * a cross-platform workaround for this */ @@ -609,14 +719,29 @@ int git_odb__add_default_backends( git_mutex_unlock(&db->lock); #endif + if (db->do_fsync) + loose_opts.flags |= GIT_ODB_BACKEND_LOOSE_FSYNC; + + loose_opts.oid_type = db->options.oid_type; + pack_opts.oid_type = db->options.oid_type; + /* add the loose object backend */ - if (git_odb_backend_loose(&loose, objects_dir, -1, db->do_fsync, 0, 0) < 0 || + if (git_odb__backend_loose(&loose, objects_dir, &loose_opts) < 0 || add_backend_internal(db, loose, git_odb__loose_priority, as_alternates, inode) < 0) return -1; /* add the packed file backend */ - if (git_odb_backend_pack(&packed, objects_dir) < 0 || - add_backend_internal(db, packed, git_odb__packed_priority, as_alternates, inode) < 0) +#ifdef GIT_EXPERIMENTAL_SHA256 + if (git_odb_backend_pack(&packed, objects_dir, &pack_opts) < 0) + return -1; +#else + GIT_UNUSED(pack_opts); + + if (git_odb_backend_pack(&packed, objects_dir) < 0) + return -1; +#endif + + if (add_backend_internal(db, packed, git_odb__packed_priority, as_alternates, inode) < 0) return -1; if (git_mutex_lock(&db->lock) < 0) { @@ -707,7 +832,10 @@ int git_odb_set_commit_graph(git_odb *odb, git_commit_graph *cgraph) return error; } -int git_odb_open(git_odb **out, const char *objects_dir) +int git_odb__open( + git_odb **out, + const char *objects_dir, + const git_odb_options *opts) { git_odb *db; @@ -716,7 +844,7 @@ int git_odb_open(git_odb **out, const char *objects_dir) *out = NULL; - if (git_odb_new(&db) < 0) + if (git_odb__new(&db, opts) < 0) return -1; if (git_odb__add_default_backends(db, objects_dir, 0, 0) < 0) { @@ -728,6 +856,25 @@ int git_odb_open(git_odb **out, const char *objects_dir) return 0; } +#ifdef GIT_EXPERIMENTAL_SHA256 + +int git_odb_open( + git_odb **out, + const char *objects_dir, + const git_odb_options *opts) +{ + return git_odb__open(out, objects_dir, opts); +} + +#else + +int git_odb_open(git_odb **out, const char *objects_dir) +{ + return git_odb__open(out, objects_dir, NULL); +} + +#endif + int git_odb__set_caps(git_odb *odb, int caps) { if (caps == GIT_ODB_CAP_FROM_OWNER) { @@ -914,7 +1061,7 @@ static int odb_exists_prefix_1(git_oid *out, git_odb *db, { size_t i; int error = GIT_ENOTFOUND, num_found = 0; - git_oid last_found = {{0}}, found; + git_oid last_found = GIT_OID_NONE, found; if ((error = git_mutex_lock(&db->lock)) < 0) { git_error_set(GIT_ERROR_ODB, "failed to acquire the odb lock"); @@ -965,7 +1112,7 @@ int git_odb_exists_prefix( git_oid *out, git_odb *db, const git_oid *short_id, size_t len) { int error; - git_oid key = {{0}}; + git_oid key = GIT_OID_NONE; GIT_ASSERT_ARG(db); GIT_ASSERT_ARG(short_id); @@ -973,7 +1120,7 @@ int git_odb_exists_prefix( if (len < GIT_OID_MINPREFIXLEN) return git_odb__error_ambiguous("prefix length too short"); - if (len >= GIT_OID_HEXSZ) { + if (len >= git_oid_hexsize(db->options.oid_type)) { if (git_odb_exists(db, short_id)) { if (out) git_oid_cpy(out, short_id); @@ -1002,11 +1149,13 @@ int git_odb_expand_ids( git_odb_expand_id *ids, size_t count) { - size_t i; + size_t hex_size, i; GIT_ASSERT_ARG(db); GIT_ASSERT_ARG(ids); + hex_size = git_oid_hexsize(db->options.oid_type); + for (i = 0; i < count; i++) { git_odb_expand_id *query = &ids[i]; int error = GIT_EAMBIGUOUS; @@ -1015,13 +1164,13 @@ int git_odb_expand_ids( query->type = GIT_OBJECT_ANY; /* if we have a short OID, expand it first */ - if (query->length >= GIT_OID_MINPREFIXLEN && query->length < GIT_OID_HEXSZ) { + if (query->length >= GIT_OID_MINPREFIXLEN && query->length < hex_size) { git_oid actual_id; error = odb_exists_prefix_1(&actual_id, db, &query->id, query->length, false); if (!error) { git_oid_cpy(&query->id, &actual_id); - query->length = GIT_OID_HEXSZ; + query->length = (unsigned short)hex_size; } } @@ -1029,7 +1178,7 @@ int git_odb_expand_ids( * now we ought to have a 40-char OID, either because we've expanded it * or because the user passed a full OID. Ensure its type is right. */ - if (query->length >= GIT_OID_HEXSZ) { + if (query->length >= hex_size) { git_object_t actual_type; error = odb_otype_fast(&actual_type, db, &query->id); @@ -1049,7 +1198,7 @@ int git_odb_expand_ids( /* the object is missing or ambiguous */ case GIT_ENOTFOUND: case GIT_EAMBIGUOUS: - memset(&query->id, 0, sizeof(git_oid)); + git_oid_clear(&query->id, db->options.oid_type); query->length = 0; query->type = 0; break; @@ -1157,7 +1306,7 @@ int git_odb__read_header_or_object( error = odb_read_header_1(len_p, type_p, db, id, true); if (error == GIT_ENOTFOUND) - return git_odb__error_notfound("cannot read header for", id, GIT_OID_HEXSZ); + return git_odb__error_notfound("cannot read header for", id, git_oid_hexsize(db->options.oid_type)); /* we found the header; return early */ if (!error) @@ -1179,8 +1328,11 @@ int git_odb__read_header_or_object( return error; } -static int odb_read_1(git_odb_object **out, git_odb *db, const git_oid *id, - bool only_refreshed) +static int odb_read_1( + git_odb_object **out, + git_odb *db, + const git_oid *id, + bool only_refreshed) { size_t i; git_rawobj raw; @@ -1224,7 +1376,7 @@ static int odb_read_1(git_odb_object **out, git_odb *db, const git_oid *id, return GIT_ENOTFOUND; if (git_odb__strict_hash_verification) { - if ((error = git_odb_hash(&hashed, raw.data, raw.len, raw.type)) < 0) + if ((error = git_odb__hash(&hashed, raw.data, raw.len, raw.type, db->options.oid_type)) < 0) goto out; if (!git_oid_equal(id, &hashed)) { @@ -1268,7 +1420,7 @@ int git_odb_read(git_odb_object **out, git_odb *db, const git_oid *id) error = odb_read_1(out, db, id, true); if (error == GIT_ENOTFOUND) - return git_odb__error_notfound("no match for id", id, GIT_OID_HEXSZ); + return git_odb__error_notfound("no match for id", id, git_oid_hexsize(git_oid_type(id))); return error; } @@ -1305,7 +1457,7 @@ static int read_prefix_1(git_odb_object **out, git_odb *db, { size_t i; int error = 0; - git_oid found_full_oid = {{0}}; + git_oid found_full_oid = GIT_OID_NONE; git_rawobj raw = {0}; void *data = NULL; bool found = false; @@ -1365,7 +1517,7 @@ static int read_prefix_1(git_odb_object **out, git_odb *db, if (git_odb__strict_hash_verification) { git_oid hash; - if ((error = git_odb_hash(&hash, raw.data, raw.len, raw.type)) < 0) + if ((error = git_odb__hash(&hash, raw.data, raw.len, raw.type, db->options.oid_type)) < 0) goto out; if (!git_oid_equal(&found_full_oid, &hash)) { @@ -1391,19 +1543,22 @@ out: int git_odb_read_prefix( git_odb_object **out, git_odb *db, const git_oid *short_id, size_t len) { - git_oid key = {{0}}; + git_oid key = GIT_OID_NONE; + size_t hex_size; int error; GIT_ASSERT_ARG(out); GIT_ASSERT_ARG(db); + hex_size = git_oid_hexsize(db->options.oid_type); + if (len < GIT_OID_MINPREFIXLEN) return git_odb__error_ambiguous("prefix length too short"); - if (len > GIT_OID_HEXSZ) - len = GIT_OID_HEXSZ; + if (len > hex_size) + len = hex_size; - if (len == GIT_OID_HEXSZ) { + if (len == hex_size) { *out = git_cache_get_raw(odb_cache(db), short_id); if (*out != NULL) return 0; @@ -1463,7 +1618,7 @@ int git_odb_write( GIT_ASSERT_ARG(oid); GIT_ASSERT_ARG(db); - if ((error = git_odb_hash(oid, data, len, type)) < 0) + if ((error = git_odb__hash(oid, data, len, type, db->options.oid_type)) < 0) return error; if (git_oid_is_zero(oid)) @@ -1564,10 +1719,13 @@ int git_odb_open_wstream( ctx = git__malloc(sizeof(git_hash_ctx)); GIT_ERROR_CHECK_ALLOC(ctx); - if ((error = git_hash_ctx_init(ctx, GIT_HASH_ALGORITHM_SHA1)) < 0 || - (error = hash_header(ctx, size, type)) < 0) + if ((error = git_hash_ctx_init(ctx, git_oid_algorithm(db->options.oid_type))) < 0 || + (error = hash_header(ctx, size, type)) < 0) goto done; +#ifdef GIT_EXPERIMENTAL_SHA256 + (*stream)->oid_type = db->options.oid_type; +#endif (*stream)->hash_ctx = ctx; (*stream)->declared_size = size; (*stream)->received_bytes = 0; @@ -1612,6 +1770,10 @@ int git_odb_stream_finalize_write(git_oid *out, git_odb_stream *stream) git_hash_final(out->id, stream->hash_ctx); +#ifdef GIT_EXPERIMENTAL_SHA256 + out->type = stream->oid_type; +#endif + if (git_odb__freshen(stream->backend->odb, out)) return 0; @@ -1786,10 +1948,11 @@ int git_odb_refresh(struct git_odb *db) int git_odb__error_mismatch(const git_oid *expected, const git_oid *actual) { - char expected_oid[GIT_OID_HEXSZ + 1], actual_oid[GIT_OID_HEXSZ + 1]; + char expected_oid[GIT_OID_MAX_HEXSIZE + 1], + actual_oid[GIT_OID_MAX_HEXSIZE + 1]; - git_oid_tostr(expected_oid, sizeof(expected_oid), expected); - git_oid_tostr(actual_oid, sizeof(actual_oid), actual); + git_oid_tostr(expected_oid, git_oid_hexsize(git_oid_type(expected)) + 1, expected); + git_oid_tostr(actual_oid, git_oid_hexsize(git_oid_type(actual)) + 1, actual); git_error_set(GIT_ERROR_ODB, "object hash mismatch - expected %s but got %s", expected_oid, actual_oid); @@ -1801,7 +1964,7 @@ int git_odb__error_notfound( const char *message, const git_oid *oid, size_t oid_len) { if (oid != NULL) { - char oid_str[GIT_OID_HEXSZ + 1]; + char oid_str[GIT_OID_MAX_HEXSIZE + 1]; git_oid_tostr(oid_str, oid_len+1, oid); git_error_set(GIT_ERROR_ODB, "object not found - %s (%.*s)", message, (int) oid_len, oid_str); @@ -1819,7 +1982,7 @@ static int error_null_oid(int error, const char *message) int git_odb__error_ambiguous(const char *message) { - git_error_set(GIT_ERROR_ODB, "ambiguous SHA1 prefix - %s", message); + git_error_set(GIT_ERROR_ODB, "ambiguous OID prefix - %s", message); return GIT_EAMBIGUOUS; } diff --git a/src/libgit2/odb.h b/src/libgit2/odb.h index 5aa4cc84a..7a712e202 100644 --- a/src/libgit2/odb.h +++ b/src/libgit2/odb.h @@ -10,6 +10,7 @@ #include "common.h" #include "git2/odb.h" +#include "git2/odb_backend.h" #include "git2/oid.h" #include "git2/types.h" #include "git2/sys/commit_graph.h" @@ -46,6 +47,7 @@ struct git_odb_object { struct git_odb { git_refcount rc; git_mutex lock; /* protects backends */ + git_odb_options options; git_vector backends; git_cache own_cache; git_commit_graph *cgraph; @@ -72,7 +74,7 @@ int git_odb__add_default_backends( * Hash a git_rawobj internally. * The `git_rawobj` is supposed to be previously initialized */ -int git_odb__hashobj(git_oid *id, git_rawobj *obj); +int git_odb__hashobj(git_oid *id, git_rawobj *obj, git_oid_t oid_type); /* * Format the object header such as it would appear in the on-disk object @@ -89,14 +91,24 @@ int git_odb__format_object_header(size_t *out_len, char *hdr, size_t hdr_size, g * The fd is never closed, not even on error. It must be opened and closed * by the caller */ -int git_odb__hashfd(git_oid *out, git_file fd, size_t size, git_object_t type); +int git_odb__hashfd( + git_oid *out, + git_file fd, + size_t size, + git_object_t object_type, + git_oid_t oid_type); /* * Hash an open file descriptor applying an array of filters * Acts just like git_odb__hashfd with the addition of filters... */ int git_odb__hashfd_filtered( - git_oid *out, git_file fd, size_t len, git_object_t type, git_filter_list *fl); + git_oid *out, + git_file fd, + size_t len, + git_object_t object_type, + git_oid_t oid_type, + git_filter_list *fl); /* * Hash a `path`, assuming it could be a POSIX symlink: if the path is a @@ -106,7 +118,7 @@ int git_odb__hashfd_filtered( * The hash type for this call is always `GIT_OBJECT_BLOB` because * symlinks may only point to blobs. */ -int git_odb__hashlink(git_oid *out, const char *path); +int git_odb__hashlink(git_oid *out, const char *path, git_oid_t oid_type); /** * Generate a GIT_EMISMATCH error for the ODB. @@ -146,4 +158,31 @@ int git_odb__freshen(git_odb *db, const git_oid *id); /* fully free the object; internal method, DO NOT EXPORT */ void git_odb_object__free(void *object); +/* SHA256 support */ + +int git_odb__new(git_odb **out, const git_odb_options *opts); + +int git_odb__open( + git_odb **out, + const char *objects_dir, + const git_odb_options *opts); + +int git_odb__hash( + git_oid *out, + const void *data, + size_t len, + git_object_t object_type, + git_oid_t oid_type); + +int git_odb__hashfile( + git_oid *out, + const char *path, + git_object_t object_type, + git_oid_t oid_type); + +GIT_EXTERN(int) git_odb__backend_loose( + git_odb_backend **out, + const char *objects_dir, + git_odb_backend_loose_options *opts); + #endif diff --git a/src/libgit2/odb_loose.c b/src/libgit2/odb_loose.c index 463e24fa5..51195d357 100644 --- a/src/libgit2/odb_loose.c +++ b/src/libgit2/odb_loose.c @@ -46,10 +46,8 @@ typedef struct { typedef struct loose_backend { git_odb_backend parent; - int object_zlib_level; /** loose object zlib compression level. */ - int fsync_object_files; /** loose object file fsync flag. */ - mode_t object_file_mode; - mode_t object_dir_mode; + git_odb_backend_loose_options options; + size_t oid_hexsize; size_t objects_dirlen; char objects_dir[GIT_FLEX_ARRAY]; @@ -59,13 +57,19 @@ typedef struct loose_backend { * in order to locate objects matching a short oid. */ typedef struct { + loose_backend *backend; + size_t dir_len; - unsigned char short_oid[GIT_OID_HEXSZ]; /* hex formatted oid to match */ + + /* Hex formatted oid to match (and its length) */ + unsigned char short_oid[GIT_OID_MAX_HEXSIZE]; size_t short_oid_len; - int found; /* number of matching - * objects already found */ - unsigned char res_oid[GIT_OID_HEXSZ]; /* hex formatted oid of - * the object found */ + + /* Number of matching objects found so far */ + int found; + + /* Hex formatted oid of the object found */ + unsigned char res_oid[GIT_OID_MAX_HEXSIZE]; } loose_locate_object_state; @@ -78,20 +82,17 @@ typedef struct { static int object_file_name( git_str *name, const loose_backend *be, const git_oid *id) { - size_t alloclen; - - /* expand length for object root + 40 hex sha1 chars + 2 * '/' + '\0' */ - GIT_ERROR_CHECK_ALLOC_ADD(&alloclen, be->objects_dirlen, GIT_OID_HEXSZ); - GIT_ERROR_CHECK_ALLOC_ADD(&alloclen, alloclen, 3); - if (git_str_grow(name, alloclen) < 0) - return -1; + /* append loose object filename: aa/aaa... (41 bytes plus NUL) */ + size_t path_size = be->oid_hexsize + 1; git_str_set(name, be->objects_dir, be->objects_dirlen); git_fs_path_to_dir(name); - /* loose object filename: aa/aaa... (41 bytes) */ + if (git_str_grow_by(name, path_size + 1) < 0) + return -1; + git_oid_pathfmt(name->ptr + name->size, id); - name->size += GIT_OID_HEXSZ + 1; + name->size += path_size; name->ptr[name->size] = '\0'; return 0; @@ -100,7 +101,9 @@ static int object_file_name( static int object_mkdir(const git_str *name, const loose_backend *be) { return git_futils_mkdir_relative( - name->ptr + be->objects_dirlen, be->objects_dir, be->object_dir_mode, + name->ptr + be->objects_dirlen, + be->objects_dir, + be->options.dir_mode, GIT_MKDIR_PATH | GIT_MKDIR_SKIP_LAST | GIT_MKDIR_VERIFY_DIR, NULL); } @@ -461,8 +464,9 @@ static int locate_object( /* Explore an entry of a directory and see if it matches a short oid */ static int fn_locate_object_short_oid(void *state, git_str *pathbuf) { loose_locate_object_state *sstate = (loose_locate_object_state *)state; + size_t hex_size = sstate->backend->oid_hexsize; - if (git_str_len(pathbuf) - sstate->dir_len != GIT_OID_HEXSZ - 2) { + if (git_str_len(pathbuf) - sstate->dir_len != hex_size - 2) { /* Entry cannot be an object. Continue to next entry */ return 0; } @@ -477,7 +481,9 @@ static int fn_locate_object_short_oid(void *state, git_str *pathbuf) { if (!sstate->found) { sstate->res_oid[0] = sstate->short_oid[0]; sstate->res_oid[1] = sstate->short_oid[1]; - memcpy(sstate->res_oid+2, pathbuf->ptr+sstate->dir_len, GIT_OID_HEXSZ-2); + memcpy(sstate->res_oid + 2, + pathbuf->ptr+sstate->dir_len, + hex_size - 2); } sstate->found++; } @@ -503,7 +509,7 @@ static int locate_object_short_oid( int error; /* prealloc memory for OBJ_DIR/xx/xx..38x..xx */ - GIT_ERROR_CHECK_ALLOC_ADD(&alloc_len, dir_len, GIT_OID_HEXSZ); + GIT_ERROR_CHECK_ALLOC_ADD(&alloc_len, dir_len, backend->oid_hexsize); GIT_ERROR_CHECK_ALLOC_ADD(&alloc_len, alloc_len, 3); if (git_str_grow(object_location, alloc_len) < 0) return -1; @@ -527,6 +533,7 @@ static int locate_object_short_oid( return git_odb__error_notfound("no matching loose object for prefix", short_oid, len); + state.backend = backend; state.dir_len = git_str_len(object_location); state.short_oid_len = len; state.found = 0; @@ -545,12 +552,12 @@ static int locate_object_short_oid( return git_odb__error_ambiguous("multiple matches in loose objects"); /* Convert obtained hex formatted oid to raw */ - error = git_oid_fromstr(res_oid, (char *)state.res_oid); + error = git_oid__fromstr(res_oid, (char *)state.res_oid, backend->options.oid_type); if (error) return error; /* Update the location according to the oid obtained */ - GIT_ERROR_CHECK_ALLOC_ADD(&alloc_len, dir_len, GIT_OID_HEXSZ); + GIT_ERROR_CHECK_ALLOC_ADD(&alloc_len, dir_len, backend->oid_hexsize); GIT_ERROR_CHECK_ALLOC_ADD(&alloc_len, alloc_len, 2); git_str_truncate(object_location, dir_len); @@ -559,20 +566,12 @@ static int locate_object_short_oid( git_oid_pathfmt(object_location->ptr + dir_len, res_oid); - object_location->size += GIT_OID_HEXSZ + 1; + object_location->size += backend->oid_hexsize + 1; object_location->ptr[object_location->size] = '\0'; return 0; } - - - - - - - - /*********************************************************** * * LOOSE BACKEND PUBLIC API @@ -595,7 +594,7 @@ static int loose_backend__read_header(size_t *len_p, git_object_t *type_p, git_o if (locate_object(&object_path, (loose_backend *)backend, oid) < 0) { error = git_odb__error_notfound("no matching loose object", - oid, GIT_OID_HEXSZ); + oid, ((struct loose_backend *)backend)->oid_hexsize); } else if ((error = read_header_loose(&raw, &object_path)) == 0) { *len_p = raw.len; *type_p = raw.type; @@ -617,7 +616,7 @@ static int loose_backend__read(void **buffer_p, size_t *len_p, git_object_t *typ if (locate_object(&object_path, (loose_backend *)backend, oid) < 0) { error = git_odb__error_notfound("no matching loose object", - oid, GIT_OID_HEXSZ); + oid, ((struct loose_backend *)backend)->oid_hexsize); } else if ((error = read_loose(&raw, &object_path)) == 0) { *buffer_p = raw.data; *len_p = raw.len; @@ -634,17 +633,19 @@ static int loose_backend__read_prefix( void **buffer_p, size_t *len_p, git_object_t *type_p, - git_odb_backend *backend, + git_odb_backend *_backend, const git_oid *short_oid, size_t len) { + struct loose_backend *backend = (struct loose_backend *)_backend; int error = 0; - GIT_ASSERT_ARG(len >= GIT_OID_MINPREFIXLEN && len <= GIT_OID_HEXSZ); + GIT_ASSERT_ARG(len >= GIT_OID_MINPREFIXLEN && + len <= backend->oid_hexsize); - if (len == GIT_OID_HEXSZ) { + if (len == backend->oid_hexsize) { /* We can fall back to regular read method */ - error = loose_backend__read(buffer_p, len_p, type_p, backend, short_oid); + error = loose_backend__read(buffer_p, len_p, type_p, _backend, short_oid); if (!error) git_oid_cpy(out_oid, short_oid); } else { @@ -703,15 +704,18 @@ static int loose_backend__exists_prefix( } struct foreach_state { + struct loose_backend *backend; size_t dir_len; git_odb_foreach_cb cb; void *data; }; -GIT_INLINE(int) filename_to_oid(git_oid *oid, const char *ptr) +GIT_INLINE(int) filename_to_oid(struct loose_backend *backend, git_oid *oid, const char *ptr) { - int v, i = 0; - if (strlen(ptr) != GIT_OID_HEXSZ+1) + int v; + size_t i = 0; + + if (strlen(ptr) != backend->oid_hexsize + 1) return -1; if (ptr[2] != '/') { @@ -725,7 +729,7 @@ GIT_INLINE(int) filename_to_oid(git_oid *oid, const char *ptr) oid->id[0] = (unsigned char) v; ptr += 3; - for (i = 0; i < 38; i += 2) { + for (i = 0; i < backend->oid_hexsize - 2; i += 2) { v = (git__fromhex(ptr[i]) << 4) | git__fromhex(ptr[i + 1]); if (v < 0) return -1; @@ -733,6 +737,10 @@ GIT_INLINE(int) filename_to_oid(git_oid *oid, const char *ptr) oid->id[1 + i/2] = (unsigned char) v; } +#ifdef GIT_EXPERIMENTAL_SHA256 + oid->type = backend->options.oid_type; +#endif + return 0; } @@ -741,7 +749,7 @@ static int foreach_object_dir_cb(void *_state, git_str *path) git_oid oid; struct foreach_state *state = (struct foreach_state *) _state; - if (filename_to_oid(&oid, path->ptr + state->dir_len) < 0) + if (filename_to_oid(state->backend, &oid, path->ptr + state->dir_len) < 0) return 0; return git_error_set_after_callback_function( @@ -778,6 +786,7 @@ static int loose_backend__foreach(git_odb_backend *_backend, git_odb_foreach_cb return -1; memset(&state, 0, sizeof(state)); + state.backend = backend; state.cb = cb; state.data = data; state.dir_len = git_str_len(&buf); @@ -825,9 +834,10 @@ static void loose_backend__writestream_free(git_odb_stream *_stream) static int filebuf_flags(loose_backend *backend) { int flags = GIT_FILEBUF_TEMPORARY | - (backend->object_zlib_level << GIT_FILEBUF_DEFLATE_SHIFT); + (backend->options.compression_level << GIT_FILEBUF_DEFLATE_SHIFT); - if (backend->fsync_object_files || git_repository__fsync_gitdir) + if ((backend->options.flags & GIT_ODB_BACKEND_LOOSE_FSYNC) || + git_repository__fsync_gitdir) flags |= GIT_FILEBUF_FSYNC; return flags; @@ -863,7 +873,7 @@ static int loose_backend__writestream(git_odb_stream **stream_out, git_odb_backe if (git_str_joinpath(&tmp_path, backend->objects_dir, "tmp_object") < 0 || git_filebuf_open(&stream->fbuf, tmp_path.ptr, filebuf_flags(backend), - backend->object_file_mode) < 0 || + backend->options.file_mode) < 0 || stream->stream.write((git_odb_stream *)stream, hdr, hdrlen) < 0) { git_filebuf_cleanup(&stream->fbuf); @@ -997,6 +1007,7 @@ static int loose_backend__readstream( loose_readstream *stream = NULL; git_hash_ctx *hash_ctx = NULL; git_str object_path = GIT_STR_INIT; + git_hash_algorithm_t algorithm; obj_hdr hdr; int error = 0; @@ -1013,7 +1024,7 @@ static int loose_backend__readstream( if (locate_object(&object_path, backend, oid) < 0) { error = git_odb__error_notfound("no matching loose object", - oid, GIT_OID_HEXSZ); + oid, backend->oid_hexsize); goto done; } @@ -1023,9 +1034,11 @@ static int loose_backend__readstream( hash_ctx = git__malloc(sizeof(git_hash_ctx)); GIT_ERROR_CHECK_ALLOC(hash_ctx); - if ((error = git_hash_ctx_init(hash_ctx, GIT_HASH_ALGORITHM_SHA1)) < 0 || - (error = git_futils_mmap_ro_file(&stream->map, object_path.ptr)) < 0 || - (error = git_zstream_init(&stream->zstream, GIT_ZSTREAM_INFLATE)) < 0) + algorithm = git_oid_algorithm(backend->options.oid_type); + + if ((error = git_hash_ctx_init(hash_ctx, algorithm)) < 0 || + (error = git_futils_mmap_ro_file(&stream->map, object_path.ptr)) < 0 || + (error = git_zstream_init(&stream->zstream, GIT_ZSTREAM_INFLATE)) < 0) goto done; /* check for a packlike loose object */ @@ -1081,7 +1094,7 @@ static int loose_backend__write(git_odb_backend *_backend, const git_oid *oid, c if (git_str_joinpath(&final_path, backend->objects_dir, "tmp_object") < 0 || git_filebuf_open(&fbuf, final_path.ptr, filebuf_flags(backend), - backend->object_file_mode) < 0) + backend->options.file_mode) < 0) { error = -1; goto cleanup; @@ -1124,13 +1137,34 @@ static void loose_backend__free(git_odb_backend *_backend) git__free(_backend); } -int git_odb_backend_loose( +static void normalize_options( + git_odb_backend_loose_options *opts, + const git_odb_backend_loose_options *given_opts) +{ + git_odb_backend_loose_options init = GIT_ODB_BACKEND_LOOSE_OPTIONS_INIT; + + if (given_opts) + memcpy(opts, given_opts, sizeof(git_odb_backend_loose_options)); + else + memcpy(opts, &init, sizeof(git_odb_backend_loose_options)); + + if (opts->compression_level < 0) + opts->compression_level = Z_BEST_SPEED; + + if (opts->dir_mode == 0) + opts->dir_mode = GIT_OBJECT_DIR_MODE; + + if (opts->file_mode == 0) + opts->file_mode = GIT_OBJECT_FILE_MODE; + + if (opts->oid_type == 0) + opts->oid_type = GIT_OID_DEFAULT; +} + +int git_odb__backend_loose( git_odb_backend **backend_out, const char *objects_dir, - int compression_level, - int do_fsync, - unsigned int dir_mode, - unsigned int file_mode) + git_odb_backend_loose_options *opts) { loose_backend *backend; size_t objects_dirlen, alloclen; @@ -1148,22 +1182,12 @@ int git_odb_backend_loose( backend->parent.version = GIT_ODB_BACKEND_VERSION; backend->objects_dirlen = objects_dirlen; memcpy(backend->objects_dir, objects_dir, objects_dirlen); + if (backend->objects_dir[backend->objects_dirlen - 1] != '/') backend->objects_dir[backend->objects_dirlen++] = '/'; - if (compression_level < 0) - compression_level = Z_BEST_SPEED; - - if (dir_mode == 0) - dir_mode = GIT_OBJECT_DIR_MODE; - - if (file_mode == 0) - file_mode = GIT_OBJECT_FILE_MODE; - - backend->object_zlib_level = compression_level; - backend->fsync_object_files = do_fsync; - backend->object_dir_mode = dir_mode; - backend->object_file_mode = file_mode; + normalize_options(&backend->options, opts); + backend->oid_hexsize = git_oid_hexsize(backend->options.oid_type); backend->parent.read = &loose_backend__read; backend->parent.write = &loose_backend__write; @@ -1180,3 +1204,37 @@ int git_odb_backend_loose( *backend_out = (git_odb_backend *)backend; return 0; } + + +#ifdef GIT_EXPERIMENTAL_SHA256 +int git_odb_backend_loose( + git_odb_backend **backend_out, + const char *objects_dir, + git_odb_backend_loose_options *opts) +{ + return git_odb__backend_loose(backend_out, objects_dir, opts); +} +#else +int git_odb_backend_loose( + git_odb_backend **backend_out, + const char *objects_dir, + int compression_level, + int do_fsync, + unsigned int dir_mode, + unsigned int file_mode) +{ + git_odb_backend_loose_flag_t flags = 0; + git_odb_backend_loose_options opts = GIT_ODB_BACKEND_LOOSE_OPTIONS_INIT; + + if (do_fsync) + flags |= GIT_ODB_BACKEND_LOOSE_FSYNC; + + opts.flags = flags; + opts.compression_level = compression_level; + opts.dir_mode = dir_mode; + opts.file_mode = file_mode; + opts.oid_type = GIT_OID_DEFAULT; + + return git_odb__backend_loose(backend_out, objects_dir, &opts); +} +#endif diff --git a/src/libgit2/odb_pack.c b/src/libgit2/odb_pack.c index 818cc6125..1b1d122b0 100644 --- a/src/libgit2/odb_pack.c +++ b/src/libgit2/odb_pack.c @@ -26,6 +26,7 @@ struct pack_backend { git_odb_backend parent; + git_odb_backend_pack_options opts; git_midx_file *midx; git_vector midx_packs; git_vector packs; @@ -95,24 +96,24 @@ struct pack_writepack { * -------------------------------------------------- * * # pack_backend__exists / pack_backend__exists_prefix - * | Check if the given SHA1 oid (or a SHA1 oid prefix) exists in any of the + * | Check if the given oid (or an oid prefix) exists in any of the * | packs that have been loaded for our ODB. * | * |-# pack_entry_find / pack_entry_find_prefix - * | If there is a multi-pack-index present, search the SHA1 oid in that + * | If there is a multi-pack-index present, search the oid in that * | index first. If it is not found there, iterate through all the unindexed * | packs that have been preloaded (starting by the pack where the latest * | object was found) to try to find the OID in one of them. * | * |-# git_midx_entry_find - * | Search for the SHA1 oid in the multi-pack-index. See + * | Search for the oid in the multi-pack-index. See * | * | for specifics on the multi-pack-index format and how do we find * | entries in it. * | * |-# git_pack_entry_find - * | Check the index of an individual unindexed pack to see if the SHA1 - * | OID can be found. If we can find the offset to that SHA1 inside of the + * | Check the index of an individual unindexed pack to see if the + * | OID can be found. If we can find the offset to that inside of the * | index, that means the object is contained inside of the packfile and * | we can stop searching. Before returning, we verify that the * | packfile behind the index we are searching still exists on disk. @@ -141,13 +142,13 @@ struct pack_writepack { * -------------------------------------------------- * * # pack_backend__read / pack_backend__read_prefix - * | Check if the given SHA1 oid (or a SHA1 oid prefix) exists in any of the + * | Check if the given oid (or an oid prefix) exists in any of the * | packs that have been loaded for our ODB. If it does, open the packfile and * | read from it. * | * |-# git_packfile_unpack * Armed with a packfile and the offset within it, we can finally unpack - * the object pointed at by the SHA1 oid. This involves mmapping part of + * the object pointed at by the oid. This involves mmapping part of * the `.pack` file, and uncompressing the object within it (if it is * stored in the undelfitied representation), or finding a base object and * applying some deltas to its uncompressed representation (if it is stored @@ -177,7 +178,7 @@ static int pack_entry_find(struct git_pack_entry *e, * a prefix of an identifier. * Sets GIT_EAMBIGUOUS if short oid is ambiguous. * This method assumes that len is between - * GIT_OID_MINPREFIXLEN and GIT_OID_HEXSZ. + * GIT_OID_MINPREFIXLEN and the hexsize for the hash type. */ static int pack_entry_find_prefix( struct git_pack_entry *e, @@ -251,7 +252,7 @@ static int packfile_load__cb(void *data, git_str *path) if (git_vector_search2(NULL, &backend->packs, packfile_byname_search_cmp, &index_prefix) == 0) return 0; - error = git_mwindow_get_pack(&pack, path->ptr); + error = git_mwindow_get_pack(&pack, path->ptr, backend->opts.oid_type); /* ignore missing .pack file as git does */ if (error == GIT_ENOTFOUND) { @@ -270,33 +271,34 @@ static int pack_entry_find(struct git_pack_entry *e, struct pack_backend *backen { struct git_pack_file *last_found = backend->last_found, *p; git_midx_entry midx_entry; + size_t oid_hexsize = git_oid_hexsize(backend->opts.oid_type); size_t i; if (backend->midx && - git_midx_entry_find(&midx_entry, backend->midx, oid, GIT_OID_HEXSZ) == 0 && + git_midx_entry_find(&midx_entry, backend->midx, oid, oid_hexsize) == 0 && midx_entry.pack_index < git_vector_length(&backend->midx_packs)) { e->offset = midx_entry.offset; - git_oid_cpy(&e->sha1, &midx_entry.sha1); + git_oid_cpy(&e->id, &midx_entry.sha1); e->p = git_vector_get(&backend->midx_packs, midx_entry.pack_index); return 0; } if (last_found && - git_pack_entry_find(e, last_found, oid, GIT_OID_HEXSZ) == 0) + git_pack_entry_find(e, last_found, oid, oid_hexsize) == 0) return 0; git_vector_foreach(&backend->packs, i, p) { if (p == last_found) continue; - if (git_pack_entry_find(e, p, oid, GIT_OID_HEXSZ) == 0) { + if (git_pack_entry_find(e, p, oid, oid_hexsize) == 0) { backend->last_found = p; return 0; } } return git_odb__error_notfound( - "failed to find pack entry", oid, GIT_OID_HEXSZ); + "failed to find pack entry", oid, oid_hexsize); } static int pack_entry_find_prefix( @@ -307,7 +309,7 @@ static int pack_entry_find_prefix( { int error; size_t i; - git_oid found_full_oid = {{0}}; + git_oid found_full_oid = GIT_OID_SHA1_ZERO; bool found = false; struct git_pack_file *last_found = backend->last_found, *p; git_midx_entry midx_entry; @@ -318,9 +320,9 @@ static int pack_entry_find_prefix( return error; if (!error && midx_entry.pack_index < git_vector_length(&backend->midx_packs)) { e->offset = midx_entry.offset; - git_oid_cpy(&e->sha1, &midx_entry.sha1); + git_oid_cpy(&e->id, &midx_entry.sha1); e->p = git_vector_get(&backend->midx_packs, midx_entry.pack_index); - git_oid_cpy(&found_full_oid, &e->sha1); + git_oid_cpy(&found_full_oid, &e->id); found = true; } } @@ -330,9 +332,9 @@ static int pack_entry_find_prefix( if (error == GIT_EAMBIGUOUS) return error; if (!error) { - if (found && git_oid_cmp(&e->sha1, &found_full_oid)) + if (found && git_oid_cmp(&e->id, &found_full_oid)) return git_odb__error_ambiguous("found multiple pack entries"); - git_oid_cpy(&found_full_oid, &e->sha1); + git_oid_cpy(&found_full_oid, &e->id); found = true; } } @@ -345,9 +347,9 @@ static int pack_entry_find_prefix( if (error == GIT_EAMBIGUOUS) return error; if (!error) { - if (found && git_oid_cmp(&e->sha1, &found_full_oid)) + if (found && git_oid_cmp(&e->id, &found_full_oid)) return git_odb__error_ambiguous("found multiple pack entries"); - git_oid_cpy(&found_full_oid, &e->sha1); + git_oid_cpy(&found_full_oid, &e->id); found = true; backend->last_found = p; } @@ -425,7 +427,10 @@ static int process_multi_pack_index_pack( } /* Pack was not found. Allocate a new one. */ - error = git_mwindow_get_pack(&pack, git_str_cstr(&pack_path)); + error = git_mwindow_get_pack( + &pack, + git_str_cstr(&pack_path), + backend->opts.oid_type); git_str_dispose(&pack_path); if (error < 0) return error; @@ -596,32 +601,33 @@ static int pack_backend__read_prefix( void **buffer_p, size_t *len_p, git_object_t *type_p, - git_odb_backend *backend, + git_odb_backend *_backend, const git_oid *short_oid, size_t len) { + struct pack_backend *backend = (struct pack_backend *)_backend; int error = 0; if (len < GIT_OID_MINPREFIXLEN) error = git_odb__error_ambiguous("prefix length too short"); - else if (len >= GIT_OID_HEXSZ) { + else if (len >= git_oid_hexsize(backend->opts.oid_type)) { /* We can fall back to regular read method */ - error = pack_backend__read(buffer_p, len_p, type_p, backend, short_oid); + error = pack_backend__read(buffer_p, len_p, type_p, _backend, short_oid); if (!error) git_oid_cpy(out_oid, short_oid); } else { struct git_pack_entry e; git_rawobj raw = {NULL}; - if ((error = pack_entry_find_prefix( - &e, (struct pack_backend *)backend, short_oid, len)) == 0 && - (error = git_packfile_unpack(&raw, e.p, &e.offset)) == 0) + if ((error = pack_entry_find_prefix(&e, + backend, short_oid, len)) == 0 && + (error = git_packfile_unpack(&raw, e.p, &e.offset)) == 0) { *buffer_p = raw.data; *len_p = raw.len; *type_p = raw.type; - git_oid_cpy(out_oid, &e.sha1); + git_oid_cpy(out_oid, &e.id); } } @@ -642,7 +648,7 @@ static int pack_backend__exists_prefix( struct git_pack_entry e = {0}; error = pack_entry_find_prefix(&e, pb, short_id, len); - git_oid_cpy(out, &e.sha1); + git_oid_cpy(out, &e.id); return error; } @@ -712,6 +718,7 @@ static int pack_backend__writepack(struct git_odb_writepack **out, git_indexer_options opts = GIT_INDEXER_OPTIONS_INIT; struct pack_backend *backend; struct pack_writepack *writepack; + int error; GIT_ASSERT_ARG(out); GIT_ASSERT_ARG(_backend); @@ -726,11 +733,20 @@ static int pack_backend__writepack(struct git_odb_writepack **out, writepack = git__calloc(1, sizeof(struct pack_writepack)); GIT_ERROR_CHECK_ALLOC(writepack); - if (git_indexer_new(&writepack->indexer, - backend->pack_folder, 0, odb, &opts) < 0) { - git__free(writepack); +#ifdef GIT_EXPERIMENTAL_SHA256 + opts.odb = odb; + + error = git_indexer_new(&writepack->indexer, + backend->pack_folder, + backend->opts.oid_type, + &opts); +#else + error = git_indexer_new(&writepack->indexer, + backend->pack_folder, 0, odb, &opts); +#endif + + if (error < 0) return -1; - } writepack->parent.backend = _backend; writepack->parent.append = pack_backend__writepack_append; @@ -840,7 +856,10 @@ static void pack_backend__free(git_odb_backend *_backend) git__free(backend); } -static int pack_backend__alloc(struct pack_backend **out, size_t initial_size) +static int pack_backend__alloc( + struct pack_backend **out, + size_t initial_size, + const git_odb_backend_pack_options *opts) { struct pack_backend *backend = git__calloc(1, sizeof(struct pack_backend)); GIT_ERROR_CHECK_ALLOC(backend); @@ -849,12 +868,19 @@ static int pack_backend__alloc(struct pack_backend **out, size_t initial_size) git__free(backend); return -1; } + if (git_vector_init(&backend->packs, initial_size, packfile_sort__cb) < 0) { git_vector_free(&backend->midx_packs); git__free(backend); return -1; } + if (opts) + memcpy(&backend->opts, opts, sizeof(git_odb_backend_pack_options)); + + if (!backend->opts.oid_type) + backend->opts.oid_type = GIT_OID_DEFAULT; + backend->parent.version = GIT_ODB_BACKEND_VERSION; backend->parent.read = &pack_backend__read; @@ -873,17 +899,31 @@ static int pack_backend__alloc(struct pack_backend **out, size_t initial_size) return 0; } -int git_odb_backend_one_pack(git_odb_backend **backend_out, const char *idx) +#ifdef GIT_EXPERIMENTAL_SHA256 +int git_odb_backend_one_pack( + git_odb_backend **backend_out, + const char *idx, + const git_odb_backend_pack_options *opts) +#else +int git_odb_backend_one_pack( + git_odb_backend **backend_out, + const char *idx) +#endif { struct pack_backend *backend = NULL; struct git_pack_file *packfile = NULL; - if (pack_backend__alloc(&backend, 1) < 0) +#ifndef GIT_EXPERIMENTAL_SHA256 + git_odb_backend_pack_options *opts = NULL; +#endif + + git_oid_t oid_type = opts ? opts->oid_type : 0; + + if (pack_backend__alloc(&backend, 1, opts) < 0) return -1; - if (git_mwindow_get_pack(&packfile, idx) < 0 || - git_vector_insert(&backend->packs, packfile) < 0) - { + if (git_mwindow_get_pack(&packfile, idx, oid_type) < 0 || + git_vector_insert(&backend->packs, packfile) < 0) { pack_backend__free((git_odb_backend *)backend); return -1; } @@ -892,18 +932,30 @@ int git_odb_backend_one_pack(git_odb_backend **backend_out, const char *idx) return 0; } -int git_odb_backend_pack(git_odb_backend **backend_out, const char *objects_dir) +#ifdef GIT_EXPERIMENTAL_SHA256 +int git_odb_backend_pack( + git_odb_backend **backend_out, + const char *objects_dir, + const git_odb_backend_pack_options *opts) +#else +int git_odb_backend_pack( + git_odb_backend **backend_out, + const char *objects_dir) +#endif { int error = 0; struct pack_backend *backend = NULL; git_str path = GIT_STR_INIT; - if (pack_backend__alloc(&backend, 8) < 0) +#ifndef GIT_EXPERIMENTAL_SHA256 + git_odb_backend_pack_options *opts = NULL; +#endif + + if (pack_backend__alloc(&backend, 8, opts) < 0) return -1; if (!(error = git_str_joinpath(&path, objects_dir, "pack")) && - git_fs_path_isdir(git_str_cstr(&path))) - { + git_fs_path_isdir(git_str_cstr(&path))) { backend->pack_folder = git_str_detach(&path); error = pack_backend__refresh((git_odb_backend *)backend); } diff --git a/src/libgit2/oid.c b/src/libgit2/oid.c index fb92174ab..6cc21641d 100644 --- a/src/libgit2/oid.c +++ b/src/libgit2/oid.c @@ -14,13 +14,13 @@ #include const git_oid git_oid__empty_blob_sha1 = - {{ 0xe6, 0x9d, 0xe2, 0x9b, 0xb2, 0xd1, 0xd6, 0x43, 0x4b, 0x8b, - 0x29, 0xae, 0x77, 0x5a, 0xd8, 0xc2, 0xe4, 0x8c, 0x53, 0x91 }}; + GIT_OID_INIT(GIT_OID_SHA1, + { 0xe6, 0x9d, 0xe2, 0x9b, 0xb2, 0xd1, 0xd6, 0x43, 0x4b, 0x8b, + 0x29, 0xae, 0x77, 0x5a, 0xd8, 0xc2, 0xe4, 0x8c, 0x53, 0x91 }); const git_oid git_oid__empty_tree_sha1 = - {{ 0x4b, 0x82, 0x5d, 0xc6, 0x42, 0xcb, 0x6e, 0xb9, 0xa0, 0x60, - 0xe5, 0x4b, 0xf8, 0xd6, 0x92, 0x88, 0xfb, 0xee, 0x49, 0x04 }}; - -static char to_hex[] = "0123456789abcdef"; + GIT_OID_INIT(GIT_OID_SHA1, + { 0x4b, 0x82, 0x5d, 0xc6, 0x42, 0xcb, 0x6e, 0xb9, 0xa0, 0x60, + 0xe5, 0x4b, 0xf8, 0xd6, 0x92, 0x88, 0xfb, 0xee, 0x49, 0x04 }); static int oid_error_invalid(const char *msg) { @@ -28,21 +28,31 @@ static int oid_error_invalid(const char *msg) return -1; } -int git_oid_fromstrn(git_oid *out, const char *str, size_t length) +int git_oid__fromstrn( + git_oid *out, + const char *str, + size_t length, + git_oid_t type) { - size_t p; + size_t size, p; int v; GIT_ASSERT_ARG(out); GIT_ASSERT_ARG(str); + if (!(size = git_oid_size(type))) + return oid_error_invalid("unknown type"); + if (!length) return oid_error_invalid("too short"); - if (length > GIT_OID_HEXSZ) + if (length > git_oid_hexsize(type)) return oid_error_invalid("too long"); - memset(out->id, 0, GIT_OID_RAWSZ); +#ifdef GIT_EXPERIMENTAL_SHA256 + out->type = type; +#endif + memset(out->id, 0, size); for (p = 0; p < length; p++) { v = git__fromhex(str[p]); @@ -55,87 +65,128 @@ int git_oid_fromstrn(git_oid *out, const char *str, size_t length) return 0; } +int git_oid__fromstrp(git_oid *out, const char *str, git_oid_t type) +{ + return git_oid__fromstrn(out, str, strlen(str), type); +} + +int git_oid__fromstr(git_oid *out, const char *str, git_oid_t type) +{ + return git_oid__fromstrn(out, str, git_oid_hexsize(type), type); +} + +#ifdef GIT_EXPERIMENTAL_SHA256 +int git_oid_fromstrn( + git_oid *out, + const char *str, + size_t length, + git_oid_t type) +{ + return git_oid__fromstrn(out, str, length, type); +} + +int git_oid_fromstrp(git_oid *out, const char *str, git_oid_t type) +{ + return git_oid_fromstrn(out, str, strlen(str), type); +} + +int git_oid_fromstr(git_oid *out, const char *str, git_oid_t type) +{ + return git_oid_fromstrn(out, str, git_oid_hexsize(type), type); +} +#else +int git_oid_fromstrn( + git_oid *out, + const char *str, + size_t length) +{ + return git_oid__fromstrn(out, str, length, GIT_OID_SHA1); +} + int git_oid_fromstrp(git_oid *out, const char *str) { - return git_oid_fromstrn(out, str, strlen(str)); + return git_oid__fromstrn(out, str, strlen(str), GIT_OID_SHA1); } int git_oid_fromstr(git_oid *out, const char *str) { - return git_oid_fromstrn(out, str, GIT_OID_HEXSZ); -} - -GIT_INLINE(char) *fmt_one(char *str, unsigned int val) -{ - *str++ = to_hex[val >> 4]; - *str++ = to_hex[val & 0xf]; - return str; + return git_oid__fromstrn(out, str, GIT_OID_SHA1_HEXSIZE, GIT_OID_SHA1); } +#endif int git_oid_nfmt(char *str, size_t n, const git_oid *oid) { - size_t i, max_i; + size_t hex_size; if (!oid) { memset(str, 0, n); return 0; } - if (n > GIT_OID_HEXSZ) { - memset(&str[GIT_OID_HEXSZ], 0, n - GIT_OID_HEXSZ); - n = GIT_OID_HEXSZ; + + if (!(hex_size = git_oid_hexsize(git_oid_type(oid)))) + return oid_error_invalid("unknown type"); + + if (n > hex_size) { + memset(&str[hex_size], 0, n - hex_size); + n = hex_size; } - max_i = n / 2; - - for (i = 0; i < max_i; i++) - str = fmt_one(str, oid->id[i]); - - if (n & 1) - *str++ = to_hex[oid->id[i] >> 4]; - + git_oid_fmt_substr(str, oid, 0, n); return 0; } int git_oid_fmt(char *str, const git_oid *oid) { - return git_oid_nfmt(str, GIT_OID_HEXSZ, oid); + return git_oid_nfmt(str, git_oid_hexsize(git_oid_type(oid)), oid); } int git_oid_pathfmt(char *str, const git_oid *oid) { - size_t i; + size_t hex_size; - str = fmt_one(str, oid->id[0]); - *str++ = '/'; - for (i = 1; i < sizeof(oid->id); i++) - str = fmt_one(str, oid->id[i]); + if (!(hex_size = git_oid_hexsize(git_oid_type(oid)))) + return oid_error_invalid("unknown type"); + git_oid_fmt_substr(str, oid, 0, 2); + str[2] = '/'; + git_oid_fmt_substr(&str[3], oid, 2, (hex_size - 2)); return 0; } char *git_oid_tostr_s(const git_oid *oid) { char *str = GIT_THREADSTATE->oid_fmt; - git_oid_nfmt(str, GIT_OID_HEXSZ + 1, oid); + git_oid_nfmt(str, git_oid_hexsize(git_oid_type(oid)) + 1, oid); return str; } char *git_oid_allocfmt(const git_oid *oid) { - char *str = git__malloc(GIT_OID_HEXSZ + 1); - if (!str) + size_t hex_size = git_oid_hexsize(git_oid_type(oid)); + char *str = git__malloc(hex_size + 1); + + if (!hex_size || !str) return NULL; - git_oid_nfmt(str, GIT_OID_HEXSZ + 1, oid); + + if (git_oid_nfmt(str, hex_size + 1, oid) < 0) { + git__free(str); + return NULL; + } + return str; } char *git_oid_tostr(char *out, size_t n, const git_oid *oid) { + size_t hex_size; + if (!out || n == 0) return ""; - if (n > GIT_OID_HEXSZ + 1) - n = GIT_OID_HEXSZ + 1; + hex_size = oid ? git_oid_hexsize(git_oid_type(oid)) : 0; + + if (n > hex_size + 1) + n = hex_size + 1; git_oid_nfmt(out, n - 1, oid); /* allow room for terminating NUL */ out[n - 1] = '\0'; @@ -143,51 +194,44 @@ char *git_oid_tostr(char *out, size_t n, const git_oid *oid) return out; } -int git_oid__parse( - git_oid *oid, const char **buffer_out, - const char *buffer_end, const char *header) +int git_oid__fromraw(git_oid *out, const unsigned char *raw, git_oid_t type) { - const size_t sha_len = GIT_OID_HEXSZ; - const size_t header_len = strlen(header); + size_t size; - const char *buffer = *buffer_out; - - if (buffer + (header_len + sha_len + 1) > buffer_end) - return -1; - - if (memcmp(buffer, header, header_len) != 0) - return -1; - - if (buffer[header_len + sha_len] != '\n') - return -1; - - if (git_oid_fromstr(oid, buffer + header_len) < 0) - return -1; - - *buffer_out = buffer + (header_len + sha_len + 1); + if (!(size = git_oid_size(type))) + return oid_error_invalid("unknown type"); +#ifdef GIT_EXPERIMENTAL_SHA256 + out->type = type; +#endif + memcpy(out->id, raw, size); return 0; } -void git_oid__writebuf(git_str *buf, const char *header, const git_oid *oid) +#ifdef GIT_EXPERIMENTAL_SHA256 +int git_oid_fromraw(git_oid *out, const unsigned char *raw, git_oid_t type) { - char hex_oid[GIT_OID_HEXSZ]; - - git_oid_fmt(hex_oid, oid); - git_str_puts(buf, header); - git_str_put(buf, hex_oid, GIT_OID_HEXSZ); - git_str_putc(buf, '\n'); + return git_oid__fromraw(out, raw, type); } - +#else int git_oid_fromraw(git_oid *out, const unsigned char *raw) { - memcpy(out->id, raw, sizeof(out->id)); - return 0; + return git_oid__fromraw(out, raw, GIT_OID_SHA1); } +#endif int git_oid_cpy(git_oid *out, const git_oid *src) { - return git_oid_raw_cpy(out->id, src->id); + size_t size; + + if (!(size = git_oid_size(git_oid_type(src)))) + return oid_error_invalid("unknown type"); + +#ifdef GIT_EXPERIMENTAL_SHA256 + out->type = src->type; +#endif + + return git_oid_raw_cpy(out->id, src->id, size); } int git_oid_cmp(const git_oid *a, const git_oid *b) @@ -202,6 +246,11 @@ int git_oid_equal(const git_oid *a, const git_oid *b) int git_oid_ncmp(const git_oid *oid_a, const git_oid *oid_b, size_t len) { +#ifdef GIT_EXPERIMENTAL_SHA256 + if (oid_a->type != oid_b->type) + return oid_a->type - oid_b->type; +#endif + return git_oid_raw_ncmp(oid_a->id, oid_b->id, len); } @@ -209,9 +258,10 @@ int git_oid_strcmp(const git_oid *oid_a, const char *str) { const unsigned char *a; unsigned char strval; + long size = (long)git_oid_size(git_oid_type(oid_a)); int hexval; - for (a = oid_a->id; *str && (a - oid_a->id) < GIT_OID_RAWSZ; ++a) { + for (a = oid_a->id; *str && (a - oid_a->id) < size; ++a) { if ((hexval = git__fromhex(*str++)) < 0) return -1; strval = (unsigned char)(hexval << 4); @@ -235,8 +285,16 @@ int git_oid_streq(const git_oid *oid_a, const char *str) int git_oid_is_zero(const git_oid *oid_a) { const unsigned char *a = oid_a->id; - unsigned int i; - for (i = 0; i < GIT_OID_RAWSZ; ++i, ++a) + size_t size = git_oid_size(git_oid_type(oid_a)), i; + +#ifdef GIT_EXPERIMENTAL_SHA256 + if (!oid_a->type) + return 1; + else if (!size) + return 0; +#endif + + for (i = 0; i < size; ++i, ++a) if (*a != 0) return 0; return 1; @@ -393,7 +451,7 @@ int git_oid_shorten_add(git_oid_shorten *os, const char *text_oid) idx = 0; is_leaf = false; - for (i = 0; i < GIT_OID_HEXSZ; ++i) { + for (i = 0; i < GIT_OID_SHA1_HEXSIZE; ++i) { int c = git__fromhex(text_oid[i]); trie_node *node; diff --git a/src/libgit2/oid.h b/src/libgit2/oid.h index abae9a4b2..7b6b09d8b 100644 --- a/src/libgit2/oid.h +++ b/src/libgit2/oid.h @@ -9,11 +9,120 @@ #include "common.h" +#include "git2/experimental.h" #include "git2/oid.h" +#include "hash.h" + +#ifdef GIT_EXPERIMENTAL_SHA256 +# define GIT_OID_NONE { 0, { 0 } } +# define GIT_OID_INIT(type, ...) { type, __VA_ARGS__ } +#else +# define GIT_OID_NONE { { 0 } } +# define GIT_OID_INIT(type, ...) { __VA_ARGS__ } +#endif extern const git_oid git_oid__empty_blob_sha1; extern const git_oid git_oid__empty_tree_sha1; +GIT_INLINE(git_oid_t) git_oid_type(const git_oid *oid) +{ +#ifdef GIT_EXPERIMENTAL_SHA256 + return oid->type; +#else + GIT_UNUSED(oid); + return GIT_OID_SHA1; +#endif +} + +GIT_INLINE(size_t) git_oid_size(git_oid_t type) +{ + switch (type) { + case GIT_OID_SHA1: + return GIT_OID_SHA1_SIZE; + +#ifdef GIT_EXPERIMENTAL_SHA256 + case GIT_OID_SHA256: + return GIT_OID_SHA256_SIZE; +#endif + + } + + return 0; +} + +GIT_INLINE(size_t) git_oid_hexsize(git_oid_t type) +{ + switch (type) { + case GIT_OID_SHA1: + return GIT_OID_SHA1_HEXSIZE; + +#ifdef GIT_EXPERIMENTAL_SHA256 + case GIT_OID_SHA256: + return GIT_OID_SHA256_HEXSIZE; +#endif + + } + + return 0; +} + +GIT_INLINE(const char *) git_oid_type_name(git_oid_t type) +{ + switch (type) { + case GIT_OID_SHA1: + return "sha1"; + +#ifdef GIT_EXPERIMENTAL_SHA256 + case GIT_OID_SHA256: + return "sha256"; +#endif + } + + return "unknown"; +} + +GIT_INLINE(git_oid_t) git_oid_type_fromstr(const char *name) +{ + if (strcmp(name, "sha1") == 0) + return GIT_OID_SHA1; + +#ifdef GIT_EXPERIMENTAL_SHA256 + if (strcmp(name, "sha256") == 0) + return GIT_OID_SHA256; +#endif + + return 0; +} + +GIT_INLINE(git_oid_t) git_oid_type_fromstrn(const char *name, size_t len) +{ + if (len == CONST_STRLEN("sha1") && strncmp(name, "sha1", len) == 0) + return GIT_OID_SHA1; + +#ifdef GIT_EXPERIMENTAL_SHA256 + if (len == CONST_STRLEN("sha256") && strncmp(name, "sha256", len) == 0) + return GIT_OID_SHA256; +#endif + + return 0; +} + +GIT_INLINE(git_hash_algorithm_t) git_oid_algorithm(git_oid_t type) +{ + switch (type) { + case GIT_OID_SHA1: + return GIT_HASH_ALGORITHM_SHA1; + +#ifdef GIT_EXPERIMENTAL_SHA256 + case GIT_OID_SHA256: + return GIT_HASH_ALGORITHM_SHA256; +#endif + + } + + return 0; +} + /** * Format a git_oid into a newly allocated c-string. * @@ -25,13 +134,42 @@ extern const git_oid git_oid__empty_tree_sha1; */ char *git_oid_allocfmt(const git_oid *id); +/** + * Format the requested nibbles of an object id. + * + * @param str the string to write into + * @param oid the oid structure to format + * @param start the starting number of nibbles + * @param count the number of nibbles to format + */ +GIT_INLINE(void) git_oid_fmt_substr( + char *str, + const git_oid *oid, + size_t start, + size_t count) +{ + static char hex[] = "0123456789abcdef"; + size_t i, end = start + count, min = start / 2, max = end / 2; + + if (start & 1) + *str++ = hex[oid->id[min++] & 0x0f]; + + for (i = min; i < max; i++) { + *str++ = hex[oid->id[i] >> 4]; + *str++ = hex[oid->id[i] & 0x0f]; + } + + if (end & 1) + *str++ = hex[oid->id[i] >> 4]; +} + GIT_INLINE(int) git_oid_raw_ncmp( const unsigned char *sha1, const unsigned char *sha2, size_t len) { - if (len > GIT_OID_HEXSZ) - len = GIT_OID_HEXSZ; + if (len > GIT_OID_MAX_HEXSIZE) + len = GIT_OID_MAX_HEXSIZE; while (len > 1) { if (*sha1 != *sha2) @@ -50,16 +188,18 @@ GIT_INLINE(int) git_oid_raw_ncmp( GIT_INLINE(int) git_oid_raw_cmp( const unsigned char *sha1, - const unsigned char *sha2) + const unsigned char *sha2, + size_t size) { - return memcmp(sha1, sha2, GIT_OID_RAWSZ); + return memcmp(sha1, sha2, size); } GIT_INLINE(int) git_oid_raw_cpy( unsigned char *dst, - const unsigned char *src) + const unsigned char *src, + size_t size) { - memcpy(dst, src, GIT_OID_RAWSZ); + memcpy(dst, src, size); return 0; } @@ -72,19 +212,30 @@ GIT_INLINE(int) git_oid_raw_cpy( */ GIT_INLINE(int) git_oid__cmp(const git_oid *a, const git_oid *b) { - return git_oid_raw_cmp(a->id, b->id); +#ifdef GIT_EXPERIMENTAL_SHA256 + if (a->type != b->type) + return a->type - b->type; + + return git_oid_raw_cmp(a->id, b->id, git_oid_size(a->type)); +#else + return git_oid_raw_cmp(a->id, b->id, git_oid_size(GIT_OID_SHA1)); +#endif } GIT_INLINE(void) git_oid__cpy_prefix( git_oid *out, const git_oid *id, size_t len) { +#ifdef GIT_EXPERIMENTAL_SHA256 + out->type = id->type; +#endif + memcpy(&out->id, id->id, (len + 1) / 2); if (len & 1) out->id[len / 2] &= 0xF0; } -GIT_INLINE(bool) git_oid__is_hexstr(const char *str) +GIT_INLINE(bool) git_oid__is_hexstr(const char *str, git_oid_t type) { size_t i; @@ -93,7 +244,30 @@ GIT_INLINE(bool) git_oid__is_hexstr(const char *str) return false; } - return (i == GIT_OID_HEXSZ); + return (i == git_oid_hexsize(type)); } +GIT_INLINE(void) git_oid_clear(git_oid *out, git_oid_t type) +{ + memset(out->id, 0, git_oid_size(type)); + +#ifdef GIT_EXPERIMENTAL_SHA256 + out->type = type; +#endif +} + +/* SHA256 support */ + +int git_oid__fromstr(git_oid *out, const char *str, git_oid_t type); + +int git_oid__fromstrp(git_oid *out, const char *str, git_oid_t type); + +int git_oid__fromstrn( + git_oid *out, + const char *str, + size_t length, + git_oid_t type); + +int git_oid__fromraw(git_oid *out, const unsigned char *raw, git_oid_t type); + #endif diff --git a/src/libgit2/pack-objects.c b/src/libgit2/pack-objects.c index 1aa6731b3..20a5dfcbd 100644 --- a/src/libgit2/pack-objects.c +++ b/src/libgit2/pack-objects.c @@ -347,8 +347,8 @@ static int write_object( goto done; if (type == GIT_OBJECT_REF_DELTA) { - if ((error = write_cb(po->delta->id.id, GIT_OID_RAWSZ, cb_data)) < 0 || - (error = git_hash_update(&pb->ctx, po->delta->id.id, GIT_OID_RAWSZ)) < 0) + if ((error = write_cb(po->delta->id.id, GIT_OID_SHA1_SIZE, cb_data)) < 0 || + (error = git_hash_update(&pb->ctx, po->delta->id.id, GIT_OID_SHA1_SIZE)) < 0) goto done; } @@ -668,7 +668,7 @@ static int write_pack(git_packbuilder *pb, if ((error = git_hash_final(entry_oid.id, &pb->ctx)) < 0) goto done; - error = write_cb(entry_oid.id, GIT_OID_RAWSZ, cb_data); + error = write_cb(entry_oid.id, GIT_OID_SHA1_SIZE, cb_data); done: /* if callback cancelled writing, we must still free delta_data */ @@ -1407,7 +1407,18 @@ int git_packbuilder_write( opts.progress_cb = progress_cb; opts.progress_cb_payload = progress_cb_payload; - if ((error = git_indexer_new(&indexer, path, mode, pb->odb, &opts)) < 0) + /* TODO: SHA256 */ + +#ifdef GIT_EXPERIMENTAL_SHA256 + opts.mode = mode; + opts.odb = pb->odb; + + error = git_indexer_new(&indexer, path, GIT_OID_SHA1, &opts); +#else + error = git_indexer_new(&indexer, path, mode, pb->odb, &opts); +#endif + + if (error < 0) goto cleanup; if (!git_repository__configmap_lookup(&t, pb->repo, GIT_CONFIGMAP_FSYNCOBJECTFILES) && t) diff --git a/src/libgit2/pack.c b/src/libgit2/pack.c index 16fe378bd..d59973aa9 100644 --- a/src/libgit2/pack.c +++ b/src/libgit2/pack.c @@ -32,7 +32,7 @@ static int packfile_unpack_compressed( * Throws GIT_EAMBIGUOUSOIDPREFIX if short oid * is ambiguous within the pack. * This method assumes that len is between - * GIT_OID_MINPREFIXLEN and GIT_OID_HEXSZ. + * GIT_OID_MINPREFIXLEN and the oid type's hexsize. */ static int pack_entry_find_offset( off64_t *offset_out, @@ -186,9 +186,9 @@ static int cache_add( static void pack_index_free(struct git_pack_file *p) { - if (p->oids) { - git__free(p->oids); - p->oids = NULL; + if (p->ids) { + git__free(p->ids); + p->ids = NULL; } if (p->index_map.data) { git_futils_mmap_free(&p->index_map); @@ -200,11 +200,12 @@ static void pack_index_free(struct git_pack_file *p) static int pack_index_check_locked(const char *path, struct git_pack_file *p) { struct git_pack_idx_header *hdr; - uint32_t version, nr, i, *index; + uint32_t version, nr = 0, i, *index; void *idx_map; size_t idx_size; struct stat st; int error; + /* TODO: properly open the file without access time using O_NOATIME */ git_file fd = git_futils_open_ro(path); if (fd < 0) @@ -218,8 +219,7 @@ static int pack_index_check_locked(const char *path, struct git_pack_file *p) if (!S_ISREG(st.st_mode) || !git__is_sizet(st.st_size) || - (idx_size = (size_t)st.st_size) < 4 * 256 + 20 + 20) - { + (idx_size = (size_t)st.st_size) < (size_t)((4 * 256) + (p->oid_size * 2))) { p_close(fd); git_error_set(GIT_ERROR_ODB, "invalid pack index '%s'", path); return -1; @@ -242,10 +242,10 @@ static int pack_index_check_locked(const char *path, struct git_pack_file *p) return packfile_error("unsupported index version"); } - } else + } else { version = 1; + } - nr = 0; index = idx_map; if (version > 1) @@ -264,11 +264,11 @@ static int pack_index_check_locked(const char *path, struct git_pack_file *p) /* * Total size: * - 256 index entries 4 bytes each - * - 24-byte entries * nr (20-byte sha1 + 4-byte offset) - * - 20-byte SHA1 of the packfile - * - 20-byte SHA1 file checksum + * - 24/36-byte entries * nr (20/32 byte SHA + 4-byte offset) + * - 20/32-byte SHA of the packfile + * - 20/32-byte SHA file checksum */ - if (idx_size != 4*256 + nr * 24 + 20 + 20) { + if (idx_size != (4 * 256 + ((uint64_t) nr * (p->oid_size + 4)) + (p->oid_size * 2))) { git_futils_mmap_free(&p->index_map); return packfile_error("index is corrupted"); } @@ -277,17 +277,17 @@ static int pack_index_check_locked(const char *path, struct git_pack_file *p) * Minimum size: * - 8 bytes of header * - 256 index entries 4 bytes each - * - 20-byte sha1 entry * nr + * - 20/32-byte SHA entry * nr * - 4-byte crc entry * nr * - 4-byte offset entry * nr - * - 20-byte SHA1 of the packfile - * - 20-byte SHA1 file checksum + * - 20/32-byte SHA of the packfile + * - 20/32-byte SHA file checksum * And after the 4-byte offset table might be a * variable sized table containing 8-byte entries * for offsets larger than 2^31. */ - unsigned long min_size = 8 + 4*256 + nr*(20 + 4 + 4) + 20 + 20; - unsigned long max_size = min_size; + uint64_t min_size = 8 + (4 * 256) + ((uint64_t)nr * (p->oid_size + 4 + 4)) + (p->oid_size * 2); + uint64_t max_size = min_size; if (nr) max_size += (nr - 1)*8; @@ -365,12 +365,12 @@ static unsigned char *pack_window_open( * Don't allow a negative offset, as that means we've wrapped * around. */ - if (offset > (p->mwf.size - 20)) + if (offset > (p->mwf.size - p->oid_size)) goto cleanup; if (offset < 0) goto cleanup; - pack_data = git_mwindow_open(&p->mwf, w_cursor, offset, 20, left); + pack_data = git_mwindow_open(&p->mwf, w_cursor, offset, p->oid_size, left); cleanup: git_mutex_unlock(&p->mwf.lock); @@ -473,13 +473,13 @@ int git_packfile_unpack_header( return error; } - /* pack_window_open() assures us we have [base, base + 20) available - * as a range that we can look at at. (Its actually the hash - * size that is assured.) With our object header encoding - * the maximum deflated object size is 2^137, which is just - * insane, so we know won't exceed what we have been given. + /* pack_window_open() assures us we have [base, base + oid_size) + * available as a range that we can look at at. (It's actually + * the hash size that is assured.) With our object header + * encoding the maximum deflated object size is 2^137, which is + * just insane, so we know won't exceed what we have been given. */ - base = git_mwindow_open(&p->mwf, w_curs, *curpos, 20, &left); + base = git_mwindow_open(&p->mwf, w_curs, *curpos, p->oid_size, &left); git_mutex_unlock(&p->lock); git_mutex_unlock(&p->mwf.lock); if (base == NULL) @@ -977,11 +977,12 @@ int get_delta_base( /* Assumption: the only reason this would fail is because the file is too small */ if (base_info == NULL) return GIT_EBUFS; - /* pack_window_open() assured us we have [base_info, base_info + 20) - * as a range that we can look at without walking off the - * end of the mapped window. Its actually the hash size - * that is assured. An OFS_DELTA longer than the hash size - * is stupid, as then a REF_DELTA would be smaller to store. + /* pack_window_open() assured us we have + * [base_info, base_info + oid_size) as a range that we can look + * at without walking off the end of the mapped window. Its + * actually the hash size that is assured. An OFS_DELTA longer + * than the hash size is stupid, as then a REF_DELTA would be + * smaller to store. */ if (type == GIT_OBJECT_OFS_DELTA) { unsigned used = 0; @@ -1002,7 +1003,7 @@ int get_delta_base( *curpos += used; } else if (type == GIT_OBJECT_REF_DELTA) { git_oid base_oid; - git_oid_fromraw(&base_oid, base_info); + git_oid__fromraw(&base_oid, base_info, p->oid_type); /* If we have the cooperative cache, search in it first */ if (p->has_cache) { @@ -1012,7 +1013,7 @@ int get_delta_base( if (entry->offset == 0) return packfile_error("delta offset is zero"); - *curpos += 20; + *curpos += p->oid_size; *delta_base_out = entry->offset; return 0; } else { @@ -1025,9 +1026,9 @@ int get_delta_base( } /* The base entry _must_ be in the same pack */ - if (pack_entry_find_offset(&base_offset, &unused, p, &base_oid, GIT_OID_HEXSZ) < 0) + if (pack_entry_find_offset(&base_offset, &unused, p, &base_oid, p->oid_hexsize) < 0) return packfile_error("base entry delta is not in the same pack"); - *curpos += 20; + *curpos += p->oid_size; } else return packfile_error("unknown object type"); @@ -1070,7 +1071,7 @@ void git_packfile_free(struct git_pack_file *p, bool unlink_packfile) pack_index_free(p); - git__free(p->bad_object_sha1); + git__free(p->bad_object_ids); git_mutex_free(&p->bases.lock); git_mutex_free(&p->mwf.lock); @@ -1083,8 +1084,8 @@ static int packfile_open_locked(struct git_pack_file *p) { struct stat st; struct git_pack_header hdr; - unsigned char sha1[GIT_OID_RAWSZ]; - unsigned char *idx_sha1; + unsigned char checksum[GIT_OID_MAX_SIZE]; + unsigned char *idx_checksum; if (pack_index_open_locked(p) < 0) return git_odb__error_notfound("failed to open packfile", NULL, 0); @@ -1131,12 +1132,13 @@ static int packfile_open_locked(struct git_pack_file *p) /* Verify the pack matches its index. */ if (p->num_objects != ntohl(hdr.hdr_entries) || - p_pread(p->mwf.fd, sha1, GIT_OID_RAWSZ, p->mwf.size - GIT_OID_RAWSZ) < 0) + p_pread(p->mwf.fd, checksum, p->oid_size, p->mwf.size - p->oid_size) < 0) goto cleanup; - idx_sha1 = ((unsigned char *)p->index_map.data) + p->index_map.len - 40; + idx_checksum = ((unsigned char *)p->index_map.data) + + p->index_map.len - (p->oid_size * 2); - if (git_oid_raw_cmp(sha1, idx_sha1) != 0) + if (git_oid_raw_cmp(checksum, idx_checksum, p->oid_size) != 0) goto cleanup; if (git_mwindow_file_register(&p->mwf) < 0) @@ -1171,7 +1173,10 @@ int git_packfile__name(char **out, const char *path) return 0; } -int git_packfile_alloc(struct git_pack_file **pack_out, const char *path) +int git_packfile_alloc( + struct git_pack_file **pack_out, + const char *path, + git_oid_t oid_type) { struct stat st; struct git_pack_file *p; @@ -1219,6 +1224,9 @@ int git_packfile_alloc(struct git_pack_file **pack_out, const char *path) p->pack_local = 1; p->mtime = (git_time_t)st.st_mtime; p->index_version = -1; + p->oid_type = oid_type ? oid_type : GIT_OID_DEFAULT; + p->oid_size = (unsigned int)git_oid_size(p->oid_type); + p->oid_hexsize = (unsigned int)git_oid_hexsize(p->oid_type); if (git_mutex_init(&p->lock) < 0) { git_error_set(GIT_ERROR_OS, "failed to initialize packfile mutex"); @@ -1260,9 +1268,9 @@ static off64_t nth_packed_object_offset_locked(struct git_pack_file *p, uint32_t end = index + p->index_map.len; index += 4 * 256; if (p->index_version == 1) - return ntohl(*((uint32_t *)(index + 24 * n))); + return ntohl(*((uint32_t *)(index + (p->oid_size + 4) * n))); - index += 8 + p->num_objects * (20 + 4); + index += 8 + p->num_objects * (p->oid_size + 4); off32 = ntohl(*((uint32_t *)(index + 4 * n))); if (!(off32 & 0x80000000)) return off32; @@ -1273,7 +1281,7 @@ static off64_t nth_packed_object_offset_locked(struct git_pack_file *p, uint32_t return -1; return (((uint64_t)ntohl(*((uint32_t *)(index + 0)))) << 32) | - ntohl(*((uint32_t *)(index + 4))); + ntohl(*((uint32_t *)(index + 4))); } static int git__memcmp4(const void *a, const void *b) { @@ -1312,7 +1320,7 @@ int git_pack_foreach_entry( index += 4 * 256; - if (p->oids == NULL) { + if (p->ids == NULL) { git_vector offsets, oids; if ((error = git_vector_init(&oids, p->num_objects, NULL))) { @@ -1326,22 +1334,25 @@ int git_pack_foreach_entry( } if (p->index_version > 1) { - const unsigned char *off = index + 24 * p->num_objects; + const unsigned char *off = index + + (p->oid_size + 4) * p->num_objects; + for (i = 0; i < p->num_objects; i++) git_vector_insert(&offsets, (void*)&off[4 * i]); + git_vector_sort(&offsets); git_vector_foreach(&offsets, i, current) git_vector_insert(&oids, (void*)&index[5 * (current - off)]); } else { for (i = 0; i < p->num_objects; i++) - git_vector_insert(&offsets, (void*)&index[24 * i]); + git_vector_insert(&offsets, (void*)&index[(p->oid_size + 4) * i]); git_vector_sort(&offsets); git_vector_foreach(&offsets, i, current) git_vector_insert(&oids, (void*)¤t[4]); } git_vector_free(&offsets); - p->oids = (unsigned char **)git_vector_detach(NULL, NULL, &oids); + p->ids = (unsigned char **)git_vector_detach(NULL, NULL, &oids); } /* @@ -1362,7 +1373,7 @@ int git_pack_foreach_entry( git_array_clear(oids); GIT_ERROR_CHECK_ALLOC(oid); } - git_oid_fromraw(oid, p->oids[i]); + git_oid__fromraw(oid, p->ids[i], p->oid_type); } git_mutex_unlock(&p->lock); @@ -1412,10 +1423,13 @@ int git_pack_foreach_entry_offset( /* all offsets should have been validated by pack_index_check_locked */ if (p->index_version > 1) { - const unsigned char *offsets = index + 24 * p->num_objects; + const unsigned char *offsets = index + + (p->oid_size + 4) * p->num_objects; const unsigned char *large_offset_ptr; - const unsigned char *large_offsets = index + 28 * p->num_objects; - const unsigned char *large_offsets_end = ((const unsigned char *)p->index_map.data) + p->index_map.len - 20; + const unsigned char *large_offsets = index + + (p->oid_size + 8) * p->num_objects; + const unsigned char *large_offsets_end = ((const unsigned char *)p->index_map.data) + p->index_map.len - p->oid_size; + for (i = 0; i < p->num_objects; i++) { current_offset = ntohl(*(const uint32_t *)(offsets + 4 * i)); if (current_offset & 0x80000000) { @@ -1428,7 +1442,7 @@ int git_pack_foreach_entry_offset( ntohl(*((uint32_t *)(large_offset_ptr + 4))); } - git_oid_fromraw(¤t_oid, (index + 20 * i)); + git_oid__fromraw(¤t_oid, (index + p->oid_size * i), p->oid_type); if ((error = cb(¤t_oid, current_offset, data)) != 0) { error = git_error_set_after_callback(error); goto cleanup; @@ -1436,8 +1450,8 @@ int git_pack_foreach_entry_offset( } } else { for (i = 0; i < p->num_objects; i++) { - current_offset = ntohl(*(const uint32_t *)(index + 24 * i)); - git_oid_fromraw(¤t_oid, (index + 24 * i + 4)); + current_offset = ntohl(*(const uint32_t *)(index + (p->oid_size + 4) * i)); + git_oid__fromraw(¤t_oid, (index + (p->oid_size + 4) * i + 4), p->oid_type); if ((error = cb(¤t_oid, current_offset, data)) != 0) { error = git_error_set_after_callback(error); goto cleanup; @@ -1450,14 +1464,20 @@ cleanup: return error; } -int git_pack__lookup_sha1(const void *oid_lookup_table, size_t stride, unsigned lo, - unsigned hi, const unsigned char *oid_prefix) +int git_pack__lookup_id( + const void *oid_lookup_table, + size_t stride, + unsigned lo, + unsigned hi, + const unsigned char *oid_prefix, + const git_oid_t oid_type) { const unsigned char *base = oid_lookup_table; + size_t oid_size = git_oid_size(oid_type); while (lo < hi) { unsigned mi = (lo + hi) / 2; - int cmp = git_oid_raw_cmp(base + mi * stride, oid_prefix); + int cmp = git_oid_raw_cmp(base + mi * stride, oid_prefix, oid_size); if (!cmp) return mi; @@ -1512,9 +1532,9 @@ static int pack_entry_find_offset( lo = ((short_oid->id[0] == 0x0) ? 0 : ntohl(level1_ofs[(int)short_oid->id[0] - 1])); if (p->index_version > 1) { - stride = 20; + stride = p->oid_size; } else { - stride = 24; + stride = p->oid_size + 4; index += 4; } @@ -1523,7 +1543,8 @@ static int pack_entry_find_offset( short_oid->id[0], short_oid->id[1], short_oid->id[2], lo, hi, p->num_objects); #endif - pos = git_pack__lookup_sha1(index, stride, lo, hi, short_oid->id); + pos = git_pack__lookup_id(index, stride, lo, hi, + short_oid->id, p->oid_type); if (pos >= 0) { /* An object matching exactly the oid was found */ @@ -1541,7 +1562,9 @@ static int pack_entry_find_offset( } } - if (found && len != GIT_OID_HEXSZ && pos + 1 < (int)p->num_objects) { + if (found && + len != p->oid_hexsize && + pos + 1 < (int)p->num_objects) { /* Check for ambiguousity */ const unsigned char *next = current + stride; @@ -1566,13 +1589,13 @@ static int pack_entry_find_offset( } *offset_out = offset; - git_oid_fromraw(found_oid, current); + git_oid__fromraw(found_oid, current, p->oid_type); #ifdef INDEX_DEBUG_LOOKUP { - unsigned char hex_sha1[GIT_OID_HEXSZ + 1]; + char hex_sha1[p->oid_hexsize + 1]; git_oid_fmt(hex_sha1, found_oid); - hex_sha1[GIT_OID_HEXSZ] = '\0'; + hex_sha1[p->oid_hexsize] = '\0'; printf("found lo=%d %s\n", lo, hex_sha1); } #endif @@ -1594,10 +1617,10 @@ int git_pack_entry_find( GIT_ASSERT_ARG(p); - if (len == GIT_OID_HEXSZ && p->num_bad_objects) { + if (len == p->oid_hexsize && p->num_bad_objects) { unsigned i; for (i = 0; i < p->num_bad_objects; i++) - if (git_oid__cmp(short_oid, &p->bad_object_sha1[i]) == 0) + if (git_oid__cmp(short_oid, &p->bad_object_ids[i]) == 0) return packfile_error("bad object found in packfile"); } @@ -1630,6 +1653,6 @@ int git_pack_entry_find( e->offset = offset; e->p = p; - git_oid_cpy(&e->sha1, &found_oid); + git_oid_cpy(&e->id, &found_oid); return 0; } diff --git a/src/libgit2/pack.h b/src/libgit2/pack.h index d90588f79..1a9eb14b2 100644 --- a/src/libgit2/pack.h +++ b/src/libgit2/pack.h @@ -99,13 +99,19 @@ struct git_pack_file { uint32_t num_objects; uint32_t num_bad_objects; - git_oid *bad_object_sha1; /* array of git_oid */ + git_oid *bad_object_ids; /* array of git_oid */ + + git_oid_t oid_type; + unsigned oid_hexsize:7, + oid_size:6, + pack_local:1, + pack_keep:1, + has_cache:1; int index_version; git_time_t mtime; - unsigned pack_local:1, pack_keep:1, has_cache:1; git_oidmap *idx_cache; - unsigned char **oids; + unsigned char **ids; git_pack_cache bases; /* delta base cache */ @@ -116,21 +122,26 @@ struct git_pack_file { }; /** - * Return the position where an OID (or a prefix) would be inserted within the - * OID Lookup Table of an .idx file. This performs binary search between the lo - * and hi indices. + * Return the position where an OID (or a prefix) would be inserted within + * the OID Lookup Table of an .idx file. This performs binary search + * between the lo and hi indices. * - * The stride parameter is provided because .idx files version 1 store the OIDs - * interleaved with the 4-byte file offsets of the objects within the .pack - * file (stride = 24), whereas files with version 2 store them in a contiguous - * flat array (stride = 20). + * The stride parameter is provided because .idx files version 1 store the + * OIDs interleaved with the 4-byte file offsets of the objects within the + * .pack file (stride = oid_size + 4), whereas files with version 2 store + * them in a contiguous flat array (stride = oid_size). */ -int git_pack__lookup_sha1(const void *oid_lookup_table, size_t stride, unsigned lo, - unsigned hi, const unsigned char *oid_prefix); +int git_pack__lookup_id( + const void *id_lookup_table, + size_t stride, + unsigned lo, + unsigned hi, + const unsigned char *id_prefix, + const git_oid_t oid_type); struct git_pack_entry { off64_t offset; - git_oid sha1; + git_oid id; struct git_pack_file *p; }; @@ -174,12 +185,15 @@ int get_delta_base( off64_t delta_obj_offset); void git_packfile_free(struct git_pack_file *p, bool unlink_packfile); -int git_packfile_alloc(struct git_pack_file **pack_out, const char *path); +int git_packfile_alloc( + struct git_pack_file **pack_out, + const char *path, + git_oid_t oid_type); int git_pack_entry_find( struct git_pack_entry *e, struct git_pack_file *p, - const git_oid *short_oid, + const git_oid *short_id, size_t len); int git_pack_foreach_entry( struct git_pack_file *p, diff --git a/src/libgit2/parse.c b/src/libgit2/parse.c index 0a10758bf..55d3cb10e 100644 --- a/src/libgit2/parse.c +++ b/src/libgit2/parse.c @@ -5,6 +5,7 @@ * a Linking Exception. For full terms see the included COPYING file. */ #include "parse.h" +#include "oid.h" int git_parse_ctx_init(git_parse_ctx *ctx, const char *content, size_t content_len) { @@ -103,11 +104,11 @@ int git_parse_advance_digit(int64_t *out, git_parse_ctx *ctx, int base) int git_parse_advance_oid(git_oid *out, git_parse_ctx *ctx) { - if (ctx->line_len < GIT_OID_HEXSZ) + if (ctx->line_len < GIT_OID_SHA1_HEXSIZE) return -1; - if ((git_oid_fromstrn(out, ctx->line, GIT_OID_HEXSZ)) < 0) + if ((git_oid__fromstrn(out, ctx->line, GIT_OID_SHA1_HEXSIZE, GIT_OID_SHA1)) < 0) return -1; - git_parse_advance_chars(ctx, GIT_OID_HEXSZ); + git_parse_advance_chars(ctx, GIT_OID_SHA1_HEXSIZE); return 0; } diff --git a/src/libgit2/patch_parse.c b/src/libgit2/patch_parse.c index 78cd96252..ffdb99231 100644 --- a/src/libgit2/patch_parse.c +++ b/src/libgit2/patch_parse.c @@ -168,13 +168,13 @@ static int parse_header_oid( { size_t len; - for (len = 0; len < ctx->parse_ctx.line_len && len < GIT_OID_HEXSZ; len++) { + for (len = 0; len < ctx->parse_ctx.line_len && len < GIT_OID_SHA1_HEXSIZE; len++) { if (!git__isxdigit(ctx->parse_ctx.line[len])) break; } - if (len < GIT_OID_MINPREFIXLEN || len > GIT_OID_HEXSZ || - git_oid_fromstrn(oid, ctx->parse_ctx.line, len) < 0) + if (len < GIT_OID_MINPREFIXLEN || len > GIT_OID_SHA1_HEXSIZE || + git_oid__fromstrn(oid, ctx->parse_ctx.line, len, GIT_OID_SHA1) < 0) return git_parse_err("invalid hex formatted object id at line %"PRIuZ, ctx->parse_ctx.line_num); @@ -1065,12 +1065,12 @@ static int check_patch(git_patch_parsed *patch) return git_parse_err("patch with no hunks"); if (delta->status == GIT_DELTA_ADDED) { - memset(&delta->old_file.id, 0x0, sizeof(git_oid)); + git_oid_clear(&delta->old_file.id, GIT_OID_SHA1); delta->old_file.id_abbrev = 0; } if (delta->status == GIT_DELTA_DELETED) { - memset(&delta->new_file.id, 0x0, sizeof(git_oid)); + git_oid_clear(&delta->new_file.id, GIT_OID_SHA1); delta->new_file.id_abbrev = 0; } diff --git a/src/libgit2/push.c b/src/libgit2/push.c index da8aebadd..e25681870 100644 --- a/src/libgit2/push.c +++ b/src/libgit2/push.c @@ -118,6 +118,9 @@ static int parse_refspec(git_push *push, push_spec **spec, const char *str) s = git__calloc(1, sizeof(*s)); GIT_ERROR_CHECK_ALLOC(s); + git_oid_clear(&s->loid, GIT_OID_SHA1); + git_oid_clear(&s->roid, GIT_OID_SHA1); + if (git_refspec__parse(&s->refspec, str, false) < 0) { git_error_set(GIT_ERROR_INVALID, "invalid refspec %s", str); goto on_error; @@ -382,11 +385,18 @@ static int calculate_work(git_push *push) git_vector_foreach(&push->specs, i, spec) { if (spec->refspec.src && spec->refspec.src[0]!= '\0') { /* This is a create or update. Local ref must exist. */ - if (git_reference_name_to_id( - &spec->loid, push->repo, spec->refspec.src) < 0) { - git_error_set(GIT_ERROR_REFERENCE, "no such reference '%s'", spec->refspec.src); + + git_object *obj; + int error = git_revparse_single(&obj, push->repo, spec->refspec.src); + + if (error < 0) { + git_object_free(obj); + git_error_set(GIT_ERROR_REFERENCE, "src refspec %s does not match any", spec->refspec.src); return -1; } + + git_oid_cpy(&spec->loid, git_object_id(obj)); + git_object_free(obj); } /* Remote ref may or may not (e.g. during create) already exist. */ diff --git a/src/libgit2/reader.c b/src/libgit2/reader.c index ba9775240..be29bb41c 100644 --- a/src/libgit2/reader.c +++ b/src/libgit2/reader.c @@ -125,7 +125,7 @@ static int workdir_reader_read( goto done; if (out_id || reader->index) { - if ((error = git_odb_hash(&id, out->ptr, out->size, GIT_OBJECT_BLOB)) < 0) + if ((error = git_odb__hash(&id, out->ptr, out->size, GIT_OBJECT_BLOB, GIT_OID_SHA1)) < 0) goto done; } diff --git a/src/libgit2/rebase.c b/src/libgit2/rebase.c index 5e48f0dfb..1970d5ddc 100644 --- a/src/libgit2/rebase.c +++ b/src/libgit2/rebase.c @@ -181,7 +181,8 @@ GIT_INLINE(int) rebase_readoid( if ((error = rebase_readfile(str_out, state_path, filename)) < 0) return error; - if (str_out->size != GIT_OID_HEXSZ || git_oid_fromstr(out, str_out->ptr) < 0) { + if (str_out->size != GIT_OID_SHA1_HEXSIZE || + git_oid__fromstr(out, str_out->ptr, GIT_OID_SHA1) < 0) { git_error_set(GIT_ERROR_REBASE, "the file '%s' contains an invalid object ID", filename); return -1; } @@ -363,7 +364,7 @@ int git_rebase_open( git_str_rtrim(&orig_head_id); - if ((error = git_oid_fromstr(&rebase->orig_head_id, orig_head_id.ptr)) < 0) + if ((error = git_oid__fromstr(&rebase->orig_head_id, orig_head_id.ptr, GIT_OID_SHA1)) < 0) goto done; git_str_truncate(&path, state_path_len); @@ -374,7 +375,7 @@ int git_rebase_open( git_str_rtrim(&onto_id); - if ((error = git_oid_fromstr(&rebase->onto_id, onto_id.ptr)) < 0) + if ((error = git_oid__fromstr(&rebase->onto_id, onto_id.ptr, GIT_OID_SHA1)) < 0) goto done; if (!rebase->head_detached) @@ -452,7 +453,7 @@ static const char *rebase_onto_name(const git_annotated_commit *onto) static int rebase_setupfiles_merge(git_rebase *rebase) { git_str commit_filename = GIT_STR_INIT; - char id_str[GIT_OID_HEXSZ]; + char id_str[GIT_OID_SHA1_HEXSIZE]; git_rebase_operation *operation; size_t i; int error = 0; @@ -470,7 +471,7 @@ static int rebase_setupfiles_merge(git_rebase *rebase) git_oid_fmt(id_str, &operation->id); if ((error = rebase_setupfile(rebase, commit_filename.ptr, 0, - "%.*s\n", GIT_OID_HEXSZ, id_str)) < 0) + "%.*s\n", GIT_OID_SHA1_HEXSIZE, id_str)) < 0) goto done; } @@ -481,7 +482,7 @@ done: static int rebase_setupfiles(git_rebase *rebase) { - char onto[GIT_OID_HEXSZ], orig_head[GIT_OID_HEXSZ]; + char onto[GIT_OID_SHA1_HEXSIZE], orig_head[GIT_OID_SHA1_HEXSIZE]; const char *orig_head_name; git_oid_fmt(onto, &rebase->onto_id); @@ -497,8 +498,8 @@ static int rebase_setupfiles(git_rebase *rebase) if (git_repository__set_orig_head(rebase->repo, &rebase->orig_head_id) < 0 || rebase_setupfile(rebase, HEAD_NAME_FILE, 0, "%s\n", orig_head_name) < 0 || - rebase_setupfile(rebase, ONTO_FILE, 0, "%.*s\n", GIT_OID_HEXSZ, onto) < 0 || - rebase_setupfile(rebase, ORIG_HEAD_FILE, 0, "%.*s\n", GIT_OID_HEXSZ, orig_head) < 0 || + rebase_setupfile(rebase, ONTO_FILE, 0, "%.*s\n", GIT_OID_SHA1_HEXSIZE, onto) < 0 || + rebase_setupfile(rebase, ORIG_HEAD_FILE, 0, "%.*s\n", GIT_OID_SHA1_HEXSIZE, orig_head) < 0 || rebase_setupfile(rebase, QUIET_FILE, 0, rebase->quiet ? "t\n" : "\n") < 0) return -1; @@ -813,7 +814,7 @@ static int rebase_next_merge( git_indexwriter indexwriter = GIT_INDEXWRITER_INIT; git_rebase_operation *operation; git_checkout_options checkout_opts; - char current_idstr[GIT_OID_HEXSZ]; + char current_idstr[GIT_OID_SHA1_HEXSIZE]; unsigned int parent_count; int error; @@ -842,7 +843,7 @@ static int rebase_next_merge( if ((error = git_indexwriter_init_for_operation(&indexwriter, rebase->repo, &checkout_opts.checkout_strategy)) < 0 || (error = rebase_setupfile(rebase, MSGNUM_FILE, 0, "%" PRIuZ "\n", rebase->current+1)) < 0 || - (error = rebase_setupfile(rebase, CURRENT_FILE, 0, "%.*s\n", GIT_OID_HEXSZ, current_idstr)) < 0 || + (error = rebase_setupfile(rebase, CURRENT_FILE, 0, "%.*s\n", GIT_OID_SHA1_HEXSIZE, current_idstr)) < 0 || (error = git_merge_trees(&index, rebase->repo, parent_tree, head_tree, current_tree, &rebase->options.merge_options)) < 0 || (error = git_merge__check_result(rebase->repo, index)) < 0 || (error = git_checkout_index(rebase->repo, index, &checkout_opts)) < 0 || @@ -1102,7 +1103,7 @@ static int rebase_commit_merge( git_reference *head = NULL; git_commit *head_commit = NULL, *commit = NULL; git_index *index = NULL; - char old_idstr[GIT_OID_HEXSZ], new_idstr[GIT_OID_HEXSZ]; + char old_idstr[GIT_OID_SHA1_HEXSIZE], new_idstr[GIT_OID_SHA1_HEXSIZE]; int error; operation = git_array_get(rebase->operations, rebase->current); @@ -1122,7 +1123,7 @@ static int rebase_commit_merge( git_oid_fmt(new_idstr, git_commit_id(commit)); if ((error = rebase_setupfile(rebase, REWRITTEN_FILE, O_CREAT|O_WRONLY|O_APPEND, - "%.*s %.*s\n", GIT_OID_HEXSZ, old_idstr, GIT_OID_HEXSZ, new_idstr)) < 0) + "%.*s %.*s\n", GIT_OID_SHA1_HEXSIZE, old_idstr, GIT_OID_SHA1_HEXSIZE, new_idstr)) < 0) goto done; git_oid_cpy(commit_id, git_commit_id(commit)); @@ -1341,10 +1342,10 @@ static int rebase_copy_notes( tostr = end+1; *end = '\0'; - if (strlen(fromstr) != GIT_OID_HEXSZ || - strlen(tostr) != GIT_OID_HEXSZ || - git_oid_fromstr(&from, fromstr) < 0 || - git_oid_fromstr(&to, tostr) < 0) + if (strlen(fromstr) != GIT_OID_SHA1_HEXSIZE || + strlen(tostr) != GIT_OID_SHA1_HEXSIZE || + git_oid__fromstr(&from, fromstr, GIT_OID_SHA1) < 0 || + git_oid__fromstr(&to, tostr, GIT_OID_SHA1) < 0) goto on_error; if ((error = rebase_copy_note(rebase, notes_ref.ptr, &from, &to, committer)) < 0) @@ -1372,14 +1373,14 @@ static int return_to_orig_head(git_rebase *rebase) git_reference *terminal_ref = NULL, *branch_ref = NULL, *head_ref = NULL; git_commit *terminal_commit = NULL; git_str branch_msg = GIT_STR_INIT, head_msg = GIT_STR_INIT; - char onto[GIT_OID_HEXSZ]; + char onto[GIT_OID_SHA1_HEXSIZE]; int error = 0; git_oid_fmt(onto, &rebase->onto_id); if ((error = git_str_printf(&branch_msg, "rebase finished: %s onto %.*s", - rebase->orig_head_name, GIT_OID_HEXSZ, onto)) == 0 && + rebase->orig_head_name, GIT_OID_SHA1_HEXSIZE, onto)) == 0 && (error = git_str_printf(&head_msg, "rebase finished: returning to %s", rebase->orig_head_name)) == 0 && diff --git a/src/libgit2/refdb_fs.c b/src/libgit2/refdb_fs.c index 0f49b16bb..9ce1a9608 100644 --- a/src/libgit2/refdb_fs.c +++ b/src/libgit2/refdb_fs.c @@ -60,15 +60,17 @@ typedef struct refdb_fs_backend { /* path to common objects' directory */ char *commonpath; - git_sortedcache *refcache; + git_oid_t oid_type; + + int fsync : 1, + sorted : 1; int peeling_mode; git_iterator_flag_t iterator_flags; uint32_t direach_flags; - int fsync; + git_sortedcache *refcache; git_map packed_refs_map; git_mutex prlock; /* protect packed_refs_map */ git_futils_filestamp packed_refs_stamp; - bool sorted; } refdb_fs_backend; static int refdb_reflog_fs__delete(git_refdb_backend *_backend, const char *name); @@ -113,6 +115,7 @@ static int packed_reload(refdb_fs_backend *backend) { int error; git_str packedrefs = GIT_STR_INIT; + size_t oid_hexsize = git_oid_hexsize(backend->oid_type); char *scan, *eof, *eol; if (!backend->gitpath) @@ -158,9 +161,9 @@ static int packed_reload(refdb_fs_backend *backend) /* parse " \n" */ - if (git_oid_fromstr(&oid, scan) < 0) + if (git_oid__fromstr(&oid, scan, backend->oid_type) < 0) goto parse_failed; - scan += GIT_OID_HEXSZ; + scan += oid_hexsize; if (*scan++ != ' ') goto parse_failed; @@ -179,9 +182,9 @@ static int packed_reload(refdb_fs_backend *backend) /* look for optional "^\n" */ if (*scan == '^') { - if (git_oid_fromstr(&oid, scan + 1) < 0) + if (git_oid__fromstr(&oid, scan + 1, backend->oid_type) < 0) goto parse_failed; - scan += GIT_OID_HEXSZ + 1; + scan += oid_hexsize + 1; if (scan < eof) { if (!(eol = strchr(scan, '\n'))) @@ -214,19 +217,23 @@ parse_failed: } static int loose_parse_oid( - git_oid *oid, const char *filename, git_str *file_content) + git_oid *oid, + const char *filename, + git_str *file_content, + git_oid_t oid_type) { const char *str = git_str_cstr(file_content); + size_t oid_hexsize = git_oid_hexsize(oid_type); - if (git_str_len(file_content) < GIT_OID_HEXSZ) + if (git_str_len(file_content) < oid_hexsize) goto corrupted; /* we need to get 40 OID characters from the file */ - if (git_oid_fromstr(oid, str) < 0) + if (git_oid__fromstr(oid, str, oid_type) < 0) goto corrupted; /* If the file is longer than 40 chars, the 41st must be a space */ - str += GIT_OID_HEXSZ; + str += oid_hexsize; if (*str == '\0' || git__isspace(*str)) return 0; @@ -266,7 +273,7 @@ static int loose_lookup_to_packfile(refdb_fs_backend *backend, const char *name) goto done; /* parse OID from file */ - if ((error = loose_parse_oid(&oid, name, &ref_file)) < 0) + if ((error = loose_parse_oid(&oid, name, &ref_file, backend->oid_type)) < 0) goto done; if ((error = git_sortedcache_wlock(backend->refcache)) < 0) @@ -437,7 +444,7 @@ static int loose_lookup( } else { git_oid oid; - if (!(error = loose_parse_oid(&oid, ref_name, &ref_file)) && + if (!(error = loose_parse_oid(&oid, ref_name, &ref_file, backend->oid_type)) && out != NULL) *out = git_reference__alloc(ref_name, &oid, NULL); } @@ -615,19 +622,24 @@ static const char *end_of_record(const char *p, const char *end) return p; } -static int -cmp_record_to_refname(const char *rec, size_t data_end, const char *ref_name) +static int cmp_record_to_refname( + const char *rec, + size_t data_end, + const char *ref_name, + git_oid_t oid_type) { const size_t ref_len = strlen(ref_name); int cmp_val; const char *end; + size_t oid_hexsize = git_oid_hexsize(oid_type); - rec += GIT_OID_HEXSZ + 1; /* + space */ - if (data_end < GIT_OID_HEXSZ + 3) { - /* an incomplete (corrupt) record is treated as less than ref_name */ + rec += oid_hexsize + 1; /* + space */ + + /* an incomplete (corrupt) record is treated as less than ref_name */ + if (data_end < oid_hexsize + 3) return -1; - } - data_end -= GIT_OID_HEXSZ + 1; + + data_end -= oid_hexsize + 1; end = memchr(rec, '\n', data_end); if (end) @@ -675,6 +687,7 @@ static int packed_lookup( { int error = 0; const char *left, *right, *data_end; + size_t oid_hexsize = git_oid_hexsize(backend->oid_type); if ((error = packed_map_check(backend)) < 0) return error; @@ -698,7 +711,7 @@ static int packed_lookup( mid = left + (right - left) / 2; rec = start_of_record(left, mid); - compare = cmp_record_to_refname(rec, data_end - rec, ref_name); + compare = cmp_record_to_refname(rec, data_end - rec, ref_name, backend->oid_type); if (compare < 0) { left = end_of_record(mid, right); @@ -708,11 +721,11 @@ static int packed_lookup( const char *eol; git_oid oid, peel, *peel_ptr = NULL; - if (data_end - rec < GIT_OID_HEXSZ || - git_oid_fromstr(&oid, rec) < 0) { + if (data_end - rec < (long)oid_hexsize || + git_oid__fromstr(&oid, rec, backend->oid_type) < 0) { goto parse_failed; } - rec += GIT_OID_HEXSZ + 1; + rec += oid_hexsize + 1; if (!(eol = memchr(rec, '\n', data_end - rec))) { goto parse_failed; } @@ -724,8 +737,8 @@ static int packed_lookup( if (*rec == '^') { rec++; - if (data_end - rec < GIT_OID_HEXSZ || - git_oid_fromstr(&peel, rec) < 0) { + if (data_end - rec < (long)oid_hexsize || + git_oid__fromstr(&peel, rec, backend->oid_type) < 0) { goto parse_failed; } peel_ptr = &peel; @@ -1108,7 +1121,7 @@ static int loose_commit(git_filebuf *file, const git_reference *ref) GIT_ASSERT_ARG(ref); if (ref->type == GIT_REFERENCE_DIRECT) { - char oid[GIT_OID_HEXSZ + 1]; + char oid[GIT_OID_MAX_HEXSIZE + 1]; git_oid_nfmt(oid, sizeof(oid), &ref->target.oid); git_filebuf_printf(file, "%s\n", oid); @@ -1224,7 +1237,7 @@ static int packed_find_peel(refdb_fs_backend *backend, struct packref *ref) */ static int packed_write_ref(struct packref *ref, git_filebuf *file) { - char oid[GIT_OID_HEXSZ + 1]; + char oid[GIT_OID_MAX_HEXSIZE + 1]; git_oid_nfmt(oid, sizeof(oid), &ref->oid); /* @@ -1238,7 +1251,7 @@ static int packed_write_ref(struct packref *ref, git_filebuf *file) * The required peels have already been loaded into `ref->peel_target`. */ if (ref->flags & PACKREF_HAS_PEEL) { - char peel[GIT_OID_HEXSZ + 1]; + char peel[GIT_OID_MAX_HEXSIZE + 1]; git_oid_nfmt(peel, sizeof(peel), &ref->peel); if (git_filebuf_printf(file, "%s %s\n^%s\n", oid, ref->name, peel) < 0) @@ -1302,7 +1315,7 @@ static int packed_remove_loose(refdb_fs_backend *backend) continue; /* Figure out the current id; if we find a bad ref file, skip it so we can do the rest */ - if (loose_parse_oid(¤t_id, lock.path_original, &ref_content) < 0) + if (loose_parse_oid(¤t_id, lock.path_original, &ref_content, backend->oid_type) < 0) continue; /* If the ref moved since we packed it, we must not delete it */ @@ -1891,7 +1904,10 @@ done: return out; } -static int reflog_alloc(git_reflog **reflog, const char *name) +static int reflog_alloc( + git_reflog **reflog, + const char *name, + git_oid_t oid_type) { git_reflog *log; @@ -1903,6 +1919,8 @@ static int reflog_alloc(git_reflog **reflog, const char *name) log->ref_name = git__strdup(name); GIT_ERROR_CHECK_ALLOC(log->ref_name); + log->oid_type = oid_type; + if (git_vector_init(&log->entries, 0, NULL) < 0) { git__free(log->ref_name); git__free(log); @@ -2032,7 +2050,10 @@ static int refdb_reflog_fs__has_log(git_refdb_backend *_backend, const char *nam return has_reflog(backend->repo, name); } -static int refdb_reflog_fs__read(git_reflog **out, git_refdb_backend *_backend, const char *name) +static int refdb_reflog_fs__read( + git_reflog **out, + git_refdb_backend *_backend, + const char *name) { int error = -1; git_str log_path = GIT_STR_INIT; @@ -2048,7 +2069,7 @@ static int refdb_reflog_fs__read(git_reflog **out, git_refdb_backend *_backend, backend = GIT_CONTAINER_OF(_backend, refdb_fs_backend, parent); repo = backend->repo; - if (reflog_alloc(&log, name) < 0) + if (reflog_alloc(&log, name, backend->oid_type) < 0) return -1; if (reflog_path(&log_path, repo, name) < 0) @@ -2086,11 +2107,11 @@ static int serialize_reflog_entry( const git_signature *committer, const char *msg) { - char raw_old[GIT_OID_HEXSZ+1]; - char raw_new[GIT_OID_HEXSZ+1]; + char raw_old[GIT_OID_MAX_HEXSIZE + 1]; + char raw_new[GIT_OID_MAX_HEXSIZE + 1]; - git_oid_tostr(raw_old, GIT_OID_HEXSZ+1, oid_old); - git_oid_tostr(raw_new, GIT_OID_HEXSZ+1, oid_new); + git_oid_tostr(raw_old, GIT_OID_MAX_HEXSIZE + 1, oid_old); + git_oid_tostr(raw_new, GIT_OID_MAX_HEXSIZE + 1, oid_new); git_str_clear(buf); @@ -2189,10 +2210,16 @@ success: } /* Append to the reflog, must be called under reference lock */ -static int reflog_append(refdb_fs_backend *backend, const git_reference *ref, const git_oid *old, const git_oid *new, const git_signature *who, const char *message) +static int reflog_append( + refdb_fs_backend *backend, + const git_reference *ref, + const git_oid *old, + const git_oid *new, + const git_signature *who, + const char *message) { int error, is_symbolic, open_flags; - git_oid old_id = {{0}}, new_id = {{0}}; + git_oid old_id, new_id; git_str buf = GIT_STR_INIT, path = GIT_STR_INIT; git_repository *repo = backend->repo; @@ -2206,6 +2233,9 @@ static int reflog_append(refdb_fs_backend *backend, const git_reference *ref, co /* From here on is_symbolic also means that it's HEAD */ + git_oid_clear(&old_id, backend->oid_type); + git_oid_clear(&new_id, backend->oid_type); + if (old) { git_oid_cpy(&old_id, old); } else { @@ -2402,6 +2432,7 @@ int git_refdb_backend_fs( goto fail; backend->repo = repository; + backend->oid_type = repository->oid_type; if (repository->gitdir) { backend->gitpath = setup_namespace(repository, repository->gitdir); diff --git a/src/libgit2/reflog.c b/src/libgit2/reflog.c index 1e9c0d4f1..86d4355e3 100644 --- a/src/libgit2/reflog.c +++ b/src/libgit2/reflog.c @@ -71,7 +71,11 @@ int git_reflog_write(git_reflog *reflog) return db->backend->reflog_write(db->backend, reflog); } -int git_reflog_append(git_reflog *reflog, const git_oid *new_oid, const git_signature *committer, const char *msg) +int git_reflog_append( + git_reflog *reflog, + const git_oid *new_oid, + const git_signature *committer, + const char *msg) { const git_reflog_entry *previous; git_reflog_entry *entry; @@ -104,7 +108,7 @@ int git_reflog_append(git_reflog *reflog, const git_oid *new_oid, const git_sign previous = git_reflog_entry_byindex(reflog, 0); if (previous == NULL) - git_oid_fromstr(&entry->oid_old, GIT_OID_HEX_ZERO); + git_oid_clear(&entry->oid_old, reflog->oid_type); else git_oid_cpy(&entry->oid_old, &previous->oid_cur); @@ -219,9 +223,7 @@ int git_reflog_drop(git_reflog *reflog, size_t idx, int rewrite_previous_entry) /* If the oldest entry has just been removed... */ if (idx == entrycount - 1) { /* ...clear the oid_old member of the "new" oldest entry */ - if (git_oid_fromstr(&entry->oid_old, GIT_OID_HEX_ZERO) < 0) - return -1; - + git_oid_clear(&entry->oid_old, reflog->oid_type); return 0; } diff --git a/src/libgit2/reflog.h b/src/libgit2/reflog.h index 8c3895952..bc9878598 100644 --- a/src/libgit2/reflog.h +++ b/src/libgit2/reflog.h @@ -16,8 +16,6 @@ #define GIT_REFLOG_DIR_MODE 0777 #define GIT_REFLOG_FILE_MODE 0666 -#define GIT_REFLOG_SIZE_MIN (2*GIT_OID_HEXSZ+2+17) - struct git_reflog_entry { git_oid oid_old; git_oid oid_cur; @@ -30,6 +28,7 @@ struct git_reflog_entry { struct git_reflog { git_refdb *db; char *ref_name; + git_oid_t oid_type; git_vector entries; }; diff --git a/src/libgit2/refs.c b/src/libgit2/refs.c index 5c875b95b..8e4abaccc 100644 --- a/src/libgit2/refs.c +++ b/src/libgit2/refs.c @@ -86,6 +86,8 @@ git_reference *git_reference__alloc( if (peel != NULL) git_oid_cpy(&ref->peel, peel); + else + git_oid_clear(&ref->peel, GIT_OID_SHA1); return ref; } diff --git a/src/libgit2/remote.c b/src/libgit2/remote.c index 3d0593712..c3e2a324d 100644 --- a/src/libgit2/remote.c +++ b/src/libgit2/remote.c @@ -17,6 +17,7 @@ #include "fetchhead.h" #include "push.h" #include "proxy.h" +#include "strarray.h" #include "git2/config.h" #include "git2/types.h" @@ -1026,6 +1027,24 @@ int git_remote_capabilities(unsigned int *out, git_remote *remote) return remote->transport->capabilities(out, remote->transport); } +int git_remote_oid_type(git_oid_t *out, git_remote *remote) +{ + GIT_ASSERT_ARG(remote); + + if (!remote->transport) { + git_error_set(GIT_ERROR_NET, "this remote has never connected"); + *out = 0; + return -1; + } + +#ifdef GIT_EXPERIMENTAL_SHA256 + return remote->transport->oid_type(out, remote->transport); +#else + *out = GIT_OID_SHA1; + return 0; +#endif +} + static int lookup_config(char **out, git_config *cfg, const char *name) { git_config_entry *ce = NULL; @@ -1225,24 +1244,6 @@ static int ls_to_vector(git_vector *out, git_remote *remote) return 0; } -#define copy_opts(out, in) \ - if (in) { \ - (out)->callbacks = (in)->callbacks; \ - (out)->proxy_opts = (in)->proxy_opts; \ - (out)->custom_headers = (in)->custom_headers; \ - (out)->follow_redirects = (in)->follow_redirects; \ - } - -GIT_INLINE(int) connect_opts_from_fetch_opts( - git_remote_connect_options *out, - git_remote *remote, - const git_fetch_options *fetch_opts) -{ - git_remote_connect_options tmp = GIT_REMOTE_CONNECT_OPTIONS_INIT; - copy_opts(&tmp, fetch_opts); - return git_remote_connect_options_normalize(out, remote->repo, &tmp); -} - static int connect_or_reset_options( git_remote *remote, int direction, @@ -1330,7 +1331,8 @@ int git_remote_download( return -1; } - if (connect_opts_from_fetch_opts(&connect_opts, remote, opts) < 0) + if (git_remote_connect_options__from_fetch_opts(&connect_opts, + remote, opts) < 0) return -1; if ((error = connect_or_reset_options(remote, GIT_DIRECTION_FETCH, &connect_opts)) < 0) @@ -1350,6 +1352,8 @@ int git_remote_fetch( bool prune = false; git_str reflog_msg_buf = GIT_STR_INIT; git_remote_connect_options connect_opts = GIT_REMOTE_CONNECT_OPTIONS_INIT; + unsigned int capabilities; + git_oid_t oid_type; GIT_ASSERT_ARG(remote); @@ -1358,7 +1362,8 @@ int git_remote_fetch( return -1; } - if (connect_opts_from_fetch_opts(&connect_opts, remote, opts) < 0) + if (git_remote_connect_options__from_fetch_opts(&connect_opts, + remote, opts) < 0) return -1; if ((error = connect_or_reset_options(remote, GIT_DIRECTION_FETCH, &connect_opts)) < 0) @@ -1369,6 +1374,10 @@ int git_remote_fetch( tagopt = opts->download_tags; } + if ((error = git_remote_capabilities(&capabilities, remote)) < 0 || + (error = git_remote_oid_type(&oid_type, remote)) < 0) + return error; + /* Connect and download everything */ error = git_remote__download(remote, refspecs, opts); @@ -1622,7 +1631,7 @@ int git_remote_prune(git_remote *remote, const git_remote_callbacks *callbacks) const git_refspec *spec; const char *refname; int error; - git_oid zero_id = {{ 0 }}; + git_oid zero_id = GIT_OID_SHA1_ZERO; if (callbacks) GIT_ERROR_CHECK_VERSION(callbacks, GIT_REMOTE_CALLBACKS_VERSION, "git_remote_callbacks"); @@ -1724,7 +1733,7 @@ static int update_ref( const git_remote_callbacks *callbacks) { git_reference *ref; - git_oid old_id; + git_oid old_id = GIT_OID_SHA1_ZERO; int error; error = git_reference_name_to_id(&old_id, remote->repo, ref_name); @@ -1830,7 +1839,7 @@ static int update_one_tip( } if (error == GIT_ENOTFOUND) { - memset(&old, 0, sizeof(git_oid)); + git_oid_clear(&old, GIT_OID_SHA1); error = 0; if (autotag && (error = git_vector_insert(update_heads, head)) < 0) @@ -1892,10 +1901,10 @@ static int update_tips_for_spec( } /* Handle specified oid sources */ - if (git_oid__is_hexstr(spec->src)) { + if (git_oid__is_hexstr(spec->src, GIT_OID_SHA1)) { git_oid id; - if ((error = git_oid_fromstr(&id, spec->src)) < 0) + if ((error = git_oid__fromstr(&id, spec->src, GIT_OID_SHA1)) < 0) goto on_error; if (spec->dst && @@ -2896,16 +2905,6 @@ done: return error; } -GIT_INLINE(int) connect_opts_from_push_opts( - git_remote_connect_options *out, - git_remote *remote, - const git_push_options *push_opts) -{ - git_remote_connect_options tmp = GIT_REMOTE_CONNECT_OPTIONS_INIT; - copy_opts(&tmp, push_opts); - return git_remote_connect_options_normalize(out, remote->repo, &tmp); -} - int git_remote_upload( git_remote *remote, const git_strarray *refspecs, @@ -2924,7 +2923,8 @@ int git_remote_upload( return -1; } - if ((error = connect_opts_from_push_opts(&connect_opts, remote, opts)) < 0) + if ((error = git_remote_connect_options__from_push_opts( + &connect_opts, remote, opts)) < 0) goto cleanup; if ((error = connect_or_reset_options(remote, GIT_DIRECTION_PUSH, &connect_opts)) < 0) @@ -2985,7 +2985,8 @@ int git_remote_push( return -1; } - if (connect_opts_from_push_opts(&connect_opts, remote, opts) < 0) + if (git_remote_connect_options__from_push_opts(&connect_opts, + remote, opts) < 0) return -1; if ((error = git_remote_upload(remote, refspecs, opts)) < 0) diff --git a/src/libgit2/remote.h b/src/libgit2/remote.h index 41ee58e0f..676b3c2ab 100644 --- a/src/libgit2/remote.h +++ b/src/libgit2/remote.h @@ -17,6 +17,7 @@ #include "refspec.h" #include "vector.h" #include "net.h" +#include "proxy.h" #define GIT_REMOTE_ORIGIN "origin" @@ -56,5 +57,44 @@ int git_remote_connect_options_normalize( const git_remote_connect_options *src); int git_remote_capabilities(unsigned int *out, git_remote *remote); +int git_remote_oid_type(git_oid_t *out, git_remote *remote); + + +#define git_remote_connect_options__copy_opts(out, in) \ + if (in) { \ + (out)->callbacks = (in)->callbacks; \ + (out)->proxy_opts = (in)->proxy_opts; \ + (out)->custom_headers = (in)->custom_headers; \ + (out)->follow_redirects = (in)->follow_redirects; \ + } + +GIT_INLINE(int) git_remote_connect_options__from_fetch_opts( + git_remote_connect_options *out, + git_remote *remote, + const git_fetch_options *fetch_opts) +{ + git_remote_connect_options tmp = GIT_REMOTE_CONNECT_OPTIONS_INIT; + git_remote_connect_options__copy_opts(&tmp, fetch_opts); + return git_remote_connect_options_normalize(out, remote->repo, &tmp); +} + +GIT_INLINE(int) git_remote_connect_options__from_push_opts( + git_remote_connect_options *out, + git_remote *remote, + const git_push_options *push_opts) +{ + git_remote_connect_options tmp = GIT_REMOTE_CONNECT_OPTIONS_INIT; + git_remote_connect_options__copy_opts(&tmp, push_opts); + return git_remote_connect_options_normalize(out, remote->repo, &tmp); +} + +#undef git_remote_connect_options__copy_opts + +GIT_INLINE(void) git_remote_connect_options__dispose( + git_remote_connect_options *opts) +{ + git_proxy_options_dispose(&opts->proxy_opts); + git_strarray_dispose(&opts->custom_headers); +} #endif diff --git a/src/libgit2/repository.c b/src/libgit2/repository.c index f761b5f32..8c41167a1 100644 --- a/src/libgit2/repository.c +++ b/src/libgit2/repository.c @@ -67,6 +67,7 @@ static const struct { static int check_repositoryformatversion(int *version, git_config *config); static int check_extensions(git_config *config, int version); static int load_global_config(git_config **config); +static int load_objectformat(git_repository *repo, git_config *config); #define GIT_COMMONDIR_FILE "commondir" #define GIT_GITDIR_FILE "gitdir" @@ -75,8 +76,8 @@ static int load_global_config(git_config **config); #define GIT_BRANCH_DEFAULT "master" -#define GIT_REPO_VERSION 0 -#define GIT_REPO_MAX_VERSION 1 +#define GIT_REPO_VERSION_DEFAULT 0 +#define GIT_REPO_VERSION_MAX 1 git_str git_repository__reserved_names_win32[] = { { DOT_GIT, 0, CONST_STRLEN(DOT_GIT) }, @@ -240,7 +241,7 @@ GIT_INLINE(int) validate_repo_path(git_str *path) */ static size_t suffix_len = CONST_STRLEN("objects/pack/pack-.pack.lock") + - GIT_OID_HEXSZ; + GIT_OID_MAX_HEXSIZE; return git_fs_path_validate_str_length_with_suffix( path, suffix_len); @@ -495,12 +496,47 @@ static int validate_ownership_cb(const git_config_entry *entry, void *payload) { validate_ownership_data *data = payload; - if (strcmp(entry->value, "") == 0) + if (strcmp(entry->value, "") == 0) { *data->is_safe = false; - - if (git_fs_path_prettify_dir(&data->tmp, entry->value, NULL) == 0 && - strcmp(data->tmp.ptr, data->repo_path) == 0) + } else if (strcmp(entry->value, "*") == 0) { *data->is_safe = true; + } else { + const char *test_path = entry->value; + +#ifdef GIT_WIN32 + /* + * Git for Windows does some truly bizarre things with + * paths that start with a forward slash; and expects you + * to escape that with `%(prefix)`. This syntax generally + * means to add the prefix that Git was installed to -- eg + * `/usr/local` -- unless it's an absolute path, in which + * case the leading `%(prefix)/` is just removed. And Git + * for Windows expects you to use this syntax for absolute + * Unix-style paths (in "Git Bash" or Windows Subsystem for + * Linux). + * + * Worse, the behavior used to be that a leading `/` was + * not absolute. It would indicate that Git for Windows + * should add the prefix. So `//` is required for absolute + * Unix-style paths. Yes, this is truly horrifying. + * + * Emulate that behavior, I guess, but only for absolute + * paths. We won't deal with the Git install prefix. Also, + * give WSL users an escape hatch where they don't have to + * think about this and can use the literal path that the + * filesystem APIs provide (`//wsl.localhost/...`). + */ + if (strncmp(test_path, "%(prefix)//", strlen("%(prefix)//")) == 0) + test_path += strlen("%(prefix)/"); + else if (strncmp(test_path, "//", 2) == 0 && + strncmp(test_path, "//wsl.localhost/", strlen("//wsl.localhost/")) != 0) + test_path++; +#endif + + if (git_fs_path_prettify_dir(&data->tmp, test_path, NULL) == 0 && + strcmp(data->tmp.ptr, data->repo_path) == 0) + *data->is_safe = true; + } return 0; } @@ -521,6 +557,9 @@ static int validate_ownership_config(bool *is_safe, const char *path) validate_ownership_cb, &ownership_data); + if (error == GIT_ENOTFOUND) + error = 0; + git_config_free(config); git_str_dispose(&ownership_data.tmp); @@ -541,6 +580,9 @@ static int validate_ownership_path(bool *is_safe, const char *path) if (error == GIT_ENOTFOUND) { *is_safe = true; error = 0; + } else if (error == GIT_EINVALID) { + *is_safe = false; + error = 0; } return error; @@ -727,6 +769,43 @@ out: return error; } +static int obtain_config_and_set_oid_type( + git_config **config_ptr, + git_repository *repo) +{ + int error; + git_config *config = NULL; + int version = 0; + + /* + * We'd like to have the config, but git doesn't particularly + * care if it's not there, so we need to deal with that. + */ + + error = git_repository_config_snapshot(&config, repo); + if (error < 0 && error != GIT_ENOTFOUND) + goto out; + + if (config && + (error = check_repositoryformatversion(&version, config)) < 0) + goto out; + + if ((error = check_extensions(config, version)) < 0) + goto out; + + if (version > 0) { + if ((error = load_objectformat(repo, config)) < 0) + goto out; + } else { + repo->oid_type = GIT_OID_SHA1; + } + +out: + *config_ptr = config; + + return error; +} + int git_repository_open_bare( git_repository **repo_ptr, const char *bare_path) @@ -735,6 +814,7 @@ int git_repository_open_bare( git_repository *repo = NULL; bool is_valid; int error; + git_config *config; if ((error = git_fs_path_prettify_dir(&path, bare_path, NULL)) < 0 || (error = is_valid_repository_path(&is_valid, &path, &common_path)) < 0) @@ -760,8 +840,15 @@ int git_repository_open_bare( repo->is_worktree = 0; repo->workdir = NULL; + if ((error = obtain_config_and_set_oid_type(&config, repo)) < 0) + goto cleanup; + *repo_ptr = repo; - return 0; + +cleanup: + git_config_free(config); + + return error; } static int _git_repository_open_ext_from_env( @@ -843,7 +930,7 @@ static int _git_repository_open_ext_from_env( else if (error < 0) goto error; else { - error = git_odb_open(&odb, git_str_cstr(&object_dir_buf)); + error = git_odb__open(&odb, git_str_cstr(&object_dir_buf), NULL); if (error < 0) goto error; } @@ -968,7 +1055,6 @@ int git_repository_open_ext( gitlink = GIT_STR_INIT, commondir = GIT_STR_INIT; git_repository *repo = NULL; git_config *config = NULL; - int version = 0; if (flags & GIT_REPOSITORY_OPEN_FROM_ENV) return _git_repository_open_ext_from_env(repo_ptr, start_path); @@ -1001,19 +1087,8 @@ int git_repository_open_ext( goto cleanup; repo->is_worktree = is_worktree; - /* - * We'd like to have the config, but git doesn't particularly - * care if it's not there, so we need to deal with that. - */ - - error = git_repository_config_snapshot(&config, repo); - if (error < 0 && error != GIT_ENOTFOUND) - goto cleanup; - - if (config && (error = check_repositoryformatversion(&version, config)) < 0) - goto cleanup; - - if ((error = check_extensions(config, version)) < 0) + error = obtain_config_and_set_oid_type(&config, repo); + if (error < 0) goto cleanup; if ((flags & GIT_REPOSITORY_OPEN_BARE) != 0) { @@ -1264,11 +1339,14 @@ int git_repository_odb__weakptr(git_odb **out, git_repository *repo) *out = git_atomic_load(repo->_odb); if (*out == NULL) { git_str odb_path = GIT_STR_INIT; + git_odb_options odb_opts = GIT_ODB_OPTIONS_INIT; git_odb *odb; + odb_opts.oid_type = repo->oid_type; + if ((error = git_repository__item_path(&odb_path, repo, GIT_REPOSITORY_ITEM_OBJECTS)) < 0 || - (error = git_odb_new(&odb)) < 0) + (error = git_odb__new(&odb, &odb_opts)) < 0) return error; GIT_REFCOUNT_OWN(odb, repo); @@ -1526,6 +1604,7 @@ static int check_repositoryformatversion(int *version, git_config *config) int error; error = git_config_get_int32(version, config, "core.repositoryformatversion"); + /* git ignores this if the config variable isn't there */ if (error == GIT_ENOTFOUND) return 0; @@ -1533,10 +1612,15 @@ static int check_repositoryformatversion(int *version, git_config *config) if (error < 0) return -1; - if (GIT_REPO_MAX_VERSION < *version) { + if (*version < 0) { + git_error_set(GIT_ERROR_REPOSITORY, + "invalid repository version %d", *version); + } + + if (GIT_REPO_VERSION_MAX < *version) { git_error_set(GIT_ERROR_REPOSITORY, "unsupported repository version %d; only versions up to %d are supported", - *version, GIT_REPO_MAX_VERSION); + *version, GIT_REPO_VERSION_MAX); return -1; } @@ -1544,7 +1628,8 @@ static int check_repositoryformatversion(int *version, git_config *config) } static const char *builtin_extensions[] = { - "noop" + "noop", + "objectformat" }; static git_vector user_extensions = GIT_VECTOR_INIT; @@ -1608,6 +1693,79 @@ static int check_extensions(git_config *config, int version) return git_config_foreach_match(config, "^extensions\\.", check_valid_extension, NULL); } +static int load_objectformat(git_repository *repo, git_config *config) +{ + git_config_entry *entry = NULL; + int error; + + if ((error = git_config_get_entry(&entry, config, "extensions.objectformat")) < 0) { + if (error == GIT_ENOTFOUND) { + repo->oid_type = GIT_OID_SHA1; + git_error_clear(); + error = 0; + } + + goto done; + } + + if ((repo->oid_type = git_oid_type_fromstr(entry->value)) == 0) { + git_error_set(GIT_ERROR_REPOSITORY, + "unknown object format '%s'", entry->value); + error = GIT_EINVALID; + } + +done: + git_config_entry_free(entry); + return error; +} + +int git_repository__set_objectformat( + git_repository *repo, + git_oid_t oid_type) +{ + git_config *cfg; + + /* + * Older clients do not necessarily understand the + * `objectformat` extension, even when it's set to an + * object format that they understand (SHA1). Do not set + * the objectformat extension unless we're not using the + * default object format. + */ + if (oid_type == GIT_OID_DEFAULT) + return 0; + + if (!git_repository_is_empty(repo) && repo->oid_type != oid_type) { + git_error_set(GIT_ERROR_REPOSITORY, + "cannot change object id type of existing repository"); + return -1; + } + + if (git_repository_config__weakptr(&cfg, repo) < 0) + return -1; + + if (git_config_set_int32(cfg, + "core.repositoryformatversion", 1) < 0 || + git_config_set_string(cfg, "extensions.objectformat", + git_oid_type_name(oid_type)) < 0) + return -1; + + /* + * During repo init, we may create some backends with the + * default oid type. Clear them so that we create them with + * the proper oid type. + */ + if (repo->oid_type != oid_type) { + set_index(repo, NULL); + set_odb(repo, NULL); + set_refdb(repo, NULL); + + repo->oid_type = oid_type; + } + + return 0; +} + int git_repository__extensions(char ***out, size_t *out_len) { git_vector extensions; @@ -1886,19 +2044,21 @@ static int repo_init_config( const char *repo_dir, const char *work_dir, uint32_t flags, - uint32_t mode) + uint32_t mode, + git_oid_t oid_type) { int error = 0; git_str cfg_path = GIT_STR_INIT, worktree_path = GIT_STR_INIT; git_config *config = NULL; bool is_bare = ((flags & GIT_REPOSITORY_INIT_BARE) != 0); bool is_reinit = ((flags & GIT_REPOSITORY_INIT__IS_REINIT) != 0); - int version = 0; + int version = GIT_REPO_VERSION_DEFAULT; if ((error = repo_local_config(&config, &cfg_path, NULL, repo_dir)) < 0) goto cleanup; - if (is_reinit && (error = check_repositoryformatversion(&version, config)) < 0) + if (is_reinit && + (error = check_repositoryformatversion(&version, config)) < 0) goto cleanup; if ((error = check_extensions(config, version)) < 0) @@ -1909,7 +2069,7 @@ static int repo_init_config( goto cleanup; } while (0) SET_REPO_CONFIG(bool, "core.bare", is_bare); - SET_REPO_CONFIG(int32, "core.repositoryformatversion", GIT_REPO_VERSION); + SET_REPO_CONFIG(int32, "core.repositoryformatversion", version); if ((error = repo_init_fs_configs( config, cfg_path.ptr, repo_dir, work_dir, !is_reinit)) < 0) @@ -1942,6 +2102,11 @@ static int repo_init_config( SET_REPO_CONFIG(bool, "receive.denyNonFastforwards", true); } + if (oid_type != GIT_OID_SHA1) { + SET_REPO_CONFIG(int32, "core.repositoryformatversion", 1); + SET_REPO_CONFIG(string, "extensions.objectformat", git_oid_type_name(oid_type)); + } + cleanup: git_str_dispose(&cfg_path); git_str_dispose(&worktree_path); @@ -2422,6 +2587,7 @@ int git_repository_init_ext( common_path = GIT_STR_INIT; const char *wd; bool is_valid; + git_oid_t oid_type = GIT_OID_DEFAULT; int error; GIT_ASSERT_ARG(out); @@ -2430,6 +2596,11 @@ int git_repository_init_ext( GIT_ERROR_CHECK_VERSION(opts, GIT_REPOSITORY_INIT_OPTIONS_VERSION, "git_repository_init_options"); +#ifdef GIT_EXPERIMENTAL_SHA256 + if (opts->oid_type) + oid_type = opts->oid_type; +#endif + if ((error = repo_init_directories(&repo_path, &wd_path, given_repo, opts)) < 0) goto out; @@ -2448,13 +2619,13 @@ int git_repository_init_ext( opts->flags |= GIT_REPOSITORY_INIT__IS_REINIT; - if ((error = repo_init_config(repo_path.ptr, wd, opts->flags, opts->mode)) < 0) + if ((error = repo_init_config(repo_path.ptr, wd, opts->flags, opts->mode, oid_type)) < 0) goto out; /* TODO: reinitialize the templates */ } else { if ((error = repo_init_structure(repo_path.ptr, wd, opts)) < 0 || - (error = repo_init_config(repo_path.ptr, wd, opts->flags, opts->mode)) < 0 || + (error = repo_init_config(repo_path.ptr, wd, opts->flags, opts->mode, oid_type)) < 0 || (error = repo_init_head(repo_path.ptr, opts->initial_head)) < 0) goto out; } @@ -2917,14 +3088,14 @@ int git_repository__set_orig_head(git_repository *repo, const git_oid *orig_head { git_filebuf file = GIT_FILEBUF_INIT; git_str file_path = GIT_STR_INIT; - char orig_head_str[GIT_OID_HEXSZ]; + char orig_head_str[GIT_OID_MAX_HEXSIZE]; int error = 0; git_oid_fmt(orig_head_str, orig_head); if ((error = git_str_joinpath(&file_path, repo->gitdir, GIT_ORIG_HEAD_FILE)) == 0 && (error = git_filebuf_open(&file, file_path.ptr, GIT_FILEBUF_CREATE_LEADING_DIRS, GIT_MERGE_FILE_MODE)) == 0 && - (error = git_filebuf_printf(&file, "%.*s\n", GIT_OID_HEXSZ, orig_head_str)) == 0) + (error = git_filebuf_printf(&file, "%.*s\n", (int)git_oid_hexsize(repo->oid_type), orig_head_str)) == 0) error = git_filebuf_commit(&file); if (error < 0) @@ -3037,7 +3208,7 @@ int git_repository_hashfile( goto cleanup; } - error = git_odb__hashfd_filtered(out, fd, (size_t)len, type, fl); + error = git_odb__hashfd_filtered(out, fd, (size_t)len, type, repo->oid_type, fl); cleanup: if (fd >= 0) @@ -3384,3 +3555,8 @@ int git_repository_submodule_cache_clear(git_repository *repo) repo->submodule_cache = NULL; return error; } + +git_oid_t git_repository_oid_type(git_repository *repo) +{ + return repo ? repo->oid_type : 0; +} diff --git a/src/libgit2/repository.h b/src/libgit2/repository.h index a488f2bf2..75380ae53 100644 --- a/src/libgit2/repository.h +++ b/src/libgit2/repository.h @@ -153,6 +153,7 @@ struct git_repository { unsigned is_bare:1; unsigned is_worktree:1; + git_oid_t oid_type; unsigned int lru_counter; @@ -256,4 +257,12 @@ int git_repository__extensions(char ***out, size_t *out_len); int git_repository__set_extensions(const char **extensions, size_t len); void git_repository__free_extensions(void); +/* + * Set the object format (OID type) for a repository; this will set + * both the configuration and the internal value for the oid type. + */ +int git_repository__set_objectformat( + git_repository *repo, + git_oid_t oid_type); + #endif diff --git a/src/libgit2/reset.c b/src/libgit2/reset.c index e0d942e5e..9574819cb 100644 --- a/src/libgit2/reset.c +++ b/src/libgit2/reset.c @@ -188,9 +188,9 @@ int git_reset( git_reset_t reset_type, const git_checkout_options *checkout_opts) { - char to[GIT_OID_HEXSZ + 1]; + char to[GIT_OID_SHA1_HEXSIZE + 1]; - git_oid_tostr(to, GIT_OID_HEXSZ + 1, git_object_id(target)); + git_oid_tostr(to, GIT_OID_SHA1_HEXSIZE + 1, git_object_id(target)); return reset(repo, target, to, reset_type, checkout_opts); } diff --git a/src/libgit2/revert.c b/src/libgit2/revert.c index d6ab6ae3c..1106dfe2f 100644 --- a/src/libgit2/revert.c +++ b/src/libgit2/revert.c @@ -107,10 +107,10 @@ static int revert_state_cleanup(git_repository *repo) static int revert_seterr(git_commit *commit, const char *fmt) { - char commit_oidstr[GIT_OID_HEXSZ + 1]; + char commit_oidstr[GIT_OID_SHA1_HEXSIZE + 1]; git_oid_fmt(commit_oidstr, git_commit_id(commit)); - commit_oidstr[GIT_OID_HEXSZ] = '\0'; + commit_oidstr[GIT_OID_SHA1_HEXSIZE] = '\0'; git_error_set(GIT_ERROR_REVERT, fmt, commit_oidstr); @@ -176,7 +176,7 @@ int git_revert( git_revert_options opts; git_reference *our_ref = NULL; git_commit *our_commit = NULL; - char commit_oidstr[GIT_OID_HEXSZ + 1]; + char commit_oidstr[GIT_OID_SHA1_HEXSIZE + 1]; const char *commit_msg; git_str their_label = GIT_STR_INIT; git_index *index = NULL; @@ -192,7 +192,7 @@ int git_revert( return error; git_oid_fmt(commit_oidstr, git_commit_id(commit)); - commit_oidstr[GIT_OID_HEXSZ] = '\0'; + commit_oidstr[GIT_OID_SHA1_HEXSIZE] = '\0'; if ((commit_msg = git_commit_summary(commit)) == NULL) { error = -1; diff --git a/src/libgit2/revparse.c b/src/libgit2/revparse.c index 9bc28e9fc..964afe378 100644 --- a/src/libgit2/revparse.c +++ b/src/libgit2/revparse.c @@ -15,21 +15,28 @@ #include "git2.h" -static int maybe_sha_or_abbrev(git_object **out, git_repository *repo, const char *spec, size_t speclen) +static int maybe_sha_or_abbrev( + git_object **out, + git_repository *repo, + const char *spec, + size_t speclen) { git_oid oid; - if (git_oid_fromstrn(&oid, spec, speclen) < 0) + if (git_oid__fromstrn(&oid, spec, speclen, repo->oid_type) < 0) return GIT_ENOTFOUND; return git_object_lookup_prefix(out, repo, &oid, speclen, GIT_OBJECT_ANY); } -static int maybe_sha(git_object **out, git_repository *repo, const char *spec) +static int maybe_sha( + git_object **out, + git_repository *repo, + const char *spec) { size_t speclen = strlen(spec); - if (speclen != GIT_OID_HEXSZ) + if (speclen != git_oid_hexsize(repo->oid_type)) return GIT_ENOTFOUND; return maybe_sha_or_abbrev(out, repo, spec, speclen); @@ -110,8 +117,8 @@ static int revparse_lookup_object( if (error != GIT_ENOTFOUND) return error; - if ((strlen(spec) < GIT_OID_HEXSZ) && - ((error = maybe_abbrev(object_out, repo, spec)) != GIT_ENOTFOUND)) + if ((strlen(spec) < git_oid_hexsize(repo->oid_type)) && + ((error = maybe_abbrev(object_out, repo, spec)) != GIT_ENOTFOUND)) return error; if ((error = maybe_describe(object_out, repo, spec)) != GIT_ENOTFOUND) @@ -268,7 +275,16 @@ static int retrieve_revobject_from_reflog(git_object **out, git_reference **base int error = -1; if (*base_ref == NULL) { - if ((error = git_reference_dwim(&ref, repo, identifier)) < 0) + /* + * When HEAD@{n} is specified, do not use dwim, which would resolve the + * reference (to the current branch that HEAD is pointing to). + */ + if (position > 0 && strcmp(identifier, GIT_HEAD_FILE) == 0) + error = git_reference_lookup(&ref, repo, GIT_HEAD_FILE); + else + error = git_reference_dwim(&ref, repo, identifier); + + if (error < 0) return error; } else { ref = *base_ref; diff --git a/src/libgit2/revwalk.c b/src/libgit2/revwalk.c index 553e0497a..3269d9279 100644 --- a/src/libgit2/revwalk.c +++ b/src/libgit2/revwalk.c @@ -121,8 +121,12 @@ int git_revwalk__push_ref(git_revwalk *walk, const char *refname, const git_revw { git_oid oid; - if (git_reference_name_to_id(&oid, walk->repo, refname) < 0) + int error = git_reference_name_to_id(&oid, walk->repo, refname); + if (opts->from_glob && (error == GIT_ENOTFOUND || error == GIT_EINVALIDSPEC || error == GIT_EPEEL)) { + return 0; + } else if (error < 0) { return -1; + } return git_revwalk__push_commit(walk, &oid, opts); } diff --git a/src/libgit2/stash.c b/src/libgit2/stash.c index 5fc01ac36..319ae3a3f 100644 --- a/src/libgit2/stash.c +++ b/src/libgit2/stash.c @@ -25,6 +25,7 @@ #include "merge.h" #include "diff.h" #include "diff_generate.h" +#include "strarray.h" static int create_error(int error, const char *msg) { @@ -193,6 +194,30 @@ static int stash_to_index( return git_index_add(index, &entry); } +static int stash_update_index_from_paths( + git_repository *repo, + git_index *index, + const git_strarray *paths) +{ + unsigned int status_flags; + size_t i; + int error = 0; + + for (i = 0; i < paths->count; i++) { + git_status_file(&status_flags, repo, paths->strings[i]); + + if (status_flags & (GIT_STATUS_WT_DELETED | GIT_STATUS_INDEX_DELETED)) { + if ((error = git_index_remove(index, paths->strings[i], 0)) < 0) + return error; + } else { + if ((error = stash_to_index(repo, index, paths->strings[i])) < 0) + return error; + } + } + + return error; +} + static int stash_update_index_from_diff( git_repository *repo, git_index *index, @@ -388,6 +413,66 @@ cleanup: return error; } +static int build_stash_commit_from_tree( + git_oid *w_commit_oid, + git_repository *repo, + const git_signature *stasher, + const char *message, + git_commit *i_commit, + git_commit *b_commit, + git_commit *u_commit, + const git_tree *tree) +{ + const git_commit *parents[] = { NULL, NULL, NULL }; + + parents[0] = b_commit; + parents[1] = i_commit; + parents[2] = u_commit; + + return git_commit_create( + w_commit_oid, + repo, + NULL, + stasher, + stasher, + NULL, + message, + tree, + u_commit ? 3 : 2, + parents); +} + +static int build_stash_commit_from_index( + git_oid *w_commit_oid, + git_repository *repo, + const git_signature *stasher, + const char *message, + git_commit *i_commit, + git_commit *b_commit, + git_commit *u_commit, + git_index *index) +{ + git_tree *tree; + int error; + + if ((error = build_tree_from_index(&tree, repo, index)) < 0) + goto cleanup; + + error = build_stash_commit_from_tree( + w_commit_oid, + repo, + stasher, + message, + i_commit, + b_commit, + u_commit, + tree); + +cleanup: + git_tree_free(tree); + return error; +} + static int commit_worktree( git_oid *w_commit_oid, git_repository *repo, @@ -397,15 +482,10 @@ static int commit_worktree( git_commit *b_commit, git_commit *u_commit) { - const git_commit *parents[] = { NULL, NULL, NULL }; git_index *i_index = NULL, *r_index = NULL; git_tree *w_tree = NULL; int error = 0, ignorecase; - parents[0] = b_commit; - parents[1] = i_commit; - parents[2] = u_commit; - if ((error = git_repository_index(&r_index, repo) < 0) || (error = git_index_new(&i_index)) < 0 || (error = git_index__fill(i_index, &r_index->entries) < 0) || @@ -417,17 +497,16 @@ static int commit_worktree( if ((error = build_workdir_tree(&w_tree, repo, i_index, b_commit)) < 0) goto cleanup; - error = git_commit_create( + error = build_stash_commit_from_tree( w_commit_oid, repo, - NULL, stasher, - stasher, - NULL, message, - w_tree, - u_commit ? 3 : 2, - parents); + i_commit, + b_commit, + u_commit, + w_tree + ); cleanup: git_tree_free(w_tree); @@ -520,6 +599,54 @@ static int ensure_there_are_changes_to_stash(git_repository *repo, uint32_t flag return error; } +static int has_changes_cb( + const char *path, + unsigned int status, + void *payload) +{ + GIT_UNUSED(path); + GIT_UNUSED(status); + GIT_UNUSED(payload); + + if (status == GIT_STATUS_CURRENT) + return GIT_ENOTFOUND; + + return 0; +} + +static int ensure_there_are_changes_to_stash_paths( + git_repository *repo, + uint32_t flags, + const git_strarray *paths) +{ + int error; + git_status_options opts = GIT_STATUS_OPTIONS_INIT; + + opts.show = GIT_STATUS_SHOW_INDEX_AND_WORKDIR; + opts.flags = GIT_STATUS_OPT_EXCLUDE_SUBMODULES | + GIT_STATUS_OPT_INCLUDE_UNMODIFIED | + GIT_STATUS_OPT_DISABLE_PATHSPEC_MATCH; + + if (flags & GIT_STASH_INCLUDE_UNTRACKED) + opts.flags |= GIT_STATUS_OPT_INCLUDE_UNTRACKED | + GIT_STATUS_OPT_RECURSE_UNTRACKED_DIRS; + + if (flags & GIT_STASH_INCLUDE_IGNORED) + opts.flags |= GIT_STATUS_OPT_INCLUDE_IGNORED | + GIT_STATUS_OPT_RECURSE_IGNORED_DIRS; + + git_strarray_copy(&opts.pathspec, paths); + + error = git_status_foreach_ext(repo, &opts, has_changes_cb, NULL); + + git_strarray_dispose(&opts.pathspec); + + if (error == GIT_ENOTFOUND) + return create_error(GIT_ENOTFOUND, "one of the files does not have any changes to stash."); + + return error; +} + static int reset_index_and_workdir(git_repository *repo, git_commit *commit, uint32_t flags) { git_checkout_options opts = GIT_CHECKOUT_OPTIONS_INIT; @@ -540,14 +667,36 @@ int git_stash_save( const char *message, uint32_t flags) { - git_index *index = NULL; + git_stash_save_options opts = GIT_STASH_SAVE_OPTIONS_INIT; + + GIT_ASSERT_ARG(stasher); + + opts.stasher = stasher; + opts.message = message; + opts.flags = flags; + + return git_stash_save_with_opts(out, repo, &opts); +} + +int git_stash_save_with_opts( + git_oid *out, + git_repository *repo, + const git_stash_save_options *opts) +{ + git_index *index = NULL, *paths_index = NULL; git_commit *b_commit = NULL, *i_commit = NULL, *u_commit = NULL; git_str msg = GIT_STR_INIT; + git_tree *tree = NULL; + git_reference *head = NULL; + bool has_paths = false; + int error; GIT_ASSERT_ARG(out); GIT_ASSERT_ARG(repo); - GIT_ASSERT_ARG(stasher); + GIT_ASSERT_ARG(opts && opts->stasher); + + has_paths = opts->paths.count > 0; if ((error = git_repository__ensure_not_bare(repo, "stash save")) < 0) return error; @@ -555,44 +704,63 @@ int git_stash_save( if ((error = retrieve_base_commit_and_message(&b_commit, &msg, repo)) < 0) goto cleanup; - if ((error = ensure_there_are_changes_to_stash(repo, flags)) < 0) + if (!has_paths && + (error = ensure_there_are_changes_to_stash(repo, opts->flags)) < 0) + goto cleanup; + else if (has_paths && + (error = ensure_there_are_changes_to_stash_paths( + repo, opts->flags, &opts->paths)) < 0) goto cleanup; if ((error = git_repository_index(&index, repo)) < 0) goto cleanup; - if ((error = commit_index(&i_commit, repo, index, stasher, + if ((error = commit_index(&i_commit, repo, index, opts->stasher, git_str_cstr(&msg), b_commit)) < 0) goto cleanup; - if ((flags & (GIT_STASH_INCLUDE_UNTRACKED | GIT_STASH_INCLUDE_IGNORED)) && - (error = commit_untracked(&u_commit, repo, stasher, - git_str_cstr(&msg), i_commit, flags)) < 0) + if ((opts->flags & (GIT_STASH_INCLUDE_UNTRACKED | GIT_STASH_INCLUDE_IGNORED)) && + (error = commit_untracked(&u_commit, repo, opts->stasher, + git_str_cstr(&msg), i_commit, opts->flags)) < 0) goto cleanup; - if ((error = prepare_worktree_commit_message(&msg, message)) < 0) + if ((error = prepare_worktree_commit_message(&msg, opts->message)) < 0) goto cleanup; - if ((error = commit_worktree(out, repo, stasher, git_str_cstr(&msg), - i_commit, b_commit, u_commit)) < 0) - goto cleanup; + if (!has_paths) { + if ((error = commit_worktree(out, repo, opts->stasher, git_str_cstr(&msg), + i_commit, b_commit, u_commit)) < 0) + goto cleanup; + } else { + if ((error = git_index_new(&paths_index)) < 0 || + (error = retrieve_head(&head, repo)) < 0 || + (error = git_reference_peel((git_object**)&tree, head, GIT_OBJECT_TREE)) < 0 || + (error = git_index_read_tree(paths_index, tree)) < 0 || + (error = stash_update_index_from_paths(repo, paths_index, &opts->paths)) < 0 || + (error = build_stash_commit_from_index(out, repo, opts->stasher, git_str_cstr(&msg), + i_commit, b_commit, u_commit, paths_index)) < 0) + goto cleanup; + } git_str_rtrim(&msg); if ((error = update_reflog(out, repo, git_str_cstr(&msg))) < 0) goto cleanup; - if ((error = reset_index_and_workdir(repo, (flags & GIT_STASH_KEEP_INDEX) ? i_commit : b_commit, - flags)) < 0) + if (!(opts->flags & GIT_STASH_KEEP_ALL) && + (error = reset_index_and_workdir(repo, + (opts->flags & GIT_STASH_KEEP_INDEX) ? i_commit : b_commit,opts->flags)) < 0) goto cleanup; cleanup: - git_str_dispose(&msg); git_commit_free(i_commit); git_commit_free(b_commit); git_commit_free(u_commit); + git_tree_free(tree); + git_reference_free(head); git_index_free(index); + git_index_free(paths_index); return error; } @@ -777,6 +945,13 @@ int git_stash_apply_options_init(git_stash_apply_options *opts, unsigned int ver return 0; } +int git_stash_save_options_init(git_stash_save_options *opts, unsigned int version) +{ + GIT_INIT_STRUCTURE_FROM_TEMPLATE( + opts, version, git_stash_save_options, GIT_STASH_SAVE_OPTIONS_INIT); + return 0; +} + #ifndef GIT_DEPRECATE_HARD int git_stash_apply_init_options(git_stash_apply_options *opts, unsigned int version) { diff --git a/src/libgit2/strarray.c b/src/libgit2/strarray.c index 2f9b77cc2..25e75f02a 100644 --- a/src/libgit2/strarray.c +++ b/src/libgit2/strarray.c @@ -8,6 +8,7 @@ #include "util.h" #include "common.h" +#include "strarray.h" int git_strarray_copy(git_strarray *tgt, const git_strarray *src) { diff --git a/src/libgit2/strarray.h b/src/libgit2/strarray.h new file mode 100644 index 000000000..198480535 --- /dev/null +++ b/src/libgit2/strarray.h @@ -0,0 +1,25 @@ +/* + * Copyright (C) the libgit2 contributors. All rights reserved. + * + * This file is part of libgit2, distributed under the GNU GPL v2 with + * a Linking Exception. For full terms see the included COPYING file. + */ +#ifndef INCLUDE_strarray_h__ +#define INCLUDE_strarray_h__ + +#include "common.h" +#include "git2/strarray.h" + +/** + * Copy a string array object from source to target. + * + * Note: target is overwritten and hence should be empty, otherwise its + * contents are leaked. Call git_strarray_free() if necessary. + * + * @param tgt target + * @param src source + * @return 0 on success, < 0 on allocation failure + */ +extern int git_strarray_copy(git_strarray *tgt, const git_strarray *src); + +#endif diff --git a/src/libgit2/streams/openssl.c b/src/libgit2/streams/openssl.c index 89c96780c..5e0e2c939 100644 --- a/src/libgit2/streams/openssl.c +++ b/src/libgit2/streams/openssl.c @@ -198,7 +198,7 @@ static int openssl_ensure_initialized(void) if ((error = git_openssl_stream_dynamic_init()) == 0) error = openssl_init(); - openssl_initialized = true; + openssl_initialized = !error; } error |= git_mutex_unlock(&openssl_mutex); diff --git a/src/libgit2/streams/openssl_dynamic.c b/src/libgit2/streams/openssl_dynamic.c index da16b6ed7..222c1099d 100644 --- a/src/libgit2/streams/openssl_dynamic.c +++ b/src/libgit2/streams/openssl_dynamic.c @@ -91,7 +91,7 @@ int (*sk_num)(const void *sk); void *(*sk_value)(const void *sk, int i); void (*sk_free)(void *sk); -void *openssl_handle; +static void *openssl_handle; GIT_INLINE(void *) openssl_sym(int *err, const char *name, bool required) { @@ -125,7 +125,8 @@ int git_openssl_stream_dynamic_init(void) (openssl_handle = dlopen("libssl.1.1.dylib", RTLD_NOW)) == NULL && (openssl_handle = dlopen("libssl.so.1.0.0", RTLD_NOW)) == NULL && (openssl_handle = dlopen("libssl.1.0.0.dylib", RTLD_NOW)) == NULL && - (openssl_handle = dlopen("libssl.so.10", RTLD_NOW)) == NULL) { + (openssl_handle = dlopen("libssl.so.10", RTLD_NOW)) == NULL && + (openssl_handle = dlopen("libssl.so.3", RTLD_NOW)) == NULL) { git_error_set(GIT_ERROR_SSL, "could not load ssl libraries"); return -1; } @@ -175,7 +176,6 @@ int git_openssl_stream_dynamic_init(void) SSL_connect = (int (*)(SSL *))openssl_sym(&err, "SSL_connect", true); SSL_ctrl = (long (*)(SSL *, int, long, void *))openssl_sym(&err, "SSL_ctrl", true); - SSL_get_peer_certificate = (X509 *(*)(const SSL *))openssl_sym(&err, "SSL_get_peer_certificate", true); SSL_library_init = (int (*)(void))openssl_sym(&err, "SSL_library_init", false); SSL_free = (void (*)(SSL *))openssl_sym(&err, "SSL_free", true); SSL_get_error = (int (*)(SSL *, int))openssl_sym(&err, "SSL_get_error", true); @@ -187,6 +187,10 @@ int git_openssl_stream_dynamic_init(void) SSL_shutdown = (int (*)(SSL *ssl))openssl_sym(&err, "SSL_shutdown", true); SSL_write = (int (*)(SSL *, const void *, int))openssl_sym(&err, "SSL_write", true); + if (!(SSL_get_peer_certificate = (X509 *(*)(const SSL *))openssl_sym(&err, "SSL_get_peer_certificate", false))) { + SSL_get_peer_certificate = (X509 *(*)(const SSL *))openssl_sym(&err, "SSL_get1_peer_certificate", true); + } + SSL_CTX_ctrl = (long (*)(SSL_CTX *, int, long, void *))openssl_sym(&err, "SSL_CTX_ctrl", true); SSL_CTX_free = (void (*)(SSL_CTX *))openssl_sym(&err, "SSL_CTX_free", true); SSL_CTX_new = (SSL_CTX *(*)(const SSL_METHOD *))openssl_sym(&err, "SSL_CTX_new", true); diff --git a/src/libgit2/streams/socket.c b/src/libgit2/streams/socket.c index 9415fe892..908e8c02f 100644 --- a/src/libgit2/streams/socket.c +++ b/src/libgit2/streams/socket.c @@ -135,9 +135,12 @@ static ssize_t socket_write(git_stream *stream, const char *data, size_t len, in git_socket_stream *st = (git_socket_stream *) stream; ssize_t written; + GIT_ASSERT(flags == 0); + GIT_UNUSED(flags); + errno = 0; - if ((written = p_send(st->s, data, len, flags)) < 0) { + if ((written = p_send(st->s, data, len, 0)) < 0) { net_set_error("error sending data"); return -1; } diff --git a/src/libgit2/submodule.c b/src/libgit2/submodule.c index 0f4f0726c..95ea84fc2 100644 --- a/src/libgit2/submodule.c +++ b/src/libgit2/submodule.c @@ -1338,7 +1338,11 @@ int git_submodule_update(git_submodule *sm, int init, git_submodule_update_optio /* Get the status of the submodule to determine if it is already initialized */ if ((error = git_submodule_status(&submodule_status, sm->repo, sm->name, GIT_SUBMODULE_IGNORE_UNSPECIFIED)) < 0) goto done; - + + /* If the submodule is configured but hasn't been added, skip it */ + if (submodule_status == GIT_SUBMODULE_STATUS_IN_CONFIG) + goto done; + /* * If submodule work dir is not already initialized, check to see * what we need to do (initialize, clone, return error...) @@ -1389,7 +1393,7 @@ int git_submodule_update(git_submodule *sm, int init, git_submodule_update_optio */ clone_options.checkout_opts.checkout_strategy = GIT_CHECKOUT_NONE; - if ((error = git_clone(&sub_repo, submodule_url, sm->path, &clone_options)) < 0 || + if ((error = git_clone__submodule(&sub_repo, submodule_url, sm->path, &clone_options)) < 0 || (error = git_repository_set_head_detached(sub_repo, git_submodule_index_id(sm))) < 0 || (error = git_checkout_head(sub_repo, &update_options.checkout_opts)) != 0) goto done; diff --git a/src/libgit2/sysdir.c b/src/libgit2/sysdir.c index 450cb509b..7838a6789 100644 --- a/src/libgit2/sysdir.c +++ b/src/libgit2/sysdir.c @@ -12,16 +12,262 @@ #include "fs_path.h" #include #if GIT_WIN32 -#include "win32/findfile.h" +# include "fs_path.h" +# include "win32/path_w32.h" +# include "win32/utf-conv.h" #else -#include -#include +# include +# include #endif +#ifdef GIT_WIN32 +# define REG_GITFORWINDOWS_KEY L"SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Uninstall\\Git_is1" +# define REG_GITFORWINDOWS_KEY_WOW64 L"SOFTWARE\\Wow6432Node\\Microsoft\\Windows\\CurrentVersion\\Uninstall\\Git_is1" + +static int expand_win32_path(git_win32_path dest, const wchar_t *src) +{ + DWORD len = ExpandEnvironmentStringsW(src, dest, GIT_WIN_PATH_UTF16); + + if (!len || len > GIT_WIN_PATH_UTF16) + return -1; + + return 0; +} + +static int win32_path_to_utf8(git_str *dest, const wchar_t *src) +{ + git_win32_utf8_path utf8_path; + + if (git_win32_path_to_utf8(utf8_path, src) < 0) { + git_error_set(GIT_ERROR_OS, "unable to convert path to UTF-8"); + return -1; + } + + /* Convert backslashes to forward slashes */ + git_fs_path_mkposix(utf8_path); + + return git_str_sets(dest, utf8_path); +} + +static git_win32_path mock_registry; +static bool mock_registry_set; + +extern int git_win32__set_registry_system_dir(const wchar_t *mock_sysdir) +{ + if (!mock_sysdir) { + mock_registry[0] = L'\0'; + mock_registry_set = false; + } else { + size_t len = wcslen(mock_sysdir); + + if (len > GIT_WIN_PATH_MAX) { + git_error_set(GIT_ERROR_INVALID, "mock path too long"); + return -1; + } + + wcscpy(mock_registry, mock_sysdir); + mock_registry_set = true; + } + + return 0; +} + +static int lookup_registry_key( + git_win32_path out, + const HKEY hive, + const wchar_t* key, + const wchar_t *value) +{ + HKEY hkey; + DWORD type, size; + int error = GIT_ENOTFOUND; + + /* + * Registry data may not be NUL terminated, provide room to do + * it ourselves. + */ + size = (DWORD)((sizeof(git_win32_path) - 1) * sizeof(wchar_t)); + + if (RegOpenKeyExW(hive, key, 0, KEY_READ, &hkey) != 0) + return GIT_ENOTFOUND; + + if (RegQueryValueExW(hkey, value, NULL, &type, (LPBYTE)out, &size) == 0 && + type == REG_SZ && + size > 0 && + size < sizeof(git_win32_path)) { + size_t wsize = size / sizeof(wchar_t); + size_t len = wsize - 1; + + if (out[wsize - 1] != L'\0') { + len = wsize; + out[wsize] = L'\0'; + } + + if (out[len - 1] == L'\\') + out[len - 1] = L'\0'; + + if (_waccess(out, F_OK) == 0) + error = 0; + } + + RegCloseKey(hkey); + return error; +} + +static int find_sysdir_in_registry(git_win32_path out) +{ + if (mock_registry_set) { + if (mock_registry[0] == L'\0') + return GIT_ENOTFOUND; + + wcscpy(out, mock_registry); + return 0; + } + + if (lookup_registry_key(out, HKEY_CURRENT_USER, REG_GITFORWINDOWS_KEY, L"InstallLocation") == 0 || + lookup_registry_key(out, HKEY_CURRENT_USER, REG_GITFORWINDOWS_KEY_WOW64, L"InstallLocation") == 0 || + lookup_registry_key(out, HKEY_LOCAL_MACHINE, REG_GITFORWINDOWS_KEY, L"InstallLocation") == 0 || + lookup_registry_key(out, HKEY_LOCAL_MACHINE, REG_GITFORWINDOWS_KEY_WOW64, L"InstallLocation") == 0) + return 0; + + return GIT_ENOTFOUND; +} + +static int find_sysdir_in_path(git_win32_path out) +{ + size_t out_len; + + if (git_win32_path_find_executable(out, L"git.exe") < 0 && + git_win32_path_find_executable(out, L"git.cmd") < 0) + return GIT_ENOTFOUND; + + out_len = wcslen(out); + + /* Trim the file name */ + if (out_len <= CONST_STRLEN(L"git.exe")) + return GIT_ENOTFOUND; + + out_len -= CONST_STRLEN(L"git.exe"); + + if (out_len && out[out_len - 1] == L'\\') + out_len--; + + /* + * Git for Windows usually places the command in a 'bin' or + * 'cmd' directory, trim that. + */ + if (out_len >= CONST_STRLEN(L"\\bin") && + wcsncmp(&out[out_len - CONST_STRLEN(L"\\bin")], L"\\bin", CONST_STRLEN(L"\\bin")) == 0) + out_len -= CONST_STRLEN(L"\\bin"); + else if (out_len >= CONST_STRLEN(L"\\cmd") && + wcsncmp(&out[out_len - CONST_STRLEN(L"\\cmd")], L"\\cmd", CONST_STRLEN(L"\\cmd")) == 0) + out_len -= CONST_STRLEN(L"\\cmd"); + + if (!out_len) + return GIT_ENOTFOUND; + + out[out_len] = L'\0'; + return 0; +} + +static int find_win32_dirs( + git_str *out, + const wchar_t* tmpl[]) +{ + git_win32_path path16; + git_str buf = GIT_STR_INIT; + + git_str_clear(out); + + for (; *tmpl != NULL; tmpl++) { + if (!expand_win32_path(path16, *tmpl) && + path16[0] != L'%' && + !_waccess(path16, F_OK)) { + win32_path_to_utf8(&buf, path16); + + if (buf.size) + git_str_join(out, GIT_PATH_LIST_SEPARATOR, out->ptr, buf.ptr); + } + } + + git_str_dispose(&buf); + + return (git_str_oom(out) ? -1 : 0); +} + +static int append_subdir(git_str *out, git_str *path, const char *subdir) +{ + static const char* architecture_roots[] = { + "", + "mingw64", + "mingw32", + NULL + }; + const char **root; + size_t orig_path_len = path->size; + + for (root = architecture_roots; *root; root++) { + if ((*root[0] && git_str_joinpath(path, path->ptr, *root) < 0) || + git_str_joinpath(path, path->ptr, subdir) < 0) + return -1; + + if (git_fs_path_exists(path->ptr) && + git_str_join(out, GIT_PATH_LIST_SEPARATOR, out->ptr, path->ptr) < 0) + return -1; + + git_str_truncate(path, orig_path_len); + } + + return 0; +} + +int git_win32__find_system_dirs(git_str *out, const char *subdir) +{ + git_win32_path pathdir, regdir; + git_str path8 = GIT_STR_INIT; + bool has_pathdir, has_regdir; + int error; + + has_pathdir = (find_sysdir_in_path(pathdir) == 0); + has_regdir = (find_sysdir_in_registry(regdir) == 0); + + if (!has_pathdir && !has_regdir) + return 0; + + /* + * Usually the git in the path is the same git in the registry, + * in this case there's no need to duplicate the paths. + */ + if (has_pathdir && has_regdir && wcscmp(pathdir, regdir) == 0) + has_regdir = false; + + if (has_pathdir) { + if ((error = win32_path_to_utf8(&path8, pathdir)) < 0 || + (error = append_subdir(out, &path8, subdir)) < 0) + goto done; + } + + if (has_regdir) { + if ((error = win32_path_to_utf8(&path8, regdir)) < 0 || + (error = append_subdir(out, &path8, subdir)) < 0) + goto done; + } + +done: + git_str_dispose(&path8); + return error; +} +#endif /* WIN32 */ + static int git_sysdir_guess_programdata_dirs(git_str *out) { #ifdef GIT_WIN32 - return git_win32__find_programdata_dirs(out); + static const wchar_t *programdata_tmpls[2] = { + L"%PROGRAMDATA%\\Git", + NULL, + }; + + return find_win32_dirs(out, programdata_tmpls); #else git_str_clear(out); return 0; @@ -75,10 +321,17 @@ out: } #endif -static int git_sysdir_guess_global_dirs(git_str *out) +static int git_sysdir_guess_home_dirs(git_str *out) { #ifdef GIT_WIN32 - return git_win32__find_global_dirs(out); + static const wchar_t *global_tmpls[4] = { + L"%HOME%\\", + L"%HOMEDRIVE%%HOMEPATH%\\", + L"%USERPROFILE%\\", + NULL, + }; + + return find_win32_dirs(out, global_tmpls); #else int error; uid_t uid, euid; @@ -114,10 +367,25 @@ static int git_sysdir_guess_global_dirs(git_str *out) #endif } +static int git_sysdir_guess_global_dirs(git_str *out) +{ + return git_sysdir_guess_home_dirs(out); +} + static int git_sysdir_guess_xdg_dirs(git_str *out) { #ifdef GIT_WIN32 - return git_win32__find_xdg_dirs(out); + static const wchar_t *global_tmpls[7] = { + L"%XDG_CONFIG_HOME%\\git", + L"%APPDATA%\\git", + L"%LOCALAPPDATA%\\git", + L"%HOME%\\.config\\git", + L"%HOMEDRIVE%%HOMEPATH%\\.config\\git", + L"%USERPROFILE%\\.config\\git", + NULL, + }; + + return find_win32_dirs(out, global_tmpls); #else git_str env = GIT_STR_INIT; int error; @@ -171,6 +439,7 @@ static struct git_sysdir__dir git_sysdir__dirs[] = { { GIT_STR_INIT, git_sysdir_guess_xdg_dirs }, { GIT_STR_INIT, git_sysdir_guess_programdata_dirs }, { GIT_STR_INIT, git_sysdir_guess_template_dirs }, + { GIT_STR_INIT, git_sysdir_guess_home_dirs } }; static void git_sysdir_global_shutdown(void) @@ -350,6 +619,12 @@ int git_sysdir_find_template_dir(git_str *path) path, NULL, GIT_SYSDIR_TEMPLATE, "template"); } +int git_sysdir_find_homedir(git_str *path) +{ + return git_sysdir_find_in_dirlist( + path, NULL, GIT_SYSDIR_HOME, "home directory"); +} + int git_sysdir_expand_global_file(git_str *path, const char *filename) { int error; @@ -361,3 +636,15 @@ int git_sysdir_expand_global_file(git_str *path, const char *filename) return error; } + +int git_sysdir_expand_homedir_file(git_str *path, const char *filename) +{ + int error; + + if ((error = git_sysdir_find_homedir(path)) == 0) { + if (filename) + error = git_str_joinpath(path, path->ptr, filename); + } + + return error; +} diff --git a/src/libgit2/sysdir.h b/src/libgit2/sysdir.h index 568f27940..03f59e1de 100644 --- a/src/libgit2/sysdir.h +++ b/src/libgit2/sysdir.h @@ -57,10 +57,22 @@ extern int git_sysdir_find_programdata_file(git_str *path, const char *filename) extern int git_sysdir_find_template_dir(git_str *path); /** - * Expand the name of a "global" file (i.e. one in a user's home - * directory). Unlike `find_global_file` (above), this makes no - * attempt to check for the existence of the file, and is useful if - * you want the full path regardless of existence. + * Find the home directory. On Windows, this will look at the `HOME`, + * `HOMEPATH`, and `USERPROFILE` environment variables (in that order) + * and return the first path that is set and exists. On other systems, + * this will simply return the contents of the `HOME` environment variable. + * + * @param path buffer to write the full path into + * @return 0 if found, GIT_ENOTFOUND if not found, or -1 on other OS error + */ +extern int git_sysdir_find_homedir(git_str *path); + +/** + * Expand the name of a "global" file -- by default inside the user's + * home directory, but can be overridden by the user configuration. + * Unlike `find_global_file` (above), this makes no attempt to check + * for the existence of the file, and is useful if you want the full + * path regardless of existence. * * @param path buffer to write the full path into * @param filename name of file in the home directory @@ -68,13 +80,25 @@ extern int git_sysdir_find_template_dir(git_str *path); */ extern int git_sysdir_expand_global_file(git_str *path, const char *filename); +/** + * Expand the name of a file in the user's home directory. This + * function makes no attempt to check for the existence of the file, + * and is useful if you want the full path regardless of existence. + * + * @param path buffer to write the full path into + * @param filename name of file in the home directory + * @return 0 on success or -1 on error + */ +extern int git_sysdir_expand_homedir_file(git_str *path, const char *filename); + typedef enum { - GIT_SYSDIR_SYSTEM = 0, - GIT_SYSDIR_GLOBAL = 1, - GIT_SYSDIR_XDG = 2, + GIT_SYSDIR_SYSTEM = 0, + GIT_SYSDIR_GLOBAL = 1, + GIT_SYSDIR_XDG = 2, GIT_SYSDIR_PROGRAMDATA = 3, - GIT_SYSDIR_TEMPLATE = 4, - GIT_SYSDIR__MAX = 5 + GIT_SYSDIR_TEMPLATE = 4, + GIT_SYSDIR_HOME = 5, + GIT_SYSDIR__MAX = 6 } git_sysdir_t; /** @@ -110,4 +134,12 @@ extern int git_sysdir_set(git_sysdir_t which, const char *paths); */ extern int git_sysdir_reset(void); +#ifdef GIT_WIN32 +/** Sets the registry system dir to a mock; for testing. */ +extern int git_win32__set_registry_system_dir(const wchar_t *mock_sysdir); + +/** Find the given system dir; for testing. */ +extern int git_win32__find_system_dirs(git_str *out, const char *subdir); +#endif + #endif diff --git a/src/libgit2/tag.c b/src/libgit2/tag.c index 792155a4b..562ec13ea 100644 --- a/src/libgit2/tag.c +++ b/src/libgit2/tag.c @@ -65,7 +65,11 @@ static int tag_error(const char *str) return GIT_EINVALID; } -static int tag_parse(git_tag *tag, const char *buffer, const char *buffer_end) +static int tag_parse( + git_tag *tag, + const char *buffer, + const char *buffer_end, + git_oid_t oid_type) { static const char *tag_types[] = { NULL, "commit\n", "tree\n", "blob\n", "tag\n" @@ -75,7 +79,8 @@ static int tag_parse(git_tag *tag, const char *buffer, const char *buffer_end) unsigned int i; int error; - if (git_oid__parse(&tag->target, &buffer, buffer_end, "object ") < 0) + if (git_object__parse_oid_header(&tag->target, + &buffer, buffer_end, "object ", oid_type) < 0) return tag_error("object field invalid"); if (buffer + 5 >= buffer_end) @@ -160,18 +165,25 @@ static int tag_parse(git_tag *tag, const char *buffer, const char *buffer_end) return 0; } -int git_tag__parse_raw(void *_tag, const char *data, size_t size) +int git_tag__parse_raw( + void *_tag, + const char *data, + size_t size, + git_oid_t oid_type) { - return tag_parse(_tag, data, data + size); + return tag_parse(_tag, data, data + size, oid_type); } -int git_tag__parse(void *_tag, git_odb_object *odb_obj) +int git_tag__parse( + void *_tag, + git_odb_object *odb_obj, + git_oid_t oid_type) { git_tag *tag = _tag; const char *buffer = git_odb_object_data(odb_obj); const char *buffer_end = buffer + git_odb_object_size(odb_obj); - return tag_parse(tag, buffer, buffer_end); + return tag_parse(tag, buffer, buffer_end, oid_type); } static int retrieve_tag_reference( @@ -220,7 +232,9 @@ static int write_tag_annotation( git_str tag = GIT_STR_INIT; git_odb *odb; - git_oid__writebuf(&tag, "object ", git_object_id(target)); + if (git_object__write_oid_header(&tag, "object ", git_object_id(target)) < 0) + goto on_error; + git_str_printf(&tag, "type %s\n", git_object_type2string(git_object_type(target))); git_str_printf(&tag, "tag %s\n", tag_name); git_signature__writebuf(&tag, "tagger ", tagger); @@ -296,8 +310,10 @@ static int git_tag_create__internal( } if (create_tag_annotation) { - if (write_tag_annotation(oid, repo, tag_name, target, tagger, message) < 0) + if (write_tag_annotation(oid, repo, tag_name, target, tagger, message) < 0) { + git_str_dispose(&ref_name); return -1; + } } else git_oid_cpy(oid, git_object_id(target)); @@ -369,7 +385,7 @@ int git_tag_create_from_buffer(git_oid *oid, git_repository *repo, const char *b return -1; /* validate the buffer */ - if (tag_parse(&tag, buffer, buffer + strlen(buffer)) < 0) + if (tag_parse(&tag, buffer, buffer + strlen(buffer), repo->oid_type) < 0) return -1; /* validate the target */ @@ -394,14 +410,17 @@ int git_tag_create_from_buffer(git_oid *oid, git_repository *repo, const char *b /** Ensure the tag name doesn't conflict with an already existing * reference unless overwriting has explicitly been requested **/ if (error == 0 && !allow_ref_overwrite) { + git_str_dispose(&ref_name); git_error_set(GIT_ERROR_TAG, "tag already exists"); return GIT_EEXISTS; } /* write the buffer */ if ((error = git_odb_open_wstream( - &stream, odb, strlen(buffer), GIT_OBJECT_TAG)) < 0) + &stream, odb, strlen(buffer), GIT_OBJECT_TAG)) < 0) { + git_str_dispose(&ref_name); return error; + } if (!(error = git_odb_stream_write(stream, buffer, strlen(buffer)))) error = git_odb_stream_finalize_write(oid, stream); diff --git a/src/libgit2/tag.h b/src/libgit2/tag.h index 76ae1508e..fdaaa463c 100644 --- a/src/libgit2/tag.h +++ b/src/libgit2/tag.h @@ -25,7 +25,7 @@ struct git_tag { }; void git_tag__free(void *tag); -int git_tag__parse(void *tag, git_odb_object *obj); -int git_tag__parse_raw(void *tag, const char *data, size_t size); +int git_tag__parse(void *tag, git_odb_object *obj, git_oid_t oid_type); +int git_tag__parse_raw(void *tag, const char *data, size_t size, git_oid_t oid_type); #endif diff --git a/src/libgit2/threadstate.h b/src/libgit2/threadstate.h index c10f26b59..f9e7ba7bf 100644 --- a/src/libgit2/threadstate.h +++ b/src/libgit2/threadstate.h @@ -13,7 +13,7 @@ typedef struct { git_error *last_error; git_error error_t; git_str error_buf; - char oid_fmt[GIT_OID_HEXSZ+1]; + char oid_fmt[GIT_OID_SHA1_HEXSIZE+1]; } git_threadstate; extern int git_threadstate_global_init(void); diff --git a/src/libgit2/transports/http.c b/src/libgit2/transports/http.c index 7db5582ca..cda76ae61 100644 --- a/src/libgit2/transports/http.c +++ b/src/libgit2/transports/http.c @@ -655,6 +655,7 @@ static int http_action( { http_subtransport *transport = GIT_CONTAINER_OF(t, http_subtransport, parent); git_remote_connect_options *connect_opts = &transport->owner->connect_opts; + git_http_client_options opts = {0}; http_stream *stream; const http_service *service; int error; @@ -683,14 +684,14 @@ static int http_action( stream = git__calloc(sizeof(http_stream), 1); GIT_ERROR_CHECK_ALLOC(stream); - if (!transport->http_client) { - git_http_client_options opts = {0}; - - opts.server_certificate_check_cb = connect_opts->callbacks.certificate_check; - opts.server_certificate_check_payload = connect_opts->callbacks.payload; - opts.proxy_certificate_check_cb = connect_opts->proxy_opts.certificate_check; - opts.proxy_certificate_check_payload = connect_opts->proxy_opts.payload; + opts.server_certificate_check_cb = connect_opts->callbacks.certificate_check; + opts.server_certificate_check_payload = connect_opts->callbacks.payload; + opts.proxy_certificate_check_cb = connect_opts->proxy_opts.certificate_check; + opts.proxy_certificate_check_payload = connect_opts->proxy_opts.payload; + if (transport->http_client) { + git_http_client_set_options(transport->http_client, &opts); + } else { if (git_http_client_new(&transport->http_client, &opts) < 0) return -1; } diff --git a/src/libgit2/transports/httpclient.c b/src/libgit2/transports/httpclient.c index f07923ef2..0ad6cd4dc 100644 --- a/src/libgit2/transports/httpclient.c +++ b/src/libgit2/transports/httpclient.c @@ -1541,6 +1541,15 @@ int git_http_client_new( return 0; } +/* Update the options of an existing httpclient instance. */ +void git_http_client_set_options( + git_http_client *client, + git_http_client_options *opts) +{ + if (opts) + memcpy(&client->opts, opts, sizeof(git_http_client_options)); +} + GIT_INLINE(void) http_server_close(git_http_server *server) { if (server->stream) { diff --git a/src/libgit2/transports/httpclient.h b/src/libgit2/transports/httpclient.h index 6d0ef9edb..22c4dd093 100644 --- a/src/libgit2/transports/httpclient.h +++ b/src/libgit2/transports/httpclient.h @@ -88,6 +88,16 @@ extern int git_http_client_new( git_http_client **out, git_http_client_options *opts); +/** + * Update the options of an existing httpclient instance. + * + * @param client the httpclient instance to modify + * @param opts new options or NULL to keep existing options + */ +extern void git_http_client_set_options( + git_http_client *client, + git_http_client_options *opts); + /* * Sends a request to the host specified by the request URL. If the * method is POST, either the content_length or the chunked flag must diff --git a/src/libgit2/transports/local.c b/src/libgit2/transports/local.c index 6c754a034..4d86f1713 100644 --- a/src/libgit2/transports/local.c +++ b/src/libgit2/transports/local.c @@ -266,6 +266,17 @@ static int local_capabilities(unsigned int *capabilities, git_transport *transpo return 0; } +#ifdef GIT_EXPERIMENTAL_SHA256 +static int local_oid_type(git_oid_t *out, git_transport *transport) +{ + transport_local *t = (transport_local *)transport; + + *out = t->repo->oid_type; + + return 0; +} +#endif + static int local_ls(const git_remote_head ***out, size_t *size, git_transport *transport) { transport_local *t = (transport_local *)transport; @@ -732,6 +743,9 @@ int git_transport_local(git_transport **out, git_remote *owner, void *param) t->parent.connect = local_connect; t->parent.set_connect_opts = local_set_connect_opts; t->parent.capabilities = local_capabilities; +#ifdef GIT_EXPERIMENTAL_SHA256 + t->parent.oid_type = local_oid_type; +#endif t->parent.negotiate_fetch = local_negotiate_fetch; t->parent.download_pack = local_download_pack; t->parent.push = local_push; diff --git a/src/libgit2/transports/smart.c b/src/libgit2/transports/smart.c index 7f57dba2a..c3a764bd3 100644 --- a/src/libgit2/transports/smart.c +++ b/src/libgit2/transports/smart.c @@ -54,6 +54,12 @@ GIT_INLINE(int) git_smart__reset_stream(transport_smart *t, bool close_subtransp return -1; } + git__free(t->caps.object_format); + t->caps.object_format = NULL; + + git__free(t->caps.agent); + t->caps.agent = NULL; + return 0; } @@ -242,6 +248,30 @@ static int git_smart__capabilities(unsigned int *capabilities, git_transport *tr return 0; } +#ifdef GIT_EXPERIMENTAL_SHA256 +static int git_smart__oid_type(git_oid_t *out, git_transport *transport) +{ + transport_smart *t = GIT_CONTAINER_OF(transport, transport_smart, parent); + + *out = 0; + + if (t->caps.object_format == NULL) { + *out = GIT_OID_DEFAULT; + } else { + *out = git_oid_type_fromstr(t->caps.object_format); + + if (!*out) { + git_error_set(GIT_ERROR_INVALID, + "unknown object format '%s'", + t->caps.object_format); + return -1; + } + } + + return 0; +} +#endif + static int git_smart__ls(const git_remote_head ***out, size_t *size, git_transport *transport) { transport_smart *t = GIT_CONTAINER_OF(transport, transport_smart, parent); @@ -386,6 +416,8 @@ static void git_smart__free(git_transport *transport) git_remote_connect_options_dispose(&t->connect_opts); + git__free(t->caps.object_format); + git__free(t->caps.agent); git__free(t); } @@ -452,6 +484,9 @@ int git_transport_smart(git_transport **out, git_remote *owner, void *param) t->parent.connect = git_smart__connect; t->parent.set_connect_opts = git_smart__set_connect_opts; t->parent.capabilities = git_smart__capabilities; +#ifdef GIT_EXPERIMENTAL_SHA256 + t->parent.oid_type = git_smart__oid_type; +#endif t->parent.close = git_smart__close; t->parent.free = git_smart__free; t->parent.negotiate_fetch = git_smart__negotiate_fetch; diff --git a/src/libgit2/transports/smart.h b/src/libgit2/transports/smart.h index 9323d6c44..d71160d8e 100644 --- a/src/libgit2/transports/smart.h +++ b/src/libgit2/transports/smart.h @@ -32,6 +32,8 @@ #define GIT_CAP_SYMREF "symref" #define GIT_CAP_WANT_TIP_SHA1 "allow-tip-sha1-in-want" #define GIT_CAP_WANT_REACHABLE_SHA1 "allow-reachable-sha1-in-want" +#define GIT_CAP_OBJECT_FORMAT "object-format=" +#define GIT_CAP_AGENT "agent=" extern bool git_smart__ofs_delta_enabled; @@ -133,6 +135,8 @@ typedef struct transport_smart_caps { thin_pack:1, want_tip_sha1:1, want_reachable_sha1:1; + char *object_format; + char *agent; } transport_smart_caps; typedef int (*packetsize_cb)(size_t received, void *payload); @@ -182,7 +186,12 @@ int git_smart__get_push_stream(transport_smart *t, git_smart_subtransport_stream int git_smart__update_heads(transport_smart *t, git_vector *symrefs); /* smart_pkt.c */ -int git_pkt_parse_line(git_pkt **head, const char **endptr, const char *line, size_t linelen); +typedef struct { + git_oid_t oid_type; + int seen_capabilities: 1; +} git_pkt_parse_data; + +int git_pkt_parse_line(git_pkt **head, const char **endptr, const char *line, size_t linelen, git_pkt_parse_data *data); int git_pkt_buffer_flush(git_str *buf); int git_pkt_send_flush(GIT_SOCKET s); int git_pkt_buffer_done(git_str *buf); diff --git a/src/libgit2/transports/smart_pkt.c b/src/libgit2/transports/smart_pkt.c index b42edd0d6..5fce42175 100644 --- a/src/libgit2/transports/smart_pkt.c +++ b/src/libgit2/transports/smart_pkt.c @@ -12,6 +12,7 @@ #include "netops.h" #include "posix.h" #include "str.h" +#include "oid.h" #include "git2/types.h" #include "git2/errors.h" @@ -20,11 +21,14 @@ #include -#define PKT_LEN_SIZE 4 -static const char pkt_done_str[] = "0009done\n"; -static const char pkt_flush_str[] = "0000"; -static const char pkt_have_prefix[] = "0032have "; -static const char pkt_want_prefix[] = "0032want "; +#define PKT_DONE_STR "0009done\n" +#define PKT_FLUSH_STR "0000" +#define PKT_HAVE_PREFIX "have " +#define PKT_WANT_PREFIX "want " + +#define PKT_LEN_SIZE 4 +#define PKT_MAX_SIZE 0xffff +#define PKT_MAX_WANTLEN (PKT_LEN_SIZE + CONST_STRLEN(PKT_WANT_PREFIX) + GIT_OID_MAX_HEXSIZE + 1) static int flush_pkt(git_pkt **out) { @@ -53,10 +57,11 @@ static int ack_pkt(git_pkt **out, const char *line, size_t len) line += 4; len -= 4; - if (len < GIT_OID_HEXSZ || git_oid_fromstr(&pkt->oid, line) < 0) + if (len < GIT_OID_SHA1_HEXSIZE || + git_oid__fromstr(&pkt->oid, line, GIT_OID_SHA1) < 0) goto out_err; - line += GIT_OID_HEXSZ; - len -= GIT_OID_HEXSZ; + line += GIT_OID_SHA1_HEXSIZE; + len -= GIT_OID_SHA1_HEXSIZE; if (len && line[0] == ' ') { line++; @@ -210,25 +215,87 @@ static int sideband_error_pkt(git_pkt **out, const char *line, size_t len) return 0; } +static int set_data( + git_pkt_parse_data *data, + const char *line, + size_t len) +{ + const char *caps, *format_str = NULL, *eos; + size_t format_len; + git_oid_t remote_oid_type; + + GIT_ASSERT_ARG(data); + + if ((caps = memchr(line, '\0', len)) != NULL) { + caps++; + + if (strncmp(caps, "object-format=", CONST_STRLEN("object-format=")) == 0) + format_str = caps + CONST_STRLEN("object-format="); + else if ((format_str = strstr(caps, " object-format=")) != NULL) + format_str += CONST_STRLEN(" object-format="); + } + + if (format_str) { + if ((eos = strchr(format_str, ' ')) == NULL) + eos = strchr(format_str, '\0'); + + GIT_ASSERT(eos); + + format_len = eos - format_str; + + if ((remote_oid_type = git_oid_type_fromstrn(format_str, format_len)) == 0) { + git_error_set(GIT_ERROR_INVALID, "unknown remote object format '%.*s'", (int)format_len, format_str); + return -1; + } + } else { + remote_oid_type = GIT_OID_SHA1; + } + + if (!data->oid_type) { + data->oid_type = remote_oid_type; + } else if (data->oid_type != remote_oid_type) { + git_error_set(GIT_ERROR_INVALID, + "the local object format '%s' does not match the remote object format '%s'", + git_oid_type_name(data->oid_type), + git_oid_type_name(remote_oid_type)); + return -1; + } + + return 0; +} + /* * Parse an other-ref line. */ -static int ref_pkt(git_pkt **out, const char *line, size_t len) +static int ref_pkt( + git_pkt **out, + const char *line, + size_t len, + git_pkt_parse_data *data) { git_pkt_ref *pkt; - size_t alloclen; + size_t alloclen, oid_hexsize; pkt = git__calloc(1, sizeof(git_pkt_ref)); GIT_ERROR_CHECK_ALLOC(pkt); pkt->type = GIT_PKT_REF; - if (len < GIT_OID_HEXSZ || git_oid_fromstr(&pkt->head.oid, line) < 0) + /* Determine OID type from capabilities */ + if (!data->seen_capabilities && set_data(data, line, len) < 0) + return -1; + + GIT_ASSERT(data->oid_type); + oid_hexsize = git_oid_hexsize(data->oid_type); + + if (len < oid_hexsize || + git_oid__fromstr(&pkt->head.oid, line, data->oid_type) < 0) goto out_err; - line += GIT_OID_HEXSZ; - len -= GIT_OID_HEXSZ; + line += oid_hexsize; + len -= oid_hexsize; if (git__prefixncmp(line, len, " ")) goto out_err; + line++; len--; @@ -245,8 +312,14 @@ static int ref_pkt(git_pkt **out, const char *line, size_t len) memcpy(pkt->head.name, line, len); pkt->head.name[len] = '\0'; - if (strlen(pkt->head.name) < len) - pkt->capabilities = strchr(pkt->head.name, '\0') + 1; + if (strlen(pkt->head.name) < len) { + if (!data->seen_capabilities) + pkt->capabilities = strchr(pkt->head.name, '\0') + 1; + else + goto out_err; + } + + data->seen_capabilities = 1; *out = (git_pkt *)pkt; return 0; @@ -415,7 +488,11 @@ static int parse_len(size_t *out, const char *line, size_t linelen) */ int git_pkt_parse_line( - git_pkt **pkt, const char **endptr, const char *line, size_t linelen) + git_pkt **pkt, + const char **endptr, + const char *line, + size_t linelen, + git_pkt_parse_data *data) { int error; size_t len; @@ -490,7 +567,7 @@ int git_pkt_parse_line( else if (!git__prefixncmp(line, len, "unpack")) error = unpack_pkt(pkt, line, len); else - error = ref_pkt(pkt, line, len); + error = ref_pkt(pkt, line, len, data); *endptr = line + len; @@ -524,14 +601,21 @@ void git_pkt_free(git_pkt *pkt) int git_pkt_buffer_flush(git_str *buf) { - return git_str_put(buf, pkt_flush_str, strlen(pkt_flush_str)); + return git_str_put(buf, PKT_FLUSH_STR, CONST_STRLEN(PKT_FLUSH_STR)); } -static int buffer_want_with_caps(const git_remote_head *head, transport_smart_caps *caps, git_str *buf) +static int buffer_want_with_caps( + const git_remote_head *head, + transport_smart_caps *caps, + git_oid_t oid_type, + git_str *buf) { git_str str = GIT_STR_INIT; - char oid[GIT_OID_HEXSZ +1] = {0}; - size_t len; + char oid[GIT_OID_MAX_HEXSIZE]; + size_t oid_hexsize, len; + + oid_hexsize = git_oid_hexsize(oid_type); + git_oid_fmt(oid, &head->oid); /* Prefer multi_ack_detailed */ if (caps->multi_ack_detailed) @@ -557,19 +641,20 @@ static int buffer_want_with_caps(const git_remote_head *head, transport_smart_ca if (git_str_oom(&str)) return -1; - len = strlen("XXXXwant ") + GIT_OID_HEXSZ + 1 /* NUL */ + - git_str_len(&str) + 1 /* LF */; - - if (len > 0xffff) { + if (str.size > (PKT_MAX_SIZE - (PKT_MAX_WANTLEN + 1))) { git_error_set(GIT_ERROR_NET, - "tried to produce packet with invalid length %" PRIuZ, len); + "tried to produce packet with invalid caps length %" PRIuZ, str.size); return -1; } + len = PKT_LEN_SIZE + CONST_STRLEN(PKT_WANT_PREFIX) + + oid_hexsize + 1 /* NUL */ + + git_str_len(&str) + 1 /* LF */; + git_str_grow_by(buf, len); - git_oid_fmt(oid, &head->oid); git_str_printf(buf, - "%04xwant %s %s\n", (unsigned int)len, oid, git_str_cstr(&str)); + "%04x%s%.*s %s\n", (unsigned int)len, PKT_WANT_PREFIX, + (int)oid_hexsize, oid, git_str_cstr(&str)); git_str_dispose(&str); GIT_ERROR_CHECK_ALLOC_STR(buf); @@ -588,8 +673,21 @@ int git_pkt_buffer_wants( transport_smart_caps *caps, git_str *buf) { - size_t i = 0; const git_remote_head *head; + char oid[GIT_OID_MAX_HEXSIZE]; + git_oid_t oid_type; + size_t oid_hexsize, want_len, i = 0; + +#ifdef GIT_EXPERIMENTAL_SHA256 + oid_type = count > 0 ? refs[0]->oid.type : GIT_OID_SHA1; +#else + oid_type = GIT_OID_SHA1; +#endif + + oid_hexsize = git_oid_hexsize(oid_type); + + want_len = PKT_LEN_SIZE + CONST_STRLEN(PKT_WANT_PREFIX) + + oid_hexsize + 1 /* LF */; if (caps->common) { for (; i < count; ++i) { @@ -598,23 +696,24 @@ int git_pkt_buffer_wants( break; } - if (buffer_want_with_caps(refs[i], caps, buf) < 0) + if (buffer_want_with_caps(refs[i], caps, oid_type, buf) < 0) return -1; i++; } for (; i < count; ++i) { - char oid[GIT_OID_HEXSZ]; - head = refs[i]; + if (head->local) continue; git_oid_fmt(oid, &head->oid); - git_str_put(buf, pkt_want_prefix, strlen(pkt_want_prefix)); - git_str_put(buf, oid, GIT_OID_HEXSZ); - git_str_putc(buf, '\n'); + + git_str_printf(buf, "%04x%s%.*s\n", + (unsigned int)want_len, PKT_WANT_PREFIX, + (int)oid_hexsize, oid); + if (git_str_oom(buf)) return -1; } @@ -624,14 +723,27 @@ int git_pkt_buffer_wants( int git_pkt_buffer_have(git_oid *oid, git_str *buf) { - char oidhex[GIT_OID_HEXSZ + 1]; + char oid_str[GIT_OID_MAX_HEXSIZE]; + git_oid_t oid_type; + size_t oid_hexsize, have_len; - memset(oidhex, 0x0, sizeof(oidhex)); - git_oid_fmt(oidhex, oid); - return git_str_printf(buf, "%s%s\n", pkt_have_prefix, oidhex); +#ifdef GIT_EXPERIMENTAL_SHA256 + oid_type = oid->type; +#else + oid_type = GIT_OID_SHA1; +#endif + + oid_hexsize = git_oid_hexsize(oid_type); + have_len = PKT_LEN_SIZE + CONST_STRLEN(PKT_HAVE_PREFIX) + + oid_hexsize + 1 /* LF */; + + git_oid_fmt(oid_str, oid); + return git_str_printf(buf, "%04x%s%.*s\n", + (unsigned int)have_len, PKT_HAVE_PREFIX, + (int)oid_hexsize, oid_str); } int git_pkt_buffer_done(git_str *buf) { - return git_str_puts(buf, pkt_done_str); + return git_str_put(buf, PKT_DONE_STR, CONST_STRLEN(PKT_DONE_STR)); } diff --git a/src/libgit2/transports/smart_protocol.c b/src/libgit2/transports/smart_protocol.c index 8cf027133..0d47acafe 100644 --- a/src/libgit2/transports/smart_protocol.c +++ b/src/libgit2/transports/smart_protocol.c @@ -32,6 +32,7 @@ int git_smart__store_refs(transport_smart *t, int flushes) int error, flush = 0, recvd; const char *line_end = NULL; git_pkt *pkt = NULL; + git_pkt_parse_data pkt_parse_data = { 0 }; size_t i; /* Clear existing refs in case git_remote_connect() is called again @@ -45,7 +46,7 @@ int git_smart__store_refs(transport_smart *t, int flushes) do { if (buf->offset > 0) - error = git_pkt_parse_line(&pkt, &line_end, buf->data, buf->offset); + error = git_pkt_parse_line(&pkt, &line_end, buf->data, buf->offset, &pkt_parse_data); else error = GIT_EBUFS; @@ -133,9 +134,12 @@ on_invalid: return -1; } -int git_smart__detect_caps(git_pkt_ref *pkt, transport_smart_caps *caps, git_vector *symrefs) +int git_smart__detect_caps( + git_pkt_ref *pkt, + transport_smart_caps *caps, + git_vector *symrefs) { - const char *ptr; + const char *ptr, *start; /* No refs or capabilities, odd but not a problem */ if (pkt == NULL || pkt->capabilities == NULL) @@ -207,13 +211,35 @@ int git_smart__detect_caps(git_pkt_ref *pkt, transport_smart_caps *caps, git_vec if (!git__prefixcmp(ptr, GIT_CAP_WANT_TIP_SHA1)) { caps->common = caps->want_tip_sha1 = 1; - ptr += strlen(GIT_CAP_DELETE_REFS); + ptr += strlen(GIT_CAP_WANT_TIP_SHA1); continue; } if (!git__prefixcmp(ptr, GIT_CAP_WANT_REACHABLE_SHA1)) { caps->common = caps->want_reachable_sha1 = 1; - ptr += strlen(GIT_CAP_DELETE_REFS); + ptr += strlen(GIT_CAP_WANT_REACHABLE_SHA1); + continue; + } + + if (!git__prefixcmp(ptr, GIT_CAP_OBJECT_FORMAT)) { + ptr += strlen(GIT_CAP_OBJECT_FORMAT); + + start = ptr; + ptr = strchr(ptr, ' '); + + if ((caps->object_format = git__strndup(start, (ptr - start))) == NULL) + return -1; + continue; + } + + if (!git__prefixcmp(ptr, GIT_CAP_AGENT)) { + ptr += strlen(GIT_CAP_AGENT); + + start = ptr; + ptr = strchr(ptr, ' '); + + if ((caps->agent = git__strndup(start, (ptr - start))) == NULL) + return -1; continue; } @@ -228,11 +254,12 @@ static int recv_pkt(git_pkt **out_pkt, git_pkt_type *out_type, gitno_buffer *buf { const char *ptr = buf->data, *line_end = ptr; git_pkt *pkt = NULL; + git_pkt_parse_data pkt_parse_data = { 0 }; int error = 0, ret; do { if (buf->offset > 0) - error = git_pkt_parse_line(&pkt, &line_end, ptr, buf->offset); + error = git_pkt_parse_line(&pkt, &line_end, ptr, buf->offset, &pkt_parse_data); else error = GIT_EBUFS; @@ -643,12 +670,12 @@ static int gen_pktline(git_str *buf, git_push *push) { push_spec *spec; size_t i, len; - char old_id[GIT_OID_HEXSZ+1], new_id[GIT_OID_HEXSZ+1]; + char old_id[GIT_OID_SHA1_HEXSIZE+1], new_id[GIT_OID_SHA1_HEXSIZE+1]; - old_id[GIT_OID_HEXSZ] = '\0'; new_id[GIT_OID_HEXSZ] = '\0'; + old_id[GIT_OID_SHA1_HEXSIZE] = '\0'; new_id[GIT_OID_SHA1_HEXSIZE] = '\0'; git_vector_foreach(&push->specs, i, spec) { - len = 2*GIT_OID_HEXSZ + 7 + strlen(spec->refspec.dst); + len = 2*GIT_OID_SHA1_HEXSIZE + 7 + strlen(spec->refspec.dst); if (i == 0) { ++len; /* '\0' */ @@ -723,6 +750,7 @@ static int add_push_report_pkt(git_push *push, git_pkt *pkt) static int add_push_report_sideband_pkt(git_push *push, git_pkt_data *data_pkt, git_str *data_pkt_buf) { git_pkt *pkt; + git_pkt_parse_data pkt_parse_data = { 0 }; const char *line, *line_end = NULL; size_t line_len; int error; @@ -741,7 +769,7 @@ static int add_push_report_sideband_pkt(git_push *push, git_pkt_data *data_pkt, } while (line_len > 0) { - error = git_pkt_parse_line(&pkt, &line_end, line, line_len); + error = git_pkt_parse_line(&pkt, &line_end, line, line_len, &pkt_parse_data); if (error == GIT_EBUFS) { /* Buffer the data when the inner packet is split @@ -777,6 +805,7 @@ done: static int parse_report(transport_smart *transport, git_push *push) { git_pkt *pkt = NULL; + git_pkt_parse_data pkt_parse_data = { 0 }; const char *line_end = NULL; gitno_buffer *buf = &transport->buffer; int error, recvd; @@ -785,7 +814,8 @@ static int parse_report(transport_smart *transport, git_push *push) for (;;) { if (buf->offset > 0) error = git_pkt_parse_line(&pkt, &line_end, - buf->data, buf->offset); + buf->data, buf->offset, + &pkt_parse_data); else error = GIT_EBUFS; @@ -1020,7 +1050,7 @@ int git_smart__push(git_transport *transport, git_push *push) #ifdef PUSH_DEBUG { git_remote_head *head; - char hex[GIT_OID_HEXSZ+1]; hex[GIT_OID_HEXSZ] = '\0'; + char hex[GIT_OID_SHA1_HEXSIZE+1]; hex[GIT_OID_SHA1_HEXSIZE] = '\0'; git_vector_foreach(&push->remote->refs, i, head) { git_oid_fmt(hex, &head->oid); diff --git a/src/libgit2/transports/ssh.c b/src/libgit2/transports/ssh.c index 85e779744..5500ea100 100644 --- a/src/libgit2/transports/ssh.c +++ b/src/libgit2/transports/ssh.c @@ -16,6 +16,7 @@ #include "netops.h" #include "smart.h" #include "streams/socket.h" +#include "sysdir.h" #include "git2/credential.h" #include "git2/sys/credential.h" @@ -245,8 +246,10 @@ static int ssh_agent_auth(LIBSSH2_SESSION *session, git_credential_ssh_key *c) { rc = libssh2_agent_connect(agent); - if (rc != LIBSSH2_ERROR_NONE) + if (rc != LIBSSH2_ERROR_NONE) { + rc = LIBSSH2_ERROR_AUTHENTICATION_FAILED; goto shutdown; + } rc = libssh2_agent_list_identities(agent); @@ -421,7 +424,8 @@ static int request_creds(git_credential **out, ssh_subtransport *t, const char * return 0; } -#define KNOWN_HOSTS_FILE ".ssh/known_hosts" +#define SSH_DIR ".ssh" +#define KNOWN_HOSTS_FILE "known_hosts" /* * Load the known_hosts file. @@ -430,16 +434,14 @@ static int request_creds(git_credential **out, ssh_subtransport *t, const char * */ static int load_known_hosts(LIBSSH2_KNOWNHOSTS **hosts, LIBSSH2_SESSION *session) { - git_str path = GIT_STR_INIT, home = GIT_STR_INIT; + git_str path = GIT_STR_INIT, sshdir = GIT_STR_INIT; LIBSSH2_KNOWNHOSTS *known_hosts = NULL; int error; GIT_ASSERT_ARG(hosts); - if ((error = git__getenv(&home, "HOME")) < 0) - return error; - - if ((error = git_str_joinpath(&path, git_str_cstr(&home), KNOWN_HOSTS_FILE)) < 0) + if ((error = git_sysdir_expand_homedir_file(&sshdir, SSH_DIR)) < 0 || + (error = git_str_joinpath(&path, git_str_cstr(&sshdir), KNOWN_HOSTS_FILE)) < 0) goto out; if ((known_hosts = libssh2_knownhost_init(session)) == NULL) { @@ -461,34 +463,32 @@ static int load_known_hosts(LIBSSH2_KNOWNHOSTS **hosts, LIBSSH2_SESSION *session out: *hosts = known_hosts; - git_str_clear(&home); - git_str_clear(&path); + git_str_dispose(&sshdir); + git_str_dispose(&path); return error; } -static const char *hostkey_type_to_string(int type) +static void add_hostkey_pref_if_avail( + LIBSSH2_KNOWNHOSTS *known_hosts, + const char *hostname, + int port, + git_str *prefs, + int type, + const char *type_name) { - switch (type) { - case LIBSSH2_KNOWNHOST_KEY_SSHRSA: - return "ssh-rsa"; - case LIBSSH2_KNOWNHOST_KEY_SSHDSS: - return "ssh-dss"; -#ifdef LIBSSH2_KNOWNHOST_KEY_ECDSA_256 - case LIBSSH2_KNOWNHOST_KEY_ECDSA_256: - return "ecdsa-sha2-nistp256"; - case LIBSSH2_KNOWNHOST_KEY_ECDSA_384: - return "ecdsa-sha2-nistp384"; - case LIBSSH2_KNOWNHOST_KEY_ECDSA_521: - return "ecdsa-sha2-nistp521"; -#endif -#ifdef LIBSSH2_KNOWNHOST_KEY_ED25519 - case LIBSSH2_KNOWNHOST_KEY_ED25519: - return "ssh-ed25519"; -#endif - } + struct libssh2_knownhost *host = NULL; + const char key = '\0'; + int mask = LIBSSH2_KNOWNHOST_TYPE_PLAIN | LIBSSH2_KNOWNHOST_KEYENC_RAW | type; + int error; - return NULL; + error = libssh2_knownhost_checkp(known_hosts, hostname, port, &key, 1, mask, &host); + if (error == LIBSSH2_KNOWNHOST_CHECK_MISMATCH) { + if (git_str_len(prefs) > 0) { + git_str_putc(prefs, ','); + } + git_str_puts(prefs, type_name); + } } /* @@ -496,27 +496,27 @@ static const char *hostkey_type_to_string(int type) * look it up with a nonsense key and using that mismatch to figure out what key * we do have stored for the host. * - * Returns the string to pass to libssh2_session_method_pref or NULL if we were - * unable to find anything or an error happened. + * Populates prefs with the string to pass to libssh2_session_method_pref. */ -static const char *find_hostkey_preference(LIBSSH2_KNOWNHOSTS *known_hosts, const char *hostname, int port) +static void find_hostkey_preference( + LIBSSH2_KNOWNHOSTS *known_hosts, + const char *hostname, + int port, + git_str *prefs) { - struct libssh2_knownhost *host = NULL; - /* Specify no key type so we don't filter on that */ - int type = LIBSSH2_KNOWNHOST_TYPE_PLAIN | LIBSSH2_KNOWNHOST_KEYENC_RAW; - const char key = '\0'; - int error; - /* - * In case of mismatch, we can find the type of key from known_hosts in - * the returned host's information as it means that an entry was found - * but our nonsense key obviously didn't match. + * The order here is important as it indicates the priority of what will + * be preferred. */ - error = libssh2_knownhost_checkp(known_hosts, hostname, port, &key, 1, type, &host); - if (error == LIBSSH2_KNOWNHOST_CHECK_MISMATCH) - return hostkey_type_to_string(host->typemask & LIBSSH2_KNOWNHOST_KEY_MASK); - - return NULL; +#ifdef LIBSSH2_KNOWNHOST_KEY_ED25519 + add_hostkey_pref_if_avail(known_hosts, hostname, port, prefs, LIBSSH2_KNOWNHOST_KEY_ED25519, "ssh-ed25519"); +#endif +#ifdef LIBSSH2_KNOWNHOST_KEY_ECDSA_256 + add_hostkey_pref_if_avail(known_hosts, hostname, port, prefs, LIBSSH2_KNOWNHOST_KEY_ECDSA_256, "ecdsa-sha2-nistp256"); + add_hostkey_pref_if_avail(known_hosts, hostname, port, prefs, LIBSSH2_KNOWNHOST_KEY_ECDSA_384, "ecdsa-sha2-nistp384"); + add_hostkey_pref_if_avail(known_hosts, hostname, port, prefs, LIBSSH2_KNOWNHOST_KEY_ECDSA_521, "ecdsa-sha2-nistp521"); +#endif + add_hostkey_pref_if_avail(known_hosts, hostname, port, prefs, LIBSSH2_KNOWNHOST_KEY_SSHRSA, "ssh-rsa"); } static int _git_ssh_session_create( @@ -526,11 +526,11 @@ static int _git_ssh_session_create( int port, git_stream *io) { - int rc = 0; + git_socket_stream *socket = GIT_CONTAINER_OF(io, git_socket_stream, parent); LIBSSH2_SESSION *s; LIBSSH2_KNOWNHOSTS *known_hosts; - git_socket_stream *socket = GIT_CONTAINER_OF(io, git_socket_stream, parent); - const char *keytype = NULL; + git_str prefs = GIT_STR_INIT; + int rc = 0; GIT_ASSERT_ARG(session); GIT_ASSERT_ARG(hosts); @@ -547,16 +547,17 @@ static int _git_ssh_session_create( return -1; } - if ((keytype = find_hostkey_preference(known_hosts, hostname, port)) != NULL) { + find_hostkey_preference(known_hosts, hostname, port, &prefs); + if (git_str_len(&prefs) > 0) { do { - rc = libssh2_session_method_pref(s, LIBSSH2_METHOD_HOSTKEY, keytype); + rc = libssh2_session_method_pref(s, LIBSSH2_METHOD_HOSTKEY, git_str_cstr(&prefs)); } while (LIBSSH2_ERROR_EAGAIN == rc || LIBSSH2_ERROR_TIMEOUT == rc); if (rc != LIBSSH2_ERROR_NONE) { ssh_error(s, "failed to set hostkey preference"); goto on_error; } } - + git_str_dispose(&prefs); do { rc = libssh2_session_handshake(s, socket->s); @@ -753,7 +754,7 @@ static int check_certificate( if (error == GIT_PASSTHROUGH) { error = git_error_state_restore(&previous_error); } else if (error < 0 && !git_error_last()) { - git_error_set(GIT_ERROR_NET, "user canceled hostkey check"); + git_error_set(GIT_ERROR_NET, "unknown remote host key"); } git_error_state_free(&previous_error); @@ -787,15 +788,8 @@ static int _git_ssh_setup_conn( s->session = NULL; s->channel = NULL; - if (git_net_str_is_url(url)) - error = git_net_url_parse(&s->url, url); - else - error = git_net_url_parse_scp(&s->url, url); - - if (error < 0) - goto done; - - if ((error = git_socket_stream_new(&s->io, s->url.host, s->url.port)) < 0 || + if ((error = git_net_url_parse_standard_or_scp(&s->url, url)) < 0 || + (error = git_socket_stream_new(&s->io, s->url.host, s->url.port)) < 0 || (error = git_stream_connect(s->io)) < 0) goto done; @@ -805,8 +799,11 @@ static int _git_ssh_setup_conn( * as part of the stream connection, but that's not something that's * exposed. */ - if (git__strntol32(&port, s->url.port, strlen(s->url.port), NULL, 10) < 0) - port = -1; + if (git__strntol32(&port, s->url.port, strlen(s->url.port), NULL, 10) < 0) { + git_error_set(GIT_ERROR_NET, "invalid port to ssh: %s", s->url.port); + error = -1; + goto done; + } if ((error = _git_ssh_session_create(&session, &known_hosts, s->url.host, port, s->io)) < 0) goto done; @@ -1009,7 +1006,7 @@ static int list_auth_methods(int *out, LIBSSH2_SESSION *session, const char *use /* either error, or the remote accepts NONE auth, which is bizarre, let's punt */ if (list == NULL && !libssh2_userauth_authenticated(session)) { - ssh_error(session, "Failed to retrieve list of SSH authentication methods"); + ssh_error(session, "remote rejected authentication"); return GIT_EAUTH; } diff --git a/src/libgit2/transports/winhttp.c b/src/libgit2/transports/winhttp.c index 8ec5b37c5..098227607 100644 --- a/src/libgit2/transports/winhttp.c +++ b/src/libgit2/transports/winhttp.c @@ -562,18 +562,23 @@ static int winhttp_stream_connect(winhttp_stream *s) for (i = 0; i < t->owner->connect_opts.custom_headers.count; i++) { if (t->owner->connect_opts.custom_headers.strings[i]) { + wchar_t *custom_header_wide = NULL; + git_str_clear(&buf); git_str_puts(&buf, t->owner->connect_opts.custom_headers.strings[i]); - if (git__utf8_to_16(ct, MAX_CONTENT_TYPE_LEN, git_str_cstr(&buf)) < 0) { - git_error_set(GIT_ERROR_OS, "failed to convert custom header to wide characters"); + + /* Convert header to wide characters */ + if ((error = git__utf8_to_16_alloc(&custom_header_wide, git_str_cstr(&buf))) < 0) + goto on_error; + + if (!WinHttpAddRequestHeaders(s->request, custom_header_wide, (ULONG)-1L, + WINHTTP_ADDREQ_FLAG_ADD | WINHTTP_ADDREQ_FLAG_REPLACE)) { + git_error_set(GIT_ERROR_OS, "failed to add a header to the request"); + git__free(custom_header_wide); goto on_error; } - if (!WinHttpAddRequestHeaders(s->request, ct, (ULONG)-1L, - WINHTTP_ADDREQ_FLAG_ADD | WINHTTP_ADDREQ_FLAG_REPLACE)) { - git_error_set(GIT_ERROR_OS, "failed to add a header to the request"); - goto on_error; - } + git__free(custom_header_wide); } } diff --git a/src/libgit2/tree-cache.c b/src/libgit2/tree-cache.c index cd69e7bf8..19fad85ae 100644 --- a/src/libgit2/tree-cache.c +++ b/src/libgit2/tree-cache.c @@ -111,11 +111,11 @@ static int read_tree_internal(git_tree_cache **out, /* The SHA1 is only there if it's not invalidated */ if (tree->entry_count >= 0) { /* 160-bit SHA-1 for this tree and it's children */ - if (buffer + GIT_OID_RAWSZ > buffer_end) + if (buffer + GIT_OID_SHA1_SIZE > buffer_end) goto corrupted; - git_oid_fromraw(&tree->oid, (const unsigned char *)buffer); - buffer += GIT_OID_RAWSZ; + git_oid__fromraw(&tree->oid, (const unsigned char *)buffer, GIT_OID_SHA1); + buffer += GIT_OID_SHA1_SIZE; } /* Parse children: */ @@ -263,7 +263,7 @@ static void write_tree(git_str *out, git_tree_cache *tree) git_str_printf(out, "%s%c%"PRIdZ" %"PRIuZ"\n", tree->name, 0, tree->entry_count, tree->children_count); if (tree->entry_count != -1) - git_str_put(out, (char *)&tree->oid.id, GIT_OID_RAWSZ); + git_str_put(out, (char *)&tree->oid.id, GIT_OID_SHA1_SIZE); for (i = 0; i < tree->children_count; i++) write_tree(out, tree->children[i]); diff --git a/src/libgit2/tree.c b/src/libgit2/tree.c index a5371fd87..9293d9422 100644 --- a/src/libgit2/tree.c +++ b/src/libgit2/tree.c @@ -85,11 +85,17 @@ static git_tree_entry *alloc_entry(const char *filename, size_t filename_len, co char *filename_ptr; size_t tree_len; +#ifdef GIT_EXPERIMENTAL_SHA256 + size_t oid_size = git_oid_size(id->type); +#else + size_t oid_size = GIT_OID_SHA1_SIZE; +#endif + TREE_ENTRY_CHECK_NAMELEN(filename_len); if (GIT_ADD_SIZET_OVERFLOW(&tree_len, sizeof(git_tree_entry), filename_len) || GIT_ADD_SIZET_OVERFLOW(&tree_len, tree_len, 1) || - GIT_ADD_SIZET_OVERFLOW(&tree_len, tree_len, GIT_OID_RAWSZ)) + GIT_ADD_SIZET_OVERFLOW(&tree_len, tree_len, oid_size)) return NULL; entry = git__calloc(1, tree_len); @@ -383,11 +389,12 @@ static int parse_mode(uint16_t *mode_out, const char *buffer, size_t buffer_len, return 0; } -int git_tree__parse_raw(void *_tree, const char *data, size_t size) +int git_tree__parse_raw(void *_tree, const char *data, size_t size, git_oid_t oid_type) { git_tree *tree = _tree; const char *buffer; const char *buffer_end; + const long oid_size = (long)git_oid_size(oid_type); buffer = data; buffer_end = buffer + size; @@ -414,35 +421,33 @@ int git_tree__parse_raw(void *_tree, const char *data, size_t size) if ((filename_len = nul - buffer) == 0 || filename_len > UINT16_MAX) return tree_parse_error("failed to parse tree: can't parse filename", NULL); - if ((buffer_end - (nul + 1)) < GIT_OID_RAWSZ) + if ((buffer_end - (nul + 1)) < (long)oid_size) return tree_parse_error("failed to parse tree: can't parse OID", NULL); /* Allocate the entry */ - { - entry = git_array_alloc(tree->entries); - GIT_ERROR_CHECK_ALLOC(entry); - - entry->attr = attr; - entry->filename_len = (uint16_t)filename_len; - entry->filename = buffer; - git_oid_fromraw(&entry->oid, ((unsigned char *) buffer + filename_len + 1)); - } + entry = git_array_alloc(tree->entries); + GIT_ERROR_CHECK_ALLOC(entry); + entry->attr = attr; + entry->filename_len = (uint16_t)filename_len; + entry->filename = buffer; buffer += filename_len + 1; - buffer += GIT_OID_RAWSZ; + + git_oid__fromraw(&entry->oid, (unsigned char *)buffer, oid_type); + buffer += oid_size; } return 0; } -int git_tree__parse(void *_tree, git_odb_object *odb_obj) +int git_tree__parse(void *_tree, git_odb_object *odb_obj, git_oid_t oid_type) { git_tree *tree = _tree; const char *data = git_odb_object_data(odb_obj); size_t size = git_odb_object_size(odb_obj); int error; - if ((error = git_tree__parse_raw(tree, data, size)) < 0 || + if ((error = git_tree__parse_raw(tree, data, size, oid_type)) < 0 || (error = git_odb_object_dup(&tree->odb_obj, odb_obj)) < 0) return error; @@ -506,6 +511,7 @@ static int git_treebuilder__write_with_buffer( git_odb *odb; git_tree_entry *entry; git_vector entries = GIT_VECTOR_INIT; + size_t oid_size = git_oid_size(bld->repo->oid_type); git_str_clear(buf); @@ -529,7 +535,7 @@ static int git_treebuilder__write_with_buffer( git_str_printf(buf, "%o ", entry->attr); git_str_put(buf, entry->filename, entry->filename_len + 1); - git_str_put(buf, (char *)entry->oid.id, GIT_OID_RAWSZ); + git_str_put(buf, (char *)entry->oid.id, oid_size); if (git_str_oom(buf)) { error = -1; diff --git a/src/libgit2/tree.h b/src/libgit2/tree.h index 0dd963ff2..5088450ab 100644 --- a/src/libgit2/tree.h +++ b/src/libgit2/tree.h @@ -41,8 +41,8 @@ GIT_INLINE(bool) git_tree_entry__is_tree(const struct git_tree_entry *e) } void git_tree__free(void *tree); -int git_tree__parse(void *tree, git_odb_object *obj); -int git_tree__parse_raw(void *_tree, const char *data, size_t size); +int git_tree__parse(void *tree, git_odb_object *obj, git_oid_t oid_type); +int git_tree__parse_raw(void *_tree, const char *data, size_t size, git_oid_t oid_type); /** * Write a tree to the given repository diff --git a/src/libgit2/worktree.c b/src/libgit2/worktree.c index 2ac2274f1..82e1d2d7e 100644 --- a/src/libgit2/worktree.c +++ b/src/libgit2/worktree.c @@ -187,6 +187,11 @@ int git_worktree_lookup(git_worktree **out, git_repository *repo, const char *na if ((error = git_str_join3(&path, '/', repo->commondir, "worktrees", name)) < 0) goto out; + if (!git_fs_path_isdir(path.ptr)) { + error = GIT_ENOTFOUND; + goto out; + } + if ((error = (open_worktree_dir(out, git_repository_workdir(repo), path.ptr, name))) < 0) goto out; diff --git a/src/util/CMakeLists.txt b/src/util/CMakeLists.txt index b2833954d..ee35eb961 100644 --- a/src/util/CMakeLists.txt +++ b/src/util/CMakeLists.txt @@ -4,8 +4,11 @@ add_library(util OBJECT) set_target_properties(util PROPERTIES C_STANDARD 90) set_target_properties(util PROPERTIES C_EXTENSIONS OFF) +configure_file(git2_features.h.in git2_features.h) + set(UTIL_INCLUDES - "${PROJECT_BINARY_DIR}/src" + "${PROJECT_BINARY_DIR}/src/util" + "${PROJECT_BINARY_DIR}/include" "${PROJECT_SOURCE_DIR}/src/util" "${PROJECT_SOURCE_DIR}/include") @@ -34,6 +37,7 @@ if(USE_SHA1 STREQUAL "CollisionDetection") target_compile_definitions(util PRIVATE SHA1DC_CUSTOM_INCLUDE_SHA1_C=\"git2_util.h\") target_compile_definitions(util PRIVATE SHA1DC_CUSTOM_INCLUDE_UBC_CHECK_C=\"git2_util.h\") elseif(USE_SHA1 STREQUAL "OpenSSL" OR USE_SHA1 STREQUAL "OpenSSL-Dynamic") + add_definitions(-DOPENSSL_API_COMPAT=0x10100000L) file(GLOB UTIL_SRC_SHA1 hash/openssl.*) elseif(USE_SHA1 STREQUAL "CommonCrypto") file(GLOB UTIL_SRC_SHA1 hash/common_crypto.*) @@ -50,6 +54,7 @@ list(SORT UTIL_SRC_SHA1) if(USE_SHA256 STREQUAL "Builtin") file(GLOB UTIL_SRC_SHA256 hash/builtin.* hash/rfc6234/*) elseif(USE_SHA256 STREQUAL "OpenSSL" OR USE_SHA256 STREQUAL "OpenSSL-Dynamic") + add_definitions(-DOPENSSL_API_COMPAT=0x10100000L) file(GLOB UTIL_SRC_SHA256 hash/openssl.*) elseif(USE_SHA256 STREQUAL "CommonCrypto") file(GLOB UTIL_SRC_SHA256 hash/common_crypto.*) diff --git a/src/util/fs_path.c b/src/util/fs_path.c index 6c87bfd01..b52867e77 100644 --- a/src/util/fs_path.c +++ b/src/util/fs_path.c @@ -1855,7 +1855,7 @@ static int file_owner_sid(PSID *out, const char *path) PSECURITY_DESCRIPTOR descriptor = NULL; PSID owner_sid; DWORD ret; - int error = -1; + int error = GIT_EINVALID; if (git_win32_path_from_utf8(path_w32, path) < 0) return -1; diff --git a/src/util/futils.c b/src/util/futils.c index cb872de09..084f1cd28 100644 --- a/src/util/futils.c +++ b/src/util/futils.c @@ -13,9 +13,6 @@ #include "rand.h" #include -#if GIT_WIN32 -#include "win32/findfile.h" -#endif #define GIT_FILEMODE_DEFAULT 0100666 diff --git a/src/features.h.in b/src/util/git2_features.h.in similarity index 100% rename from src/features.h.in rename to src/util/git2_features.h.in diff --git a/src/util/git2_util.h b/src/util/git2_util.h index ad3f1c71f..c62dc2419 100644 --- a/src/util/git2_util.h +++ b/src/util/git2_util.h @@ -7,8 +7,8 @@ #ifndef INCLUDE_git2_util_h__ #define INCLUDE_git2_util_h__ -#ifndef LIBGIT2_NO_FEATURES_H -# include "git2/sys/features.h" +#if !defined(LIBGIT2_NO_FEATURES_H) +# include "git2_features.h" #endif #include "git2/common.h" diff --git a/src/util/hash.h b/src/util/hash.h index 387c5a66f..21fcaf045 100644 --- a/src/util/hash.h +++ b/src/util/hash.h @@ -23,6 +23,8 @@ typedef enum { GIT_HASH_ALGORITHM_SHA256 } git_hash_algorithm_t; +#define GIT_HASH_MAX_SIZE GIT_HASH_SHA256_SIZE + typedef struct git_hash_ctx { union { git_hash_sha1_ctx sha1; @@ -45,4 +47,15 @@ int git_hash_vec(unsigned char *out, git_str_vec *vec, size_t n, git_hash_algori int git_hash_fmt(char *out, unsigned char *hash, size_t hash_len); +GIT_INLINE(size_t) git_hash_size(git_hash_algorithm_t algorithm) { + switch (algorithm) { + case GIT_HASH_ALGORITHM_SHA1: + return GIT_HASH_SHA1_SIZE; + case GIT_HASH_ALGORITHM_SHA256: + return GIT_HASH_SHA256_SIZE; + default: + return 0; + } +} + #endif diff --git a/src/util/hash/openssl.c b/src/util/hash/openssl.c index 649358ca2..eaf91e74c 100644 --- a/src/util/hash/openssl.c +++ b/src/util/hash/openssl.c @@ -10,8 +10,8 @@ #ifdef GIT_OPENSSL_DYNAMIC # include -int handle_count; -void *openssl_handle; +static int handle_count; +static void *openssl_handle; static int git_hash_openssl_global_shutdown(void) { @@ -30,7 +30,8 @@ static int git_hash_openssl_global_init(void) (openssl_handle = dlopen("libssl.1.1.dylib", RTLD_NOW)) == NULL && (openssl_handle = dlopen("libssl.so.1.0.0", RTLD_NOW)) == NULL && (openssl_handle = dlopen("libssl.1.0.0.dylib", RTLD_NOW)) == NULL && - (openssl_handle = dlopen("libssl.so.10", RTLD_NOW)) == NULL) { + (openssl_handle = dlopen("libssl.so.10", RTLD_NOW)) == NULL && + (openssl_handle = dlopen("libssl.so.3", RTLD_NOW)) == NULL) { git_error_set(GIT_ERROR_SSL, "could not load ssl libraries"); return -1; } diff --git a/src/util/hash/rfc6234/sha.h b/src/util/hash/rfc6234/sha.h index e0c400ca1..0fbcc50d3 100644 --- a/src/util/hash/rfc6234/sha.h +++ b/src/util/hash/rfc6234/sha.h @@ -191,49 +191,6 @@ typedef struct SHA256Context SHA224Context; */ typedef struct SHA512Context SHA384Context; -/* - * This structure holds context information for all SHA - * hashing operations. - */ -typedef struct USHAContext { - int whichSha; /* which SHA is being used */ - union { - SHA1Context sha1Context; - SHA224Context sha224Context; SHA256Context sha256Context; - SHA384Context sha384Context; SHA512Context sha512Context; - } ctx; -} USHAContext; - -/* - * This structure will hold context information for the HMAC - * keyed-hashing operation. - */ -typedef struct HMACContext { - int whichSha; /* which SHA is being used */ - int hashSize; /* hash size of SHA being used */ - int blockSize; /* block size of SHA being used */ - USHAContext shaContext; /* SHA context */ - unsigned char k_opad[USHA_Max_Message_Block_Size]; - /* outer padding - key XORd with opad */ - int Computed; /* Is the MAC computed? */ - int Corrupted; /* Cumulative corruption code */ - -} HMACContext; - -/* - * This structure will hold context information for the HKDF - * extract-and-expand Key Derivation Functions. - */ -typedef struct HKDFContext { - int whichSha; /* which SHA is being used */ - HMACContext hmacContext; - int hashSize; /* hash size of SHA being used */ - unsigned char prk[USHAMaxHashSize]; - /* pseudo-random key - output of hkdfInput */ - int Computed; /* Is the key material computed? */ - int Corrupted; /* Cumulative corruption code */ -} HKDFContext; - /* * Function Prototypes */ @@ -283,73 +240,4 @@ extern int SHA512FinalBits(SHA512Context *, uint8_t bits, extern int SHA512Result(SHA512Context *, uint8_t Message_Digest[SHA512HashSize]); -/* Unified SHA functions, chosen by whichSha */ -extern int USHAReset(USHAContext *context, SHAversion whichSha); -extern int USHAInput(USHAContext *context, - const uint8_t *bytes, unsigned int bytecount); -extern int USHAFinalBits(USHAContext *context, - uint8_t bits, unsigned int bit_count); -extern int USHAResult(USHAContext *context, - uint8_t Message_Digest[USHAMaxHashSize]); -extern int USHABlockSize(enum SHAversion whichSha); -extern int USHAHashSize(enum SHAversion whichSha); -extern int USHAHashSizeBits(enum SHAversion whichSha); -extern const char *USHAHashName(enum SHAversion whichSha); - -/* - * HMAC Keyed-Hashing for Message Authentication, RFC 2104, - * for all SHAs. - * This interface allows a fixed-length text input to be used. - */ -extern int hmac(SHAversion whichSha, /* which SHA algorithm to use */ - const unsigned char *text, /* pointer to data stream */ - int text_len, /* length of data stream */ - const unsigned char *key, /* pointer to authentication key */ - int key_len, /* length of authentication key */ - uint8_t digest[USHAMaxHashSize]); /* caller digest to fill in */ - -/* - * HMAC Keyed-Hashing for Message Authentication, RFC 2104, - * for all SHAs. - * This interface allows any length of text input to be used. - */ -extern int hmacReset(HMACContext *context, enum SHAversion whichSha, - const unsigned char *key, int key_len); -extern int hmacInput(HMACContext *context, const unsigned char *text, - int text_len); -extern int hmacFinalBits(HMACContext *context, uint8_t bits, - unsigned int bit_count); -extern int hmacResult(HMACContext *context, - uint8_t digest[USHAMaxHashSize]); - -/* - * HKDF HMAC-based Extract-and-Expand Key Derivation Function, - * RFC 5869, for all SHAs. - */ -extern int hkdf(SHAversion whichSha, const unsigned char *salt, - int salt_len, const unsigned char *ikm, int ikm_len, - const unsigned char *info, int info_len, - uint8_t okm[ ], int okm_len); -extern int hkdfExtract(SHAversion whichSha, const unsigned char *salt, - int salt_len, const unsigned char *ikm, - int ikm_len, uint8_t prk[USHAMaxHashSize]); -extern int hkdfExpand(SHAversion whichSha, const uint8_t prk[ ], - int prk_len, const unsigned char *info, - int info_len, uint8_t okm[ ], int okm_len); - -/* - * HKDF HMAC-based Extract-and-Expand Key Derivation Function, - * RFC 5869, for all SHAs. - * This interface allows any length of text input to be used. - */ -extern int hkdfReset(HKDFContext *context, enum SHAversion whichSha, - const unsigned char *salt, int salt_len); -extern int hkdfInput(HKDFContext *context, const unsigned char *ikm, - int ikm_len); -extern int hkdfFinalBits(HKDFContext *context, uint8_t ikm_bits, - unsigned int ikm_bit_count); -extern int hkdfResult(HKDFContext *context, - uint8_t prk[USHAMaxHashSize], - const unsigned char *info, int info_len, - uint8_t okm[USHAMaxHashSize], int okm_len); #endif /* _SHA_H_ */ diff --git a/src/util/net.c b/src/util/net.c index b2236daf8..ac7befe07 100644 --- a/src/util/net.c +++ b/src/util/net.c @@ -93,121 +93,367 @@ int git_net_url_dup(git_net_url *out, git_net_url *in) return 0; } +static int url_invalid(const char *message) +{ + git_error_set(GIT_ERROR_NET, "invalid url: %s", message); + return GIT_EINVALIDSPEC; +} + +static int url_parse_authority( + const char **user_start, size_t *user_len, + const char **password_start, size_t *password_len, + const char **host_start, size_t *host_len, + const char **port_start, size_t *port_len, + const char *authority_start, size_t len, + const char *scheme_start, size_t scheme_len) +{ + const char *c, *hostport_end, *host_end = NULL, + *userpass_end, *user_end = NULL; + + enum { + HOSTPORT, HOST, IPV6, HOST_END, USERPASS, USER + } state = HOSTPORT; + + if (len == 0) + return 0; + + /* + * walk the authority backwards so that we can parse google code's + * ssh urls that are not rfc compliant and allow @ in the username + */ + for (hostport_end = authority_start + len, c = hostport_end - 1; + c >= authority_start && !user_end; + c--) { + switch (state) { + case HOSTPORT: + if (*c == ':') { + *port_start = c + 1; + *port_len = hostport_end - *port_start; + host_end = c; + state = HOST; + break; + } + + /* + * if we've only seen digits then we don't know + * if we're parsing just a host or a host and port. + * if we see a non-digit, then we're in a host, + * otherwise, fall through to possibly match the + * "@" (user/host separator). + */ + + if (*c < '0' || *c > '9') { + host_end = hostport_end; + state = HOST; + } + + /* fall through */ + + case HOST: + if (*c == ']' && host_end == c + 1) { + host_end = c; + state = IPV6; + } + + else if (*c == '@') { + *host_start = c + 1; + *host_len = host_end ? host_end - *host_start : + hostport_end - *host_start; + userpass_end = c; + state = USERPASS; + } + + else if (*c == '[' || *c == ']' || *c == ':') { + return url_invalid("malformed hostname"); + } + + break; + + case IPV6: + if (*c == '[') { + *host_start = c + 1; + *host_len = host_end - *host_start; + state = HOST_END; + } + + else if ((*c < '0' || *c > '9') && + (*c < 'a' || *c > 'f') && + (*c < 'A' || *c > 'F') && + (*c != ':')) { + return url_invalid("malformed hostname"); + } + + break; + + case HOST_END: + if (*c == '@') { + userpass_end = c; + state = USERPASS; + break; + } + + return url_invalid("malformed hostname"); + + case USERPASS: + if (*c == '@' && + strncasecmp(scheme_start, "ssh", scheme_len)) + return url_invalid("malformed hostname"); + + if (*c == ':') { + *password_start = c + 1; + *password_len = userpass_end - *password_start; + user_end = c; + state = USER; + break; + } + + break; + + default: + GIT_ASSERT(!"unhandled state"); + } + } + + switch (state) { + case HOSTPORT: + *host_start = authority_start; + *host_len = (hostport_end - *host_start); + break; + case HOST: + *host_start = authority_start; + *host_len = (host_end - *host_start); + break; + case IPV6: + return url_invalid("malformed hostname"); + case HOST_END: + break; + case USERPASS: + *user_start = authority_start; + *user_len = (userpass_end - *user_start); + break; + case USER: + *user_start = authority_start; + *user_len = (user_end - *user_start); + break; + default: + GIT_ASSERT(!"unhandled state"); + } + + return 0; +} + int git_net_url_parse(git_net_url *url, const char *given) { - struct http_parser_url u = {0}; - bool has_scheme, has_host, has_port, has_path, has_query, has_userinfo; - git_str scheme = GIT_STR_INIT, - host = GIT_STR_INIT, - port = GIT_STR_INIT, - path = GIT_STR_INIT, - username = GIT_STR_INIT, - password = GIT_STR_INIT, - query = GIT_STR_INIT; - int error = GIT_EINVALIDSPEC; + const char *c, *scheme_start, *authority_start, *user_start, + *password_start, *host_start, *port_start, *path_start, + *query_start, *fragment_start, *default_port; + git_str scheme = GIT_STR_INIT, user = GIT_STR_INIT, + password = GIT_STR_INIT, host = GIT_STR_INIT, + port = GIT_STR_INIT, path = GIT_STR_INIT, + query = GIT_STR_INIT, fragment = GIT_STR_INIT; + size_t scheme_len = 0, user_len = 0, password_len = 0, host_len = 0, + port_len = 0, path_len = 0, query_len = 0, fragment_len = 0; + bool hierarchical = false; + int error = 0; - if (http_parser_parse_url(given, strlen(given), false, &u)) { - git_error_set(GIT_ERROR_NET, "malformed URL '%s'", given); - goto done; + enum { + SCHEME, + AUTHORITY_START, AUTHORITY, + PATH_START, PATH, + QUERY, + FRAGMENT + } state = SCHEME; + + memset(url, 0, sizeof(git_net_url)); + + for (c = scheme_start = given; *c; c++) { + switch (state) { + case SCHEME: + if (*c == ':') { + scheme_len = (c - scheme_start); + + if (*(c+1) == '/' && *(c+2) == '/') { + c += 2; + hierarchical = true; + state = AUTHORITY_START; + } else { + state = PATH_START; + } + } else if ((*c < 'A' || *c > 'Z') && + (*c < 'a' || *c > 'z') && + (*c < '0' || *c > '9') && + (*c != '+' && *c != '-' && *c != '.')) { + /* + * an illegal scheme character means that we + * were just given a relative path + */ + path_start = given; + state = PATH; + break; + } + break; + + case AUTHORITY_START: + authority_start = c; + state = AUTHORITY; + + /* fall through */ + + case AUTHORITY: + if (*c != '/') + break; + + /* + * authority is sufficiently complex that we parse + * it separately + */ + if ((error = url_parse_authority( + &user_start, &user_len, + &password_start,&password_len, + &host_start, &host_len, + &port_start, &port_len, + authority_start, (c - authority_start), + scheme_start, scheme_len)) < 0) + goto done; + + /* fall through */ + + case PATH_START: + path_start = c; + state = PATH; + /* fall through */ + + case PATH: + switch (*c) { + case '?': + path_len = (c - path_start); + query_start = c + 1; + state = QUERY; + break; + case '#': + path_len = (c - path_start); + fragment_start = c + 1; + state = FRAGMENT; + break; + } + break; + + case QUERY: + if (*c == '#') { + query_len = (c - query_start); + fragment_start = c + 1; + state = FRAGMENT; + } + break; + + case FRAGMENT: + break; + + default: + GIT_ASSERT(!"unhandled state"); + } } - has_scheme = !!(u.field_set & (1 << UF_SCHEMA)); - has_host = !!(u.field_set & (1 << UF_HOST)); - has_port = !!(u.field_set & (1 << UF_PORT)); - has_path = !!(u.field_set & (1 << UF_PATH)); - has_query = !!(u.field_set & (1 << UF_QUERY)); - has_userinfo = !!(u.field_set & (1 << UF_USERINFO)); - - if (has_scheme) { - const char *url_scheme = given + u.field_data[UF_SCHEMA].off; - size_t url_scheme_len = u.field_data[UF_SCHEMA].len; - git_str_put(&scheme, url_scheme, url_scheme_len); - git__strntolower(scheme.ptr, scheme.size); - } else { - git_error_set(GIT_ERROR_NET, "malformed URL '%s'", given); - goto done; - } - - if (has_host) { - const char *url_host = given + u.field_data[UF_HOST].off; - size_t url_host_len = u.field_data[UF_HOST].len; - git_str_decode_percent(&host, url_host, url_host_len); - } - - if (has_port) { - const char *url_port = given + u.field_data[UF_PORT].off; - size_t url_port_len = u.field_data[UF_PORT].len; - git_str_put(&port, url_port, url_port_len); - } else { - const char *default_port = default_port_for_scheme(scheme.ptr); - - if (default_port == NULL) { - git_error_set(GIT_ERROR_NET, "unknown scheme for URL '%s'", given); + switch (state) { + case SCHEME: + /* + * if we never saw a ':' then we were given a relative + * path, not a bare scheme + */ + path_start = given; + path_len = (c - scheme_start); + break; + case AUTHORITY_START: + break; + case AUTHORITY: + if ((error = url_parse_authority( + &user_start, &user_len, + &password_start,&password_len, + &host_start, &host_len, + &port_start, &port_len, + authority_start, (c - authority_start), + scheme_start, scheme_len)) < 0) goto done; - } - - git_str_puts(&port, default_port); + break; + case PATH_START: + break; + case PATH: + path_len = (c - path_start); + break; + case QUERY: + query_len = (c - query_start); + break; + case FRAGMENT: + fragment_len = (c - fragment_start); + break; + default: + GIT_ASSERT(!"unhandled state"); } - if (has_path) { - const char *url_path = given + u.field_data[UF_PATH].off; - size_t url_path_len = u.field_data[UF_PATH].len; - git_str_put(&path, url_path, url_path_len); - } else { - git_str_puts(&path, "/"); + if (scheme_len) { + if ((error = git_str_put(&scheme, scheme_start, scheme_len)) < 0) + goto done; + + git__strntolower(scheme.ptr, scheme.size); } - if (has_query) { - const char *url_query = given + u.field_data[UF_QUERY].off; - size_t url_query_len = u.field_data[UF_QUERY].len; - git_str_decode_percent(&query, url_query, url_query_len); - } + if (user_len && + (error = git_str_decode_percent(&user, user_start, user_len)) < 0) + goto done; - if (has_userinfo) { - const char *url_userinfo = given + u.field_data[UF_USERINFO].off; - size_t url_userinfo_len = u.field_data[UF_USERINFO].len; - const char *colon = memchr(url_userinfo, ':', url_userinfo_len); + if (password_len && + (error = git_str_decode_percent(&password, password_start, password_len)) < 0) + goto done; - if (colon) { - const char *url_username = url_userinfo; - size_t url_username_len = colon - url_userinfo; - const char *url_password = colon + 1; - size_t url_password_len = url_userinfo_len - (url_username_len + 1); + if (host_len && + (error = git_str_decode_percent(&host, host_start, host_len)) < 0) + goto done; - git_str_decode_percent(&username, url_username, url_username_len); - git_str_decode_percent(&password, url_password, url_password_len); - } else { - git_str_decode_percent(&username, url_userinfo, url_userinfo_len); - } - } + if (port_len) + error = git_str_put(&port, port_start, port_len); + else if (scheme_len && (default_port = default_port_for_scheme(scheme.ptr)) != NULL) + error = git_str_puts(&port, default_port); - if (git_str_oom(&scheme) || - git_str_oom(&host) || - git_str_oom(&port) || - git_str_oom(&path) || - git_str_oom(&query) || - git_str_oom(&username) || - git_str_oom(&password)) - return -1; + if (error < 0) + goto done; + + if (path_len) + error = git_str_put(&path, path_start, path_len); + else if (hierarchical) + error = git_str_puts(&path, "/"); + + if (error < 0) + goto done; + + if (query_len && + (error = git_str_decode_percent(&query, query_start, query_len)) < 0) + goto done; + + if (fragment_len && + (error = git_str_decode_percent(&fragment, fragment_start, fragment_len)) < 0) + goto done; url->scheme = git_str_detach(&scheme); url->host = git_str_detach(&host); url->port = git_str_detach(&port); url->path = git_str_detach(&path); url->query = git_str_detach(&query); - url->username = git_str_detach(&username); + url->fragment = git_str_detach(&fragment); + url->username = git_str_detach(&user); url->password = git_str_detach(&password); error = 0; done: git_str_dispose(&scheme); + git_str_dispose(&user); + git_str_dispose(&password); git_str_dispose(&host); git_str_dispose(&port); git_str_dispose(&path); git_str_dispose(&query); - git_str_dispose(&username); - git_str_dispose(&password); + git_str_dispose(&fragment); + return error; } @@ -374,7 +620,7 @@ int git_net_url_parse_scp(git_net_url *url, const char *given) break; default: - GIT_ASSERT("unhandled state"); + GIT_ASSERT(!"unhandled state"); } } @@ -400,6 +646,13 @@ int git_net_url_parse_scp(git_net_url *url, const char *given) return 0; } +int git_net_url_parse_standard_or_scp(git_net_url *url, const char *given) +{ + return git_net_str_is_url(given) ? + git_net_url_parse(url, given) : + git_net_url_parse_scp(url, given); +} + int git_net_url_joinpath( git_net_url *out, git_net_url *one, @@ -588,7 +841,7 @@ bool git_net_url_is_default_port(git_net_url *url) { const char *default_port; - if ((default_port = default_port_for_scheme(url->scheme)) != NULL) + if (url->scheme && (default_port = default_port_for_scheme(url->scheme)) != NULL) return (strcmp(url->port, default_port) == 0); else return false; @@ -744,6 +997,7 @@ void git_net_url_dispose(git_net_url *url) git__free(url->port); url->port = NULL; git__free(url->path); url->path = NULL; git__free(url->query); url->query = NULL; + git__free(url->fragment); url->fragment = NULL; git__free(url->username); url->username = NULL; git__free(url->password); url->password = NULL; } diff --git a/src/util/net.h b/src/util/net.h index 88030a952..17f0bc4f0 100644 --- a/src/util/net.h +++ b/src/util/net.h @@ -15,6 +15,7 @@ typedef struct git_net_url { char *port; char *path; char *query; + char *fragment; char *username; char *password; } git_net_url; @@ -33,6 +34,12 @@ extern int git_net_url_parse(git_net_url *url, const char *str); /** Parses a string containing an SCP style path into a URL structure. */ extern int git_net_url_parse_scp(git_net_url *url, const char *str); +/** + * Parses a string containing a standard URL or an SCP style path into + * a URL structure. + */ +extern int git_net_url_parse_standard_or_scp(git_net_url *url, const char *str); + /** Appends a path and/or query string to the given URL */ extern int git_net_url_joinpath( git_net_url *out, diff --git a/src/util/posix.h b/src/util/posix.h index c8f8cd9d2..607aa9dce 100644 --- a/src/util/posix.h +++ b/src/util/posix.h @@ -104,6 +104,8 @@ typedef __int64 off64_t; typedef __haiku_std_int64 off64_t; #elif defined(__APPLE__) typedef __int64_t off64_t; +#elif defined(_AIX) +typedef long long off64_t; #else typedef int64_t off64_t; #endif diff --git a/src/util/rand.c b/src/util/rand.c index d28e4aa97..940faf947 100644 --- a/src/util/rand.c +++ b/src/util/rand.c @@ -14,6 +14,10 @@ See . */ # include #endif +#if defined(GIT_WIN32) +# include +#endif + static uint64_t state[4]; static git_mutex state_lock; diff --git a/src/util/regexp.c b/src/util/regexp.c index 2569dea0a..08700882b 100644 --- a/src/util/regexp.c +++ b/src/util/regexp.c @@ -108,11 +108,11 @@ int git_regexp_match(const git_regexp *r, const char *string) data = pcre2_match_data_create(1, NULL); GIT_ERROR_CHECK_ALLOC(data); - if ((error = pcre2_match(*r, (const unsigned char *) string, strlen(string), - 0, 0, data, NULL)) < 0) + error = pcre2_match(*r, (const unsigned char *) string, strlen(string), 0, 0, data, NULL); + pcre2_match_data_free(data); + if (error < 0) return (error == PCRE2_ERROR_NOMATCH) ? GIT_ENOTFOUND : GIT_EINVALIDSPEC; - pcre2_match_data_free(data); return 0; } diff --git a/src/util/thread.h b/src/util/thread.h index 4bbac9fd8..c32554bfd 100644 --- a/src/util/thread.h +++ b/src/util/thread.h @@ -260,36 +260,37 @@ GIT_INLINE(int64_t) git_atomic64_get(git_atomic64 *a) #else -#define git_threads_global_init git__noop +#define git_threads_global_init git__noop #define git_thread unsigned int -#define git_thread_create(thread, start_routine, arg) git__noop() -#define git_thread_join(id, status) git__noop() +#define git_thread_create(t, s, a) git__noop(t, s, a) +#define git_thread_join(i, s) git__noop_args(i, s) /* Pthreads Mutex */ #define git_mutex unsigned int -#define git_mutex_init(a) git__noop() -#define git_mutex_init(a) git__noop() -#define git_mutex_lock(a) git__noop() -#define git_mutex_unlock(a) git__noop() -#define git_mutex_free(a) git__noop() +#define git_mutex_init(a) git__noop_args(a) +#define git_mutex_init(a) git__noop_args(a) +#define git_mutex_lock(a) git__noop_args(a) +#define git_mutex_unlock(a) git__noop_args(a) +#define git_mutex_free(a) git__noop_args(a) /* Pthreads condition vars */ #define git_cond unsigned int -#define git_cond_init(c) git__noop() -#define git_cond_free(c) git__noop() -#define git_cond_wait(c, l) git__noop() -#define git_cond_signal(c) git__noop() -#define git_cond_broadcast(c) git__noop() +#define git_cond_init(c) git__noop_args(c) +#define git_cond_free(c) git__noop_args(c) +#define git_cond_wait(c, l) git__noop_args(c, l) +#define git_cond_signal(c) git__noop_args(c) +#define git_cond_broadcast(c) git__noop_args(c) /* Pthreads rwlock */ #define git_rwlock unsigned int -#define git_rwlock_init(a) git__noop() -#define git_rwlock_rdlock(a) git__noop() -#define git_rwlock_rdunlock(a) git__noop() -#define git_rwlock_wrlock(a) git__noop() -#define git_rwlock_wrunlock(a) git__noop() -#define git_rwlock_free(a) git__noop() +#define git_rwlock_init(a) git__noop_args(a) +#define git_rwlock_rdlock(a) git__noop_args(a) +#define git_rwlock_rdunlock(a) git__noop_args(a) +#define git_rwlock_wrlock(a) git__noop_args(a) +#define git_rwlock_wrunlock(a) git__noop_args(a) +#define git_rwlock_free(a) git__noop_args(a) + #define GIT_RWLOCK_STATIC_INIT 0 diff --git a/src/util/util.h b/src/util/util.h index 8d6d1d6b6..63d6080f7 100644 --- a/src/util/util.h +++ b/src/util/util.h @@ -381,6 +381,7 @@ extern int git__getenv(git_str *out, const char *name); extern int git__online_cpus(void); GIT_INLINE(int) git__noop(void) { return 0; } +GIT_INLINE(int) git__noop_args(void *a, ...) { GIT_UNUSED(a); return 0; } #include "alloc.h" diff --git a/src/util/win32/findfile.c b/src/util/win32/findfile.c deleted file mode 100644 index 725a90167..000000000 --- a/src/util/win32/findfile.c +++ /dev/null @@ -1,286 +0,0 @@ -/* - * Copyright (C) the libgit2 contributors. All rights reserved. - * - * This file is part of libgit2, distributed under the GNU GPL v2 with - * a Linking Exception. For full terms see the included COPYING file. - */ - -#include "findfile.h" - -#include "path_w32.h" -#include "utf-conv.h" -#include "fs_path.h" - -#define REG_GITFORWINDOWS_KEY L"SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Uninstall\\Git_is1" -#define REG_GITFORWINDOWS_KEY_WOW64 L"SOFTWARE\\Wow6432Node\\Microsoft\\Windows\\CurrentVersion\\Uninstall\\Git_is1" - -static int git_win32__expand_path(git_win32_path dest, const wchar_t *src) -{ - DWORD len = ExpandEnvironmentStringsW(src, dest, GIT_WIN_PATH_UTF16); - - if (!len || len > GIT_WIN_PATH_UTF16) - return -1; - - return 0; -} - -static int win32_path_to_8(git_str *dest, const wchar_t *src) -{ - git_win32_utf8_path utf8_path; - - if (git_win32_path_to_utf8(utf8_path, src) < 0) { - git_error_set(GIT_ERROR_OS, "unable to convert path to UTF-8"); - return -1; - } - - /* Convert backslashes to forward slashes */ - git_fs_path_mkposix(utf8_path); - - return git_str_sets(dest, utf8_path); -} - -static git_win32_path mock_registry; -static bool mock_registry_set; - -extern int git_win32__set_registry_system_dir(const wchar_t *mock_sysdir) -{ - if (!mock_sysdir) { - mock_registry[0] = L'\0'; - mock_registry_set = false; - } else { - size_t len = wcslen(mock_sysdir); - - if (len > GIT_WIN_PATH_MAX) { - git_error_set(GIT_ERROR_INVALID, "mock path too long"); - return -1; - } - - wcscpy(mock_registry, mock_sysdir); - mock_registry_set = true; - } - - return 0; -} - -static int lookup_registry_key( - git_win32_path out, - const HKEY hive, - const wchar_t* key, - const wchar_t *value) -{ - HKEY hkey; - DWORD type, size; - int error = GIT_ENOTFOUND; - - /* - * Registry data may not be NUL terminated, provide room to do - * it ourselves. - */ - size = (DWORD)((sizeof(git_win32_path) - 1) * sizeof(wchar_t)); - - if (RegOpenKeyExW(hive, key, 0, KEY_READ, &hkey) != 0) - return GIT_ENOTFOUND; - - if (RegQueryValueExW(hkey, value, NULL, &type, (LPBYTE)out, &size) == 0 && - type == REG_SZ && - size > 0 && - size < sizeof(git_win32_path)) { - size_t wsize = size / sizeof(wchar_t); - size_t len = wsize - 1; - - if (out[wsize - 1] != L'\0') { - len = wsize; - out[wsize] = L'\0'; - } - - if (out[len - 1] == L'\\') - out[len - 1] = L'\0'; - - if (_waccess(out, F_OK) == 0) - error = 0; - } - - RegCloseKey(hkey); - return error; -} - -static int find_sysdir_in_registry(git_win32_path out) -{ - if (mock_registry_set) { - if (mock_registry[0] == L'\0') - return GIT_ENOTFOUND; - - wcscpy(out, mock_registry); - return 0; - } - - if (lookup_registry_key(out, HKEY_CURRENT_USER, REG_GITFORWINDOWS_KEY, L"InstallLocation") == 0 || - lookup_registry_key(out, HKEY_CURRENT_USER, REG_GITFORWINDOWS_KEY_WOW64, L"InstallLocation") == 0 || - lookup_registry_key(out, HKEY_LOCAL_MACHINE, REG_GITFORWINDOWS_KEY, L"InstallLocation") == 0 || - lookup_registry_key(out, HKEY_LOCAL_MACHINE, REG_GITFORWINDOWS_KEY_WOW64, L"InstallLocation") == 0) - return 0; - - return GIT_ENOTFOUND; -} - -static int find_sysdir_in_path(git_win32_path out) -{ - size_t out_len; - - if (git_win32_path_find_executable(out, L"git.exe") < 0 && - git_win32_path_find_executable(out, L"git.cmd") < 0) - return GIT_ENOTFOUND; - - out_len = wcslen(out); - - /* Trim the file name */ - if (out_len <= CONST_STRLEN(L"git.exe")) - return GIT_ENOTFOUND; - - out_len -= CONST_STRLEN(L"git.exe"); - - if (out_len && out[out_len - 1] == L'\\') - out_len--; - - /* - * Git for Windows usually places the command in a 'bin' or - * 'cmd' directory, trim that. - */ - if (out_len >= CONST_STRLEN(L"\\bin") && - wcsncmp(&out[out_len - CONST_STRLEN(L"\\bin")], L"\\bin", CONST_STRLEN(L"\\bin")) == 0) - out_len -= CONST_STRLEN(L"\\bin"); - else if (out_len >= CONST_STRLEN(L"\\cmd") && - wcsncmp(&out[out_len - CONST_STRLEN(L"\\cmd")], L"\\cmd", CONST_STRLEN(L"\\cmd")) == 0) - out_len -= CONST_STRLEN(L"\\cmd"); - - if (!out_len) - return GIT_ENOTFOUND; - - out[out_len] = L'\0'; - return 0; -} - -static int win32_find_existing_dirs( - git_str* out, - const wchar_t* tmpl[]) -{ - git_win32_path path16; - git_str buf = GIT_STR_INIT; - - git_str_clear(out); - - for (; *tmpl != NULL; tmpl++) { - if (!git_win32__expand_path(path16, *tmpl) && - path16[0] != L'%' && - !_waccess(path16, F_OK)) { - win32_path_to_8(&buf, path16); - - if (buf.size) - git_str_join(out, GIT_PATH_LIST_SEPARATOR, out->ptr, buf.ptr); - } - } - - git_str_dispose(&buf); - - return (git_str_oom(out) ? -1 : 0); -} - -static int append_subdir(git_str *out, git_str *path, const char *subdir) -{ - static const char* architecture_roots[] = { - "", - "mingw64", - "mingw32", - NULL - }; - const char **root; - size_t orig_path_len = path->size; - - for (root = architecture_roots; *root; root++) { - if ((*root[0] && git_str_joinpath(path, path->ptr, *root) < 0) || - git_str_joinpath(path, path->ptr, subdir) < 0) - return -1; - - if (git_fs_path_exists(path->ptr) && - git_str_join(out, GIT_PATH_LIST_SEPARATOR, out->ptr, path->ptr) < 0) - return -1; - - git_str_truncate(path, orig_path_len); - } - - return 0; -} - -int git_win32__find_system_dirs(git_str *out, const char *subdir) -{ - git_win32_path pathdir, regdir; - git_str path8 = GIT_STR_INIT; - bool has_pathdir, has_regdir; - int error; - - has_pathdir = (find_sysdir_in_path(pathdir) == 0); - has_regdir = (find_sysdir_in_registry(regdir) == 0); - - if (!has_pathdir && !has_regdir) - return 0; - - /* - * Usually the git in the path is the same git in the registry, - * in this case there's no need to duplicate the paths. - */ - if (has_pathdir && has_regdir && wcscmp(pathdir, regdir) == 0) - has_regdir = false; - - if (has_pathdir) { - if ((error = win32_path_to_8(&path8, pathdir)) < 0 || - (error = append_subdir(out, &path8, subdir)) < 0) - goto done; - } - - if (has_regdir) { - if ((error = win32_path_to_8(&path8, regdir)) < 0 || - (error = append_subdir(out, &path8, subdir)) < 0) - goto done; - } - -done: - git_str_dispose(&path8); - return error; -} - -int git_win32__find_global_dirs(git_str *out) -{ - static const wchar_t *global_tmpls[4] = { - L"%HOME%\\", - L"%HOMEDRIVE%%HOMEPATH%\\", - L"%USERPROFILE%\\", - NULL, - }; - - return win32_find_existing_dirs(out, global_tmpls); -} - -int git_win32__find_xdg_dirs(git_str *out) -{ - static const wchar_t *global_tmpls[7] = { - L"%XDG_CONFIG_HOME%\\git", - L"%APPDATA%\\git", - L"%LOCALAPPDATA%\\git", - L"%HOME%\\.config\\git", - L"%HOMEDRIVE%%HOMEPATH%\\.config\\git", - L"%USERPROFILE%\\.config\\git", - NULL, - }; - - return win32_find_existing_dirs(out, global_tmpls); -} - -int git_win32__find_programdata_dirs(git_str *out) -{ - static const wchar_t *programdata_tmpls[2] = { - L"%PROGRAMDATA%\\Git", - NULL, - }; - - return win32_find_existing_dirs(out, programdata_tmpls); -} diff --git a/src/util/win32/findfile.h b/src/util/win32/findfile.h deleted file mode 100644 index 7b191d1fe..000000000 --- a/src/util/win32/findfile.h +++ /dev/null @@ -1,22 +0,0 @@ -/* - * Copyright (C) the libgit2 contributors. All rights reserved. - * - * This file is part of libgit2, distributed under the GNU GPL v2 with - * a Linking Exception. For full terms see the included COPYING file. - */ - -#ifndef INCLUDE_win32_findfile_h__ -#define INCLUDE_win32_findfile_h__ - -#include "git2_util.h" - -/** Sets the mock registry root for Git for Windows for testing. */ -extern int git_win32__set_registry_system_dir(const wchar_t *mock_sysdir); - -extern int git_win32__find_system_dirs(git_str *out, const char *subpath); -extern int git_win32__find_global_dirs(git_str *out); -extern int git_win32__find_xdg_dirs(git_str *out); -extern int git_win32__find_programdata_dirs(git_str *out); - -#endif - diff --git a/tests/clar/clar.c b/tests/clar/clar.c index ca508d073..c9c3fde38 100644 --- a/tests/clar/clar.c +++ b/tests/clar/clar.c @@ -12,6 +12,7 @@ #include #include #include +#include /* required for sandboxing */ #include @@ -86,6 +87,8 @@ typedef struct stat STAT_T; #endif +#define MAX(x, y) (((x) > (y)) ? (x) : (y)) + #include "clar.h" static void fs_rm(const char *_source); @@ -117,6 +120,8 @@ struct clar_report { const char *suite; enum cl_test_status status; + time_t start; + double elapsed; struct clar_error *errors; struct clar_error *last_error; @@ -145,7 +150,7 @@ static struct { int report_errors_only; int exit_on_error; - int report_suite_names; + int verbosity; int write_summary; char *summary_filename; @@ -186,7 +191,7 @@ struct clar_suite { static void clar_print_init(int test_count, int suite_count, const char *suite_names); static void clar_print_shutdown(int test_count, int suite_count, int error_count); static void clar_print_error(int num, const struct clar_report *report, const struct clar_error *error); -static void clar_print_ontest(const char *test_name, int test_number, enum cl_test_status failed); +static void clar_print_ontest(const char *suite_name, const char *test_name, int test_number, enum cl_test_status failed); static void clar_print_onsuite(const char *suite_name, int suite_index); static void clar_print_onabort(const char *msg, ...); @@ -245,16 +250,53 @@ clar_report_all(void) } } +#ifdef WIN32 +# define clar_time DWORD + +static void clar_time_now(clar_time *out) +{ + *out = GetTickCount(); +} + +static double clar_time_diff(clar_time *start, clar_time *end) +{ + return ((double)*end - (double)*start) / 1000; +} +#else +# include + +# define clar_time struct timeval + +static void clar_time_now(clar_time *out) +{ + struct timezone tz; + + gettimeofday(out, &tz); +} + +static double clar_time_diff(clar_time *start, clar_time *end) +{ + return ((double)end->tv_sec + (double)end->tv_usec / 1.0E6) - + ((double)start->tv_sec + (double)start->tv_usec / 1.0E6); +} +#endif + static void clar_run_test( + const struct clar_suite *suite, const struct clar_func *test, const struct clar_func *initialize, const struct clar_func *cleanup) { + clar_time start, end; + _clar.trampoline_enabled = 1; CL_TRACE(CL_TRACE__TEST__BEGIN); + _clar.last_report->start = time(NULL); + clar_time_now(&start); + if (setjmp(_clar.trampoline) == 0) { if (initialize->ptr != NULL) initialize->ptr(); @@ -264,11 +306,15 @@ clar_run_test( CL_TRACE(CL_TRACE__TEST__RUN_END); } + clar_time_now(&end); + _clar.trampoline_enabled = 0; if (_clar.last_report->status == CL_TEST_NOTRUN) _clar.last_report->status = CL_TEST_OK; + _clar.last_report->elapsed = clar_time_diff(&start, &end); + if (_clar.local_cleanup != NULL) _clar.local_cleanup(_clar.local_cleanup_payload); @@ -286,7 +332,7 @@ clar_run_test( if (_clar.report_errors_only) { clar_report_errors(_clar.last_report); } else { - clar_print_ontest(test->name, _clar.tests_ran, _clar.last_report->status); + clar_print_ontest(suite->name, test->name, _clar.tests_ran, _clar.last_report->status); } } @@ -352,7 +398,7 @@ clar_run_suite(const struct clar_suite *suite, const char *filter) _clar.last_report = report; - clar_run_test(&test[i], &suite->initialize, &suite->cleanup); + clar_run_test(suite, &test[i], &suite->initialize, &suite->cleanup); if (_clar.exit_on_error && _clar.total_errors) return; @@ -427,7 +473,7 @@ clar_parse_args(int argc, char **argv) ++found; if (!exact) - _clar.report_suite_names = 1; + _clar.verbosity = MAX(_clar.verbosity, 1); switch (action) { case 's': { @@ -486,13 +532,13 @@ clar_parse_args(int argc, char **argv) } case 'v': - _clar.report_suite_names = 1; + _clar.verbosity++; break; case 'r': _clar.write_summary = 1; free(_clar.summary_filename); - _clar.summary_filename = strdup(*(argument + 2) ? (argument + 2) : "summary.xml"); + _clar.summary_filename = *(argument + 2) ? strdup(argument + 2) : NULL; break; default: @@ -504,6 +550,8 @@ clar_parse_args(int argc, char **argv) void clar_test_init(int argc, char **argv) { + const char *summary_env; + if (argc > 1) clar_parse_args(argc, argv); @@ -513,11 +561,15 @@ clar_test_init(int argc, char **argv) "" ); - if ((_clar.summary_filename = getenv("CLAR_SUMMARY")) != NULL) { + if (!_clar.summary_filename && + (summary_env = getenv("CLAR_SUMMARY")) != NULL) { _clar.write_summary = 1; - _clar.summary_filename = strdup(_clar.summary_filename); + _clar.summary_filename = strdup(summary_env); } + if (_clar.write_summary && !_clar.summary_filename) + _clar.summary_filename = strdup("summary.xml"); + if (_clar.write_summary && !(_clar.summary = clar_summary_init(_clar.summary_filename))) { clar_print_onabort("Failed to open the summary file\n"); diff --git a/tests/clar/clar.h b/tests/clar/clar.h index 3f659c2f6..8c22382bd 100644 --- a/tests/clar/clar.h +++ b/tests/clar/clar.h @@ -13,12 +13,12 @@ enum cl_test_status { CL_TEST_OK, CL_TEST_FAILURE, CL_TEST_SKIP, - CL_TEST_NOTRUN + CL_TEST_NOTRUN, }; enum cl_output_format { CL_OUTPUT_CLAP, - CL_OUTPUT_TAP + CL_OUTPUT_TAP, }; /** Setup clar environment */ @@ -60,7 +60,7 @@ typedef enum cl_trace_event { CL_TRACE__TEST__END, CL_TRACE__TEST__RUN_BEGIN, CL_TRACE__TEST__RUN_END, - CL_TRACE__TEST__LONGJMP + CL_TRACE__TEST__LONGJMP, } cl_trace_event; typedef void (cl_trace_cb)( diff --git a/tests/clar/clar/print.h b/tests/clar/clar/print.h index dbfd27655..c17e2f693 100644 --- a/tests/clar/clar/print.h +++ b/tests/clar/clar/print.h @@ -36,24 +36,35 @@ static void clar_print_clap_error(int num, const struct clar_report *report, con fflush(stdout); } -static void clar_print_clap_ontest(const char *test_name, int test_number, enum cl_test_status status) +static void clar_print_clap_ontest(const char *suite_name, const char *test_name, int test_number, enum cl_test_status status) { (void)test_name; (void)test_number; - switch(status) { - case CL_TEST_OK: printf("."); break; - case CL_TEST_FAILURE: printf("F"); break; - case CL_TEST_SKIP: printf("S"); break; - case CL_TEST_NOTRUN: printf("N"); break; - } + if (_clar.verbosity > 1) { + printf("%s::%s: ", suite_name, test_name); - fflush(stdout); + switch (status) { + case CL_TEST_OK: printf("ok\n"); break; + case CL_TEST_FAILURE: printf("fail\n"); break; + case CL_TEST_SKIP: printf("skipped"); break; + case CL_TEST_NOTRUN: printf("notrun"); break; + } + } else { + switch (status) { + case CL_TEST_OK: printf("."); break; + case CL_TEST_FAILURE: printf("F"); break; + case CL_TEST_SKIP: printf("S"); break; + case CL_TEST_NOTRUN: printf("N"); break; + } + + fflush(stdout); + } } static void clar_print_clap_onsuite(const char *suite_name, int suite_index) { - if (_clar.report_suite_names) + if (_clar.verbosity == 1) printf("\n%s", suite_name); (void)suite_index; @@ -102,7 +113,7 @@ static void print_escaped(const char *str) printf("%s", str); } -static void clar_print_tap_ontest(const char *test_name, int test_number, enum cl_test_status status) +static void clar_print_tap_ontest(const char *suite_name, const char *test_name, int test_number, enum cl_test_status status) { const struct clar_error *error = _clar.last_report->errors; @@ -111,10 +122,10 @@ static void clar_print_tap_ontest(const char *test_name, int test_number, enum c switch(status) { case CL_TEST_OK: - printf("ok %d - %s::%s\n", test_number, _clar.active_suite, test_name); + printf("ok %d - %s::%s\n", test_number, suite_name, test_name); break; case CL_TEST_FAILURE: - printf("not ok %d - %s::%s\n", test_number, _clar.active_suite, test_name); + printf("not ok %d - %s::%s\n", test_number, suite_name, test_name); printf(" ---\n"); printf(" reason: |\n"); @@ -132,7 +143,7 @@ static void clar_print_tap_ontest(const char *test_name, int test_number, enum c break; case CL_TEST_SKIP: case CL_TEST_NOTRUN: - printf("ok %d - # SKIP %s::%s\n", test_number, _clar.active_suite, test_name); + printf("ok %d - # SKIP %s::%s\n", test_number, suite_name, test_name); break; } @@ -181,9 +192,9 @@ static void clar_print_error(int num, const struct clar_report *report, const st PRINT(error, num, report, error); } -static void clar_print_ontest(const char *test_name, int test_number, enum cl_test_status status) +static void clar_print_ontest(const char *suite_name, const char *test_name, int test_number, enum cl_test_status status) { - PRINT(ontest, test_name, test_number, status); + PRINT(ontest, suite_name, test_name, test_number, status); } static void clar_print_onsuite(const char *suite_name, int suite_index) diff --git a/tests/clar/clar/summary.h b/tests/clar/clar/summary.h index 6279f5057..4dd352e28 100644 --- a/tests/clar/clar/summary.h +++ b/tests/clar/clar/summary.h @@ -20,8 +20,8 @@ static int clar_summary_testsuites(struct clar_summary *summary) } static int clar_summary_testsuite(struct clar_summary *summary, - int idn, const char *name, const char *pkg, time_t timestamp, - double elapsed, int test_count, int fail_count, int error_count) + int idn, const char *name, time_t timestamp, + int test_count, int fail_count, int error_count) { struct tm *tm = localtime(×tamp); char iso_dt[20]; @@ -29,17 +29,15 @@ static int clar_summary_testsuite(struct clar_summary *summary, if (strftime(iso_dt, sizeof(iso_dt), "%Y-%m-%dT%H:%M:%S", tm) == 0) return -1; - return fprintf(summary->fp, "\tfp, "\t\n", - idn, name, pkg, iso_dt, elapsed, test_count, fail_count, error_count); + idn, name, iso_dt, test_count, fail_count, error_count); } static int clar_summary_testcase(struct clar_summary *summary, @@ -58,15 +56,23 @@ static int clar_summary_failure(struct clar_summary *summary, type, message, desc); } +static int clar_summary_skipped(struct clar_summary *summary) +{ + return fprintf(summary->fp, "\t\t\t\n"); +} + struct clar_summary *clar_summary_init(const char *filename) { struct clar_summary *summary; FILE *fp; - if ((fp = fopen(filename, "w")) == NULL) + if ((fp = fopen(filename, "w")) == NULL) { + perror("fopen"); return NULL; + } if ((summary = malloc(sizeof(struct clar_summary))) == NULL) { + perror("malloc"); fclose(fp); return NULL; } @@ -90,14 +96,14 @@ int clar_summary_shutdown(struct clar_summary *summary) struct clar_error *error = report->errors; if (last_suite == NULL || strcmp(last_suite, report->suite) != 0) { - if (clar_summary_testsuite(summary, 0, report->suite, "", - time(NULL), 0, _clar.tests_ran, _clar.total_errors, 0) < 0) + if (clar_summary_testsuite(summary, 0, report->suite, + report->start, _clar.tests_ran, _clar.total_errors, 0) < 0) goto on_error; } last_suite = report->suite; - clar_summary_testcase(summary, report->test, "what", 0); + clar_summary_testcase(summary, report->test, report->suite, report->elapsed); while (error != NULL) { if (clar_summary_failure(summary, "assert", @@ -107,6 +113,9 @@ int clar_summary_shutdown(struct clar_summary *summary) error = error->next; } + if (report->status == CL_TEST_SKIP) + clar_summary_skipped(summary); + if (clar_summary_close_tag(summary, "testcase", 2) < 0) goto on_error; diff --git a/tests/clar/clar_libgit2.c b/tests/clar/clar_libgit2.c index 783b457f9..54122997d 100644 --- a/tests/clar/clar_libgit2.c +++ b/tests/clar/clar_libgit2.c @@ -1,6 +1,7 @@ #include "clar_libgit2.h" #include "posix.h" #include "fs_path.h" +#include "futils.h" #include "git2/sys/repository.h" void cl_git_report_failure( @@ -476,6 +477,25 @@ int cl_repo_get_bool(git_repository *repo, const char *cfg) return val; } +void cl_repo_set_int(git_repository *repo, const char *cfg, int value) +{ + git_config *config; + cl_git_pass(git_repository_config(&config, repo)); + cl_git_pass(git_config_set_int32(config, cfg, value)); + git_config_free(config); +} + +int cl_repo_get_int(git_repository *repo, const char *cfg) +{ + int val = 0; + git_config *config; + cl_git_pass(git_repository_config(&config, repo)); + if (git_config_get_int32(&val, config, cfg) < 0) + git_error_clear(); + git_config_free(config); + return val; +} + void cl_repo_set_string(git_repository *repo, const char *cfg, const char *value) { git_config *config; @@ -548,33 +568,95 @@ void clar__assert_equal_file( (size_t)expected_bytes, (size_t)total_bytes); } -static git_buf _cl_restore_home = GIT_BUF_INIT; +#define FAKE_HOMEDIR_NAME "cl_fake_home" -void cl_fake_home_cleanup(void *payload) +static git_buf _cl_restore_homedir = GIT_BUF_INIT; + +void cl_fake_homedir_cleanup(void *payload) { GIT_UNUSED(payload); - if (_cl_restore_home.ptr) { - cl_git_pass(git_libgit2_opts( - GIT_OPT_SET_SEARCH_PATH, GIT_CONFIG_LEVEL_GLOBAL, _cl_restore_home.ptr)); - git_buf_dispose(&_cl_restore_home); + if (_cl_restore_homedir.ptr) { + cl_git_pass(git_futils_rmdir_r(FAKE_HOMEDIR_NAME, NULL, GIT_RMDIR_REMOVE_FILES)); + + cl_git_pass(git_libgit2_opts(GIT_OPT_SET_HOMEDIR, _cl_restore_homedir.ptr)); + git_buf_dispose(&_cl_restore_homedir); } } -void cl_fake_home(void) +void cl_fake_homedir(git_str *out) { git_str path = GIT_STR_INIT; cl_git_pass(git_libgit2_opts( - GIT_OPT_GET_SEARCH_PATH, GIT_CONFIG_LEVEL_GLOBAL, &_cl_restore_home)); + GIT_OPT_GET_HOMEDIR, &_cl_restore_homedir)); - cl_set_cleanup(cl_fake_home_cleanup, NULL); + cl_set_cleanup(cl_fake_homedir_cleanup, NULL); + + /* TOC/TOU but merely attempts to prevent accidental cleanup. */ + cl_assert(!git_fs_path_exists(FAKE_HOMEDIR_NAME)); + cl_must_pass(p_mkdir(FAKE_HOMEDIR_NAME, 0777)); + cl_git_pass(git_fs_path_prettify(&path, FAKE_HOMEDIR_NAME, NULL)); + cl_git_pass(git_libgit2_opts(GIT_OPT_SET_HOMEDIR, path.ptr)); + + if (out) + git_str_swap(out, &path); + + git_str_dispose(&path); +} + +#define FAKE_GLOBALCONFIG_NAME "cl_fake_global" + +static git_buf _cl_restore_globalconfig = GIT_BUF_INIT; + +void cl_fake_globalconfig_cleanup(void *payload) +{ + GIT_UNUSED(payload); + + if (_cl_restore_globalconfig.ptr) { + cl_git_pass(git_futils_rmdir_r(FAKE_GLOBALCONFIG_NAME, NULL, GIT_RMDIR_REMOVE_FILES)); + + cl_git_pass(git_libgit2_opts(GIT_OPT_SET_HOMEDIR, _cl_restore_globalconfig.ptr)); + git_buf_dispose(&_cl_restore_globalconfig); + } +} + +void cl_fake_globalconfig(git_str *out) +{ + git_str path = GIT_STR_INIT; - if (!git_fs_path_exists("home")) - cl_must_pass(p_mkdir("home", 0777)); - cl_git_pass(git_fs_path_prettify(&path, "home", NULL)); cl_git_pass(git_libgit2_opts( - GIT_OPT_SET_SEARCH_PATH, GIT_CONFIG_LEVEL_GLOBAL, path.ptr)); + GIT_OPT_GET_SEARCH_PATH, GIT_CONFIG_LEVEL_GLOBAL, &_cl_restore_globalconfig)); + + cl_set_cleanup(cl_fake_globalconfig_cleanup, NULL); + + /* TOC/TOU but merely attempts to prevent accidental cleanup. */ + cl_assert(!git_fs_path_exists(FAKE_GLOBALCONFIG_NAME)); + cl_must_pass(p_mkdir(FAKE_GLOBALCONFIG_NAME, 0777)); + cl_git_pass(git_fs_path_prettify(&path, FAKE_GLOBALCONFIG_NAME, NULL)); + cl_git_pass(git_libgit2_opts(GIT_OPT_SET_SEARCH_PATH, GIT_CONFIG_LEVEL_GLOBAL, path.ptr)); + + if (out) + git_str_swap(out, &path); + + git_str_dispose(&path); +} + +void cl_sandbox_set_homedir(const char *home) +{ + git_str path = GIT_STR_INIT; + + if (home) { + git_libgit2_opts(GIT_OPT_SET_HOMEDIR, home); + } else { + git_str_joinpath(&path, clar_sandbox_path(), "__home"); + + if (!git_fs_path_exists(path.ptr)) + cl_must_pass(p_mkdir(path.ptr, 0777)); + + git_libgit2_opts(GIT_OPT_SET_HOMEDIR, path.ptr); + } + git_str_dispose(&path); } diff --git a/tests/clar/clar_libgit2.h b/tests/clar/clar_libgit2.h index da3f41524..c33b5d28b 100644 --- a/tests/clar/clar_libgit2.h +++ b/tests/clar/clar_libgit2.h @@ -5,6 +5,7 @@ #include #include "common.h" #include "posix.h" +#include "oid.h" /** * Replace for `clar_must_pass` that passes the last library error as the @@ -136,13 +137,32 @@ GIT_INLINE(void) clar__assert_equal_oid( const char *file, const char *func, int line, const char *desc, const git_oid *one, const git_oid *two) { - if (git_oid_cmp(one, two)) { - char err[] = "\"........................................\" != \"........................................\""; + if (git_oid_equal(one, two)) + return; + + if (git_oid_type(one) != git_oid_type(two)) { + char err[64]; + + snprintf(err, 64, "different oid types: %d vs %d", git_oid_type(one), git_oid_type(two)); + clar__fail(file, func, line, desc, err, 1); + } else if (git_oid_type(one) == GIT_OID_SHA1) { + char err[] = "\"........................................\" != \"........................................\""; git_oid_fmt(&err[1], one); git_oid_fmt(&err[47], two); clar__fail(file, func, line, desc, err, 1); +#ifdef GIT_EXPERIMENTAL_SHA256 + } else if (one->type == GIT_OID_SHA256) { + char err[] = "\"................................................................\" != \"................................................................\""; + + git_oid_fmt(&err[1], one); + git_oid_fmt(&err[71], one); + + clar__fail(file, func, line, desc, err, 1); +#endif + } else { + clar__fail(file, func, line, desc, "unknown oid types", 1); } } @@ -211,16 +231,28 @@ void cl_repo_commit_from_index( void cl_repo_set_bool(git_repository *repo, const char *cfg, int value); int cl_repo_get_bool(git_repository *repo, const char *cfg); +void cl_repo_set_int(git_repository *repo, const char *cfg, int value); +int cl_repo_get_int(git_repository *repo, const char *cfg); + void cl_repo_set_string(git_repository *repo, const char *cfg, const char *value); -/* set up a fake "home" directory and set libgit2 GLOBAL search path. - * - * automatically configures cleanup function to restore the regular search - * path, although you can call it explicitly if you wish (with NULL). +/* + * set up a fake "home" directory -- automatically configures cleanup + * function to restore the home directory, although you can call it + * explicitly if you wish (with NULL). */ -void cl_fake_home(void); -void cl_fake_home_cleanup(void *); +void cl_fake_homedir(git_str *); +void cl_fake_homedir_cleanup(void *); +/* + * set up a fake global configuration directory -- automatically + * configures cleanup function to restore the global config + * although you can call it explicitly if you wish (with NULL). + */ +void cl_fake_globalconfig(git_str *); +void cl_fake_globalconfig_cleanup(void *); + +void cl_sandbox_set_homedir(const char *); void cl_sandbox_set_search_path_defaults(void); void cl_sandbox_disable_ownership_validation(void); diff --git a/tests/clar/main.c b/tests/clar/main.c index d879073a8..e3f4fe740 100644 --- a/tests/clar/main.c +++ b/tests/clar/main.c @@ -25,6 +25,7 @@ int main(int argc, char *argv[]) } cl_global_trace_register(); + cl_sandbox_set_homedir(getenv("CLAR_HOMEDIR")); cl_sandbox_set_search_path_defaults(); cl_sandbox_disable_ownership_validation(); diff --git a/tests/libgit2/CMakeLists.txt b/tests/libgit2/CMakeLists.txt index 280b9a8ef..866122d1c 100644 --- a/tests/libgit2/CMakeLists.txt +++ b/tests/libgit2/CMakeLists.txt @@ -65,10 +65,12 @@ endif() include(AddClarTest) add_clar_test(libgit2_tests offline -v -xonline) -add_clar_test(libgit2_tests invasive -v -score::ftruncate -sfilter::stream::bigfile -sodb::largefiles -siterator::workdir::filesystem_gunk -srepo::init -srepo::init::at_filesystem_root) -add_clar_test(libgit2_tests online -v -sonline -xonline::customcert -xonline::clone::ssh_auth_methods) +add_clar_test(libgit2_tests invasive -v -sfilter::stream::bigfile -sodb::largefiles -siterator::workdir::filesystem_gunk -srepo::init -srepo::init::at_filesystem_root) +add_clar_test(libgit2_tests online -v -sonline -xonline::customcert) add_clar_test(libgit2_tests online_customcert -v -sonline::customcert) add_clar_test(libgit2_tests gitdaemon -v -sonline::push) +add_clar_test(libgit2_tests gitdaemon_namespace -v -sonline::clone::namespace) +add_clar_test(libgit2_tests gitdaemon_sha256 -v -sonline::clone::sha256) add_clar_test(libgit2_tests ssh -v -sonline::push -sonline::clone::ssh_cert -sonline::clone::ssh_with_paths -sonline::clone::path_whitespace_ssh -sonline::clone::ssh_auth_methods) add_clar_test(libgit2_tests proxy -v -sonline::clone::proxy) add_clar_test(libgit2_tests auth_clone -v -sonline::clone::cred) diff --git a/tests/libgit2/apply/apply_helpers.c b/tests/libgit2/apply/apply_helpers.c index 91cc51a71..e78b8ffcb 100644 --- a/tests/libgit2/apply/apply_helpers.c +++ b/tests/libgit2/apply/apply_helpers.c @@ -14,7 +14,7 @@ static int iterator_compare(const git_index_entry *entry, void *_data) struct iterator_compare_data *data = (struct iterator_compare_data *)_data; cl_assert_equal_i(GIT_INDEX_ENTRY_STAGE(entry), data->expected[data->idx].stage); - cl_git_pass(git_oid_fromstr(&expected_id, data->expected[data->idx].oid_str)); + cl_git_pass(git_oid__fromstr(&expected_id, data->expected[data->idx].oid_str, GIT_OID_SHA1)); cl_assert_equal_oid(&entry->id, &expected_id); cl_assert_equal_i(entry->mode, data->expected[data->idx].mode); cl_assert_equal_s(entry->path, data->expected[data->idx].path); diff --git a/tests/libgit2/apply/both.c b/tests/libgit2/apply/both.c index 108963270..1331e7ea4 100644 --- a/tests/libgit2/apply/both.c +++ b/tests/libgit2/apply/both.c @@ -12,7 +12,7 @@ void test_apply_both__initialize(void) repo = cl_git_sandbox_init(TEST_REPO_PATH); - git_oid_fromstr(&oid, "539bd011c4822c560c1d17cab095006b7a10f707"); + git_oid__fromstr(&oid, "539bd011c4822c560c1d17cab095006b7a10f707", GIT_OID_SHA1); cl_git_pass(git_commit_lookup(&commit, repo, &oid)); cl_git_pass(git_reset(repo, (git_object *)commit, GIT_RESET_HARD, NULL)); git_commit_free(commit); @@ -42,8 +42,8 @@ void test_apply_both__generated_diff(void) size_t both_expected_cnt = sizeof(both_expected) / sizeof(struct merge_index_entry); - git_oid_fromstr(&a_oid, "539bd011c4822c560c1d17cab095006b7a10f707"); - git_oid_fromstr(&b_oid, "7c7bf85e978f1d18c0566f702d2cb7766b9c8d4f"); + git_oid__fromstr(&a_oid, "539bd011c4822c560c1d17cab095006b7a10f707", GIT_OID_SHA1); + git_oid__fromstr(&b_oid, "7c7bf85e978f1d18c0566f702d2cb7766b9c8d4f", GIT_OID_SHA1); cl_git_pass(git_commit_lookup(&a_commit, repo, &a_oid)); cl_git_pass(git_commit_lookup(&b_commit, repo, &b_oid)); @@ -192,7 +192,7 @@ void test_apply_both__index_must_match_workdir(void) memset(&idx_entry, 0, sizeof(git_index_entry)); idx_entry.mode = 0100644; idx_entry.path = "asparagus.txt"; - cl_git_pass(git_oid_fromstr(&idx_entry.id, "06d3fefb8726ab1099acc76e02dfb85e034b2538")); + cl_git_pass(git_oid__fromstr(&idx_entry.id, "06d3fefb8726ab1099acc76e02dfb85e034b2538", GIT_OID_SHA1)); cl_git_pass(git_index_add(index, &idx_entry)); cl_git_pass(git_index_write(index)); @@ -290,7 +290,7 @@ void test_apply_both__keeps_nonconflicting_changes(void) memset(&idx_entry, 0, sizeof(git_index_entry)); idx_entry.mode = 0100644; idx_entry.path = "beef.txt"; - cl_git_pass(git_oid_fromstr(&idx_entry.id, "898d12687fb35be271c27c795a6b32c8b51da79e")); + cl_git_pass(git_oid__fromstr(&idx_entry.id, "898d12687fb35be271c27c795a6b32c8b51da79e", GIT_OID_SHA1)); cl_git_pass(git_index_add(index, &idx_entry)); cl_git_pass(git_index_remove(index, "bouilli.txt", 0)); @@ -386,7 +386,7 @@ void test_apply_both__honors_crlf_attributes(void) cl_git_rmfile("merge-recursive/asparagus.txt"); cl_git_rmfile("merge-recursive/veal.txt"); - git_oid_fromstr(&oid, "539bd011c4822c560c1d17cab095006b7a10f707"); + git_oid__fromstr(&oid, "539bd011c4822c560c1d17cab095006b7a10f707", GIT_OID_SHA1); cl_git_pass(git_commit_lookup(&commit, repo, &oid)); cl_git_pass(git_reset(repo, (git_object *)commit, GIT_RESET_HARD, NULL)); git_commit_free(commit); diff --git a/tests/libgit2/apply/callbacks.c b/tests/libgit2/apply/callbacks.c index 1b759dc9b..2f9af3101 100644 --- a/tests/libgit2/apply/callbacks.c +++ b/tests/libgit2/apply/callbacks.c @@ -12,7 +12,7 @@ void test_apply_callbacks__initialize(void) repo = cl_git_sandbox_init(TEST_REPO_PATH); - git_oid_fromstr(&oid, "539bd011c4822c560c1d17cab095006b7a10f707"); + git_oid__fromstr(&oid, "539bd011c4822c560c1d17cab095006b7a10f707", GIT_OID_SHA1); cl_git_pass(git_commit_lookup(&commit, repo, &oid)); cl_git_pass(git_reset(repo, (git_object *)commit, GIT_RESET_HARD, NULL)); git_commit_free(commit); diff --git a/tests/libgit2/apply/check.c b/tests/libgit2/apply/check.c index 9e42365ed..d055d455b 100644 --- a/tests/libgit2/apply/check.c +++ b/tests/libgit2/apply/check.c @@ -12,7 +12,7 @@ void test_apply_check__initialize(void) repo = cl_git_sandbox_init(TEST_REPO_PATH); - git_oid_fromstr(&oid, "539bd011c4822c560c1d17cab095006b7a10f707"); + git_oid__fromstr(&oid, "539bd011c4822c560c1d17cab095006b7a10f707", GIT_OID_SHA1); cl_git_pass(git_commit_lookup(&commit, repo, &oid)); cl_git_pass(git_reset(repo, (git_object *)commit, GIT_RESET_HARD, NULL)); git_commit_free(commit); @@ -32,8 +32,8 @@ void test_apply_check__generate_diff(void) git_diff_options diff_opts = GIT_DIFF_OPTIONS_INIT; git_apply_options opts = GIT_APPLY_OPTIONS_INIT; - cl_git_pass(git_oid_fromstr(&a_oid, "539bd011c4822c560c1d17cab095006b7a10f707")); - cl_git_pass(git_oid_fromstr(&b_oid, "7c7bf85e978f1d18c0566f702d2cb7766b9c8d4f")); + cl_git_pass(git_oid__fromstr(&a_oid, "539bd011c4822c560c1d17cab095006b7a10f707", GIT_OID_SHA1)); + cl_git_pass(git_oid__fromstr(&b_oid, "7c7bf85e978f1d18c0566f702d2cb7766b9c8d4f", GIT_OID_SHA1)); cl_git_pass(git_commit_lookup(&a_commit, repo, &a_oid)); cl_git_pass(git_commit_lookup(&b_commit, repo, &b_oid)); diff --git a/tests/libgit2/apply/index.c b/tests/libgit2/apply/index.c index 9c9094cce..2dc0d53cb 100644 --- a/tests/libgit2/apply/index.c +++ b/tests/libgit2/apply/index.c @@ -12,7 +12,7 @@ void test_apply_index__initialize(void) repo = cl_git_sandbox_init(TEST_REPO_PATH); - git_oid_fromstr(&oid, "539bd011c4822c560c1d17cab095006b7a10f707"); + git_oid__fromstr(&oid, "539bd011c4822c560c1d17cab095006b7a10f707", GIT_OID_SHA1); cl_git_pass(git_commit_lookup(&commit, repo, &oid)); cl_git_pass(git_reset(repo, (git_object *)commit, GIT_RESET_HARD, NULL)); git_commit_free(commit); @@ -42,8 +42,8 @@ void test_apply_index__generate_diff(void) size_t index_expected_cnt = sizeof(index_expected) / sizeof(struct merge_index_entry); - git_oid_fromstr(&a_oid, "539bd011c4822c560c1d17cab095006b7a10f707"); - git_oid_fromstr(&b_oid, "7c7bf85e978f1d18c0566f702d2cb7766b9c8d4f"); + git_oid__fromstr(&a_oid, "539bd011c4822c560c1d17cab095006b7a10f707", GIT_OID_SHA1); + git_oid__fromstr(&b_oid, "7c7bf85e978f1d18c0566f702d2cb7766b9c8d4f", GIT_OID_SHA1); cl_git_pass(git_commit_lookup(&a_commit, repo, &a_oid)); cl_git_pass(git_commit_lookup(&b_commit, repo, &b_oid)); @@ -233,7 +233,7 @@ void test_apply_index__keeps_nonconflicting_changes(void) memset(&idx_entry, 0, sizeof(git_index_entry)); idx_entry.mode = 0100644; idx_entry.path = "beef.txt"; - cl_git_pass(git_oid_fromstr(&idx_entry.id, "898d12687fb35be271c27c795a6b32c8b51da79e")); + cl_git_pass(git_oid__fromstr(&idx_entry.id, "898d12687fb35be271c27c795a6b32c8b51da79e", GIT_OID_SHA1)); cl_git_pass(git_index_add(index, &idx_entry)); cl_git_pass(git_index_remove(index, "bouilli.txt", 0)); @@ -279,7 +279,7 @@ void test_apply_index__can_apply_nonconflicting_file_changes(void) memset(&idx_entry, 0, sizeof(git_index_entry)); idx_entry.mode = 0100644; idx_entry.path = "asparagus.txt"; - cl_git_pass(git_oid_fromstr(&idx_entry.id, "06d3fefb8726ab1099acc76e02dfb85e034b2538")); + cl_git_pass(git_oid__fromstr(&idx_entry.id, "06d3fefb8726ab1099acc76e02dfb85e034b2538", GIT_OID_SHA1)); cl_git_pass(git_index_add(index, &idx_entry)); cl_git_pass(git_index_write(index)); diff --git a/tests/libgit2/apply/tree.c b/tests/libgit2/apply/tree.c index 5154f134f..667bb9d40 100644 --- a/tests/libgit2/apply/tree.c +++ b/tests/libgit2/apply/tree.c @@ -35,8 +35,8 @@ void test_apply_tree__one(void) { 0100644, "a7b066537e6be7109abfe4ff97b675d4e077da20", 0, "veal.txt" }, }; - git_oid_fromstr(&a_oid, "539bd011c4822c560c1d17cab095006b7a10f707"); - git_oid_fromstr(&b_oid, "7c7bf85e978f1d18c0566f702d2cb7766b9c8d4f"); + git_oid__fromstr(&a_oid, "539bd011c4822c560c1d17cab095006b7a10f707", GIT_OID_SHA1); + git_oid__fromstr(&b_oid, "7c7bf85e978f1d18c0566f702d2cb7766b9c8d4f", GIT_OID_SHA1); cl_git_pass(git_commit_lookup(&a_commit, repo, &a_oid)); cl_git_pass(git_commit_lookup(&b_commit, repo, &b_oid)); @@ -75,7 +75,7 @@ void test_apply_tree__adds_file(void) { 0100644, "94d2c01087f48213bd157222d54edfefd77c9bba", 0, "veal.txt" }, }; - git_oid_fromstr(&a_oid, "539bd011c4822c560c1d17cab095006b7a10f707"); + git_oid__fromstr(&a_oid, "539bd011c4822c560c1d17cab095006b7a10f707", GIT_OID_SHA1); cl_git_pass(git_commit_lookup(&a_commit, repo, &a_oid)); diff --git a/tests/libgit2/apply/workdir.c b/tests/libgit2/apply/workdir.c index d0d9c1aba..e1011d114 100644 --- a/tests/libgit2/apply/workdir.c +++ b/tests/libgit2/apply/workdir.c @@ -12,7 +12,7 @@ void test_apply_workdir__initialize(void) repo = cl_git_sandbox_init(TEST_REPO_PATH); - git_oid_fromstr(&oid, "539bd011c4822c560c1d17cab095006b7a10f707"); + git_oid__fromstr(&oid, "539bd011c4822c560c1d17cab095006b7a10f707", GIT_OID_SHA1); cl_git_pass(git_commit_lookup(&commit, repo, &oid)); cl_git_pass(git_reset(repo, (git_object *)commit, GIT_RESET_HARD, NULL)); git_commit_free(commit); @@ -42,8 +42,8 @@ void test_apply_workdir__generated_diff(void) size_t workdir_expected_cnt = sizeof(workdir_expected) / sizeof(struct merge_index_entry); - git_oid_fromstr(&a_oid, "539bd011c4822c560c1d17cab095006b7a10f707"); - git_oid_fromstr(&b_oid, "7c7bf85e978f1d18c0566f702d2cb7766b9c8d4f"); cl_git_pass(git_commit_lookup(&a_commit, repo, &a_oid)); + git_oid__fromstr(&a_oid, "539bd011c4822c560c1d17cab095006b7a10f707", GIT_OID_SHA1); + git_oid__fromstr(&b_oid, "7c7bf85e978f1d18c0566f702d2cb7766b9c8d4f", GIT_OID_SHA1); cl_git_pass(git_commit_lookup(&a_commit, repo, &a_oid)); cl_git_pass(git_commit_lookup(&b_commit, repo, &b_oid)); cl_git_pass(git_commit_tree(&a_tree, a_commit)); @@ -171,7 +171,7 @@ void test_apply_workdir__modified_index_with_unmodified_workdir_is_ok(void) idx_entry.mode = 0100644; idx_entry.path = "veal.txt"; - cl_git_pass(git_oid_fromstr(&idx_entry.id, "ffb36e513f5fdf8a6ba850a20142676a2ac4807d")); + cl_git_pass(git_oid__fromstr(&idx_entry.id, "ffb36e513f5fdf8a6ba850a20142676a2ac4807d", GIT_OID_SHA1)); cl_git_pass(git_index_add(index, &idx_entry)); cl_git_pass(git_index_remove(index, "asparagus.txt", 0)); diff --git a/tests/libgit2/blame/blame_helpers.c b/tests/libgit2/blame/blame_helpers.c index 6b3ce677d..8aeaa5886 100644 --- a/tests/libgit2/blame/blame_helpers.c +++ b/tests/libgit2/blame/blame_helpers.c @@ -17,7 +17,7 @@ void hunk_message(size_t idx, const git_blame_hunk *hunk, const char *fmt, ...) void check_blame_hunk_index(git_repository *repo, git_blame *blame, int idx, size_t start_line, size_t len, char boundary, const char *commit_id, const char *orig_path) { - char expected[GIT_OID_HEXSZ+1] = {0}, actual[GIT_OID_HEXSZ+1] = {0}; + char expected[GIT_OID_SHA1_HEXSIZE+1] = {0}, actual[GIT_OID_SHA1_HEXSIZE+1] = {0}; const git_blame_hunk *hunk = git_blame_get_hunk_byindex(blame, idx); cl_assert(hunk); diff --git a/tests/libgit2/blame/getters.c b/tests/libgit2/blame/getters.c index 66eaeecf9..c160cd383 100644 --- a/tests/libgit2/blame/getters.c +++ b/tests/libgit2/blame/getters.c @@ -10,11 +10,11 @@ void test_blame_getters__initialize(void) git_blame_options opts = GIT_BLAME_OPTIONS_INIT; git_blame_hunk hunks[] = { - { 3, {{0}}, 1, NULL, {{0}}, "a", 0}, - { 3, {{0}}, 4, NULL, {{0}}, "b", 0}, - { 3, {{0}}, 7, NULL, {{0}}, "c", 0}, - { 3, {{0}}, 10, NULL, {{0}}, "d", 0}, - { 3, {{0}}, 13, NULL, {{0}}, "e", 0}, + { 3, GIT_OID_SHA1_ZERO, 1, NULL, GIT_OID_SHA1_ZERO, "a", 0}, + { 3, GIT_OID_SHA1_ZERO, 4, NULL, GIT_OID_SHA1_ZERO, "b", 0}, + { 3, GIT_OID_SHA1_ZERO, 7, NULL, GIT_OID_SHA1_ZERO, "c", 0}, + { 3, GIT_OID_SHA1_ZERO, 10, NULL, GIT_OID_SHA1_ZERO, "d", 0}, + { 3, GIT_OID_SHA1_ZERO, 13, NULL, GIT_OID_SHA1_ZERO, "e", 0}, }; g_blame = git_blame__alloc(NULL, opts, ""); diff --git a/tests/libgit2/checkout/binaryunicode.c b/tests/libgit2/checkout/binaryunicode.c index edb5cfaf5..b8c6c079e 100644 --- a/tests/libgit2/checkout/binaryunicode.c +++ b/tests/libgit2/checkout/binaryunicode.c @@ -3,6 +3,7 @@ #include "repo/repo_helpers.h" #include "path.h" #include "futils.h" +#include "odb.h" static git_repository *g_repo; @@ -35,13 +36,13 @@ static void execute_test(void) git_commit_free(commit); /* Verify that the lenna.jpg file was checked out correctly */ - cl_git_pass(git_oid_fromstr(&check, "8ab005d890fe53f65eda14b23672f60d9f4ec5a1")); - cl_git_pass(git_odb_hashfile(&oid, "binaryunicode/lenna.jpg", GIT_OBJECT_BLOB)); + cl_git_pass(git_oid__fromstr(&check, "8ab005d890fe53f65eda14b23672f60d9f4ec5a1", GIT_OID_SHA1)); + cl_git_pass(git_odb__hashfile(&oid, "binaryunicode/lenna.jpg", GIT_OBJECT_BLOB, GIT_OID_SHA1)); cl_assert_equal_oid(&oid, &check); /* Verify that the text file was checked out correctly */ - cl_git_pass(git_oid_fromstr(&check, "965b223880dd4249e2c66a0cc0b4cffe1dc40f5a")); - cl_git_pass(git_odb_hashfile(&oid, "binaryunicode/utf16_withbom_noeol_crlf.txt", GIT_OBJECT_BLOB)); + cl_git_pass(git_oid__fromstr(&check, "965b223880dd4249e2c66a0cc0b4cffe1dc40f5a", GIT_OID_SHA1)); + cl_git_pass(git_odb__hashfile(&oid, "binaryunicode/utf16_withbom_noeol_crlf.txt", GIT_OBJECT_BLOB, GIT_OID_SHA1)); cl_assert_equal_oid(&oid, &check); } diff --git a/tests/libgit2/checkout/conflict.c b/tests/libgit2/checkout/conflict.c index 4a9e4b9fa..b2eb939dc 100644 --- a/tests/libgit2/checkout/conflict.c +++ b/tests/libgit2/checkout/conflict.c @@ -49,7 +49,7 @@ static git_index *g_index; struct checkout_index_entry { uint16_t mode; - char oid_str[GIT_OID_HEXSZ+1]; + char oid_str[GIT_OID_SHA1_HEXSIZE+1]; int stage; char path[128]; }; @@ -104,7 +104,7 @@ static void create_index(struct checkout_index_entry *entries, size_t entries_le entry.mode = entries[i].mode; GIT_INDEX_ENTRY_STAGE_SET(&entry, entries[i].stage); - git_oid_fromstr(&entry.id, entries[i].oid_str); + git_oid__fromstr(&entry.id, entries[i].oid_str, GIT_OID_SHA1); entry.path = entries[i].path; cl_git_pass(git_index_add(g_index, &entry)); @@ -155,7 +155,7 @@ static void ensure_workdir_oid(const char *path, const char *oid_str) { git_oid expected, actual; - cl_git_pass(git_oid_fromstr(&expected, oid_str)); + cl_git_pass(git_oid__fromstr(&expected, oid_str, GIT_OID_SHA1)); cl_git_pass(git_repository_hashfile(&actual, g_repo, path, GIT_OBJECT_BLOB, NULL)); cl_assert_equal_oid(&expected, &actual); } diff --git a/tests/libgit2/checkout/index.c b/tests/libgit2/checkout/index.c index 6a80d22c5..6432cba84 100644 --- a/tests/libgit2/checkout/index.c +++ b/tests/libgit2/checkout/index.c @@ -791,15 +791,15 @@ static void add_conflict(git_index *index, const char *path) entry.mode = 0100644; entry.path = path; - git_oid_fromstr(&entry.id, "d427e0b2e138501a3d15cc376077a3631e15bd46"); + git_oid__fromstr(&entry.id, "d427e0b2e138501a3d15cc376077a3631e15bd46", GIT_OID_SHA1); GIT_INDEX_ENTRY_STAGE_SET(&entry, 1); cl_git_pass(git_index_add(index, &entry)); - git_oid_fromstr(&entry.id, "4e886e602529caa9ab11d71f86634bd1b6e0de10"); + git_oid__fromstr(&entry.id, "4e886e602529caa9ab11d71f86634bd1b6e0de10", GIT_OID_SHA1); GIT_INDEX_ENTRY_STAGE_SET(&entry, 2); cl_git_pass(git_index_add(index, &entry)); - git_oid_fromstr(&entry.id, "2bd0a343aeef7a2cf0d158478966a6e587ff3863"); + git_oid__fromstr(&entry.id, "2bd0a343aeef7a2cf0d158478966a6e587ff3863", GIT_OID_SHA1); GIT_INDEX_ENTRY_STAGE_SET(&entry, 3); cl_git_pass(git_index_add(index, &entry)); } diff --git a/tests/libgit2/checkout/tree.c b/tests/libgit2/checkout/tree.c index d4b57f5d1..65df00cd8 100644 --- a/tests/libgit2/checkout/tree.c +++ b/tests/libgit2/checkout/tree.c @@ -139,8 +139,8 @@ void test_checkout_tree__doesnt_write_unrequested_files_to_worktree(void) git_commit* p_chomped_commit; git_checkout_options opts = GIT_CHECKOUT_OPTIONS_INIT; - git_oid_fromstr(&master_oid, "a65fedf39aefe402d3bb6e24df4d4f5fe4547750"); - git_oid_fromstr(&chomped_oid, "e90810b8df3e80c413d903f631643c716887138d"); + git_oid__fromstr(&master_oid, "a65fedf39aefe402d3bb6e24df4d4f5fe4547750", GIT_OID_SHA1); + git_oid__fromstr(&chomped_oid, "e90810b8df3e80c413d903f631643c716887138d", GIT_OID_SHA1); cl_git_pass(git_commit_lookup(&p_master_commit, g_repo, &master_oid)); cl_git_pass(git_commit_lookup(&p_chomped_commit, g_repo, &chomped_oid)); @@ -615,7 +615,7 @@ void test_checkout_tree__donot_update_deleted_file_by_default(void) cl_git_pass(git_repository_index(&index, g_repo)); - cl_git_pass(git_oid_fromstr(&old_id, "be3563ae3f795b2b4353bcce3a527ad0a4f7f644")); + cl_git_pass(git_oid__fromstr(&old_id, "be3563ae3f795b2b4353bcce3a527ad0a4f7f644", GIT_OID_SHA1)); cl_git_pass(git_commit_lookup(&old_commit, g_repo, &old_id)); cl_git_pass(git_reset(g_repo, (git_object *)old_commit, GIT_RESET_HARD, NULL)); @@ -625,7 +625,7 @@ void test_checkout_tree__donot_update_deleted_file_by_default(void) cl_assert(!git_fs_path_exists("testrepo/branch_file.txt")); - cl_git_pass(git_oid_fromstr(&new_id, "099fabac3a9ea935598528c27f866e34089c2eff")); + cl_git_pass(git_oid__fromstr(&new_id, "099fabac3a9ea935598528c27f866e34089c2eff", GIT_OID_SHA1)); cl_git_pass(git_commit_lookup(&new_commit, g_repo, &new_id)); @@ -941,16 +941,16 @@ static void create_conflict(const char *path) memset(&entry, 0x0, sizeof(git_index_entry)); entry.mode = 0100644; GIT_INDEX_ENTRY_STAGE_SET(&entry, 1); - git_oid_fromstr(&entry.id, "d427e0b2e138501a3d15cc376077a3631e15bd46"); + git_oid__fromstr(&entry.id, "d427e0b2e138501a3d15cc376077a3631e15bd46", GIT_OID_SHA1); entry.path = path; cl_git_pass(git_index_add(index, &entry)); GIT_INDEX_ENTRY_STAGE_SET(&entry, 2); - git_oid_fromstr(&entry.id, "ee3fa1b8c00aff7fe02065fdb50864bb0d932ccf"); + git_oid__fromstr(&entry.id, "ee3fa1b8c00aff7fe02065fdb50864bb0d932ccf", GIT_OID_SHA1); cl_git_pass(git_index_add(index, &entry)); GIT_INDEX_ENTRY_STAGE_SET(&entry, 3); - git_oid_fromstr(&entry.id, "2bd0a343aeef7a2cf0d158478966a6e587ff3863"); + git_oid__fromstr(&entry.id, "2bd0a343aeef7a2cf0d158478966a6e587ff3863", GIT_OID_SHA1); cl_git_pass(git_index_add(index, &entry)); cl_git_pass(git_index_write(index)); @@ -988,7 +988,7 @@ void test_checkout_tree__filemode_preserved_in_index(void) cl_git_pass(git_repository_index(&index, g_repo)); /* test a freshly added executable */ - cl_git_pass(git_oid_fromstr(&executable_oid, "afe4393b2b2a965f06acf2ca9658eaa01e0cd6b6")); + cl_git_pass(git_oid__fromstr(&executable_oid, "afe4393b2b2a965f06acf2ca9658eaa01e0cd6b6", GIT_OID_SHA1)); cl_git_pass(git_commit_lookup(&commit, g_repo, &executable_oid)); cl_git_pass(git_checkout_tree(g_repo, (const git_object *)commit, &opts)); @@ -999,7 +999,7 @@ void test_checkout_tree__filemode_preserved_in_index(void) /* Now start with a commit which has a text file */ - cl_git_pass(git_oid_fromstr(&executable_oid, "cf80f8de9f1185bf3a05f993f6121880dd0cfbc9")); + cl_git_pass(git_oid__fromstr(&executable_oid, "cf80f8de9f1185bf3a05f993f6121880dd0cfbc9", GIT_OID_SHA1)); cl_git_pass(git_commit_lookup(&commit, g_repo, &executable_oid)); cl_git_pass(git_checkout_tree(g_repo, (const git_object *)commit, &opts)); @@ -1010,7 +1010,7 @@ void test_checkout_tree__filemode_preserved_in_index(void) /* And then check out to a commit which converts the text file to an executable */ - cl_git_pass(git_oid_fromstr(&executable_oid, "144344043ba4d4a405da03de3844aa829ae8be0e")); + cl_git_pass(git_oid__fromstr(&executable_oid, "144344043ba4d4a405da03de3844aa829ae8be0e", GIT_OID_SHA1)); cl_git_pass(git_commit_lookup(&commit, g_repo, &executable_oid)); cl_git_pass(git_checkout_tree(g_repo, (const git_object *)commit, &opts)); @@ -1021,7 +1021,7 @@ void test_checkout_tree__filemode_preserved_in_index(void) /* Finally, check out the text file again and check that the exec bit is cleared */ - cl_git_pass(git_oid_fromstr(&executable_oid, "cf80f8de9f1185bf3a05f993f6121880dd0cfbc9")); + cl_git_pass(git_oid__fromstr(&executable_oid, "cf80f8de9f1185bf3a05f993f6121880dd0cfbc9", GIT_OID_SHA1)); cl_git_pass(git_commit_lookup(&commit, g_repo, &executable_oid)); cl_git_pass(git_checkout_tree(g_repo, (const git_object *)commit, &opts)); @@ -1063,7 +1063,7 @@ void test_checkout_tree__filemode_preserved_in_workdir(void) opts.checkout_strategy = GIT_CHECKOUT_FORCE; /* test a freshly added executable */ - cl_git_pass(git_oid_fromstr(&executable_oid, "afe4393b2b2a965f06acf2ca9658eaa01e0cd6b6")); + cl_git_pass(git_oid__fromstr(&executable_oid, "afe4393b2b2a965f06acf2ca9658eaa01e0cd6b6", GIT_OID_SHA1)); cl_git_pass(git_commit_lookup(&commit, g_repo, &executable_oid)); cl_git_pass(git_checkout_tree(g_repo, (const git_object *)commit, &opts)); @@ -1073,7 +1073,7 @@ void test_checkout_tree__filemode_preserved_in_workdir(void) /* Now start with a commit which has a text file */ - cl_git_pass(git_oid_fromstr(&executable_oid, "cf80f8de9f1185bf3a05f993f6121880dd0cfbc9")); + cl_git_pass(git_oid__fromstr(&executable_oid, "cf80f8de9f1185bf3a05f993f6121880dd0cfbc9", GIT_OID_SHA1)); cl_git_pass(git_commit_lookup(&commit, g_repo, &executable_oid)); cl_git_pass(git_checkout_tree(g_repo, (const git_object *)commit, &opts)); @@ -1083,7 +1083,7 @@ void test_checkout_tree__filemode_preserved_in_workdir(void) /* And then check out to a commit which converts the text file to an executable */ - cl_git_pass(git_oid_fromstr(&executable_oid, "144344043ba4d4a405da03de3844aa829ae8be0e")); + cl_git_pass(git_oid__fromstr(&executable_oid, "144344043ba4d4a405da03de3844aa829ae8be0e", GIT_OID_SHA1)); cl_git_pass(git_commit_lookup(&commit, g_repo, &executable_oid)); cl_git_pass(git_checkout_tree(g_repo, (const git_object *)commit, &opts)); @@ -1093,7 +1093,7 @@ void test_checkout_tree__filemode_preserved_in_workdir(void) /* Finally, check out the text file again and check that the exec bit is cleared */ - cl_git_pass(git_oid_fromstr(&executable_oid, "cf80f8de9f1185bf3a05f993f6121880dd0cfbc9")); + cl_git_pass(git_oid__fromstr(&executable_oid, "cf80f8de9f1185bf3a05f993f6121880dd0cfbc9", GIT_OID_SHA1)); cl_git_pass(git_commit_lookup(&commit, g_repo, &executable_oid)); cl_git_pass(git_checkout_tree(g_repo, (const git_object *)commit, &opts)); @@ -1112,7 +1112,7 @@ void test_checkout_tree__removes_conflicts(void) git_checkout_options opts = GIT_CHECKOUT_OPTIONS_INIT; git_index *index; - cl_git_pass(git_oid_fromstr(&commit_id, "afe4393b2b2a965f06acf2ca9658eaa01e0cd6b6")); + cl_git_pass(git_oid__fromstr(&commit_id, "afe4393b2b2a965f06acf2ca9658eaa01e0cd6b6", GIT_OID_SHA1)); cl_git_pass(git_commit_lookup(&commit, g_repo, &commit_id)); opts.checkout_strategy = GIT_CHECKOUT_FORCE; @@ -1155,7 +1155,7 @@ void test_checkout_tree__removes_conflicts_only_by_pathscope(void) git_index *index; const char *path = "executable.txt"; - cl_git_pass(git_oid_fromstr(&commit_id, "afe4393b2b2a965f06acf2ca9658eaa01e0cd6b6")); + cl_git_pass(git_oid__fromstr(&commit_id, "afe4393b2b2a965f06acf2ca9658eaa01e0cd6b6", GIT_OID_SHA1)); cl_git_pass(git_commit_lookup(&commit, g_repo, &commit_id)); opts.checkout_strategy = GIT_CHECKOUT_FORCE; @@ -1583,7 +1583,7 @@ static void modify_index_ondisk(void) cl_git_pass(git_repository_open(&other_repo, git_repository_workdir(g_repo))); cl_git_pass(git_repository_index(&other_index, other_repo)); - cl_git_pass(git_oid_fromstr(&entry.id, "1385f264afb75a56a5bec74243be9b367ba4ca08")); + cl_git_pass(git_oid__fromstr(&entry.id, "1385f264afb75a56a5bec74243be9b367ba4ca08", GIT_OID_SHA1)); entry.mode = 0100644; entry.path = "README"; diff --git a/tests/libgit2/checkout/typechange.c b/tests/libgit2/checkout/typechange.c index b888843f0..1fa2d3095 100644 --- a/tests/libgit2/checkout/typechange.c +++ b/tests/libgit2/checkout/typechange.c @@ -319,7 +319,7 @@ void test_checkout_typechange__status_char(void) git_diff_options diffopts = GIT_DIFF_OPTIONS_INIT; char expected[8] = {'M', 'M', 'R', 'T', 'D', 'R', 'A', 'R'}; - git_oid_fromstr(&oid, "9b19edf33a03a0c59cdfc113bfa5c06179bf9b1a"); + git_oid__fromstr(&oid, "9b19edf33a03a0c59cdfc113bfa5c06179bf9b1a", GIT_OID_SHA1); cl_git_pass(git_commit_lookup(&commit, g_repo, &oid)); diffopts.flags |= GIT_DIFF_INCLUDE_TYPECHANGE; cl_git_pass(git_diff__commit(&diff, g_repo, commit, &diffopts)); diff --git a/tests/libgit2/cherrypick/bare.c b/tests/libgit2/cherrypick/bare.c index f90ce0226..664468899 100644 --- a/tests/libgit2/cherrypick/bare.c +++ b/tests/libgit2/cherrypick/bare.c @@ -32,10 +32,10 @@ void test_cherrypick_bare__automerge(void) { 0100644, "df6b290e0bd6a89b01d69f66687e8abf385283ca", 0, "file3.txt" }, }; - git_oid_fromstr(&head_oid, "d3d77487660ee3c0194ee01dc5eaf478782b1c7e"); + git_oid__fromstr(&head_oid, "d3d77487660ee3c0194ee01dc5eaf478782b1c7e", GIT_OID_SHA1); cl_git_pass(git_commit_lookup(&head, repo, &head_oid)); - git_oid_fromstr(&cherry_oid, "cfc4f0999a8367568e049af4f72e452d40828a15"); + git_oid__fromstr(&cherry_oid, "cfc4f0999a8367568e049af4f72e452d40828a15", GIT_OID_SHA1); cl_git_pass(git_commit_lookup(&commit, repo, &cherry_oid)); cl_git_pass(git_cherrypick_commit(&index, repo, commit, head, 0, NULL)); @@ -62,10 +62,10 @@ void test_cherrypick_bare__conflicts(void) { 0100644, "e233b9ed408a95e9d4b65fec7fc34943a556deb2", 3, "file3.txt" }, }; - git_oid_fromstr(&head_oid, "bafbf6912c09505ac60575cd43d3f2aba3bd84d8"); + git_oid__fromstr(&head_oid, "bafbf6912c09505ac60575cd43d3f2aba3bd84d8", GIT_OID_SHA1); cl_git_pass(git_commit_lookup(&head, repo, &head_oid)); - git_oid_fromstr(&cherry_oid, "e9b63f3655b2ad80c0ff587389b5a9589a3a7110"); + git_oid__fromstr(&cherry_oid, "e9b63f3655b2ad80c0ff587389b5a9589a3a7110", GIT_OID_SHA1); cl_git_pass(git_commit_lookup(&commit, repo, &cherry_oid)); cl_git_pass(git_cherrypick_commit(&index, repo, commit, head, 0, NULL)); @@ -89,10 +89,10 @@ void test_cherrypick_bare__orphan(void) { 0100644, "9ccb9bf50c011fd58dcbaa65df917bf79539717f", 0, "orphan.txt" }, }; - git_oid_fromstr(&head_oid, "d3d77487660ee3c0194ee01dc5eaf478782b1c7e"); + git_oid__fromstr(&head_oid, "d3d77487660ee3c0194ee01dc5eaf478782b1c7e", GIT_OID_SHA1); cl_git_pass(git_commit_lookup(&head, repo, &head_oid)); - git_oid_fromstr(&cherry_oid, "74f06b5bfec6d33d7264f73606b57a7c0b963819"); + git_oid__fromstr(&cherry_oid, "74f06b5bfec6d33d7264f73606b57a7c0b963819", GIT_OID_SHA1); cl_git_pass(git_commit_lookup(&commit, repo, &cherry_oid)); cl_git_pass(git_cherrypick_commit(&index, repo, commit, head, 0, NULL)); diff --git a/tests/libgit2/cherrypick/workdir.c b/tests/libgit2/cherrypick/workdir.c index 8fd1ecbdf..c16b7814a 100644 --- a/tests/libgit2/cherrypick/workdir.c +++ b/tests/libgit2/cherrypick/workdir.c @@ -57,7 +57,7 @@ void test_cherrypick_workdir__automerge(void) cl_git_pass(git_signature_new(&signature, "Picker", "picker@example.org", time(NULL), 0)); - git_oid_fromstr(&head_oid, "d3d77487660ee3c0194ee01dc5eaf478782b1c7e"); + git_oid__fromstr(&head_oid, "d3d77487660ee3c0194ee01dc5eaf478782b1c7e", GIT_OID_SHA1); for (i = 0; i < 3; ++i) { git_commit *head = NULL, *commit = NULL; @@ -67,7 +67,7 @@ void test_cherrypick_workdir__automerge(void) cl_git_pass(git_commit_lookup(&head, repo, &head_oid)); cl_git_pass(git_reset(repo, (git_object *)head, GIT_RESET_HARD, NULL)); - git_oid_fromstr(&cherry_oid, cherrypick_oids[i]); + git_oid__fromstr(&cherry_oid, cherrypick_oids[i], GIT_OID_SHA1); cl_git_pass(git_commit_lookup(&commit, repo, &cherry_oid)); cl_git_pass(git_cherrypick(repo, commit, NULL)); @@ -110,7 +110,7 @@ void test_cherrypick_workdir__empty_result(void) cl_git_pass(git_signature_new(&signature, "Picker", "picker@example.org", time(NULL), 0)); - git_oid_fromstr(&head_oid, "cfc4f0999a8367568e049af4f72e452d40828a15"); + git_oid__fromstr(&head_oid, "cfc4f0999a8367568e049af4f72e452d40828a15", GIT_OID_SHA1); /* Create an untracked file that should not conflict */ cl_git_mkfile(TEST_REPO_PATH "/file4.txt", ""); @@ -119,7 +119,7 @@ void test_cherrypick_workdir__empty_result(void) cl_git_pass(git_commit_lookup(&head, repo, &head_oid)); cl_git_pass(git_reset(repo, (git_object *)head, GIT_RESET_HARD, NULL)); - git_oid_fromstr(&cherry_oid, cherrypick_oid); + git_oid__fromstr(&cherry_oid, cherrypick_oid, GIT_OID_SHA1); cl_git_pass(git_commit_lookup(&commit, repo, &cherry_oid)); cl_git_pass(git_cherrypick(repo, commit, NULL)); @@ -151,12 +151,12 @@ void test_cherrypick_workdir__conflicts(void) { 0100644, "e233b9ed408a95e9d4b65fec7fc34943a556deb2", 3, "file3.txt" }, }; - git_oid_fromstr(&head_oid, "bafbf6912c09505ac60575cd43d3f2aba3bd84d8"); + git_oid__fromstr(&head_oid, "bafbf6912c09505ac60575cd43d3f2aba3bd84d8", GIT_OID_SHA1); cl_git_pass(git_commit_lookup(&head, repo, &head_oid)); cl_git_pass(git_reset(repo, (git_object *)head, GIT_RESET_HARD, NULL)); - git_oid_fromstr(&cherry_oid, "e9b63f3655b2ad80c0ff587389b5a9589a3a7110"); + git_oid__fromstr(&cherry_oid, "e9b63f3655b2ad80c0ff587389b5a9589a3a7110", GIT_OID_SHA1); cl_git_pass(git_commit_lookup(&commit, repo, &cherry_oid)); cl_git_pass(git_cherrypick(repo, commit, NULL)); @@ -259,12 +259,12 @@ void test_cherrypick_workdir__conflict_use_ours(void) /* leave the index in a conflicted state, but checkout "ours" to the workdir */ opts.checkout_opts.checkout_strategy = GIT_CHECKOUT_SAFE | GIT_CHECKOUT_USE_OURS; - git_oid_fromstr(&head_oid, "bafbf6912c09505ac60575cd43d3f2aba3bd84d8"); + git_oid__fromstr(&head_oid, "bafbf6912c09505ac60575cd43d3f2aba3bd84d8", GIT_OID_SHA1); cl_git_pass(git_commit_lookup(&head, repo, &head_oid)); cl_git_pass(git_reset(repo, (git_object *)head, GIT_RESET_HARD, NULL)); - git_oid_fromstr(&cherry_oid, "e9b63f3655b2ad80c0ff587389b5a9589a3a7110"); + git_oid__fromstr(&cherry_oid, "e9b63f3655b2ad80c0ff587389b5a9589a3a7110", GIT_OID_SHA1); cl_git_pass(git_commit_lookup(&commit, repo, &cherry_oid)); cl_git_pass(git_cherrypick(repo, commit, &opts)); @@ -302,11 +302,11 @@ void test_cherrypick_workdir__rename(void) opts.merge_opts.flags |= GIT_MERGE_FIND_RENAMES; opts.merge_opts.rename_threshold = 50; - git_oid_fromstr(&head_oid, "cfc4f0999a8367568e049af4f72e452d40828a15"); + git_oid__fromstr(&head_oid, "cfc4f0999a8367568e049af4f72e452d40828a15", GIT_OID_SHA1); cl_git_pass(git_commit_lookup(&head, repo, &head_oid)); cl_git_pass(git_reset(repo, (git_object *)head, GIT_RESET_HARD, NULL)); - git_oid_fromstr(&cherry_oid, "2a26c7e88b285613b302ba76712bc998863f3cbc"); + git_oid__fromstr(&cherry_oid, "2a26c7e88b285613b302ba76712bc998863f3cbc", GIT_OID_SHA1); cl_git_pass(git_commit_lookup(&commit, repo, &cherry_oid)); cl_git_pass(git_cherrypick(repo, commit, &opts)); @@ -337,11 +337,11 @@ void test_cherrypick_workdir__both_renamed(void) opts.merge_opts.flags |= GIT_MERGE_FIND_RENAMES; opts.merge_opts.rename_threshold = 50; - git_oid_fromstr(&head_oid, "44cd2ed2052c9c68f9a439d208e9614dc2a55c70"); + git_oid__fromstr(&head_oid, "44cd2ed2052c9c68f9a439d208e9614dc2a55c70", GIT_OID_SHA1); cl_git_pass(git_commit_lookup(&head, repo, &head_oid)); cl_git_pass(git_reset(repo, (git_object *)head, GIT_RESET_HARD, NULL)); - git_oid_fromstr(&cherry_oid, "2a26c7e88b285613b302ba76712bc998863f3cbc"); + git_oid__fromstr(&cherry_oid, "2a26c7e88b285613b302ba76712bc998863f3cbc", GIT_OID_SHA1); cl_git_pass(git_commit_lookup(&commit, repo, &cherry_oid)); cl_git_pass(git_cherrypick(repo, commit, &opts)); @@ -388,11 +388,11 @@ void test_cherrypick_workdir__merge_fails_without_mainline_specified(void) git_commit *head, *commit; git_oid head_oid, cherry_oid; - git_oid_fromstr(&head_oid, "cfc4f0999a8367568e049af4f72e452d40828a15"); + git_oid__fromstr(&head_oid, "cfc4f0999a8367568e049af4f72e452d40828a15", GIT_OID_SHA1); cl_git_pass(git_commit_lookup(&head, repo, &head_oid)); cl_git_pass(git_reset(repo, (git_object *)head, GIT_RESET_HARD, NULL)); - git_oid_fromstr(&cherry_oid, "abe4603bc7cd5b8167a267e0e2418fd2348f8cff"); + git_oid__fromstr(&cherry_oid, "abe4603bc7cd5b8167a267e0e2418fd2348f8cff", GIT_OID_SHA1); cl_git_pass(git_commit_lookup(&commit, repo, &cherry_oid)); cl_must_fail(git_cherrypick(repo, commit, NULL)); @@ -420,11 +420,11 @@ void test_cherrypick_workdir__merge_first_parent(void) opts.mainline = 1; - git_oid_fromstr(&head_oid, "cfc4f0999a8367568e049af4f72e452d40828a15"); + git_oid__fromstr(&head_oid, "cfc4f0999a8367568e049af4f72e452d40828a15", GIT_OID_SHA1); cl_git_pass(git_commit_lookup(&head, repo, &head_oid)); cl_git_pass(git_reset(repo, (git_object *)head, GIT_RESET_HARD, NULL)); - git_oid_fromstr(&cherry_oid, "abe4603bc7cd5b8167a267e0e2418fd2348f8cff"); + git_oid__fromstr(&cherry_oid, "abe4603bc7cd5b8167a267e0e2418fd2348f8cff", GIT_OID_SHA1); cl_git_pass(git_commit_lookup(&commit, repo, &cherry_oid)); cl_git_pass(git_cherrypick(repo, commit, &opts)); @@ -452,11 +452,11 @@ void test_cherrypick_workdir__merge_second_parent(void) opts.mainline = 2; - git_oid_fromstr(&head_oid, "cfc4f0999a8367568e049af4f72e452d40828a15"); + git_oid__fromstr(&head_oid, "cfc4f0999a8367568e049af4f72e452d40828a15", GIT_OID_SHA1); cl_git_pass(git_commit_lookup(&head, repo, &head_oid)); cl_git_pass(git_reset(repo, (git_object *)head, GIT_RESET_HARD, NULL)); - git_oid_fromstr(&cherry_oid, "abe4603bc7cd5b8167a267e0e2418fd2348f8cff"); + git_oid__fromstr(&cherry_oid, "abe4603bc7cd5b8167a267e0e2418fd2348f8cff", GIT_OID_SHA1); cl_git_pass(git_commit_lookup(&commit, repo, &cherry_oid)); cl_git_pass(git_cherrypick(repo, commit, &opts)); diff --git a/tests/libgit2/commit/commit.c b/tests/libgit2/commit/commit.c index fd574f7f2..140f87d0c 100644 --- a/tests/libgit2/commit/commit.c +++ b/tests/libgit2/commit/commit.c @@ -26,10 +26,10 @@ void test_commit_commit__create_unexisting_update_ref(void) git_signature *s; git_reference *ref; - git_oid_fromstr(&oid, "a65fedf39aefe402d3bb6e24df4d4f5fe4547750"); + git_oid__fromstr(&oid, "a65fedf39aefe402d3bb6e24df4d4f5fe4547750", GIT_OID_SHA1); cl_git_pass(git_commit_lookup(&commit, _repo, &oid)); - git_oid_fromstr(&oid, "944c0f6e4dfa41595e6eb3ceecdb14f50fe18162"); + git_oid__fromstr(&oid, "944c0f6e4dfa41595e6eb3ceecdb14f50fe18162", GIT_OID_SHA1); cl_git_pass(git_tree_lookup(&tree, _repo, &oid)); cl_git_pass(git_signature_now(&s, "alice", "alice@example.com")); @@ -59,10 +59,10 @@ void test_commit_commit__create_initial_commit(void) git_signature *s; git_reference *ref; - git_oid_fromstr(&oid, "a65fedf39aefe402d3bb6e24df4d4f5fe4547750"); + git_oid__fromstr(&oid, "a65fedf39aefe402d3bb6e24df4d4f5fe4547750", GIT_OID_SHA1); cl_git_pass(git_commit_lookup(&commit, _repo, &oid)); - git_oid_fromstr(&oid, "944c0f6e4dfa41595e6eb3ceecdb14f50fe18162"); + git_oid__fromstr(&oid, "944c0f6e4dfa41595e6eb3ceecdb14f50fe18162", GIT_OID_SHA1); cl_git_pass(git_tree_lookup(&tree, _repo, &oid)); cl_git_pass(git_signature_now(&s, "alice", "alice@example.com")); @@ -89,10 +89,10 @@ void test_commit_commit__create_initial_commit_parent_not_current(void) git_commit *commit; git_signature *s; - git_oid_fromstr(&oid, "a65fedf39aefe402d3bb6e24df4d4f5fe4547750"); + git_oid__fromstr(&oid, "a65fedf39aefe402d3bb6e24df4d4f5fe4547750", GIT_OID_SHA1); cl_git_pass(git_commit_lookup(&commit, _repo, &oid)); - git_oid_fromstr(&oid, "944c0f6e4dfa41595e6eb3ceecdb14f50fe18162"); + git_oid__fromstr(&oid, "944c0f6e4dfa41595e6eb3ceecdb14f50fe18162", GIT_OID_SHA1); cl_git_pass(git_tree_lookup(&tree, _repo, &oid)); cl_git_pass(git_signature_now(&s, "alice", "alice@example.com")); diff --git a/tests/libgit2/commit/parent.c b/tests/libgit2/commit/parent.c index 18ce0bba6..1ec96babb 100644 --- a/tests/libgit2/commit/parent.c +++ b/tests/libgit2/commit/parent.c @@ -9,7 +9,7 @@ void test_commit_parent__initialize(void) cl_git_pass(git_repository_open(&_repo, cl_fixture("testrepo.git"))); - git_oid_fromstr(&oid, "be3563ae3f795b2b4353bcce3a527ad0a4f7f644"); + git_oid__fromstr(&oid, "be3563ae3f795b2b4353bcce3a527ad0a4f7f644", GIT_OID_SHA1); cl_git_pass(git_commit_lookup(&commit, _repo, &oid)); } diff --git a/tests/libgit2/commit/parse.c b/tests/libgit2/commit/parse.c index 04366d7d2..3a1fc3d26 100644 --- a/tests/libgit2/commit/parse.c +++ b/tests/libgit2/commit/parse.c @@ -56,7 +56,8 @@ void test_commit_parse__header(void) const char *line = testcase->line; const char *line_end = line + strlen(line); - cl_git_pass(git_oid__parse(&oid, &line, line_end, testcase->header)); + cl_git_pass(git_object__parse_oid_header(&oid, + &line, line_end, testcase->header, GIT_OID_SHA1)); cl_assert(line == line_end); } @@ -65,7 +66,8 @@ void test_commit_parse__header(void) const char *line = testcase->line; const char *line_end = line + strlen(line); - cl_git_fail(git_oid__parse(&oid, &line, line_end, testcase->header)); + cl_git_fail(git_object__parse_oid_header(&oid, + &line, line_end, testcase->header, GIT_OID_SHA1)); } } @@ -285,7 +287,7 @@ static int parse_commit(git_commit **out, const char *buffer) fake_odb_object.buffer = (char *)buffer; fake_odb_object.cached.size = strlen(fake_odb_object.buffer); - error = git_commit__parse(commit, &fake_odb_object); + error = git_commit__parse(commit, &fake_odb_object, GIT_OID_SHA1); *out = commit; return error; @@ -341,7 +343,7 @@ void test_commit_parse__details0(void) { unsigned int parents, p; git_commit *parent = NULL, *old_parent = NULL; - git_oid_fromstr(&id, commit_ids[i]); + git_oid__fromstr(&id, commit_ids[i], GIT_OID_SHA1); cl_git_pass(git_commit_lookup(&commit, g_repo, &id)); @@ -531,7 +533,7 @@ corrupt signature\n"; git_buf_dispose(&signed_data); /* Try to parse a tree */ - cl_git_pass(git_oid_fromstr(&commit_id, "45dd856fdd4d89b884c340ba0e047752d9b085d6")); + cl_git_pass(git_oid__fromstr(&commit_id, "45dd856fdd4d89b884c340ba0e047752d9b085d6", GIT_OID_SHA1)); cl_git_fail_with(GIT_ENOTFOUND, git_commit_extract_signature(&signature, &signed_data, g_repo, &commit_id, NULL)); cl_assert_equal_i(GIT_ERROR_INVALID, git_error_last()->klass); diff --git a/tests/libgit2/commit/write.c b/tests/libgit2/commit/write.c index 5a9c9d5a5..890f7384b 100644 --- a/tests/libgit2/commit/write.c +++ b/tests/libgit2/commit/write.c @@ -51,10 +51,10 @@ void test_commit_write__from_memory(void) git_commit *parent; git_tree *tree; - git_oid_fromstr(&tree_id, tree_id_str); + git_oid__fromstr(&tree_id, tree_id_str, GIT_OID_SHA1); cl_git_pass(git_tree_lookup(&tree, g_repo, &tree_id)); - git_oid_fromstr(&parent_id, parent_id_str); + git_oid__fromstr(&parent_id, parent_id_str, GIT_OID_SHA1); cl_git_pass(git_commit_lookup(&parent, g_repo, &parent_id)); /* create signatures */ @@ -107,14 +107,14 @@ void test_commit_write__into_buf(void) git_oid parent_id; git_buf commit = GIT_BUF_INIT; - git_oid_fromstr(&tree_id, tree_id_str); + git_oid__fromstr(&tree_id, tree_id_str, GIT_OID_SHA1); cl_git_pass(git_tree_lookup(&tree, g_repo, &tree_id)); /* create signatures */ cl_git_pass(git_signature_new(&committer, committer_name, committer_email, 123456789, 60)); cl_git_pass(git_signature_new(&author, committer_name, committer_email, 987654321, 90)); - git_oid_fromstr(&parent_id, parent_id_str); + git_oid__fromstr(&parent_id, parent_id_str, GIT_OID_SHA1); cl_git_pass(git_commit_lookup(&parent, g_repo, &parent_id)); cl_git_pass(git_commit_create_buffer(&commit, g_repo, author, committer, @@ -148,7 +148,7 @@ void test_commit_write__root(void) git_reflog *log; const git_reflog_entry *entry; - git_oid_fromstr(&tree_id, tree_id_str); + git_oid__fromstr(&tree_id, tree_id_str, GIT_OID_SHA1); cl_git_pass(git_tree_lookup(&tree, g_repo, &tree_id)); /* create signatures */ @@ -242,34 +242,34 @@ void test_commit_write__can_write_invalid_objects(void) cl_git_pass(git_libgit2_opts(GIT_OPT_ENABLE_STRICT_OBJECT_CREATION, 0)); /* this is a valid tree and parent */ - git_oid_fromstr(&tree_id, tree_id_str); - git_oid_fromstr(&parent_id, parent_id_str); + git_oid__fromstr(&tree_id, tree_id_str, GIT_OID_SHA1); + git_oid__fromstr(&parent_id, parent_id_str, GIT_OID_SHA1); - git_oid_fromstr(&expected_id, "c8571bbec3a72c4bcad31648902e5a453f1adece"); + git_oid__fromstr(&expected_id, "c8571bbec3a72c4bcad31648902e5a453f1adece", GIT_OID_SHA1); cl_git_pass(create_commit_from_ids(&commit_id, &tree_id, &parent_id)); cl_assert_equal_oid(&expected_id, &commit_id); /* this is a wholly invented tree id */ - git_oid_fromstr(&tree_id, "1234567890123456789012345678901234567890"); - git_oid_fromstr(&parent_id, parent_id_str); + git_oid__fromstr(&tree_id, "1234567890123456789012345678901234567890", GIT_OID_SHA1); + git_oid__fromstr(&parent_id, parent_id_str, GIT_OID_SHA1); - git_oid_fromstr(&expected_id, "996008340b8e68d69bf3c28d7c57fb7ec3c8e202"); + git_oid__fromstr(&expected_id, "996008340b8e68d69bf3c28d7c57fb7ec3c8e202", GIT_OID_SHA1); cl_git_pass(create_commit_from_ids(&commit_id, &tree_id, &parent_id)); cl_assert_equal_oid(&expected_id, &commit_id); /* this is a wholly invented parent id */ - git_oid_fromstr(&tree_id, tree_id_str); - git_oid_fromstr(&parent_id, "1234567890123456789012345678901234567890"); + git_oid__fromstr(&tree_id, tree_id_str, GIT_OID_SHA1); + git_oid__fromstr(&parent_id, "1234567890123456789012345678901234567890", GIT_OID_SHA1); - git_oid_fromstr(&expected_id, "d78f660cab89d9791ca6714b57978bf2a7e709fd"); + git_oid__fromstr(&expected_id, "d78f660cab89d9791ca6714b57978bf2a7e709fd", GIT_OID_SHA1); cl_git_pass(create_commit_from_ids(&commit_id, &tree_id, &parent_id)); cl_assert_equal_oid(&expected_id, &commit_id); /* these are legitimate objects, but of the wrong type */ - git_oid_fromstr(&tree_id, parent_id_str); - git_oid_fromstr(&parent_id, tree_id_str); + git_oid__fromstr(&tree_id, parent_id_str, GIT_OID_SHA1); + git_oid__fromstr(&parent_id, tree_id_str, GIT_OID_SHA1); - git_oid_fromstr(&expected_id, "5d80c07414e3f18792949699dfcacadf7748f361"); + git_oid__fromstr(&expected_id, "5d80c07414e3f18792949699dfcacadf7748f361", GIT_OID_SHA1); cl_git_pass(create_commit_from_ids(&commit_id, &tree_id, &parent_id)); cl_assert_equal_oid(&expected_id, &commit_id); } @@ -279,23 +279,23 @@ void test_commit_write__can_validate_objects(void) git_oid tree_id, parent_id, commit_id; /* this is a valid tree and parent */ - git_oid_fromstr(&tree_id, tree_id_str); - git_oid_fromstr(&parent_id, parent_id_str); + git_oid__fromstr(&tree_id, tree_id_str, GIT_OID_SHA1); + git_oid__fromstr(&parent_id, parent_id_str, GIT_OID_SHA1); cl_git_pass(create_commit_from_ids(&commit_id, &tree_id, &parent_id)); /* this is a wholly invented tree id */ - git_oid_fromstr(&tree_id, "1234567890123456789012345678901234567890"); - git_oid_fromstr(&parent_id, parent_id_str); + git_oid__fromstr(&tree_id, "1234567890123456789012345678901234567890", GIT_OID_SHA1); + git_oid__fromstr(&parent_id, parent_id_str, GIT_OID_SHA1); cl_git_fail(create_commit_from_ids(&commit_id, &tree_id, &parent_id)); /* this is a wholly invented parent id */ - git_oid_fromstr(&tree_id, tree_id_str); - git_oid_fromstr(&parent_id, "1234567890123456789012345678901234567890"); + git_oid__fromstr(&tree_id, tree_id_str, GIT_OID_SHA1); + git_oid__fromstr(&parent_id, "1234567890123456789012345678901234567890", GIT_OID_SHA1); cl_git_fail(create_commit_from_ids(&commit_id, &tree_id, &parent_id)); /* these are legitimate objects, but of the wrong type */ - git_oid_fromstr(&tree_id, parent_id_str); - git_oid_fromstr(&parent_id, tree_id_str); + git_oid__fromstr(&tree_id, parent_id_str, GIT_OID_SHA1); + git_oid__fromstr(&parent_id, tree_id_str, GIT_OID_SHA1); cl_git_fail(create_commit_from_ids(&commit_id, &tree_id, &parent_id)); } diff --git a/tests/libgit2/config/find.c b/tests/libgit2/config/find.c new file mode 100644 index 000000000..7ca8ec767 --- /dev/null +++ b/tests/libgit2/config/find.c @@ -0,0 +1,11 @@ +#include "clar_libgit2.h" + +void test_config_find__one(void) +{ + git_buf buf = GIT_BUF_INIT; + + cl_git_fail_with(GIT_ENOTFOUND, git_config_find_global(&buf)); + cl_git_fail_with(GIT_ENOTFOUND, git_config_find_xdg(&buf)); + cl_git_fail_with(GIT_ENOTFOUND, git_config_find_system(&buf)); + cl_git_fail_with(GIT_ENOTFOUND, git_config_find_programdata(&buf)); +} diff --git a/tests/libgit2/config/include.c b/tests/libgit2/config/include.c index 9328f3cf6..1b55fdc86 100644 --- a/tests/libgit2/config/include.c +++ b/tests/libgit2/config/include.c @@ -42,8 +42,13 @@ void test_config_include__absolute(void) void test_config_include__homedir(void) { - cl_git_pass(git_libgit2_opts(GIT_OPT_SET_SEARCH_PATH, GIT_CONFIG_LEVEL_GLOBAL, cl_fixture("config"))); + git_str homefile = GIT_STR_INIT; + + cl_fake_homedir(&homefile); + cl_git_pass(git_str_joinpath(&homefile, homefile.ptr, "config-included")); + cl_git_mkfile("config-include-homedir", "[include]\npath = ~/config-included"); + cl_git_mkfile(homefile.ptr, "[foo \"bar\"]\n\tbaz = huzzah\n"); cl_git_pass(git_config_open_ondisk(&cfg, "config-include-homedir")); @@ -53,6 +58,8 @@ void test_config_include__homedir(void) cl_sandbox_set_search_path_defaults(); cl_git_pass(p_unlink("config-include-homedir")); + + git_str_dispose(&homefile); } /* We need to pretend that the variables were defined where the file was included */ @@ -113,7 +120,8 @@ void test_config_include__missing(void) void test_config_include__missing_homedir(void) { - cl_git_pass(git_libgit2_opts(GIT_OPT_SET_SEARCH_PATH, GIT_CONFIG_LEVEL_GLOBAL, cl_fixture("config"))); + cl_fake_homedir(NULL); + cl_git_mkfile("including", "[include]\npath = ~/.nonexistentfile\n[foo]\nbar = baz"); git_error_clear(); diff --git a/tests/libgit2/config/read.c b/tests/libgit2/config/read.c index a2e668c20..ac6459b9e 100644 --- a/tests/libgit2/config/read.c +++ b/tests/libgit2/config/read.c @@ -728,14 +728,11 @@ void test_config_read__path(void) { git_config *cfg; git_buf path = GIT_BUF_INIT; - git_buf old_path = GIT_BUF_INIT; git_str home_path = GIT_STR_INIT; git_str expected_path = GIT_STR_INIT; - cl_git_pass(p_mkdir("fakehome", 0777)); - cl_git_pass(git_fs_path_prettify(&home_path, "fakehome", NULL)); - cl_git_pass(git_libgit2_opts(GIT_OPT_GET_SEARCH_PATH, GIT_CONFIG_LEVEL_GLOBAL, &old_path)); - cl_git_pass(git_libgit2_opts(GIT_OPT_SET_SEARCH_PATH, GIT_CONFIG_LEVEL_GLOBAL, home_path.ptr)); + cl_fake_homedir(&home_path); + cl_git_mkfile("./testconfig", "[some]\n path = ~/somefile"); cl_git_pass(git_fs_path_join_unrooted(&expected_path, "somefile", home_path.ptr, NULL)); @@ -761,8 +758,6 @@ void test_config_read__path(void) cl_git_mkfile("./testconfig", "[some]\n path = ~user/foo"); cl_git_fail(git_config_get_path(&path, cfg, "some.path")); - cl_git_pass(git_libgit2_opts(GIT_OPT_SET_SEARCH_PATH, GIT_CONFIG_LEVEL_GLOBAL, old_path.ptr)); - git_buf_dispose(&old_path); git_str_dispose(&home_path); git_str_dispose(&expected_path); git_config_free(cfg); diff --git a/tests/libgit2/core/oid.c b/tests/libgit2/core/oid.c index 894feadf6..a405b3344 100644 --- a/tests/libgit2/core/oid.c +++ b/tests/libgit2/core/oid.c @@ -1,79 +1,213 @@ #include "clar_libgit2.h" #include "oid.h" -static git_oid id; -static git_oid idp; -static git_oid idm; -const char *str_oid = "ae90f12eea699729ed24555e40b9fd669da12a12"; -const char *str_oid_p = "ae90f12eea699729ed"; -const char *str_oid_m = "ae90f12eea699729ed24555e40b9fd669da12a12THIS IS EXTRA TEXT THAT SHOULD GET IGNORED"; +static git_oid id_sha1; +static git_oid idp_sha1; +static git_oid idm_sha1; + +const char *str_oid_sha1 = "ae90f12eea699729ed24555e40b9fd669da12a12"; +const char *str_oid_sha1_p = "ae90f12eea699729ed"; +const char *str_oid_sha1_m = "ae90f12eea699729ed24555e40b9fd669da12a12THIS IS EXTRA TEXT THAT SHOULD GET IGNORED"; + +#ifdef GIT_EXPERIMENTAL_SHA256 +static git_oid id_sha256; +static git_oid idp_sha256; +static git_oid idm_sha256; + +const char *str_oid_sha256 = "d3e63d2f2e43d1fee23a74bf19a0ede156cba2d1bd602eba13de433cea1bb512"; +const char *str_oid_sha256_p = "d3e63d2f2e43d1fee2"; +const char *str_oid_sha256_m = "d3e63d2f2e43d1fee23a74bf19a0ede156cba2d1bd602eba13de433cea1bb512 GARBAGE EXTRA TEXT AT THE END"; +#endif void test_core_oid__initialize(void) { - cl_git_pass(git_oid_fromstr(&id, str_oid)); - cl_git_pass(git_oid_fromstrp(&idp, str_oid_p)); - cl_git_fail(git_oid_fromstrp(&idm, str_oid_m)); + cl_git_pass(git_oid__fromstr(&id_sha1, str_oid_sha1, GIT_OID_SHA1)); + cl_git_pass(git_oid__fromstrp(&idp_sha1, str_oid_sha1_p, GIT_OID_SHA1)); + cl_git_fail(git_oid__fromstrp(&idm_sha1, str_oid_sha1_m, GIT_OID_SHA1)); + +#ifdef GIT_EXPERIMENTAL_SHA256 + cl_git_pass(git_oid__fromstr(&id_sha256, str_oid_sha256, GIT_OID_SHA256)); + cl_git_pass(git_oid__fromstrp(&idp_sha256, str_oid_sha256_p, GIT_OID_SHA256)); + cl_git_fail(git_oid__fromstrp(&idm_sha256, str_oid_sha256_m, GIT_OID_SHA256)); +#endif } -void test_core_oid__streq(void) +void test_core_oid__streq_sha1(void) { - cl_assert_equal_i(0, git_oid_streq(&id, str_oid)); - cl_assert_equal_i(-1, git_oid_streq(&id, "deadbeefdeadbeefdeadbeefdeadbeefdeadbeef")); + cl_assert_equal_i(0, git_oid_streq(&id_sha1, str_oid_sha1)); + cl_assert_equal_i(-1, git_oid_streq(&id_sha1, "deadbeefdeadbeefdeadbeefdeadbeefdeadbeef")); - cl_assert_equal_i(-1, git_oid_streq(&id, "deadbeef")); - cl_assert_equal_i(-1, git_oid_streq(&id, "I'm not an oid.... :)")); + cl_assert_equal_i(-1, git_oid_streq(&id_sha1, "deadbeef")); + cl_assert_equal_i(-1, git_oid_streq(&id_sha1, "I'm not an oid.... :)")); - cl_assert_equal_i(0, git_oid_streq(&idp, "ae90f12eea699729ed0000000000000000000000")); - cl_assert_equal_i(0, git_oid_streq(&idp, "ae90f12eea699729ed")); - cl_assert_equal_i(-1, git_oid_streq(&idp, "ae90f12eea699729ed1")); - cl_assert_equal_i(-1, git_oid_streq(&idp, "ae90f12eea699729ec")); - cl_assert_equal_i(-1, git_oid_streq(&idp, "deadbeefdeadbeefdeadbeefdeadbeefdeadbeef")); + cl_assert_equal_i(0, git_oid_streq(&idp_sha1, "ae90f12eea699729ed0000000000000000000000")); + cl_assert_equal_i(0, git_oid_streq(&idp_sha1, "ae90f12eea699729ed")); + cl_assert_equal_i(-1, git_oid_streq(&idp_sha1, "ae90f12eea699729ed1")); + cl_assert_equal_i(-1, git_oid_streq(&idp_sha1, "ae90f12eea699729ec")); + cl_assert_equal_i(-1, git_oid_streq(&idp_sha1, "deadbeefdeadbeefdeadbeefdeadbeefdeadbeef")); - cl_assert_equal_i(-1, git_oid_streq(&idp, "deadbeef")); - cl_assert_equal_i(-1, git_oid_streq(&idp, "I'm not an oid.... :)")); + cl_assert_equal_i(-1, git_oid_streq(&idp_sha1, "deadbeef")); + cl_assert_equal_i(-1, git_oid_streq(&idp_sha1, "I'm not an oid.... :)")); } -void test_core_oid__strcmp(void) +void test_core_oid__streq_sha256(void) { - cl_assert_equal_i(0, git_oid_strcmp(&id, str_oid)); - cl_assert(git_oid_strcmp(&id, "deadbeefdeadbeefdeadbeefdeadbeefdeadbeef") < 0); +#ifndef GIT_EXPERIMENTAL_SHA256 + cl_skip(); +#else + cl_assert_equal_i(0, git_oid_streq(&id_sha256, str_oid_sha256)); + cl_assert_equal_i(-1, git_oid_streq(&id_sha256, "deadbeefdeadbeefdeadbeefdeadbeefdeadbeefdeadbeefdeadbeefdeadbeef")); - cl_assert(git_oid_strcmp(&id, "deadbeef") < 0); - cl_assert_equal_i(-1, git_oid_strcmp(&id, "I'm not an oid.... :)")); + cl_assert_equal_i(-1, git_oid_streq(&id_sha256, "deadbeef")); + cl_assert_equal_i(-1, git_oid_streq(&id_sha256, "I'm not an oid.... :)")); - cl_assert_equal_i(0, git_oid_strcmp(&idp, "ae90f12eea699729ed0000000000000000000000")); - cl_assert_equal_i(0, git_oid_strcmp(&idp, "ae90f12eea699729ed")); - cl_assert(git_oid_strcmp(&idp, "ae90f12eea699729ed1") < 0); - cl_assert(git_oid_strcmp(&idp, "ae90f12eea699729ec") > 0); - cl_assert(git_oid_strcmp(&idp, "deadbeefdeadbeefdeadbeefdeadbeefdeadbeef") < 0); + cl_assert_equal_i(0, git_oid_streq(&idp_sha256, "d3e63d2f2e43d1fee20000000000000000000000000000000000000000000000")); + cl_assert_equal_i(0, git_oid_streq(&idp_sha256, "d3e63d2f2e43d1fee2")); + cl_assert_equal_i(-1, git_oid_streq(&idp_sha1, "d3e63d2f2e43d1fee21")); + cl_assert_equal_i(-1, git_oid_streq(&idp_sha1, "d3e63d2f2e43d1fee1")); + cl_assert_equal_i(-1, git_oid_streq(&idp_sha256, "deadbeefdeadbeefdeadbeefdeadbeefdeadbeefdeadbeefdeadbeefdeadbeef")); - cl_assert(git_oid_strcmp(&idp, "deadbeef") < 0); - cl_assert_equal_i(-1, git_oid_strcmp(&idp, "I'm not an oid.... :)")); + cl_assert_equal_i(-1, git_oid_streq(&idp_sha1, "deadbeef")); + cl_assert_equal_i(-1, git_oid_streq(&idp_sha1, "I'm not an oid.... :)")); +#endif } -void test_core_oid__ncmp(void) +void test_core_oid__strcmp_sha1(void) { - cl_assert(!git_oid_ncmp(&id, &idp, 0)); - cl_assert(!git_oid_ncmp(&id, &idp, 1)); - cl_assert(!git_oid_ncmp(&id, &idp, 2)); - cl_assert(!git_oid_ncmp(&id, &idp, 17)); - cl_assert(!git_oid_ncmp(&id, &idp, 18)); - cl_assert(git_oid_ncmp(&id, &idp, 19)); - cl_assert(git_oid_ncmp(&id, &idp, 40)); - cl_assert(git_oid_ncmp(&id, &idp, 41)); - cl_assert(git_oid_ncmp(&id, &idp, 42)); + cl_assert_equal_i(0, git_oid_strcmp(&id_sha1, str_oid_sha1)); + cl_assert(git_oid_strcmp(&id_sha1, "deadbeefdeadbeefdeadbeefdeadbeefdeadbeef") < 0); - cl_assert(!git_oid_ncmp(&id, &id, 0)); - cl_assert(!git_oid_ncmp(&id, &id, 1)); - cl_assert(!git_oid_ncmp(&id, &id, 39)); - cl_assert(!git_oid_ncmp(&id, &id, 40)); - cl_assert(!git_oid_ncmp(&id, &id, 41)); + cl_assert(git_oid_strcmp(&id_sha1, "deadbeef") < 0); + cl_assert_equal_i(-1, git_oid_strcmp(&id_sha1, "I'm not an oid.... :)")); + + cl_assert_equal_i(0, git_oid_strcmp(&idp_sha1, "ae90f12eea699729ed0000000000000000000000")); + cl_assert_equal_i(0, git_oid_strcmp(&idp_sha1, "ae90f12eea699729ed")); + cl_assert(git_oid_strcmp(&idp_sha1, "ae90f12eea699729ed1") < 0); + cl_assert(git_oid_strcmp(&idp_sha1, "ae90f12eea699729ec") > 0); + cl_assert(git_oid_strcmp(&idp_sha1, "deadbeefdeadbeefdeadbeefdeadbeefdeadbeef") < 0); + + cl_assert(git_oid_strcmp(&idp_sha1, "deadbeef") < 0); + cl_assert_equal_i(-1, git_oid_strcmp(&idp_sha1, "I'm not an oid.... :)")); +} + +void test_core_oid__strcmp_sha256(void) +{ +#ifndef GIT_EXPERIMENTAL_SHA256 + cl_skip(); +#else + cl_assert_equal_i(0, git_oid_strcmp(&id_sha256, str_oid_sha256)); + cl_assert(git_oid_strcmp(&id_sha256, "deadbeefdeadbeefdeadbeefdeadbeefdeadbeefdeadbeefdeadbeefdeadbeef") < 0); + + cl_assert(git_oid_strcmp(&id_sha256, "deadbeef") < 0); + cl_assert_equal_i(-1, git_oid_strcmp(&id_sha256, "I'm not an oid.... :)")); + + cl_assert_equal_i(0, git_oid_strcmp(&idp_sha256, "d3e63d2f2e43d1fee20000000000000000000000")); + cl_assert_equal_i(0, git_oid_strcmp(&idp_sha256, "d3e63d2f2e43d1fee2")); + cl_assert(git_oid_strcmp(&idp_sha256, "d3e63d2f2e43d1fee21") < 0); + cl_assert(git_oid_strcmp(&idp_sha256, "d3e63d2f2e43d1fee1") > 0); + cl_assert(git_oid_strcmp(&idp_sha256, "deadbeefdeadbeefdeadbeefdeadbeefdeadbeef") < 0); + + cl_assert(git_oid_strcmp(&idp_sha256, "deadbeef") < 0); + cl_assert_equal_i(-1, git_oid_strcmp(&idp_sha256, "I'm not an oid.... :)")); +#endif +} + +void test_core_oid__ncmp_sha1(void) +{ + cl_assert(!git_oid_ncmp(&id_sha1, &idp_sha1, 0)); + cl_assert(!git_oid_ncmp(&id_sha1, &idp_sha1, 1)); + cl_assert(!git_oid_ncmp(&id_sha1, &idp_sha1, 2)); + cl_assert(!git_oid_ncmp(&id_sha1, &idp_sha1, 17)); + cl_assert(!git_oid_ncmp(&id_sha1, &idp_sha1, 18)); + cl_assert(git_oid_ncmp(&id_sha1, &idp_sha1, 19)); + cl_assert(git_oid_ncmp(&id_sha1, &idp_sha1, 40)); + cl_assert(git_oid_ncmp(&id_sha1, &idp_sha1, 41)); + cl_assert(git_oid_ncmp(&id_sha1, &idp_sha1, 42)); + + cl_assert(!git_oid_ncmp(&id_sha1, &id_sha1, 0)); + cl_assert(!git_oid_ncmp(&id_sha1, &id_sha1, 1)); + cl_assert(!git_oid_ncmp(&id_sha1, &id_sha1, 39)); + cl_assert(!git_oid_ncmp(&id_sha1, &id_sha1, 40)); + cl_assert(!git_oid_ncmp(&id_sha1, &id_sha1, 41)); +} + +void test_core_oid__ncmp_sha256(void) +{ +#ifndef GIT_EXPERIMENTAL_SHA256 + cl_skip(); +#else + cl_assert(!git_oid_ncmp(&id_sha256, &idp_sha256, 0)); + cl_assert(!git_oid_ncmp(&id_sha256, &idp_sha256, 1)); + cl_assert(!git_oid_ncmp(&id_sha256, &idp_sha256, 2)); + cl_assert(!git_oid_ncmp(&id_sha256, &idp_sha256, 17)); + cl_assert(!git_oid_ncmp(&id_sha256, &idp_sha256, 18)); + cl_assert(git_oid_ncmp(&id_sha256, &idp_sha256, 19)); + cl_assert(git_oid_ncmp(&id_sha256, &idp_sha256, 40)); + cl_assert(git_oid_ncmp(&id_sha256, &idp_sha256, 41)); + cl_assert(git_oid_ncmp(&id_sha256, &idp_sha256, 42)); + cl_assert(git_oid_ncmp(&id_sha256, &idp_sha256, 63)); + cl_assert(git_oid_ncmp(&id_sha256, &idp_sha256, 64)); + cl_assert(git_oid_ncmp(&id_sha256, &idp_sha256, 65)); + + cl_assert(!git_oid_ncmp(&id_sha256, &id_sha256, 0)); + cl_assert(!git_oid_ncmp(&id_sha256, &id_sha256, 1)); + cl_assert(!git_oid_ncmp(&id_sha256, &id_sha256, 39)); + cl_assert(!git_oid_ncmp(&id_sha256, &id_sha256, 40)); + cl_assert(!git_oid_ncmp(&id_sha256, &id_sha256, 41)); + cl_assert(!git_oid_ncmp(&id_sha256, &id_sha256, 63)); + cl_assert(!git_oid_ncmp(&id_sha256, &id_sha256, 64)); + cl_assert(!git_oid_ncmp(&id_sha256, &id_sha256, 65)); +#endif } void test_core_oid__is_hexstr(void) { - cl_assert(git_oid__is_hexstr("deadbeefdeadbeefdeadbeefdeadbeefdeadbeef")); - cl_assert(!git_oid__is_hexstr("deadbeefdeadbeef")); - cl_assert(!git_oid__is_hexstr("zeadbeefdeadbeefdeadbeefdeadbeefdeadbeef")); - cl_assert(!git_oid__is_hexstr("deadbeefdeadbeefdeadbeefdeadbeefdeadbeef1")); + cl_assert(git_oid__is_hexstr("deadbeefdeadbeefdeadbeefdeadbeefdeadbeef", GIT_OID_SHA1)); + cl_assert(!git_oid__is_hexstr("deadbeefdeadbeef", GIT_OID_SHA1)); + cl_assert(!git_oid__is_hexstr("zeadbeefdeadbeefdeadbeefdeadbeefdeadbeef", GIT_OID_SHA1)); + cl_assert(!git_oid__is_hexstr("deadbeefdeadbeefdeadbeefdeadbeefdeadbeef1", GIT_OID_SHA1)); +} + +void test_core_oid__fmt_substr_sha1(void) +{ + char buf[GIT_OID_MAX_HEXSIZE + 1]; + + memset(buf, 0, GIT_OID_MAX_HEXSIZE + 1); + git_oid_fmt_substr(buf, &id_sha1, 0, 40); + cl_assert_equal_s(buf, str_oid_sha1); + + memset(buf, 0, GIT_OID_MAX_HEXSIZE + 1); + git_oid_fmt_substr(buf, &id_sha1, 0, 18); + cl_assert_equal_s(buf, str_oid_sha1_p); + + memset(buf, 0, GIT_OID_MAX_HEXSIZE + 1); + git_oid_fmt_substr(buf, &id_sha1, 0, 5); + cl_assert_equal_s(buf, "ae90f"); + + memset(buf, 0, GIT_OID_MAX_HEXSIZE + 1); + git_oid_fmt_substr(buf, &id_sha1, 5, 5); + cl_assert_equal_s(buf, "12eea"); + + memset(buf, 0, GIT_OID_MAX_HEXSIZE + 1); + git_oid_fmt_substr(buf, &id_sha1, 5, 6); + cl_assert_equal_s(buf, "12eea6"); +} + +void test_core_oid__type_lookup(void) +{ + cl_assert_equal_i(GIT_OID_SHA1, git_oid_type_fromstr("sha1")); + cl_assert_equal_i(GIT_OID_SHA1, git_oid_type_fromstrn("sha1...", 4)); + cl_assert_equal_s("sha1", git_oid_type_name(GIT_OID_SHA1)); + +#ifdef GIT_EXPERIMENTAL_SHA256 + cl_assert_equal_i(GIT_OID_SHA256, git_oid_type_fromstr("sha256")); + cl_assert_equal_i(GIT_OID_SHA256, git_oid_type_fromstrn("sha256...", 6)); + cl_assert_equal_s("sha256", git_oid_type_name(GIT_OID_SHA256)); +#endif + + cl_assert_equal_i(0, git_oid_type_fromstr("sha42")); + cl_assert_equal_i(0, git_oid_type_fromstrn("sha1", 3)); + cl_assert_equal_i(0, git_oid_type_fromstrn("sha1...", 5)); + cl_assert_equal_s("unknown", git_oid_type_name(0)); + cl_assert_equal_s("unknown", git_oid_type_name(42)); } diff --git a/tests/libgit2/core/oidmap.c b/tests/libgit2/core/oidmap.c index 7f98287a6..34374ceef 100644 --- a/tests/libgit2/core/oidmap.c +++ b/tests/libgit2/core/oidmap.c @@ -17,7 +17,7 @@ void test_core_oidmap__initialize(void) test_oids[i].extra = i; - for (j = 0; j < GIT_OID_RAWSZ / 4; ++j) { + for (j = 0; j < GIT_OID_SHA1_SIZE / 4; ++j) { test_oids[i].oid.id[j * 4 ] = (unsigned char)modi; test_oids[i].oid.id[j * 4 + 1] = (unsigned char)(modi >> 8); test_oids[i].oid.id[j * 4 + 2] = (unsigned char)(modi >> 16); @@ -28,6 +28,9 @@ void test_core_oidmap__initialize(void) test_oids[i].oid.id[ 9] = (unsigned char)(i >> 8); test_oids[i].oid.id[10] = (unsigned char)(i >> 16); test_oids[i].oid.id[11] = (unsigned char)(i >> 24); +#ifdef GIT_EXPERIMENTAL_SHA256 + test_oids[i].oid.type = GIT_OID_SHA1; +#endif } cl_git_pass(git_oidmap_new(&g_map)); @@ -93,9 +96,9 @@ void test_core_oidmap__get_fails_with_nonexisting_key(void) void test_core_oidmap__setting_oid_persists(void) { git_oid oids[] = { - {{ 0x01 }}, - {{ 0x02 }}, - {{ 0x03 }} + GIT_OID_INIT(GIT_OID_SHA1, { 0x01 }), + GIT_OID_INIT(GIT_OID_SHA1, { 0x02 }), + GIT_OID_INIT(GIT_OID_SHA1, { 0x03 }) }; cl_git_pass(git_oidmap_set(g_map, &oids[0], "one")); @@ -110,9 +113,9 @@ void test_core_oidmap__setting_oid_persists(void) void test_core_oidmap__setting_existing_key_updates(void) { git_oid oids[] = { - {{ 0x01 }}, - {{ 0x02 }}, - {{ 0x03 }} + GIT_OID_INIT(GIT_OID_SHA1, { 0x01 }), + GIT_OID_INIT(GIT_OID_SHA1, { 0x02 }), + GIT_OID_INIT(GIT_OID_SHA1, { 0x03 }) }; cl_git_pass(git_oidmap_set(g_map, &oids[0], "one")); diff --git a/tests/libgit2/core/opts.c b/tests/libgit2/core/opts.c index e8f65d510..486ff58c6 100644 --- a/tests/libgit2/core/opts.c +++ b/tests/libgit2/core/opts.c @@ -34,8 +34,9 @@ void test_core_opts__extensions_query(void) cl_git_pass(git_libgit2_opts(GIT_OPT_GET_EXTENSIONS, &out)); - cl_assert_equal_sz(out.count, 1); + cl_assert_equal_sz(out.count, 2); cl_assert_equal_s("noop", out.strings[0]); + cl_assert_equal_s("objectformat", out.strings[1]); git_strarray_dispose(&out); } @@ -48,9 +49,10 @@ void test_core_opts__extensions_add(void) cl_git_pass(git_libgit2_opts(GIT_OPT_SET_EXTENSIONS, in, ARRAY_SIZE(in))); cl_git_pass(git_libgit2_opts(GIT_OPT_GET_EXTENSIONS, &out)); - cl_assert_equal_sz(out.count, 2); + cl_assert_equal_sz(out.count, 3); cl_assert_equal_s("noop", out.strings[0]); - cl_assert_equal_s("foo", out.strings[1]); + cl_assert_equal_s("objectformat", out.strings[1]); + cl_assert_equal_s("foo", out.strings[2]); git_strarray_dispose(&out); } @@ -63,9 +65,10 @@ void test_core_opts__extensions_remove(void) cl_git_pass(git_libgit2_opts(GIT_OPT_SET_EXTENSIONS, in, ARRAY_SIZE(in))); cl_git_pass(git_libgit2_opts(GIT_OPT_GET_EXTENSIONS, &out)); - cl_assert_equal_sz(out.count, 2); - cl_assert_equal_s("bar", out.strings[0]); - cl_assert_equal_s("baz", out.strings[1]); + cl_assert_equal_sz(out.count, 3); + cl_assert_equal_s("objectformat", out.strings[0]); + cl_assert_equal_s("bar", out.strings[1]); + cl_assert_equal_s("baz", out.strings[2]); git_strarray_dispose(&out); } diff --git a/tests/libgit2/core/pool.c b/tests/libgit2/core/pool.c index 5746e35b8..cf01cb9d1 100644 --- a/tests/libgit2/core/pool.c +++ b/tests/libgit2/core/pool.c @@ -7,7 +7,7 @@ static char to_hex[] = "0123456789abcdef"; void test_core_pool__oid(void) { git_pool p; - char oid_hex[GIT_OID_HEXSZ]; + char oid_hex[GIT_OID_SHA1_HEXSIZE]; git_oid *oid; int i, j; @@ -22,12 +22,17 @@ void test_core_pool__oid(void) for (j = 0; j < 8; j++) oid_hex[j] = to_hex[(i >> (4 * j)) & 0x0f]; - cl_git_pass(git_oid_fromstr(oid, oid_hex)); + cl_git_pass(git_oid__fromstr(oid, oid_hex, GIT_OID_SHA1)); } #ifndef GIT_DEBUG_POOL /* with fixed page size, allocation must end up with these values */ + +# ifdef GIT_EXPERIMENTAL_SHA256 + cl_assert_equal_i(sizeof(void *) == 8 ? 90 : 82, git_pool__open_pages(&p)); +# else cl_assert_equal_i(sizeof(void *) == 8 ? 55 : 45, git_pool__open_pages(&p)); +# endif #endif git_pool_clear(&p); } diff --git a/tests/libgit2/core/structinit.c b/tests/libgit2/core/structinit.c index 160e2f612..8a6e48d2a 100644 --- a/tests/libgit2/core/structinit.c +++ b/tests/libgit2/core/structinit.c @@ -160,6 +160,11 @@ void test_core_structinit__compare(void) git_stash_apply_options, GIT_STASH_APPLY_OPTIONS_VERSION, \ GIT_STASH_APPLY_OPTIONS_INIT, git_stash_apply_options_init); + /* stash save */ + CHECK_MACRO_FUNC_INIT_EQUAL( \ + git_stash_save_options, GIT_STASH_SAVE_OPTIONS_VERSION, \ + GIT_STASH_SAVE_OPTIONS_INIT, git_stash_save_options_init); + /* status */ CHECK_MACRO_FUNC_INIT_EQUAL( \ git_status_options, GIT_STATUS_OPTIONS_VERSION, \ diff --git a/tests/libgit2/diff/binary.c b/tests/libgit2/diff/binary.c index 4e71f39c6..3bf39f34a 100644 --- a/tests/libgit2/diff/binary.c +++ b/tests/libgit2/diff/binary.c @@ -31,12 +31,12 @@ static void test_patch( git_patch *patch; git_buf actual = GIT_BUF_INIT; - cl_git_pass(git_oid_fromstr(&id_one, one)); + cl_git_pass(git_oid__fromstr(&id_one, one, GIT_OID_SHA1)); cl_git_pass(git_commit_lookup(&commit_one, repo, &id_one)); cl_git_pass(git_commit_tree(&tree_one, commit_one)); if (two) { - cl_git_pass(git_oid_fromstr(&id_two, two)); + cl_git_pass(git_oid__fromstr(&id_two, two, GIT_OID_SHA1)); cl_git_pass(git_commit_lookup(&commit_two, repo, &id_two)); cl_git_pass(git_commit_tree(&tree_two, commit_two)); } else { @@ -100,7 +100,7 @@ void test_diff_binary__add(void) "\n"; opts.flags = GIT_DIFF_SHOW_BINARY; - opts.id_abbrev = GIT_OID_HEXSZ; + opts.id_abbrev = GIT_OID_SHA1_HEXSIZE; repo = cl_git_sandbox_init("diff_format_email"); test_patch( @@ -183,7 +183,7 @@ void test_diff_binary__delete(void) "\n"; opts.flags = GIT_DIFF_SHOW_BINARY; - opts.id_abbrev = GIT_OID_HEXSZ; + opts.id_abbrev = GIT_OID_SHA1_HEXSIZE; repo = cl_git_sandbox_init("diff_format_email"); test_patch( @@ -215,7 +215,7 @@ void test_diff_binary__delta(void) "\n"; opts.flags = GIT_DIFF_SHOW_BINARY | GIT_DIFF_FORCE_BINARY; - opts.id_abbrev = GIT_OID_HEXSZ; + opts.id_abbrev = GIT_OID_SHA1_HEXSIZE; repo = cl_git_sandbox_init("renames"); cl_git_pass(git_repository_index(&index, repo)); @@ -257,7 +257,7 @@ void test_diff_binary__delta_append(void) "\n"; opts.flags = GIT_DIFF_SHOW_BINARY | GIT_DIFF_FORCE_BINARY; - opts.id_abbrev = GIT_OID_HEXSZ; + opts.id_abbrev = GIT_OID_SHA1_HEXSIZE; repo = cl_git_sandbox_init("renames"); cl_git_pass(git_repository_index(&index, repo)); @@ -285,11 +285,11 @@ void test_diff_binary__empty_for_no_diff(void) git_str actual = GIT_STR_INIT; opts.flags = GIT_DIFF_SHOW_BINARY | GIT_DIFF_FORCE_BINARY; - opts.id_abbrev = GIT_OID_HEXSZ; + opts.id_abbrev = GIT_OID_SHA1_HEXSIZE; repo = cl_git_sandbox_init("renames"); - cl_git_pass(git_oid_fromstr(&id, "19dd32dfb1520a64e5bbaae8dce6ef423dfa2f13")); + cl_git_pass(git_oid__fromstr(&id, "19dd32dfb1520a64e5bbaae8dce6ef423dfa2f13", GIT_OID_SHA1)); cl_git_pass(git_commit_lookup(&commit, repo, &id)); cl_git_pass(git_commit_tree(&tree, commit)); @@ -323,7 +323,7 @@ void test_diff_binary__index_to_workdir(void) "\n"; opts.flags = GIT_DIFF_SHOW_BINARY | GIT_DIFF_FORCE_BINARY; - opts.id_abbrev = GIT_OID_HEXSZ; + opts.id_abbrev = GIT_OID_SHA1_HEXSIZE; repo = cl_git_sandbox_init("renames"); cl_git_pass(git_repository_index(&index, repo)); @@ -389,7 +389,7 @@ void test_diff_binary__print_patch_from_diff(void) "\n"; opts.flags = GIT_DIFF_SHOW_BINARY | GIT_DIFF_FORCE_BINARY; - opts.id_abbrev = GIT_OID_HEXSZ; + opts.id_abbrev = GIT_OID_SHA1_HEXSIZE; repo = cl_git_sandbox_init("renames"); cl_git_pass(git_repository_index(&index, repo)); @@ -501,7 +501,7 @@ void test_diff_binary__blob_to_blob(void) struct diff_data diff_data = {0}; opts.flags = GIT_DIFF_SHOW_BINARY | GIT_DIFF_FORCE_BINARY; - opts.id_abbrev = GIT_OID_HEXSZ; + opts.id_abbrev = GIT_OID_SHA1_HEXSIZE; repo = cl_git_sandbox_init("renames"); cl_git_pass(git_repository_index__weakptr(&index, repo)); @@ -510,8 +510,8 @@ void test_diff_binary__blob_to_blob(void) cl_git_pass(git_index_add_bypath(index, "untimely.txt")); cl_git_pass(git_index_write(index)); - git_oid_fromstr(&old_id, "9a69d960ae94b060f56c2a8702545e2bb1abb935"); - git_oid_fromstr(&new_id, "1111d4f11f4b35bf6759e0fb714fe09731ef0840"); + git_oid__fromstr(&old_id, "9a69d960ae94b060f56c2a8702545e2bb1abb935", GIT_OID_SHA1); + git_oid__fromstr(&new_id, "1111d4f11f4b35bf6759e0fb714fe09731ef0840", GIT_OID_SHA1); cl_git_pass(git_blob_lookup(&old_blob, repo, &old_id)); cl_git_pass(git_blob_lookup(&new_blob, repo, &new_id)); diff --git a/tests/libgit2/diff/blob.c b/tests/libgit2/diff/blob.c index d2f42207d..cb7e48b8d 100644 --- a/tests/libgit2/diff/blob.c +++ b/tests/libgit2/diff/blob.c @@ -45,11 +45,11 @@ void test_diff_blob__initialize(void) memset(&expected, 0, sizeof(expected)); /* tests/resources/attr/root_test4.txt */ - cl_git_pass(git_oid_fromstrn(&oid, "a0f7217a", 8)); + cl_git_pass(git_oid__fromstrn(&oid, "a0f7217a", 8, GIT_OID_SHA1)); cl_git_pass(git_blob_lookup_prefix(&d, g_repo, &oid, 8)); /* alien.png */ - cl_git_pass(git_oid_fromstrn(&oid, "edf3dcee", 8)); + cl_git_pass(git_oid__fromstrn(&oid, "edf3dcee", 8, GIT_OID_SHA1)); cl_git_pass(git_blob_lookup_prefix(&alien, g_repo, &oid, 8)); } @@ -86,10 +86,10 @@ void test_diff_blob__patch_with_freed_blobs(void) git_buf buf = GIT_BUF_INIT; /* tests/resources/attr/root_test1 */ - cl_git_pass(git_oid_fromstrn(&a_oid, "45141a79", 8)); + cl_git_pass(git_oid__fromstrn(&a_oid, "45141a79", 8, GIT_OID_SHA1)); cl_git_pass(git_blob_lookup_prefix(&a, g_repo, &a_oid, 4)); /* tests/resources/attr/root_test2 */ - cl_git_pass(git_oid_fromstrn(&b_oid, "4d713dc4", 8)); + cl_git_pass(git_oid__fromstrn(&b_oid, "4d713dc4", 8, GIT_OID_SHA1)); cl_git_pass(git_blob_lookup_prefix(&b, g_repo, &b_oid, 4)); cl_git_pass(git_patch_from_blobs(&p, a, NULL, b, NULL, NULL)); @@ -110,15 +110,15 @@ void test_diff_blob__can_compare_text_blobs(void) git_oid a_oid, b_oid, c_oid; /* tests/resources/attr/root_test1 */ - cl_git_pass(git_oid_fromstrn(&a_oid, "45141a79", 8)); + cl_git_pass(git_oid__fromstrn(&a_oid, "45141a79", 8, GIT_OID_SHA1)); cl_git_pass(git_blob_lookup_prefix(&a, g_repo, &a_oid, 4)); /* tests/resources/attr/root_test2 */ - cl_git_pass(git_oid_fromstrn(&b_oid, "4d713dc4", 8)); + cl_git_pass(git_oid__fromstrn(&b_oid, "4d713dc4", 8, GIT_OID_SHA1)); cl_git_pass(git_blob_lookup_prefix(&b, g_repo, &b_oid, 4)); /* tests/resources/attr/root_test3 */ - cl_git_pass(git_oid_fromstrn(&c_oid, "c96bbb2c2557a832", 16)); + cl_git_pass(git_oid__fromstrn(&c_oid, "c96bbb2c2557a832", 16, GIT_OID_SHA1)); cl_git_pass(git_blob_lookup_prefix(&c, g_repo, &c_oid, 16)); /* Doing the equivalent of a `git diff -U1` on these files */ @@ -201,15 +201,15 @@ void test_diff_blob__can_compare_text_blobs_with_patch(void) git_patch *p; /* tests/resources/attr/root_test1 */ - cl_git_pass(git_oid_fromstrn(&a_oid, "45141a79", 8)); + cl_git_pass(git_oid__fromstrn(&a_oid, "45141a79", 8, GIT_OID_SHA1)); cl_git_pass(git_blob_lookup_prefix(&a, g_repo, &a_oid, 8)); /* tests/resources/attr/root_test2 */ - cl_git_pass(git_oid_fromstrn(&b_oid, "4d713dc4", 8)); + cl_git_pass(git_oid__fromstrn(&b_oid, "4d713dc4", 8, GIT_OID_SHA1)); cl_git_pass(git_blob_lookup_prefix(&b, g_repo, &b_oid, 8)); /* tests/resources/attr/root_test3 */ - cl_git_pass(git_oid_fromstrn(&c_oid, "c96bbb2c2557a832", 16)); + cl_git_pass(git_oid__fromstrn(&c_oid, "c96bbb2c2557a832", 16, GIT_OID_SHA1)); cl_git_pass(git_blob_lookup_prefix(&c, g_repo, &c_oid, 16)); /* Doing the equivalent of a `git diff -U1` on these files */ @@ -475,7 +475,7 @@ void test_diff_blob__can_compare_two_binary_blobs(void) git_oid h_oid; /* heart.png */ - cl_git_pass(git_oid_fromstrn(&h_oid, "de863bff", 8)); + cl_git_pass(git_oid__fromstrn(&h_oid, "de863bff", 8, GIT_OID_SHA1)); cl_git_pass(git_blob_lookup_prefix(&heart, g_repo, &h_oid, 8)); cl_git_pass(git_diff_blobs( @@ -543,7 +543,7 @@ void test_diff_blob__comparing_two_text_blobs_honors_interhunkcontext(void) opts.context_lines = 3; /* tests/resources/attr/root_test1 from commit f5b0af1 */ - cl_git_pass(git_oid_fromstrn(&old_d_oid, "fe773770", 8)); + cl_git_pass(git_oid__fromstrn(&old_d_oid, "fe773770", 8, GIT_OID_SHA1)); cl_git_pass(git_blob_lookup_prefix(&old_d, g_repo, &old_d_oid, 8)); /* Test with default inter-hunk-context (not set) => default is 0 */ @@ -652,7 +652,7 @@ void test_diff_blob__can_compare_blob_to_buffer(void) const char *b_content = "Hello from the root\n\nSome additional lines\n\nDown here below\n\n"; /* tests/resources/attr/root_test1 */ - cl_git_pass(git_oid_fromstrn(&a_oid, "45141a79", 8)); + cl_git_pass(git_oid__fromstrn(&a_oid, "45141a79", 8, GIT_OID_SHA1)); cl_git_pass(git_blob_lookup_prefix(&a, g_repo, &a_oid, 8)); /* diff from blob a to content of b */ @@ -694,7 +694,7 @@ void test_diff_blob__can_compare_blob_to_buffer_with_patch(void) size_t tc, ta, td; /* tests/resources/attr/root_test1 */ - cl_git_pass(git_oid_fromstrn(&a_oid, "45141a79", 8)); + cl_git_pass(git_oid__fromstrn(&a_oid, "45141a79", 8, GIT_OID_SHA1)); cl_git_pass(git_blob_lookup_prefix(&a, g_repo, &a_oid, 8)); /* diff from blob a to content of b */ @@ -773,10 +773,10 @@ void test_diff_blob__binary_data_comparisons(void) opts.flags |= GIT_DIFF_INCLUDE_UNMODIFIED; - cl_git_pass(git_oid_fromstrn(&oid, "45141a79", 8)); + cl_git_pass(git_oid__fromstrn(&oid, "45141a79", 8, GIT_OID_SHA1)); cl_git_pass(git_blob_lookup_prefix(&nonbin, g_repo, &oid, 8)); - cl_git_pass(git_oid_fromstrn(&oid, "b435cd56", 8)); + cl_git_pass(git_oid__fromstrn(&oid, "b435cd56", 8, GIT_OID_SHA1)); cl_git_pass(git_blob_lookup_prefix(&bin, g_repo, &oid, 8)); /* non-binary to reference content */ @@ -879,11 +879,11 @@ void test_diff_blob__using_path_and_attributes(void) opts.context_lines = 0; opts.flags |= GIT_DIFF_INCLUDE_UNMODIFIED; - cl_git_pass(git_oid_fromstrn(&oid, "45141a79", 8)); + cl_git_pass(git_oid__fromstrn(&oid, "45141a79", 8, GIT_OID_SHA1)); cl_git_pass(git_blob_lookup_prefix(&nonbin, g_repo, &oid, 8)); /* 20b: "Hello from the root\n" */ - cl_git_pass(git_oid_fromstrn(&oid, "b435cd56", 8)); + cl_git_pass(git_oid__fromstrn(&oid, "b435cd56", 8, GIT_OID_SHA1)); cl_git_pass(git_blob_lookup_prefix(&bin, g_repo, &oid, 8)); /* 33b: "0123456789\n\x01\x02\x03\x04\x05\x06\x07\x08\x09\n0123456789\n" */ diff --git a/tests/libgit2/diff/diff_helpers.c b/tests/libgit2/diff/diff_helpers.c index e9900339f..341b0a448 100644 --- a/tests/libgit2/diff/diff_helpers.c +++ b/tests/libgit2/diff/diff_helpers.c @@ -11,7 +11,7 @@ git_tree *resolve_commit_oid_to_tree( git_object *obj = NULL; git_tree *tree = NULL; - if (git_oid_fromstrn(&oid, partial_oid, len) == 0) + if (git_oid__fromstrn(&oid, partial_oid, len, GIT_OID_SHA1) == 0) cl_git_pass(git_object_lookup_prefix(&obj, repo, &oid, len, GIT_OBJECT_ANY)); cl_git_pass(git_object_peel((git_object **) &tree, obj, GIT_OBJECT_TREE)); diff --git a/tests/libgit2/diff/format_email.c b/tests/libgit2/diff/format_email.c index 612804c42..2726edb0d 100644 --- a/tests/libgit2/diff/format_email.c +++ b/tests/libgit2/diff/format_email.c @@ -28,7 +28,7 @@ static void assert_email_match( git_diff *diff = NULL; git_buf buf = GIT_BUF_INIT; - git_oid_fromstr(&oid, oidstr); + git_oid__fromstr(&oid, oidstr, GIT_OID_SHA1); cl_git_pass(git_commit_lookup(&commit, repo, &oid)); @@ -228,7 +228,7 @@ void test_diff_format_email__multiple(void) "\n"; - git_oid_fromstr(&oid, "10808fe9c9be5a190c0ba68d1a002233fb363508"); + git_oid__fromstr(&oid, "10808fe9c9be5a190c0ba68d1a002233fb363508", GIT_OID_SHA1); cl_git_pass(git_commit_lookup(&commit, repo, &oid)); opts.id = git_commit_id(commit); @@ -245,7 +245,7 @@ void test_diff_format_email__multiple(void) diff = NULL; commit = NULL; - git_oid_fromstr(&oid, "873806f6f27e631eb0b23e4b56bea2bfac14a373"); + git_oid__fromstr(&oid, "873806f6f27e631eb0b23e4b56bea2bfac14a373", GIT_OID_SHA1); cl_git_pass(git_commit_lookup(&commit, repo, &oid)); opts.id = git_commit_id(commit); @@ -324,7 +324,7 @@ void test_diff_format_email__invalid_no(void) git_diff_format_email_options opts = GIT_DIFF_FORMAT_EMAIL_OPTIONS_INIT; git_buf buf = GIT_BUF_INIT; - git_oid_fromstr(&oid, "9264b96c6d104d0e07ae33d3007b6a48246c6f92"); + git_oid__fromstr(&oid, "9264b96c6d104d0e07ae33d3007b6a48246c6f92", GIT_OID_SHA1); cl_git_pass(git_commit_lookup(&commit, repo, &oid)); diff --git a/tests/libgit2/diff/index.c b/tests/libgit2/diff/index.c index b616a372b..5773b748e 100644 --- a/tests/libgit2/diff/index.c +++ b/tests/libgit2/diff/index.c @@ -185,9 +185,9 @@ static void do_conflicted_diff(diff_expects *exp, unsigned long flags) ancestor.path = ours.path = theirs.path = "staged_changes"; ancestor.mode = ours.mode = theirs.mode = GIT_FILEMODE_BLOB; - git_oid_fromstr(&ancestor.id, "d427e0b2e138501a3d15cc376077a3631e15bd46"); - git_oid_fromstr(&ours.id, "ee3fa1b8c00aff7fe02065fdb50864bb0d932ccf"); - git_oid_fromstr(&theirs.id, "2bd0a343aeef7a2cf0d158478966a6e587ff3863"); + git_oid__fromstr(&ancestor.id, "d427e0b2e138501a3d15cc376077a3631e15bd46", GIT_OID_SHA1); + git_oid__fromstr(&ours.id, "ee3fa1b8c00aff7fe02065fdb50864bb0d932ccf", GIT_OID_SHA1); + git_oid__fromstr(&theirs.id, "2bd0a343aeef7a2cf0d158478966a6e587ff3863", GIT_OID_SHA1); cl_git_pass(git_index_conflict_add(index, &ancestor, &ours, &theirs)); cl_git_pass(git_diff_tree_to_index(&diff, g_repo, a, index, &opts)); @@ -255,7 +255,7 @@ void test_diff_index__not_in_head_conflicted(void) theirs.path = "file_not_in_head"; theirs.mode = GIT_FILEMODE_BLOB; - git_oid_fromstr(&theirs.id, "2bd0a343aeef7a2cf0d158478966a6e587ff3863"); + git_oid__fromstr(&theirs.id, "2bd0a343aeef7a2cf0d158478966a6e587ff3863", GIT_OID_SHA1); cl_git_pass(git_index_conflict_add(index, NULL, NULL, &theirs)); cl_git_pass(git_diff_tree_to_index(&diff, g_repo, a, index, NULL)); diff --git a/tests/libgit2/diff/parse.c b/tests/libgit2/diff/parse.c index 9c3f798e4..cae843cc8 100644 --- a/tests/libgit2/diff/parse.c +++ b/tests/libgit2/diff/parse.c @@ -151,7 +151,7 @@ static void test_tree_to_tree_computed_to_parsed( repo = cl_git_sandbox_init(sandbox); - opts.id_abbrev = GIT_OID_HEXSZ; + opts.id_abbrev = GIT_OID_SHA1_HEXSIZE; opts.flags = GIT_DIFF_SHOW_BINARY | diff_flags; findopts.flags = find_flags; diff --git a/tests/libgit2/diff/patchid.c b/tests/libgit2/diff/patchid.c index 621a720f7..1cc368e21 100644 --- a/tests/libgit2/diff/patchid.c +++ b/tests/libgit2/diff/patchid.c @@ -6,7 +6,7 @@ static void verify_patch_id(const char *diff_content, const char *expected_id) git_oid expected_oid, actual_oid; git_diff *diff; - cl_git_pass(git_oid_fromstr(&expected_oid, expected_id)); + cl_git_pass(git_oid__fromstr(&expected_oid, expected_id, GIT_OID_SHA1)); cl_git_pass(git_diff_from_buffer(&diff, diff_content, strlen(diff_content))); cl_git_pass(git_diff_patchid(&actual_oid, diff, NULL)); diff --git a/tests/libgit2/diff/rename.c b/tests/libgit2/diff/rename.c index 30e9ea432..9d4439462 100644 --- a/tests/libgit2/diff/rename.c +++ b/tests/libgit2/diff/rename.c @@ -574,7 +574,7 @@ void test_diff_rename__working_directory_changes(void) /* again with exact match blob */ - cl_git_pass(git_oid_fromstr(&id, blobsha)); + cl_git_pass(git_oid__fromstr(&id, blobsha, GIT_OID_SHA1)); cl_git_pass(git_blob_lookup(&blob, g_repo, &id)); cl_git_pass(git_str_set( &content, git_blob_rawcontent(blob), (size_t)git_blob_rawsize(blob))); diff --git a/tests/libgit2/diff/stats.c b/tests/libgit2/diff/stats.c index f69dba9b3..b076ad5a9 100644 --- a/tests/libgit2/diff/stats.c +++ b/tests/libgit2/diff/stats.c @@ -26,7 +26,7 @@ static void diff_stats_from_commit_oid( git_commit *commit; git_diff *diff; - git_oid_fromstr(&oid, oidstr); + git_oid__fromstr(&oid, oidstr, GIT_OID_SHA1); cl_git_pass(git_commit_lookup(&commit, _repo, &oid)); cl_git_pass(git_diff__commit(&diff, _repo, commit, NULL)); if (rename) diff --git a/tests/libgit2/diff/workdir.c b/tests/libgit2/diff/workdir.c index 20e000906..21c5b0de9 100644 --- a/tests/libgit2/diff/workdir.c +++ b/tests/libgit2/diff/workdir.c @@ -86,11 +86,11 @@ void test_diff_workdir__to_index_with_conflicts(void) /* Adding an entry that represents a rename gets two files in conflict */ our_entry.path = "subdir/modified_file"; our_entry.mode = 0100644; - git_oid_fromstr(&our_entry.id, "ee3fa1b8c00aff7fe02065fdb50864bb0d932ccf"); + git_oid__fromstr(&our_entry.id, "ee3fa1b8c00aff7fe02065fdb50864bb0d932ccf", GIT_OID_SHA1); their_entry.path = "subdir/rename_conflict"; their_entry.mode = 0100644; - git_oid_fromstr(&their_entry.id, "2bd0a343aeef7a2cf0d158478966a6e587ff3863"); + git_oid__fromstr(&their_entry.id, "2bd0a343aeef7a2cf0d158478966a6e587ff3863", GIT_OID_SHA1); cl_git_pass(git_repository_index(&index, g_repo)); cl_git_pass(git_index_conflict_add(index, NULL, &our_entry, &their_entry)); @@ -1232,6 +1232,42 @@ void test_diff_workdir__checks_options_version(void) cl_assert_equal_i(GIT_ERROR_INVALID, err->klass); } +void test_diff_workdir__can_diff_empty_untracked_file(void) +{ + git_diff_options opts = GIT_DIFF_OPTIONS_INIT; + git_diff *diff = NULL; + git_patch *patch = NULL; + + g_repo = cl_git_sandbox_init("empty_standard_repo"); + + cl_git_mkfile("empty_standard_repo/emptyfile.txt", ""); + + opts.context_lines = 3; + opts.interhunk_lines = 1; + opts.flags |= GIT_DIFF_INCLUDE_UNTRACKED | GIT_DIFF_SHOW_UNTRACKED_CONTENT; + + cl_git_pass(git_diff_index_to_workdir(&diff, g_repo, NULL, &opts)); + + /* without filters */ + git_patch_from_diff(&patch, diff, 0); + cl_assert(NULL != patch); + cl_assert(0 == git_patch_get_delta(patch)->new_file.size); + cl_assert(0 == strcmp("emptyfile.txt", git_patch_get_delta(patch)->new_file.path)); + git_patch_free(patch); + patch = NULL; + + /* with a filter */ + cl_repo_set_bool(g_repo, "core.autocrlf", true); /* install some filter */ + git_patch_from_diff(&patch, diff, 0); + cl_assert(NULL != patch); + cl_assert(0 == git_patch_get_delta(patch)->new_file.size); + cl_assert(0 == strcmp("emptyfile.txt", git_patch_get_delta(patch)->new_file.path)); + git_patch_free(patch); + patch = NULL; + + git_diff_free(diff); +} + void test_diff_workdir__can_diff_empty_file(void) { git_diff *diff; @@ -1979,9 +2015,9 @@ void test_diff_workdir__to_index_conflicted(void) { ancestor.path = ours.path = theirs.path = "_file"; ancestor.mode = ours.mode = theirs.mode = 0100644; - git_oid_fromstr(&ancestor.id, "d427e0b2e138501a3d15cc376077a3631e15bd46"); - git_oid_fromstr(&ours.id, "ee3fa1b8c00aff7fe02065fdb50864bb0d932ccf"); - git_oid_fromstr(&theirs.id, "2bd0a343aeef7a2cf0d158478966a6e587ff3863"); + git_oid__fromstr(&ancestor.id, "d427e0b2e138501a3d15cc376077a3631e15bd46", GIT_OID_SHA1); + git_oid__fromstr(&ours.id, "ee3fa1b8c00aff7fe02065fdb50864bb0d932ccf", GIT_OID_SHA1); + git_oid__fromstr(&theirs.id, "2bd0a343aeef7a2cf0d158478966a6e587ff3863", GIT_OID_SHA1); cl_git_pass(git_index_conflict_add(index, &ancestor, &ours, &theirs)); cl_git_pass(git_diff_tree_to_index(&diff1, g_repo, a, index, NULL)); diff --git a/tests/libgit2/email/create.c b/tests/libgit2/email/create.c index 27a665582..cf40ff552 100644 --- a/tests/libgit2/email/create.c +++ b/tests/libgit2/email/create.c @@ -24,7 +24,7 @@ static void email_for_commit( git_commit *commit = NULL; git_diff *diff = NULL; - git_oid_fromstr(&oid, commit_id); + git_oid__fromstr(&oid, commit_id, GIT_OID_SHA1); cl_git_pass(git_commit_lookup(&commit, repo, &oid)); @@ -323,7 +323,7 @@ void test_email_create__custom_summary_and_body(void) opts.subject_prefix = "PPPPPATCH"; - git_oid_fromstr(&oid, "627e7e12d87e07a83fad5b6bfa25e86ead4a5270"); + git_oid__fromstr(&oid, "627e7e12d87e07a83fad5b6bfa25e86ead4a5270", GIT_OID_SHA1); cl_git_pass(git_commit_lookup(&commit, repo, &oid)); cl_git_pass(git_diff__commit(&diff, repo, commit, NULL)); cl_git_pass(git_email_create_from_diff(&buf, diff, 2, 4, &oid, summary, body, git_commit_author(commit), &opts)); diff --git a/tests/libgit2/email/create.c.bak b/tests/libgit2/email/create.c.bak deleted file mode 100644 index 3bb95a6f6..000000000 --- a/tests/libgit2/email/create.c.bak +++ /dev/null @@ -1,386 +0,0 @@ -#include "clar.h" -#include "clar_libgit2.h" - -#include "buffer.h" -#include "diff_generate.h" - -static git_repository *repo; - -void test_email_create__initialize(void) -{ - repo = cl_git_sandbox_init("diff_format_email"); -} - -void test_email_create__cleanup(void) -{ - cl_git_sandbox_cleanup(); -} - -static void email_for_commit( - git_buf *out, - const char *commit_id, - git_email_create_options *opts) -{ - git_oid oid; - git_commit *commit = NULL; - git_diff *diff = NULL; - - git_oid_fromstr(&oid, commit_id); - - cl_git_pass(git_commit_lookup(&commit, repo, &oid)); - - cl_git_pass(git_email_create_from_commit(out, commit, opts)); - - git_diff_free(diff); - git_commit_free(commit); -} - -static void assert_email_match( - const char *expected, - const char *commit_id, - git_email_create_options *opts) -{ - git_buf buf = GIT_BUF_INIT; - - email_for_commit(&buf, commit_id, opts); - cl_assert_equal_s(expected, git_buf_cstr(&buf)); - - git_buf_dispose(&buf); -} - -static void assert_subject_match( - const char *expected, - const char *commit_id, - git_email_create_options *opts) -{ - git_buf buf = GIT_BUF_INIT; - const char *loc; - - email_for_commit(&buf, commit_id, opts); - - cl_assert((loc = strstr(buf.ptr, "\nSubject: ")) != NULL); - git_buf_consume(&buf, (loc + 10)); - git_buf_truncate_at_char(&buf, '\n'); - - cl_assert_equal_s(expected, git_buf_cstr(&buf)); - - git_buf_dispose(&buf); -} - -void test_email_create__commit(void) -{ - const char *expected = - "From 9264b96c6d104d0e07ae33d3007b6a48246c6f92 Mon Sep 17 00:00:00 2001\n" \ - "From: Jacques Germishuys \n" \ - "Date: Wed, 9 Apr 2014 20:57:01 +0200\n" \ - "Subject: [PATCH] Modify some content\n" \ - "\n" \ - "---\n" \ - " file1.txt | 8 +++++---\n" \ - " 1 file changed, 5 insertions(+), 3 deletions(-)\n" \ - "\n" \ - "diff --git a/file1.txt b/file1.txt\n" \ - "index 94aaae8..af8f41d 100644\n" \ - "--- a/file1.txt\n" \ - "+++ b/file1.txt\n" \ - "@@ -1,15 +1,17 @@\n" \ - " file1.txt\n" \ - " file1.txt\n" \ - "+_file1.txt_\n" \ - " file1.txt\n" \ - " file1.txt\n" \ - " file1.txt\n" \ - " file1.txt\n" \ - "+\n" \ - "+\n" \ - " file1.txt\n" \ - " file1.txt\n" \ - " file1.txt\n" \ - " file1.txt\n" \ - " file1.txt\n" \ - "-file1.txt\n" \ - "-file1.txt\n" \ - "-file1.txt\n" \ - "+_file1.txt_\n" \ - "+_file1.txt_\n" \ - " file1.txt\n" \ - "--\n" \ - "libgit2 " LIBGIT2_VERSION "\n" \ - "\n"; - - assert_email_match( - expected, "9264b96c6d104d0e07ae33d3007b6a48246c6f92", NULL); -} - -void test_email_create__custom_summary_and_body(void) -{ - const char *expected = "From 627e7e12d87e07a83fad5b6bfa25e86ead4a5270 Mon Sep 17 00:00:00 2001\n" \ - "From: Patrick Steinhardt \n" \ - "Date: Tue, 24 Nov 2015 13:34:39 +0100\n" \ - "Subject: [PPPPPATCH 2/4] This is a subject\n" \ - "\n" \ - "Modify content of file3.txt by appending a new line. Make this\n" \ - "commit message somewhat longer to test behavior with newlines\n" \ - "embedded in the message body.\n" \ - "\n" \ - "Also test if new paragraphs are included correctly.\n" \ - "---\n" \ - " file3.txt | 1 +\n" \ - " 1 file changed, 1 insertion(+)\n" \ - "\n" \ - "diff --git a/file3.txt b/file3.txt\n" \ - "index 9a2d780..7309653 100644\n" \ - "--- a/file3.txt\n" \ - "+++ b/file3.txt\n" \ - "@@ -3,3 +3,4 @@ file3!\n" \ - " file3\n" \ - " file3\n" \ - " file3\n" \ - "+file3\n" \ - "--\n" \ - "libgit2 " LIBGIT2_VERSION "\n" \ - "\n"; - - const char *summary = "This is a subject\nwith\nnewlines"; - const char *body = "Modify content of file3.txt by appending a new line. Make this\n" \ - "commit message somewhat longer to test behavior with newlines\n" \ - "embedded in the message body.\n" \ - "\n" \ - "Also test if new paragraphs are included correctly."; - - git_oid oid; - git_commit *commit = NULL; - git_diff *diff = NULL; - git_buf buf = GIT_BUF_INIT; - git_email_create_options opts = GIT_EMAIL_CREATE_OPTIONS_INIT; - - opts.subject_prefix = "PPPPPATCH"; - - git_oid_fromstr(&oid, "627e7e12d87e07a83fad5b6bfa25e86ead4a5270"); - cl_git_pass(git_commit_lookup(&commit, repo, &oid)); - cl_git_pass(git_diff__commit(&diff, repo, commit, NULL)); - cl_git_pass(git_email_create_from_diff(&buf, diff, 2, 4, &oid, summary, body, git_commit_author(commit), &opts)); - - cl_assert_equal_s(expected, git_buf_cstr(&buf)); - - git_diff_free(diff); - git_commit_free(commit); - git_buf_dispose(&buf); -} - -void test_email_create__mode_change(void) -{ - const char *expected = - "From 7ade76dd34bba4733cf9878079f9fd4a456a9189 Mon Sep 17 00:00:00 2001\n" \ - "From: Jacques Germishuys \n" \ - "Date: Thu, 10 Apr 2014 10:05:03 +0200\n" \ - "Subject: [PATCH] Update permissions\n" \ - "\n" \ - "---\n" \ - " file1.txt.renamed | 0\n" \ - " 1 file changed, 0 insertions(+), 0 deletions(-)\n" \ - " mode change 100644 => 100755 file1.txt.renamed\n" \ - "\n" \ - "diff --git a/file1.txt.renamed b/file1.txt.renamed\n" \ - "old mode 100644\n" \ - "new mode 100755\n" \ - "--\n" \ - "libgit2 " LIBGIT2_VERSION "\n" \ - "\n"; - - assert_email_match(expected, "7ade76dd34bba4733cf9878079f9fd4a456a9189", NULL); -} - -void test_email_create__rename(void) -{ - const char *expected = - "From 6e05acc5a5dab507d91a0a0cc0fb05a3dd98892d Mon Sep 17 00:00:00 2001\n" \ - "From: Jacques Germishuys \n" \ - "Date: Wed, 9 Apr 2014 21:15:56 +0200\n" \ - "Subject: [PATCH] Renamed file1.txt -> file1.txt.renamed\n" \ - "\n" \ - "---\n" \ - " file1.txt => file1.txt.renamed | 4 ++--\n" \ - " 1 file changed, 2 insertions(+), 2 deletions(-)\n" \ - "\n" \ - "diff --git a/file1.txt b/file1.txt.renamed\n" \ - "similarity index 86%\n" \ - "rename from file1.txt\n" \ - "rename to file1.txt.renamed\n" \ - "index af8f41d..a97157a 100644\n" \ - "--- a/file1.txt\n" \ - "+++ b/file1.txt.renamed\n" \ - "@@ -3,13 +3,13 @@ file1.txt\n" \ - " _file1.txt_\n" \ - " file1.txt\n" \ - " file1.txt\n" \ - "-file1.txt\n" \ - "+file1.txt_renamed\n" \ - " file1.txt\n" \ - " \n" \ - " \n" \ - " file1.txt\n" \ - " file1.txt\n" \ - "-file1.txt\n" \ - "+file1.txt_renamed\n" \ - " file1.txt\n" \ - " file1.txt\n" \ - " _file1.txt_\n" \ - "--\n" \ - "libgit2 " LIBGIT2_VERSION "\n" \ - "\n"; - - assert_email_match(expected, "6e05acc5a5dab507d91a0a0cc0fb05a3dd98892d", NULL); -} - -void test_email_create__rename_as_add_delete(void) -{ - const char *expected = - "From 6e05acc5a5dab507d91a0a0cc0fb05a3dd98892d Mon Sep 17 00:00:00 2001\n" \ - "From: Jacques Germishuys \n" \ - "Date: Wed, 9 Apr 2014 21:15:56 +0200\n" \ - "Subject: [PATCH] Renamed file1.txt -> file1.txt.renamed\n" \ - "\n" \ - "---\n" \ - " file1.txt | 17 -----------------\n" \ - " file1.txt.renamed | 17 +++++++++++++++++\n" \ - " 2 files changed, 17 insertions(+), 17 deletions(-)\n" \ - " delete mode 100644 file1.txt\n" \ - " create mode 100644 file1.txt.renamed\n" \ - "\n" \ - "diff --git a/file1.txt b/file1.txt\n" \ - "deleted file mode 100644\n" \ - "index af8f41d..0000000\n" \ - "--- a/file1.txt\n" \ - "+++ /dev/null\n" \ - "@@ -1,17 +0,0 @@\n" \ - "-file1.txt\n" \ - "-file1.txt\n" \ - "-_file1.txt_\n" \ - "-file1.txt\n" \ - "-file1.txt\n" \ - "-file1.txt\n" \ - "-file1.txt\n" \ - "-\n" \ - "-\n" \ - "-file1.txt\n" \ - "-file1.txt\n" \ - "-file1.txt\n" \ - "-file1.txt\n" \ - "-file1.txt\n" \ - "-_file1.txt_\n" \ - "-_file1.txt_\n" \ - "-file1.txt\n" \ - "diff --git a/file1.txt.renamed b/file1.txt.renamed\n" \ - "new file mode 100644\n" \ - "index 0000000..a97157a\n" \ - "--- /dev/null\n" \ - "+++ b/file1.txt.renamed\n" \ - "@@ -0,0 +1,17 @@\n" \ - "+file1.txt\n" \ - "+file1.txt\n" \ - "+_file1.txt_\n" \ - "+file1.txt\n" \ - "+file1.txt\n" \ - "+file1.txt_renamed\n" \ - "+file1.txt\n" \ - "+\n" \ - "+\n" \ - "+file1.txt\n" \ - "+file1.txt\n" \ - "+file1.txt_renamed\n" \ - "+file1.txt\n" \ - "+file1.txt\n" \ - "+_file1.txt_\n" \ - "+_file1.txt_\n" \ - "+file1.txt\n" \ - "--\n" \ - "libgit2 " LIBGIT2_VERSION "\n" \ - "\n"; - - git_email_create_options opts = GIT_EMAIL_CREATE_OPTIONS_INIT; - opts.flags |= GIT_EMAIL_CREATE_NO_RENAMES; - - assert_email_match(expected, "6e05acc5a5dab507d91a0a0cc0fb05a3dd98892d", &opts); -} - -void test_email_create__binary(void) -{ - const char *expected = - "From 8d7523f6fcb2404257889abe0d96f093d9f524f9 Mon Sep 17 00:00:00 2001\n" \ - "From: Jacques Germishuys \n" \ - "Date: Sun, 13 Apr 2014 18:10:18 +0200\n" \ - "Subject: [PATCH] Modified binary file\n" \ - "\n" \ - "---\n" \ - " binary.bin | Bin 3 -> 5 bytes\n" \ - " 1 file changed, 0 insertions(+), 0 deletions(-)\n" \ - "\n" \ - "diff --git a/binary.bin b/binary.bin\n" \ - "index bd474b2519cc15eab801ff851cc7d50f0dee49a1..9ac35ff15cd8864aeafd889e4826a3150f0b06c4 100644\n" \ - "GIT binary patch\n" \ - "literal 5\n" \ - "Mc${NkU}WL~000&M4gdfE\n" \ - "\n" \ - "literal 3\n" \ - "Kc${Nk-~s>u4FC%O\n" \ - "\n" \ - "--\n" \ - "libgit2 " LIBGIT2_VERSION "\n" \ - "\n"; - - assert_email_match(expected, "8d7523f6fcb2404257889abe0d96f093d9f524f9", NULL); -} - -void test_email_create__binary_not_included(void) -{ - const char *expected = - "From 8d7523f6fcb2404257889abe0d96f093d9f524f9 Mon Sep 17 00:00:00 2001\n" \ - "From: Jacques Germishuys \n" \ - "Date: Sun, 13 Apr 2014 18:10:18 +0200\n" \ - "Subject: [PATCH] Modified binary file\n" \ - "\n" \ - "---\n" \ - " binary.bin | Bin 3 -> 5 bytes\n" \ - " 1 file changed, 0 insertions(+), 0 deletions(-)\n" \ - "\n" \ - "diff --git a/binary.bin b/binary.bin\n" \ - "index bd474b2..9ac35ff 100644\n" \ - "Binary files a/binary.bin and b/binary.bin differ\n" \ - "--\n" \ - "libgit2 " LIBGIT2_VERSION "\n" \ - "\n"; - - git_email_create_options opts = GIT_EMAIL_CREATE_OPTIONS_INIT; - opts.diff_opts.flags &= ~GIT_DIFF_SHOW_BINARY; - - assert_email_match(expected, "8d7523f6fcb2404257889abe0d96f093d9f524f9", &opts); -} - -void test_email_create__commit_subjects(void) -{ - git_email_create_options opts = GIT_EMAIL_CREATE_OPTIONS_INIT; - - assert_subject_match("[PATCH] Modify some content", "9264b96c6d104d0e07ae33d3007b6a48246c6f92", &opts); - - opts.reroll_number = 42; - assert_subject_match("[PATCH v42] Modify some content", "9264b96c6d104d0e07ae33d3007b6a48246c6f92", &opts); - - opts.flags |= GIT_EMAIL_CREATE_ALWAYS_NUMBER; - assert_subject_match("[PATCH v42 1/1] Modify some content", "9264b96c6d104d0e07ae33d3007b6a48246c6f92", &opts); - - opts.start_number = 9; - assert_subject_match("[PATCH v42 9/9] Modify some content", "9264b96c6d104d0e07ae33d3007b6a48246c6f92", &opts); - - opts.subject_prefix = ""; - assert_subject_match("[v42 9/9] Modify some content", "9264b96c6d104d0e07ae33d3007b6a48246c6f92", &opts); - - opts.reroll_number = 0; - assert_subject_match("[9/9] Modify some content", "9264b96c6d104d0e07ae33d3007b6a48246c6f92", &opts); - - opts.start_number = 0; - assert_subject_match("[1/1] Modify some content", "9264b96c6d104d0e07ae33d3007b6a48246c6f92", &opts); - - opts.flags = GIT_EMAIL_CREATE_OMIT_NUMBERS; - assert_subject_match("Modify some content", "9264b96c6d104d0e07ae33d3007b6a48246c6f92", &opts); -} diff --git a/tests/libgit2/fetch/local.c b/tests/libgit2/fetch/local.c index 20bd7adf4..5d2417f1c 100644 --- a/tests/libgit2/fetch/local.c +++ b/tests/libgit2/fetch/local.c @@ -26,7 +26,7 @@ void test_fetch_local__defaults(void) cl_fixture("testrepo.git"))); cl_git_pass(git_remote_fetch(remote, NULL, NULL, NULL)); - git_oid_fromstr(&expected_id, "258f0e2a959a364e40ed6603d5d44fbb24765b10"); + git_oid__fromstr(&expected_id, "258f0e2a959a364e40ed6603d5d44fbb24765b10", GIT_OID_SHA1); cl_git_pass(git_revparse_single(&obj, repo, "refs/remotes/test/haacked")); cl_assert_equal_oid(&expected_id, git_object_id(obj)); @@ -47,7 +47,7 @@ void test_fetch_local__reachable_commit(void) refspecs.strings = &refspec; refspecs.count = 1; - git_oid_fromstr(&expected_id, "5b5b025afb0b4c913b4c338a42934a3863bf3644"); + git_oid__fromstr(&expected_id, "5b5b025afb0b4c913b4c338a42934a3863bf3644", GIT_OID_SHA1); cl_git_pass(git_remote_create(&remote, repo, "test", cl_fixture("testrepo.git"))); diff --git a/tests/libgit2/fetchhead/nonetwork.c b/tests/libgit2/fetchhead/nonetwork.c index aadcc7880..2519d895e 100644 --- a/tests/libgit2/fetchhead/nonetwork.c +++ b/tests/libgit2/fetchhead/nonetwork.c @@ -29,43 +29,49 @@ static void populate_fetchhead(git_vector *out, git_repository *repo) git_fetchhead_ref *fetchhead_ref; git_oid oid; - cl_git_pass(git_oid_fromstr(&oid, - "49322bb17d3acc9146f98c97d078513228bbf3c0")); + cl_git_pass(git_oid__fromstr(&oid, + "49322bb17d3acc9146f98c97d078513228bbf3c0", + GIT_OID_SHA1)); cl_git_pass(git_fetchhead_ref_create(&fetchhead_ref, &oid, 1, "refs/heads/master", "https://github.com/libgit2/TestGitRepository")); cl_git_pass(git_vector_insert(out, fetchhead_ref)); - cl_git_pass(git_oid_fromstr(&oid, - "0966a434eb1a025db6b71485ab63a3bfbea520b6")); + cl_git_pass(git_oid__fromstr(&oid, + "0966a434eb1a025db6b71485ab63a3bfbea520b6", + GIT_OID_SHA1)); cl_git_pass(git_fetchhead_ref_create(&fetchhead_ref, &oid, 0, "refs/heads/first-merge", "https://github.com/libgit2/TestGitRepository")); cl_git_pass(git_vector_insert(out, fetchhead_ref)); - cl_git_pass(git_oid_fromstr(&oid, - "42e4e7c5e507e113ebbb7801b16b52cf867b7ce1")); + cl_git_pass(git_oid__fromstr(&oid, + "42e4e7c5e507e113ebbb7801b16b52cf867b7ce1", + GIT_OID_SHA1)); cl_git_pass(git_fetchhead_ref_create(&fetchhead_ref, &oid, 0, "refs/heads/no-parent", "https://github.com/libgit2/TestGitRepository")); cl_git_pass(git_vector_insert(out, fetchhead_ref)); - cl_git_pass(git_oid_fromstr(&oid, - "d96c4e80345534eccee5ac7b07fc7603b56124cb")); + cl_git_pass(git_oid__fromstr(&oid, + "d96c4e80345534eccee5ac7b07fc7603b56124cb", + GIT_OID_SHA1)); cl_git_pass(git_fetchhead_ref_create(&fetchhead_ref, &oid, 0, "refs/tags/annotated_tag", "https://github.com/libgit2/TestGitRepository")); cl_git_pass(git_vector_insert(out, fetchhead_ref)); - cl_git_pass(git_oid_fromstr(&oid, - "55a1a760df4b86a02094a904dfa511deb5655905")); + cl_git_pass(git_oid__fromstr(&oid, + "55a1a760df4b86a02094a904dfa511deb5655905", + GIT_OID_SHA1)); cl_git_pass(git_fetchhead_ref_create(&fetchhead_ref, &oid, 0, "refs/tags/blob", "https://github.com/libgit2/TestGitRepository")); cl_git_pass(git_vector_insert(out, fetchhead_ref)); - cl_git_pass(git_oid_fromstr(&oid, - "8f50ba15d49353813cc6e20298002c0d17b0a9ee")); + cl_git_pass(git_oid__fromstr(&oid, + "8f50ba15d49353813cc6e20298002c0d17b0a9ee", + GIT_OID_SHA1)); cl_git_pass(git_fetchhead_ref_create(&fetchhead_ref, &oid, 0, "refs/tags/commit_tree", "https://github.com/libgit2/TestGitRepository")); @@ -170,7 +176,7 @@ static int read_old_style_cb(const char *name, const char *url, GIT_UNUSED(payload); - git_oid_fromstr(&expected, "49322bb17d3acc9146f98c97d078513228bbf3c0"); + git_oid__fromstr(&expected, "49322bb17d3acc9146f98c97d078513228bbf3c0", GIT_OID_SHA1); cl_assert(name == NULL); cl_assert(url == NULL); @@ -197,7 +203,7 @@ static int read_type_missing(const char *ref_name, const char *remote_url, GIT_UNUSED(payload); - git_oid_fromstr(&expected, "49322bb17d3acc9146f98c97d078513228bbf3c0"); + git_oid__fromstr(&expected, "49322bb17d3acc9146f98c97d078513228bbf3c0", GIT_OID_SHA1); cl_assert_equal_s("name", ref_name); cl_assert_equal_s("remote_url", remote_url); @@ -224,7 +230,7 @@ static int read_name_missing(const char *ref_name, const char *remote_url, GIT_UNUSED(payload); - git_oid_fromstr(&expected, "49322bb17d3acc9146f98c97d078513228bbf3c0"); + git_oid__fromstr(&expected, "49322bb17d3acc9146f98c97d078513228bbf3c0", GIT_OID_SHA1); cl_assert(ref_name == NULL); cl_assert_equal_s("remote_url", remote_url); @@ -528,13 +534,13 @@ void test_fetchhead_nonetwork__credentials_are_stripped(void) git_fetchhead_ref *ref; git_oid oid; - cl_git_pass(git_oid_fromstr(&oid, "49322bb17d3acc9146f98c97d078513228bbf3c0")); + cl_git_pass(git_oid__fromstr(&oid, "49322bb17d3acc9146f98c97d078513228bbf3c0", GIT_OID_SHA1)); cl_git_pass(git_fetchhead_ref_create(&ref, &oid, 0, "refs/tags/commit_tree", "http://foo:bar@github.com/libgit2/TestGitRepository")); cl_assert_equal_s(ref->remote_url, "http://github.com/libgit2/TestGitRepository"); git_fetchhead_ref_free(ref); - cl_git_pass(git_oid_fromstr(&oid, "49322bb17d3acc9146f98c97d078513228bbf3c0")); + cl_git_pass(git_oid__fromstr(&oid, "49322bb17d3acc9146f98c97d078513228bbf3c0", GIT_OID_SHA1)); cl_git_pass(git_fetchhead_ref_create(&ref, &oid, 0, "refs/tags/commit_tree", "https://foo:bar@github.com/libgit2/TestGitRepository")); cl_assert_equal_s(ref->remote_url, "https://github.com/libgit2/TestGitRepository"); diff --git a/tests/libgit2/filter/bare.c b/tests/libgit2/filter/bare.c index 8402638ce..f53cfcb49 100644 --- a/tests/libgit2/filter/bare.c +++ b/tests/libgit2/filter/bare.c @@ -140,7 +140,7 @@ void test_filter_bare__from_specific_commit_one(void) opts.flags |= GIT_BLOB_FILTER_NO_SYSTEM_ATTRIBUTES; opts.flags |= GIT_BLOB_FILTER_ATTRIBUTES_FROM_COMMIT; - cl_git_pass(git_oid_fromstr(&opts.attr_commit_id, "b8986fec0f7bde90f78ac72706e782d82f24f2f0")); + cl_git_pass(git_oid__fromstr(&opts.attr_commit_id, "b8986fec0f7bde90f78ac72706e782d82f24f2f0", GIT_OID_SHA1)); cl_git_pass(git_revparse_single( (git_object **)&blob, g_repo, "055c872")); /* ident */ @@ -165,7 +165,7 @@ void test_filter_bare__from_specific_commit_with_no_attributes_file(void) opts.flags |= GIT_BLOB_FILTER_NO_SYSTEM_ATTRIBUTES; opts.flags |= GIT_BLOB_FILTER_ATTRIBUTES_FROM_COMMIT; - cl_git_pass(git_oid_fromstr(&opts.attr_commit_id, "5afb6a14a864e30787857dd92af837e8cdd2cb1b")); + cl_git_pass(git_oid__fromstr(&opts.attr_commit_id, "5afb6a14a864e30787857dd92af837e8cdd2cb1b", GIT_OID_SHA1)); cl_git_pass(git_revparse_single( (git_object **)&blob, g_repo, "799770d")); /* all-lf */ diff --git a/tests/libgit2/graph/ahead_behind.c b/tests/libgit2/graph/ahead_behind.c index 77d7768af..dd828c5f3 100644 --- a/tests/libgit2/graph/ahead_behind.c +++ b/tests/libgit2/graph/ahead_behind.c @@ -10,7 +10,7 @@ void test_graph_ahead_behind__initialize(void) git_oid oid; cl_git_pass(git_repository_open(&_repo, cl_fixture("testrepo.git"))); - cl_git_pass(git_oid_fromstr(&oid, "be3563ae3f795b2b4353bcce3a527ad0a4f7f644")); + cl_git_pass(git_oid__fromstr(&oid, "be3563ae3f795b2b4353bcce3a527ad0a4f7f644", GIT_OID_SHA1)); cl_git_pass(git_commit_lookup(&commit, _repo, &oid)); } @@ -29,8 +29,8 @@ void test_graph_ahead_behind__returns_correct_result(void) git_oid oid2; git_commit *other; - cl_git_pass(git_oid_fromstr(&oid, "e90810b8df3e80c413d903f631643c716887138d")); - cl_git_pass(git_oid_fromstr(&oid2, "be3563ae3f795b2b4353bcce3a527ad0a4f7f644")); + cl_git_pass(git_oid__fromstr(&oid, "e90810b8df3e80c413d903f631643c716887138d", GIT_OID_SHA1)); + cl_git_pass(git_oid__fromstr(&oid2, "be3563ae3f795b2b4353bcce3a527ad0a4f7f644", GIT_OID_SHA1)); cl_git_pass(git_graph_ahead_behind(&ahead, &behind, _repo, &oid, &oid2)); cl_assert_equal_sz(2, ahead); diff --git a/tests/libgit2/graph/commitgraph.c b/tests/libgit2/graph/commitgraph.c index 7607c35a3..82f7f936f 100644 --- a/tests/libgit2/graph/commitgraph.c +++ b/tests/libgit2/graph/commitgraph.c @@ -19,28 +19,28 @@ void test_graph_commitgraph__parse(void) cl_git_pass(git_commit_graph_file_open(&file, git_str_cstr(&commit_graph_path))); cl_assert_equal_i(git_commit_graph_file_needs_refresh(file, git_str_cstr(&commit_graph_path)), 0); - cl_git_pass(git_oid_fromstr(&id, "5001298e0c09ad9c34e4249bc5801c75e9754fa5")); - cl_git_pass(git_commit_graph_entry_find(&e, file, &id, GIT_OID_HEXSZ)); + cl_git_pass(git_oid__fromstr(&id, "5001298e0c09ad9c34e4249bc5801c75e9754fa5", GIT_OID_SHA1)); + cl_git_pass(git_commit_graph_entry_find(&e, file, &id, GIT_OID_SHA1_HEXSIZE)); cl_assert_equal_oid(&e.sha1, &id); - cl_git_pass(git_oid_fromstr(&id, "418382dff1ffb8bdfba833f4d8bbcde58b1e7f47")); + cl_git_pass(git_oid__fromstr(&id, "418382dff1ffb8bdfba833f4d8bbcde58b1e7f47", GIT_OID_SHA1)); cl_assert_equal_oid(&e.tree_oid, &id); cl_assert_equal_i(e.generation, 1); cl_assert_equal_i(e.commit_time, UINT64_C(1273610423)); cl_assert_equal_i(e.parent_count, 0); - cl_git_pass(git_oid_fromstr(&id, "be3563ae3f795b2b4353bcce3a527ad0a4f7f644")); - cl_git_pass(git_commit_graph_entry_find(&e, file, &id, GIT_OID_HEXSZ)); + cl_git_pass(git_oid__fromstr(&id, "be3563ae3f795b2b4353bcce3a527ad0a4f7f644", GIT_OID_SHA1)); + cl_git_pass(git_commit_graph_entry_find(&e, file, &id, GIT_OID_SHA1_HEXSIZE)); cl_assert_equal_oid(&e.sha1, &id); cl_assert_equal_i(e.generation, 5); cl_assert_equal_i(e.commit_time, UINT64_C(1274813907)); cl_assert_equal_i(e.parent_count, 2); - cl_git_pass(git_oid_fromstr(&id, "9fd738e8f7967c078dceed8190330fc8648ee56a")); + cl_git_pass(git_oid__fromstr(&id, "9fd738e8f7967c078dceed8190330fc8648ee56a", GIT_OID_SHA1)); cl_git_pass(git_commit_graph_entry_parent(&parent, file, &e, 0)); cl_assert_equal_oid(&parent.sha1, &id); cl_assert_equal_i(parent.generation, 4); - cl_git_pass(git_oid_fromstr(&id, "c47800c7266a2be04c571c04d5a6614691ea99bd")); + cl_git_pass(git_oid__fromstr(&id, "c47800c7266a2be04c571c04d5a6614691ea99bd", GIT_OID_SHA1)); cl_git_pass(git_commit_graph_entry_parent(&parent, file, &e, 1)); cl_assert_equal_oid(&parent.sha1, &id); cl_assert_equal_i(parent.generation, 3); @@ -62,26 +62,26 @@ void test_graph_commitgraph__parse_octopus_merge(void) cl_git_pass(git_str_joinpath(&commit_graph_path, git_repository_path(repo), "objects/info/commit-graph")); cl_git_pass(git_commit_graph_file_open(&file, git_str_cstr(&commit_graph_path))); - cl_git_pass(git_oid_fromstr(&id, "d71c24b3b113fd1d1909998c5bfe33b86a65ee03")); - cl_git_pass(git_commit_graph_entry_find(&e, file, &id, GIT_OID_HEXSZ)); + cl_git_pass(git_oid__fromstr(&id, "d71c24b3b113fd1d1909998c5bfe33b86a65ee03", GIT_OID_SHA1)); + cl_git_pass(git_commit_graph_entry_find(&e, file, &id, GIT_OID_SHA1_HEXSIZE)); cl_assert_equal_oid(&e.sha1, &id); - cl_git_pass(git_oid_fromstr(&id, "348f16ffaeb73f319a75cec5b16a0a47d2d5e27c")); + cl_git_pass(git_oid__fromstr(&id, "348f16ffaeb73f319a75cec5b16a0a47d2d5e27c", GIT_OID_SHA1)); cl_assert_equal_oid(&e.tree_oid, &id); cl_assert_equal_i(e.generation, 7); cl_assert_equal_i(e.commit_time, UINT64_C(1447083009)); cl_assert_equal_i(e.parent_count, 3); - cl_git_pass(git_oid_fromstr(&id, "ad2ace9e15f66b3d1138922e6ffdc3ea3f967fa6")); + cl_git_pass(git_oid__fromstr(&id, "ad2ace9e15f66b3d1138922e6ffdc3ea3f967fa6", GIT_OID_SHA1)); cl_git_pass(git_commit_graph_entry_parent(&parent, file, &e, 0)); cl_assert_equal_oid(&parent.sha1, &id); cl_assert_equal_i(parent.generation, 6); - cl_git_pass(git_oid_fromstr(&id, "483065df53c0f4a02cdc6b2910b05d388fc17ffb")); + cl_git_pass(git_oid__fromstr(&id, "483065df53c0f4a02cdc6b2910b05d388fc17ffb", GIT_OID_SHA1)); cl_git_pass(git_commit_graph_entry_parent(&parent, file, &e, 1)); cl_assert_equal_oid(&parent.sha1, &id); cl_assert_equal_i(parent.generation, 2); - cl_git_pass(git_oid_fromstr(&id, "815b5a1c80ca749d705c7aa0cb294a00cbedd340")); + cl_git_pass(git_oid__fromstr(&id, "815b5a1c80ca749d705c7aa0cb294a00cbedd340", GIT_OID_SHA1)); cl_git_pass(git_commit_graph_entry_parent(&parent, file, &e, 2)); cl_assert_equal_oid(&parent.sha1, &id); cl_assert_equal_i(parent.generation, 6); @@ -124,3 +124,44 @@ void test_graph_commitgraph__writer(void) git_commit_graph_writer_free(w); git_repository_free(repo); } + +void test_graph_commitgraph__validate(void) +{ + git_repository *repo; + struct git_commit_graph *cgraph; + git_str objects_dir = GIT_STR_INIT; + + cl_git_pass(git_repository_open(&repo, cl_fixture("testrepo.git"))); + cl_git_pass(git_str_joinpath(&objects_dir, git_repository_path(repo), "objects")); + + /* git_commit_graph_open() calls git_commit_graph_validate() */ + cl_git_pass(git_commit_graph_open(&cgraph, git_str_cstr(&objects_dir))); + + git_commit_graph_free(cgraph); + git_str_dispose(&objects_dir); + git_repository_free(repo); +} + +void test_graph_commitgraph__validate_corrupt(void) +{ + git_repository *repo; + struct git_commit_graph *cgraph; + int fd = -1; + + cl_fixture_sandbox("testrepo.git"); + cl_git_pass(git_repository_open(&repo, cl_git_sandbox_path(1, "testrepo.git", NULL))); + + /* corrupt commit graph checksum at the end of the file */ + cl_assert((fd = p_open(cl_git_sandbox_path(0, "testrepo.git", "objects", "info", "commit-graph", NULL), O_WRONLY)) > 0); + cl_assert(p_lseek(fd, -5, SEEK_END) > 0); + cl_must_pass(p_write(fd, "\0\0", 2)); + cl_must_pass(p_close(fd)); + + /* git_commit_graph_open() calls git_commit_graph_validate() */ + cl_git_fail(git_commit_graph_open(&cgraph, cl_git_sandbox_path(1, "testrepo.git", "objects", NULL))); + + git_commit_graph_free(cgraph); + git_repository_free(repo); + + cl_fixture_cleanup("testrepo.git"); +} diff --git a/tests/libgit2/graph/descendant_of.c b/tests/libgit2/graph/descendant_of.c index 8e9952a09..b6dffae06 100644 --- a/tests/libgit2/graph/descendant_of.c +++ b/tests/libgit2/graph/descendant_of.c @@ -9,7 +9,7 @@ void test_graph_descendant_of__initialize(void) cl_git_pass(git_repository_open(&_repo, cl_fixture("testrepo.git"))); - git_oid_fromstr(&oid, "be3563ae3f795b2b4353bcce3a527ad0a4f7f644"); + git_oid__fromstr(&oid, "be3563ae3f795b2b4353bcce3a527ad0a4f7f644", GIT_OID_SHA1); cl_git_pass(git_commit_lookup(&commit, _repo, &oid)); } @@ -50,6 +50,6 @@ void test_graph_descendant_of__nopath(void) { git_oid oid; - git_oid_fromstr(&oid, "e90810b8df3e80c413d903f631643c716887138d"); + git_oid__fromstr(&oid, "e90810b8df3e80c413d903f631643c716887138d", GIT_OID_SHA1); cl_assert_equal_i(0, git_graph_descendant_of(_repo, git_commit_id(commit), &oid)); } diff --git a/tests/libgit2/graph/reachable_from_any.c b/tests/libgit2/graph/reachable_from_any.c index 9693d7d67..8e1c23874 100644 --- a/tests/libgit2/graph/reachable_from_any.c +++ b/tests/libgit2/graph/reachable_from_any.c @@ -17,7 +17,7 @@ void test_graph_reachable_from_any__initialize(void) repo = cl_git_sandbox_init(TEST_REPO_PATH); - git_oid_fromstr(&oid, "539bd011c4822c560c1d17cab095006b7a10f707"); + git_oid__fromstr(&oid, "539bd011c4822c560c1d17cab095006b7a10f707", GIT_OID_SHA1); cl_git_pass(git_commit_lookup(&commit, repo, &oid)); cl_git_pass(git_reset(repo, (git_object *)commit, GIT_RESET_HARD, NULL)); git_commit_free(commit); diff --git a/tests/libgit2/ignore/path.c b/tests/libgit2/ignore/path.c index a574d1d79..17f28bc5d 100644 --- a/tests/libgit2/ignore/path.c +++ b/tests/libgit2/ignore/path.c @@ -286,14 +286,16 @@ void test_ignore_path__subdirectory_gitignore(void) void test_ignore_path__expand_tilde_to_homedir(void) { + git_str homefile = GIT_STR_INIT; git_config *cfg; assert_is_ignored(false, "example.global_with_tilde"); - cl_fake_home(); + cl_fake_homedir(&homefile); + cl_git_pass(git_str_joinpath(&homefile, homefile.ptr, "globalexclude")); /* construct fake home with fake global excludes */ - cl_git_mkfile("home/globalexclude", "# found me\n*.global_with_tilde\n"); + cl_git_mkfile(homefile.ptr, "# found me\n*.global_with_tilde\n"); cl_git_pass(git_repository_config(&cfg, g_repo)); cl_git_pass(git_config_set_string(cfg, "core.excludesfile", "~/globalexclude")); @@ -305,11 +307,13 @@ void test_ignore_path__expand_tilde_to_homedir(void) cl_git_pass(git_futils_rmdir_r("home", NULL, GIT_RMDIR_REMOVE_FILES)); - cl_fake_home_cleanup(NULL); + cl_fake_homedir_cleanup(NULL); git_attr_cache_flush(g_repo); /* must reset to pick up change */ assert_is_ignored(false, "example.global_with_tilde"); + + git_str_dispose(&homefile); } /* Ensure that the .gitignore in the subdirectory only affects diff --git a/tests/libgit2/ignore/status.c b/tests/libgit2/ignore/status.c index deb717590..a007774d7 100644 --- a/tests/libgit2/ignore/status.c +++ b/tests/libgit2/ignore/status.c @@ -363,6 +363,7 @@ void test_ignore_status__subdirectories_not_at_root(void) void test_ignore_status__leading_slash_ignores(void) { + git_str homedir = GIT_STR_INIT; git_status_options opts = GIT_STATUS_OPTIONS_INIT; status_entry_counts counts; static const char *paths_2[] = { @@ -385,8 +386,9 @@ void test_ignore_status__leading_slash_ignores(void) make_test_data(test_repo_1, test_files_1); - cl_fake_home(); - cl_git_mkfile("home/.gitignore", "/ignore_me\n"); + cl_fake_homedir(&homedir); + cl_git_pass(git_str_joinpath(&homedir, homedir.ptr, ".gitignore")); + cl_git_mkfile(homedir.ptr, "/ignore_me\n"); { git_config *cfg; cl_git_pass(git_repository_config(&cfg, g_repo)); @@ -412,6 +414,8 @@ void test_ignore_status__leading_slash_ignores(void) cl_assert_equal_i(counts.expected_entry_count, counts.entry_count); cl_assert_equal_i(0, counts.wrong_status_flags_count); cl_assert_equal_i(0, counts.wrong_sorted_path); + + git_str_dispose(&homedir); } void test_ignore_status__multiple_leading_slash(void) diff --git a/tests/libgit2/index/add.c b/tests/libgit2/index/add.c index f101ea266..b0c3bd2b7 100644 --- a/tests/libgit2/index/add.c +++ b/tests/libgit2/index/add.c @@ -28,7 +28,7 @@ static void test_add_entry( { git_index_entry entry = {{0}}; - cl_git_pass(git_oid_fromstr(&entry.id, idstr)); + cl_git_pass(git_oid__fromstr(&entry.id, idstr, GIT_OID_SHA1)); entry.path = mode == GIT_FILEMODE_TREE ? "test_folder" : "test_file"; entry.mode = mode; diff --git a/tests/libgit2/index/addall.c b/tests/libgit2/index/addall.c index 6f95f6386..e76b6e81d 100644 --- a/tests/libgit2/index/addall.c +++ b/tests/libgit2/index/addall.c @@ -441,6 +441,52 @@ void test_index_addall__callback_filtering(void) git_index_free(index); } +void test_index_addall__handles_ignored_files_in_directory(void) +{ + git_index *index; + + g_repo = cl_git_sandbox_init_new(TEST_DIR); + + cl_git_mkfile(TEST_DIR "/file.foo", "a file"); + cl_git_mkfile(TEST_DIR "/file.bar", "another file"); + cl_must_pass(p_mkdir(TEST_DIR "/folder", 0777)); + cl_git_mkfile(TEST_DIR "/folder/asdf", "yet another file"); + + cl_git_mkfile(TEST_DIR "/.gitignore", "folder/\n"); + + check_status(g_repo, 0, 0, 0, 3, 0, 0, 1, 0); + + cl_git_pass(git_repository_index(&index, g_repo)); + cl_git_pass(git_index_add_all(index, NULL, 0, NULL, NULL)); + + check_status(g_repo, 3, 0, 0, 0, 0, 0, 1, 0); + + git_index_free(index); +} + +void test_index_addall__force_adds_ignored_directories(void) +{ + git_index *index; + + g_repo = cl_git_sandbox_init_new(TEST_DIR); + + cl_git_mkfile(TEST_DIR "/file.foo", "a file"); + cl_git_mkfile(TEST_DIR "/file.bar", "another file"); + cl_must_pass(p_mkdir(TEST_DIR "/folder", 0777)); + cl_git_mkfile(TEST_DIR "/folder/asdf", "yet another file"); + + cl_git_mkfile(TEST_DIR "/.gitignore", "folder/\n"); + + check_status(g_repo, 0, 0, 0, 3, 0, 0, 1, 0); + + cl_git_pass(git_repository_index(&index, g_repo)); + cl_git_pass(git_index_add_all(index, NULL, GIT_INDEX_ADD_FORCE, NULL, NULL)); + + check_status(g_repo, 4, 0, 0, 0, 0, 0, 0, 0); + + git_index_free(index); +} + void test_index_addall__adds_conflicts(void) { git_index *index; diff --git a/tests/libgit2/index/bypath.c b/tests/libgit2/index/bypath.c index b32a0a789..15c11af5f 100644 --- a/tests/libgit2/index/bypath.c +++ b/tests/libgit2/index/bypath.c @@ -131,7 +131,7 @@ void test_index_bypath__add_honors_existing_case_2(void) clar__skip(); dummy.mode = GIT_FILEMODE_BLOB; - cl_git_pass(git_oid_fromstr(&dummy.id, "f990a25a74d1a8281ce2ab018ea8df66795cd60b")); + cl_git_pass(git_oid__fromstr(&dummy.id, "f990a25a74d1a8281ce2ab018ea8df66795cd60b", GIT_OID_SHA1)); /* note that `git_index_add` does no checking to canonical directories */ dummy.path = "Just_a_dir/file0.txt"; @@ -187,7 +187,7 @@ void test_index_bypath__add_honors_existing_case_3(void) clar__skip(); dummy.mode = GIT_FILEMODE_BLOB; - cl_git_pass(git_oid_fromstr(&dummy.id, "f990a25a74d1a8281ce2ab018ea8df66795cd60b")); + cl_git_pass(git_oid__fromstr(&dummy.id, "f990a25a74d1a8281ce2ab018ea8df66795cd60b", GIT_OID_SHA1)); dummy.path = "just_a_dir/filea.txt"; cl_git_pass(git_index_add(g_idx, &dummy)); @@ -218,7 +218,7 @@ void test_index_bypath__add_honors_existing_case_4(void) clar__skip(); dummy.mode = GIT_FILEMODE_BLOB; - cl_git_pass(git_oid_fromstr(&dummy.id, "f990a25a74d1a8281ce2ab018ea8df66795cd60b")); + cl_git_pass(git_oid__fromstr(&dummy.id, "f990a25a74d1a8281ce2ab018ea8df66795cd60b", GIT_OID_SHA1)); dummy.path = "just_a_dir/a/b/c/d/e/file1.txt"; cl_git_pass(git_index_add(g_idx, &dummy)); diff --git a/tests/libgit2/index/cache.c b/tests/libgit2/index/cache.c index 56885aff7..7576331b0 100644 --- a/tests/libgit2/index/cache.c +++ b/tests/libgit2/index/cache.c @@ -26,7 +26,7 @@ void test_index_cache__write_extension_at_root(void) cl_git_pass(git_index_open(&index, index_file)); cl_assert(index->tree == NULL); - cl_git_pass(git_oid_fromstr(&id, tree_id_str)); + cl_git_pass(git_oid__fromstr(&id, tree_id_str, GIT_OID_SHA1)); cl_git_pass(git_tree_lookup(&tree, g_repo, &id)); cl_git_pass(git_index_read_tree(index, tree)); git_tree_free(tree); @@ -58,7 +58,7 @@ void test_index_cache__write_extension_invalidated_root(void) cl_git_pass(git_index_open(&index, index_file)); cl_assert(index->tree == NULL); - cl_git_pass(git_oid_fromstr(&id, tree_id_str)); + cl_git_pass(git_oid__fromstr(&id, tree_id_str, GIT_OID_SHA1)); cl_git_pass(git_tree_lookup(&tree, g_repo, &id)); cl_git_pass(git_index_read_tree(index, tree)); git_tree_free(tree); @@ -98,7 +98,7 @@ void test_index_cache__read_tree_no_children(void) cl_git_pass(git_index_new(&index)); cl_assert(index->tree == NULL); - cl_git_pass(git_oid_fromstr(&id, "45dd856fdd4d89b884c340ba0e047752d9b085d6")); + cl_git_pass(git_oid__fromstr(&id, "45dd856fdd4d89b884c340ba0e047752d9b085d6", GIT_OID_SHA1)); cl_git_pass(git_tree_lookup(&tree, g_repo, &id)); cl_git_pass(git_index_read_tree(index, tree)); git_tree_free(tree); @@ -111,7 +111,7 @@ void test_index_cache__read_tree_no_children(void) memset(&entry, 0x0, sizeof(git_index_entry)); entry.path = "new.txt"; entry.mode = GIT_FILEMODE_BLOB; - git_oid_fromstr(&entry.id, "d4bcc68acd4410bf836a39f20afb2c2ece09584e"); + git_oid__fromstr(&entry.id, "d4bcc68acd4410bf836a39f20afb2c2ece09584e", GIT_OID_SHA1); cl_git_pass(git_index_add(index, &entry)); cl_assert_equal_i(-1, index->tree->entry_count); @@ -132,7 +132,7 @@ void test_index_cache__two_levels(void) memset(&entry, 0x0, sizeof(entry)); entry.mode = GIT_FILEMODE_BLOB; - cl_git_pass(git_oid_fromstr(&entry.id, "a8233120f6ad708f843d861ce2b7228ec4e3dec6")); + cl_git_pass(git_oid__fromstr(&entry.id, "a8233120f6ad708f843d861ce2b7228ec4e3dec6", GIT_OID_SHA1)); entry.path = "top-level.txt"; cl_git_pass(git_index_add(index, &entry)); @@ -156,7 +156,7 @@ void test_index_cache__two_levels(void) cl_assert(git_tree_cache_get(index->tree, "subdir")); entry.path = "top-level.txt"; - cl_git_pass(git_oid_fromstr(&entry.id, "3697d64be941a53d4ae8f6a271e4e3fa56b022cc")); + cl_git_pass(git_oid__fromstr(&entry.id, "3697d64be941a53d4ae8f6a271e4e3fa56b022cc", GIT_OID_SHA1)); cl_git_pass(git_index_add(index, &entry)); /* writ out the index after we invalidate the root */ @@ -191,7 +191,7 @@ void test_index_cache__read_tree_children(void) memset(&entry, 0x0, sizeof(git_index_entry)); entry.path = "top-level"; entry.mode = GIT_FILEMODE_BLOB; - git_oid_fromstr(&entry.id, "ee3fa1b8c00aff7fe02065fdb50864bb0d932ccf"); + git_oid__fromstr(&entry.id, "ee3fa1b8c00aff7fe02065fdb50864bb0d932ccf", GIT_OID_SHA1); cl_git_pass(git_index_add(index, &entry)); @@ -217,7 +217,7 @@ void test_index_cache__read_tree_children(void) /* override with a slightly different id, also dummy */ entry.path = "subdir/some-file"; - git_oid_fromstr(&entry.id, "ee3fa1b8c00aff7fe02065fdb50864bb0d932ccf"); + git_oid__fromstr(&entry.id, "ee3fa1b8c00aff7fe02065fdb50864bb0d932ccf", GIT_OID_SHA1); cl_git_pass(git_index_add(index, &entry)); cl_assert_equal_i(-1, index->tree->entry_count); diff --git a/tests/libgit2/index/conflicts.c b/tests/libgit2/index/conflicts.c index 41d0e219c..353886f7b 100644 --- a/tests/libgit2/index/conflicts.c +++ b/tests/libgit2/index/conflicts.c @@ -37,17 +37,17 @@ void test_index_conflicts__add(void) ancestor_entry.path = "test-one.txt"; ancestor_entry.mode = 0100644; GIT_INDEX_ENTRY_STAGE_SET(&ancestor_entry, 1); - git_oid_fromstr(&ancestor_entry.id, CONFLICTS_ONE_ANCESTOR_OID); + git_oid__fromstr(&ancestor_entry.id, CONFLICTS_ONE_ANCESTOR_OID, GIT_OID_SHA1); our_entry.path = "test-one.txt"; our_entry.mode = 0100644; GIT_INDEX_ENTRY_STAGE_SET(&our_entry, 2); - git_oid_fromstr(&our_entry.id, CONFLICTS_ONE_OUR_OID); + git_oid__fromstr(&our_entry.id, CONFLICTS_ONE_OUR_OID, GIT_OID_SHA1); their_entry.path = "test-one.txt"; their_entry.mode = 0100644; GIT_INDEX_ENTRY_STAGE_SET(&ancestor_entry, 2); - git_oid_fromstr(&their_entry.id, CONFLICTS_ONE_THEIR_OID); + git_oid__fromstr(&their_entry.id, CONFLICTS_ONE_THEIR_OID, GIT_OID_SHA1); cl_git_pass(git_index_conflict_add(repo_index, &ancestor_entry, &our_entry, &their_entry)); @@ -68,17 +68,17 @@ void test_index_conflicts__add_fixes_incorrect_stage(void) ancestor_entry.path = "test-one.txt"; ancestor_entry.mode = 0100644; GIT_INDEX_ENTRY_STAGE_SET(&ancestor_entry, 3); - git_oid_fromstr(&ancestor_entry.id, CONFLICTS_ONE_ANCESTOR_OID); + git_oid__fromstr(&ancestor_entry.id, CONFLICTS_ONE_ANCESTOR_OID, GIT_OID_SHA1); our_entry.path = "test-one.txt"; our_entry.mode = 0100644; GIT_INDEX_ENTRY_STAGE_SET(&our_entry, 1); - git_oid_fromstr(&our_entry.id, CONFLICTS_ONE_OUR_OID); + git_oid__fromstr(&our_entry.id, CONFLICTS_ONE_OUR_OID, GIT_OID_SHA1); their_entry.path = "test-one.txt"; their_entry.mode = 0100644; GIT_INDEX_ENTRY_STAGE_SET(&their_entry, 2); - git_oid_fromstr(&their_entry.id, CONFLICTS_ONE_THEIR_OID); + git_oid__fromstr(&their_entry.id, CONFLICTS_ONE_THEIR_OID, GIT_OID_SHA1); cl_git_pass(git_index_conflict_add(repo_index, &ancestor_entry, &our_entry, &their_entry)); @@ -111,17 +111,17 @@ void test_index_conflicts__add_detects_invalid_filemode(void) ancestor_entry.path = "test-one.txt"; ancestor_entry.mode = 0100644; GIT_INDEX_ENTRY_STAGE_SET(&ancestor_entry, 3); - git_oid_fromstr(&ancestor_entry.id, CONFLICTS_ONE_ANCESTOR_OID); + git_oid__fromstr(&ancestor_entry.id, CONFLICTS_ONE_ANCESTOR_OID, GIT_OID_SHA1); our_entry.path = "test-one.txt"; our_entry.mode = 0100644; GIT_INDEX_ENTRY_STAGE_SET(&our_entry, 1); - git_oid_fromstr(&our_entry.id, CONFLICTS_ONE_OUR_OID); + git_oid__fromstr(&our_entry.id, CONFLICTS_ONE_OUR_OID, GIT_OID_SHA1); their_entry.path = "test-one.txt"; their_entry.mode = 0100644; GIT_INDEX_ENTRY_STAGE_SET(&their_entry, 2); - git_oid_fromstr(&their_entry.id, CONFLICTS_ONE_THEIR_OID); + git_oid__fromstr(&their_entry.id, CONFLICTS_ONE_THEIR_OID, GIT_OID_SHA1); /* Corrupt the conflict entry's mode */ conflict_entry[i]->mode = 027431745; @@ -151,17 +151,17 @@ void test_index_conflicts__add_removes_stage_zero(void) ancestor_entry.path = "test-one.txt"; ancestor_entry.mode = 0100644; GIT_INDEX_ENTRY_STAGE_SET(&ancestor_entry, 3); - git_oid_fromstr(&ancestor_entry.id, CONFLICTS_ONE_ANCESTOR_OID); + git_oid__fromstr(&ancestor_entry.id, CONFLICTS_ONE_ANCESTOR_OID, GIT_OID_SHA1); our_entry.path = "test-one.txt"; our_entry.mode = 0100644; GIT_INDEX_ENTRY_STAGE_SET(&our_entry, 1); - git_oid_fromstr(&our_entry.id, CONFLICTS_ONE_OUR_OID); + git_oid__fromstr(&our_entry.id, CONFLICTS_ONE_OUR_OID, GIT_OID_SHA1); their_entry.path = "test-one.txt"; their_entry.mode = 0100644; GIT_INDEX_ENTRY_STAGE_SET(&their_entry, 2); - git_oid_fromstr(&their_entry.id, CONFLICTS_ONE_THEIR_OID); + git_oid__fromstr(&their_entry.id, CONFLICTS_ONE_THEIR_OID, GIT_OID_SHA1); cl_git_pass(git_index_conflict_add(repo_index, &ancestor_entry, &our_entry, &their_entry)); @@ -189,13 +189,13 @@ void test_index_conflicts__get(void) cl_assert_equal_s("conflicts-one.txt", conflict_entry[0]->path); - git_oid_fromstr(&oid, CONFLICTS_ONE_ANCESTOR_OID); + git_oid__fromstr(&oid, CONFLICTS_ONE_ANCESTOR_OID, GIT_OID_SHA1); cl_assert_equal_oid(&oid, &conflict_entry[0]->id); - git_oid_fromstr(&oid, CONFLICTS_ONE_OUR_OID); + git_oid__fromstr(&oid, CONFLICTS_ONE_OUR_OID, GIT_OID_SHA1); cl_assert_equal_oid(&oid, &conflict_entry[1]->id); - git_oid_fromstr(&oid, CONFLICTS_ONE_THEIR_OID); + git_oid__fromstr(&oid, CONFLICTS_ONE_THEIR_OID, GIT_OID_SHA1); cl_assert_equal_oid(&oid, &conflict_entry[2]->id); cl_git_pass(git_index_conflict_get(&conflict_entry[0], &conflict_entry[1], @@ -203,13 +203,13 @@ void test_index_conflicts__get(void) cl_assert_equal_s("conflicts-two.txt", conflict_entry[0]->path); - git_oid_fromstr(&oid, CONFLICTS_TWO_ANCESTOR_OID); + git_oid__fromstr(&oid, CONFLICTS_TWO_ANCESTOR_OID, GIT_OID_SHA1); cl_assert_equal_oid(&oid, &conflict_entry[0]->id); - git_oid_fromstr(&oid, CONFLICTS_TWO_OUR_OID); + git_oid__fromstr(&oid, CONFLICTS_TWO_OUR_OID, GIT_OID_SHA1); cl_assert_equal_oid(&oid, &conflict_entry[1]->id); - git_oid_fromstr(&oid, CONFLICTS_TWO_THEIR_OID); + git_oid__fromstr(&oid, CONFLICTS_TWO_THEIR_OID, GIT_OID_SHA1); cl_assert_equal_oid(&oid, &conflict_entry[2]->id); } @@ -223,29 +223,29 @@ void test_index_conflicts__iterate(void) cl_git_pass(git_index_conflict_next(&conflict_entry[0], &conflict_entry[1], &conflict_entry[2], iterator)); - git_oid_fromstr(&oid, CONFLICTS_ONE_ANCESTOR_OID); + git_oid__fromstr(&oid, CONFLICTS_ONE_ANCESTOR_OID, GIT_OID_SHA1); cl_assert_equal_oid(&oid, &conflict_entry[0]->id); cl_assert(git__strcmp(conflict_entry[0]->path, "conflicts-one.txt") == 0); - git_oid_fromstr(&oid, CONFLICTS_ONE_OUR_OID); + git_oid__fromstr(&oid, CONFLICTS_ONE_OUR_OID, GIT_OID_SHA1); cl_assert_equal_oid(&oid, &conflict_entry[1]->id); cl_assert(git__strcmp(conflict_entry[0]->path, "conflicts-one.txt") == 0); - git_oid_fromstr(&oid, CONFLICTS_ONE_THEIR_OID); + git_oid__fromstr(&oid, CONFLICTS_ONE_THEIR_OID, GIT_OID_SHA1); cl_assert_equal_oid(&oid, &conflict_entry[2]->id); cl_assert(git__strcmp(conflict_entry[0]->path, "conflicts-one.txt") == 0); cl_git_pass(git_index_conflict_next(&conflict_entry[0], &conflict_entry[1], &conflict_entry[2], iterator)); - git_oid_fromstr(&oid, CONFLICTS_TWO_ANCESTOR_OID); + git_oid__fromstr(&oid, CONFLICTS_TWO_ANCESTOR_OID, GIT_OID_SHA1); cl_assert_equal_oid(&oid, &conflict_entry[0]->id); cl_assert(git__strcmp(conflict_entry[0]->path, "conflicts-two.txt") == 0); - git_oid_fromstr(&oid, CONFLICTS_TWO_OUR_OID); + git_oid__fromstr(&oid, CONFLICTS_TWO_OUR_OID, GIT_OID_SHA1); cl_assert_equal_oid(&oid, &conflict_entry[1]->id); cl_assert(git__strcmp(conflict_entry[0]->path, "conflicts-two.txt") == 0); - git_oid_fromstr(&oid, CONFLICTS_TWO_THEIR_OID); + git_oid__fromstr(&oid, CONFLICTS_TWO_THEIR_OID, GIT_OID_SHA1); cl_assert_equal_oid(&oid, &conflict_entry[2]->id); cl_assert(git__strcmp(conflict_entry[0]->path, "conflicts-two.txt") == 0); @@ -357,7 +357,7 @@ void test_index_conflicts__partial(void) ancestor_entry.path = "test-one.txt"; ancestor_entry.mode = 0100644; GIT_INDEX_ENTRY_STAGE_SET(&ancestor_entry, 1); - git_oid_fromstr(&ancestor_entry.id, CONFLICTS_ONE_ANCESTOR_OID); + git_oid__fromstr(&ancestor_entry.id, CONFLICTS_ONE_ANCESTOR_OID, GIT_OID_SHA1); cl_git_pass(git_index_conflict_add(repo_index, &ancestor_entry, NULL, NULL)); cl_assert(git_index_entrycount(repo_index) == 9); @@ -387,17 +387,17 @@ void test_index_conflicts__case_matters(void) ancestor_entry.path = upper_case; GIT_INDEX_ENTRY_STAGE_SET(&ancestor_entry, GIT_INDEX_STAGE_ANCESTOR); - git_oid_fromstr(&ancestor_entry.id, CONFLICTS_ONE_ANCESTOR_OID); + git_oid__fromstr(&ancestor_entry.id, CONFLICTS_ONE_ANCESTOR_OID, GIT_OID_SHA1); ancestor_entry.mode = GIT_FILEMODE_BLOB; our_entry.path = upper_case; GIT_INDEX_ENTRY_STAGE_SET(&our_entry, GIT_INDEX_STAGE_OURS); - git_oid_fromstr(&our_entry.id, CONFLICTS_ONE_OUR_OID); + git_oid__fromstr(&our_entry.id, CONFLICTS_ONE_OUR_OID, GIT_OID_SHA1); our_entry.mode = GIT_FILEMODE_BLOB; their_entry.path = upper_case; GIT_INDEX_ENTRY_STAGE_SET(&their_entry, GIT_INDEX_STAGE_THEIRS); - git_oid_fromstr(&their_entry.id, CONFLICTS_ONE_THEIR_OID); + git_oid__fromstr(&their_entry.id, CONFLICTS_ONE_THEIR_OID, GIT_OID_SHA1); their_entry.mode = GIT_FILEMODE_BLOB; cl_git_pass(git_index_conflict_add(repo_index, @@ -405,17 +405,17 @@ void test_index_conflicts__case_matters(void) ancestor_entry.path = mixed_case; GIT_INDEX_ENTRY_STAGE_SET(&ancestor_entry, GIT_INDEX_STAGE_ANCESTOR); - git_oid_fromstr(&ancestor_entry.id, CONFLICTS_TWO_ANCESTOR_OID); + git_oid__fromstr(&ancestor_entry.id, CONFLICTS_TWO_ANCESTOR_OID, GIT_OID_SHA1); ancestor_entry.mode = GIT_FILEMODE_BLOB; our_entry.path = mixed_case; GIT_INDEX_ENTRY_STAGE_SET(&ancestor_entry, GIT_INDEX_STAGE_ANCESTOR); - git_oid_fromstr(&our_entry.id, CONFLICTS_TWO_OUR_OID); + git_oid__fromstr(&our_entry.id, CONFLICTS_TWO_OUR_OID, GIT_OID_SHA1); ancestor_entry.mode = GIT_FILEMODE_BLOB; their_entry.path = mixed_case; GIT_INDEX_ENTRY_STAGE_SET(&their_entry, GIT_INDEX_STAGE_THEIRS); - git_oid_fromstr(&their_entry.id, CONFLICTS_TWO_THEIR_OID); + git_oid__fromstr(&their_entry.id, CONFLICTS_TWO_THEIR_OID, GIT_OID_SHA1); their_entry.mode = GIT_FILEMODE_BLOB; cl_git_pass(git_index_conflict_add(repo_index, @@ -434,29 +434,29 @@ void test_index_conflicts__case_matters(void) correct_case = upper_case; cl_assert_equal_s(correct_case, conflict_entry[0]->path); - git_oid_fromstr(&oid, ignorecase ? CONFLICTS_TWO_ANCESTOR_OID : CONFLICTS_ONE_ANCESTOR_OID); + git_oid__fromstr(&oid, ignorecase ? CONFLICTS_TWO_ANCESTOR_OID : CONFLICTS_ONE_ANCESTOR_OID, GIT_OID_SHA1); cl_assert_equal_oid(&oid, &conflict_entry[0]->id); cl_assert_equal_s(correct_case, conflict_entry[1]->path); - git_oid_fromstr(&oid, ignorecase ? CONFLICTS_TWO_OUR_OID : CONFLICTS_ONE_OUR_OID); + git_oid__fromstr(&oid, ignorecase ? CONFLICTS_TWO_OUR_OID : CONFLICTS_ONE_OUR_OID, GIT_OID_SHA1); cl_assert_equal_oid(&oid, &conflict_entry[1]->id); cl_assert_equal_s(correct_case, conflict_entry[2]->path); - git_oid_fromstr(&oid, ignorecase ? CONFLICTS_TWO_THEIR_OID : CONFLICTS_ONE_THEIR_OID); + git_oid__fromstr(&oid, ignorecase ? CONFLICTS_TWO_THEIR_OID : CONFLICTS_ONE_THEIR_OID, GIT_OID_SHA1); cl_assert_equal_oid(&oid, &conflict_entry[2]->id); cl_git_pass(git_index_conflict_get(&conflict_entry[0], &conflict_entry[1], &conflict_entry[2], repo_index, mixed_case)); cl_assert_equal_s(mixed_case, conflict_entry[0]->path); - git_oid_fromstr(&oid, CONFLICTS_TWO_ANCESTOR_OID); + git_oid__fromstr(&oid, CONFLICTS_TWO_ANCESTOR_OID, GIT_OID_SHA1); cl_assert_equal_oid(&oid, &conflict_entry[0]->id); cl_assert_equal_s(mixed_case, conflict_entry[1]->path); - git_oid_fromstr(&oid, CONFLICTS_TWO_OUR_OID); + git_oid__fromstr(&oid, CONFLICTS_TWO_OUR_OID, GIT_OID_SHA1); cl_assert_equal_oid(&oid, &conflict_entry[1]->id); cl_assert_equal_s(mixed_case, conflict_entry[2]->path); - git_oid_fromstr(&oid, CONFLICTS_TWO_THEIR_OID); + git_oid__fromstr(&oid, CONFLICTS_TWO_THEIR_OID, GIT_OID_SHA1); cl_assert_equal_oid(&oid, &conflict_entry[2]->id); } diff --git a/tests/libgit2/index/crlf.c b/tests/libgit2/index/crlf.c index 7520c23a3..666ac1a0c 100644 --- a/tests/libgit2/index/crlf.c +++ b/tests/libgit2/index/crlf.c @@ -243,8 +243,9 @@ void test_index_crlf__autocrlf_false_no_attrs(void) cl_git_pass(git_index_add_bypath(g_index, "newfile.txt")); entry = git_index_get_bypath(g_index, "newfile.txt", 0); - cl_git_pass(git_oid_fromstr(&oid, - (GIT_EOL_NATIVE == GIT_EOL_CRLF) ? FILE_OID_CRLF : FILE_OID_LF)); + cl_git_pass(git_oid__fromstr(&oid, + (GIT_EOL_NATIVE == GIT_EOL_CRLF) ? FILE_OID_CRLF : FILE_OID_LF, + GIT_OID_SHA1)); cl_assert_equal_oid(&oid, &entry->id); } @@ -261,7 +262,7 @@ void test_index_crlf__autocrlf_true_no_attrs(void) cl_git_pass(git_index_add_bypath(g_index, "newfile.txt")); entry = git_index_get_bypath(g_index, "newfile.txt", 0); - cl_git_pass(git_oid_fromstr(&oid, FILE_OID_LF)); + cl_git_pass(git_oid__fromstr(&oid, FILE_OID_LF, GIT_OID_SHA1)); cl_assert_equal_oid(&oid, &entry->id); } @@ -278,7 +279,7 @@ void test_index_crlf__autocrlf_input_no_attrs(void) cl_git_pass(git_index_add_bypath(g_index, "newfile.txt")); entry = git_index_get_bypath(g_index, "newfile.txt", 0); - cl_git_pass(git_oid_fromstr(&oid, FILE_OID_LF)); + cl_git_pass(git_oid__fromstr(&oid, FILE_OID_LF, GIT_OID_SHA1)); cl_assert_equal_oid(&oid, &entry->id); } @@ -297,7 +298,7 @@ void test_index_crlf__autocrlf_false_text_auto_attr(void) cl_git_pass(git_index_add_bypath(g_index, "newfile.txt")); entry = git_index_get_bypath(g_index, "newfile.txt", 0); - cl_git_pass(git_oid_fromstr(&oid, FILE_OID_LF)); + cl_git_pass(git_oid__fromstr(&oid, FILE_OID_LF, GIT_OID_SHA1)); cl_assert_equal_oid(&oid, &entry->id); } @@ -316,7 +317,7 @@ void test_index_crlf__autocrlf_true_text_auto_attr(void) cl_git_pass(git_index_add_bypath(g_index, "newfile.txt")); entry = git_index_get_bypath(g_index, "newfile.txt", 0); - cl_git_pass(git_oid_fromstr(&oid, FILE_OID_LF)); + cl_git_pass(git_oid__fromstr(&oid, FILE_OID_LF, GIT_OID_SHA1)); cl_assert_equal_oid(&oid, &entry->id); } @@ -335,7 +336,7 @@ void test_index_crlf__autocrlf_input_text_auto_attr(void) cl_git_pass(git_index_add_bypath(g_index, "newfile.txt")); entry = git_index_get_bypath(g_index, "newfile.txt", 0); - cl_git_pass(git_oid_fromstr(&oid, FILE_OID_LF)); + cl_git_pass(git_oid__fromstr(&oid, FILE_OID_LF, GIT_OID_SHA1)); cl_assert_equal_oid(&oid, &entry->id); } @@ -355,7 +356,7 @@ void test_index_crlf__safecrlf_true_autocrlf_input_text_auto_attr(void) entry = git_index_get_bypath(g_index, "newfile.txt", 0); cl_assert(entry); - cl_git_pass(git_oid_fromstr(&oid, FILE_OID_LF)); + cl_git_pass(git_oid__fromstr(&oid, FILE_OID_LF, GIT_OID_SHA1)); cl_assert_equal_oid(&oid, &entry->id); cl_git_mkfile("./crlf/newfile2.txt", FILE_CONTENTS_CRLF); @@ -376,7 +377,7 @@ void test_index_crlf__safecrlf_true_autocrlf_input_text__no_attr(void) entry = git_index_get_bypath(g_index, "newfile.txt", 0); cl_assert(entry); - cl_git_pass(git_oid_fromstr(&oid, FILE_OID_LF)); + cl_git_pass(git_oid__fromstr(&oid, FILE_OID_LF, GIT_OID_SHA1)); cl_assert_equal_oid(&oid, &entry->id); cl_git_mkfile("./crlf/newfile2.txt", FILE_CONTENTS_CRLF); diff --git a/tests/libgit2/index/names.c b/tests/libgit2/index/names.c index 369318b03..2a41100aa 100644 --- a/tests/libgit2/index/names.c +++ b/tests/libgit2/index/names.c @@ -42,21 +42,21 @@ static void index_add_conflicts(void) entry.path = conflict[0]; entry.mode = GIT_FILEMODE_BLOB; GIT_INDEX_ENTRY_STAGE_SET(&entry, GIT_INDEX_STAGE_ANCESTOR); - git_oid_fromstr(&entry.id, "1f85ca51b8e0aac893a621b61a9c2661d6aa6d81"); + git_oid__fromstr(&entry.id, "1f85ca51b8e0aac893a621b61a9c2661d6aa6d81", GIT_OID_SHA1); cl_git_pass(git_index_add(repo_index, &entry)); /* ours */ entry.path = conflict[1]; entry.mode = GIT_FILEMODE_BLOB; GIT_INDEX_ENTRY_STAGE_SET(&entry, GIT_INDEX_STAGE_OURS); - git_oid_fromstr(&entry.id, "1f85ca51b8e0aac893a621b61a9c2661d6aa6d81"); + git_oid__fromstr(&entry.id, "1f85ca51b8e0aac893a621b61a9c2661d6aa6d81", GIT_OID_SHA1); cl_git_pass(git_index_add(repo_index, &entry)); /* theirs */ entry.path = conflict[2]; entry.mode = GIT_FILEMODE_BLOB; GIT_INDEX_ENTRY_STAGE_SET(&entry, GIT_INDEX_STAGE_THEIRS); - git_oid_fromstr(&entry.id, "1f85ca51b8e0aac893a621b61a9c2661d6aa6d81"); + git_oid__fromstr(&entry.id, "1f85ca51b8e0aac893a621b61a9c2661d6aa6d81", GIT_OID_SHA1); cl_git_pass(git_index_add(repo_index, &entry)); } } diff --git a/tests/libgit2/index/read_index.c b/tests/libgit2/index/read_index.c index 836c12b0e..ac03cf177 100644 --- a/tests/libgit2/index/read_index.c +++ b/tests/libgit2/index/read_index.c @@ -49,7 +49,7 @@ void test_index_read_index__maintains_stat_cache(void) /* add a new entry that will not have stat data */ memset(&new_entry, 0, sizeof(git_index_entry)); new_entry.path = "Hello"; - git_oid_fromstr(&new_entry.id, "0123456789012345678901234567890123456789"); + git_oid__fromstr(&new_entry.id, "0123456789012345678901234567890123456789", GIT_OID_SHA1); new_entry.file_size = 1234; new_entry.mode = 0100644; cl_git_pass(git_index_add(new_index, &new_entry)); @@ -79,7 +79,7 @@ static bool roundtrip_with_read_index(const char *tree_idstr) git_tree *tree; git_index *tree_index; - cl_git_pass(git_oid_fromstr(&tree_id, tree_idstr)); + cl_git_pass(git_oid__fromstr(&tree_id, tree_idstr, GIT_OID_SHA1)); cl_git_pass(git_tree_lookup(&tree, _repo, &tree_id)); cl_git_pass(git_index_new(&tree_index)); cl_git_pass(git_index_read_tree(tree_index, tree)); @@ -111,7 +111,7 @@ void test_index_read_index__read_and_writes(void) git_tree *tree; git_index *tree_index, *new_index; - cl_git_pass(git_oid_fromstr(&tree_id, "ae90f12eea699729ed24555e40b9fd669da12a12")); + cl_git_pass(git_oid__fromstr(&tree_id, "ae90f12eea699729ed24555e40b9fd669da12a12", GIT_OID_SHA1)); cl_git_pass(git_tree_lookup(&tree, _repo, &tree_id)); cl_git_pass(git_index_new(&tree_index)); cl_git_pass(git_index_read_tree(tree_index, tree)); @@ -148,17 +148,17 @@ static void add_conflicts(git_index *index, const char *filename) ancestor_entry.path = filename; ancestor_entry.mode = 0100644; GIT_INDEX_ENTRY_STAGE_SET(&ancestor_entry, 1); - git_oid_fromstr(&ancestor_entry.id, ancestor_ids[conflict_idx]); + git_oid__fromstr(&ancestor_entry.id, ancestor_ids[conflict_idx], GIT_OID_SHA1); our_entry.path = filename; our_entry.mode = 0100644; GIT_INDEX_ENTRY_STAGE_SET(&our_entry, 2); - git_oid_fromstr(&our_entry.id, our_ids[conflict_idx]); + git_oid__fromstr(&our_entry.id, our_ids[conflict_idx], GIT_OID_SHA1); their_entry.path = filename; their_entry.mode = 0100644; GIT_INDEX_ENTRY_STAGE_SET(&ancestor_entry, 2); - git_oid_fromstr(&their_entry.id, their_ids[conflict_idx]); + git_oid__fromstr(&their_entry.id, their_ids[conflict_idx], GIT_OID_SHA1); cl_git_pass(git_index_conflict_add(index, &ancestor_entry, &our_entry, &their_entry)); @@ -172,7 +172,7 @@ void test_index_read_index__handles_conflicts(void) git_index_conflict_iterator *conflict_iterator; const git_index_entry *ancestor, *ours, *theirs; - cl_git_pass(git_oid_fromstr(&tree_id, "ae90f12eea699729ed24555e40b9fd669da12a12")); + cl_git_pass(git_oid__fromstr(&tree_id, "ae90f12eea699729ed24555e40b9fd669da12a12", GIT_OID_SHA1)); cl_git_pass(git_tree_lookup(&tree, _repo, &tree_id)); cl_git_pass(git_index_new(&index)); cl_git_pass(git_index_new(&new_index)); diff --git a/tests/libgit2/index/rename.c b/tests/libgit2/index/rename.c index 86eaf0053..9b132cb61 100644 --- a/tests/libgit2/index/rename.c +++ b/tests/libgit2/index/rename.c @@ -22,7 +22,7 @@ void test_index_rename__single_file(void) cl_git_pass(git_index_add_bypath(index, "lame.name.txt")); cl_assert(git_index_entrycount(index) == 1); - cl_git_pass(git_oid_fromstr(&expected, "d4fa8600b4f37d7516bef4816ae2c64dbf029e3a")); + cl_git_pass(git_oid__fromstr(&expected, "d4fa8600b4f37d7516bef4816ae2c64dbf029e3a", GIT_OID_SHA1)); cl_assert(!git_index_find(&position, index, "lame.name.txt")); diff --git a/tests/libgit2/index/reuc.c b/tests/libgit2/index/reuc.c index 1f95c4136..7d8766c57 100644 --- a/tests/libgit2/index/reuc.c +++ b/tests/libgit2/index/reuc.c @@ -38,9 +38,9 @@ void test_index_reuc__add(void) git_oid ancestor_oid, our_oid, their_oid; const git_index_reuc_entry *reuc; - git_oid_fromstr(&ancestor_oid, ONE_ANCESTOR_OID); - git_oid_fromstr(&our_oid, ONE_OUR_OID); - git_oid_fromstr(&their_oid, ONE_THEIR_OID); + git_oid__fromstr(&ancestor_oid, ONE_ANCESTOR_OID, GIT_OID_SHA1); + git_oid__fromstr(&our_oid, ONE_OUR_OID, GIT_OID_SHA1); + git_oid__fromstr(&their_oid, ONE_THEIR_OID, GIT_OID_SHA1); cl_git_pass(git_index_reuc_add(repo_index, "newfile.txt", 0100644, &ancestor_oid, @@ -66,8 +66,8 @@ void test_index_reuc__add_no_ancestor(void) const git_index_reuc_entry *reuc; memset(&ancestor_oid, 0x0, sizeof(git_oid)); - git_oid_fromstr(&our_oid, ONE_OUR_OID); - git_oid_fromstr(&their_oid, ONE_THEIR_OID); + git_oid__fromstr(&our_oid, ONE_OUR_OID, GIT_OID_SHA1); + git_oid__fromstr(&their_oid, ONE_THEIR_OID, GIT_OID_SHA1); cl_git_pass(git_index_reuc_add(repo_index, "newfile.txt", 0, NULL, @@ -100,11 +100,11 @@ void test_index_reuc__read_bypath(void) cl_assert(reuc->mode[0] == 0100644); cl_assert(reuc->mode[1] == 0100644); cl_assert(reuc->mode[2] == 0100644); - git_oid_fromstr(&oid, TWO_ANCESTOR_OID); + git_oid__fromstr(&oid, TWO_ANCESTOR_OID, GIT_OID_SHA1); cl_assert_equal_oid(&reuc->oid[0], &oid); - git_oid_fromstr(&oid, TWO_OUR_OID); + git_oid__fromstr(&oid, TWO_OUR_OID, GIT_OID_SHA1); cl_assert_equal_oid(&reuc->oid[1], &oid); - git_oid_fromstr(&oid, TWO_THEIR_OID); + git_oid__fromstr(&oid, TWO_THEIR_OID, GIT_OID_SHA1); cl_assert_equal_oid(&reuc->oid[2], &oid); cl_assert(reuc = git_index_reuc_get_bypath(repo_index, "one.txt")); @@ -113,11 +113,11 @@ void test_index_reuc__read_bypath(void) cl_assert(reuc->mode[0] == 0100644); cl_assert(reuc->mode[1] == 0100644); cl_assert(reuc->mode[2] == 0100644); - git_oid_fromstr(&oid, ONE_ANCESTOR_OID); + git_oid__fromstr(&oid, ONE_ANCESTOR_OID, GIT_OID_SHA1); cl_assert_equal_oid(&reuc->oid[0], &oid); - git_oid_fromstr(&oid, ONE_OUR_OID); + git_oid__fromstr(&oid, ONE_OUR_OID, GIT_OID_SHA1); cl_assert_equal_oid(&reuc->oid[1], &oid); - git_oid_fromstr(&oid, ONE_THEIR_OID); + git_oid__fromstr(&oid, ONE_THEIR_OID, GIT_OID_SHA1); cl_assert_equal_oid(&reuc->oid[2], &oid); } @@ -145,11 +145,11 @@ void test_index_reuc__ignore_case(void) cl_assert(reuc->mode[0] == 0100644); cl_assert(reuc->mode[1] == 0100644); cl_assert(reuc->mode[2] == 0100644); - git_oid_fromstr(&oid, TWO_ANCESTOR_OID); + git_oid__fromstr(&oid, TWO_ANCESTOR_OID, GIT_OID_SHA1); cl_assert_equal_oid(&reuc->oid[0], &oid); - git_oid_fromstr(&oid, TWO_OUR_OID); + git_oid__fromstr(&oid, TWO_OUR_OID, GIT_OID_SHA1); cl_assert_equal_oid(&reuc->oid[1], &oid); - git_oid_fromstr(&oid, TWO_THEIR_OID); + git_oid__fromstr(&oid, TWO_THEIR_OID, GIT_OID_SHA1); cl_assert_equal_oid(&reuc->oid[2], &oid); } @@ -166,11 +166,11 @@ void test_index_reuc__read_byindex(void) cl_assert(reuc->mode[0] == 0100644); cl_assert(reuc->mode[1] == 0100644); cl_assert(reuc->mode[2] == 0100644); - git_oid_fromstr(&oid, ONE_ANCESTOR_OID); + git_oid__fromstr(&oid, ONE_ANCESTOR_OID, GIT_OID_SHA1); cl_assert_equal_oid(&reuc->oid[0], &oid); - git_oid_fromstr(&oid, ONE_OUR_OID); + git_oid__fromstr(&oid, ONE_OUR_OID, GIT_OID_SHA1); cl_assert_equal_oid(&reuc->oid[1], &oid); - git_oid_fromstr(&oid, ONE_THEIR_OID); + git_oid__fromstr(&oid, ONE_THEIR_OID, GIT_OID_SHA1); cl_assert_equal_oid(&reuc->oid[2], &oid); cl_assert(reuc = git_index_reuc_get_byindex(repo_index, 1)); @@ -179,11 +179,11 @@ void test_index_reuc__read_byindex(void) cl_assert(reuc->mode[0] == 0100644); cl_assert(reuc->mode[1] == 0100644); cl_assert(reuc->mode[2] == 0100644); - git_oid_fromstr(&oid, TWO_ANCESTOR_OID); + git_oid__fromstr(&oid, TWO_ANCESTOR_OID, GIT_OID_SHA1); cl_assert_equal_oid(&reuc->oid[0], &oid); - git_oid_fromstr(&oid, TWO_OUR_OID); + git_oid__fromstr(&oid, TWO_OUR_OID, GIT_OID_SHA1); cl_assert_equal_oid(&reuc->oid[1], &oid); - git_oid_fromstr(&oid, TWO_THEIR_OID); + git_oid__fromstr(&oid, TWO_THEIR_OID, GIT_OID_SHA1); cl_assert_equal_oid(&reuc->oid[2], &oid); } @@ -200,9 +200,9 @@ void test_index_reuc__updates_existing(void) index_caps |= GIT_INDEX_CAPABILITY_IGNORE_CASE; cl_git_pass(git_index_set_caps(repo_index, index_caps)); - git_oid_fromstr(&ancestor_oid, TWO_ANCESTOR_OID); - git_oid_fromstr(&our_oid, TWO_OUR_OID); - git_oid_fromstr(&their_oid, TWO_THEIR_OID); + git_oid__fromstr(&ancestor_oid, TWO_ANCESTOR_OID, GIT_OID_SHA1); + git_oid__fromstr(&our_oid, TWO_OUR_OID, GIT_OID_SHA1); + git_oid__fromstr(&their_oid, TWO_THEIR_OID, GIT_OID_SHA1); cl_git_pass(git_index_reuc_add(repo_index, "two.txt", 0100644, &ancestor_oid, @@ -219,11 +219,11 @@ void test_index_reuc__updates_existing(void) cl_assert(reuc = git_index_reuc_get_byindex(repo_index, 0)); cl_assert_equal_s("TWO.txt", reuc->path); - git_oid_fromstr(&oid, TWO_OUR_OID); + git_oid__fromstr(&oid, TWO_OUR_OID, GIT_OID_SHA1); cl_assert_equal_oid(&reuc->oid[0], &oid); - git_oid_fromstr(&oid, TWO_THEIR_OID); + git_oid__fromstr(&oid, TWO_THEIR_OID, GIT_OID_SHA1); cl_assert_equal_oid(&reuc->oid[1], &oid); - git_oid_fromstr(&oid, TWO_ANCESTOR_OID); + git_oid__fromstr(&oid, TWO_ANCESTOR_OID, GIT_OID_SHA1); cl_assert_equal_oid(&reuc->oid[2], &oid); } @@ -245,11 +245,11 @@ void test_index_reuc__remove(void) cl_assert(reuc->mode[0] == 0100644); cl_assert(reuc->mode[1] == 0100644); cl_assert(reuc->mode[2] == 0100644); - git_oid_fromstr(&oid, TWO_ANCESTOR_OID); + git_oid__fromstr(&oid, TWO_ANCESTOR_OID, GIT_OID_SHA1); cl_assert_equal_oid(&reuc->oid[0], &oid); - git_oid_fromstr(&oid, TWO_OUR_OID); + git_oid__fromstr(&oid, TWO_OUR_OID, GIT_OID_SHA1); cl_assert_equal_oid(&reuc->oid[1], &oid); - git_oid_fromstr(&oid, TWO_THEIR_OID); + git_oid__fromstr(&oid, TWO_THEIR_OID, GIT_OID_SHA1); cl_assert_equal_oid(&reuc->oid[2], &oid); } @@ -261,18 +261,18 @@ void test_index_reuc__write(void) git_index_clear(repo_index); /* Write out of order to ensure sorting is correct */ - git_oid_fromstr(&ancestor_oid, TWO_ANCESTOR_OID); - git_oid_fromstr(&our_oid, TWO_OUR_OID); - git_oid_fromstr(&their_oid, TWO_THEIR_OID); + git_oid__fromstr(&ancestor_oid, TWO_ANCESTOR_OID, GIT_OID_SHA1); + git_oid__fromstr(&our_oid, TWO_OUR_OID, GIT_OID_SHA1); + git_oid__fromstr(&their_oid, TWO_THEIR_OID, GIT_OID_SHA1); cl_git_pass(git_index_reuc_add(repo_index, "two.txt", 0100644, &ancestor_oid, 0100644, &our_oid, 0100644, &their_oid)); - git_oid_fromstr(&ancestor_oid, ONE_ANCESTOR_OID); - git_oid_fromstr(&our_oid, ONE_OUR_OID); - git_oid_fromstr(&their_oid, ONE_THEIR_OID); + git_oid__fromstr(&ancestor_oid, ONE_ANCESTOR_OID, GIT_OID_SHA1); + git_oid__fromstr(&our_oid, ONE_OUR_OID, GIT_OID_SHA1); + git_oid__fromstr(&their_oid, ONE_THEIR_OID, GIT_OID_SHA1); cl_git_pass(git_index_reuc_add(repo_index, "one.txt", 0100644, &ancestor_oid, diff --git a/tests/libgit2/index/tests.c b/tests/libgit2/index/tests.c index 205d12e5b..da3ff6dd7 100644 --- a/tests/libgit2/index/tests.c +++ b/tests/libgit2/index/tests.c @@ -259,7 +259,7 @@ void test_index_tests__add(void) * This has been generated by executing the following * $ echo "hey there" | git hash-object --stdin */ - cl_git_pass(git_oid_fromstr(&id1, "a8233120f6ad708f843d861ce2b7228ec4e3dec6")); + cl_git_pass(git_oid__fromstr(&id1, "a8233120f6ad708f843d861ce2b7228ec4e3dec6", GIT_OID_SHA1)); /* Add the new file to the index */ cl_git_pass(git_index_add_bypath(index, "test.txt")); @@ -304,7 +304,7 @@ void test_index_tests__add_frombuffer(void) * This has been generated by executing the following * $ echo "hey there" | git hash-object --stdin */ - cl_git_pass(git_oid_fromstr(&id1, "a8233120f6ad708f843d861ce2b7228ec4e3dec6")); + cl_git_pass(git_oid__fromstr(&id1, "a8233120f6ad708f843d861ce2b7228ec4e3dec6", GIT_OID_SHA1)); /* Add the new file to the index */ memset(&entry, 0x0, sizeof(git_index_entry)); @@ -447,7 +447,7 @@ void test_index_tests__add_frombuffer_reset_entry(void) * This has been generated by executing the following * $ echo "hey there" | git hash-object --stdin */ - cl_git_pass(git_oid_fromstr(&id1, "a8233120f6ad708f843d861ce2b7228ec4e3dec6")); + cl_git_pass(git_oid__fromstr(&id1, "a8233120f6ad708f843d861ce2b7228ec4e3dec6", GIT_OID_SHA1)); cl_git_pass(git_index_add_bypath(index, "test.txt")); @@ -511,7 +511,7 @@ void test_index_tests__add_issue_1397(void) * This has been generated by executing the following * $ git hash-object crlf_file.txt */ - cl_git_pass(git_oid_fromstr(&id1, "8312e0889a9cbab77c732b6bc39b51a683e3a318")); + cl_git_pass(git_oid__fromstr(&id1, "8312e0889a9cbab77c732b6bc39b51a683e3a318", GIT_OID_SHA1)); /* Make sure the initial SHA-1 is correct */ cl_assert((entry = git_index_get_bypath(index, "crlf_file.txt", 0)) != NULL); @@ -600,7 +600,7 @@ static void assert_add_fails(git_repository *repo, const char *fn) entry.path = fn; entry.mode = GIT_FILEMODE_BLOB; - cl_git_pass(git_oid_fromstr(&entry.id, "e69de29bb2d1d6434b8b29ae775ad8c2e48c5391")); + cl_git_pass(git_oid__fromstr(&entry.id, "e69de29bb2d1d6434b8b29ae775ad8c2e48c5391", GIT_OID_SHA1)); cl_git_fail(git_index_add(index, &entry)); @@ -705,7 +705,7 @@ void test_index_tests__write_tree_invalid_unowned_index(void) cl_git_pass(git_index_new(&idx)); - cl_git_pass(git_oid_fromstr(&entry.id, "8312e0a89a9cbab77c732b6bc39b51a783e3a318")); + cl_git_pass(git_oid__fromstr(&entry.id, "8312e0a89a9cbab77c732b6bc39b51a783e3a318", GIT_OID_SHA1)); entry.path = "foo"; entry.mode = GIT_FILEMODE_BLOB; cl_git_pass(git_index_add(idx, &entry)); @@ -1147,12 +1147,12 @@ void test_index_tests__can_modify_while_iterating(void) * ensure that our iterator is backed by a snapshot and thus returns * the number of entries from when the iterator was created. */ - cl_git_pass(git_oid_fromstr(&new_entry.id, "8312e0a89a9cbab77c732b6bc39b51a783e3a318")); + cl_git_pass(git_oid__fromstr(&new_entry.id, "8312e0a89a9cbab77c732b6bc39b51a783e3a318", GIT_OID_SHA1)); new_entry.path = "newfile"; new_entry.mode = GIT_FILEMODE_BLOB; cl_git_pass(git_index_add(index, &new_entry)); - cl_git_pass(git_oid_fromstr(&new_entry.id, "4141414141414141414141414141414141414141")); + cl_git_pass(git_oid__fromstr(&new_entry.id, "4141414141414141414141414141414141414141", GIT_OID_SHA1)); new_entry.path = "Makefile"; new_entry.mode = GIT_FILEMODE_BLOB; cl_git_pass(git_index_add(index, &new_entry)); diff --git a/tests/libgit2/iterator/index.c b/tests/libgit2/iterator/index.c index 7218b4f75..a0083479d 100644 --- a/tests/libgit2/iterator/index.c +++ b/tests/libgit2/iterator/index.c @@ -52,7 +52,7 @@ static void index_iterator_test( if (expected_oids != NULL) { git_oid oid; - cl_git_pass(git_oid_fromstr(&oid, expected_oids[count])); + cl_git_pass(git_oid__fromstr(&oid, expected_oids[count], GIT_OID_SHA1)); cl_assert_equal_oid(&oid, &entry->id); } @@ -999,7 +999,7 @@ static void create_paths(git_index *index, const char *root, int depth) memset(&entry, 0, sizeof(git_index_entry)); entry.path = fullpath.ptr; entry.mode = GIT_FILEMODE_BLOB; - git_oid_fromstr(&entry.id, "d44e18fb93b7107b5cd1b95d601591d77869a1b6"); + git_oid__fromstr(&entry.id, "d44e18fb93b7107b5cd1b95d601591d77869a1b6", GIT_OID_SHA1); cl_git_pass(git_index_add(index, &entry)); } else if (depth > 0) { @@ -1296,17 +1296,17 @@ static void add_conflict( ancestor.path = ancestor_path; ancestor.mode = GIT_FILEMODE_BLOB; - git_oid_fromstr(&ancestor.id, "d44e18fb93b7107b5cd1b95d601591d77869a1b6"); + git_oid__fromstr(&ancestor.id, "d44e18fb93b7107b5cd1b95d601591d77869a1b6", GIT_OID_SHA1); GIT_INDEX_ENTRY_STAGE_SET(&ancestor, 1); ours.path = our_path; ours.mode = GIT_FILEMODE_BLOB; - git_oid_fromstr(&ours.id, "d44e18fb93b7107b5cd1b95d601591d77869a1b6"); + git_oid__fromstr(&ours.id, "d44e18fb93b7107b5cd1b95d601591d77869a1b6", GIT_OID_SHA1); GIT_INDEX_ENTRY_STAGE_SET(&ours, 2); theirs.path = their_path; theirs.mode = GIT_FILEMODE_BLOB; - git_oid_fromstr(&theirs.id, "d44e18fb93b7107b5cd1b95d601591d77869a1b6"); + git_oid__fromstr(&theirs.id, "d44e18fb93b7107b5cd1b95d601591d77869a1b6", GIT_OID_SHA1); GIT_INDEX_ENTRY_STAGE_SET(&theirs, 3); cl_git_pass(git_index_conflict_add(index, &ancestor, &ours, &theirs)); diff --git a/tests/libgit2/iterator/tree.c b/tests/libgit2/iterator/tree.c index 06a920a18..7dfee28be 100644 --- a/tests/libgit2/iterator/tree.c +++ b/tests/libgit2/iterator/tree.c @@ -675,7 +675,7 @@ void test_iterator_tree__case_conflicts_0(void) g_repo = cl_git_sandbox_init("icase"); - cl_git_pass(git_oid_fromstr(&blob_id, blob_sha)); /* lookup blob */ + cl_git_pass(git_oid__fromstr(&blob_id, blob_sha, GIT_OID_SHA1)); /* lookup blob */ /* create tree with: A/1.file, A/3.file, a/2.file, a/4.file */ build_test_tree( @@ -729,7 +729,7 @@ void test_iterator_tree__case_conflicts_1(void) g_repo = cl_git_sandbox_init("icase"); - cl_git_pass(git_oid_fromstr(&blob_id, blob_sha)); /* lookup blob */ + cl_git_pass(git_oid__fromstr(&blob_id, blob_sha, GIT_OID_SHA1)); /* lookup blob */ /* create: A/a A/b/1 A/c a/a a/b a/C */ build_test_tree(&Ab_id, g_repo, "b|1|", &blob_id); @@ -798,7 +798,7 @@ void test_iterator_tree__case_conflicts_2(void) g_repo = cl_git_sandbox_init("icase"); - cl_git_pass(git_oid_fromstr(&blob_id, blob_sha)); /* lookup blob */ + cl_git_pass(git_oid__fromstr(&blob_id, blob_sha, GIT_OID_SHA1)); /* lookup blob */ build_test_tree(&d1, g_repo, "b|16|,b|foo|", &blob_id, &blob_id); build_test_tree(&d2, g_repo, "b|15|,b|FOO|", &blob_id, &blob_id); diff --git a/tests/libgit2/iterator/workdir.c b/tests/libgit2/iterator/workdir.c index 86b847cab..7634997e1 100644 --- a/tests/libgit2/iterator/workdir.c +++ b/tests/libgit2/iterator/workdir.c @@ -1481,7 +1481,7 @@ void test_iterator_workdir__hash_when_requested(void) git_iterator *iter; const git_index_entry *entry; git_iterator_options iter_opts = GIT_ITERATOR_OPTIONS_INIT; - git_oid expected_id = {{0}}; + git_oid expected_id = GIT_OID_SHA1_ZERO; size_t i; struct merge_index_entry expected[] = { @@ -1514,7 +1514,7 @@ void test_iterator_workdir__hash_when_requested(void) for (i = 0; i < sizeof(expected) / sizeof(struct merge_index_entry); i++) { cl_git_pass(git_iterator_advance(&entry, iter)); - cl_git_pass(git_oid_fromstr(&expected_id, expected[i].oid_str)); + cl_git_pass(git_oid__fromstr(&expected_id, expected[i].oid_str, GIT_OID_SHA1)); cl_assert_equal_oid(&expected_id, &entry->id); cl_assert_equal_s(expected[i].path, entry->path); } diff --git a/tests/libgit2/merge/driver.c b/tests/libgit2/merge/driver.c index b7d320cbb..fd73c3770 100644 --- a/tests/libgit2/merge/driver.c +++ b/tests/libgit2/merge/driver.c @@ -22,7 +22,7 @@ void test_merge_driver__initialize(void) repo = cl_git_sandbox_init(TEST_REPO_PATH); git_repository_index(&repo_index, repo); - git_oid_fromstr(&automergeable_id, AUTOMERGEABLE_IDSTR); + git_oid__fromstr(&automergeable_id, AUTOMERGEABLE_IDSTR, GIT_OID_SHA1); /* Ensure that the user's merge.conflictstyle doesn't interfere */ cl_git_pass(git_repository_config(&cfg, repo)); @@ -145,7 +145,7 @@ static void merge_branch(void) git_oid their_id; git_annotated_commit *their_head; - cl_git_pass(git_oid_fromstr(&their_id, BRANCH_ID)); + cl_git_pass(git_oid__fromstr(&their_id, BRANCH_ID, GIT_OID_SHA1)); cl_git_pass(git_annotated_commit_lookup(&their_head, repo, &their_id)); cl_git_pass(git_merge(repo, (const git_annotated_commit **)&their_head, @@ -299,7 +299,7 @@ void test_merge_driver__default_can_be_specified(void) merge_opts.default_driver = "custom"; - cl_git_pass(git_oid_fromstr(&their_id, BRANCH_ID)); + cl_git_pass(git_oid__fromstr(&their_id, BRANCH_ID, GIT_OID_SHA1)); cl_git_pass(git_annotated_commit_lookup(&their_head, repo, &their_id)); cl_git_pass(git_merge(repo, (const git_annotated_commit **)&their_head, diff --git a/tests/libgit2/merge/files.c b/tests/libgit2/merge/files.c index 6296f3b7b..6c1c2e13f 100644 --- a/tests/libgit2/merge/files.c +++ b/tests/libgit2/merge/files.c @@ -149,15 +149,15 @@ void test_merge_files__automerge_from_index(void) git_merge_file_result result = {0}; git_index_entry ancestor, ours, theirs; - git_oid_fromstr(&ancestor.id, "6212c31dab5e482247d7977e4f0dd3601decf13b"); + git_oid__fromstr(&ancestor.id, "6212c31dab5e482247d7977e4f0dd3601decf13b", GIT_OID_SHA1); ancestor.path = "automergeable.txt"; ancestor.mode = 0100644; - git_oid_fromstr(&ours.id, "ee3fa1b8c00aff7fe02065fdb50864bb0d932ccf"); + git_oid__fromstr(&ours.id, "ee3fa1b8c00aff7fe02065fdb50864bb0d932ccf", GIT_OID_SHA1); ours.path = "automergeable.txt"; ours.mode = 0100755; - git_oid_fromstr(&theirs.id, "058541fc37114bfc1dddf6bd6bffc7fae5c2e6fe"); + git_oid__fromstr(&theirs.id, "058541fc37114bfc1dddf6bd6bffc7fae5c2e6fe", GIT_OID_SHA1); theirs.path = "newname.txt"; theirs.mode = 0100644; diff --git a/tests/libgit2/merge/merge_helpers.c b/tests/libgit2/merge/merge_helpers.c index ce3cd229b..1406987e5 100644 --- a/tests/libgit2/merge/merge_helpers.c +++ b/tests/libgit2/merge/merge_helpers.c @@ -165,7 +165,7 @@ static int index_entry_eq_merge_index_entry(const struct merge_index_entry *expe bool test_oid; if (strlen(expected->oid_str) != 0) { - cl_git_pass(git_oid_fromstr(&expected_oid, expected->oid_str)); + cl_git_pass(git_oid__fromstr(&expected_oid, expected->oid_str, GIT_OID_SHA1)); test_oid = 1; } else test_oid = 0; @@ -304,21 +304,21 @@ int merge_test_reuc(git_index *index, const struct merge_reuc_entry expected[], return 0; if (expected[i].ancestor_mode > 0) { - cl_git_pass(git_oid_fromstr(&expected_oid, expected[i].ancestor_oid_str)); + cl_git_pass(git_oid__fromstr(&expected_oid, expected[i].ancestor_oid_str, GIT_OID_SHA1)); if (git_oid_cmp(&reuc_entry->oid[0], &expected_oid) != 0) return 0; } if (expected[i].our_mode > 0) { - cl_git_pass(git_oid_fromstr(&expected_oid, expected[i].our_oid_str)); + cl_git_pass(git_oid__fromstr(&expected_oid, expected[i].our_oid_str, GIT_OID_SHA1)); if (git_oid_cmp(&reuc_entry->oid[1], &expected_oid) != 0) return 0; } if (expected[i].their_mode > 0) { - cl_git_pass(git_oid_fromstr(&expected_oid, expected[i].their_oid_str)); + cl_git_pass(git_oid__fromstr(&expected_oid, expected[i].their_oid_str, GIT_OID_SHA1)); if (git_oid_cmp(&reuc_entry->oid[2], &expected_oid) != 0) return 0; @@ -353,7 +353,7 @@ int merge_test_workdir(git_repository *repo, const struct merge_index_entry expe for (i = 0; i < expected_len; i++) { git_blob_create_from_workdir(&actual_oid, repo, expected[i].path); - git_oid_fromstr(&expected_oid, expected[i].oid_str); + git_oid__fromstr(&expected_oid, expected[i].oid_str, GIT_OID_SHA1); if (git_oid_cmp(&actual_oid, &expected_oid) != 0) return 0; diff --git a/tests/libgit2/merge/merge_helpers.h b/tests/libgit2/merge/merge_helpers.h index 339812ba5..72c6e61f7 100644 --- a/tests/libgit2/merge/merge_helpers.h +++ b/tests/libgit2/merge/merge_helpers.h @@ -6,7 +6,7 @@ struct merge_index_entry { uint16_t mode; - char oid_str[GIT_OID_HEXSZ+1]; + char oid_str[GIT_OID_SHA1_HEXSIZE+1]; int stage; char path[128]; }; @@ -27,9 +27,9 @@ struct merge_reuc_entry { unsigned int ancestor_mode; unsigned int our_mode; unsigned int their_mode; - char ancestor_oid_str[GIT_OID_HEXSZ+1]; - char our_oid_str[GIT_OID_HEXSZ+1]; - char their_oid_str[GIT_OID_HEXSZ+1]; + char ancestor_oid_str[GIT_OID_SHA1_HEXSIZE+1]; + char our_oid_str[GIT_OID_SHA1_HEXSIZE+1]; + char their_oid_str[GIT_OID_SHA1_HEXSIZE+1]; }; struct merge_index_conflict_data { diff --git a/tests/libgit2/merge/trees/renames.c b/tests/libgit2/merge/trees/renames.c index 26f6d3306..a27945ee0 100644 --- a/tests/libgit2/merge/trees/renames.c +++ b/tests/libgit2/merge/trees/renames.c @@ -286,7 +286,7 @@ void test_merge_trees_renames__cache_recomputation(void) void *data; size_t i; - cl_git_pass(git_oid_fromstr(&blob, "a2d8d1824c68541cca94ffb90f79291eba495921")); + cl_git_pass(git_oid__fromstr(&blob, "a2d8d1824c68541cca94ffb90f79291eba495921", GIT_OID_SHA1)); /* * Create a 50MB blob that consists of NUL bytes only. It is important diff --git a/tests/libgit2/merge/trees/treediff.c b/tests/libgit2/merge/trees/treediff.c index cd2cf7827..094018d3c 100644 --- a/tests/libgit2/merge/trees/treediff.c +++ b/tests/libgit2/merge/trees/treediff.c @@ -61,9 +61,9 @@ static void test_find_differences( opts.metric->similarity = git_diff_find_similar__calc_similarity; opts.metric->payload = (void *)GIT_HASHSIG_SMART_WHITESPACE; - cl_git_pass(git_oid_fromstr(&ancestor_oid, ancestor_oidstr)); - cl_git_pass(git_oid_fromstr(&ours_oid, ours_oidstr)); - cl_git_pass(git_oid_fromstr(&theirs_oid, theirs_oidstr)); + cl_git_pass(git_oid__fromstr(&ancestor_oid, ancestor_oidstr, GIT_OID_SHA1)); + cl_git_pass(git_oid__fromstr(&ours_oid, ours_oidstr, GIT_OID_SHA1)); + cl_git_pass(git_oid__fromstr(&theirs_oid, theirs_oidstr, GIT_OID_SHA1)); cl_git_pass(git_tree_lookup(&ancestor_tree, repo, &ancestor_oid)); cl_git_pass(git_tree_lookup(&ours_tree, repo, &ours_oid)); diff --git a/tests/libgit2/merge/trees/trivial.c b/tests/libgit2/merge/trees/trivial.c index dce392c86..287a53cfe 100644 --- a/tests/libgit2/merge/trees/trivial.c +++ b/tests/libgit2/merge/trees/trivial.c @@ -258,7 +258,7 @@ void test_merge_trees_trivial__13(void) cl_git_pass(merge_trivial(&result, "trivial-13", "trivial-13-branch")); cl_assert(entry = git_index_get_bypath(result, "modified-in-13.txt", 0)); - cl_git_pass(git_oid_fromstr(&expected_oid, "1cff9ec6a47a537380dedfdd17c9e76d74259a2b")); + cl_git_pass(git_oid__fromstr(&expected_oid, "1cff9ec6a47a537380dedfdd17c9e76d74259a2b", GIT_OID_SHA1)); cl_assert_equal_oid(&expected_oid, &entry->id); cl_assert(git_index_reuc_entrycount(result) == 0); @@ -277,7 +277,7 @@ void test_merge_trees_trivial__14(void) cl_git_pass(merge_trivial(&result, "trivial-14", "trivial-14-branch")); cl_assert(entry = git_index_get_bypath(result, "modified-in-14-branch.txt", 0)); - cl_git_pass(git_oid_fromstr(&expected_oid, "26153a3ff3649b6c2bb652d3f06878c6e0a172f9")); + cl_git_pass(git_oid__fromstr(&expected_oid, "26153a3ff3649b6c2bb652d3f06878c6e0a172f9", GIT_OID_SHA1)); cl_assert(git_oid_cmp(&entry->id, &expected_oid) == 0); cl_assert(git_index_reuc_entrycount(result) == 0); diff --git a/tests/libgit2/merge/workdir/dirty.c b/tests/libgit2/merge/workdir/dirty.c index b9c2ad033..36b42a103 100644 --- a/tests/libgit2/merge/workdir/dirty.c +++ b/tests/libgit2/merge/workdir/dirty.c @@ -94,7 +94,7 @@ static int merge_branch(void) git_checkout_options checkout_opts = GIT_CHECKOUT_OPTIONS_INIT; int error; - cl_git_pass(git_oid_fromstr(&their_oids[0], MERGE_BRANCH_OID)); + cl_git_pass(git_oid__fromstr(&their_oids[0], MERGE_BRANCH_OID, GIT_OID_SHA1)); cl_git_pass(git_annotated_commit_lookup(&their_head, repo, &their_oids[0])); checkout_opts.checkout_strategy = GIT_CHECKOUT_SAFE; diff --git a/tests/libgit2/merge/workdir/setup.c b/tests/libgit2/merge/workdir/setup.c index 3db2d074f..98ccdf700 100644 --- a/tests/libgit2/merge/workdir/setup.c +++ b/tests/libgit2/merge/workdir/setup.c @@ -78,7 +78,7 @@ void test_merge_workdir_setup__one_branch(void) git_reference *octo1_ref; git_annotated_commit *our_head, *their_heads[1]; - cl_git_pass(git_oid_fromstr(&our_oid, ORIG_HEAD)); + cl_git_pass(git_oid__fromstr(&our_oid, ORIG_HEAD, GIT_OID_SHA1)); cl_git_pass(git_annotated_commit_lookup(&our_head, repo, &our_oid)); cl_git_pass(git_reference_lookup(&octo1_ref, repo, GIT_REFS_HEADS_DIR OCTO1_BRANCH)); @@ -104,10 +104,10 @@ void test_merge_workdir_setup__one_oid(void) git_oid octo1_oid; git_annotated_commit *our_head, *their_heads[1]; - cl_git_pass(git_oid_fromstr(&our_oid, ORIG_HEAD)); + cl_git_pass(git_oid__fromstr(&our_oid, ORIG_HEAD, GIT_OID_SHA1)); cl_git_pass(git_annotated_commit_lookup(&our_head, repo, &our_oid)); - cl_git_pass(git_oid_fromstr(&octo1_oid, OCTO1_OID)); + cl_git_pass(git_oid__fromstr(&octo1_oid, OCTO1_OID, GIT_OID_SHA1)); cl_git_pass(git_annotated_commit_lookup(&their_heads[0], repo, &octo1_oid)); cl_git_pass(git_merge__setup(repo, our_head, (const git_annotated_commit **)their_heads, 1)); @@ -129,7 +129,7 @@ void test_merge_workdir_setup__two_branches(void) git_reference *octo2_ref; git_annotated_commit *our_head, *their_heads[2]; - cl_git_pass(git_oid_fromstr(&our_oid, ORIG_HEAD)); + cl_git_pass(git_oid__fromstr(&our_oid, ORIG_HEAD, GIT_OID_SHA1)); cl_git_pass(git_annotated_commit_lookup(&our_head, repo, &our_oid)); cl_git_pass(git_reference_lookup(&octo1_ref, repo, GIT_REFS_HEADS_DIR OCTO1_BRANCH)); @@ -162,7 +162,7 @@ void test_merge_workdir_setup__three_branches(void) git_reference *octo3_ref; git_annotated_commit *our_head, *their_heads[3]; - cl_git_pass(git_oid_fromstr(&our_oid, ORIG_HEAD)); + cl_git_pass(git_oid__fromstr(&our_oid, ORIG_HEAD, GIT_OID_SHA1)); cl_git_pass(git_annotated_commit_lookup(&our_head, repo, &our_oid)); cl_git_pass(git_reference_lookup(&octo1_ref, repo, GIT_REFS_HEADS_DIR OCTO1_BRANCH)); @@ -200,16 +200,16 @@ void test_merge_workdir_setup__three_oids(void) git_oid octo3_oid; git_annotated_commit *our_head, *their_heads[3]; - cl_git_pass(git_oid_fromstr(&our_oid, ORIG_HEAD)); + cl_git_pass(git_oid__fromstr(&our_oid, ORIG_HEAD, GIT_OID_SHA1)); cl_git_pass(git_annotated_commit_lookup(&our_head, repo, &our_oid)); - cl_git_pass(git_oid_fromstr(&octo1_oid, OCTO1_OID)); + cl_git_pass(git_oid__fromstr(&octo1_oid, OCTO1_OID, GIT_OID_SHA1)); cl_git_pass(git_annotated_commit_lookup(&their_heads[0], repo, &octo1_oid)); - cl_git_pass(git_oid_fromstr(&octo2_oid, OCTO2_OID)); + cl_git_pass(git_oid__fromstr(&octo2_oid, OCTO2_OID, GIT_OID_SHA1)); cl_git_pass(git_annotated_commit_lookup(&their_heads[1], repo, &octo2_oid)); - cl_git_pass(git_oid_fromstr(&octo3_oid, OCTO3_OID)); + cl_git_pass(git_oid__fromstr(&octo3_oid, OCTO3_OID, GIT_OID_SHA1)); cl_git_pass(git_annotated_commit_lookup(&their_heads[2], repo, &octo3_oid)); cl_git_pass(git_merge__setup(repo, our_head, (const git_annotated_commit **)their_heads, 3)); @@ -233,13 +233,13 @@ void test_merge_workdir_setup__branches_and_oids_1(void) git_oid octo2_oid; git_annotated_commit *our_head, *their_heads[2]; - cl_git_pass(git_oid_fromstr(&our_oid, ORIG_HEAD)); + cl_git_pass(git_oid__fromstr(&our_oid, ORIG_HEAD, GIT_OID_SHA1)); cl_git_pass(git_annotated_commit_lookup(&our_head, repo, &our_oid)); cl_git_pass(git_reference_lookup(&octo1_ref, repo, GIT_REFS_HEADS_DIR OCTO1_BRANCH)); cl_git_pass(git_annotated_commit_from_ref(&their_heads[0], repo, octo1_ref)); - cl_git_pass(git_oid_fromstr(&octo2_oid, OCTO2_OID)); + cl_git_pass(git_oid__fromstr(&octo2_oid, OCTO2_OID, GIT_OID_SHA1)); cl_git_pass(git_annotated_commit_lookup(&their_heads[1], repo, &octo2_oid)); cl_git_pass(git_merge__setup(repo, our_head, (const git_annotated_commit **)their_heads, 2)); @@ -266,19 +266,19 @@ void test_merge_workdir_setup__branches_and_oids_2(void) git_oid octo4_oid; git_annotated_commit *our_head, *their_heads[4]; - cl_git_pass(git_oid_fromstr(&our_oid, ORIG_HEAD)); + cl_git_pass(git_oid__fromstr(&our_oid, ORIG_HEAD, GIT_OID_SHA1)); cl_git_pass(git_annotated_commit_lookup(&our_head, repo, &our_oid)); cl_git_pass(git_reference_lookup(&octo1_ref, repo, GIT_REFS_HEADS_DIR OCTO1_BRANCH)); cl_git_pass(git_annotated_commit_from_ref(&their_heads[0], repo, octo1_ref)); - cl_git_pass(git_oid_fromstr(&octo2_oid, OCTO2_OID)); + cl_git_pass(git_oid__fromstr(&octo2_oid, OCTO2_OID, GIT_OID_SHA1)); cl_git_pass(git_annotated_commit_lookup(&their_heads[1], repo, &octo2_oid)); cl_git_pass(git_reference_lookup(&octo3_ref, repo, GIT_REFS_HEADS_DIR OCTO3_BRANCH)); cl_git_pass(git_annotated_commit_from_ref(&their_heads[2], repo, octo3_ref)); - cl_git_pass(git_oid_fromstr(&octo4_oid, OCTO4_OID)); + cl_git_pass(git_oid__fromstr(&octo4_oid, OCTO4_OID, GIT_OID_SHA1)); cl_git_pass(git_annotated_commit_lookup(&their_heads[3], repo, &octo4_oid)); cl_git_pass(git_merge__setup(repo, our_head, (const git_annotated_commit **)their_heads, 4)); @@ -308,16 +308,16 @@ void test_merge_workdir_setup__branches_and_oids_3(void) git_reference *octo4_ref; git_annotated_commit *our_head, *their_heads[4]; - cl_git_pass(git_oid_fromstr(&our_oid, ORIG_HEAD)); + cl_git_pass(git_oid__fromstr(&our_oid, ORIG_HEAD, GIT_OID_SHA1)); cl_git_pass(git_annotated_commit_lookup(&our_head, repo, &our_oid)); - cl_git_pass(git_oid_fromstr(&octo1_oid, OCTO1_OID)); + cl_git_pass(git_oid__fromstr(&octo1_oid, OCTO1_OID, GIT_OID_SHA1)); cl_git_pass(git_annotated_commit_lookup(&their_heads[0], repo, &octo1_oid)); cl_git_pass(git_reference_lookup(&octo2_ref, repo, GIT_REFS_HEADS_DIR OCTO2_BRANCH)); cl_git_pass(git_annotated_commit_from_ref(&their_heads[1], repo, octo2_ref)); - cl_git_pass(git_oid_fromstr(&octo3_oid, OCTO3_OID)); + cl_git_pass(git_oid__fromstr(&octo3_oid, OCTO3_OID, GIT_OID_SHA1)); cl_git_pass(git_annotated_commit_lookup(&their_heads[2], repo, &octo3_oid)); cl_git_pass(git_reference_lookup(&octo4_ref, repo, GIT_REFS_HEADS_DIR OCTO4_BRANCH)); @@ -351,16 +351,16 @@ void test_merge_workdir_setup__branches_and_oids_4(void) git_reference *octo5_ref; git_annotated_commit *our_head, *their_heads[5]; - cl_git_pass(git_oid_fromstr(&our_oid, ORIG_HEAD)); + cl_git_pass(git_oid__fromstr(&our_oid, ORIG_HEAD, GIT_OID_SHA1)); cl_git_pass(git_annotated_commit_lookup(&our_head, repo, &our_oid)); - cl_git_pass(git_oid_fromstr(&octo1_oid, OCTO1_OID)); + cl_git_pass(git_oid__fromstr(&octo1_oid, OCTO1_OID, GIT_OID_SHA1)); cl_git_pass(git_annotated_commit_lookup(&their_heads[0], repo, &octo1_oid)); cl_git_pass(git_reference_lookup(&octo2_ref, repo, GIT_REFS_HEADS_DIR OCTO2_BRANCH)); cl_git_pass(git_annotated_commit_from_ref(&their_heads[1], repo, octo2_ref)); - cl_git_pass(git_oid_fromstr(&octo3_oid, OCTO3_OID)); + cl_git_pass(git_oid__fromstr(&octo3_oid, OCTO3_OID, GIT_OID_SHA1)); cl_git_pass(git_annotated_commit_lookup(&their_heads[2], repo, &octo3_oid)); cl_git_pass(git_reference_lookup(&octo4_ref, repo, GIT_REFS_HEADS_DIR OCTO4_BRANCH)); @@ -397,7 +397,7 @@ void test_merge_workdir_setup__three_same_branches(void) git_reference *octo1_3_ref; git_annotated_commit *our_head, *their_heads[3]; - cl_git_pass(git_oid_fromstr(&our_oid, ORIG_HEAD)); + cl_git_pass(git_oid__fromstr(&our_oid, ORIG_HEAD, GIT_OID_SHA1)); cl_git_pass(git_annotated_commit_lookup(&our_head, repo, &our_oid)); cl_git_pass(git_reference_lookup(&octo1_1_ref, repo, GIT_REFS_HEADS_DIR OCTO1_BRANCH)); @@ -435,16 +435,16 @@ void test_merge_workdir_setup__three_same_oids(void) git_oid octo1_3_oid; git_annotated_commit *our_head, *their_heads[3]; - cl_git_pass(git_oid_fromstr(&our_oid, ORIG_HEAD)); + cl_git_pass(git_oid__fromstr(&our_oid, ORIG_HEAD, GIT_OID_SHA1)); cl_git_pass(git_annotated_commit_lookup(&our_head, repo, &our_oid)); - cl_git_pass(git_oid_fromstr(&octo1_1_oid, OCTO1_OID)); + cl_git_pass(git_oid__fromstr(&octo1_1_oid, OCTO1_OID, GIT_OID_SHA1)); cl_git_pass(git_annotated_commit_lookup(&their_heads[0], repo, &octo1_1_oid)); - cl_git_pass(git_oid_fromstr(&octo1_2_oid, OCTO1_OID)); + cl_git_pass(git_oid__fromstr(&octo1_2_oid, OCTO1_OID, GIT_OID_SHA1)); cl_git_pass(git_annotated_commit_lookup(&their_heads[1], repo, &octo1_2_oid)); - cl_git_pass(git_oid_fromstr(&octo1_3_oid, OCTO1_OID)); + cl_git_pass(git_oid__fromstr(&octo1_3_oid, OCTO1_OID, GIT_OID_SHA1)); cl_git_pass(git_annotated_commit_lookup(&their_heads[2], repo, &octo1_3_oid)); cl_git_pass(git_merge__setup(repo, our_head, (const git_annotated_commit **)their_heads, 3)); @@ -512,7 +512,7 @@ void test_merge_workdir_setup__remote_tracking_one_branch(void) cl_git_pass(create_remote_tracking_branch(OCTO1_BRANCH, OCTO1_OID)); - cl_git_pass(git_oid_fromstr(&our_oid, ORIG_HEAD)); + cl_git_pass(git_oid__fromstr(&our_oid, ORIG_HEAD, GIT_OID_SHA1)); cl_git_pass(git_annotated_commit_lookup(&our_head, repo, &our_oid)); cl_git_pass(git_reference_lookup(&octo1_ref, repo, GIT_REFS_REMOTES_DIR "origin/" OCTO1_BRANCH)); @@ -542,7 +542,7 @@ void test_merge_workdir_setup__remote_tracking_two_branches(void) cl_git_pass(create_remote_tracking_branch(OCTO1_BRANCH, OCTO1_OID)); cl_git_pass(create_remote_tracking_branch(OCTO2_BRANCH, OCTO2_OID)); - cl_git_pass(git_oid_fromstr(&our_oid, ORIG_HEAD)); + cl_git_pass(git_oid__fromstr(&our_oid, ORIG_HEAD, GIT_OID_SHA1)); cl_git_pass(git_annotated_commit_lookup(&our_head, repo, &our_oid)); cl_git_pass(git_reference_lookup(&octo1_ref, repo, GIT_REFS_REMOTES_DIR "origin/" OCTO1_BRANCH)); @@ -579,7 +579,7 @@ void test_merge_workdir_setup__remote_tracking_three_branches(void) cl_git_pass(create_remote_tracking_branch(OCTO2_BRANCH, OCTO2_OID)); cl_git_pass(create_remote_tracking_branch(OCTO3_BRANCH, OCTO3_OID)); - cl_git_pass(git_oid_fromstr(&our_oid, ORIG_HEAD)); + cl_git_pass(git_oid__fromstr(&our_oid, ORIG_HEAD, GIT_OID_SHA1)); cl_git_pass(git_annotated_commit_lookup(&our_head, repo, &our_oid)); cl_git_pass(git_reference_lookup(&octo1_ref, repo, GIT_REFS_REMOTES_DIR "origin/" OCTO1_BRANCH)); @@ -618,7 +618,7 @@ void test_merge_workdir_setup__normal_branch_and_remote_tracking_branch(void) cl_git_pass(create_remote_tracking_branch(OCTO2_BRANCH, OCTO2_OID)); - cl_git_pass(git_oid_fromstr(&our_oid, ORIG_HEAD)); + cl_git_pass(git_oid__fromstr(&our_oid, ORIG_HEAD, GIT_OID_SHA1)); cl_git_pass(git_annotated_commit_lookup(&our_head, repo, &our_oid)); cl_git_pass(git_reference_lookup(&octo1_ref, repo, GIT_REFS_HEADS_DIR OCTO1_BRANCH)); @@ -652,7 +652,7 @@ void test_merge_workdir_setup__remote_tracking_branch_and_normal_branch(void) cl_git_pass(create_remote_tracking_branch(OCTO1_BRANCH, OCTO1_OID)); - cl_git_pass(git_oid_fromstr(&our_oid, ORIG_HEAD)); + cl_git_pass(git_oid__fromstr(&our_oid, ORIG_HEAD, GIT_OID_SHA1)); cl_git_pass(git_annotated_commit_lookup(&our_head, repo, &our_oid)); cl_git_pass(git_reference_lookup(&octo1_ref, repo, GIT_REFS_REMOTES_DIR "origin/" OCTO1_BRANCH)); @@ -689,7 +689,7 @@ void test_merge_workdir_setup__two_remote_tracking_branch_and_two_normal_branche cl_git_pass(create_remote_tracking_branch(OCTO2_BRANCH, OCTO2_OID)); cl_git_pass(create_remote_tracking_branch(OCTO4_BRANCH, OCTO4_OID)); - cl_git_pass(git_oid_fromstr(&our_oid, ORIG_HEAD)); + cl_git_pass(git_oid__fromstr(&our_oid, ORIG_HEAD, GIT_OID_SHA1)); cl_git_pass(git_annotated_commit_lookup(&our_head, repo, &our_oid)); cl_git_pass(git_reference_lookup(&octo1_ref, repo, GIT_REFS_HEADS_DIR OCTO1_BRANCH)); @@ -730,10 +730,10 @@ void test_merge_workdir_setup__pull_one(void) git_oid octo1_1_oid; git_annotated_commit *our_head, *their_heads[1]; - cl_git_pass(git_oid_fromstr(&our_oid, ORIG_HEAD)); + cl_git_pass(git_oid__fromstr(&our_oid, ORIG_HEAD, GIT_OID_SHA1)); cl_git_pass(git_annotated_commit_lookup(&our_head, repo, &our_oid)); - cl_git_pass(git_oid_fromstr(&octo1_1_oid, OCTO1_OID)); + cl_git_pass(git_oid__fromstr(&octo1_1_oid, OCTO1_OID, GIT_OID_SHA1)); cl_git_pass(git_annotated_commit_from_fetchhead(&their_heads[0], repo, GIT_REFS_HEADS_DIR OCTO1_BRANCH, "http://remote.url/repo.git", &octo1_1_oid)); cl_git_pass(git_merge__setup(repo, our_head, (const git_annotated_commit **)their_heads, 1)); @@ -755,13 +755,13 @@ void test_merge_workdir_setup__pull_two(void) git_oid octo2_oid; git_annotated_commit *our_head, *their_heads[2]; - cl_git_pass(git_oid_fromstr(&our_oid, ORIG_HEAD)); + cl_git_pass(git_oid__fromstr(&our_oid, ORIG_HEAD, GIT_OID_SHA1)); cl_git_pass(git_annotated_commit_lookup(&our_head, repo, &our_oid)); - cl_git_pass(git_oid_fromstr(&octo1_oid, OCTO1_OID)); + cl_git_pass(git_oid__fromstr(&octo1_oid, OCTO1_OID, GIT_OID_SHA1)); cl_git_pass(git_annotated_commit_from_fetchhead(&their_heads[0], repo, GIT_REFS_HEADS_DIR OCTO1_BRANCH, "http://remote.url/repo.git", &octo1_oid)); - cl_git_pass(git_oid_fromstr(&octo2_oid, OCTO2_OID)); + cl_git_pass(git_oid__fromstr(&octo2_oid, OCTO2_OID, GIT_OID_SHA1)); cl_git_pass(git_annotated_commit_from_fetchhead(&their_heads[1], repo, GIT_REFS_HEADS_DIR OCTO2_BRANCH, "http://remote.url/repo.git", &octo2_oid)); cl_git_pass(git_merge__setup(repo, our_head, (const git_annotated_commit **)their_heads, 2)); @@ -785,16 +785,16 @@ void test_merge_workdir_setup__pull_three(void) git_oid octo3_oid; git_annotated_commit *our_head, *their_heads[3]; - cl_git_pass(git_oid_fromstr(&our_oid, ORIG_HEAD)); + cl_git_pass(git_oid__fromstr(&our_oid, ORIG_HEAD, GIT_OID_SHA1)); cl_git_pass(git_annotated_commit_lookup(&our_head, repo, &our_oid)); - cl_git_pass(git_oid_fromstr(&octo1_oid, OCTO1_OID)); + cl_git_pass(git_oid__fromstr(&octo1_oid, OCTO1_OID, GIT_OID_SHA1)); cl_git_pass(git_annotated_commit_from_fetchhead(&their_heads[0], repo, GIT_REFS_HEADS_DIR OCTO1_BRANCH, "http://remote.url/repo.git", &octo1_oid)); - cl_git_pass(git_oid_fromstr(&octo2_oid, OCTO2_OID)); + cl_git_pass(git_oid__fromstr(&octo2_oid, OCTO2_OID, GIT_OID_SHA1)); cl_git_pass(git_annotated_commit_from_fetchhead(&their_heads[1], repo, GIT_REFS_HEADS_DIR OCTO2_BRANCH, "http://remote.url/repo.git", &octo2_oid)); - cl_git_pass(git_oid_fromstr(&octo3_oid, OCTO3_OID)); + cl_git_pass(git_oid__fromstr(&octo3_oid, OCTO3_OID, GIT_OID_SHA1)); cl_git_pass(git_annotated_commit_from_fetchhead(&their_heads[2], repo, GIT_REFS_HEADS_DIR OCTO3_BRANCH, "http://remote.url/repo.git", &octo3_oid)); cl_git_pass(git_merge__setup(repo, our_head, (const git_annotated_commit **)their_heads, 3)); @@ -818,16 +818,16 @@ void test_merge_workdir_setup__three_remotes(void) git_oid octo3_oid; git_annotated_commit *our_head, *their_heads[3]; - cl_git_pass(git_oid_fromstr(&our_oid, ORIG_HEAD)); + cl_git_pass(git_oid__fromstr(&our_oid, ORIG_HEAD, GIT_OID_SHA1)); cl_git_pass(git_annotated_commit_lookup(&our_head, repo, &our_oid)); - cl_git_pass(git_oid_fromstr(&octo1_oid, OCTO1_OID)); + cl_git_pass(git_oid__fromstr(&octo1_oid, OCTO1_OID, GIT_OID_SHA1)); cl_git_pass(git_annotated_commit_from_fetchhead(&their_heads[0], repo, GIT_REFS_HEADS_DIR OCTO1_BRANCH, "http://remote.first/repo.git", &octo1_oid)); - cl_git_pass(git_oid_fromstr(&octo2_oid, OCTO2_OID)); + cl_git_pass(git_oid__fromstr(&octo2_oid, OCTO2_OID, GIT_OID_SHA1)); cl_git_pass(git_annotated_commit_from_fetchhead(&their_heads[1], repo, GIT_REFS_HEADS_DIR OCTO2_BRANCH, "http://remote.second/repo.git", &octo2_oid)); - cl_git_pass(git_oid_fromstr(&octo3_oid, OCTO3_OID)); + cl_git_pass(git_oid__fromstr(&octo3_oid, OCTO3_OID, GIT_OID_SHA1)); cl_git_pass(git_annotated_commit_from_fetchhead(&their_heads[2], repo, GIT_REFS_HEADS_DIR OCTO3_BRANCH, "http://remote.third/repo.git", &octo3_oid)); cl_git_pass(git_merge__setup(repo, our_head, (const git_annotated_commit **)their_heads, 3)); @@ -852,19 +852,19 @@ void test_merge_workdir_setup__two_remotes(void) git_oid octo4_oid; git_annotated_commit *our_head, *their_heads[4]; - cl_git_pass(git_oid_fromstr(&our_oid, ORIG_HEAD)); + cl_git_pass(git_oid__fromstr(&our_oid, ORIG_HEAD, GIT_OID_SHA1)); cl_git_pass(git_annotated_commit_lookup(&our_head, repo, &our_oid)); - cl_git_pass(git_oid_fromstr(&octo1_oid, OCTO1_OID)); + cl_git_pass(git_oid__fromstr(&octo1_oid, OCTO1_OID, GIT_OID_SHA1)); cl_git_pass(git_annotated_commit_from_fetchhead(&their_heads[0], repo, GIT_REFS_HEADS_DIR OCTO1_BRANCH, "http://remote.first/repo.git", &octo1_oid)); - cl_git_pass(git_oid_fromstr(&octo2_oid, OCTO2_OID)); + cl_git_pass(git_oid__fromstr(&octo2_oid, OCTO2_OID, GIT_OID_SHA1)); cl_git_pass(git_annotated_commit_from_fetchhead(&their_heads[1], repo, GIT_REFS_HEADS_DIR OCTO2_BRANCH, "http://remote.second/repo.git", &octo2_oid)); - cl_git_pass(git_oid_fromstr(&octo3_oid, OCTO3_OID)); + cl_git_pass(git_oid__fromstr(&octo3_oid, OCTO3_OID, GIT_OID_SHA1)); cl_git_pass(git_annotated_commit_from_fetchhead(&their_heads[2], repo, GIT_REFS_HEADS_DIR OCTO3_BRANCH, "http://remote.first/repo.git", &octo3_oid)); - cl_git_pass(git_oid_fromstr(&octo4_oid, OCTO4_OID)); + cl_git_pass(git_oid__fromstr(&octo4_oid, OCTO4_OID, GIT_OID_SHA1)); cl_git_pass(git_annotated_commit_from_fetchhead(&their_heads[3], repo, GIT_REFS_HEADS_DIR OCTO4_BRANCH, "http://remote.second/repo.git", &octo4_oid)); cl_git_pass(git_merge__setup(repo, our_head, (const git_annotated_commit **)their_heads, 4)); @@ -888,7 +888,7 @@ void test_merge_workdir_setup__id_from_head(void) git_reference *ref; git_annotated_commit *heads[3]; - cl_git_pass(git_oid_fromstr(&expected_id, OCTO1_OID)); + cl_git_pass(git_oid__fromstr(&expected_id, OCTO1_OID, GIT_OID_SHA1)); cl_git_pass(git_annotated_commit_from_fetchhead(&heads[0], repo, GIT_REFS_HEADS_DIR OCTO1_BRANCH, "http://remote.url/repo.git", &expected_id)); id = git_annotated_commit_id(heads[0]); cl_assert_equal_i(1, git_oid_equal(id, &expected_id)); @@ -920,7 +920,7 @@ static int annotated_commit_foreach_cb(const git_oid *oid, void *payload) git_oid expected_oid; struct annotated_commit_cb_data *cb_data = payload; - git_oid_fromstr(&expected_oid, cb_data->oid_str[cb_data->i]); + git_oid__fromstr(&expected_oid, cb_data->oid_str[cb_data->i], GIT_OID_SHA1); cl_assert(git_oid_cmp(&expected_oid, oid) == 0); cb_data->i++; return 0; @@ -998,7 +998,7 @@ void test_merge_workdir_setup__retained_after_success(void) git_reference *octo1_ref; git_annotated_commit *our_head, *their_heads[1]; - cl_git_pass(git_oid_fromstr(&our_oid, ORIG_HEAD)); + cl_git_pass(git_oid__fromstr(&our_oid, ORIG_HEAD, GIT_OID_SHA1)); cl_git_pass(git_annotated_commit_lookup(&our_head, repo, &our_oid)); cl_git_pass(git_reference_lookup(&octo1_ref, repo, GIT_REFS_HEADS_DIR OCTO1_BRANCH)); @@ -1025,7 +1025,7 @@ void test_merge_workdir_setup__removed_after_failure(void) git_reference *octo1_ref; git_annotated_commit *our_head, *their_heads[1]; - cl_git_pass(git_oid_fromstr(&our_oid, ORIG_HEAD)); + cl_git_pass(git_oid__fromstr(&our_oid, ORIG_HEAD, GIT_OID_SHA1)); cl_git_pass(git_annotated_commit_lookup(&our_head, repo, &our_oid)); cl_git_pass(git_reference_lookup(&octo1_ref, repo, GIT_REFS_HEADS_DIR OCTO1_BRANCH)); @@ -1052,7 +1052,7 @@ void test_merge_workdir_setup__unlocked_after_success(void) git_reference *octo1_ref; git_annotated_commit *our_head, *their_heads[1]; - cl_git_pass(git_oid_fromstr(&our_oid, ORIG_HEAD)); + cl_git_pass(git_oid__fromstr(&our_oid, ORIG_HEAD, GIT_OID_SHA1)); cl_git_pass(git_annotated_commit_lookup(&our_head, repo, &our_oid)); cl_git_pass(git_reference_lookup(&octo1_ref, repo, GIT_REFS_HEADS_DIR OCTO1_BRANCH)); @@ -1075,7 +1075,7 @@ void test_merge_workdir_setup__unlocked_after_conflict(void) git_reference *octo1_ref; git_annotated_commit *our_head, *their_heads[1]; - cl_git_pass(git_oid_fromstr(&our_oid, ORIG_HEAD)); + cl_git_pass(git_oid__fromstr(&our_oid, ORIG_HEAD, GIT_OID_SHA1)); cl_git_pass(git_annotated_commit_lookup(&our_head, repo, &our_oid)); cl_git_pass(git_reference_lookup(&octo1_ref, repo, GIT_REFS_HEADS_DIR OCTO1_BRANCH)); diff --git a/tests/libgit2/merge/workdir/simple.c b/tests/libgit2/merge/workdir/simple.c index b9d3fc24c..e9cffeea8 100644 --- a/tests/libgit2/merge/workdir/simple.c +++ b/tests/libgit2/merge/workdir/simple.c @@ -99,7 +99,7 @@ static void merge_simple_branch(int merge_file_favor, int addl_checkout_strategy git_merge_options merge_opts = GIT_MERGE_OPTIONS_INIT; git_checkout_options checkout_opts = GIT_CHECKOUT_OPTIONS_INIT; - cl_git_pass(git_oid_fromstr(&their_oids[0], THEIRS_SIMPLE_OID)); + cl_git_pass(git_oid__fromstr(&their_oids[0], THEIRS_SIMPLE_OID, GIT_OID_SHA1)); cl_git_pass(git_annotated_commit_lookup(&their_heads[0], repo, &their_oids[0])); merge_opts.file_favor = merge_file_favor; @@ -180,14 +180,14 @@ void test_merge_workdir_simple__index_reload(void) cl_git_pass(git_index_read(repo_index, 0)); entry.mode = GIT_FILEMODE_BLOB; - cl_git_pass(git_oid_fromstr(&entry.id, "11deab00b2d3a6f5a3073988ac050c2d7b6655e2")); + cl_git_pass(git_oid__fromstr(&entry.id, "11deab00b2d3a6f5a3073988ac050c2d7b6655e2", GIT_OID_SHA1)); entry.path = "automergeable.txt"; cl_git_pass(git_index_add(repo_index, &entry)); cl_git_pass(git_index_add_bypath(tmp_index, "automergeable.txt")); cl_git_pass(git_index_write(tmp_index)); - cl_git_pass(git_oid_fromstr(&their_oid, THEIRS_SIMPLE_OID)); + cl_git_pass(git_oid__fromstr(&their_oid, THEIRS_SIMPLE_OID, GIT_OID_SHA1)); cl_git_pass(git_annotated_commit_lookup(&their_heads[0], repo, &their_oid)); cl_git_pass(git_merge(repo, (const git_annotated_commit **)their_heads, 1, NULL, NULL)); @@ -669,7 +669,7 @@ void test_merge_workdir_simple__directory_file(void) cl_git_pass(git_commit_lookup(&head_commit, repo, &head_commit_id)); cl_git_pass(git_reset(repo, (git_object *)head_commit, GIT_RESET_HARD, NULL)); - cl_git_pass(git_oid_fromstr(&their_oids[0], THEIRS_DIRECTORY_FILE)); + cl_git_pass(git_oid__fromstr(&their_oids[0], THEIRS_DIRECTORY_FILE, GIT_OID_SHA1)); cl_git_pass(git_annotated_commit_lookup(&their_heads[0], repo, &their_oids[0])); merge_opts.file_favor = 0; @@ -700,7 +700,7 @@ void test_merge_workdir_simple__unrelated(void) { 0100644, "c8f06f2e3bb2964174677e91f0abead0e43c9e5d", 0, "unchanged.txt" }, }; - cl_git_pass(git_oid_fromstr(&their_oids[0], THEIRS_UNRELATED_PARENT)); + cl_git_pass(git_oid__fromstr(&their_oids[0], THEIRS_UNRELATED_PARENT, GIT_OID_SHA1)); cl_git_pass(git_annotated_commit_lookup(&their_heads[0], repo, &their_oids[0])); merge_opts.file_favor = 0; @@ -731,7 +731,7 @@ void test_merge_workdir_simple__unrelated_with_conflicts(void) { 0100644, "c8f06f2e3bb2964174677e91f0abead0e43c9e5d", 0, "unchanged.txt" }, }; - cl_git_pass(git_oid_fromstr(&their_oids[0], THEIRS_UNRELATED_OID)); + cl_git_pass(git_oid__fromstr(&their_oids[0], THEIRS_UNRELATED_OID, GIT_OID_SHA1)); cl_git_pass(git_annotated_commit_lookup(&their_heads[0], repo, &their_oids[0])); merge_opts.file_favor = 0; @@ -755,8 +755,8 @@ void test_merge_workdir_simple__binary(void) { 0100644, "836b8b82b26cab22eaaed8820877c76d6c8bca19", 3, "binary" }, }; - cl_git_pass(git_oid_fromstr(&our_oid, "cc338e4710c9b257106b8d16d82f86458d5beaf1")); - cl_git_pass(git_oid_fromstr(&their_oid, "ad01aebfdf2ac13145efafe3f9fcf798882f1730")); + cl_git_pass(git_oid__fromstr(&our_oid, "cc338e4710c9b257106b8d16d82f86458d5beaf1", GIT_OID_SHA1)); + cl_git_pass(git_oid__fromstr(&their_oid, "ad01aebfdf2ac13145efafe3f9fcf798882f1730", GIT_OID_SHA1)); cl_git_pass(git_commit_lookup(&our_commit, repo, &our_oid)); cl_git_pass(git_reset(repo, (git_object *)our_commit, GIT_RESET_HARD, NULL)); @@ -770,7 +770,7 @@ void test_merge_workdir_simple__binary(void) cl_git_pass(git_index_add_bypath(repo_index, "binary")); cl_assert((binary_entry = git_index_get_bypath(repo_index, "binary", 0)) != NULL); - cl_git_pass(git_oid_fromstr(&our_file_oid, "23ed141a6ae1e798b2f721afedbe947c119111ba")); + cl_git_pass(git_oid__fromstr(&our_file_oid, "23ed141a6ae1e798b2f721afedbe947c119111ba", GIT_OID_SHA1)); cl_assert(git_oid_cmp(&binary_entry->id, &our_file_oid) == 0); git_annotated_commit_free(their_head); diff --git a/tests/libgit2/merge/workdir/trivial.c b/tests/libgit2/merge/workdir/trivial.c index fe8374851..364182c89 100644 --- a/tests/libgit2/merge/workdir/trivial.c +++ b/tests/libgit2/merge/workdir/trivial.c @@ -222,7 +222,7 @@ void test_merge_workdir_trivial__13(void) cl_git_pass(merge_trivial("trivial-13", "trivial-13-branch")); cl_assert(entry = git_index_get_bypath(repo_index, "modified-in-13.txt", 0)); - cl_git_pass(git_oid_fromstr(&expected_oid, "1cff9ec6a47a537380dedfdd17c9e76d74259a2b")); + cl_git_pass(git_oid__fromstr(&expected_oid, "1cff9ec6a47a537380dedfdd17c9e76d74259a2b", GIT_OID_SHA1)); cl_assert(git_oid_cmp(&entry->id, &expected_oid) == 0); cl_assert(git_index_reuc_entrycount(repo_index) == 0); @@ -238,7 +238,7 @@ void test_merge_workdir_trivial__14(void) cl_git_pass(merge_trivial("trivial-14", "trivial-14-branch")); cl_assert(entry = git_index_get_bypath(repo_index, "modified-in-14-branch.txt", 0)); - cl_git_pass(git_oid_fromstr(&expected_oid, "26153a3ff3649b6c2bb652d3f06878c6e0a172f9")); + cl_git_pass(git_oid__fromstr(&expected_oid, "26153a3ff3649b6c2bb652d3f06878c6e0a172f9", GIT_OID_SHA1)); cl_assert(git_oid_cmp(&entry->id, &expected_oid) == 0); cl_assert(git_index_reuc_entrycount(repo_index) == 0); diff --git a/tests/libgit2/network/remote/push.c b/tests/libgit2/network/remote/push.c index 3905debdf..16588a292 100644 --- a/tests/libgit2/network/remote/push.c +++ b/tests/libgit2/network/remote/push.c @@ -1,5 +1,6 @@ #include "clar_libgit2.h" #include "git2/sys/commit.h" +#include "oid.h" static git_remote *_remote; static git_repository *_repo, *_dummy; @@ -57,7 +58,7 @@ void test_network_remote_push__delete_notification(void) expected.src_refname = ""; expected.dst_refname = "refs/heads/master"; - memset(&expected.dst, 0, sizeof(git_oid)); + git_oid_clear(&expected.dst, GIT_OID_SHA1); git_oid_cpy(&expected.src, git_reference_target(ref)); opts.callbacks.push_negotiation = negotiation_cb; @@ -102,7 +103,7 @@ void test_network_remote_push__create_notification(void) expected.src_refname = "refs/heads/empty-tree"; expected.dst_refname = "refs/heads/empty-tree"; git_oid_cpy(&expected.dst, git_reference_target(ref)); - memset(&expected.src, 0, sizeof(git_oid)); + git_oid_clear(&expected.src, GIT_OID_SHA1); opts.callbacks.push_negotiation = negotiation_cb; opts.callbacks.payload = &expected; diff --git a/tests/libgit2/network/remote/rename.c b/tests/libgit2/network/remote/rename.c index 1fd2affba..b071f9cef 100644 --- a/tests/libgit2/network/remote/rename.c +++ b/tests/libgit2/network/remote/rename.c @@ -164,13 +164,13 @@ void test_network_remote_rename__renaming_a_remote_moves_the_underlying_referenc void test_network_remote_rename__overwrite_ref_in_target(void) { git_oid id; - char idstr[GIT_OID_HEXSZ + 1] = {0}; + char idstr[GIT_OID_SHA1_HEXSIZE + 1] = {0}; git_reference *ref; git_branch_t btype; git_branch_iterator *iter; git_strarray problems = {0}; - cl_git_pass(git_oid_fromstr(&id, "a65fedf39aefe402d3bb6e24df4d4f5fe4547750")); + cl_git_pass(git_oid__fromstr(&id, "a65fedf39aefe402d3bb6e24df4d4f5fe4547750", GIT_OID_SHA1)); cl_git_pass(git_reference_create(&ref, _repo, "refs/remotes/renamed/master", &id, 1, NULL)); git_reference_free(ref); @@ -206,7 +206,7 @@ void test_network_remote_rename__symref_head(void) git_branch_t btype; git_branch_iterator *iter; git_strarray problems = {0}; - char idstr[GIT_OID_HEXSZ + 1] = {0}; + char idstr[GIT_OID_SHA1_HEXSIZE + 1] = {0}; git_vector refs; cl_git_pass(git_reference_symbolic_create(&ref, _repo, "refs/remotes/test/HEAD", "refs/remotes/test/master", 0, NULL)); diff --git a/tests/libgit2/notes/notes.c b/tests/libgit2/notes/notes.c index a36cddb8a..06c440955 100644 --- a/tests/libgit2/notes/notes.c +++ b/tests/libgit2/notes/notes.c @@ -33,7 +33,7 @@ static void create_note(git_oid *note_oid, const char *canonical_namespace, cons { git_oid oid; - cl_git_pass(git_oid_fromstr(&oid, target_sha)); + cl_git_pass(git_oid__fromstr(&oid, target_sha, GIT_OID_SHA1)); cl_git_pass(git_note_create(note_oid, _repo, canonical_namespace, _sig, _sig, &oid, message, 0)); } @@ -60,10 +60,10 @@ static int note_list_cb( cl_assert(*count < EXPECTATIONS_COUNT); - cl_git_pass(git_oid_fromstr(&expected_note_oid, list_expectations[*count].note_sha)); + cl_git_pass(git_oid__fromstr(&expected_note_oid, list_expectations[*count].note_sha, GIT_OID_SHA1)); cl_assert_equal_oid(&expected_note_oid, blob_id); - cl_git_pass(git_oid_fromstr(&expected_target_oid, list_expectations[*count].annotated_object_sha)); + cl_git_pass(git_oid__fromstr(&expected_target_oid, list_expectations[*count].annotated_object_sha, GIT_OID_SHA1)); cl_assert_equal_oid(&expected_target_oid, annotated_obj_id); (*count)++; @@ -85,12 +85,12 @@ static int note_list_create_cb( size_t i; for (i = 0; notes[i].note_oid != NULL; i++) { - cl_git_pass(git_oid_fromstr(&expected_note_oid, notes[i].note_oid)); + cl_git_pass(git_oid__fromstr(&expected_note_oid, notes[i].note_oid, GIT_OID_SHA1)); if (git_oid_cmp(&expected_note_oid, blob_oid) != 0) continue; - cl_git_pass(git_oid_fromstr(&expected_target_oid, notes[i].object_oid)); + cl_git_pass(git_oid__fromstr(&expected_target_oid, notes[i].object_oid, GIT_OID_SHA1)); if (git_oid_cmp(&expected_target_oid, annotated_obj_id) != 0) continue; @@ -140,7 +140,7 @@ void test_notes_notes__can_create_a_note_from_commit(void) { NULL, NULL, 0 } }; - cl_git_pass(git_oid_fromstr(&oid, can_create_a_note_from_commit[0].object_oid)); + cl_git_pass(git_oid__fromstr(&oid, can_create_a_note_from_commit[0].object_oid, GIT_OID_SHA1)); cl_git_pass(git_note_commit_create(¬es_commit_out, NULL, _repo, NULL, _sig, _sig, &oid, "I decorate 4a20\n", 1)); @@ -169,11 +169,11 @@ void test_notes_notes__can_create_a_note_from_commit_given_an_existing_commit(vo { NULL, NULL, 0 } }; - cl_git_pass(git_oid_fromstr(&oid, "4a202b346bb0fb0db7eff3cffeb3c70babbd2045")); + cl_git_pass(git_oid__fromstr(&oid, "4a202b346bb0fb0db7eff3cffeb3c70babbd2045", GIT_OID_SHA1)); cl_git_pass(git_note_commit_create(¬es_commit_out, NULL, _repo, NULL, _sig, _sig, &oid, "I decorate 4a20\n", 0)); - cl_git_pass(git_oid_fromstr(&oid, "9fd738e8f7967c078dceed8190330fc8648ee56a")); + cl_git_pass(git_oid__fromstr(&oid, "9fd738e8f7967c078dceed8190330fc8648ee56a", GIT_OID_SHA1)); git_commit_lookup(&existing_notes_commit, _repo, ¬es_commit_out); @@ -274,7 +274,7 @@ void test_notes_notes__inserting_a_note_without_passing_a_namespace_uses_the_def git_note *note, *default_namespace_note; git_buf default_ref = GIT_BUF_INIT; - cl_git_pass(git_oid_fromstr(&target_oid, "08b041783f40edfe12bb406c9c9a8a040177c125")); + cl_git_pass(git_oid__fromstr(&target_oid, "08b041783f40edfe12bb406c9c9a8a040177c125", GIT_OID_SHA1)); cl_git_pass(git_note_default_ref(&default_ref, _repo)); create_note(¬e_oid, NULL, "08b041783f40edfe12bb406c9c9a8a040177c125", "hello world\n"); @@ -295,7 +295,7 @@ void test_notes_notes__can_insert_a_note_with_a_custom_namespace(void) git_oid note_oid, target_oid; git_note *note; - cl_git_pass(git_oid_fromstr(&target_oid, "08b041783f40edfe12bb406c9c9a8a040177c125")); + cl_git_pass(git_oid__fromstr(&target_oid, "08b041783f40edfe12bb406c9c9a8a040177c125", GIT_OID_SHA1)); create_note(¬e_oid, "refs/notes/some/namespace", "08b041783f40edfe12bb406c9c9a8a040177c125", "hello world on a custom namespace\n"); @@ -315,7 +315,7 @@ void test_notes_notes__creating_a_note_on_a_target_which_already_has_one_returns int error; git_oid note_oid, target_oid; - cl_git_pass(git_oid_fromstr(&target_oid, "08b041783f40edfe12bb406c9c9a8a040177c125")); + cl_git_pass(git_oid__fromstr(&target_oid, "08b041783f40edfe12bb406c9c9a8a040177c125", GIT_OID_SHA1)); create_note(¬e_oid, NULL, "08b041783f40edfe12bb406c9c9a8a040177c125", "hello world\n"); error = git_note_create(¬e_oid, _repo, NULL, _sig, _sig, &target_oid, "hello world\n", 0); @@ -334,7 +334,7 @@ void test_notes_notes__creating_a_note_on_a_target_can_overwrite_existing_note(v git_oid note_oid, target_oid; git_note *note, *namespace_note; - cl_git_pass(git_oid_fromstr(&target_oid, "08b041783f40edfe12bb406c9c9a8a040177c125")); + cl_git_pass(git_oid__fromstr(&target_oid, "08b041783f40edfe12bb406c9c9a8a040177c125", GIT_OID_SHA1)); create_note(¬e_oid, NULL, "08b041783f40edfe12bb406c9c9a8a040177c125", "hello old world\n"); cl_git_pass(git_note_create(¬e_oid, _repo, NULL, _sig, _sig, &target_oid, "hello new world\n", 1)); @@ -381,7 +381,7 @@ void test_notes_notes__can_read_a_note(void) create_note(¬e_oid, "refs/notes/i-can-see-dead-notes", "4a202b346bb0fb0db7eff3cffeb3c70babbd2045", "I decorate 4a20\n"); - cl_git_pass(git_oid_fromstr(&target_oid, "4a202b346bb0fb0db7eff3cffeb3c70babbd2045")); + cl_git_pass(git_oid__fromstr(&target_oid, "4a202b346bb0fb0db7eff3cffeb3c70babbd2045", GIT_OID_SHA1)); cl_git_pass(git_note_read(¬e, _repo, "refs/notes/i-can-see-dead-notes", &target_oid)); @@ -397,7 +397,7 @@ void test_notes_notes__can_read_a_note_from_a_commit(void) git_commit *notes_commit; git_note *note; - cl_git_pass(git_oid_fromstr(&oid, "4a202b346bb0fb0db7eff3cffeb3c70babbd2045")); + cl_git_pass(git_oid__fromstr(&oid, "4a202b346bb0fb0db7eff3cffeb3c70babbd2045", GIT_OID_SHA1)); cl_git_pass(git_note_commit_create(¬es_commit_oid, NULL, _repo, NULL, _sig, _sig, &oid, "I decorate 4a20\n", 1)); cl_git_pass(git_commit_lookup(¬es_commit, _repo, ¬es_commit_oid)); cl_assert(notes_commit); @@ -416,7 +416,7 @@ void test_notes_notes__attempt_to_read_a_note_from_a_commit_with_no_note_fails(v git_commit *notes_commit; git_note *note; - cl_git_pass(git_oid_fromstr(&oid, "4a202b346bb0fb0db7eff3cffeb3c70babbd2045")); + cl_git_pass(git_oid__fromstr(&oid, "4a202b346bb0fb0db7eff3cffeb3c70babbd2045", GIT_OID_SHA1)); cl_git_pass(git_note_commit_create(¬es_commit_oid, NULL, _repo, NULL, _sig, _sig, &oid, "I decorate 4a20\n", 1)); @@ -450,7 +450,7 @@ void test_notes_notes__can_insert_a_note_in_an_existing_fanout(void) git_oid note_oid, target_oid; git_note *_note; - cl_git_pass(git_oid_fromstr(&target_oid, "08b041783f40edfe12bb406c9c9a8a040177c125")); + cl_git_pass(git_oid__fromstr(&target_oid, "08b041783f40edfe12bb406c9c9a8a040177c125", GIT_OID_SHA1)); for (i = 0; i < MESSAGES_COUNT; i++) { cl_git_pass(git_note_create(¬e_oid, _repo, "refs/notes/fanout", _sig, _sig, &target_oid, messages[i], 0)); @@ -470,10 +470,10 @@ void test_notes_notes__can_read_a_note_in_an_existing_fanout(void) git_oid note_oid, target_oid; git_note *note; - cl_git_pass(git_oid_fromstr(&target_oid, "8496071c1b46c854b31185ea97743be6a8774479")); + cl_git_pass(git_oid__fromstr(&target_oid, "8496071c1b46c854b31185ea97743be6a8774479", GIT_OID_SHA1)); cl_git_pass(git_note_read(¬e, _repo, "refs/notes/fanout", &target_oid)); - cl_git_pass(git_oid_fromstr(¬e_oid, "08b041783f40edfe12bb406c9c9a8a040177c125")); + cl_git_pass(git_oid__fromstr(¬e_oid, "08b041783f40edfe12bb406c9c9a8a040177c125", GIT_OID_SHA1)); cl_assert_equal_oid(git_note_id(note), ¬e_oid); git_note_free(note); @@ -487,7 +487,7 @@ void test_notes_notes__can_remove_a_note(void) create_note(¬e_oid, "refs/notes/i-can-see-dead-notes", "4a202b346bb0fb0db7eff3cffeb3c70babbd2045", "I decorate 4a20\n"); - cl_git_pass(git_oid_fromstr(&target_oid, "4a202b346bb0fb0db7eff3cffeb3c70babbd2045")); + cl_git_pass(git_oid__fromstr(&target_oid, "4a202b346bb0fb0db7eff3cffeb3c70babbd2045", GIT_OID_SHA1)); cl_git_pass(git_note_remove(_repo, "refs/notes/i-can-see-dead-notes", _sig, _sig, &target_oid)); cl_git_fail(git_note_read(¬e, _repo, "refs/notes/i-can-see-dead-notes", &target_oid)); @@ -501,7 +501,7 @@ void test_notes_notes__can_remove_a_note_from_commit(void) git_commit *existing_notes_commit; git_reference *ref; - cl_git_pass(git_oid_fromstr(&oid, "4a202b346bb0fb0db7eff3cffeb3c70babbd2045")); + cl_git_pass(git_oid__fromstr(&oid, "4a202b346bb0fb0db7eff3cffeb3c70babbd2045", GIT_OID_SHA1)); cl_git_pass(git_note_commit_create(¬es_commit_oid, NULL, _repo, NULL, _sig, _sig, &oid, "I decorate 4a20\n", 0)); @@ -528,7 +528,7 @@ void test_notes_notes__can_remove_a_note_in_an_existing_fanout(void) git_oid target_oid; git_note *note; - cl_git_pass(git_oid_fromstr(&target_oid, "8496071c1b46c854b31185ea97743be6a8774479")); + cl_git_pass(git_oid__fromstr(&target_oid, "8496071c1b46c854b31185ea97743be6a8774479", GIT_OID_SHA1)); cl_git_pass(git_note_remove(_repo, "refs/notes/fanout", _sig, _sig, &target_oid)); cl_git_fail(git_note_read(¬e, _repo, "refs/notes/fanout", &target_oid)); @@ -539,7 +539,7 @@ void test_notes_notes__removing_a_note_which_doesnt_exists_returns_ENOTFOUND(voi int error; git_oid target_oid; - cl_git_pass(git_oid_fromstr(&target_oid, "8496071c1b46c854b31185ea97743be6a8774479")); + cl_git_pass(git_oid__fromstr(&target_oid, "8496071c1b46c854b31185ea97743be6a8774479", GIT_OID_SHA1)); cl_git_pass(git_note_remove(_repo, "refs/notes/fanout", _sig, _sig, &target_oid)); error = git_note_remove(_repo, "refs/notes/fanout", _sig, _sig, &target_oid); @@ -628,8 +628,8 @@ void test_notes_notes__iterate_from_commit(void) }; int i, err; - cl_git_pass(git_oid_fromstr(&(oids[0]), "a65fedf39aefe402d3bb6e24df4d4f5fe4547750")); - cl_git_pass(git_oid_fromstr(&(oids[1]), "c47800c7266a2be04c571c04d5a6614691ea99bd")); + cl_git_pass(git_oid__fromstr(&(oids[0]), "a65fedf39aefe402d3bb6e24df4d4f5fe4547750", GIT_OID_SHA1)); + cl_git_pass(git_oid__fromstr(&(oids[1]), "c47800c7266a2be04c571c04d5a6614691ea99bd", GIT_OID_SHA1)); cl_git_pass(git_note_commit_create(¬es_commit_oids[0], NULL, _repo, NULL, _sig, _sig, &(oids[0]), note_message[0], 0)); diff --git a/tests/libgit2/notes/notesref.c b/tests/libgit2/notes/notesref.c index 6ba324c76..8696ff66a 100644 --- a/tests/libgit2/notes/notesref.c +++ b/tests/libgit2/notes/notesref.c @@ -36,7 +36,7 @@ void test_notes_notesref__config_corenotesref(void) git_buf default_ref = GIT_BUF_INIT; cl_git_pass(git_signature_now(&_sig, "alice", "alice@example.com")); - cl_git_pass(git_oid_fromstr(&oid, "8496071c1b46c854b31185ea97743be6a8774479")); + cl_git_pass(git_oid__fromstr(&oid, "8496071c1b46c854b31185ea97743be6a8774479", GIT_OID_SHA1)); cl_git_pass(git_repository_config(&_cfg, _repo)); diff --git a/tests/libgit2/object/blob/fromstream.c b/tests/libgit2/object/blob/fromstream.c index 60ff3991b..dad0b52e1 100644 --- a/tests/libgit2/object/blob/fromstream.c +++ b/tests/libgit2/object/blob/fromstream.c @@ -23,7 +23,7 @@ void test_object_blob_fromstream__multiple_write(void) git_writestream *stream; int i, howmany = 6; - cl_git_pass(git_oid_fromstr(&expected_id, "321cbdf08803c744082332332838df6bd160f8f9")); + cl_git_pass(git_oid__fromstr(&expected_id, "321cbdf08803c744082332332838df6bd160f8f9", GIT_OID_SHA1)); cl_git_fail_with(GIT_ENOTFOUND, git_object_lookup(&blob, repo, &expected_id, GIT_OBJECT_ANY)); @@ -64,7 +64,7 @@ static void assert_named_chunked_blob(const char *expected_sha, const char *fake git_writestream *stream; int i, howmany = 6; - cl_git_pass(git_oid_fromstr(&expected_id, expected_sha)); + cl_git_pass(git_oid__fromstr(&expected_id, expected_sha, GIT_OID_SHA1)); cl_git_pass(git_blob_create_from_stream(&stream, repo, fake_name)); diff --git a/tests/libgit2/object/cache.c b/tests/libgit2/object/cache.c index 08bf03648..bf8c6fb53 100644 --- a/tests/libgit2/object/cache.c +++ b/tests/libgit2/object/cache.c @@ -91,7 +91,7 @@ void test_object_cache__cache_counts(void) for (i = 0; g_data[i].sha != NULL; ++i) { int count = (int)git_cache_size(&g_repo->objects); - cl_git_pass(git_oid_fromstr(&oid, g_data[i].sha)); + cl_git_pass(git_oid__fromstr(&oid, g_data[i].sha, GIT_OID_SHA1)); /* alternate between loading raw and parsed objects */ if ((i & 1) == 0) { @@ -118,7 +118,7 @@ void test_object_cache__cache_counts(void) for (i = 0; g_data[i].sha != NULL; ++i) { int count = (int)git_cache_size(&g_repo->objects); - cl_git_pass(git_oid_fromstr(&oid, g_data[i].sha)); + cl_git_pass(git_oid__fromstr(&oid, g_data[i].sha, GIT_OID_SHA1)); cl_git_pass(git_object_lookup(&obj, g_repo, &oid, GIT_OBJECT_ANY)); cl_assert(g_data[i].type == git_object_type(obj)); git_object_free(obj); @@ -136,14 +136,14 @@ static void *cache_parsed(void *arg) git_object *obj; for (i = ((int *)arg)[1]; g_data[i].sha != NULL; i += 2) { - cl_git_pass(git_oid_fromstr(&oid, g_data[i].sha)); + cl_git_pass(git_oid__fromstr(&oid, g_data[i].sha, GIT_OID_SHA1)); cl_git_pass(git_object_lookup(&obj, g_repo, &oid, GIT_OBJECT_ANY)); cl_assert(g_data[i].type == git_object_type(obj)); git_object_free(obj); } for (i = 0; i < ((int *)arg)[1]; i += 2) { - cl_git_pass(git_oid_fromstr(&oid, g_data[i].sha)); + cl_git_pass(git_oid__fromstr(&oid, g_data[i].sha, GIT_OID_SHA1)); cl_git_pass(git_object_lookup(&obj, g_repo, &oid, GIT_OBJECT_ANY)); cl_assert(g_data[i].type == git_object_type(obj)); git_object_free(obj); @@ -162,14 +162,14 @@ static void *cache_raw(void *arg) cl_git_pass(git_repository_odb(&odb, g_repo)); for (i = ((int *)arg)[1]; g_data[i].sha != NULL; i += 2) { - cl_git_pass(git_oid_fromstr(&oid, g_data[i].sha)); + cl_git_pass(git_oid__fromstr(&oid, g_data[i].sha, GIT_OID_SHA1)); cl_git_pass(git_odb_read(&odb_obj, odb, &oid)); cl_assert(g_data[i].type == git_odb_object_type(odb_obj)); git_odb_object_free(odb_obj); } for (i = 0; i < ((int *)arg)[1]; i += 2) { - cl_git_pass(git_oid_fromstr(&oid, g_data[i].sha)); + cl_git_pass(git_oid__fromstr(&oid, g_data[i].sha, GIT_OID_SHA1)); cl_git_pass(git_odb_read(&odb_obj, odb, &oid)); cl_assert(g_data[i].type == git_odb_object_type(odb_obj)); git_odb_object_free(odb_obj); @@ -234,7 +234,7 @@ static void *cache_quick(void *arg) git_oid oid; git_object *obj; - cl_git_pass(git_oid_fromstr(&oid, g_data[4].sha)); + cl_git_pass(git_oid__fromstr(&oid, g_data[4].sha, GIT_OID_SHA1)); cl_git_pass(git_object_lookup(&obj, g_repo, &oid, GIT_OBJECT_ANY)); cl_assert(g_data[4].type == git_object_type(obj)); git_object_free(obj); diff --git a/tests/libgit2/object/commit/commitstagedfile.c b/tests/libgit2/object/commit/commitstagedfile.c index 7322a4e86..61f50b2af 100644 --- a/tests/libgit2/object/commit/commitstagedfile.c +++ b/tests/libgit2/object/commit/commitstagedfile.c @@ -64,9 +64,9 @@ void test_object_commit_commitstagedfile__generate_predictable_object_ids(void) * 100644 blob 9daeafb9864cf43055ae93beb0afd6c7d144bfa4 test.txt */ - cl_git_pass(git_oid_fromstr(&expected_commit_oid, "1fe3126578fc4eca68c193e4a3a0a14a0704624d")); - cl_git_pass(git_oid_fromstr(&expected_tree_oid, "2b297e643c551e76cfa1f93810c50811382f9117")); - cl_git_pass(git_oid_fromstr(&expected_blob_oid, "9daeafb9864cf43055ae93beb0afd6c7d144bfa4")); + cl_git_pass(git_oid__fromstr(&expected_commit_oid, "1fe3126578fc4eca68c193e4a3a0a14a0704624d", GIT_OID_SHA1)); + cl_git_pass(git_oid__fromstr(&expected_tree_oid, "2b297e643c551e76cfa1f93810c50811382f9117", GIT_OID_SHA1)); + cl_git_pass(git_oid__fromstr(&expected_blob_oid, "9daeafb9864cf43055ae93beb0afd6c7d144bfa4", GIT_OID_SHA1)); /* * Add a new file to the index diff --git a/tests/libgit2/object/commit/parse.c b/tests/libgit2/object/commit/parse.c index 4ff1ad62a..6f9a65507 100644 --- a/tests/libgit2/object/commit/parse.c +++ b/tests/libgit2/object/commit/parse.c @@ -3,7 +3,10 @@ #include "object.h" #include "signature.h" -static void assert_commit_parses(const char *data, size_t datalen, +static void assert_commit_parses( + const char *data, + size_t datalen, + git_oid_t oid_type, const char *expected_treeid, const char *expected_author, const char *expected_committer, @@ -14,7 +17,7 @@ static void assert_commit_parses(const char *data, size_t datalen, git_commit *commit; if (!datalen) datalen = strlen(data); - cl_git_pass(git_object__from_raw((git_object **) &commit, data, datalen, GIT_OBJECT_COMMIT)); + cl_git_pass(git_object__from_raw((git_object **) &commit, data, datalen, GIT_OBJECT_COMMIT, oid_type)); if (expected_author) { git_signature *author; @@ -51,7 +54,7 @@ static void assert_commit_parses(const char *data, size_t datalen, if (expected_treeid) { git_oid tree_oid; - cl_git_pass(git_oid_fromstr(&tree_oid, expected_treeid)); + cl_git_pass(git_oid__fromstr(&tree_oid, expected_treeid, oid_type)); cl_assert_equal_oid(&tree_oid, &commit->tree_id); } @@ -60,15 +63,18 @@ static void assert_commit_parses(const char *data, size_t datalen, git_object__free(&commit->object); } -static void assert_commit_fails(const char *data, size_t datalen) +static void assert_commit_fails( + const char *data, + size_t datalen, + git_oid_t oid_type) { git_object *object; if (!datalen) datalen = strlen(data); - cl_git_fail(git_object__from_raw(&object, data, datalen, GIT_OBJECT_COMMIT)); + cl_git_fail(git_object__from_raw(&object, data, datalen, GIT_OBJECT_COMMIT, oid_type)); } -void test_object_commit_parse__parsing_commit_succeeds(void) +void test_object_commit_parse__sha1_parsing_commit_succeeds(void) { const char *commit = "tree 3e7ac388cadacccdf1c6c5f3445895b71d9cb0f8\n" @@ -77,7 +83,7 @@ void test_object_commit_parse__parsing_commit_succeeds(void) "encoding Encoding\n" "\n" "Message"; - assert_commit_parses(commit, 0, + assert_commit_parses(commit, 0, GIT_OID_SHA1, "3e7ac388cadacccdf1c6c5f3445895b71d9cb0f8", "Author ", "Committer ", @@ -85,7 +91,7 @@ void test_object_commit_parse__parsing_commit_succeeds(void) "Message", 0); } -void test_object_commit_parse__parsing_commit_without_encoding_succeeds(void) +void test_object_commit_parse__sha1_parsing_commit_without_encoding_succeeds(void) { const char *commit = "tree 3e7ac388cadacccdf1c6c5f3445895b71d9cb0f8\n" @@ -93,7 +99,7 @@ void test_object_commit_parse__parsing_commit_without_encoding_succeeds(void) "committer Committer \n" "\n" "Message"; - assert_commit_parses(commit, 0, + assert_commit_parses(commit, 0, GIT_OID_SHA1, "3e7ac388cadacccdf1c6c5f3445895b71d9cb0f8", "Author ", "Committer ", @@ -101,7 +107,7 @@ void test_object_commit_parse__parsing_commit_without_encoding_succeeds(void) "Message", 0); } -void test_object_commit_parse__parsing_commit_with_multiple_authors_succeeds(void) +void test_object_commit_parse__sha1_parsing_commit_with_multiple_authors_succeeds(void) { const char *commit = "tree 3e7ac388cadacccdf1c6c5f3445895b71d9cb0f8\n" @@ -112,7 +118,7 @@ void test_object_commit_parse__parsing_commit_with_multiple_authors_succeeds(voi "committer Committer \n" "\n" "Message"; - assert_commit_parses(commit, 0, + assert_commit_parses(commit, 0, GIT_OID_SHA1, "3e7ac388cadacccdf1c6c5f3445895b71d9cb0f8", "Author1 ", "Committer ", @@ -120,7 +126,7 @@ void test_object_commit_parse__parsing_commit_with_multiple_authors_succeeds(voi "Message", 0); } -void test_object_commit_parse__parsing_commit_with_multiple_committers_succeeds(void) +void test_object_commit_parse__sha1_parsing_commit_with_multiple_committers_succeeds(void) { const char *commit = "tree 3e7ac388cadacccdf1c6c5f3445895b71d9cb0f8\n" @@ -131,7 +137,7 @@ void test_object_commit_parse__parsing_commit_with_multiple_committers_succeeds( "committer Committer4 \n" "\n" "Message"; - assert_commit_parses(commit, 0, + assert_commit_parses(commit, 0, GIT_OID_SHA1, "3e7ac388cadacccdf1c6c5f3445895b71d9cb0f8", "Author ", "Committer1 ", @@ -139,13 +145,13 @@ void test_object_commit_parse__parsing_commit_with_multiple_committers_succeeds( "Message", 0); } -void test_object_commit_parse__parsing_commit_without_message_succeeds(void) +void test_object_commit_parse__sha1_parsing_commit_without_message_succeeds(void) { const char *commit = "tree 3e7ac388cadacccdf1c6c5f3445895b71d9cb0f8\n" "author Author \n" "committer Committer \n"; - assert_commit_parses(commit, 0, + assert_commit_parses(commit, 0, GIT_OID_SHA1, "3e7ac388cadacccdf1c6c5f3445895b71d9cb0f8", "Author ", "Committer ", @@ -153,7 +159,7 @@ void test_object_commit_parse__parsing_commit_without_message_succeeds(void) "", 0); } -void test_object_commit_parse__parsing_commit_with_unknown_fields_succeeds(void) +void test_object_commit_parse__sha1_parsing_commit_with_unknown_fields_succeeds(void) { const char *commit = "tree 3e7ac388cadacccdf1c6c5f3445895b71d9cb0f8\n" @@ -163,7 +169,7 @@ void test_object_commit_parse__parsing_commit_with_unknown_fields_succeeds(void) "more garbage\n" "\n" "Message"; - assert_commit_parses(commit, 0, + assert_commit_parses(commit, 0, GIT_OID_SHA1, "3e7ac388cadacccdf1c6c5f3445895b71d9cb0f8", "Author ", "Committer ", @@ -171,7 +177,7 @@ void test_object_commit_parse__parsing_commit_with_unknown_fields_succeeds(void) "Message", 0); } -void test_object_commit_parse__parsing_commit_with_invalid_tree_fails(void) +void test_object_commit_parse__sha1_parsing_commit_with_invalid_tree_fails(void) { const char *commit = "tree 3e7ac388cadacccdf1xxx5f3445895b71d9cb0f8\n" @@ -179,40 +185,51 @@ void test_object_commit_parse__parsing_commit_with_invalid_tree_fails(void) "committer Committer \n" "\n" "Message"; - assert_commit_fails(commit, 0); + assert_commit_fails(commit, 0, GIT_OID_SHA1); } -void test_object_commit_parse__parsing_commit_without_tree_fails(void) +void test_object_commit_parse__sha1_parsing_commit_with_sha256_tree_fails(void) +{ + const char *commit = + "tree f2a108f86a3b4fd9ad75ed55e9cb3cb46e348fca3b9dba3db64f7c9f64b8a736\n" + "author Author \n" + "committer Committer \n" + "\n" + "Message"; + assert_commit_fails(commit, 0, GIT_OID_SHA1); +} + +void test_object_commit_parse__sha1_parsing_commit_without_tree_fails(void) { const char *commit = "author Author \n" "committer Committer \n" "\n" "Message"; - assert_commit_fails(commit, 0); + assert_commit_fails(commit, 0, GIT_OID_SHA1); } -void test_object_commit_parse__parsing_commit_without_author_fails(void) +void test_object_commit_parse__sha1_parsing_commit_without_author_fails(void) { const char *commit = "tree 3e7ac388cadacccdf1c6c5f3445895b71d9cb0f8\n" "committer Committer \n" "\n" "Message"; - assert_commit_fails(commit, 0); + assert_commit_fails(commit, 0, GIT_OID_SHA1); } -void test_object_commit_parse__parsing_commit_without_committer_fails(void) +void test_object_commit_parse__sha1_parsing_commit_without_committer_fails(void) { const char *commit = "tree 3e7ac388cadacccdf1c6c5f3445895b71d9cb0f8\n" "author Author \n" "\n" "Message"; - assert_commit_fails(commit, 0); + assert_commit_fails(commit, 0, GIT_OID_SHA1); } -void test_object_commit_parse__parsing_encoding_will_not_cause_oob_read(void) +void test_object_commit_parse__sha1_parsing_encoding_will_not_cause_oob_read(void) { const char *commit = "tree 3e7ac388cadacccdf1c6c5f3445895b71d9cb0f8\n" @@ -223,10 +240,237 @@ void test_object_commit_parse__parsing_encoding_will_not_cause_oob_read(void) * As we ignore unknown fields, the cut-off encoding field will be * parsed just fine. */ - assert_commit_parses(commit, strlen(commit) - strlen("ncoding foo\n"), + assert_commit_parses( + commit, strlen(commit) - strlen("ncoding foo\n"), + GIT_OID_SHA1, "3e7ac388cadacccdf1c6c5f3445895b71d9cb0f8", "<>", "<>", NULL, "", 0); } + + +void test_object_commit_parse__sha256_parsing_commit_succeeds(void) +{ +#ifndef GIT_EXPERIMENTAL_SHA256 + cl_skip(); +#else + const char *commit = + "tree f2a108f86a3b4fd9ad75ed55e9cb3cb46e348fca3b9dba3db64f7c9f64b8a736\n" + "author Author \n" + "committer Committer \n" + "encoding Encoding\n" + "\n" + "Message"; + assert_commit_parses(commit, 0, GIT_OID_SHA256, + "f2a108f86a3b4fd9ad75ed55e9cb3cb46e348fca3b9dba3db64f7c9f64b8a736", + "Author ", + "Committer ", + "Encoding", + "Message", 0); +#endif +} + +void test_object_commit_parse__sha256_parsing_commit_without_encoding_succeeds(void) +{ +#ifndef GIT_EXPERIMENTAL_SHA256 + cl_skip(); +#else + const char *commit = + "tree f2a108f86a3b4fd9ad75ed55e9cb3cb46e348fca3b9dba3db64f7c9f64b8a736\n" + "author Author \n" + "committer Committer \n" + "\n" + "Message"; + assert_commit_parses(commit, 0, GIT_OID_SHA256, + "f2a108f86a3b4fd9ad75ed55e9cb3cb46e348fca3b9dba3db64f7c9f64b8a736", + "Author ", + "Committer ", + NULL, + "Message", 0); +#endif +} + +void test_object_commit_parse__sha256_parsing_commit_with_multiple_authors_succeeds(void) +{ +#ifndef GIT_EXPERIMENTAL_SHA256 + cl_skip(); +#else + const char *commit = + "tree f2a108f86a3b4fd9ad75ed55e9cb3cb46e348fca3b9dba3db64f7c9f64b8a736\n" + "author Author1 \n" + "author Author2 \n" + "author Author3 \n" + "author Author4 \n" + "committer Committer \n" + "\n" + "Message"; + assert_commit_parses(commit, 0, GIT_OID_SHA256, + "f2a108f86a3b4fd9ad75ed55e9cb3cb46e348fca3b9dba3db64f7c9f64b8a736", + "Author1 ", + "Committer ", + NULL, + "Message", 0); +#endif +} + +void test_object_commit_parse__sha256_parsing_commit_with_multiple_committers_succeeds(void) +{ +#ifndef GIT_EXPERIMENTAL_SHA256 + cl_skip(); +#else + const char *commit = + "tree f2a108f86a3b4fd9ad75ed55e9cb3cb46e348fca3b9dba3db64f7c9f64b8a736\n" + "author Author \n" + "committer Committer1 \n" + "committer Committer2 \n" + "committer Committer3 \n" + "committer Committer4 \n" + "\n" + "Message"; + assert_commit_parses(commit, 0, GIT_OID_SHA256, + "f2a108f86a3b4fd9ad75ed55e9cb3cb46e348fca3b9dba3db64f7c9f64b8a736", + "Author ", + "Committer1 ", + NULL, + "Message", 0); +#endif +} + +void test_object_commit_parse__sha256_parsing_commit_without_message_succeeds(void) +{ +#ifndef GIT_EXPERIMENTAL_SHA256 + cl_skip(); +#else + const char *commit = + "tree f2a108f86a3b4fd9ad75ed55e9cb3cb46e348fca3b9dba3db64f7c9f64b8a736\n" + "author Author \n" + "committer Committer \n"; + assert_commit_parses(commit, 0, GIT_OID_SHA256, + "f2a108f86a3b4fd9ad75ed55e9cb3cb46e348fca3b9dba3db64f7c9f64b8a736", + "Author ", + "Committer ", + NULL, + "", 0); +#endif +} + +void test_object_commit_parse__sha256_parsing_commit_with_unknown_fields_succeeds(void) +{ +#ifndef GIT_EXPERIMENTAL_SHA256 + cl_skip(); +#else + const char *commit = + "tree f2a108f86a3b4fd9ad75ed55e9cb3cb46e348fca3b9dba3db64f7c9f64b8a736\n" + "author Author \n" + "committer Committer \n" + "foo bar\n" + "more garbage\n" + "\n" + "Message"; + assert_commit_parses(commit, 0, GIT_OID_SHA256, + "f2a108f86a3b4fd9ad75ed55e9cb3cb46e348fca3b9dba3db64f7c9f64b8a736", + "Author ", + "Committer ", + NULL, + "Message", 0); +#endif +} + +void test_object_commit_parse__sha256_parsing_commit_with_invalid_tree_fails(void) +{ +#ifndef GIT_EXPERIMENTAL_SHA256 + cl_skip(); +#else + const char *commit = + "tree f2a108f86a3b4fd9adxxxd55e9cb3cb46e348fca3b9dba3db64f7c9f64b8a736\n" + "author Author \n" + "committer Committer \n" + "\n" + "Message"; + assert_commit_fails(commit, 0, GIT_OID_SHA256); +#endif +} + +void test_object_commit_parse__sha256_parsing_commit_with_sha1_tree_fails(void) +{ +#ifndef GIT_EXPERIMENTAL_SHA256 + cl_skip(); +#else + const char *commit = + "tree 3e7ac388cadacccdf1c6c5f3445895b71d9cb0f8\n" + "author Author \n" + "committer Committer \n" + "\n" + "Message"; + assert_commit_fails(commit, 0, GIT_OID_SHA256); +#endif +} + +void test_object_commit_parse__sha256_parsing_commit_without_tree_fails(void) +{ +#ifndef GIT_EXPERIMENTAL_SHA256 + cl_skip(); +#else + const char *commit = + "author Author \n" + "committer Committer \n" + "\n" + "Message"; + assert_commit_fails(commit, 0, GIT_OID_SHA256); +#endif +} + +void test_object_commit_parse__sha256_parsing_commit_without_author_fails(void) +{ +#ifndef GIT_EXPERIMENTAL_SHA256 + cl_skip(); +#else + const char *commit = + "tree f2a108f86a3b4fd9ad75ed55e9cb3cb46e348fca3b9dba3db64f7c9f64b8a736\n" + "committer Committer \n" + "\n" + "Message"; + assert_commit_fails(commit, 0, GIT_OID_SHA256); +#endif +} + +void test_object_commit_parse__sha256_parsing_commit_without_committer_fails(void) +{ +#ifndef GIT_EXPERIMENTAL_SHA256 + cl_skip(); +#else + const char *commit = + "tree f2a108f86a3b4fd9ad75ed55e9cb3cb46e348fca3b9dba3db64f7c9f64b8a736\n" + "author Author \n" + "\n" + "Message"; + assert_commit_fails(commit, 0, GIT_OID_SHA256); +#endif +} + +void test_object_commit_parse__sha256_parsing_encoding_will_not_cause_oob_read(void) +{ +#ifndef GIT_EXPERIMENTAL_SHA256 + cl_skip(); +#else + const char *commit = + "tree f2a108f86a3b4fd9ad75ed55e9cb3cb46e348fca3b9dba3db64f7c9f64b8a736\n" + "author <>\n" + "committer <>\n" + "encoding foo\n"; + /* + * As we ignore unknown fields, the cut-off encoding field will be + * parsed just fine. + */ + assert_commit_parses( + commit, strlen(commit) - strlen("ncoding foo\n"), + GIT_OID_SHA256, + "f2a108f86a3b4fd9ad75ed55e9cb3cb46e348fca3b9dba3db64f7c9f64b8a736", + "<>", + "<>", + NULL, + "", 0); +#endif +} diff --git a/tests/libgit2/object/lookup.c b/tests/libgit2/object/lookup.c index a7b1ceeb4..7ef1dbd1c 100644 --- a/tests/libgit2/object/lookup.c +++ b/tests/libgit2/object/lookup.c @@ -20,7 +20,7 @@ void test_object_lookup__lookup_wrong_type_returns_enotfound(void) git_oid oid; git_object *object; - cl_git_pass(git_oid_fromstr(&oid, commit)); + cl_git_pass(git_oid__fromstr(&oid, commit, GIT_OID_SHA1)); cl_assert_equal_i( GIT_ENOTFOUND, git_object_lookup(&object, g_repo, &oid, GIT_OBJECT_TAG)); } @@ -31,7 +31,7 @@ void test_object_lookup__lookup_nonexisting_returns_enotfound(void) git_oid oid; git_object *object; - cl_git_pass(git_oid_fromstr(&oid, unknown)); + cl_git_pass(git_oid__fromstr(&oid, unknown, GIT_OID_SHA1)); cl_assert_equal_i( GIT_ENOTFOUND, git_object_lookup(&object, g_repo, &oid, GIT_OBJECT_ANY)); } @@ -42,7 +42,7 @@ void test_object_lookup__lookup_wrong_type_by_abbreviated_id_returns_enotfound(v git_oid oid; git_object *object; - cl_git_pass(git_oid_fromstrn(&oid, commit, strlen(commit))); + cl_git_pass(git_oid__fromstrn(&oid, commit, strlen(commit), GIT_OID_SHA1)); cl_assert_equal_i( GIT_ENOTFOUND, git_object_lookup_prefix(&object, g_repo, &oid, strlen(commit), GIT_OBJECT_TAG)); } @@ -53,7 +53,7 @@ void test_object_lookup__lookup_wrong_type_eventually_returns_enotfound(void) git_oid oid; git_object *object; - cl_git_pass(git_oid_fromstr(&oid, commit)); + cl_git_pass(git_oid__fromstr(&oid, commit, GIT_OID_SHA1)); cl_git_pass(git_object_lookup(&object, g_repo, &oid, GIT_OBJECT_COMMIT)); git_object_free(object); @@ -71,7 +71,7 @@ void test_object_lookup__lookup_corrupt_object_returns_error(void) git_object *object; size_t i; - cl_git_pass(git_oid_fromstr(&oid, commit)); + cl_git_pass(git_oid__fromstr(&oid, commit, GIT_OID_SHA1)); cl_git_pass(git_str_joinpath(&path, git_repository_path(g_repo), file)); cl_git_pass(git_futils_readbuffer(&contents, path.ptr)); @@ -101,7 +101,7 @@ void test_object_lookup__lookup_object_with_wrong_hash_returns_error(void) git_object *object; git_oid oid; - cl_git_pass(git_oid_fromstr(&oid, commit)); + cl_git_pass(git_oid__fromstr(&oid, commit, GIT_OID_SHA1)); /* Copy object to another location with wrong hash */ cl_git_pass(git_str_joinpath(&oldpath, git_repository_path(g_repo), oldloose)); diff --git a/tests/libgit2/object/lookup256.c b/tests/libgit2/object/lookup256.c new file mode 100644 index 000000000..3e1dab661 --- /dev/null +++ b/tests/libgit2/object/lookup256.c @@ -0,0 +1,153 @@ +#include "clar_libgit2.h" + +#include "repository.h" + +#ifdef GIT_EXPERIMENTAL_SHA256 +static git_repository *g_repo; +#endif + +void test_object_lookup256__initialize(void) +{ +#ifdef GIT_EXPERIMENTAL_SHA256 + g_repo = cl_git_sandbox_init("testrepo_256.git"); +#endif +} + +void test_object_lookup256__cleanup(void) +{ +#ifdef GIT_EXPERIMENTAL_SHA256 + cl_git_sandbox_cleanup(); +#endif +} + +void test_object_lookup256__lookup_wrong_type_returns_enotfound(void) +{ +#ifndef GIT_EXPERIMENTAL_SHA256 + cl_skip(); +#else + const char *commit = "4d46d9719e425ef2dfb5bfba098d0b62e21b2b92d0731892eef70db0870e3744"; + git_oid oid; + git_object *object; + + cl_git_pass(git_oid__fromstr(&oid, commit, GIT_OID_SHA256)); + cl_assert_equal_i( + GIT_ENOTFOUND, git_object_lookup(&object, g_repo, &oid, GIT_OBJECT_TAG)); +#endif +} + +void test_object_lookup256__lookup_nonexisting_returns_enotfound(void) +{ +#ifndef GIT_EXPERIMENTAL_SHA256 + cl_skip(); +#else + const char *unknown = "deadbeefdeadbeefdeadbeefdeadbeefdeadbeefdeadbeefdeadbeefdeadbeef"; + git_oid oid; + git_object *object; + + cl_git_pass(git_oid__fromstr(&oid, unknown, GIT_OID_SHA256)); + cl_assert_equal_i( + GIT_ENOTFOUND, git_object_lookup(&object, g_repo, &oid, GIT_OBJECT_ANY)); +#endif +} + +void test_object_lookup256__lookup_wrong_type_by_abbreviated_id_returns_enotfound(void) +{ +#ifndef GIT_EXPERIMENTAL_SHA256 + cl_skip(); +#else + const char *commit = "4d46d97"; + git_oid oid; + git_object *object; + + cl_git_pass(git_oid__fromstrn(&oid, commit, strlen(commit), GIT_OID_SHA256)); + cl_assert_equal_i( + GIT_ENOTFOUND, git_object_lookup_prefix(&object, g_repo, &oid, strlen(commit), GIT_OBJECT_TAG)); +#endif +} + +void test_object_lookup256__lookup_wrong_type_eventually_returns_enotfound(void) +{ +#ifndef GIT_EXPERIMENTAL_SHA256 + cl_skip(); +#else + const char *commit = "4d46d9719e425ef2dfb5bfba098d0b62e21b2b92d0731892eef70db0870e3744"; + git_oid oid; + git_object *object; + + cl_git_pass(git_oid__fromstr(&oid, commit, GIT_OID_SHA256)); + + cl_git_pass(git_object_lookup(&object, g_repo, &oid, GIT_OBJECT_COMMIT)); + git_object_free(object); + + cl_assert_equal_i( + GIT_ENOTFOUND, git_object_lookup(&object, g_repo, &oid, GIT_OBJECT_TAG)); +#endif +} + +void test_object_lookup256__lookup_corrupt_object_returns_error(void) +{ +#ifndef GIT_EXPERIMENTAL_SHA256 + cl_skip(); +#else + const char *commit = "5ca8959deb2b8327458e0344523eb1ddeeef4bce03e35864640b452f84d26848", + *file = "objects/5c/a8959deb2b8327458e0344523eb1ddeeef4bce03e35864640b452f84d26848"; + git_str path = GIT_STR_INIT, contents = GIT_STR_INIT; + git_oid oid; + git_object *object; + size_t i; + + cl_git_pass(git_oid__fromstr(&oid, commit, GIT_OID_SHA256)); + cl_git_pass(git_str_joinpath(&path, git_repository_path(g_repo), file)); + cl_git_pass(git_futils_readbuffer(&contents, path.ptr)); + + /* Corrupt and try to read the object */ + for (i = 0; i < contents.size; i++) { + contents.ptr[i] ^= 0x1; + cl_git_pass(git_futils_writebuffer(&contents, path.ptr, O_RDWR, 0644)); + cl_git_fail(git_object_lookup(&object, g_repo, &oid, GIT_OBJECT_COMMIT)); + contents.ptr[i] ^= 0x1; + } + + /* Restore original content and assert we can read the object */ + cl_git_pass(git_futils_writebuffer(&contents, path.ptr, O_RDWR, 0644)); + cl_git_pass(git_object_lookup(&object, g_repo, &oid, GIT_OBJECT_COMMIT)); + + git_object_free(object); + git_str_dispose(&path); + git_str_dispose(&contents); +#endif +} + +void test_object_lookup256__lookup_object_with_wrong_hash_returns_error(void) +{ +#ifndef GIT_EXPERIMENTAL_SHA256 + cl_skip(); +#else + const char *oldloose = "objects/5c/a8959deb2b8327458e0344523eb1ddeeef4bce03e35864640b452f84d26848", + *newloose = "objects/5c/a8959deb2b8327458e0344523eb1ddeeef4bce03e35864640b452f84d26840", + *commit = "5ca8959deb2b8327458e0344523eb1ddeeef4bce03e35864640b452f84d26840"; + + git_str oldpath = GIT_STR_INIT, newpath = GIT_STR_INIT; + git_object *object; + git_oid oid; + + cl_git_pass(git_oid__fromstr(&oid, commit, GIT_OID_SHA256)); + + /* Copy object to another location with wrong hash */ + cl_git_pass(git_str_joinpath(&oldpath, git_repository_path(g_repo), oldloose)); + cl_git_pass(git_str_joinpath(&newpath, git_repository_path(g_repo), newloose)); + cl_git_pass(git_futils_cp(oldpath.ptr, newpath.ptr, 0644)); + + /* Verify that lookup fails due to a hashsum mismatch */ + cl_git_fail_with(GIT_EMISMATCH, git_object_lookup(&object, g_repo, &oid, GIT_OBJECT_COMMIT)); + + /* Disable verification and try again */ + cl_git_pass(git_libgit2_opts(GIT_OPT_ENABLE_STRICT_HASH_VERIFICATION, 0)); + cl_git_pass(git_object_lookup(&object, g_repo, &oid, GIT_OBJECT_COMMIT)); + cl_git_pass(git_libgit2_opts(GIT_OPT_ENABLE_STRICT_HASH_VERIFICATION, 1)); + + git_object_free(object); + git_str_dispose(&oldpath); + git_str_dispose(&newpath); +#endif +} diff --git a/tests/libgit2/object/peel.c b/tests/libgit2/object/peel.c index 8be6e42d4..da3ef17e2 100644 --- a/tests/libgit2/object/peel.c +++ b/tests/libgit2/object/peel.c @@ -23,12 +23,12 @@ static void assert_peel( git_object *obj; git_object *peeled; - cl_git_pass(git_oid_fromstr(&oid, sha)); + cl_git_pass(git_oid__fromstr(&oid, sha, GIT_OID_SHA1)); cl_git_pass(git_object_lookup(&obj, g_repo, &oid, GIT_OBJECT_ANY)); cl_git_pass(git_object_peel(&peeled, obj, requested_type)); - cl_git_pass(git_oid_fromstr(&expected_oid, expected_sha)); + cl_git_pass(git_oid__fromstr(&expected_oid, expected_sha, GIT_OID_SHA1)); cl_assert_equal_oid(&expected_oid, git_object_id(peeled)); cl_assert_equal_i(expected_type, git_object_type(peeled)); @@ -43,7 +43,7 @@ static void assert_peel_error(int error, const char *sha, git_object_t requested git_object *obj; git_object *peeled; - cl_git_pass(git_oid_fromstr(&oid, sha)); + cl_git_pass(git_oid__fromstr(&oid, sha, GIT_OID_SHA1)); cl_git_pass(git_object_lookup(&obj, g_repo, &oid, GIT_OBJECT_ANY)); cl_assert_equal_i(error, git_object_peel(&peeled, obj, requested_type)); diff --git a/tests/libgit2/object/raw/chars.c b/tests/libgit2/object/raw/chars.c index cde0bdbf6..cb159e9ac 100644 --- a/tests/libgit2/object/raw/chars.c +++ b/tests/libgit2/object/raw/chars.c @@ -19,10 +19,10 @@ void test_object_raw_chars__find_invalid_chars_in_oid(void) in[38] = (char)i; if (git__fromhex(i) >= 0) { exp[19] = (unsigned char)(git__fromhex(i) << 4); - cl_git_pass(git_oid_fromstr(&out, in)); - cl_assert(memcmp(out.id, exp, sizeof(out.id)) == 0); + cl_git_pass(git_oid__fromstr(&out, in, GIT_OID_SHA1)); + cl_assert(memcmp(out.id, exp, GIT_OID_SHA1_SIZE) == 0); } else { - cl_git_fail(git_oid_fromstr(&out, in)); + cl_git_fail(git_oid__fromstr(&out, in, GIT_OID_SHA1)); } } } @@ -36,6 +36,6 @@ void test_object_raw_chars__build_valid_oid_from_raw_bytes(void) 0xb7, 0x75, 0x21, 0x3c, 0x23, 0xa8, 0xbd, 0x74, 0xf5, 0xe0, }; - git_oid_fromraw(&out, exp); - cl_git_pass(memcmp(out.id, exp, sizeof(out.id))); + git_oid__fromraw(&out, exp, GIT_OID_SHA1); + cl_git_pass(memcmp(out.id, exp, GIT_OID_SHA1_SIZE)); } diff --git a/tests/libgit2/object/raw/compare.c b/tests/libgit2/object/raw/compare.c index 56c016b72..9258eef41 100644 --- a/tests/libgit2/object/raw/compare.c +++ b/tests/libgit2/object/raw/compare.c @@ -13,9 +13,9 @@ void test_object_raw_compare__succeed_on_copy_oid(void) 0xa8, 0xbd, 0x74, 0xf5, 0xe0, }; memset(&b, 0, sizeof(b)); - git_oid_fromraw(&a, exp); + git_oid__fromraw(&a, exp, GIT_OID_SHA1); git_oid_cpy(&b, &a); - cl_git_pass(memcmp(a.id, exp, sizeof(a.id))); + cl_git_pass(memcmp(a.id, exp, GIT_OID_SHA1_SIZE)); } void test_object_raw_compare__succeed_on_oid_comparison_lesser(void) @@ -33,8 +33,8 @@ void test_object_raw_compare__succeed_on_oid_comparison_lesser(void) 0xb7, 0x75, 0x21, 0x3c, 0x23, 0xa8, 0xbd, 0x74, 0xf5, 0xf0, }; - git_oid_fromraw(&a, a_in); - git_oid_fromraw(&b, b_in); + git_oid__fromraw(&a, a_in, GIT_OID_SHA1); + git_oid__fromraw(&b, b_in, GIT_OID_SHA1); cl_assert(git_oid_cmp(&a, &b) < 0); } @@ -47,8 +47,8 @@ void test_object_raw_compare__succeed_on_oid_comparison_equal(void) 0xb7, 0x75, 0x21, 0x3c, 0x23, 0xa8, 0xbd, 0x74, 0xf5, 0xe0, }; - git_oid_fromraw(&a, a_in); - git_oid_fromraw(&b, a_in); + git_oid__fromraw(&a, a_in, GIT_OID_SHA1); + git_oid__fromraw(&b, a_in, GIT_OID_SHA1); cl_assert(git_oid_cmp(&a, &b) == 0); } @@ -67,8 +67,8 @@ void test_object_raw_compare__succeed_on_oid_comparison_greater(void) 0xb7, 0x75, 0x21, 0x3c, 0x23, 0xa8, 0xbd, 0x74, 0xf5, 0xd0, }; - git_oid_fromraw(&a, a_in); - git_oid_fromraw(&b, b_in); + git_oid__fromraw(&a, a_in, GIT_OID_SHA1); + git_oid__fromraw(&b, b_in, GIT_OID_SHA1); cl_assert(git_oid_cmp(&a, &b) > 0); } @@ -76,17 +76,17 @@ void test_object_raw_compare__compare_fmt_oids(void) { const char *exp = "16a0123456789abcdef4b775213c23a8bd74f5e0"; git_oid in; - char out[GIT_OID_HEXSZ + 1]; + char out[GIT_OID_SHA1_HEXSIZE + 1]; - cl_git_pass(git_oid_fromstr(&in, exp)); + cl_git_pass(git_oid__fromstr(&in, exp, GIT_OID_SHA1)); /* Format doesn't touch the last byte */ - out[GIT_OID_HEXSZ] = 'Z'; + out[GIT_OID_SHA1_HEXSIZE] = 'Z'; git_oid_fmt(out, &in); - cl_assert(out[GIT_OID_HEXSZ] == 'Z'); + cl_assert(out[GIT_OID_SHA1_HEXSIZE] == 'Z'); /* Format produced the right result */ - out[GIT_OID_HEXSZ] = '\0'; + out[GIT_OID_SHA1_HEXSIZE] = '\0'; cl_assert_equal_s(exp, out); } @@ -96,7 +96,7 @@ void test_object_raw_compare__compare_static_oids(void) git_oid in; char *out; - cl_git_pass(git_oid_fromstr(&in, exp)); + cl_git_pass(git_oid__fromstr(&in, exp, GIT_OID_SHA1)); out = git_oid_tostr_s(&in); cl_assert(out); @@ -108,16 +108,16 @@ void test_object_raw_compare__compare_pathfmt_oids(void) const char *exp1 = "16a0123456789abcdef4b775213c23a8bd74f5e0"; const char *exp2 = "16/a0123456789abcdef4b775213c23a8bd74f5e0"; git_oid in; - char out[GIT_OID_HEXSZ + 2]; + char out[GIT_OID_SHA1_HEXSIZE + 2]; - cl_git_pass(git_oid_fromstr(&in, exp1)); + cl_git_pass(git_oid__fromstr(&in, exp1, GIT_OID_SHA1)); /* Format doesn't touch the last byte */ - out[GIT_OID_HEXSZ + 1] = 'Z'; + out[GIT_OID_SHA1_HEXSIZE + 1] = 'Z'; git_oid_pathfmt(out, &in); - cl_assert(out[GIT_OID_HEXSZ + 1] == 'Z'); + cl_assert(out[GIT_OID_SHA1_HEXSIZE + 1] == 'Z'); /* Format produced the right result */ - out[GIT_OID_HEXSZ + 1] = '\0'; + out[GIT_OID_SHA1_HEXSIZE + 1] = '\0'; cl_assert_equal_s(exp2, out); } diff --git a/tests/libgit2/object/raw/convert.c b/tests/libgit2/object/raw/convert.c index 40a01ae09..962476b97 100644 --- a/tests/libgit2/object/raw/convert.c +++ b/tests/libgit2/object/raw/convert.c @@ -7,11 +7,11 @@ void test_object_raw_convert__succeed_on_oid_to_string_conversion(void) { const char *exp = "16a0123456789abcdef4b775213c23a8bd74f5e0"; git_oid in; - char out[GIT_OID_HEXSZ + 1]; + char out[GIT_OID_SHA1_HEXSIZE + 1]; char *str; int i; - cl_git_pass(git_oid_fromstr(&in, exp)); + cl_git_pass(git_oid__fromstr(&in, exp, GIT_OID_SHA1)); /* NULL buffer pointer, returns static empty string */ str = git_oid_tostr(NULL, sizeof(out), &in); @@ -29,7 +29,7 @@ void test_object_raw_convert__succeed_on_oid_to_string_conversion(void) str = git_oid_tostr(out, 1, &in); cl_assert(str && *str == '\0' && str == out); - for (i = 1; i < GIT_OID_HEXSZ; i++) { + for (i = 1; i < GIT_OID_SHA1_HEXSIZE; i++) { out[i+1] = 'Z'; str = git_oid_tostr(out, i+1, &in); /* returns out containing c-string */ @@ -44,7 +44,7 @@ void test_object_raw_convert__succeed_on_oid_to_string_conversion(void) /* returns out as hex formatted c-string */ str = git_oid_tostr(out, sizeof(out), &in); - cl_assert(str && str == out && *(str+GIT_OID_HEXSZ) == '\0'); + cl_assert(str && str == out && *(str+GIT_OID_SHA1_HEXSIZE) == '\0'); cl_assert_equal_s(exp, out); } @@ -52,26 +52,26 @@ void test_object_raw_convert__succeed_on_oid_to_string_conversion_big(void) { const char *exp = "16a0123456789abcdef4b775213c23a8bd74f5e0"; git_oid in; - char big[GIT_OID_HEXSZ + 1 + 3]; /* note + 4 => big buffer */ + char big[GIT_OID_SHA1_HEXSIZE + 1 + 3]; /* note + 4 => big buffer */ char *str; - cl_git_pass(git_oid_fromstr(&in, exp)); + cl_git_pass(git_oid__fromstr(&in, exp, GIT_OID_SHA1)); /* place some tail material */ - big[GIT_OID_HEXSZ+0] = 'W'; /* should be '\0' afterwards */ - big[GIT_OID_HEXSZ+1] = 'X'; /* should remain untouched */ - big[GIT_OID_HEXSZ+2] = 'Y'; /* ditto */ - big[GIT_OID_HEXSZ+3] = 'Z'; /* ditto */ + big[GIT_OID_SHA1_HEXSIZE+0] = 'W'; /* should be '\0' afterwards */ + big[GIT_OID_SHA1_HEXSIZE+1] = 'X'; /* should remain untouched */ + big[GIT_OID_SHA1_HEXSIZE+2] = 'Y'; /* ditto */ + big[GIT_OID_SHA1_HEXSIZE+3] = 'Z'; /* ditto */ /* returns big as hex formatted c-string */ str = git_oid_tostr(big, sizeof(big), &in); - cl_assert(str && str == big && *(str+GIT_OID_HEXSZ) == '\0'); + cl_assert(str && str == big && *(str+GIT_OID_SHA1_HEXSIZE) == '\0'); cl_assert_equal_s(exp, big); /* check tail material is untouched */ - cl_assert(str && str == big && *(str+GIT_OID_HEXSZ+1) == 'X'); - cl_assert(str && str == big && *(str+GIT_OID_HEXSZ+2) == 'Y'); - cl_assert(str && str == big && *(str+GIT_OID_HEXSZ+3) == 'Z'); + cl_assert(str && str == big && *(str+GIT_OID_SHA1_HEXSIZE+1) == 'X'); + cl_assert(str && str == big && *(str+GIT_OID_SHA1_HEXSIZE+2) == 'Y'); + cl_assert(str && str == big && *(str+GIT_OID_SHA1_HEXSIZE+3) == 'Z'); } static void check_partial_oid( @@ -86,14 +86,14 @@ void test_object_raw_convert__convert_oid_partially(void) { const char *exp = "16a0123456789abcdef4b775213c23a8bd74f5e0"; git_oid in; - char big[GIT_OID_HEXSZ + 1 + 3]; /* note + 4 => big buffer */ + char big[GIT_OID_SHA1_HEXSIZE + 1 + 3]; /* note + 4 => big buffer */ - cl_git_pass(git_oid_fromstr(&in, exp)); + cl_git_pass(git_oid__fromstr(&in, exp, GIT_OID_SHA1)); git_oid_nfmt(big, sizeof(big), &in); cl_assert_equal_s(exp, big); - git_oid_nfmt(big, GIT_OID_HEXSZ + 1, &in); + git_oid_nfmt(big, GIT_OID_SHA1_HEXSIZE + 1, &in); cl_assert_equal_s(exp, big); check_partial_oid(big, 1, &in, "1"); @@ -102,11 +102,11 @@ void test_object_raw_convert__convert_oid_partially(void) check_partial_oid(big, 4, &in, "16a0"); check_partial_oid(big, 5, &in, "16a01"); - check_partial_oid(big, GIT_OID_HEXSZ, &in, exp); + check_partial_oid(big, GIT_OID_SHA1_HEXSIZE, &in, exp); check_partial_oid( - big, GIT_OID_HEXSZ - 1, &in, "16a0123456789abcdef4b775213c23a8bd74f5e"); + big, GIT_OID_SHA1_HEXSIZE - 1, &in, "16a0123456789abcdef4b775213c23a8bd74f5e"); check_partial_oid( - big, GIT_OID_HEXSZ - 2, &in, "16a0123456789abcdef4b775213c23a8bd74f5"); + big, GIT_OID_SHA1_HEXSIZE - 2, &in, "16a0123456789abcdef4b775213c23a8bd74f5"); check_partial_oid( - big, GIT_OID_HEXSZ - 3, &in, "16a0123456789abcdef4b775213c23a8bd74f"); + big, GIT_OID_SHA1_HEXSIZE - 3, &in, "16a0123456789abcdef4b775213c23a8bd74f"); } diff --git a/tests/libgit2/object/raw/fromstr.c b/tests/libgit2/object/raw/fromstr.c index 8c11c105f..302d362d7 100644 --- a/tests/libgit2/object/raw/fromstr.c +++ b/tests/libgit2/object/raw/fromstr.c @@ -6,9 +6,9 @@ void test_object_raw_fromstr__fail_on_invalid_oid_string(void) { git_oid out; - cl_git_fail(git_oid_fromstr(&out, "")); - cl_git_fail(git_oid_fromstr(&out, "moo")); - cl_git_fail(git_oid_fromstr(&out, "16a67770b7d8d72317c4b775213c23a8bd74f5ez")); + cl_git_fail(git_oid__fromstr(&out, "", GIT_OID_SHA1)); + cl_git_fail(git_oid__fromstr(&out, "moo", GIT_OID_SHA1)); + cl_git_fail(git_oid__fromstr(&out, "16a67770b7d8d72317c4b775213c23a8bd74f5ez", GIT_OID_SHA1)); } void test_object_raw_fromstr__succeed_on_valid_oid_string(void) @@ -21,10 +21,9 @@ void test_object_raw_fromstr__succeed_on_valid_oid_string(void) 0xa8, 0xbd, 0x74, 0xf5, 0xe0, }; - cl_git_pass(git_oid_fromstr(&out, "16a67770b7d8d72317c4b775213c23a8bd74f5e0")); - cl_git_pass(memcmp(out.id, exp, sizeof(out.id))); - - cl_git_pass(git_oid_fromstr(&out, "16A67770B7D8D72317C4b775213C23A8BD74F5E0")); - cl_git_pass(memcmp(out.id, exp, sizeof(out.id))); + cl_git_pass(git_oid__fromstr(&out, "16a67770b7d8d72317c4b775213c23a8bd74f5e0", GIT_OID_SHA1)); + cl_git_pass(memcmp(out.id, exp, GIT_OID_SHA1_SIZE)); + cl_git_pass(git_oid__fromstr(&out, "16A67770B7D8D72317C4b775213C23A8BD74F5E0", GIT_OID_SHA1)); + cl_git_pass(memcmp(out.id, exp, GIT_OID_SHA1_SIZE)); } diff --git a/tests/libgit2/object/raw/hash.c b/tests/libgit2/object/raw/hash.c index 8f22fe0ee..0df1afc3a 100644 --- a/tests/libgit2/object/raw/hash.c +++ b/tests/libgit2/object/raw/hash.c @@ -8,11 +8,11 @@ static void hash_object_pass(git_oid *oid, git_rawobj *obj) { - cl_git_pass(git_odb_hash(oid, obj->data, obj->len, obj->type)); + cl_git_pass(git_odb__hash(oid, obj->data, obj->len, obj->type, GIT_OID_SHA1)); } static void hash_object_fail(git_oid *oid, git_rawobj *obj) { - cl_git_fail(git_odb_hash(oid, obj->data, obj->len, obj->type)); + cl_git_fail(git_odb__hash(oid, obj->data, obj->len, obj->type, GIT_OID_SHA1)); } static char *hello_id = "22596363b3de40b06f981fb85d82312e8c0ed511"; @@ -32,16 +32,16 @@ void test_object_raw_hash__hash_by_blocks(void) /* should already be init'd */ cl_git_pass(git_hash_update(&ctx, hello_text, strlen(hello_text))); cl_git_pass(git_hash_final(hash, &ctx)); - cl_git_pass(git_oid_fromraw(&id2, hash)); - cl_git_pass(git_oid_fromstr(&id1, hello_id)); + cl_git_pass(git_oid__fromraw(&id2, hash, GIT_OID_SHA1)); + cl_git_pass(git_oid__fromstr(&id1, hello_id, GIT_OID_SHA1)); cl_assert(git_oid_cmp(&id1, &id2) == 0); /* reinit should permit reuse */ cl_git_pass(git_hash_init(&ctx)); cl_git_pass(git_hash_update(&ctx, bye_text, strlen(bye_text))); cl_git_pass(git_hash_final(hash, &ctx)); - cl_git_pass(git_oid_fromraw(&id2, hash)); - cl_git_pass(git_oid_fromstr(&id1, bye_id)); + cl_git_pass(git_oid__fromraw(&id2, hash, GIT_OID_SHA1)); + cl_git_pass(git_oid__fromstr(&id1, bye_id, GIT_OID_SHA1)); cl_assert(git_oid_cmp(&id1, &id2) == 0); git_hash_ctx_cleanup(&ctx); @@ -52,9 +52,9 @@ void test_object_raw_hash__hash_buffer_in_single_call(void) git_oid id1, id2; unsigned char hash[GIT_HASH_SHA1_SIZE]; - cl_git_pass(git_oid_fromstr(&id1, hello_id)); + cl_git_pass(git_oid__fromstr(&id1, hello_id, GIT_OID_SHA1)); cl_git_pass(git_hash_buf(hash, hello_text, strlen(hello_text), GIT_HASH_ALGORITHM_SHA1)); - cl_git_pass(git_oid_fromraw(&id2, hash)); + cl_git_pass(git_oid__fromraw(&id2, hash, GIT_OID_SHA1)); cl_assert(git_oid_cmp(&id1, &id2) == 0); } @@ -62,15 +62,17 @@ void test_object_raw_hash__hash_vector(void) { git_oid id1, id2; git_str_vec vec[2]; + unsigned char hash[GIT_HASH_SHA1_SIZE]; - cl_git_pass(git_oid_fromstr(&id1, hello_id)); + cl_git_pass(git_oid__fromstr(&id1, hello_id, GIT_OID_SHA1)); vec[0].data = hello_text; vec[0].len = 4; vec[1].data = hello_text+4; vec[1].len = strlen(hello_text)-4; - git_hash_vec(id2.id, vec, 2, GIT_HASH_ALGORITHM_SHA1); + git_hash_vec(hash, vec, 2, GIT_HASH_ALGORITHM_SHA1); + git_oid__fromraw(&id2, hash, GIT_OID_SHA1); cl_assert(git_oid_cmp(&id1, &id2) == 0); } @@ -79,7 +81,7 @@ void test_object_raw_hash__hash_junk_data(void) { git_oid id, id_zero; - cl_git_pass(git_oid_fromstr(&id_zero, zero_id)); + cl_git_pass(git_oid__fromstr(&id_zero, zero_id, GIT_OID_SHA1)); /* invalid types: */ junk_obj.data = some_data; @@ -114,7 +116,7 @@ void test_object_raw_hash__hash_commit_object(void) { git_oid id1, id2; - cl_git_pass(git_oid_fromstr(&id1, commit_id)); + cl_git_pass(git_oid__fromstr(&id1, commit_id, GIT_OID_SHA1)); hash_object_pass(&id2, &commit_obj); cl_assert(git_oid_cmp(&id1, &id2) == 0); } @@ -123,7 +125,7 @@ void test_object_raw_hash__hash_tree_object(void) { git_oid id1, id2; - cl_git_pass(git_oid_fromstr(&id1, tree_id)); + cl_git_pass(git_oid__fromstr(&id1, tree_id, GIT_OID_SHA1)); hash_object_pass(&id2, &tree_obj); cl_assert(git_oid_cmp(&id1, &id2) == 0); } @@ -132,7 +134,7 @@ void test_object_raw_hash__hash_tag_object(void) { git_oid id1, id2; - cl_git_pass(git_oid_fromstr(&id1, tag_id)); + cl_git_pass(git_oid__fromstr(&id1, tag_id, GIT_OID_SHA1)); hash_object_pass(&id2, &tag_obj); cl_assert(git_oid_cmp(&id1, &id2) == 0); } @@ -141,7 +143,7 @@ void test_object_raw_hash__hash_zero_length_object(void) { git_oid id1, id2; - cl_git_pass(git_oid_fromstr(&id1, zero_id)); + cl_git_pass(git_oid__fromstr(&id1, zero_id, GIT_OID_SHA1)); hash_object_pass(&id2, &zero_obj); cl_assert(git_oid_cmp(&id1, &id2) == 0); } @@ -150,7 +152,7 @@ void test_object_raw_hash__hash_one_byte_object(void) { git_oid id1, id2; - cl_git_pass(git_oid_fromstr(&id1, one_id)); + cl_git_pass(git_oid__fromstr(&id1, one_id, GIT_OID_SHA1)); hash_object_pass(&id2, &one_obj); cl_assert(git_oid_cmp(&id1, &id2) == 0); } @@ -159,7 +161,7 @@ void test_object_raw_hash__hash_two_byte_object(void) { git_oid id1, id2; - cl_git_pass(git_oid_fromstr(&id1, two_id)); + cl_git_pass(git_oid__fromstr(&id1, two_id, GIT_OID_SHA1)); hash_object_pass(&id2, &two_obj); cl_assert(git_oid_cmp(&id1, &id2) == 0); } @@ -168,7 +170,7 @@ void test_object_raw_hash__hash_multi_byte_object(void) { git_oid id1, id2; - cl_git_pass(git_oid_fromstr(&id1, some_id)); + cl_git_pass(git_oid__fromstr(&id1, some_id, GIT_OID_SHA1)); hash_object_pass(&id2, &some_obj); cl_assert(git_oid_cmp(&id1, &id2) == 0); } diff --git a/tests/libgit2/object/raw/short.c b/tests/libgit2/object/raw/short.c index cc2b5f62a..f867e6ba1 100644 --- a/tests/libgit2/object/raw/short.c +++ b/tests/libgit2/object/raw/short.c @@ -17,7 +17,7 @@ void test_object_raw_short__oid_shortener_no_duplicates(void) git_oid_shorten_add(os, "16a0123456789abcdef4b775213c23a8bd74f5e0"); min_len = git_oid_shorten_add(os, "ce08fe4884650f067bd5703b6a59a8b3b3c99a09"); - cl_assert(min_len == GIT_OID_HEXSZ + 1); + cl_assert(min_len == GIT_OID_SHA1_HEXSIZE + 1); git_oid_shorten_free(os); } @@ -36,11 +36,11 @@ static int insert_sequential_oids( p_snprintf(numbuf, sizeof(numbuf), "%u", (unsigned int)i); git_hash_buf(hashbuf, numbuf, strlen(numbuf), GIT_HASH_ALGORITHM_SHA1); - git_oid_fromraw(&oid, hashbuf); + git_oid__fromraw(&oid, hashbuf, GIT_OID_SHA1); - oids[i] = git__malloc(GIT_OID_HEXSZ + 1); + oids[i] = git__malloc(GIT_OID_SHA1_HEXSIZE + 1); cl_assert(oids[i]); - git_oid_nfmt(oids[i], GIT_OID_HEXSZ + 1, &oid); + git_oid_nfmt(oids[i], GIT_OID_SHA1_HEXSIZE + 1, &oid); min_len = git_oid_shorten_add(os, oids[i]); diff --git a/tests/libgit2/object/raw/size.c b/tests/libgit2/object/raw/size.c index 930c6de23..a45e1d272 100644 --- a/tests/libgit2/object/raw/size.c +++ b/tests/libgit2/object/raw/size.c @@ -6,8 +6,8 @@ void test_object_raw_size__validate_oid_size(void) { git_oid out; - cl_assert(20 == GIT_OID_RAWSZ); - cl_assert(40 == GIT_OID_HEXSZ); - cl_assert(sizeof(out) == GIT_OID_RAWSZ); - cl_assert(sizeof(out.id) == GIT_OID_RAWSZ); + + cl_assert(20 == GIT_OID_SHA1_SIZE); + cl_assert(40 == GIT_OID_SHA1_HEXSIZE); + cl_assert(sizeof(out.id) == GIT_OID_MAX_SIZE); } diff --git a/tests/libgit2/object/raw/write.c b/tests/libgit2/object/raw/write.c index 40e05f357..346053df5 100644 --- a/tests/libgit2/object/raw/write.c +++ b/tests/libgit2/object/raw/write.c @@ -66,8 +66,8 @@ void test_body(object_data *d, git_rawobj *o) git_rawobj tmp; make_odb_dir(); - cl_git_pass(git_odb_open(&db, odb_dir)); - cl_git_pass(git_oid_fromstr(&id1, d->id)); + cl_git_pass(git_odb__open(&db, odb_dir, NULL)); + cl_git_pass(git_oid__fromstr(&id1, d->id, GIT_OID_SHA1)); streaming_write(&id2, db, o); cl_assert(git_oid_cmp(&id1, &id2) == 0); diff --git a/tests/libgit2/object/shortid.c b/tests/libgit2/object/shortid.c index 9b673efeb..69fceeeda 100644 --- a/tests/libgit2/object/shortid.c +++ b/tests/libgit2/object/shortid.c @@ -19,28 +19,28 @@ void test_object_shortid__select(void) git_object *obj; git_buf shorty = {0}; - git_oid_fromstr(&full, "ce013625030ba8dba906f756967f9e9ca394464a"); + git_oid__fromstr(&full, "ce013625030ba8dba906f756967f9e9ca394464a", GIT_OID_SHA1); cl_git_pass(git_object_lookup(&obj, _repo, &full, GIT_OBJECT_ANY)); cl_git_pass(git_object_short_id(&shorty, obj)); cl_assert_equal_i(7, shorty.size); cl_assert_equal_s("ce01362", shorty.ptr); git_object_free(obj); - git_oid_fromstr(&full, "038d718da6a1ebbc6a7780a96ed75a70cc2ad6e2"); + git_oid__fromstr(&full, "038d718da6a1ebbc6a7780a96ed75a70cc2ad6e2", GIT_OID_SHA1); cl_git_pass(git_object_lookup(&obj, _repo, &full, GIT_OBJECT_ANY)); cl_git_pass(git_object_short_id(&shorty, obj)); cl_assert_equal_i(7, shorty.size); cl_assert_equal_s("038d718", shorty.ptr); git_object_free(obj); - git_oid_fromstr(&full, "dea509d097ce692e167dfc6a48a7a280cc5e877e"); + git_oid__fromstr(&full, "dea509d097ce692e167dfc6a48a7a280cc5e877e", GIT_OID_SHA1); cl_git_pass(git_object_lookup(&obj, _repo, &full, GIT_OBJECT_ANY)); cl_git_pass(git_object_short_id(&shorty, obj)); cl_assert_equal_i(9, shorty.size); cl_assert_equal_s("dea509d09", shorty.ptr); git_object_free(obj); - git_oid_fromstr(&full, "dea509d0b3cb8ee0650f6ca210bc83f4678851ba"); + git_oid__fromstr(&full, "dea509d0b3cb8ee0650f6ca210bc83f4678851ba", GIT_OID_SHA1); cl_git_pass(git_object_lookup(&obj, _repo, &full, GIT_OBJECT_ANY)); cl_git_pass(git_object_short_id(&shorty, obj)); cl_assert_equal_i(9, shorty.size); diff --git a/tests/libgit2/object/tag/parse.c b/tests/libgit2/object/tag/parse.c index 2c0635ae4..d7a4d85bf 100644 --- a/tests/libgit2/object/tag/parse.c +++ b/tests/libgit2/object/tag/parse.c @@ -14,12 +14,12 @@ static void assert_tag_parses(const char *data, size_t datalen, if (!datalen) datalen = strlen(data); - cl_git_pass(git_object__from_raw((git_object **) &tag, data, datalen, GIT_OBJECT_TAG)); + cl_git_pass(git_object__from_raw((git_object **) &tag, data, datalen, GIT_OBJECT_TAG, GIT_OID_SHA1)); cl_assert_equal_i(tag->type, GIT_OBJECT_TAG); if (expected_oid) { git_oid oid; - cl_git_pass(git_oid_fromstr(&oid, expected_oid)); + cl_git_pass(git_oid__fromstr(&oid, expected_oid, GIT_OID_SHA1)); cl_assert_equal_oid(&oid, &tag->target); } @@ -54,7 +54,7 @@ static void assert_tag_fails(const char *data, size_t datalen) git_object *object; if (!datalen) datalen = strlen(data); - cl_git_fail(git_object__from_raw(&object, data, datalen, GIT_OBJECT_TAG)); + cl_git_fail(git_object__from_raw(&object, data, datalen, GIT_OBJECT_TAG, GIT_OID_SHA1)); } void test_object_tag_parse__valid_tag_parses(void) diff --git a/tests/libgit2/object/tag/peel.c b/tests/libgit2/object/tag/peel.c index 7456a8e17..db81c5aee 100644 --- a/tests/libgit2/object/tag/peel.c +++ b/tests/libgit2/object/tag/peel.c @@ -29,7 +29,7 @@ static void retrieve_tag_from_oid(git_tag **tag_out, git_repository *repo, const { git_oid oid; - cl_git_pass(git_oid_fromstr(&oid, sha)); + cl_git_pass(git_oid__fromstr(&oid, sha, GIT_OID_SHA1)); cl_git_pass(git_tag_lookup(tag_out, repo, &oid)); } diff --git a/tests/libgit2/object/tag/read.c b/tests/libgit2/object/tag/read.c index 90ba58029..6270b567a 100644 --- a/tests/libgit2/object/tag/read.c +++ b/tests/libgit2/object/tag/read.c @@ -32,9 +32,9 @@ void test_object_tag_read__parse(void) git_commit *commit; git_oid id1, id2, id_commit; - git_oid_fromstr(&id1, tag1_id); - git_oid_fromstr(&id2, tag2_id); - git_oid_fromstr(&id_commit, tagged_commit); + git_oid__fromstr(&id1, tag1_id, GIT_OID_SHA1); + git_oid__fromstr(&id2, tag2_id, GIT_OID_SHA1); + git_oid__fromstr(&id_commit, tagged_commit, GIT_OID_SHA1); cl_git_pass(git_tag_lookup(&tag1, g_repo, &id1)); @@ -67,8 +67,8 @@ void test_object_tag_read__parse_without_tagger(void) /* TODO: This is a little messy */ cl_git_pass(git_repository_open(&bad_tag_repo, cl_fixture("bad_tag.git"))); - git_oid_fromstr(&id, bad_tag_id); - git_oid_fromstr(&id_commit, badly_tagged_commit); + git_oid__fromstr(&id, bad_tag_id, GIT_OID_SHA1); + git_oid__fromstr(&id_commit, badly_tagged_commit, GIT_OID_SHA1); cl_git_pass(git_tag_lookup(&bad_tag, bad_tag_repo, &id)); cl_assert(bad_tag != NULL); @@ -99,8 +99,8 @@ void test_object_tag_read__parse_without_message(void) /* TODO: This is a little messy */ cl_git_pass(git_repository_open(&short_tag_repo, cl_fixture("short_tag.git"))); - git_oid_fromstr(&id, short_tag_id); - git_oid_fromstr(&id_commit, short_tagged_commit); + git_oid__fromstr(&id, short_tag_id, GIT_OID_SHA1); + git_oid__fromstr(&id_commit, short_tagged_commit, GIT_OID_SHA1); cl_git_pass(git_tag_lookup(&short_tag, short_tag_repo, &id)); cl_assert(short_tag != NULL); @@ -127,7 +127,7 @@ void test_object_tag_read__without_tagger_nor_message(void) cl_git_pass(git_repository_open(&repo, cl_fixture("testrepo.git"))); - cl_git_pass(git_oid_fromstr(&id, taggerless)); + cl_git_pass(git_oid__fromstr(&id, taggerless, GIT_OID_SHA1)); cl_git_pass(git_tag_lookup(&tag, repo, &id)); diff --git a/tests/libgit2/object/tag/write.c b/tests/libgit2/object/tag/write.c index 064f328fd..79e01452a 100644 --- a/tests/libgit2/object/tag/write.c +++ b/tests/libgit2/object/tag/write.c @@ -30,7 +30,7 @@ void test_object_tag_write__basic(void) git_reference *ref_tag; git_object *target; - git_oid_fromstr(&target_id, tagged_commit); + git_oid__fromstr(&target_id, tagged_commit, GIT_OID_SHA1); cl_git_pass(git_object_lookup(&target, g_repo, &target_id, GIT_OBJECT_COMMIT)); /* create signature */ @@ -72,7 +72,7 @@ void test_object_tag_write__overwrite(void) git_signature *tagger; git_object *target; - git_oid_fromstr(&target_id, tagged_commit); + git_oid__fromstr(&target_id, tagged_commit, GIT_OID_SHA1); cl_git_pass(git_object_lookup(&target, g_repo, &target_id, GIT_OBJECT_COMMIT)); /* create signature */ @@ -99,7 +99,7 @@ void test_object_tag_write__replace(void) git_reference *ref_tag; git_object *target; - git_oid_fromstr(&target_id, tagged_commit); + git_oid__fromstr(&target_id, tagged_commit, GIT_OID_SHA1); cl_git_pass(git_object_lookup(&target, g_repo, &target_id, GIT_OBJECT_COMMIT)); cl_git_pass(git_reference_lookup(&ref_tag, g_repo, "refs/tags/e90810b")); @@ -135,7 +135,7 @@ void test_object_tag_write__lightweight(void) git_reference *ref_tag; git_object *target; - git_oid_fromstr(&target_id, tagged_commit); + git_oid__fromstr(&target_id, tagged_commit, GIT_OID_SHA1); cl_git_pass(git_object_lookup(&target, g_repo, &target_id, GIT_OBJECT_COMMIT)); cl_git_pass(git_tag_create_lightweight( @@ -163,7 +163,7 @@ void test_object_tag_write__lightweight_over_existing(void) git_oid target_id, object_id, existing_object_id; git_object *target; - git_oid_fromstr(&target_id, tagged_commit); + git_oid__fromstr(&target_id, tagged_commit, GIT_OID_SHA1); cl_git_pass(git_object_lookup(&target, g_repo, &target_id, GIT_OBJECT_COMMIT)); cl_assert_equal_i(GIT_EEXISTS, git_tag_create_lightweight( @@ -173,7 +173,7 @@ void test_object_tag_write__lightweight_over_existing(void) target, 0)); - git_oid_fromstr(&existing_object_id, tag2_id); + git_oid__fromstr(&existing_object_id, tag2_id, GIT_OID_SHA1); cl_assert(git_oid_cmp(&object_id, &existing_object_id) == 0); git_object_free(target); @@ -197,7 +197,7 @@ void test_object_tag_write__creating_with_an_invalid_name_returns_EINVALIDSPEC(v git_signature *tagger; git_object *target; - git_oid_fromstr(&target_id, tagged_commit); + git_oid__fromstr(&target_id, tagged_commit, GIT_OID_SHA1); cl_git_pass(git_object_lookup(&target, g_repo, &target_id, GIT_OBJECT_COMMIT)); cl_git_pass(git_signature_new(&tagger, tagger_name, tagger_email, 123456789, 60)); @@ -229,7 +229,7 @@ static void create_annotation(git_oid *tag_id, const char *name) cl_git_pass(git_signature_new(&tagger, tagger_name, tagger_email, 123456789, 60)); - git_oid_fromstr(&target_id, tagged_commit); + git_oid__fromstr(&target_id, tagged_commit, GIT_OID_SHA1); cl_git_pass(git_object_lookup(&target, g_repo, &target_id, GIT_OBJECT_COMMIT)); cl_git_pass(git_tag_annotation_create(tag_id, g_repo, name, target, tagger, "boom!")); @@ -265,7 +265,7 @@ void test_object_tag_write__error_when_create_tag_with_invalid_name(void) git_signature *tagger; git_object *target; - git_oid_fromstr(&target_id, tagged_commit); + git_oid__fromstr(&target_id, tagged_commit, GIT_OID_SHA1); cl_git_pass(git_object_lookup(&target, g_repo, &target_id, GIT_OBJECT_COMMIT)); cl_git_pass(git_signature_new(&tagger, tagger_name, tagger_email, 123456789, 60)); diff --git a/tests/libgit2/object/tree/attributes.c b/tests/libgit2/object/tree/attributes.c index 8654dfa31..285d19804 100644 --- a/tests/libgit2/object/tree/attributes.c +++ b/tests/libgit2/object/tree/attributes.c @@ -21,7 +21,7 @@ void test_object_tree_attributes__ensure_correctness_of_attributes_on_insertion( git_treebuilder *builder; git_oid oid; - cl_git_pass(git_oid_fromstr(&oid, blob_oid)); + cl_git_pass(git_oid__fromstr(&oid, blob_oid, GIT_OID_SHA1)); cl_git_pass(git_treebuilder_new(&builder, repo, NULL)); @@ -39,7 +39,7 @@ void test_object_tree_attributes__group_writable_tree_entries_created_with_an_an const git_tree_entry *entry; - cl_git_pass(git_oid_fromstr(&tid, tree_oid)); + cl_git_pass(git_oid__fromstr(&tid, tree_oid, GIT_OID_SHA1)); cl_git_pass(git_tree_lookup(&tree, repo, &tid)); entry = git_tree_entry_byname(tree, "old_mode.txt"); @@ -56,7 +56,7 @@ void test_object_tree_attributes__treebuilder_reject_invalid_filemode(void) git_oid bid; const git_tree_entry *entry; - cl_git_pass(git_oid_fromstr(&bid, blob_oid)); + cl_git_pass(git_oid__fromstr(&bid, blob_oid, GIT_OID_SHA1)); cl_git_pass(git_treebuilder_new(&builder, repo, NULL)); cl_git_fail(git_treebuilder_insert( @@ -76,7 +76,7 @@ void test_object_tree_attributes__normalize_attributes_when_creating_a_tree_from git_tree *tree; const git_tree_entry *entry; - cl_git_pass(git_oid_fromstr(&tid, tree_oid)); + cl_git_pass(git_oid__fromstr(&tid, tree_oid, GIT_OID_SHA1)); cl_git_pass(git_tree_lookup(&tree, repo, &tid)); cl_git_pass(git_treebuilder_new(&builder, repo, tree)); @@ -107,7 +107,7 @@ void test_object_tree_attributes__normalize_600(void) git_tree *tree; const git_tree_entry *entry; - git_oid_fromstr(&id, "0810fb7818088ff5ac41ee49199b51473b1bd6c7"); + git_oid__fromstr(&id, "0810fb7818088ff5ac41ee49199b51473b1bd6c7", GIT_OID_SHA1); cl_git_pass(git_tree_lookup(&tree, repo, &id)); entry = git_tree_entry_byname(tree, "ListaTeste.xml"); diff --git a/tests/libgit2/object/tree/duplicateentries.c b/tests/libgit2/object/tree/duplicateentries.c index c11ae0d3d..e9774cac3 100644 --- a/tests/libgit2/object/tree/duplicateentries.c +++ b/tests/libgit2/object/tree/duplicateentries.c @@ -45,7 +45,7 @@ static void tree_checker( cl_assert_equal_i(1, (int)git_tree_entrycount(tree)); entry = git_tree_entry_byindex(tree, 0); - cl_git_pass(git_oid_fromstr(&oid, expected_sha)); + cl_git_pass(git_oid__fromstr(&oid, expected_sha, GIT_OID_SHA1)); cl_assert_equal_i(0, git_oid_cmp(&oid, git_tree_entry_id(entry))); cl_assert_equal_i(expected_filemode, git_tree_entry_filemode(entry)); @@ -70,15 +70,17 @@ static void two_blobs(git_treebuilder *bld) git_oid oid; const git_tree_entry *entry; - cl_git_pass(git_oid_fromstr(&oid, - "a8233120f6ad708f843d861ce2b7228ec4e3dec6")); /* blob oid (README) */ + cl_git_pass(git_oid__fromstr(&oid, + "a8233120f6ad708f843d861ce2b7228ec4e3dec6", + GIT_OID_SHA1)); /* blob oid (README) */ cl_git_pass(git_treebuilder_insert( &entry, bld, "duplicate", &oid, GIT_FILEMODE_BLOB)); - cl_git_pass(git_oid_fromstr(&oid, - "a71586c1dfe8a71c6cbf6c129f404c5642ff31bd")); /* blob oid (new.txt) */ + cl_git_pass(git_oid__fromstr(&oid, + "a71586c1dfe8a71c6cbf6c129f404c5642ff31bd", + GIT_OID_SHA1)); /* blob oid (new.txt) */ cl_git_pass(git_treebuilder_insert( &entry, bld, "duplicate", &oid, @@ -90,15 +92,17 @@ static void one_blob_and_one_tree(git_treebuilder *bld) git_oid oid; const git_tree_entry *entry; - cl_git_pass(git_oid_fromstr(&oid, - "a8233120f6ad708f843d861ce2b7228ec4e3dec6")); /* blob oid (README) */ + cl_git_pass(git_oid__fromstr(&oid, + "a8233120f6ad708f843d861ce2b7228ec4e3dec6", + GIT_OID_SHA1)); /* blob oid (README) */ cl_git_pass(git_treebuilder_insert( &entry, bld, "duplicate", &oid, GIT_FILEMODE_BLOB)); - cl_git_pass(git_oid_fromstr(&oid, - "4e0883eeeeebc1fb1735161cea82f7cb5fab7e63")); /* tree oid (a) */ + cl_git_pass(git_oid__fromstr(&oid, + "4e0883eeeeebc1fb1735161cea82f7cb5fab7e63", + GIT_OID_SHA1)); /* tree oid (a) */ cl_git_pass(git_treebuilder_insert( &entry, bld, "duplicate", &oid, @@ -127,17 +131,17 @@ static void add_fake_conflicts(git_index *index) ancestor_entry.path = "duplicate"; ancestor_entry.mode = GIT_FILEMODE_BLOB; GIT_INDEX_ENTRY_STAGE_SET(&ancestor_entry, 1); - git_oid_fromstr(&ancestor_entry.id, "a8233120f6ad708f843d861ce2b7228ec4e3dec6"); + git_oid__fromstr(&ancestor_entry.id, "a8233120f6ad708f843d861ce2b7228ec4e3dec6", GIT_OID_SHA1); our_entry.path = "duplicate"; our_entry.mode = GIT_FILEMODE_BLOB; GIT_INDEX_ENTRY_STAGE_SET(&our_entry, 2); - git_oid_fromstr(&our_entry.id, "45b983be36b73c0788dc9cbcb76cbb80fc7bb057"); + git_oid__fromstr(&our_entry.id, "45b983be36b73c0788dc9cbcb76cbb80fc7bb057", GIT_OID_SHA1); their_entry.path = "duplicate"; their_entry.mode = GIT_FILEMODE_BLOB; GIT_INDEX_ENTRY_STAGE_SET(&their_entry, 3); - git_oid_fromstr(&their_entry.id, "a71586c1dfe8a71c6cbf6c129f404c5642ff31bd"); + git_oid__fromstr(&their_entry.id, "a71586c1dfe8a71c6cbf6c129f404c5642ff31bd", GIT_OID_SHA1); cl_git_pass(git_index_conflict_add(index, &ancestor_entry, &our_entry, &their_entry)); } diff --git a/tests/libgit2/object/tree/frompath.c b/tests/libgit2/object/tree/frompath.c index 86ca47e94..147e53e93 100644 --- a/tests/libgit2/object/tree/frompath.c +++ b/tests/libgit2/object/tree/frompath.c @@ -11,7 +11,7 @@ void test_object_tree_frompath__initialize(void) cl_git_pass(git_repository_open(&repo, cl_fixture("testrepo.git"))); cl_assert(repo != NULL); - cl_git_pass(git_oid_fromstr(&id, tree_with_subtrees_oid)); + cl_git_pass(git_oid__fromstr(&id, tree_with_subtrees_oid, GIT_OID_SHA1)); cl_git_pass(git_tree_lookup(&tree, repo, &id)); cl_assert(tree != NULL); } diff --git a/tests/libgit2/object/tree/parse.c b/tests/libgit2/object/tree/parse.c index 4e871dcfa..fc985d672 100644 --- a/tests/libgit2/object/tree/parse.c +++ b/tests/libgit2/object/tree/parse.c @@ -26,7 +26,7 @@ static void assert_tree_parses(const char *data, size_t datalen, if (!datalen) datalen = strlen(data); - cl_git_pass(git_object__from_raw((git_object **) &tree, data, datalen, GIT_OBJECT_TREE)); + cl_git_pass(git_object__from_raw((git_object **) &tree, data, datalen, GIT_OBJECT_TREE, GIT_OID_SHA1)); cl_assert_equal_i(git_tree_entrycount(tree), expected_nentries); @@ -35,7 +35,7 @@ static void assert_tree_parses(const char *data, size_t datalen, const git_tree_entry *entry; git_oid oid; - cl_git_pass(git_oid_fromstr(&oid, expected->oid)); + cl_git_pass(git_oid__fromstr(&oid, expected->oid, GIT_OID_SHA1)); cl_assert(entry = git_tree_entry_byname(tree, expected->filename)); cl_assert_equal_s(expected->filename, entry->filename); @@ -51,7 +51,7 @@ static void assert_tree_fails(const char *data, size_t datalen) git_object *object; if (!datalen) datalen = strlen(data); - cl_git_fail(git_object__from_raw(&object, data, datalen, GIT_OBJECT_TREE)); + cl_git_fail(git_object__from_raw(&object, data, datalen, GIT_OBJECT_TREE, GIT_OID_SHA1)); } void test_object_tree_parse__single_blob_parses(void) diff --git a/tests/libgit2/object/tree/read.c b/tests/libgit2/object/tree/read.c index 95a2e70fb..e18637f03 100644 --- a/tests/libgit2/object/tree/read.c +++ b/tests/libgit2/object/tree/read.c @@ -25,7 +25,7 @@ void test_object_tree_read__loaded(void) git_oid id; git_tree *tree; - git_oid_fromstr(&id, tree_oid); + git_oid__fromstr(&id, tree_oid, GIT_OID_SHA1); cl_git_pass(git_tree_lookup(&tree, g_repo, &id)); @@ -48,7 +48,7 @@ void test_object_tree_read__two(void) const git_tree_entry *entry; git_object *obj; - git_oid_fromstr(&id, tree_oid); + git_oid__fromstr(&id, tree_oid, GIT_OID_SHA1); cl_git_pass(git_tree_lookup(&tree, g_repo, &id)); diff --git a/tests/libgit2/object/tree/update.c b/tests/libgit2/object/tree/update.c index 41b50f3e9..1861ac838 100644 --- a/tests/libgit2/object/tree/update.c +++ b/tests/libgit2/object/tree/update.c @@ -21,10 +21,10 @@ void test_object_tree_update__remove_blob(void) const char *path = "README"; git_tree_update updates[] = { - { GIT_TREE_UPDATE_REMOVE, {{0}}, GIT_FILEMODE_BLOB /* ignored */, path}, + { GIT_TREE_UPDATE_REMOVE, GIT_OID_SHA1_ZERO, GIT_FILEMODE_BLOB /* ignored */, path}, }; - cl_git_pass(git_oid_fromstr(&base_id, "c4dc1555e4d4fa0e0c9c3fc46734c7c35b3ce90b")); + cl_git_pass(git_oid__fromstr(&base_id, "c4dc1555e4d4fa0e0c9c3fc46734c7c35b3ce90b", GIT_OID_SHA1)); cl_git_pass(git_tree_lookup(&base_tree, g_repo, &base_id)); /* Create it with an index */ @@ -50,10 +50,10 @@ void test_object_tree_update__remove_blob_deeper(void) const char *path = "subdir/README"; git_tree_update updates[] = { - { GIT_TREE_UPDATE_REMOVE, {{0}}, GIT_FILEMODE_BLOB /* ignored */, path}, + { GIT_TREE_UPDATE_REMOVE, GIT_OID_SHA1_ZERO, GIT_FILEMODE_BLOB /* ignored */, path}, }; - cl_git_pass(git_oid_fromstr(&base_id, "c4dc1555e4d4fa0e0c9c3fc46734c7c35b3ce90b")); + cl_git_pass(git_oid__fromstr(&base_id, "c4dc1555e4d4fa0e0c9c3fc46734c7c35b3ce90b", GIT_OID_SHA1)); cl_git_pass(git_tree_lookup(&base_tree, g_repo, &base_id)); /* Create it with an index */ @@ -80,11 +80,11 @@ void test_object_tree_update__remove_all_entries(void) const char *path2 = "subdir/subdir2/new.txt"; git_tree_update updates[] = { - { GIT_TREE_UPDATE_REMOVE, {{0}}, GIT_FILEMODE_BLOB /* ignored */, path1}, - { GIT_TREE_UPDATE_REMOVE, {{0}}, GIT_FILEMODE_BLOB /* ignored */, path2}, + { GIT_TREE_UPDATE_REMOVE, GIT_OID_SHA1_ZERO, GIT_FILEMODE_BLOB /* ignored */, path1}, + { GIT_TREE_UPDATE_REMOVE, GIT_OID_SHA1_ZERO, GIT_FILEMODE_BLOB /* ignored */, path2}, }; - cl_git_pass(git_oid_fromstr(&base_id, "c4dc1555e4d4fa0e0c9c3fc46734c7c35b3ce90b")); + cl_git_pass(git_oid__fromstr(&base_id, "c4dc1555e4d4fa0e0c9c3fc46734c7c35b3ce90b", GIT_OID_SHA1)); cl_git_pass(git_tree_lookup(&base_tree, g_repo, &base_id)); /* Create it with an index */ @@ -112,10 +112,10 @@ void test_object_tree_update__replace_blob(void) git_index_entry entry = { {0} }; git_tree_update updates[] = { - { GIT_TREE_UPDATE_UPSERT, {{0}}, GIT_FILEMODE_BLOB, path}, + { GIT_TREE_UPDATE_UPSERT, GIT_OID_SHA1_ZERO, GIT_FILEMODE_BLOB, path}, }; - cl_git_pass(git_oid_fromstr(&base_id, "c4dc1555e4d4fa0e0c9c3fc46734c7c35b3ce90b")); + cl_git_pass(git_oid__fromstr(&base_id, "c4dc1555e4d4fa0e0c9c3fc46734c7c35b3ce90b", GIT_OID_SHA1)); cl_git_pass(git_tree_lookup(&base_tree, g_repo, &base_id)); /* Create it with an index */ @@ -123,7 +123,7 @@ void test_object_tree_update__replace_blob(void) cl_git_pass(git_index_read_tree(idx, base_tree)); entry.path = path; - cl_git_pass(git_oid_fromstr(&entry.id, "fa49b077972391ad58037050f2a75f74e3671e92")); + cl_git_pass(git_oid__fromstr(&entry.id, "fa49b077972391ad58037050f2a75f74e3671e92", GIT_OID_SHA1)); entry.mode = GIT_FILEMODE_BLOB; cl_git_pass(git_index_add(idx, &entry)); @@ -131,7 +131,7 @@ void test_object_tree_update__replace_blob(void) git_index_free(idx); /* Perform the same operation via the tree updater */ - cl_git_pass(git_oid_fromstr(&updates[0].id, "fa49b077972391ad58037050f2a75f74e3671e92")); + cl_git_pass(git_oid__fromstr(&updates[0].id, "fa49b077972391ad58037050f2a75f74e3671e92", GIT_OID_SHA1)); cl_git_pass(git_tree_create_updated(&tree_updater_id, g_repo, base_tree, 1, updates)); cl_assert_equal_oid(&tree_index_id, &tree_updater_id); @@ -153,18 +153,18 @@ void test_object_tree_update__add_blobs(void) }; git_tree_update updates[] = { - { GIT_TREE_UPDATE_UPSERT, {{0}}, GIT_FILEMODE_BLOB, paths[0]}, - { GIT_TREE_UPDATE_UPSERT, {{0}}, GIT_FILEMODE_BLOB, paths[1]}, - { GIT_TREE_UPDATE_UPSERT, {{0}}, GIT_FILEMODE_BLOB, paths[2]}, + { GIT_TREE_UPDATE_UPSERT, GIT_OID_SHA1_ZERO, GIT_FILEMODE_BLOB, paths[0]}, + { GIT_TREE_UPDATE_UPSERT, GIT_OID_SHA1_ZERO, GIT_FILEMODE_BLOB, paths[1]}, + { GIT_TREE_UPDATE_UPSERT, GIT_OID_SHA1_ZERO, GIT_FILEMODE_BLOB, paths[2]}, }; - cl_git_pass(git_oid_fromstr(&base_id, "c4dc1555e4d4fa0e0c9c3fc46734c7c35b3ce90b")); + cl_git_pass(git_oid__fromstr(&base_id, "c4dc1555e4d4fa0e0c9c3fc46734c7c35b3ce90b", GIT_OID_SHA1)); entry.mode = GIT_FILEMODE_BLOB; - cl_git_pass(git_oid_fromstr(&entry.id, "fa49b077972391ad58037050f2a75f74e3671e92")); + cl_git_pass(git_oid__fromstr(&entry.id, "fa49b077972391ad58037050f2a75f74e3671e92", GIT_OID_SHA1)); for (i = 0; i < 3; i++) { - cl_git_pass(git_oid_fromstr(&updates[i].id, "fa49b077972391ad58037050f2a75f74e3671e92")); + cl_git_pass(git_oid__fromstr(&updates[i].id, "fa49b077972391ad58037050f2a75f74e3671e92", GIT_OID_SHA1)); } for (i = 0; i < 2; i++) { @@ -210,18 +210,18 @@ void test_object_tree_update__add_blobs_unsorted(void) }; git_tree_update updates[] = { - { GIT_TREE_UPDATE_UPSERT, {{0}}, GIT_FILEMODE_BLOB, paths[0]}, - { GIT_TREE_UPDATE_UPSERT, {{0}}, GIT_FILEMODE_BLOB, paths[1]}, - { GIT_TREE_UPDATE_UPSERT, {{0}}, GIT_FILEMODE_BLOB, paths[2]}, + { GIT_TREE_UPDATE_UPSERT, GIT_OID_SHA1_ZERO, GIT_FILEMODE_BLOB, paths[0]}, + { GIT_TREE_UPDATE_UPSERT, GIT_OID_SHA1_ZERO, GIT_FILEMODE_BLOB, paths[1]}, + { GIT_TREE_UPDATE_UPSERT, GIT_OID_SHA1_ZERO, GIT_FILEMODE_BLOB, paths[2]}, }; - cl_git_pass(git_oid_fromstr(&base_id, "c4dc1555e4d4fa0e0c9c3fc46734c7c35b3ce90b")); + cl_git_pass(git_oid__fromstr(&base_id, "c4dc1555e4d4fa0e0c9c3fc46734c7c35b3ce90b", GIT_OID_SHA1)); entry.mode = GIT_FILEMODE_BLOB; - cl_git_pass(git_oid_fromstr(&entry.id, "fa49b077972391ad58037050f2a75f74e3671e92")); + cl_git_pass(git_oid__fromstr(&entry.id, "fa49b077972391ad58037050f2a75f74e3671e92", GIT_OID_SHA1)); for (i = 0; i < 3; i++) { - cl_git_pass(git_oid_fromstr(&updates[i].id, "fa49b077972391ad58037050f2a75f74e3671e92")); + cl_git_pass(git_oid__fromstr(&updates[i].id, "fa49b077972391ad58037050f2a75f74e3671e92", GIT_OID_SHA1)); } for (i = 0; i < 2; i++) { @@ -258,12 +258,12 @@ void test_object_tree_update__add_conflict(void) int i; git_oid tree_updater_id; git_tree_update updates[] = { - { GIT_TREE_UPDATE_UPSERT, {{0}}, GIT_FILEMODE_BLOB, "a/dir/blob"}, - { GIT_TREE_UPDATE_UPSERT, {{0}}, GIT_FILEMODE_BLOB, "a/dir"}, + { GIT_TREE_UPDATE_UPSERT, GIT_OID_SHA1_ZERO, GIT_FILEMODE_BLOB, "a/dir/blob"}, + { GIT_TREE_UPDATE_UPSERT, GIT_OID_SHA1_ZERO, GIT_FILEMODE_BLOB, "a/dir"}, }; for (i = 0; i < 2; i++) { - cl_git_pass(git_oid_fromstr(&updates[i].id, "a71586c1dfe8a71c6cbf6c129f404c5642ff31bd")); + cl_git_pass(git_oid__fromstr(&updates[i].id, "a71586c1dfe8a71c6cbf6c129f404c5642ff31bd", GIT_OID_SHA1)); } cl_git_fail(git_tree_create_updated(&tree_updater_id, g_repo, NULL, 2, updates)); @@ -274,12 +274,12 @@ void test_object_tree_update__add_conflict2(void) int i; git_oid tree_updater_id; git_tree_update updates[] = { - { GIT_TREE_UPDATE_UPSERT, {{0}}, GIT_FILEMODE_BLOB, "a/dir/blob"}, - { GIT_TREE_UPDATE_UPSERT, {{0}}, GIT_FILEMODE_TREE, "a/dir/blob"}, + { GIT_TREE_UPDATE_UPSERT, GIT_OID_SHA1_ZERO, GIT_FILEMODE_BLOB, "a/dir/blob"}, + { GIT_TREE_UPDATE_UPSERT, GIT_OID_SHA1_ZERO, GIT_FILEMODE_TREE, "a/dir/blob"}, }; for (i = 0; i < 2; i++) { - cl_git_pass(git_oid_fromstr(&updates[i].id, "a71586c1dfe8a71c6cbf6c129f404c5642ff31bd")); + cl_git_pass(git_oid__fromstr(&updates[i].id, "a71586c1dfe8a71c6cbf6c129f404c5642ff31bd", GIT_OID_SHA1)); } cl_git_fail(git_tree_create_updated(&tree_updater_id, g_repo, NULL, 2, updates)); @@ -290,11 +290,11 @@ void test_object_tree_update__remove_invalid_submodule(void) git_tree *baseline; git_oid updated_tree_id, baseline_id; git_tree_update updates[] = { - {GIT_TREE_UPDATE_REMOVE, {{0}}, GIT_FILEMODE_BLOB, "submodule"}, + {GIT_TREE_UPDATE_REMOVE, GIT_OID_SHA1_ZERO, GIT_FILEMODE_BLOB, "submodule"}, }; /* This tree contains a submodule with an all-zero commit for a submodule named 'submodule' */ - cl_git_pass(git_oid_fromstr(&baseline_id, "396c7f1adb7925f51ba13a75f48252f44c5a14a2")); + cl_git_pass(git_oid__fromstr(&baseline_id, "396c7f1adb7925f51ba13a75f48252f44c5a14a2", GIT_OID_SHA1)); cl_git_pass(git_tree_lookup(&baseline, g_repo, &baseline_id)); cl_git_pass(git_tree_create_updated(&updated_tree_id, g_repo, baseline, 1, updates)); diff --git a/tests/libgit2/object/tree/walk.c b/tests/libgit2/object/tree/walk.c index d1fdaa3a0..573a27849 100644 --- a/tests/libgit2/object/tree/walk.c +++ b/tests/libgit2/object/tree/walk.c @@ -33,7 +33,7 @@ void test_object_tree_walk__0(void) git_tree *tree; int ct; - git_oid_fromstr(&id, tree_oid); + git_oid__fromstr(&id, tree_oid, GIT_OID_SHA1); cl_git_pass(git_tree_lookup(&tree, g_repo, &id)); @@ -77,7 +77,7 @@ void test_object_tree_walk__1(void) git_tree *tree; int ct; - git_oid_fromstr(&id, tree_oid); + git_oid__fromstr(&id, tree_oid, GIT_OID_SHA1); cl_git_pass(git_tree_lookup(&tree, g_repo, &id)); @@ -138,7 +138,7 @@ void test_object_tree_walk__2(void) struct treewalk_skip_data data; /* look up a deep tree */ - git_oid_fromstr(&id, "ae90f12eea699729ed24555e40b9fd669da12a12"); + git_oid__fromstr(&id, "ae90f12eea699729ed24555e40b9fd669da12a12", GIT_OID_SHA1); cl_git_pass(git_tree_lookup(&tree, g_repo, &id)); memset(&data, 0, sizeof(data)); diff --git a/tests/libgit2/object/tree/write.c b/tests/libgit2/object/tree/write.c index a4ceb35b6..71a4c54f6 100644 --- a/tests/libgit2/object/tree/write.c +++ b/tests/libgit2/object/tree/write.c @@ -29,9 +29,9 @@ void test_object_tree_write__from_memory(void) git_tree *tree; git_oid id, bid, rid, id2; - git_oid_fromstr(&id, first_tree); - git_oid_fromstr(&id2, second_tree); - git_oid_fromstr(&bid, blob_oid); + git_oid__fromstr(&id, first_tree, GIT_OID_SHA1); + git_oid__fromstr(&id2, second_tree, GIT_OID_SHA1); + git_oid__fromstr(&bid, blob_oid, GIT_OID_SHA1); /* create a second tree from first tree using `git_treebuilder_insert` * on REPOSITORY_FOLDER. @@ -71,10 +71,10 @@ void test_object_tree_write__subtree(void) git_oid id, bid, subtree_id, id2, id3; git_oid id_hiearar; - git_oid_fromstr(&id, first_tree); - git_oid_fromstr(&id2, second_tree); - git_oid_fromstr(&id3, third_tree); - git_oid_fromstr(&bid, blob_oid); + git_oid__fromstr(&id, first_tree, GIT_OID_SHA1); + git_oid__fromstr(&id2, second_tree, GIT_OID_SHA1); + git_oid__fromstr(&id3, third_tree, GIT_OID_SHA1); + git_oid__fromstr(&bid, blob_oid, GIT_OID_SHA1); /* create subtree */ cl_git_pass(git_treebuilder_new(&builder, g_repo, NULL)); @@ -135,8 +135,8 @@ void test_object_tree_write__sorted_subtrees(void) git_oid bid, tid, tree_oid; - cl_git_pass(git_oid_fromstr(&bid, blob_oid)); - cl_git_pass(git_oid_fromstr(&tid, first_tree)); + cl_git_pass(git_oid__fromstr(&bid, blob_oid, GIT_OID_SHA1)); + cl_git_pass(git_oid__fromstr(&tid, first_tree, GIT_OID_SHA1)); cl_git_pass(git_treebuilder_new(&builder, g_repo, NULL)); @@ -195,7 +195,7 @@ void test_object_tree_write__removing_and_re_adding_in_treebuilder(void) git_oid entry_oid, tree_oid; git_tree *tree; - cl_git_pass(git_oid_fromstr(&entry_oid, blob_oid)); + cl_git_pass(git_oid__fromstr(&entry_oid, blob_oid, GIT_OID_SHA1)); cl_git_pass(git_treebuilder_new(&builder, g_repo, NULL)); @@ -286,7 +286,7 @@ void test_object_tree_write__filtering(void) git_oid entry_oid, tree_oid; git_tree *tree; - git_oid_fromstr(&entry_oid, blob_oid); + git_oid__fromstr(&entry_oid, blob_oid, GIT_OID_SHA1); cl_git_pass(git_treebuilder_new(&builder, g_repo, NULL)); @@ -348,7 +348,7 @@ void test_object_tree_write__cruel_paths(void) int count = 0, i, j; git_tree_entry *te; - git_oid_fromstr(&bid, blob_oid); + git_oid__fromstr(&bid, blob_oid, GIT_OID_SHA1); /* create tree */ cl_git_pass(git_treebuilder_new(&builder, g_repo, NULL)); @@ -411,7 +411,7 @@ void test_object_tree_write__protect_filesystems(void) git_treebuilder *builder; git_oid bid; - cl_git_pass(git_oid_fromstr(&bid, "fa49b077972391ad58037050f2a75f74e3671e92")); + cl_git_pass(git_oid__fromstr(&bid, "fa49b077972391ad58037050f2a75f74e3671e92", GIT_OID_SHA1)); /* Ensure that (by default) we can write objects with funny names on * platforms that are not affected. @@ -460,12 +460,14 @@ static void test_invalid_objects(bool should_allow_invalid) "Expected function call to fail: " #expr), \ NULL, 1) - cl_git_pass(git_oid_fromstr(&valid_blob_id, blob_oid)); - cl_git_pass(git_oid_fromstr(&invalid_blob_id, - "1234567890123456789012345678901234567890")); - cl_git_pass(git_oid_fromstr(&valid_tree_id, first_tree)); - cl_git_pass(git_oid_fromstr(&invalid_tree_id, - "0000000000111111111122222222223333333333")); + cl_git_pass(git_oid__fromstr(&valid_blob_id, blob_oid, GIT_OID_SHA1)); + cl_git_pass(git_oid__fromstr(&invalid_blob_id, + "1234567890123456789012345678901234567890", + GIT_OID_SHA1)); + cl_git_pass(git_oid__fromstr(&valid_tree_id, first_tree, GIT_OID_SHA1)); + cl_git_pass(git_oid__fromstr(&invalid_tree_id, + "0000000000111111111122222222223333333333", + GIT_OID_SHA1)); cl_git_pass(git_treebuilder_new(&builder, g_repo, NULL)); @@ -495,7 +497,7 @@ static void test_inserting_submodule(void) git_treebuilder *bld; git_oid sm_id; - cl_git_pass(git_oid_fromstr(&sm_id, "da39a3ee5e6b4b0d3255bfef95601890afd80709")); + cl_git_pass(git_oid__fromstr(&sm_id, "da39a3ee5e6b4b0d3255bfef95601890afd80709", GIT_OID_SHA1)); cl_git_pass(git_treebuilder_new(&bld, g_repo, NULL)); cl_git_pass(git_treebuilder_insert(NULL, bld, "sm", &sm_id, GIT_FILEMODE_COMMIT)); git_treebuilder_free(bld); @@ -516,7 +518,7 @@ void test_object_tree_write__object_validity(void) void test_object_tree_write__invalid_null_oid(void) { git_treebuilder *bld; - git_oid null_oid = {{0}}; + git_oid null_oid = GIT_OID_SHA1_ZERO; cl_git_pass(git_treebuilder_new(&bld, g_repo, NULL)); cl_git_fail(git_treebuilder_insert(NULL, bld, "null_oid_file", &null_oid, GIT_FILEMODE_BLOB)); diff --git a/tests/libgit2/object/validate.c b/tests/libgit2/object/validate.c index 87193deb6..e11038115 100644 --- a/tests/libgit2/object/validate.c +++ b/tests/libgit2/object/validate.c @@ -1,50 +1,154 @@ #include "clar_libgit2.h" -#define VALID_COMMIT "tree bdd24e358576f1baa275df98cdcaf3ac9a3f4233\n" \ - "parent d6d956f1d66210bfcd0484166befab33b5987a39\n" \ - "author Edward Thomson 1638286404 -0500\n" \ - "committer Edward Thomson 1638324642 -0500\n" \ - "\n" \ - "commit go here.\n" -#define VALID_TREE "100644 HEADER\0\x42\x42\x42\x42\x42\x42\x42\x42\x42\x42\x42\x42\x42\x42\x42\x42\x42\x42\x42\x42" +#define VALID_COMMIT_SHA1 \ + "tree bdd24e358576f1baa275df98cdcaf3ac9a3f4233\n" \ + "parent d6d956f1d66210bfcd0484166befab33b5987a39\n" \ + "author Edward Thomson 1638286404 -0500\n" \ + "committer Edward Thomson 1638324642 -0500\n" \ + "\n" \ + "commit go here.\n" -#define INVALID_COMMIT "tree bdd24e358576f1baa275df98cdcaf3ac9a3f4233\n" \ - "parent d6d956f1d66210bfcd0484166befab33b5987a39\n" \ - "committer Edward Thomson 1638324642 -0500\n" \ - "\n" \ - "commit go here.\n" -#define INVALID_TREE "100644 HEADER \x42\x42\x42\x42\x42\x42\x42\x42\x42\x42\x42\x42\x42\x42\x42\x42\x42\x42\x42\x42" +#define VALID_TREE_SHA1 \ + "100644 HEADER\0\x42\x42\x42\x42\x42\x42\x42\x42\x42\x42\x42\x42\x42\x42\x42\x42\x42\x42\x42\x42" -void test_object_validate__valid(void) +#define INVALID_COMMIT_SHA1 \ + "tree bdd24e358576f1baa275df98cdcaf3ac9a3f4233\n" \ + "parent d6d956f1d66210bfcd0484166befab33b5987a39\n" \ + "committer Edward Thomson 1638324642 -0500\n" \ + "\n" \ + "commit go here.\n" + +#define INVALID_TREE_SHA1 \ + "100644 HEADER \x42\x42\x42\x42\x42\x42\x42\x42\x42\x42\x42\x42\x42\x42\x42\x42\x42\x42\x42\x42" + +#define VALID_COMMIT_SHA256 \ + "tree d0fc7f52dc42358506e7f3f3be72f5271994abb104b9397ab3e19bb42361504d\n" \ + "parent 652412419a24ba62a1d897f40aeb80eecbf873797b04a1bbb8d71918653ef65b\n" \ + "author Edward Thomson 1638286404 -0500\n" \ + "committer Edward Thomson 1638324642 -0500\n" \ + "\n" \ + "commit go here.\n" + +#define VALID_TREE_SHA256 \ + "100644 HEADER\0\x42\x42\x42\x42\x42\x42\x42\x42\x42\x42\x42\x42\x42\x42\x42\x42\x42\x42\x42\x42\x42\x42\x42\x42\x42\x42\x42\x42\x42\x42\x42\x42" + +#define INVALID_COMMIT_SHA256 \ + "tree d0fc7f52dc42358506e7f3f3be72f5271994abb104b9397ab3e19bb42361504d\n" \ + "parent 652412419a24ba62a1d897f40aeb80eecbf873797b04a1bbb8d71918653ef65b\n" \ + "committer Edward Thomson 1638324642 -0500\n" \ + "\n" \ + "commit go here.\n" + +#define INVALID_TREE_SHA256 \ + "100644 HEADER \x42\x42\x42\x42\x42\x42\x42\x42\x42\x42\x42\x42\x42\x42\x42\x42\x42\x42\x42\x42\x42\x42\x42\x42\x42\x42\x42\x42\x42\x42\x42\x42" + +#ifdef GIT_EXPERIMENTAL_SHA256 +# define sha1_rawcontent_is_valid(v, c, l, t) \ + git_object_rawcontent_is_valid(v, c, l, t, GIT_OID_SHA1) +#else +# define sha1_rawcontent_is_valid(v, c, l, t) \ + git_object_rawcontent_is_valid(v, c, l, t) +#endif + +void test_object_validate__valid_sha1(void) { int valid; - cl_git_pass(git_object_rawcontent_is_valid(&valid, "", 0, GIT_OBJECT_BLOB)); + cl_git_pass(sha1_rawcontent_is_valid(&valid, "", 0, GIT_OBJECT_BLOB)); cl_assert_equal_i(1, valid); - cl_git_pass(git_object_rawcontent_is_valid(&valid, "foobar", 0, GIT_OBJECT_BLOB)); + cl_git_pass(sha1_rawcontent_is_valid(&valid, "foobar", 0, GIT_OBJECT_BLOB)); cl_assert_equal_i(1, valid); - cl_git_pass(git_object_rawcontent_is_valid(&valid, VALID_COMMIT, CONST_STRLEN(VALID_COMMIT), GIT_OBJECT_COMMIT)); + cl_git_pass(sha1_rawcontent_is_valid(&valid, VALID_COMMIT_SHA1, CONST_STRLEN(VALID_COMMIT_SHA1), GIT_OBJECT_COMMIT)); cl_assert_equal_i(1, valid); - cl_git_pass(git_object_rawcontent_is_valid(&valid, VALID_TREE, CONST_STRLEN(VALID_TREE), GIT_OBJECT_TREE)); + cl_git_pass(sha1_rawcontent_is_valid(&valid, VALID_TREE_SHA1, CONST_STRLEN(VALID_TREE_SHA1), GIT_OBJECT_TREE)); cl_assert_equal_i(1, valid); } -void test_object_validate__invalid(void) +void test_object_validate__cannot_parse_sha256_as_sha1(void) { int valid; - cl_git_pass(git_object_rawcontent_is_valid(&valid, "", 0, GIT_OBJECT_COMMIT)); + cl_git_pass(sha1_rawcontent_is_valid(&valid, VALID_COMMIT_SHA256, CONST_STRLEN(INVALID_COMMIT_SHA256), GIT_OBJECT_COMMIT)); cl_assert_equal_i(0, valid); - cl_git_pass(git_object_rawcontent_is_valid(&valid, "foobar", 0, GIT_OBJECT_COMMIT)); - cl_assert_equal_i(0, valid); - - cl_git_pass(git_object_rawcontent_is_valid(&valid, INVALID_COMMIT, CONST_STRLEN(INVALID_COMMIT), GIT_OBJECT_COMMIT)); - cl_assert_equal_i(0, valid); - - cl_git_pass(git_object_rawcontent_is_valid(&valid, INVALID_TREE, CONST_STRLEN(INVALID_TREE), GIT_OBJECT_TREE)); + cl_git_pass(sha1_rawcontent_is_valid(&valid, INVALID_TREE_SHA256, CONST_STRLEN(INVALID_TREE_SHA256), GIT_OBJECT_TREE)); cl_assert_equal_i(0, valid); } + +void test_object_validate__invalid_sha1(void) +{ + int valid; + + cl_git_pass(sha1_rawcontent_is_valid(&valid, "", 0, GIT_OBJECT_COMMIT)); + cl_assert_equal_i(0, valid); + + cl_git_pass(sha1_rawcontent_is_valid(&valid, "foobar", 0, GIT_OBJECT_COMMIT)); + cl_assert_equal_i(0, valid); + + cl_git_pass(sha1_rawcontent_is_valid(&valid, INVALID_COMMIT_SHA1, CONST_STRLEN(INVALID_COMMIT_SHA1), GIT_OBJECT_COMMIT)); + cl_assert_equal_i(0, valid); + + cl_git_pass(sha1_rawcontent_is_valid(&valid, INVALID_TREE_SHA1, CONST_STRLEN(INVALID_TREE_SHA1), GIT_OBJECT_TREE)); + cl_assert_equal_i(0, valid); +} + + +void test_object_validate__valid_sha256(void) +{ +#ifndef GIT_EXPERIMENTAL_SHA256 + cl_skip(); +#else + int valid; + + cl_git_pass(git_object_rawcontent_is_valid(&valid, "", 0, GIT_OBJECT_BLOB, GIT_OID_SHA256)); + cl_assert_equal_i(1, valid); + + cl_git_pass(git_object_rawcontent_is_valid(&valid, "foobar", 0, GIT_OBJECT_BLOB, GIT_OID_SHA256)); + cl_assert_equal_i(1, valid); + + cl_git_pass(git_object_rawcontent_is_valid(&valid, VALID_COMMIT_SHA256, CONST_STRLEN(VALID_COMMIT_SHA256), GIT_OBJECT_COMMIT, GIT_OID_SHA256)); + cl_assert_equal_i(1, valid); + + cl_git_pass(git_object_rawcontent_is_valid(&valid, VALID_TREE_SHA256, CONST_STRLEN(VALID_TREE_SHA256), GIT_OBJECT_TREE, GIT_OID_SHA256)); + cl_assert_equal_i(1, valid); +#endif +} + +void test_object_validate__invalid_sha256(void) +{ +#ifndef GIT_EXPERIMENTAL_SHA256 + cl_skip(); +#else + int valid; + + cl_git_pass(git_object_rawcontent_is_valid(&valid, "", 0, GIT_OBJECT_COMMIT, GIT_OID_SHA256)); + cl_assert_equal_i(0, valid); + + cl_git_pass(git_object_rawcontent_is_valid(&valid, "foobar", 0, GIT_OBJECT_COMMIT, GIT_OID_SHA256)); + cl_assert_equal_i(0, valid); + + cl_git_pass(git_object_rawcontent_is_valid(&valid, INVALID_COMMIT_SHA256, CONST_STRLEN(INVALID_COMMIT_SHA256), GIT_OBJECT_COMMIT, GIT_OID_SHA256)); + cl_assert_equal_i(0, valid); + + cl_git_pass(git_object_rawcontent_is_valid(&valid, INVALID_TREE_SHA256, CONST_STRLEN(INVALID_TREE_SHA256), GIT_OBJECT_TREE, GIT_OID_SHA256)); + cl_assert_equal_i(0, valid); +#endif +} + +void test_object_validate__cannot_parse_sha1_as_sha256(void) +{ +#ifndef GIT_EXPERIMENTAL_SHA256 + cl_skip(); +#else + int valid; + + cl_git_pass(git_object_rawcontent_is_valid(&valid, VALID_COMMIT_SHA1, CONST_STRLEN(INVALID_COMMIT_SHA1), GIT_OBJECT_COMMIT, GIT_OID_SHA256)); + cl_assert_equal_i(0, valid); + + cl_git_pass(git_object_rawcontent_is_valid(&valid, INVALID_TREE_SHA1, CONST_STRLEN(INVALID_TREE_SHA1), GIT_OBJECT_TREE, GIT_OID_SHA256)); + cl_assert_equal_i(0, valid); +#endif +} diff --git a/tests/libgit2/odb/alternates.c b/tests/libgit2/odb/alternates.c index 6c00fda2f..4d2da6b1f 100644 --- a/tests/libgit2/odb/alternates.c +++ b/tests/libgit2/odb/alternates.c @@ -52,7 +52,7 @@ void test_odb_alternates__chained(void) /* Now load B and see if we can find an object from testrepo.git */ cl_git_pass(git_repository_open(&repo, paths[1])); - git_oid_fromstr(&oid, "a65fedf39aefe402d3bb6e24df4d4f5fe4547750"); + git_oid__fromstr(&oid, "a65fedf39aefe402d3bb6e24df4d4f5fe4547750", GIT_OID_SHA1); cl_git_pass(git_commit_lookup(&commit, repo, &oid)); git_commit_free(commit); git_repository_free(repo); @@ -74,7 +74,7 @@ void test_odb_alternates__long_chain(void) /* Now load the last one and see if we can find an object from testrepo.git */ cl_git_pass(git_repository_open(&repo, paths[ARRAY_SIZE(paths)-1])); - git_oid_fromstr(&oid, "a65fedf39aefe402d3bb6e24df4d4f5fe4547750"); + git_oid__fromstr(&oid, "a65fedf39aefe402d3bb6e24df4d4f5fe4547750", GIT_OID_SHA1); cl_git_fail(git_commit_lookup(&commit, repo, &oid)); git_repository_free(repo); } diff --git a/tests/libgit2/odb/backend/backend_helpers.c b/tests/libgit2/odb/backend/backend_helpers.c index 542799242..c1a0070d6 100644 --- a/tests/libgit2/odb/backend/backend_helpers.c +++ b/tests/libgit2/odb/backend/backend_helpers.c @@ -9,7 +9,7 @@ static int search_object(const fake_object **out, fake_backend *fake, const git_ while (obj && obj->oid) { git_oid current_oid; - git_oid_fromstr(¤t_oid, obj->oid); + git_oid__fromstr(¤t_oid, obj->oid, GIT_OID_SHA1); if (git_oid_ncmp(¤t_oid, oid, len) == 0) { if (found) @@ -34,7 +34,7 @@ static int fake_backend__exists(git_odb_backend *backend, const git_oid *oid) fake->exists_calls++; - return search_object(NULL, fake, oid, GIT_OID_HEXSZ) == GIT_OK; + return search_object(NULL, fake, oid, GIT_OID_SHA1_HEXSIZE) == GIT_OK; } static int fake_backend__exists_prefix( @@ -52,7 +52,7 @@ static int fake_backend__exists_prefix( return error; if (out) - git_oid_fromstr(out, obj->oid); + git_oid__fromstr(out, obj->oid, GIT_OID_SHA1); return 0; } @@ -69,7 +69,7 @@ static int fake_backend__read( fake->read_calls++; - if ((error = search_object(&obj, fake, oid, GIT_OID_HEXSZ)) < 0) + if ((error = search_object(&obj, fake, oid, GIT_OID_SHA1_HEXSIZE)) < 0) return error; *len_p = strlen(obj->content); @@ -91,7 +91,7 @@ static int fake_backend__read_header( fake->read_header_calls++; - if ((error = search_object(&obj, fake, oid, GIT_OID_HEXSZ)) < 0) + if ((error = search_object(&obj, fake, oid, GIT_OID_SHA1_HEXSIZE)) < 0) return error; *len_p = strlen(obj->content); @@ -115,7 +115,7 @@ static int fake_backend__read_prefix( if ((error = search_object(&obj, fake, short_oid, len)) < 0) return error; - git_oid_fromstr(out_oid, obj->oid); + git_oid__fromstr(out_oid, obj->oid, GIT_OID_SHA1); *len_p = strlen(obj->content); *buffer_p = git__strdup(obj->content); *type_p = GIT_OBJECT_BLOB; diff --git a/tests/libgit2/odb/backend/loose.c b/tests/libgit2/odb/backend/loose.c new file mode 100644 index 000000000..781b61d9f --- /dev/null +++ b/tests/libgit2/odb/backend/loose.c @@ -0,0 +1,43 @@ +#include "clar_libgit2.h" +#include "repository.h" +#include "odb.h" +#include "backend_helpers.h" +#include "git2/sys/mempack.h" + +static git_repository *_repo; +static git_odb *_odb; + +void test_odb_backend_loose__initialize(void) +{ + git_odb_backend *backend; + + cl_fixture_sandbox("testrepo.git"); + +#ifdef GIT_EXPERIMENTAL_SHA256 + cl_git_pass(git_odb_backend_loose(&backend, "testrepo.git/objects", NULL)); +#else + cl_git_pass(git_odb_backend_loose(&backend, "testrepo.git/objects", 0, 0, 0, 0)); +#endif + + cl_git_pass(git_odb__new(&_odb, NULL)); + cl_git_pass(git_odb_add_backend(_odb, backend, 10)); + cl_git_pass(git_repository_wrap_odb(&_repo, _odb)); +} + +void test_odb_backend_loose__cleanup(void) +{ + git_odb_free(_odb); + git_repository_free(_repo); + + cl_fixture_cleanup("testrepo.git"); +} + +void test_odb_backend_loose__read(void) +{ + git_oid oid; + git_odb_object *obj; + + cl_git_pass(git_oid__fromstr(&oid, "1385f264afb75a56a5bec74243be9b367ba4ca08", GIT_OID_SHA1)); + cl_git_pass(git_odb_read(&obj, _odb, &oid)); + git_odb_object_free(obj); +} diff --git a/tests/libgit2/odb/backend/mempack.c b/tests/libgit2/odb/backend/mempack.c index 2eeed51aa..eb8ab3cb0 100644 --- a/tests/libgit2/odb/backend/mempack.c +++ b/tests/libgit2/odb/backend/mempack.c @@ -1,5 +1,6 @@ #include "clar_libgit2.h" #include "repository.h" +#include "odb.h" #include "backend_helpers.h" #include "git2/sys/mempack.h" @@ -13,7 +14,7 @@ void test_odb_backend_mempack__initialize(void) git_odb_backend *backend; cl_git_pass(git_mempack_new(&backend)); - cl_git_pass(git_odb_new(&_odb)); + cl_git_pass(git_odb__new(&_odb, NULL)); cl_git_pass(git_odb_add_backend(_odb, backend, 10)); cl_git_pass(git_repository_wrap_odb(&_repo, _odb)); } @@ -34,13 +35,13 @@ void test_odb_backend_mempack__write_succeeds(void) void test_odb_backend_mempack__read_of_missing_object_fails(void) { - cl_git_pass(git_oid_fromstr(&_oid, "f6ea0495187600e7b2288c8ac19c5886383a4633")); + cl_git_pass(git_oid__fromstr(&_oid, "f6ea0495187600e7b2288c8ac19c5886383a4633", GIT_OID_SHA1)); cl_git_fail_with(GIT_ENOTFOUND, git_odb_read(&_obj, _odb, &_oid)); } void test_odb_backend_mempack__exists_of_missing_object_fails(void) { - cl_git_pass(git_oid_fromstr(&_oid, "f6ea0495187600e7b2288c8ac19c5886383a4633")); + cl_git_pass(git_oid__fromstr(&_oid, "f6ea0495187600e7b2288c8ac19c5886383a4633", GIT_OID_SHA1)); cl_assert(git_odb_exists(_odb, &_oid) == 0); } diff --git a/tests/libgit2/odb/backend/multiple.c b/tests/libgit2/odb/backend/multiple.c index 5f1eacd52..97588164d 100644 --- a/tests/libgit2/odb/backend/multiple.c +++ b/tests/libgit2/odb/backend/multiple.c @@ -24,7 +24,7 @@ void test_odb_backend_multiple__initialize(void) { git_odb_backend *backend; - git_oid_fromstr(&_existing_oid, EXISTING_HASH); + git_oid__fromstr(&_existing_oid, EXISTING_HASH, GIT_OID_SHA1); _obj = NULL; _repo = cl_git_sandbox_init("testrepo.git"); diff --git a/tests/libgit2/odb/backend/nobackend.c b/tests/libgit2/odb/backend/nobackend.c index 7484d423b..7d9394c6f 100644 --- a/tests/libgit2/odb/backend/nobackend.c +++ b/tests/libgit2/odb/backend/nobackend.c @@ -1,5 +1,6 @@ #include "clar_libgit2.h" #include "repository.h" +#include "odb.h" #include "git2/sys/repository.h" static git_repository *_repo; @@ -12,7 +13,7 @@ void test_odb_backend_nobackend__initialize(void) cl_git_pass(git_repository_new(&_repo)); cl_git_pass(git_config_new(&config)); - cl_git_pass(git_odb_new(&odb)); + cl_git_pass(git_odb__new(&odb, NULL)); cl_git_pass(git_refdb_new(&refdb, _repo)); git_repository_set_config(_repo, config); diff --git a/tests/libgit2/odb/backend/nonrefreshing.c b/tests/libgit2/odb/backend/nonrefreshing.c index 2db10efbc..5084eb7f7 100644 --- a/tests/libgit2/odb/backend/nonrefreshing.c +++ b/tests/libgit2/odb/backend/nonrefreshing.c @@ -33,8 +33,8 @@ static void setup_repository_and_backend(void) void test_odb_backend_nonrefreshing__initialize(void) { - git_oid_fromstr(&_nonexisting_oid, NONEXISTING_HASH); - git_oid_fromstr(&_existing_oid, EXISTING_HASH); + git_oid__fromstr(&_nonexisting_oid, NONEXISTING_HASH, GIT_OID_SHA1); + git_oid__fromstr(&_existing_oid, EXISTING_HASH, GIT_OID_SHA1); setup_repository_and_backend(); } diff --git a/tests/libgit2/odb/backend/refreshing.c b/tests/libgit2/odb/backend/refreshing.c index 9e49298a8..fcba748ee 100644 --- a/tests/libgit2/odb/backend/refreshing.c +++ b/tests/libgit2/odb/backend/refreshing.c @@ -33,8 +33,8 @@ static void setup_repository_and_backend(void) void test_odb_backend_refreshing__initialize(void) { - git_oid_fromstr(&_nonexisting_oid, NONEXISTING_HASH); - git_oid_fromstr(&_existing_oid, EXISTING_HASH); + git_oid__fromstr(&_nonexisting_oid, NONEXISTING_HASH, GIT_OID_SHA1); + git_oid__fromstr(&_existing_oid, EXISTING_HASH, GIT_OID_SHA1); setup_repository_and_backend(); } diff --git a/tests/libgit2/odb/backend/simple.c b/tests/libgit2/odb/backend/simple.c index 6c9293ac0..25dfd90a2 100644 --- a/tests/libgit2/odb/backend/simple.c +++ b/tests/libgit2/odb/backend/simple.c @@ -49,7 +49,7 @@ void test_odb_backend_simple__read_of_object_succeeds(void) setup_backend(objs); - cl_git_pass(git_oid_fromstr(&_oid, objs[0].oid)); + cl_git_pass(git_oid__fromstr(&_oid, objs[0].oid, GIT_OID_SHA1)); cl_git_pass(git_odb_read(&_obj, _odb, &_oid)); assert_object_contains(_obj, objs[0].content); @@ -64,7 +64,7 @@ void test_odb_backend_simple__read_of_nonexisting_object_fails(void) setup_backend(objs); - cl_git_pass(git_oid_fromstr(&_oid, "f6ea0495187600e7b2288c8ac19c5886383a4633")); + cl_git_pass(git_oid__fromstr(&_oid, "f6ea0495187600e7b2288c8ac19c5886383a4633", GIT_OID_SHA1)); cl_git_fail_with(GIT_ENOTFOUND, git_odb_read(&_obj, _odb, &_oid)); } @@ -77,7 +77,7 @@ void test_odb_backend_simple__read_with_hash_mismatch_fails(void) setup_backend(objs); - cl_git_pass(git_oid_fromstr(&_oid, objs[0].oid)); + cl_git_pass(git_oid__fromstr(&_oid, objs[0].oid, GIT_OID_SHA1)); cl_git_fail_with(GIT_EMISMATCH, git_odb_read(&_obj, _odb, &_oid)); } @@ -89,7 +89,7 @@ void test_odb_backend_simple__read_with_hash_mismatch_succeeds_without_verificat }; setup_backend(objs); - cl_git_pass(git_oid_fromstr(&_oid, objs[0].oid)); + cl_git_pass(git_oid__fromstr(&_oid, objs[0].oid, GIT_OID_SHA1)); cl_git_pass(git_libgit2_opts(GIT_OPT_ENABLE_STRICT_HASH_VERIFICATION, 0)); cl_git_pass(git_odb_read(&_obj, _odb, &_oid)); @@ -106,7 +106,7 @@ void test_odb_backend_simple__read_prefix_succeeds(void) setup_backend(objs); - cl_git_pass(git_oid_fromstr(&_oid, "f6ea0495187600e7b2288c8ac19c5886383a4632")); + cl_git_pass(git_oid__fromstr(&_oid, "f6ea0495187600e7b2288c8ac19c5886383a4632", GIT_OID_SHA1)); cl_git_pass(git_odb_read(&_obj, _odb, &_oid)); assert_object_contains(_obj, objs[0].content); @@ -122,7 +122,7 @@ void test_odb_backend_simple__read_prefix_of_nonexisting_object_fails(void) setup_backend(objs); - cl_git_pass(git_oid_fromstrn(&_oid, hash, strlen(hash))); + cl_git_pass(git_oid__fromstrn(&_oid, hash, strlen(hash), GIT_OID_SHA1)); cl_git_fail_with(GIT_ENOTFOUND, git_odb_read(&_obj, _odb, &_oid)); } @@ -136,7 +136,7 @@ void test_odb_backend_simple__read_with_ambiguous_prefix_fails(void) setup_backend(objs); - cl_git_pass(git_oid_fromstr(&_oid, objs[0].oid)); + cl_git_pass(git_oid__fromstr(&_oid, objs[0].oid, GIT_OID_SHA1)); cl_git_fail_with(GIT_EAMBIGUOUS, git_odb_read_prefix(&_obj, _odb, &_oid, 7)); } @@ -150,7 +150,7 @@ void test_odb_backend_simple__read_with_highly_ambiguous_prefix(void) setup_backend(objs); - cl_git_pass(git_oid_fromstr(&_oid, objs[0].oid)); + cl_git_pass(git_oid__fromstr(&_oid, objs[0].oid, GIT_OID_SHA1)); cl_git_pass(git_libgit2_opts(GIT_OPT_ENABLE_STRICT_HASH_VERIFICATION, 0)); cl_git_fail_with(GIT_EAMBIGUOUS, git_odb_read_prefix(&_obj, _odb, &_oid, 39)); cl_git_pass(git_odb_read_prefix(&_obj, _odb, &_oid, 40)); @@ -166,7 +166,7 @@ void test_odb_backend_simple__exists_succeeds(void) setup_backend(objs); - cl_git_pass(git_oid_fromstr(&_oid, objs[0].oid)); + cl_git_pass(git_oid__fromstr(&_oid, objs[0].oid, GIT_OID_SHA1)); cl_assert(git_odb_exists(_odb, &_oid)); } @@ -179,7 +179,7 @@ void test_odb_backend_simple__exists_fails_for_nonexisting_object(void) setup_backend(objs); - cl_git_pass(git_oid_fromstr(&_oid, "f6ea0495187600e7b2288c8ac19c5886383a4633")); + cl_git_pass(git_oid__fromstr(&_oid, "f6ea0495187600e7b2288c8ac19c5886383a4633", GIT_OID_SHA1)); cl_assert(git_odb_exists(_odb, &_oid) == 0); } @@ -194,7 +194,7 @@ void test_odb_backend_simple__exists_prefix_succeeds(void) setup_backend(objs); - cl_git_pass(git_oid_fromstr(&_oid, objs[0].oid)); + cl_git_pass(git_oid__fromstr(&_oid, objs[0].oid, GIT_OID_SHA1)); cl_git_pass(git_odb_exists_prefix(&found, _odb, &_oid, 12)); cl_assert(git_oid_equal(&found, &_oid)); } @@ -209,7 +209,7 @@ void test_odb_backend_simple__exists_with_ambiguous_prefix_fails(void) setup_backend(objs); - cl_git_pass(git_oid_fromstr(&_oid, objs[0].oid)); + cl_git_pass(git_oid__fromstr(&_oid, objs[0].oid, GIT_OID_SHA1)); cl_git_fail_with(GIT_EAMBIGUOUS, git_odb_exists_prefix(NULL, _odb, &_oid, 7)); } @@ -224,7 +224,7 @@ void test_odb_backend_simple__exists_with_highly_ambiguous_prefix(void) setup_backend(objs); - cl_git_pass(git_oid_fromstr(&_oid, objs[0].oid)); + cl_git_pass(git_oid__fromstr(&_oid, objs[0].oid, GIT_OID_SHA1)); cl_git_pass(git_libgit2_opts(GIT_OPT_ENABLE_STRICT_HASH_VERIFICATION, 0)); cl_git_fail_with(GIT_EAMBIGUOUS, git_odb_exists_prefix(&found, _odb, &_oid, 39)); cl_git_pass(git_odb_exists_prefix(&found, _odb, &_oid, 40)); @@ -237,7 +237,7 @@ void test_odb_backend_simple__null_oid_is_ignored(void) { "0000000000000000000000000000000000000000", "null oid content" }, { NULL, NULL } }; - git_oid null_oid = {{0}}; + git_oid null_oid = GIT_OID_SHA1_ZERO; git_odb_object *obj; setup_backend(objs); diff --git a/tests/libgit2/odb/emptyobjects.c b/tests/libgit2/odb/emptyobjects.c index e3ec62d3f..e7cc668d1 100644 --- a/tests/libgit2/odb/emptyobjects.c +++ b/tests/libgit2/odb/emptyobjects.c @@ -24,7 +24,7 @@ void test_odb_emptyobjects__blob_notfound(void) git_oid id, written_id; git_blob *blob; - cl_git_pass(git_oid_fromstr(&id, "e69de29bb2d1d6434b8b29ae775ad8c2e48c5391")); + cl_git_pass(git_oid__fromstr(&id, "e69de29bb2d1d6434b8b29ae775ad8c2e48c5391", GIT_OID_SHA1)); cl_git_fail_with(GIT_ENOTFOUND, git_blob_lookup(&blob, g_repo, &id)); cl_git_pass(git_odb_write(&written_id, g_odb, "", 0, GIT_OBJECT_BLOB)); @@ -36,7 +36,7 @@ void test_odb_emptyobjects__read_tree(void) git_oid id; git_tree *tree; - cl_git_pass(git_oid_fromstr(&id, "4b825dc642cb6eb9a060e54bf8d69288fbee4904")); + cl_git_pass(git_oid__fromstr(&id, "4b825dc642cb6eb9a060e54bf8d69288fbee4904", GIT_OID_SHA1)); cl_git_pass(git_tree_lookup(&tree, g_repo, &id)); cl_assert_equal_i(GIT_OBJECT_TREE, git_object_type((git_object *) tree)); cl_assert_equal_i(0, git_tree_entrycount(tree)); @@ -49,7 +49,7 @@ void test_odb_emptyobjects__read_tree_odb(void) git_oid id; git_odb_object *tree_odb; - cl_git_pass(git_oid_fromstr(&id, "4b825dc642cb6eb9a060e54bf8d69288fbee4904")); + cl_git_pass(git_oid__fromstr(&id, "4b825dc642cb6eb9a060e54bf8d69288fbee4904", GIT_OID_SHA1)); cl_git_pass(git_odb_read(&tree_odb, g_odb, &id)); cl_assert(git_odb_object_data(tree_odb)); cl_assert_equal_s("", git_odb_object_data(tree_odb)); diff --git a/tests/libgit2/odb/foreach.c b/tests/libgit2/odb/foreach.c index c2a448363..56b3e882c 100644 --- a/tests/libgit2/odb/foreach.c +++ b/tests/libgit2/odb/foreach.c @@ -51,8 +51,17 @@ void test_odb_foreach__one_pack(void) git_odb_backend *backend = NULL; int nobj = 0; - cl_git_pass(git_odb_new(&_odb)); - cl_git_pass(git_odb_backend_one_pack(&backend, cl_fixture("testrepo.git/objects/pack/pack-a81e489679b7d3418f9ab594bda8ceb37dd4c695.idx"))); + cl_git_pass(git_odb__new(&_odb, NULL)); + +#ifdef GIT_EXPERIMENTAL_SHA256 + cl_git_pass(git_odb_backend_one_pack(&backend, + cl_fixture("testrepo.git/objects/pack/pack-a81e489679b7d3418f9ab594bda8ceb37dd4c695.idx"), + NULL)); +#else + cl_git_pass(git_odb_backend_one_pack(&backend, + cl_fixture("testrepo.git/objects/pack/pack-a81e489679b7d3418f9ab594bda8ceb37dd4c695.idx"))); +#endif + cl_git_pass(git_odb_add_backend(_odb, backend, 1)); _repo = NULL; diff --git a/tests/libgit2/odb/freshen.c b/tests/libgit2/odb/freshen.c index 2396e3774..e337c82b7 100644 --- a/tests/libgit2/odb/freshen.c +++ b/tests/libgit2/odb/freshen.c @@ -43,7 +43,7 @@ void test_odb_freshen__loose_blob(void) git_oid expected_id, id; struct stat before, after; - cl_git_pass(git_oid_fromstr(&expected_id, LOOSE_BLOB_ID)); + cl_git_pass(git_oid__fromstr(&expected_id, LOOSE_BLOB_ID, GIT_OID_SHA1)); set_time_wayback(&before, LOOSE_BLOB_FN); /* make sure we freshen a blob */ @@ -64,7 +64,7 @@ void test_odb_freshen__readonly_object(void) git_oid expected_id, id; struct stat before, after; - cl_git_pass(git_oid_fromstr(&expected_id, UNIQUE_BLOB_ID)); + cl_git_pass(git_oid__fromstr(&expected_id, UNIQUE_BLOB_ID, GIT_OID_SHA1)); cl_git_pass(git_blob_create_from_buffer(&id, repo, UNIQUE_STR, CONST_STRLEN(UNIQUE_STR))); cl_assert_equal_oid(&expected_id, &id); @@ -89,7 +89,7 @@ void test_odb_freshen__loose_tree(void) git_tree *tree; struct stat before, after; - cl_git_pass(git_oid_fromstr(&expected_id, LOOSE_TREE_ID)); + cl_git_pass(git_oid__fromstr(&expected_id, LOOSE_TREE_ID, GIT_OID_SHA1)); set_time_wayback(&before, LOOSE_TREE_FN); cl_git_pass(git_tree_lookup(&tree, repo, &expected_id)); @@ -113,11 +113,11 @@ void test_odb_freshen__tree_during_commit(void) git_signature *signature; struct stat before, after; - cl_git_pass(git_oid_fromstr(&tree_id, LOOSE_TREE_ID)); + cl_git_pass(git_oid__fromstr(&tree_id, LOOSE_TREE_ID, GIT_OID_SHA1)); cl_git_pass(git_tree_lookup(&tree, repo, &tree_id)); set_time_wayback(&before, LOOSE_TREE_FN); - cl_git_pass(git_oid_fromstr(&parent_id, "a65fedf39aefe402d3bb6e24df4d4f5fe4547750")); + cl_git_pass(git_oid__fromstr(&parent_id, "a65fedf39aefe402d3bb6e24df4d4f5fe4547750", GIT_OID_SHA1)); cl_git_pass(git_commit_lookup(&parent, repo, &parent_id)); cl_git_pass(git_signature_new(&signature, @@ -147,7 +147,7 @@ void test_odb_freshen__packed_object(void) struct stat before, after; struct p_timeval old_times[2]; - cl_git_pass(git_oid_fromstr(&expected_id, PACKED_ID)); + cl_git_pass(git_oid__fromstr(&expected_id, PACKED_ID, GIT_OID_SHA1)); old_times[0].tv_sec = 1234567890; old_times[0].tv_usec = 0; diff --git a/tests/libgit2/odb/largefiles.c b/tests/libgit2/odb/largefiles.c index acc786ee4..2ec48102b 100644 --- a/tests/libgit2/odb/largefiles.c +++ b/tests/libgit2/odb/largefiles.c @@ -57,7 +57,7 @@ void test_odb_largefiles__write_from_memory(void) for (i = 0; i < (3041*126103); i++) cl_git_pass(git_str_puts(&buf, "Hello, world.\n")); - git_oid_fromstr(&expected, "3fb56989cca483b21ba7cb0a6edb229d10e1c26c"); + git_oid__fromstr(&expected, "3fb56989cca483b21ba7cb0a6edb229d10e1c26c", GIT_OID_SHA1); cl_git_pass(git_odb_write(&oid, odb, buf.ptr, buf.size, GIT_OBJECT_BLOB)); cl_assert_equal_oid(&expected, &oid); @@ -75,7 +75,7 @@ void test_odb_largefiles__streamwrite(void) !cl_is_env_set("GITTEST_SLOW")) cl_skip(); - git_oid_fromstr(&expected, "3fb56989cca483b21ba7cb0a6edb229d10e1c26c"); + git_oid__fromstr(&expected, "3fb56989cca483b21ba7cb0a6edb229d10e1c26c", GIT_OID_SHA1); writefile(&oid); cl_assert_equal_oid(&expected, &oid); diff --git a/tests/libgit2/odb/loose.c b/tests/libgit2/odb/loose.c index fe013a78c..0409dfb28 100644 --- a/tests/libgit2/odb/loose.c +++ b/tests/libgit2/odb/loose.c @@ -34,24 +34,27 @@ static void cmp_objects(git_rawobj *o, object_data *d) static void test_read_object(object_data *data) { - git_oid id; - git_odb_object *obj; + git_oid id; + git_odb_object *obj; git_odb *odb; git_rawobj tmp; + git_odb_options opts = GIT_ODB_OPTIONS_INIT; - write_object_files(data); + opts.oid_type = data->id_type; - cl_git_pass(git_odb_open(&odb, "test-objects")); - cl_git_pass(git_oid_fromstr(&id, data->id)); - cl_git_pass(git_odb_read(&obj, odb, &id)); + write_object_files(data); + + cl_git_pass(git_odb__open(&odb, "test-objects", &opts)); + cl_git_pass(git_oid__fromstr(&id, data->id, data->id_type)); + cl_git_pass(git_odb_read(&obj, odb, &id)); tmp.data = obj->buffer; tmp.len = obj->cached.size; tmp.type = obj->cached.type; - cmp_objects(&tmp, data); + cmp_objects(&tmp, data); - git_odb_object_free(obj); + git_odb_object_free(obj); git_odb_free(odb); } @@ -61,11 +64,14 @@ static void test_read_header(object_data *data) git_odb *odb; size_t len; git_object_t type; + git_odb_options opts = GIT_ODB_OPTIONS_INIT; + + opts.oid_type = data->id_type; write_object_files(data); - cl_git_pass(git_odb_open(&odb, "test-objects")); - cl_git_pass(git_oid_fromstr(&id, data->id)); + cl_git_pass(git_odb__open(&odb, "test-objects", &opts)); + cl_git_pass(git_oid__fromstr(&id, data->id, data->id_type)); cl_git_pass(git_odb_read_header(&len, &type, odb, &id)); cl_assert_equal_sz(data->dlen, len); @@ -83,11 +89,14 @@ static void test_readstream_object(object_data *data, size_t blocksize) char buf[2048], *ptr = buf; size_t remain; int ret; + git_odb_options opts = GIT_ODB_OPTIONS_INIT; + + opts.oid_type = data->id_type; write_object_files(data); - cl_git_pass(git_odb_open(&odb, "test-objects")); - cl_git_pass(git_oid_fromstr(&id, data->id)); + cl_git_pass(git_odb__open(&odb, "test-objects", &opts)); + cl_git_pass(git_oid__fromstr(&id, data->id, data->id_type)); cl_git_pass(git_odb_open_rstream(&stream, &tmp.len, &tmp.type, odb, &id)); remain = tmp.len; @@ -124,32 +133,64 @@ void test_odb_loose__cleanup(void) cl_fixture_cleanup("test-objects"); } -void test_odb_loose__exists(void) +void test_odb_loose__exists_sha1(void) { git_oid id, id2; git_odb *odb; write_object_files(&one); - cl_git_pass(git_odb_open(&odb, "test-objects")); + cl_git_pass(git_odb__open(&odb, "test-objects", NULL)); - cl_git_pass(git_oid_fromstr(&id, one.id)); + cl_git_pass(git_oid__fromstr(&id, one.id, GIT_OID_SHA1)); cl_assert(git_odb_exists(odb, &id)); - cl_git_pass(git_oid_fromstrp(&id, "8b137891")); + cl_git_pass(git_oid__fromstrp(&id, "8b137891", GIT_OID_SHA1)); cl_git_pass(git_odb_exists_prefix(&id2, odb, &id, 8)); cl_assert_equal_i(0, git_oid_streq(&id2, one.id)); /* Test for a missing object */ - cl_git_pass(git_oid_fromstr(&id, "8b137891791fe96927ad78e64b0aad7bded08baa")); + cl_git_pass(git_oid__fromstr(&id, "8b137891791fe96927ad78e64b0aad7bded08baa", GIT_OID_SHA1)); cl_assert(!git_odb_exists(odb, &id)); - cl_git_pass(git_oid_fromstrp(&id, "8b13789a")); + cl_git_pass(git_oid__fromstrp(&id, "8b13789a", GIT_OID_SHA1)); cl_assert_equal_i(GIT_ENOTFOUND, git_odb_exists_prefix(&id2, odb, &id, 8)); git_odb_free(odb); } -void test_odb_loose__simple_reads(void) +void test_odb_loose__exists_sha256(void) +{ +#ifndef GIT_EXPERIMENTAL_SHA256 + cl_skip(); +#else + git_oid id, id2; + git_odb *odb; + git_odb_options odb_opts = GIT_ODB_OPTIONS_INIT; + + odb_opts.oid_type = GIT_OID_SHA256; + + write_object_files(&one_sha256); + cl_git_pass(git_odb__open(&odb, "test-objects", &odb_opts)); + + cl_git_pass(git_oid__fromstr(&id, one_sha256.id, GIT_OID_SHA256)); + cl_assert(git_odb_exists(odb, &id)); + + cl_git_pass(git_oid__fromstrp(&id, "4c0d52d1", GIT_OID_SHA256)); + cl_git_pass(git_odb_exists_prefix(&id2, odb, &id, 8)); + cl_assert_equal_i(0, git_oid_streq(&id2, one_sha256.id)); + + /* Test for a missing object */ + cl_git_pass(git_oid__fromstr(&id, "4c0d52d180c61d01ce1a91dec5ee58f0cbe65fd59433aea803ab927965493faa", GIT_OID_SHA256)); + cl_assert(!git_odb_exists(odb, &id)); + + cl_git_pass(git_oid__fromstrp(&id, "4c0d52da", GIT_OID_SHA256)); + cl_assert_equal_i(GIT_ENOTFOUND, git_odb_exists_prefix(&id2, odb, &id, 8)); + + git_odb_free(odb); +#endif +} + +void test_odb_loose__simple_reads_sha1(void) { test_read_object(&commit); test_read_object(&tree); @@ -160,7 +201,22 @@ void test_odb_loose__simple_reads(void) test_read_object(&some); } -void test_odb_loose__streaming_reads(void) +void test_odb_loose__simple_reads_sha256(void) +{ +#ifndef GIT_EXPERIMENTAL_SHA256 + cl_skip(); +#else + test_read_object(&commit_sha256); + test_read_object(&tree_sha256); + test_read_object(&tag_sha256); + test_read_object(&zero_sha256); + test_read_object(&one_sha256); + test_read_object(&two_sha256); + test_read_object(&some_sha256); +#endif +} + +void test_odb_loose__streaming_reads_sha1(void) { size_t blocksizes[] = { 1, 2, 4, 16, 99, 1024, 123456789 }; size_t i; @@ -176,7 +232,27 @@ void test_odb_loose__streaming_reads(void) } } -void test_odb_loose__read_header(void) +void test_odb_loose__streaming_reads_sha256(void) +{ +#ifndef GIT_EXPERIMENTAL_SHA256 + cl_skip(); +#else + size_t blocksizes[] = { 1, 2, 4, 16, 99, 1024, 123456789 }; + size_t i; + + for (i = 0; i < ARRAY_SIZE(blocksizes); i++) { + test_readstream_object(&commit_sha256, blocksizes[i]); + test_readstream_object(&tree_sha256, blocksizes[i]); + test_readstream_object(&tag_sha256, blocksizes[i]); + test_readstream_object(&zero_sha256, blocksizes[i]); + test_readstream_object(&one_sha256, blocksizes[i]); + test_readstream_object(&two_sha256, blocksizes[i]); + test_readstream_object(&some_sha256, blocksizes[i]); + } +#endif +} + +void test_odb_loose__read_header_sha1(void) { test_read_header(&commit); test_read_header(&tree); @@ -187,6 +263,21 @@ void test_odb_loose__read_header(void) test_read_header(&some); } +void test_odb_loose__read_header_sha256(void) +{ +#ifndef GIT_EXPERIMENTAL_SHA256 + cl_skip(); +#else + test_read_header(&commit_sha256); + test_read_header(&tree_sha256); + test_read_header(&tag_sha256); + test_read_header(&zero_sha256); + test_read_header(&one_sha256); + test_read_header(&two_sha256); + test_read_header(&some_sha256); +#endif +} + static void test_write_object_permission( mode_t dir_mode, mode_t file_mode, mode_t expected_dir_mode, mode_t expected_file_mode) @@ -196,6 +287,7 @@ static void test_write_object_permission( git_oid oid; struct stat statbuf; mode_t mask, os_mask; + git_odb_backend_loose_options opts = GIT_ODB_BACKEND_LOOSE_OPTIONS_INIT; /* Windows does not return group/user bits from stat, * files are never executable. @@ -209,8 +301,11 @@ static void test_write_object_permission( mask = p_umask(0); p_umask(mask); - cl_git_pass(git_odb_new(&odb)); - cl_git_pass(git_odb_backend_loose(&backend, "test-objects", -1, 0, dir_mode, file_mode)); + opts.dir_mode = dir_mode; + opts.file_mode = file_mode; + + cl_git_pass(git_odb__new(&odb, NULL)); + cl_git_pass(git_odb__backend_loose(&backend, "test-objects", &opts)); cl_git_pass(git_odb_add_backend(odb, backend, 1)); cl_git_pass(git_odb_write(&oid, odb, "Test data\n", 10, GIT_OBJECT_BLOB)); @@ -243,9 +338,16 @@ static void write_object_to_loose_odb(int fsync) git_odb *odb; git_odb_backend *backend; git_oid oid; + git_odb_backend_loose_options opts = GIT_ODB_BACKEND_LOOSE_OPTIONS_INIT; - cl_git_pass(git_odb_new(&odb)); - cl_git_pass(git_odb_backend_loose(&backend, "test-objects", -1, fsync, 0777, 0666)); + if (fsync) + opts.flags |= GIT_ODB_BACKEND_LOOSE_FSYNC; + + opts.dir_mode = 0777; + opts.file_mode = 0666; + + cl_git_pass(git_odb__new(&odb, NULL)); + cl_git_pass(git_odb__backend_loose(&backend, "test-objects", &opts)); cl_git_pass(git_odb_add_backend(odb, backend, 1)); cl_git_pass(git_odb_write(&oid, odb, "Test data\n", 10, GIT_OBJECT_BLOB)); git_odb_free(odb); diff --git a/tests/libgit2/odb/loose_data.h b/tests/libgit2/odb/loose_data.h index c10c9bc7f..1a830740d 100644 --- a/tests/libgit2/odb/loose_data.h +++ b/tests/libgit2/odb/loose_data.h @@ -1,7 +1,8 @@ typedef struct object_data { unsigned char *bytes; /* (compressed) bytes stored in object store */ size_t blen; /* length of data in object store */ - char *id; /* object id (sha1) */ + char *id; /* object id (hex chars) */ + git_oid_t id_type; /* type of object id (sha1 or sha256) */ char *type; /* object type */ char *dir; /* object store (fan-out) directory name */ char *file; /* object store filename */ @@ -9,7 +10,10 @@ typedef struct object_data { size_t dlen; /* length of (uncompressed) object data */ } object_data; -/* one == 8b137891791fe96927ad78e64b0aad7bded08bdc */ +/* + * one == 8b137891791fe96927ad78e64b0aad7bded08bdc (sha1) + * 4c0d52d180c61d01ce1a91dec5ee58f0cbe65fd59433aea803ab927965493fd7 (sha256) + */ static unsigned char one_bytes[] = { 0x31, 0x78, 0x9c, 0xe3, 0x02, 0x00, 0x00, 0x0b, 0x00, 0x0b, @@ -23,6 +27,7 @@ static object_data one = { one_bytes, sizeof(one_bytes), "8b137891791fe96927ad78e64b0aad7bded08bdc", + GIT_OID_SHA1, "blob", "test-objects/8b", "test-objects/8b/137891791fe96927ad78e64b0aad7bded08bdc", @@ -30,8 +35,25 @@ static object_data one = { sizeof(one_data), }; +#ifdef GIT_EXPERIMENTAL_SHA256 +static object_data one_sha256 = { + one_bytes, + sizeof(one_bytes), + "4c0d52d180c61d01ce1a91dec5ee58f0cbe65fd59433aea803ab927965493fd7", + GIT_OID_SHA256, + "blob", + "test-objects/4c", + "test-objects/4c/0d52d180c61d01ce1a91dec5ee58f0cbe65fd59433aea803ab927965493fd7", + one_data, + sizeof(one_data), +}; +#endif -/* commit == 3d7f8a6af076c8c3f20071a8935cdbe8228594d1 */ + +/* + * commit == 3d7f8a6af076c8c3f20071a8935cdbe8228594d1 (sha1) + * a2a430fb63b294f868af4ef6ccc9c3e8256e370859ce578a23837ac85337f562 (sha256) + */ static unsigned char commit_bytes[] = { 0x78, 0x01, 0x85, 0x50, 0xc1, 0x6a, 0xc3, 0x30, 0x0c, 0xdd, 0xd9, 0x5f, 0xa1, 0xfb, 0x96, 0x12, @@ -64,6 +86,42 @@ static unsigned char commit_bytes[] = { 0x1f, 0x78, 0x35, }; +#ifdef GIT_EXPERIMENTAL_SHA256 +static unsigned char commit_bytes_sha256[] = { + 0x78, 0x01, 0x85, 0x90, 0xc1, 0x4e, 0xc3, 0x30, + 0x0c, 0x86, 0x39, 0xe7, 0x29, 0x7c, 0x87, 0x4e, + 0x5d, 0x93, 0xa6, 0x2d, 0x9a, 0x10, 0x13, 0x67, + 0xc4, 0x81, 0xf1, 0x00, 0x4e, 0xe3, 0xb4, 0x91, + 0x9a, 0xa4, 0x4a, 0x53, 0x69, 0x7d, 0x7b, 0x82, + 0x3a, 0x4d, 0x9c, 0xc0, 0xa7, 0xcf, 0xbf, 0xfd, + 0xff, 0xb2, 0xdc, 0x07, 0xe7, 0x6c, 0x02, 0xde, + 0xb4, 0x0f, 0x29, 0x12, 0x01, 0x17, 0x28, 0xda, + 0x5a, 0xa8, 0x5a, 0x54, 0xd2, 0x74, 0x95, 0x90, + 0xa5, 0x12, 0x48, 0xbc, 0x26, 0xa9, 0x9b, 0xae, + 0x11, 0x52, 0x91, 0x94, 0x3d, 0x6f, 0x95, 0x31, + 0x5a, 0x92, 0xe1, 0xaa, 0x17, 0xa6, 0xac, 0x39, + 0xe9, 0xa6, 0x45, 0x2e, 0x15, 0x0a, 0x86, 0x6b, + 0x1a, 0x43, 0x84, 0x33, 0x7c, 0xc1, 0xe5, 0x07, + 0x4e, 0xbb, 0xf0, 0x4a, 0x57, 0x74, 0xf3, 0x44, + 0x87, 0x3e, 0xb8, 0x17, 0x38, 0x56, 0x55, 0xd3, + 0x1e, 0x45, 0xd5, 0x35, 0xf0, 0x58, 0xe6, 0x62, + 0x59, 0xcd, 0x67, 0x24, 0x8a, 0xf0, 0x06, 0x1f, + 0xf0, 0xbe, 0xe3, 0xe9, 0xae, 0xfe, 0xe3, 0x66, + 0x67, 0x08, 0x9e, 0x8a, 0xc9, 0x7a, 0x82, 0xdd, + 0x03, 0xcb, 0xea, 0x1c, 0xc6, 0x8d, 0xb1, 0xcb, + 0x48, 0xa0, 0x82, 0xde, 0x20, 0x18, 0x48, 0x99, + 0x6f, 0x73, 0x47, 0xcb, 0x82, 0x03, 0x3d, 0xe5, + 0xde, 0x27, 0xb4, 0xde, 0xfa, 0x01, 0xcc, 0x1a, + 0xf3, 0x46, 0x04, 0xba, 0xce, 0x13, 0x7a, 0x4c, + 0x36, 0x78, 0x76, 0x73, 0xcd, 0x6b, 0x9c, 0xc3, + 0x42, 0xf7, 0x90, 0x11, 0xfd, 0x40, 0x0b, 0x58, + 0x9f, 0x62, 0xd0, 0x6b, 0x4f, 0x1a, 0xd4, 0xf6, + 0x2b, 0xfe, 0xc0, 0xd8, 0xa7, 0x1d, 0x3c, 0xe9, + 0x22, 0x98, 0x42, 0x6d, 0xcf, 0x7f, 0xbf, 0x83, + 0x7d, 0x03, 0x6d, 0x1e, 0x7e, 0xa9 +}; +#endif + static unsigned char commit_data[] = { 0x74, 0x72, 0x65, 0x65, 0x20, 0x64, 0x66, 0x66, 0x32, 0x64, 0x61, 0x39, 0x30, 0x62, 0x32, 0x35, @@ -112,10 +170,64 @@ static unsigned char commit_data[] = { 0x3e, 0x0a, }; +#ifdef GIT_EXPERIMENTAL_SHA256 +static unsigned char commit_data_sha256[] = { + 0x74, 0x72, 0x65, 0x65, 0x20, 0x33, 0x34, 0x61, + 0x34, 0x38, 0x35, 0x34, 0x62, 0x35, 0x34, 0x32, + 0x36, 0x66, 0x39, 0x32, 0x34, 0x36, 0x30, 0x62, + 0x34, 0x61, 0x65, 0x33, 0x35, 0x65, 0x36, 0x64, + 0x37, 0x39, 0x37, 0x34, 0x36, 0x62, 0x65, 0x36, + 0x36, 0x63, 0x33, 0x38, 0x62, 0x66, 0x66, 0x64, + 0x36, 0x65, 0x66, 0x33, 0x62, 0x63, 0x34, 0x66, + 0x30, 0x35, 0x33, 0x65, 0x64, 0x37, 0x38, 0x61, + 0x33, 0x36, 0x62, 0x61, 0x34, 0x0a, 0x61, 0x75, + 0x74, 0x68, 0x6f, 0x72, 0x20, 0x41, 0x20, 0x55, + 0x20, 0x54, 0x68, 0x6f, 0x72, 0x20, 0x3c, 0x61, + 0x75, 0x74, 0x68, 0x6f, 0x72, 0x40, 0x65, 0x78, + 0x61, 0x6d, 0x70, 0x6c, 0x65, 0x2e, 0x63, 0x6f, + 0x6d, 0x3e, 0x20, 0x31, 0x32, 0x32, 0x37, 0x38, + 0x31, 0x34, 0x32, 0x39, 0x37, 0x20, 0x2b, 0x30, + 0x30, 0x30, 0x30, 0x0a, 0x63, 0x6f, 0x6d, 0x6d, + 0x69, 0x74, 0x74, 0x65, 0x72, 0x20, 0x43, 0x20, + 0x4f, 0x20, 0x4d, 0x69, 0x74, 0x74, 0x65, 0x72, + 0x20, 0x3c, 0x63, 0x6f, 0x6d, 0x6d, 0x69, 0x74, + 0x74, 0x65, 0x72, 0x40, 0x65, 0x78, 0x61, 0x6d, + 0x70, 0x6c, 0x65, 0x2e, 0x63, 0x6f, 0x6d, 0x3e, + 0x20, 0x31, 0x32, 0x32, 0x37, 0x38, 0x31, 0x34, + 0x32, 0x39, 0x37, 0x20, 0x2b, 0x30, 0x30, 0x30, + 0x30, 0x0a, 0x0a, 0x41, 0x20, 0x6f, 0x6e, 0x65, + 0x2d, 0x6c, 0x69, 0x6e, 0x65, 0x20, 0x63, 0x6f, + 0x6d, 0x6d, 0x69, 0x74, 0x20, 0x73, 0x75, 0x6d, + 0x6d, 0x61, 0x72, 0x79, 0x0a, 0x0a, 0x54, 0x68, + 0x65, 0x20, 0x62, 0x6f, 0x64, 0x79, 0x20, 0x6f, + 0x66, 0x20, 0x74, 0x68, 0x65, 0x20, 0x63, 0x6f, + 0x6d, 0x6d, 0x69, 0x74, 0x20, 0x6d, 0x65, 0x73, + 0x73, 0x61, 0x67, 0x65, 0x2c, 0x20, 0x63, 0x6f, + 0x6e, 0x74, 0x61, 0x69, 0x6e, 0x69, 0x6e, 0x67, + 0x20, 0x66, 0x75, 0x72, 0x74, 0x68, 0x65, 0x72, + 0x20, 0x65, 0x78, 0x70, 0x6c, 0x61, 0x6e, 0x61, + 0x74, 0x69, 0x6f, 0x6e, 0x0a, 0x6f, 0x66, 0x20, + 0x74, 0x68, 0x65, 0x20, 0x70, 0x75, 0x72, 0x70, + 0x6f, 0x73, 0x65, 0x20, 0x6f, 0x66, 0x20, 0x74, + 0x68, 0x65, 0x20, 0x63, 0x68, 0x61, 0x6e, 0x67, + 0x65, 0x73, 0x20, 0x69, 0x6e, 0x74, 0x72, 0x6f, + 0x64, 0x75, 0x63, 0x65, 0x64, 0x20, 0x62, 0x79, + 0x20, 0x74, 0x68, 0x65, 0x20, 0x63, 0x6f, 0x6d, + 0x6d, 0x69, 0x74, 0x2e, 0x0a, 0x0a, 0x53, 0x69, + 0x67, 0x6e, 0x65, 0x64, 0x2d, 0x6f, 0x66, 0x2d, + 0x62, 0x79, 0x3a, 0x20, 0x41, 0x20, 0x55, 0x20, + 0x54, 0x68, 0x6f, 0x72, 0x20, 0x3c, 0x61, 0x75, + 0x74, 0x68, 0x6f, 0x72, 0x40, 0x65, 0x78, 0x61, + 0x6d, 0x70, 0x6c, 0x65, 0x2e, 0x63, 0x6f, 0x6d, + 0x3e, 0x0a +}; +#endif + static object_data commit = { commit_bytes, sizeof(commit_bytes), "3d7f8a6af076c8c3f20071a8935cdbe8228594d1", + GIT_OID_SHA1, "commit", "test-objects/3d", "test-objects/3d/7f8a6af076c8c3f20071a8935cdbe8228594d1", @@ -123,7 +235,24 @@ static object_data commit = { sizeof(commit_data), }; -/* tree == dff2da90b254e1beb889d1f1f1288be1803782df */ +#ifdef GIT_EXPERIMENTAL_SHA256 +static object_data commit_sha256 = { + commit_bytes_sha256, + sizeof(commit_bytes_sha256), + "a2a430fb63b294f868af4ef6ccc9c3e8256e370859ce578a23837ac85337f562", + GIT_OID_SHA256, + "commit", + "test-objects/a2", + "test-objects/a2/a430fb63b294f868af4ef6ccc9c3e8256e370859ce578a23837ac85337f562", + commit_data_sha256, + sizeof(commit_data_sha256), +}; +#endif + +/* + * tree == dff2da90b254e1beb889d1f1f1288be1803782df (sha1) + * 34a4854b5426f92460b4ae35e6d79746be66c38bffd6ef3bc4f053ed78a36ba4 (sha256) + */ static unsigned char tree_bytes[] = { 0x78, 0x01, 0x2b, 0x29, 0x4a, 0x4d, 0x55, 0x30, 0x34, 0x32, 0x63, 0x30, 0x34, 0x30, 0x30, 0x33, @@ -163,10 +292,76 @@ static unsigned char tree_data[] = { 0xd8, 0xc2, 0xe4, 0x8c, 0x53, 0x91, }; +#ifdef GIT_EXPERIMENTAL_SHA256 +static unsigned char tree_bytes_sha256[] = { + 0x78, 0x01, 0x2b, 0x29, 0x4a, 0x4d, 0x55, 0x30, + 0x32, 0x32, 0x66, 0x30, 0x34, 0x30, 0x30, 0x33, + 0x31, 0x51, 0xc8, 0x48, 0xcd, 0xc9, 0xc9, 0xd7, + 0x2b, 0xa9, 0x28, 0x61, 0x28, 0x65, 0x3b, 0x7d, + 0xde, 0x27, 0x5c, 0xfb, 0xe5, 0x83, 0x2c, 0xf9, + 0xb7, 0xa6, 0x6b, 0xa2, 0x65, 0x7f, 0x6c, 0x5d, + 0xee, 0xab, 0x76, 0xa0, 0x9e, 0x49, 0xcd, 0xe3, + 0xe9, 0xcd, 0xa8, 0xf9, 0xf9, 0x5a, 0x50, 0x0d, + 0xf9, 0x79, 0xa9, 0x0c, 0x3e, 0xbc, 0x41, 0x17, + 0x1b, 0x8e, 0xc9, 0x32, 0x9e, 0x93, 0x9a, 0x78, + 0xef, 0xe8, 0xbb, 0x88, 0x0f, 0xa7, 0x9f, 0xc5, + 0x5f, 0x9d, 0x62, 0xbc, 0x6e, 0x05, 0xf3, 0xea, + 0x49, 0x95, 0xa9, 0x9e, 0xf6, 0xd7, 0xa1, 0x4a, + 0x8b, 0xf3, 0x73, 0x53, 0x19, 0x38, 0x6c, 0xb4, + 0xbb, 0x5d, 0xc2, 0x1c, 0x2e, 0x16, 0x3e, 0x5f, + 0x95, 0x56, 0xcd, 0x6d, 0xc4, 0x50, 0xc0, 0xf6, + 0xbd, 0xad, 0x50, 0xc0, 0xe8, 0xf5, 0x0e, 0x4d, + 0xc3, 0x33, 0xcb, 0xe6, 0x1c, 0x8c, 0x86, 0xaa, + 0x2d, 0x29, 0xcf, 0x67, 0xf8, 0x91, 0x14, 0xe7, + 0xfc, 0xf3, 0x81, 0xbf, 0x8a, 0xa6, 0x7c, 0xf9, + 0xd9, 0x7d, 0x3e, 0x85, 0x9b, 0x0f, 0x2d, 0xde, + 0xc0, 0x60, 0x9f, 0xe0, 0x38, 0xdb, 0xee, 0x42, + 0x16, 0x6b, 0x6f, 0x59, 0x4e, 0x37, 0x54, 0x69, + 0x55, 0x6a, 0x51, 0x3e, 0x83, 0xcb, 0xbc, 0xd9, + 0x95, 0x21, 0x0a, 0x67, 0xc5, 0xfe, 0x25, 0xac, + 0x0d, 0x9a, 0x71, 0x3e, 0x83, 0x5f, 0x74, 0xf9, + 0x59, 0xad, 0x93, 0x5b, 0xbc, 0x6e, 0x7d, 0x7f, + 0x6b, 0x77, 0x87, 0x97, 0xe3, 0x6e, 0x05, 0x00, + 0xba, 0xd1, 0x5f, 0x75 +}; + +static unsigned char tree_data_sha256[] = { + 0x31, 0x30, 0x30, 0x36, 0x34, 0x34, 0x20, 0x68, + 0x65, 0x6c, 0x6c, 0x6f, 0x2e, 0x74, 0x78, 0x74, + 0x00, 0x75, 0x06, 0xcb, 0xcf, 0x4c, 0x57, 0x2b, + 0xe9, 0xe0, 0x6a, 0x1f, 0xed, 0x35, 0xac, 0x5b, + 0x1d, 0xf8, 0xb5, 0xa7, 0x4d, 0x26, 0xc0, 0x7f, + 0x02, 0x26, 0x48, 0xe5, 0xd9, 0x5a, 0x9f, 0x6f, + 0x2a, 0x31, 0x30, 0x30, 0x36, 0x34, 0x34, 0x20, + 0x6f, 0x6e, 0x65, 0x00, 0x4c, 0x0d, 0x52, 0xd1, + 0x80, 0xc6, 0x1d, 0x01, 0xce, 0x1a, 0x91, 0xde, + 0xc5, 0xee, 0x58, 0xf0, 0xcb, 0xe6, 0x5f, 0xd5, + 0x94, 0x33, 0xae, 0xa8, 0x03, 0xab, 0x92, 0x79, + 0x65, 0x49, 0x3f, 0xd7, 0x31, 0x30, 0x30, 0x36, + 0x34, 0x34, 0x20, 0x73, 0x6f, 0x6d, 0x65, 0x00, + 0x08, 0x3c, 0x2b, 0x8b, 0x44, 0x56, 0x40, 0xd1, + 0x71, 0xe7, 0xaa, 0x66, 0x7b, 0x0b, 0x32, 0x00, + 0x70, 0x06, 0xf7, 0x86, 0x71, 0x10, 0x32, 0xeb, + 0xb8, 0x29, 0x31, 0xcc, 0xa6, 0x9c, 0xc1, 0x5b, + 0x31, 0x30, 0x30, 0x36, 0x34, 0x34, 0x20, 0x74, + 0x77, 0x6f, 0x00, 0xf8, 0x62, 0x5e, 0x43, 0xf9, + 0xe0, 0x4f, 0x24, 0x29, 0x1f, 0x77, 0xcd, 0xbe, + 0x4c, 0x71, 0xb3, 0xc2, 0xa3, 0xb0, 0x00, 0x3f, + 0x60, 0x41, 0x9b, 0x3e, 0xd0, 0x6a, 0x05, 0x8d, + 0x76, 0x6c, 0x8b, 0x31, 0x30, 0x30, 0x36, 0x34, + 0x34, 0x20, 0x7a, 0x65, 0x72, 0x6f, 0x00, 0x44, + 0x9e, 0x9b, 0x79, 0x54, 0x20, 0xcd, 0x16, 0xfe, + 0x60, 0xad, 0x52, 0x98, 0xcf, 0x68, 0x0f, 0x15, + 0xa7, 0xcd, 0x2a, 0xc9, 0xb4, 0x4a, 0xda, 0xf7, + 0xed, 0x3e, 0xdc, 0x0d, 0x08, 0xdd, 0x78 +}; +#endif + static object_data tree = { tree_bytes, sizeof(tree_bytes), "dff2da90b254e1beb889d1f1f1288be1803782df", + GIT_OID_SHA1, "tree", "test-objects/df", "test-objects/df/f2da90b254e1beb889d1f1f1288be1803782df", @@ -174,7 +369,24 @@ static object_data tree = { sizeof(tree_data), }; -/* tag == 09d373e1dfdc16b129ceec6dd649739911541e05 */ +#ifdef GIT_EXPERIMENTAL_SHA256 +static object_data tree_sha256 = { + tree_bytes_sha256, + sizeof(tree_bytes_sha256), + "34a4854b5426f92460b4ae35e6d79746be66c38bffd6ef3bc4f053ed78a36ba4", + GIT_OID_SHA256, + "tree", + "test-objects/34", + "test-objects/34/a4854b5426f92460b4ae35e6d79746be66c38bffd6ef3bc4f053ed78a36ba4", + tree_data_sha256, + sizeof(tree_data_sha256), +}; +#endif + +/* + * tag == 09d373e1dfdc16b129ceec6dd649739911541e05 (sha1) + * f535d7595d5d0e5e530b5deb34542c96491fea300a1318036b605306548cb225 (sha256) + */ static unsigned char tag_bytes[] = { 0x78, 0x01, 0x35, 0x4e, 0xcb, 0x0a, 0xc2, 0x40, 0x10, 0xf3, 0xbc, 0x5f, 0x31, 0x77, 0xa1, 0xec, @@ -222,10 +434,101 @@ static unsigned char tag_data[] = { 0x2e, 0x30, 0x2e, 0x31, 0x0a, }; +#ifdef GIT_EXPERIMENTAL_SHA256 +static unsigned char tag_bytes_sha256[] = { + 0x78, 0x01, 0x55, 0x8f, 0xd1, 0x4e, 0x84, 0x30, + 0x10, 0x45, 0x7d, 0xee, 0x57, 0xcc, 0xbb, 0x2e, + 0x81, 0x16, 0x68, 0x31, 0x1b, 0xa3, 0xf1, 0xd9, + 0xf8, 0xe0, 0xfa, 0x01, 0x43, 0x99, 0x42, 0x0d, + 0xb4, 0xa4, 0x14, 0xb3, 0xfc, 0xbd, 0xc5, 0xdd, + 0x4d, 0xb4, 0x69, 0xd2, 0x9b, 0xc9, 0xdc, 0x7b, + 0x6e, 0x23, 0xf6, 0x20, 0xa4, 0xba, 0xf3, 0xed, + 0x17, 0xe9, 0x08, 0xc8, 0xb1, 0x14, 0xb9, 0x69, + 0x6b, 0xd1, 0xf2, 0xa6, 0x34, 0xaa, 0x56, 0x68, + 0x4a, 0x32, 0xb5, 0xd6, 0xba, 0xd1, 0x82, 0x14, + 0xaf, 0x6a, 0x12, 0x32, 0x57, 0x55, 0xa3, 0xa9, + 0x92, 0x0a, 0xb9, 0x50, 0x42, 0xa2, 0x56, 0x95, + 0x10, 0xd2, 0x54, 0x35, 0x67, 0x71, 0x9b, 0x09, + 0xb4, 0x9f, 0x26, 0x1b, 0x59, 0x4c, 0xd9, 0xdf, + 0x79, 0x96, 0x67, 0xc5, 0x2e, 0x7b, 0x0a, 0xf0, + 0x0a, 0xef, 0xf0, 0x66, 0x63, 0x4c, 0xf2, 0x78, + 0x59, 0x4a, 0xf2, 0x99, 0xce, 0x38, 0xcd, 0x23, + 0x65, 0x69, 0xf2, 0x04, 0x05, 0xe7, 0x52, 0x15, + 0x25, 0x6f, 0x24, 0xdc, 0xe7, 0xe9, 0x30, 0x76, + 0x1a, 0xec, 0x02, 0xe9, 0xc6, 0x81, 0x60, 0x8f, + 0xbc, 0x56, 0x35, 0x3e, 0x40, 0xa0, 0x91, 0x70, + 0xa1, 0x1b, 0xe5, 0x0a, 0x86, 0x65, 0x9d, 0x26, + 0x0c, 0xdb, 0x6e, 0x25, 0x68, 0x7d, 0xb7, 0x81, + 0x37, 0xbf, 0xf6, 0x0b, 0x13, 0x26, 0x5a, 0x16, + 0xec, 0xe9, 0x21, 0xed, 0xbb, 0x88, 0xd6, 0x59, + 0xd7, 0x83, 0x59, 0x43, 0x02, 0x04, 0xa0, 0xf3, + 0x3c, 0xa2, 0xc3, 0x68, 0xbd, 0x63, 0x57, 0xd7, + 0xbc, 0x86, 0xd9, 0x27, 0xca, 0x2d, 0x64, 0x40, + 0xd7, 0x53, 0xaa, 0xe4, 0x62, 0xf0, 0xdd, 0xaa, + 0xa9, 0x83, 0x76, 0xfb, 0x13, 0x9f, 0x31, 0xf6, + 0x61, 0x7b, 0x47, 0xdd, 0xc1, 0x9b, 0x43, 0xbb, + 0x3d, 0xc2, 0x0b, 0x7c, 0xc2, 0x69, 0x48, 0x75, + 0x8f, 0xb8, 0xc6, 0xf4, 0xfe, 0xfb, 0x30, 0xfb, + 0x01, 0xc9, 0x32, 0x7d, 0xbb +}; + +static unsigned char tag_data_sha256[] = { + 0x6f, 0x62, 0x6a, 0x65, 0x63, 0x74, 0x20, 0x61, + 0x32, 0x61, 0x34, 0x33, 0x30, 0x66, 0x62, 0x36, + 0x33, 0x62, 0x32, 0x39, 0x34, 0x66, 0x38, 0x36, + 0x38, 0x61, 0x66, 0x34, 0x65, 0x66, 0x36, 0x63, + 0x63, 0x63, 0x39, 0x63, 0x33, 0x65, 0x38, 0x32, + 0x35, 0x36, 0x65, 0x33, 0x37, 0x30, 0x38, 0x35, + 0x39, 0x63, 0x65, 0x35, 0x37, 0x38, 0x61, 0x32, + 0x33, 0x38, 0x33, 0x37, 0x61, 0x63, 0x38, 0x35, + 0x33, 0x33, 0x37, 0x66, 0x35, 0x36, 0x32, 0x0a, + 0x74, 0x79, 0x70, 0x65, 0x20, 0x63, 0x6f, 0x6d, + 0x6d, 0x69, 0x74, 0x0a, 0x74, 0x61, 0x67, 0x20, + 0x76, 0x30, 0x2e, 0x30, 0x2e, 0x31, 0x0a, 0x74, + 0x61, 0x67, 0x67, 0x65, 0x72, 0x20, 0x43, 0x20, + 0x4f, 0x20, 0x4d, 0x69, 0x74, 0x74, 0x65, 0x72, + 0x20, 0x3c, 0x63, 0x6f, 0x6d, 0x6d, 0x69, 0x74, + 0x74, 0x65, 0x72, 0x40, 0x65, 0x78, 0x61, 0x6d, + 0x70, 0x6c, 0x65, 0x2e, 0x63, 0x6f, 0x6d, 0x3e, + 0x20, 0x31, 0x32, 0x32, 0x37, 0x38, 0x31, 0x34, + 0x32, 0x39, 0x37, 0x20, 0x2b, 0x30, 0x30, 0x30, + 0x30, 0x0a, 0x0a, 0x54, 0x68, 0x69, 0x73, 0x20, + 0x69, 0x73, 0x20, 0x74, 0x68, 0x65, 0x20, 0x74, + 0x61, 0x67, 0x20, 0x6f, 0x62, 0x6a, 0x65, 0x63, + 0x74, 0x20, 0x66, 0x6f, 0x72, 0x20, 0x72, 0x65, + 0x6c, 0x65, 0x61, 0x73, 0x65, 0x20, 0x76, 0x30, + 0x2e, 0x30, 0x2e, 0x31, 0x0a, 0x20, 0x63, 0x6f, + 0x6d, 0x6d, 0x69, 0x74, 0x20, 0x73, 0x75, 0x6d, + 0x6d, 0x61, 0x72, 0x79, 0x0a, 0x0a, 0x54, 0x68, + 0x65, 0x20, 0x62, 0x6f, 0x64, 0x79, 0x20, 0x6f, + 0x66, 0x20, 0x74, 0x68, 0x65, 0x20, 0x63, 0x6f, + 0x6d, 0x6d, 0x69, 0x74, 0x20, 0x6d, 0x65, 0x73, + 0x73, 0x61, 0x67, 0x65, 0x2c, 0x20, 0x63, 0x6f, + 0x6e, 0x74, 0x61, 0x69, 0x6e, 0x69, 0x6e, 0x67, + 0x20, 0x66, 0x75, 0x72, 0x74, 0x68, 0x65, 0x72, + 0x20, 0x65, 0x78, 0x70, 0x6c, 0x61, 0x6e, 0x61, + 0x74, 0x69, 0x6f, 0x6e, 0x0a, 0x6f, 0x66, 0x20, + 0x74, 0x68, 0x65, 0x20, 0x70, 0x75, 0x72, 0x70, + 0x6f, 0x73, 0x65, 0x20, 0x6f, 0x66, 0x20, 0x74, + 0x68, 0x65, 0x20, 0x63, 0x68, 0x61, 0x6e, 0x67, + 0x65, 0x73, 0x20, 0x69, 0x6e, 0x74, 0x72, 0x6f, + 0x64, 0x75, 0x63, 0x65, 0x64, 0x20, 0x62, 0x79, + 0x20, 0x74, 0x68, 0x65, 0x20, 0x63, 0x6f, 0x6d, + 0x6d, 0x69, 0x74, 0x2e, 0x0a, 0x0a, 0x53, 0x69, + 0x67, 0x6e, 0x65, 0x64, 0x2d, 0x6f, 0x66, 0x2d, + 0x62, 0x79, 0x3a, 0x20, 0x41, 0x20, 0x55, 0x20, + 0x54, 0x68, 0x6f, 0x72, 0x20, 0x3c, 0x61, 0x75, + 0x74, 0x68, 0x6f, 0x72, 0x40, 0x65, 0x78, 0x61, + 0x6d, 0x70, 0x6c, 0x65, 0x2e, 0x63, 0x6f, 0x6d, + 0x3e, 0x0a +}; +#endif + static object_data tag = { tag_bytes, sizeof(tag_bytes), "09d373e1dfdc16b129ceec6dd649739911541e05", + GIT_OID_SHA1, "tag", "test-objects/09", "test-objects/09/d373e1dfdc16b129ceec6dd649739911541e05", @@ -233,7 +536,24 @@ static object_data tag = { sizeof(tag_data), }; -/* zero == e69de29bb2d1d6434b8b29ae775ad8c2e48c5391 */ +#ifdef GIT_EXPERIMENTAL_SHA256 +static object_data tag_sha256 = { + tag_bytes_sha256, + sizeof(tag_bytes_sha256), + "f535d7595d5d0e5e530b5deb34542c96491fea300a1318036b605306548cb225", + GIT_OID_SHA256, + "tag", + "test-objects/f5", + "test-objects/f5/35d7595d5d0e5e530b5deb34542c96491fea300a1318036b605306548cb225", + tag_data_sha256, + sizeof(tag_data_sha256), +}; +#endif + +/* + * zero == e69de29bb2d1d6434b8b29ae775ad8c2e48c5391 (sha1) + * 473a0f4c3be8a93681a267e3b1e9a7dcda1185436fe141f7749120a303721813 (sha256) + */ static unsigned char zero_bytes[] = { 0x78, 0x01, 0x4b, 0xca, 0xc9, 0x4f, 0x52, 0x30, 0x60, 0x00, 0x00, 0x09, 0xb0, 0x01, 0xf0, @@ -247,6 +567,7 @@ static object_data zero = { zero_bytes, sizeof(zero_bytes), "e69de29bb2d1d6434b8b29ae775ad8c2e48c5391", + GIT_OID_SHA1, "blob", "test-objects/e6", "test-objects/e6/9de29bb2d1d6434b8b29ae775ad8c2e48c5391", @@ -254,7 +575,24 @@ static object_data zero = { 0, }; -/* two == 78981922613b2afb6025042ff6bd878ac1994e85 */ +#ifdef GIT_EXPERIMENTAL_SHA256 +static object_data zero_sha256 = { + zero_bytes, + sizeof(zero_bytes), + "473a0f4c3be8a93681a267e3b1e9a7dcda1185436fe141f7749120a303721813", + GIT_OID_SHA256, + "blob", + "test-objects/47", + "test-objects/47/3a0f4c3be8a93681a267e3b1e9a7dcda1185436fe141f7749120a303721813", + zero_data, + 0, +}; +#endif + +/* + * two == 78981922613b2afb6025042ff6bd878ac1994e85 (sha1) + * f8625e43f9e04f24291f77cdbe4c71b3c2a3b0003f60419b3ed06a058d766c8b (sha256) + */ static unsigned char two_bytes[] = { 0x78, 0x01, 0x4b, 0xca, 0xc9, 0x4f, 0x52, 0x30, 0x62, 0x48, 0xe4, 0x02, 0x00, 0x0e, 0x64, 0x02, @@ -269,6 +607,7 @@ static object_data two = { two_bytes, sizeof(two_bytes), "78981922613b2afb6025042ff6bd878ac1994e85", + GIT_OID_SHA1, "blob", "test-objects/78", "test-objects/78/981922613b2afb6025042ff6bd878ac1994e85", @@ -276,7 +615,24 @@ static object_data two = { sizeof(two_data), }; -/* some == fd8430bc864cfcd5f10e5590f8a447e01b942bfe */ +#ifdef GIT_EXPERIMENTAL_SHA256 +static object_data two_sha256 = { + two_bytes, + sizeof(two_bytes), + "f8625e43f9e04f24291f77cdbe4c71b3c2a3b0003f60419b3ed06a058d766c8b", + GIT_OID_SHA256, + "blob", + "test-objects/f8", + "test-objects/f8/625e43f9e04f24291f77cdbe4c71b3c2a3b0003f60419b3ed06a058d766c8b", + two_data, + sizeof(two_data), +}; +#endif + +/* + * some == fd8430bc864cfcd5f10e5590f8a447e01b942bfe (sha1) + * 083c2b8b445640d171e7aa667b0b32007006f786711032ebb82931cca69cc15b (sha256) + */ static unsigned char some_bytes[] = { 0x78, 0x01, 0x7d, 0x54, 0xc1, 0x4e, 0xe3, 0x30, 0x10, 0xdd, 0x33, 0x5f, 0x31, 0xc7, 0x5d, 0x94, @@ -514,9 +870,24 @@ static object_data some = { some_bytes, sizeof(some_bytes), "fd8430bc864cfcd5f10e5590f8a447e01b942bfe", + GIT_OID_SHA1, "blob", "test-objects/fd", "test-objects/fd/8430bc864cfcd5f10e5590f8a447e01b942bfe", some_data, sizeof(some_data), }; + +#ifdef GIT_EXPERIMENTAL_SHA256 +static object_data some_sha256 = { + some_bytes, + sizeof(some_bytes), + "083c2b8b445640d171e7aa667b0b32007006f786711032ebb82931cca69cc15b", + GIT_OID_SHA256, + "blob", + "test-objects/08", + "test-objects/08/3c2b8b445640d171e7aa667b0b32007006f786711032ebb82931cca69cc15b", + some_data, + sizeof(some_data), +}; +#endif diff --git a/tests/libgit2/odb/mixed.c b/tests/libgit2/odb/mixed.c index 87e945c83..19e6dcebf 100644 --- a/tests/libgit2/odb/mixed.c +++ b/tests/libgit2/odb/mixed.c @@ -5,7 +5,7 @@ static git_odb *_odb; void test_odb_mixed__initialize(void) { - cl_git_pass(git_odb_open(&_odb, cl_fixture("duplicate.git/objects"))); + cl_git_pass(git_odb__open(&_odb, cl_fixture("duplicate.git/objects"), NULL)); } void test_odb_mixed__cleanup(void) @@ -20,13 +20,13 @@ void test_odb_mixed__dup_oid(void) { git_oid oid; git_odb_object *obj; - cl_git_pass(git_oid_fromstr(&oid, hex)); - cl_git_pass(git_odb_read_prefix(&obj, _odb, &oid, GIT_OID_HEXSZ)); + cl_git_pass(git_oid__fromstr(&oid, hex, GIT_OID_SHA1)); + cl_git_pass(git_odb_read_prefix(&obj, _odb, &oid, GIT_OID_SHA1_HEXSIZE)); git_odb_object_free(obj); - cl_git_pass(git_odb_exists_prefix(NULL, _odb, &oid, GIT_OID_HEXSZ)); + cl_git_pass(git_odb_exists_prefix(NULL, _odb, &oid, GIT_OID_SHA1_HEXSIZE)); - cl_git_pass(git_oid_fromstrn(&oid, short_hex, sizeof(short_hex) - 1)); + cl_git_pass(git_oid__fromstrn(&oid, short_hex, sizeof(short_hex) - 1, GIT_OID_SHA1)); cl_git_pass(git_odb_read_prefix(&obj, _odb, &oid, sizeof(short_hex) - 1)); git_odb_object_free(obj); @@ -48,63 +48,63 @@ void test_odb_mixed__dup_oid_prefix_0(void) { /* ambiguous in the same pack file */ strncpy(hex, "dea509d0", sizeof(hex)); - cl_git_pass(git_oid_fromstrn(&oid, hex, strlen(hex))); + cl_git_pass(git_oid__fromstrn(&oid, hex, strlen(hex), GIT_OID_SHA1)); cl_assert_equal_i( GIT_EAMBIGUOUS, git_odb_read_prefix(&obj, _odb, &oid, strlen(hex))); cl_assert_equal_i( GIT_EAMBIGUOUS, git_odb_exists_prefix(&found, _odb, &oid, strlen(hex))); strncpy(hex, "dea509d09", sizeof(hex)); - cl_git_pass(git_oid_fromstrn(&oid, hex, strlen(hex))); + cl_git_pass(git_oid__fromstrn(&oid, hex, strlen(hex), GIT_OID_SHA1)); cl_git_pass(git_odb_read_prefix(&obj, _odb, &oid, strlen(hex))); cl_git_pass(git_odb_exists_prefix(&found, _odb, &oid, strlen(hex))); cl_assert_equal_oid(&found, git_odb_object_id(obj)); git_odb_object_free(obj); strncpy(hex, "dea509d0b", sizeof(hex)); - cl_git_pass(git_oid_fromstrn(&oid, hex, strlen(hex))); + cl_git_pass(git_oid__fromstrn(&oid, hex, strlen(hex), GIT_OID_SHA1)); cl_git_pass(git_odb_read_prefix(&obj, _odb, &oid, strlen(hex))); git_odb_object_free(obj); /* ambiguous in different pack files */ strncpy(hex, "81b5bff5", sizeof(hex)); - cl_git_pass(git_oid_fromstrn(&oid, hex, strlen(hex))); + cl_git_pass(git_oid__fromstrn(&oid, hex, strlen(hex), GIT_OID_SHA1)); cl_assert_equal_i( GIT_EAMBIGUOUS, git_odb_read_prefix(&obj, _odb, &oid, strlen(hex))); cl_assert_equal_i( GIT_EAMBIGUOUS, git_odb_exists_prefix(&found, _odb, &oid, strlen(hex))); strncpy(hex, "81b5bff5b", sizeof(hex)); - cl_git_pass(git_oid_fromstrn(&oid, hex, strlen(hex))); + cl_git_pass(git_oid__fromstrn(&oid, hex, strlen(hex), GIT_OID_SHA1)); cl_git_pass(git_odb_read_prefix(&obj, _odb, &oid, strlen(hex))); cl_git_pass(git_odb_exists_prefix(&found, _odb, &oid, strlen(hex))); cl_assert_equal_oid(&found, git_odb_object_id(obj)); git_odb_object_free(obj); strncpy(hex, "81b5bff5f", sizeof(hex)); - cl_git_pass(git_oid_fromstrn(&oid, hex, strlen(hex))); + cl_git_pass(git_oid__fromstrn(&oid, hex, strlen(hex), GIT_OID_SHA1)); cl_git_pass(git_odb_read_prefix(&obj, _odb, &oid, strlen(hex))); git_odb_object_free(obj); /* ambiguous in pack file and loose */ strncpy(hex, "0ddeaded", sizeof(hex)); - cl_git_pass(git_oid_fromstrn(&oid, hex, strlen(hex))); + cl_git_pass(git_oid__fromstrn(&oid, hex, strlen(hex), GIT_OID_SHA1)); cl_assert_equal_i( GIT_EAMBIGUOUS, git_odb_read_prefix(&obj, _odb, &oid, strlen(hex))); cl_assert_equal_i( GIT_EAMBIGUOUS, git_odb_exists_prefix(&found, _odb, &oid, strlen(hex))); strncpy(hex, "0ddeaded9", sizeof(hex)); - cl_git_pass(git_oid_fromstrn(&oid, hex, strlen(hex))); + cl_git_pass(git_oid__fromstrn(&oid, hex, strlen(hex), GIT_OID_SHA1)); cl_git_pass(git_odb_read_prefix(&obj, _odb, &oid, strlen(hex))); cl_git_pass(git_odb_exists_prefix(&found, _odb, &oid, strlen(hex))); cl_assert_equal_oid(&found, git_odb_object_id(obj)); git_odb_object_free(obj); strncpy(hex, "0ddeadede", sizeof(hex)); - cl_git_pass(git_oid_fromstrn(&oid, hex, strlen(hex))); + cl_git_pass(git_oid__fromstrn(&oid, hex, strlen(hex), GIT_OID_SHA1)); cl_git_pass(git_odb_read_prefix(&obj, _odb, &oid, strlen(hex))); git_odb_object_free(obj); } @@ -170,7 +170,7 @@ static void setup_prefix_query( size_t len = strlen(expand_id_test_data[i].lookup_id); - git_oid_fromstrn(&id->id, expand_id_test_data[i].lookup_id, len); + git_oid__fromstrn(&id->id, expand_id_test_data[i].lookup_id, len, GIT_OID_SHA1); id->length = (unsigned short)len; id->type = expand_id_test_data[i].expected_type; } @@ -186,13 +186,13 @@ static void assert_found_objects(git_odb_expand_id *ids) num = ARRAY_SIZE(expand_id_test_data); for (i = 0; i < num; i++) { - git_oid expected_id = {{0}}; + git_oid expected_id = GIT_OID_SHA1_ZERO; size_t expected_len = 0; git_object_t expected_type = 0; if (expand_id_test_data[i].expected_id) { - git_oid_fromstr(&expected_id, expand_id_test_data[i].expected_id); - expected_len = GIT_OID_HEXSZ; + git_oid__fromstr(&expected_id, expand_id_test_data[i].expected_id, GIT_OID_SHA1); + expected_len = GIT_OID_SHA1_HEXSIZE; expected_type = expand_id_test_data[i].expected_type; } @@ -204,7 +204,7 @@ static void assert_found_objects(git_odb_expand_id *ids) static void assert_notfound_objects(git_odb_expand_id *ids) { - git_oid expected_id = {{0}}; + git_oid expected_id = GIT_OID_SHA1_ZERO; size_t num, i; num = ARRAY_SIZE(expand_id_test_data); diff --git a/tests/libgit2/odb/open.c b/tests/libgit2/odb/open.c new file mode 100644 index 000000000..395406d0f --- /dev/null +++ b/tests/libgit2/odb/open.c @@ -0,0 +1,34 @@ +#include "clar_libgit2.h" + +void test_odb_open__initialize(void) +{ + cl_fixture_sandbox("testrepo.git"); +} + +void test_odb_open__cleanup(void) +{ + cl_fixture_cleanup("testrepo.git"); +} + +void test_odb_open__exists(void) +{ + git_odb *odb; + git_oid one, two; + +#ifdef GIT_EXPERIMENTAL_SHA256 + git_odb_options opts = GIT_ODB_OPTIONS_INIT; + + cl_git_pass(git_odb_open(&odb, "testrepo.git/objects", &opts)); + cl_git_pass(git_oid_fromstr(&one, "1385f264afb75a56a5bec74243be9b367ba4ca08", GIT_OID_SHA1)); + cl_git_pass(git_oid_fromstr(&two, "00112233445566778899aabbccddeeff00112233", GIT_OID_SHA1)); +#else + cl_git_pass(git_odb_open(&odb, "testrepo.git/objects")); + cl_git_pass(git_oid_fromstr(&one, "1385f264afb75a56a5bec74243be9b367ba4ca08")); + cl_git_pass(git_oid_fromstr(&two, "00112233445566778899aabbccddeeff00112233")); +#endif + + cl_assert(git_odb_exists(odb, &one)); + cl_assert(!git_odb_exists(odb, &two)); + + git_odb_free(odb); +} diff --git a/tests/libgit2/odb/pack_data_256.h b/tests/libgit2/odb/pack_data_256.h new file mode 100644 index 000000000..b63188227 --- /dev/null +++ b/tests/libgit2/odb/pack_data_256.h @@ -0,0 +1,154 @@ +#ifdef GIT_EXPERIMENTAL_SHA256 + +static const char *packed_objects_256[] = { + "99f3b405443221141eb0fd1e0cca5d355f893983749b7fb455769fba434e7945", + "d0fc7f52dc42358506e7f3f3be72f5271994abb104b9397ab3e19bb42361504d", + "86e228d9904af64586e9a8378005ba654681ff5be3c43ca930bf6b1f28d4395f", + "652412419a24ba62a1d897f40aeb80eecbf873797b04a1bbb8d71918653ef65b", + "ad90f638cb67720b20b904478471504acebacc7bb36e5dcad3e882acec496fed", + "4d46d9719e425ef2dfb5bfba098d0b62e21b2b92d0731892eef70db0870e3744", + "80ec1e36b983e68664e8357c538cd35b30638bb0cb99626f906d145e2d2e2558", + "e8bbf40ee280bc43b33c04df2250903b75e92f2497e91759cf1cad753c23be6c", + "8864b5746d7c5780083bb98449a3f5bf78d8281e8c5e3fd12a8ccd9103eb3a1f", + "083c2b8b445640d171e7aa667b0b32007006f786711032ebb82931cca69cc15b", + "5c8bea399f78d3d6a037a41cee2e763d00024180b66f2ec738d443b6a3dd7081", + "281c36286eab5e534f1c2121a4cf2cd48a32b3773a3e78df500bed3f3c9747f3", + "c9dc53358a0d83bee1caae40ee81d752abf4962a9f206702e24a447b766b5bd7", + "fafc05a1d0b7614ba32f428eb52f3439ffbfed9a817e5ae069364cfc3fa3e4d4", + "25a4efebb38c55b8f2309ce5e3116b2b9287239952cc2fa174074e05c6e5875a", + "c223f1b579bad18635efdeffa7a8ff40567d03fa427e08bb90d9878f958d8021", + "8a0042d434a2f8a2e8d47caa4eb454f388752fb3fe71150c1cea12e807cfdf1c", + "d79e913b4137117b7f8fc2a8d184373f657d6f71bbeaca0fe83b7757ce486108", + "375f69d3d41e36d6904bfa86221690ec49de2a030664a362abaf86c426f9f7e0", + "22b6705b86e4aa9120eff203af24709d483698d9f78695e86e82de121784b570", + "4516b0e63349c81abc6584cb11ce84ab8ba38b105f9de39d0d0a1455dba2478d", + "c2b535bfc3501f0b4e179d5d6f0e2cea613940fa3813be5923db7e71e190849f", + "aa793f0e9d9d746eba8a7a60cb4981f7e24ce9691910350d7df9b9e94c7567b9", + "890bb959ac8c20db603bf083bc82f55f9f42b6dca6581d941d0b361188abae3b", + "bfc0ee6fe04854c11011539f38cc6b9b73e0c445bac2008de2fb877123efc2e3", + "5ba7253f47d390ee2c7c7afe8fd9a963a7a2674bbdadeb9a927665c9246306c4", + "79bc735b91f8dfa9379d1d6c21e2d519ac1bf0d04d48534864c9ff571df5297d", + "f362826c827aa3bcbeb3ff8b71bba08d7440b89ab53fe95d61b8922d01f46e28", + "4a1b9c078e7bb20759a2d75e3a4b96827c851446c0261750b96aa5f286efe378", + "2e2aa456dbbb8889923eb6713672427854020298a764967c50235a9a76d7ce4b", + "97b0e3661fa0caa6200c50381233f8320b907540ceb9d17ac94fedc66fd093c2", + "ade7d297ede7bb58008da582de1253f0a55cb76e82d1cd376f82ccf97f70bced", + "3315093132a8f28bd202c0a9562d04eebea4943dcd1e1c754341b0389722042f", + "6fae137ba81d0d81c2a85759b99322e7ea8103bd7c8b85be3163b7e91e18c125", + "f8b45f792840019909fd35f9dcb98082b3bc39373268d467e1b00f1da5ac71e5", + "d2ab425d6092770366bc3dff5276e3a869221bc7b6d22e99c089d556e7eb8331", + "4dd37b9df07bcc7b45ce72a44e3f5fcaf5f0a9a5f3148963714eac4c99a60388", + "8c53c0f9f0972a1c77e40549170b9ae51d365c200ffc4cb220628c5bce3dd0b2", + "11d0463a82345c2512bd704dd00211aefb7d5b8590ca92809122fd09486a9f06", + "1ab4fa663d22416f45cb1a007d767a58d0abf5255bf86f888393dae637b37c3b", + "345d2fbf1d306c7ea46a05f497793308357e9e17ab0e866446d2b9894378ddce", + "304352ddad641770fcc94ee4d9f957cde7aaf4c107dbf8b5ba14d543640bf7dd", + "cfdd565f4cbc315760c287d57714852e1a4894eef9c715332fd556f2e114a9f1", + "d6d2e87e6de8690efd26b8c5b58de28dcb3c9bd2b7659eccf34468d71a7a4478", + "aa61d4adf622265ec814c1a97198d2bcd3f58fb08989cb9beda32a4d0aab6697", + "40799f33b8cd9ca41f36a2f89d8ac8550537ad01dfb21fbc76f01eeb62f512d4", + "faa7ca59426e17f6b34fa407d06cd634faaabeb4abe26df12296e05a17c98eef", + "1f6ea2cab887a2ff4bb1557a36dd6bac9931ef1f36794ddd22b4b7b7276051fb", + "b38a7a2ee69d55f021efa91caf59e23bccdaf6b8a9c3f83acd978aa177587537", + "f66691f32eb9b23a029b43251bfa994d16481fe97903057e121b76e4e78f6ff4", + "afe1fad6f6b22eea530ff7b373d6b9b787b39792f720e6fcd0692ba6ef99e02f", + "b71ee6c8837efa5b3ba3361f88c321d391ac05f41d5b2506cad39319e80716e4", + "e207a266e228414023223530eb77c64b10f2f5124f3354deb45aff04c1db98b9", + "696503760a18787240ba52ad1abec3be6517bb802238e9469b3a8999cbd6432c", + "c30d06fd49797e3135652d654db0de122dd83f8400df1c7a0e95ca3720defb0d", + "8a9b600a21987e6ffddbad745f38c115797eacef9117043bd9d2da4835ee3cc4", + "d509fa76ff5944e25f48c2476736b6239a53f0463cba6ebc488464d087951951", + "3e00d8cae2726dc33879adf876b30c306f50e7a85b15c8add4a27f84d88616d7", + "ce55f9f5ab1d799a9ffaa839539af196d13f35677b3d0761b0fe034e764f8d07", + "84005e38a65f4115d5c94790010dc57e1a3297f4aa89744f5927f208af758bd0", + "75b0ed5f4a2d5c810f34d867dbca51db6a596d4739abfaf24fcc0f05d99097a8", + "3eab74a6894d790767f3d92615a6887dcccaffa9e48fdd2ce482b5f17efcf9b9", + "8e61988c998c96a131cfe72225fce43e555bec4e590fa8c239373172a9d485ce", + "5f45a18f90f2934e7c7985d05b2b5b3584886fd057c9202f26f562d6c3080038", + "7609c608c1097270356a6fe336a8756ff124d4a9c2e941bba26a6e8c3becdeb1", + "81ba4e67aa59ccb078e3dc9ff3075f50084ec1696bd867e8e4284fcfc34fe3cf", + "3b1b991ae70d1f5388ad16b63d2285e99ada7a618c6f5d01e50a6d4b33c4767d", + "ac49410f64fad10760838866a40107573e42c86908c83ece433d64b7a8b57f7f", + "72c472319cf7d5d59bf9fea9e90b9785d7ab39340003fbc68619c11a9e583c2f", + "3a0cd33a47fcd0c7b8f8c1d407aaa53f648e25f2ffe2533a7e9c09c3d1b9da75", + "bf409f1aa76256282ebf1a7cc6c9f4220be9ffc47b2cc42248fcc5cbb67bce1f", + "13c8c9dae9fa63b1ec48b8abb12312fc8df61b9414678f504fa68164a48eef28", + "078baf54914fab56842798c90fec863f15f67a22041e8aa54a88c43f059da050", + "41c166c241a4e878f444932a193501e12ab38ba0634747291df70e619dccee1c", + "9db520a5a88c7d75b86a4faa1ce9010edf38af922f400c69a4a93aef69e25c4c", + "edf6e0dbfaf8a7ad89b05b5768981eeedd7a2bda4b1d0fae07aa2a9d49bb39df", + "ec1866b39026366e69ab8e167c15312c27f5eda4c0afdf9367ac3d76f56bf8e7", + "695bdb545f636d454b4825effd29db96c46d81772dda6c104f97dffe2ec509f1", + "07c31b4be5f3ec8f82c7ad6c91cbdf07ae876bb73041903d64fe8bac64bbcb6e", + "06665948a581e547ac1dc883b35bab54682fc311f7a87d5563a76501ecba55fc", + "fa6a2b7e588e57115d2772c0d5250d886757404fc510a5956be8de4926e94c01", + "28aec9a4450d9de98db98a021f97026bf12f1328f66e53319669eb5adce5ed3e", + "290d84a2cf108c074d3764ca8dc56e1215a5a7482837f098dff7a55e23d89d5f", + "ed10f9520d5f0d6bbd9c467ed83a239df0cba94ae9031602e02f6ad6256c459e", + "ad05c66a177f844f8239a1d186a1f803a4daa6286c959538838e222bc6337dc9", + "88fecc715077807bd7ee9e6a1dff65fde000379e0bf2a15cc2404469cef4c82b", + "bcc4fa242e55c5e08f64900407dca1cf2451806830905be616f339bf7a5580aa", + "4a4ebb837e3c9883f35d0ecdc26d4bc76a0f665568b08f3e967096f2fd3fa537", + "9abb7801e72353060a1490ffa3331674d6882558e7d6458de397b4b00d31ff8c", + "466cdfec4c74f3ed4fe53165e468a52df5dff9c6533ec433cdf235a73e099d32", + "8a1e1a6cc00519c4df8ce404c987751446fa299662308622cb63576fb52996d7", + "e5ea38108d603a6ed8dbb0b8455abe6d971f2d60920207e67ba646d267ece305", + "97e00ba4c8028ea91e7131c8c7596227cd03d3d2d14ed2d179fe0f305ebbca39", + "807faa3586b7f1aff2797a7c39c135b0196647c9ae7ee8843322accc960b2f22", + "b9134c331629e9cb29d1bbc03904d911a942b451e087543fc16deb0116391297", + "23cb97c200205dc84109c248be5bd719c23bdab52b52c51ec92fef9a48790833", + "b6e8427e3afe1cf0095d0f5aeca0642c4fb12d4e529f62e8264b6c4db72f04b4", + "92128dfb792caea934f5218807ec993867b0c8487a3de69ebac33e067f64d38a", + "a13ecbc514b571721a9a1c92af7f89d473a5fe13228904f8d17368e71f273ea1", + "3f5dca26a2f512d6681ce1957b8afba5e031bf63d52fd52d8f57093bf92391a4", + "1aa24b7ebd910f39a676f2ccab8e9a79f14842c20b55ed18e3dc297bdbaca279", + "1e0ce38d00e8f3e613febc0f8b275e0fd7fbef8af293fd62698be46dfbbc937d", + "dd9b1d5ca653752cef167e034324198971ab6f2f38f3db9db571cb2985759f00", + "efc4b8fd4b0b2586fce256b107ee2a052d11d26f99d85ce0478c3d49d1b2186b", + "da38f65b32fb03ce332e0c4238edae0a733e4cd793d849522bb4e0bdd0af608c", + "bf66badfda7b5d2157db65c5310cfdc4e904d7d5da57ac5abe17542de612f856", + "2c0f52f9ae1f34f280dfc1c755cbfaf2b9968fd3bab1f1eb16d3ac0fafd71940", + "165ec90aa4190bbe12ee415b294fd6d204c64afcf1ca64dd815782872b24ea26", + "cc3d272d457c7e26c5d611923841511a1766bcd58e5be66433698627e6fb3f9d", + "d970d1a6296d149bfb8283b8b4a9a6f7e9ee320c5d46a5ef216e10400df2d281", + "bdc530e0b98dd736cd812408eeed9aa0d393bbd0630b355eb7601e61f0dbc7c4", + "94db24aca3f8e07f481744f62633730feb4fc47605280381a08be510ae971ffe", + "151c7527acc5b731199a03a932ae374331e16e5ae29256e98cb652f37669889b", + "ac88849a26c126b03fc6fcb17cb23ec563e87a5f63b7afe800ad0f436128ce98", + "26a2dac21f8f0939566570e48f7f4fcf89239c2746ef8d3dbf31d179c691808f", + "619f24a7f37f8ca922c83b3a1b9a384eb6a444ff3a2a52c712f3c60dde6f24fb", + "5329dd2fd8557be5ad06b57882cf42e23d767cdc8a4b25e464fdb00890649e07", + "fff5cbc10ffea865d69aba64082ae17479c522e8e0305e678469749282bf0a18", + "d0c992aae9cde855b17ac826234a73255ecb09534cdcfa633d90640f6a4324d9", + "6129f1672465ee7b9e2edef53fbf3846ab5d06e8e6a1d7fb51e31666a8b411f8", + "0a8c0add81b065b97451f7b47a9935f0e240251c5f90a89ced885cb7d4efc2ba", + "471fa4fc2da467dd94e57babb1912bbdb5e40b96c8129d46fc709c0bfc009bca", + "23cea2b49eed4993c5b92a9d5f0b82efe4fae3837ea707d921de645d04479015", + "c85e35eec23dea4089aee7a2dc7f6d937ad7e13c66bdbd7eef37bd6336418609", + "a0f3dac8fa0e22dcf356aecbbdf79440715687c1053bc59b83354f276d688ceb", + "1cfb8ae71e9e576d1b16b7bd1a62156d0641c6e51f5d76877be6de4f26410623" +}; + +static const char *loose_objects_256[] = { + "96c18f0297e38d01f4b2dacddea4259aea6b2961eb0822bd2c0c3f6029030045", + "aea29dc305d40e362df25c3fdeed5502fd56b182af01b7740d297a24459333c5", + "73b4f3c4f3182e6c8dd2c98aeb2c7811556538e7673e4b325307c71685fbf5b6", + "901505c3355518bee35475c5d3f23bac1dded688b2bd314cc32b7f157e100724", + "4bc142808884e472ee6cc331b132e66ef18f564d41efb055804ec1dd28efb3f5", + "7e4633ae1b0e83503dbea4417f9d5ccaf22b877c5a4522b6d1d2b16090ee2f6f", + "473a0f4c3be8a93681a267e3b1e9a7dcda1185436fe141f7749120a303721813", + "7030f925768d9beb65654ab8f436e3ca0a82b25eddefd237bf5a26a0441c2aa7", + "cb282e7c15fd8aeb2265cd621f5a228cb33dc84192980ca426cf9ab2a48cb9f0", + "33e415b835a670bb5c3c760efa0433ac0cbd2d44679f68f2df3a9ae7014cf2a8", + "8155958bbda08eed88c8ac908dc44452ed38911cffa54ccc06076f30a1ffb1bf", + "1b4b74772bd83ff28bf44cda9be93f4afc2279623bb5b36c9194a660b7623c24", + "f31459efb9367c5a19c9dd24c75107423d5773066922ea5e55eaeb6490979562", + "6d5fd291bb0f67444e99ab492f1bf1fcdf5dca09dab24cf331e05111b4cfc1a3", + "b83624f6ac0995273c0034a7ab8c68929bdc91b69ad54ef94979b93eba3f6022", + "61489e9e831f1d9001084d39b79f964c293db8620d679ea3596673c8a326446e", + "abee32b3339d1566d75613ea61f40c14bdfc5b101b60fde4f44b58dd06667640", + "a4813ef6708e6011e8187224297e83e4a285f58bf5eabb1db270351388603c95", + "43e084a4599ca42c476919917e3db8fde0045ee66305fd5e634b0c793c536a1b" +}; + +#endif diff --git a/tests/libgit2/odb/pack_data_one256.h b/tests/libgit2/odb/pack_data_one256.h new file mode 100644 index 000000000..98a874798 --- /dev/null +++ b/tests/libgit2/odb/pack_data_one256.h @@ -0,0 +1,21 @@ +/* Just a few to make sure it's working, the rest is tested already */ +#ifdef GIT_EXPERIMENTAL_SHA256 +static const char *packed_objects_one256[] = { + "ea926306b1bab6d3f25f45609907eb6dff91a1460b25e63bf4a0494c70e7a269", + "d048ba2ef4fafa502a44cbc1a50cd58359b9bc243b84a08f541a08ca5f621137", + "a66bda0109d2b3c9bc87970da81bd91076b5f871febbc860f09ae997668b6800", + "3609a41c0506fe19d01fb8b4729923362675f191fe5f63fab3111ef804c48fdf", + "22b6705b86e4aa9120eff203af24709d483698d9f78695e86e82de121784b570", + "6f11d93bfb269ee8c7a506178f60c430abfac5d424acfd9c0b0b27b98e6ab49b", + "0aefd477d9e5b3f8d708a3cf6d78be6b670dfa2e2ec41244634f3b8f115d8e04", + "580474d948cd2ebd2e5ce7a5b81b872d87ba4639c1ac4c0fa7a11a8eddf9827c", + "0636b4292bfdd7274a977cb6f8b2ded8f315ea1bcd8dbedfca37964c2ed3d085", + "19fb1c78b11f0f8bda658d6fa6cc63c0b573c0f6760ee5a9c2df6ce2cde00c5c", + "7f2f7afccb317bb3fdd28555f126846dc4eebe5d9ae7b8d8a1456e8ff85422ce", + "4066249c68b0d3c8b39ebe02c9188935900465acad02a49269710f56720fa58e", + "a560d1fa1edf114f57b402e16d662c17b1e3b7e8601ff7dcea6615ba7f1e48ef", + "58923faa87c7d559d308a114ec2b164e5d6046c889420ed1def6eef2d55106a2", + "753ddabab8ae9c1e733cda15e8e3c83dd43f5a2d939ae32cc3b30b0be1e91f96", + "46333d32b3801cf11d9f80b557245c9e32b0e05deca61dae968914fde159f0e5" +}; +#endif diff --git a/tests/libgit2/odb/packed.c b/tests/libgit2/odb/packed.c index 3d502ed6d..b41041fc1 100644 --- a/tests/libgit2/odb/packed.c +++ b/tests/libgit2/odb/packed.c @@ -6,7 +6,7 @@ static git_odb *_odb; void test_odb_packed__initialize(void) { - cl_git_pass(git_odb_open(&_odb, cl_fixture("testrepo.git/objects"))); + cl_git_pass(git_odb__open(&_odb, cl_fixture("testrepo.git/objects"), NULL)); } void test_odb_packed__cleanup(void) @@ -23,7 +23,7 @@ void test_odb_packed__mass_read(void) git_oid id; git_odb_object *obj; - cl_git_pass(git_oid_fromstr(&id, packed_objects[i])); + cl_git_pass(git_oid__fromstr(&id, packed_objects[i], GIT_OID_SHA1)); cl_assert(git_odb_exists(_odb, &id) == 1); cl_git_pass(git_odb_read(&obj, _odb, &id)); @@ -41,7 +41,7 @@ void test_odb_packed__read_header_0(void) size_t len; git_object_t type; - cl_git_pass(git_oid_fromstr(&id, packed_objects[i])); + cl_git_pass(git_oid__fromstr(&id, packed_objects[i], GIT_OID_SHA1)); cl_git_pass(git_odb_read(&obj, _odb, &id)); cl_git_pass(git_odb_read_header(&len, &type, _odb, &id)); @@ -63,7 +63,7 @@ void test_odb_packed__read_header_1(void) size_t len; git_object_t type; - cl_git_pass(git_oid_fromstr(&id, loose_objects[i])); + cl_git_pass(git_oid__fromstr(&id, loose_objects[i], GIT_OID_SHA1)); cl_assert(git_odb_exists(_odb, &id) == 1); diff --git a/tests/libgit2/odb/packed256.c b/tests/libgit2/odb/packed256.c new file mode 100644 index 000000000..65220fd4c --- /dev/null +++ b/tests/libgit2/odb/packed256.c @@ -0,0 +1,98 @@ +#include "clar_libgit2.h" +#include "odb.h" +#include "pack_data_256.h" + +#ifdef GIT_EXPERIMENTAL_SHA256 +static git_odb *_odb; +#endif + +void test_odb_packed256__initialize(void) +{ +#ifdef GIT_EXPERIMENTAL_SHA256 + git_odb_options opts = GIT_ODB_OPTIONS_INIT; + + opts.oid_type = GIT_OID_SHA256; + + cl_git_pass(git_odb__open( + &_odb, + cl_fixture("testrepo_256.git/objects"), + &opts)); +#endif +} + +void test_odb_packed256__cleanup(void) +{ +#ifdef GIT_EXPERIMENTAL_SHA256 + git_odb_free(_odb); + _odb = NULL; +#endif +} + +void test_odb_packed256__mass_read(void) +{ +#ifdef GIT_EXPERIMENTAL_SHA256 + unsigned int i; + + for (i = 0; i < ARRAY_SIZE(packed_objects_256); ++i) { + git_oid id; + git_odb_object *obj; + + cl_git_pass(git_oid__fromstr(&id, packed_objects_256[i], GIT_OID_SHA256)); + cl_assert(git_odb_exists(_odb, &id) == 1); + cl_git_pass(git_odb_read(&obj, _odb, &id)); + + git_odb_object_free(obj); + } +#endif +} + +void test_odb_packed256__read_header_0(void) +{ +#ifdef GIT_EXPERIMENTAL_SHA256 + unsigned int i; + + for (i = 0; i < ARRAY_SIZE(packed_objects_256); ++i) { + git_oid id; + git_odb_object *obj; + size_t len; + git_object_t type; + + cl_git_pass(git_oid__fromstr(&id, packed_objects_256[i], GIT_OID_SHA256)); + + cl_git_pass(git_odb_read(&obj, _odb, &id)); + cl_git_pass(git_odb_read_header(&len, &type, _odb, &id)); + + cl_assert(obj->cached.size == len); + cl_assert(obj->cached.type == type); + + git_odb_object_free(obj); + } +#endif +} + +void test_odb_packed256__read_header_1(void) +{ +#ifdef GIT_EXPERIMENTAL_SHA256 + unsigned int i; + + for (i = 0; i < ARRAY_SIZE(loose_objects_256); ++i) { + git_oid id; + git_odb_object *obj; + size_t len; + git_object_t type; + + cl_git_pass(git_oid__fromstr(&id, loose_objects_256[i], GIT_OID_SHA256)); + + cl_assert(git_odb_exists(_odb, &id) == 1); + + cl_git_pass(git_odb_read(&obj, _odb, &id)); + cl_git_pass(git_odb_read_header(&len, &type, _odb, &id)); + + cl_assert(obj->cached.size == len); + cl_assert(obj->cached.type == type); + + git_odb_object_free(obj); + } +#endif +} + diff --git a/tests/libgit2/odb/packed_one.c b/tests/libgit2/odb/packedone.c similarity index 55% rename from tests/libgit2/odb/packed_one.c rename to tests/libgit2/odb/packedone.c index 17cd4f760..8637001ff 100644 --- a/tests/libgit2/odb/packed_one.c +++ b/tests/libgit2/odb/packedone.c @@ -6,22 +6,29 @@ static git_odb *_odb; -void test_odb_packed_one__initialize(void) +void test_odb_packedone__initialize(void) { git_odb_backend *backend = NULL; - cl_git_pass(git_odb_new(&_odb)); - cl_git_pass(git_odb_backend_one_pack(&backend, cl_fixture("testrepo.git/objects/pack/pack-a81e489679b7d3418f9ab594bda8ceb37dd4c695.idx"))); + cl_git_pass(git_odb__new(&_odb, NULL)); +#ifdef GIT_EXPERIMENTAL_SHA256 + cl_git_pass(git_odb_backend_one_pack(&backend, + cl_fixture("testrepo.git/objects/pack/pack-a81e489679b7d3418f9ab594bda8ceb37dd4c695.idx"), + NULL)); +#else + cl_git_pass(git_odb_backend_one_pack(&backend, + cl_fixture("testrepo.git/objects/pack/pack-a81e489679b7d3418f9ab594bda8ceb37dd4c695.idx"))); +#endif cl_git_pass(git_odb_add_backend(_odb, backend, 1)); } -void test_odb_packed_one__cleanup(void) +void test_odb_packedone__cleanup(void) { git_odb_free(_odb); _odb = NULL; } -void test_odb_packed_one__mass_read(void) +void test_odb_packedone__mass_read(void) { unsigned int i; @@ -29,7 +36,7 @@ void test_odb_packed_one__mass_read(void) git_oid id; git_odb_object *obj; - cl_git_pass(git_oid_fromstr(&id, packed_objects_one[i])); + cl_git_pass(git_oid__fromstr(&id, packed_objects_one[i], GIT_OID_SHA1)); cl_assert(git_odb_exists(_odb, &id) == 1); cl_git_pass(git_odb_read(&obj, _odb, &id)); @@ -37,7 +44,7 @@ void test_odb_packed_one__mass_read(void) } } -void test_odb_packed_one__read_header_0(void) +void test_odb_packedone__read_header_0(void) { unsigned int i; @@ -47,7 +54,7 @@ void test_odb_packed_one__read_header_0(void) size_t len; git_object_t type; - cl_git_pass(git_oid_fromstr(&id, packed_objects_one[i])); + cl_git_pass(git_oid__fromstr(&id, packed_objects_one[i], GIT_OID_SHA1)); cl_git_pass(git_odb_read(&obj, _odb, &id)); cl_git_pass(git_odb_read_header(&len, &type, _odb, &id)); diff --git a/tests/libgit2/odb/packedone256.c b/tests/libgit2/odb/packedone256.c new file mode 100644 index 000000000..fdeac4205 --- /dev/null +++ b/tests/libgit2/odb/packedone256.c @@ -0,0 +1,78 @@ +#include "clar_libgit2.h" +#include "git2/odb_backend.h" + +#include "pack_data_one256.h" +#include "pack.h" + +#ifdef GIT_EXPERIMENTAL_SHA256 +static git_odb *_odb; +#endif + +void test_odb_packedone256__initialize(void) +{ +#ifdef GIT_EXPERIMENTAL_SHA256 + git_odb_backend *backend = NULL; + git_odb_options odb_opts = GIT_ODB_OPTIONS_INIT; + git_odb_backend_pack_options backend_opts = GIT_ODB_BACKEND_PACK_OPTIONS_INIT; + + odb_opts.oid_type = GIT_OID_SHA256; + backend_opts.oid_type = GIT_OID_SHA256; + + cl_git_pass(git_odb__new(&_odb, &odb_opts)); + cl_git_pass(git_odb_backend_one_pack( + &backend, + cl_fixture("testrepo_256.git/objects/pack/pack-e2f07f30db7e480ea84a0e64ee791b9b270067124b2609019b74f33f256f33fa.idx"), + &backend_opts)); + cl_git_pass(git_odb_add_backend(_odb, backend, 1)); +#endif +} + +void test_odb_packedone256__cleanup(void) +{ +#ifdef GIT_EXPERIMENTAL_SHA256 + git_odb_free(_odb); + _odb = NULL; +#endif +} + +void test_odb_packedone256__mass_read(void) +{ +#ifdef GIT_EXPERIMENTAL_SHA256 + unsigned int i; + + for (i = 0; i < ARRAY_SIZE(packed_objects_one256); ++i) { + git_oid id; + git_odb_object *obj; + + cl_git_pass(git_oid__fromstr(&id, packed_objects_one256[i], GIT_OID_SHA256)); + cl_assert(git_odb_exists(_odb, &id) == 1); + cl_git_pass(git_odb_read(&obj, _odb, &id)); + + git_odb_object_free(obj); + } +#endif +} + +void test_odb_packedone256__read_header_0(void) +{ +#ifdef GIT_EXPERIMENTAL_SHA256 + unsigned int i; + + for (i = 0; i < ARRAY_SIZE(packed_objects_one256); ++i) { + git_oid id; + git_odb_object *obj; + size_t len; + git_object_t type; + + cl_git_pass(git_oid__fromstr(&id, packed_objects_one256[i], GIT_OID_SHA256)); + + cl_git_pass(git_odb_read(&obj, _odb, &id)); + cl_git_pass(git_odb_read_header(&len, &type, _odb, &id)); + + cl_assert(obj->cached.size == len); + cl_assert(obj->cached.type == type); + + git_odb_object_free(obj); + } +#endif +} diff --git a/tests/libgit2/odb/sorting.c b/tests/libgit2/odb/sorting.c index e027230fa..ec4e3696b 100644 --- a/tests/libgit2/odb/sorting.c +++ b/tests/libgit2/odb/sorting.c @@ -37,7 +37,7 @@ static git_odb *_odb; void test_odb_sorting__initialize(void) { - cl_git_pass(git_odb_new(&_odb)); + cl_git_pass(git_odb__new(&_odb, NULL)); } void test_odb_sorting__cleanup(void) @@ -79,12 +79,17 @@ void test_odb_sorting__override_default_backend_priority(void) { git_odb *new_odb; git_odb_backend *loose, *packed, *backend; + cl_git_pass(git_libgit2_opts(GIT_OPT_SET_ODB_LOOSE_PRIORITY, 5)); cl_git_pass(git_libgit2_opts(GIT_OPT_SET_ODB_PACKED_PRIORITY, 3)); - git_odb_backend_pack(&packed, "./testrepo.git/objects"); - git_odb_backend_loose(&loose, "./testrepo.git/objects", -1, 0, 0, 0); + git_odb_backend_pack(&packed, "./testrepo.git/objects" +#ifdef GIT_EXPERIMENTAL_SHA256 + , NULL +#endif + ); + git_odb__backend_loose(&loose, "./testrepo.git/objects", NULL); - cl_git_pass(git_odb_open(&new_odb, cl_fixture("testrepo.git/objects"))); + cl_git_pass(git_odb__open(&new_odb, cl_fixture("testrepo.git/objects"), NULL)); cl_assert_equal_sz(2, git_odb_num_backends(new_odb)); cl_git_pass(git_odb_get_backend(&backend, new_odb, 0)); diff --git a/tests/libgit2/online/clone.c b/tests/libgit2/online/clone.c index dfaee0e85..1a4cdb520 100644 --- a/tests/libgit2/online/clone.c +++ b/tests/libgit2/online/clone.c @@ -21,6 +21,7 @@ static git_clone_options g_options; static char *_remote_url = NULL; static char *_remote_user = NULL; static char *_remote_pass = NULL; +static char *_remote_branch = NULL; static char *_remote_sslnoverify = NULL; static char *_remote_ssh_pubkey = NULL; static char *_remote_ssh_privkey = NULL; @@ -35,6 +36,11 @@ static char *_remote_expectcontinue = NULL; static char *_remote_redirect_initial = NULL; static char *_remote_redirect_subsequent = NULL; +static char *_github_ssh_pubkey = NULL; +static char *_github_ssh_privkey = NULL; +static char *_github_ssh_passphrase = NULL; +static char *_github_ssh_remotehostkey = NULL; + static int _orig_proxies_need_reset = 0; static char *_orig_http_proxy = NULL; static char *_orig_https_proxy = NULL; @@ -69,6 +75,7 @@ void test_online_clone__initialize(void) _remote_url = cl_getenv("GITTEST_REMOTE_URL"); _remote_user = cl_getenv("GITTEST_REMOTE_USER"); _remote_pass = cl_getenv("GITTEST_REMOTE_PASS"); + _remote_branch = cl_getenv("GITTEST_REMOTE_BRANCH"); _remote_sslnoverify = cl_getenv("GITTEST_REMOTE_SSL_NOVERIFY"); _remote_ssh_pubkey = cl_getenv("GITTEST_REMOTE_SSH_PUBKEY"); _remote_ssh_privkey = cl_getenv("GITTEST_REMOTE_SSH_KEY"); @@ -83,6 +90,11 @@ void test_online_clone__initialize(void) _remote_redirect_initial = cl_getenv("GITTEST_REMOTE_REDIRECT_INITIAL"); _remote_redirect_subsequent = cl_getenv("GITTEST_REMOTE_REDIRECT_SUBSEQUENT"); + _github_ssh_pubkey = cl_getenv("GITTEST_GITHUB_SSH_PUBKEY"); + _github_ssh_privkey = cl_getenv("GITTEST_GITHUB_SSH_KEY"); + _github_ssh_passphrase = cl_getenv("GITTEST_GITHUB_SSH_PASSPHRASE"); + _github_ssh_remotehostkey = cl_getenv("GITTEST_GITHUB_SSH_REMOTE_HOSTKEY"); + if (_remote_expectcontinue) git_libgit2_opts(GIT_OPT_ENABLE_HTTP_EXPECT_CONTINUE, 1); @@ -102,6 +114,7 @@ void test_online_clone__cleanup(void) git__free(_remote_url); git__free(_remote_user); git__free(_remote_pass); + git__free(_remote_branch); git__free(_remote_sslnoverify); git__free(_remote_ssh_pubkey); git__free(_remote_ssh_privkey); @@ -116,6 +129,11 @@ void test_online_clone__cleanup(void) git__free(_remote_redirect_initial); git__free(_remote_redirect_subsequent); + git__free(_github_ssh_pubkey); + git__free(_github_ssh_privkey); + git__free(_github_ssh_passphrase); + git__free(_github_ssh_remotehostkey); + if (_orig_proxies_need_reset) { cl_setenv("HTTP_PROXY", _orig_http_proxy); cl_setenv("HTTPS_PROXY", _orig_https_proxy); @@ -309,6 +327,16 @@ void test_online_clone__custom_headers(void) cl_git_pass(git_clone(&g_repo, LIVE_REPO_URL, "./foo", &g_options)); } +void test_online_clone__long_custom_header(void) +{ + /* Long custom header with 1500 characters */ + char *ok = "X-Custom: a0MsqH2bXV9lILn7zkAHqKpGrOVvkik7SfoyqfXbFTxccsymN5SG9hEB0RLD9koTXKWtaI1vI9jHf5ViwLHq6xvkveFX9GiqaIhe3TRu5KDZrOBgeufdBYsTTONALPlpni9XVq71bR6x3AlVEqHdXi9qiq0TRuNiujMy0ZKs8LQkQVSE8kxWZXqLsO2IJtAPw5aqsUEenK5ec12GOeOTOYlSChGllzvl2Ow4SKlVg3t8NHVWvc8HyPGmBQ79l3qUMU30P0hnUXaIrhIzGgleYWnwhGFLpryxsQfCdwkdBMuvtLH0DnkhLoAkCmnCZItEExtHBOCirEzztoFMX3lH4lM4wMqePCU8II0qloNvzPgt6cBThQJP66FYUDSCwsSb63bcTWdVx7TCa6mAplkP49PKi5pFSvFKKbs5se5MPcBVG03GiatKszIQkii0vp6OV5b54Aym4N8hQJHFMhIChKiQM91tB7PQu9vPJE6h2bzAnQsn34bBPFZHT7pBplqkASiHDjw69YV6k3M8ffTOTr2ibQnTKxh1NH3ZRx6u0KxRty9i4YLMniZUZAfFgqbSW2xXk49e8J9VNFm7j2bgHp3t813wUzqnQL4NEc0CQlF0e6pId5ADXikoH6S7aMfuYUYi1Kn1i9m7UGtaB0U7dVC65uH9vIWKnyAcmBt0mN1aikRnjz7oBKjD65SRZrKWXeCDJkpgWlXnD5JjekDCyB9m3yGkaxy1FflI1kaa4kcVbPRfs6XebHRDl9golPBUyazRG1V1iOi1mKki9ClUNO8wviNfKm5eMbWW6hU8wMXh388EotRA73TUdL4JIfNpkC4XBFLNFbFtltzO34kxXBKvhj8t0XVZOp4AWpHEL3pUtuyKhNWaWlDF6ZhjCeO8vT1akKoYaA7t6nFyqawq5nPoB0iXEHQ7YugfYfgjzpNGLgvPJ6aLg9YIKZBqfi7J9xWb356IJvTQFswi7qm6Mu7IVXarS9m84b5IfT6UCVq84u4VcdBlDswNPTw6SbBtzg9vrLLs3MoTCzJY6fHPqnKt6YthgQwOOB1ig7GTSDiX3W3SMeaz5jTASociHrUS3HrwVSgjrODnF86962cv4s3DGYjiX2cIuNfq9mZVJlNsylZjFYFV9LzOjNLlSHZVJrrGQJLjmyOCwOMkG9u2xKdSvfjxTJzqhjhTvQSQZWhKt44hA9EidUqPqjc3MhfnZ6aeAIP232gtRHoRc7FdjRSan4Q3PWy02YiRodvKAafonwCOtMcm4MASrXBiBE1tibHLSTtK4UrodFNVhymtBCRnJdVRSgrCQcr2B5Jzs4Iv6uJlJqwwyuq6In54zcmecgJZezta84B3eFoSGJhCbI6Zza0khulccglCcppciWDStAHFhncePsCQL4tup0Z8fS01RksRQ7X1xgskVvQAKELThDqbJB4FJZwrwPXOpCweAoSONntp7Ly0lAUabw75gK5sR387IxNVdISmfP"; + + g_options.fetch_opts.custom_headers.count = 1; + g_options.fetch_opts.custom_headers.strings = &ok; + cl_git_pass(git_clone(&g_repo, LIVE_REPO_URL, "./foo", &g_options)); +} + static int cred_failure_cb( git_credential **cred, const char *url, @@ -484,9 +512,13 @@ void test_online_clone__bitbucket_falls_back_to_specified_creds(void) void test_online_clone__googlesource(void) { +#ifdef __APPLE__ + cl_skip(); +#else cl_git_pass(git_clone(&g_repo, GOOGLESOURCE_REPO_URL, "./foo", &g_options)); git_repository_free(g_repo); g_repo = NULL; cl_fixture_cleanup("./foo"); +#endif } static int cancel_at_half(const git_indexer_progress *stats, void *payload) @@ -537,6 +569,68 @@ static int check_ssh_auth_methods(git_credential **cred, const char *url, const return GIT_EUSER; } +static int succeed_certificate_check(git_cert *cert, int valid, const char *host, void *payload) +{ + GIT_UNUSED(cert); + GIT_UNUSED(valid); + GIT_UNUSED(payload); + + cl_assert_equal_s("github.com", host); + + return 0; +} + +static int fail_certificate_check(git_cert *cert, int valid, const char *host, void *payload) +{ + GIT_UNUSED(cert); + GIT_UNUSED(valid); + GIT_UNUSED(host); + GIT_UNUSED(payload); + + return GIT_ECERTIFICATE; +} + +static int github_credentials( + git_credential **cred, + const char *url, + const char *username_from_url, + unsigned int allowed_types, + void *data) +{ + GIT_UNUSED(url); + GIT_UNUSED(username_from_url); + GIT_UNUSED(data); + + if ((allowed_types & GIT_CREDENTIAL_USERNAME) != 0) { + return git_credential_username_new(cred, "git"); + } + + cl_assert((allowed_types & GIT_CREDENTIAL_SSH_KEY) != 0); + + return git_credential_ssh_key_memory_new(cred, + "git", + _github_ssh_pubkey, + _github_ssh_privkey, + _github_ssh_passphrase); +} + +void test_online_clone__ssh_github(void) +{ +#if !defined(GIT_SSH) || !defined(GIT_SSH_MEMORY_CREDENTIALS) + clar__skip(); +#endif + + if (!_github_ssh_pubkey || !_github_ssh_privkey) + clar__skip(); + + cl_fake_homedir(NULL); + + g_options.fetch_opts.callbacks.credentials = github_credentials; + g_options.fetch_opts.callbacks.certificate_check = succeed_certificate_check; + + cl_git_pass(git_clone(&g_repo, SSH_REPO_URL, "./foo", &g_options)); +} + void test_online_clone__ssh_auth_methods(void) { int with_user; @@ -546,7 +640,7 @@ void test_online_clone__ssh_auth_methods(void) #endif g_options.fetch_opts.callbacks.credentials = check_ssh_auth_methods; g_options.fetch_opts.callbacks.payload = &with_user; - g_options.fetch_opts.callbacks.certificate_check = NULL; + g_options.fetch_opts.callbacks.certificate_check = succeed_certificate_check; with_user = 0; cl_git_fail_with(GIT_EUSER, @@ -557,6 +651,69 @@ void test_online_clone__ssh_auth_methods(void) git_clone(&g_repo, "ssh://git@github.com/libgit2/TestGitRepository", "./foo", &g_options)); } +/* + * Ensure that the certificate check callback is still called, and + * can accept a host key that is not in the known hosts file. + */ +void test_online_clone__ssh_certcheck_accepts_unknown(void) +{ +#if !defined(GIT_SSH) || !defined(GIT_SSH_MEMORY_CREDENTIALS) + clar__skip(); +#endif + + if (!_github_ssh_pubkey || !_github_ssh_privkey) + clar__skip(); + + cl_fake_homedir(NULL); + + g_options.fetch_opts.callbacks.credentials = github_credentials; + + /* Ensure we fail without the certificate check */ + cl_git_fail_with(GIT_ECERTIFICATE, + git_clone(&g_repo, SSH_REPO_URL, "./foo", NULL)); + + /* Set the callback to accept the certificate */ + g_options.fetch_opts.callbacks.certificate_check = succeed_certificate_check; + + cl_git_pass(git_clone(&g_repo, SSH_REPO_URL, "./foo", &g_options)); +} + +/* + * Ensure that the known hosts file is read and the certificate check + * callback is still called after that. + */ +void test_online_clone__ssh_certcheck_override_knownhosts(void) +{ + git_str knownhostsfile = GIT_STR_INIT; + +#if !defined(GIT_SSH) || !defined(GIT_SSH_MEMORY_CREDENTIALS) + clar__skip(); +#endif + + if (!_github_ssh_pubkey || !_github_ssh_privkey || !_github_ssh_remotehostkey) + clar__skip(); + + g_options.fetch_opts.callbacks.credentials = github_credentials; + + cl_fake_homedir(&knownhostsfile); + cl_git_pass(git_str_joinpath(&knownhostsfile, knownhostsfile.ptr, ".ssh")); + cl_git_pass(p_mkdir(knownhostsfile.ptr, 0777)); + + cl_git_pass(git_str_joinpath(&knownhostsfile, knownhostsfile.ptr, "known_hosts")); + cl_git_rewritefile(knownhostsfile.ptr, _github_ssh_remotehostkey); + + /* Ensure we succeed without the certificate check */ + cl_git_pass(git_clone(&g_repo, SSH_REPO_URL, "./foo", &g_options)); + git_repository_free(g_repo); + g_repo = NULL; + + /* Set the callback to reject the certificate */ + g_options.fetch_opts.callbacks.certificate_check = fail_certificate_check; + cl_git_fail_with(GIT_ECERTIFICATE, git_clone(&g_repo, SSH_REPO_URL, "./bar", &g_options)); + + git_str_dispose(&knownhostsfile); +} + static int custom_remote_ssh_with_paths( git_remote **out, git_repository *repo, @@ -629,14 +786,14 @@ void test_online_clone__ssh_cannot_change_username(void) static int ssh_certificate_check(git_cert *cert, int valid, const char *host, void *payload) { git_cert_hostkey *key; - git_oid expected = {{0}}, actual = {{0}}; + git_oid expected = GIT_OID_SHA1_ZERO, actual = GIT_OID_SHA1_ZERO; GIT_UNUSED(valid); GIT_UNUSED(payload); cl_assert(_remote_ssh_fingerprint); - cl_git_pass(git_oid_fromstrp(&expected, _remote_ssh_fingerprint)); + cl_git_pass(git_oid__fromstrp(&expected, _remote_ssh_fingerprint, GIT_OID_SHA1)); cl_assert_equal_i(GIT_CERT_HOSTKEY_LIBSSH2, cert->cert_type); key = (git_cert_hostkey *) cert; @@ -729,16 +886,6 @@ void test_online_clone__ssh_memory_auth(void) cl_git_pass(git_clone(&g_repo, _remote_url, "./foo", &g_options)); } -static int fail_certificate_check(git_cert *cert, int valid, const char *host, void *payload) -{ - GIT_UNUSED(cert); - GIT_UNUSED(valid); - GIT_UNUSED(host); - GIT_UNUSED(payload); - - return GIT_ECERTIFICATE; -} - void test_online_clone__certificate_invalid(void) { g_options.fetch_opts.callbacks.certificate_check = fail_certificate_check; @@ -752,17 +899,6 @@ void test_online_clone__certificate_invalid(void) #endif } -static int succeed_certificate_check(git_cert *cert, int valid, const char *host, void *payload) -{ - GIT_UNUSED(cert); - GIT_UNUSED(valid); - GIT_UNUSED(payload); - - cl_assert_equal_s("github.com", host); - - return 0; -} - void test_online_clone__certificate_valid(void) { g_options.fetch_opts.callbacks.certificate_check = succeed_certificate_check; @@ -1002,3 +1138,61 @@ void test_online_clone__redirect_initial_fails_for_subsequent(void) cl_git_fail(git_clone(&g_repo, _remote_redirect_subsequent, "./fail", &options)); } + +void test_online_clone__namespace_bare(void) +{ + git_clone_options options = GIT_CLONE_OPTIONS_INIT; + git_reference *head; + + if (!_remote_url) + cl_skip(); + + options.bare = true; + + cl_git_pass(git_clone(&g_repo, _remote_url, "./namespaced.git", &options)); + + cl_git_pass(git_reference_lookup(&head, g_repo, GIT_HEAD_FILE)); + cl_assert_equal_i(GIT_REFERENCE_SYMBOLIC, git_reference_type(head)); + cl_assert_equal_s("refs/heads/master", git_reference_symbolic_target(head)); + + git_reference_free(head); +} + +void test_online_clone__namespace_with_specified_branch(void) +{ + git_clone_options options = GIT_CLONE_OPTIONS_INIT; + git_reference *head; + + if (!_remote_url || !_remote_branch) + cl_skip(); + + options.checkout_branch = _remote_branch; + + cl_git_pass(git_clone(&g_repo, _remote_url, "./namespaced", &options)); + + cl_git_pass(git_reference_lookup(&head, g_repo, GIT_HEAD_FILE)); + cl_assert_equal_i(GIT_REFERENCE_SYMBOLIC, git_reference_type(head)); + cl_assert_equal_strn("refs/heads/", git_reference_symbolic_target(head), 11); + cl_assert_equal_s(_remote_branch, git_reference_symbolic_target(head) + 11); + + git_reference_free(head); +} + +void test_online_clone__sha256(void) +{ +#ifndef GIT_EXPERIMENTAL_SHA256 + cl_skip(); +#else + git_clone_options options = GIT_CLONE_OPTIONS_INIT; + git_reference *head; + + if (!_remote_url) + cl_skip(); + + cl_git_pass(git_clone(&g_repo, _remote_url, "./sha256", &options)); + cl_git_pass(git_reference_lookup(&head, g_repo, GIT_HEAD_FILE)); + cl_assert_equal_i(GIT_REFERENCE_SYMBOLIC, git_reference_type(head)); + + git_reference_free(head); +#endif +} diff --git a/tests/libgit2/online/fetch.c b/tests/libgit2/online/fetch.c index 5beb5b618..a557bbf75 100644 --- a/tests/libgit2/online/fetch.c +++ b/tests/libgit2/online/fetch.c @@ -304,7 +304,7 @@ void test_online_fetch__reachable_commit(void) refspecs.strings = &refspec; refspecs.count = 1; - git_oid_fromstr(&expected_id, "2c349335b7f797072cf729c4f3bb0914ecb6dec9"); + git_oid__fromstr(&expected_id, "2c349335b7f797072cf729c4f3bb0914ecb6dec9", GIT_OID_SHA1); cl_git_pass(git_remote_create(&remote, _repo, "test", "https://github.com/libgit2/TestGitRepository")); @@ -334,7 +334,7 @@ void test_online_fetch__reachable_commit_without_destination(void) refspecs.strings = &refspec; refspecs.count = 1; - git_oid_fromstr(&expected_id, "2c349335b7f797072cf729c4f3bb0914ecb6dec9"); + git_oid__fromstr(&expected_id, "2c349335b7f797072cf729c4f3bb0914ecb6dec9", GIT_OID_SHA1); cl_git_pass(git_remote_create(&remote, _repo, "test", "https://github.com/libgit2/TestGitRepository")); diff --git a/tests/libgit2/online/push.c b/tests/libgit2/online/push.c index 51adc3930..204572cf5 100644 --- a/tests/libgit2/online/push.c +++ b/tests/libgit2/online/push.c @@ -344,18 +344,18 @@ void test_online_push__initialize(void) * * a78705c3b2725f931d3ee05348d83cc26700f247 (b2, b1) added fold and fold/b.txt * * 5c0bb3d1b9449d1cc69d7519fd05166f01840915 added a.txt */ - git_oid_fromstr(&_oid_b6, "951bbbb90e2259a4c8950db78946784fb53fcbce"); - git_oid_fromstr(&_oid_b5, "fa38b91f199934685819bea316186d8b008c52a2"); - git_oid_fromstr(&_oid_b4, "27b7ce66243eb1403862d05f958c002312df173d"); - git_oid_fromstr(&_oid_b3, "d9b63a88223d8367516f50bd131a5f7349b7f3e4"); - git_oid_fromstr(&_oid_b2, "a78705c3b2725f931d3ee05348d83cc26700f247"); - git_oid_fromstr(&_oid_b1, "a78705c3b2725f931d3ee05348d83cc26700f247"); + git_oid__fromstr(&_oid_b6, "951bbbb90e2259a4c8950db78946784fb53fcbce", GIT_OID_SHA1); + git_oid__fromstr(&_oid_b5, "fa38b91f199934685819bea316186d8b008c52a2", GIT_OID_SHA1); + git_oid__fromstr(&_oid_b4, "27b7ce66243eb1403862d05f958c002312df173d", GIT_OID_SHA1); + git_oid__fromstr(&_oid_b3, "d9b63a88223d8367516f50bd131a5f7349b7f3e4", GIT_OID_SHA1); + git_oid__fromstr(&_oid_b2, "a78705c3b2725f931d3ee05348d83cc26700f247", GIT_OID_SHA1); + git_oid__fromstr(&_oid_b1, "a78705c3b2725f931d3ee05348d83cc26700f247", GIT_OID_SHA1); - git_oid_fromstr(&_tag_commit, "805c54522e614f29f70d2413a0470247d8b424ac"); - git_oid_fromstr(&_tag_tree, "ff83aa4c5e5d28e3bcba2f5c6e2adc61286a4e5e"); - git_oid_fromstr(&_tag_blob, "b483ae7ba66decee9aee971f501221dea84b1498"); - git_oid_fromstr(&_tag_lightweight, "951bbbb90e2259a4c8950db78946784fb53fcbce"); - git_oid_fromstr(&_tag_tag, "eea4f2705eeec2db3813f2430829afce99cd00b5"); + git_oid__fromstr(&_tag_commit, "805c54522e614f29f70d2413a0470247d8b424ac", GIT_OID_SHA1); + git_oid__fromstr(&_tag_tree, "ff83aa4c5e5d28e3bcba2f5c6e2adc61286a4e5e", GIT_OID_SHA1); + git_oid__fromstr(&_tag_blob, "b483ae7ba66decee9aee971f501221dea84b1498", GIT_OID_SHA1); + git_oid__fromstr(&_tag_lightweight, "951bbbb90e2259a4c8950db78946784fb53fcbce", GIT_OID_SHA1); + git_oid__fromstr(&_tag_tag, "eea4f2705eeec2db3813f2430829afce99cd00b5", GIT_OID_SHA1); /* Remote URL environment variable must be set. User and password are optional. */ @@ -841,13 +841,28 @@ void test_online_push__bad_refspecs(void) void test_online_push__expressions(void) { - /* TODO: Expressions in refspecs doesn't actually work yet */ - const char *specs_left_expr[] = { "refs/heads/b2~1:refs/heads/b2" }; + const char *specs_left_expr[] = { + "refs/heads/b3~1:refs/heads/b2", + "b4:refs/heads/b4", + "fa38b91f199934685819bea316186d8b008c52a2:refs/heads/b5", + "951bbbb:refs/heads/b6" + }; + push_status exp_stats[] = { + { "refs/heads/b2", 1 }, + { "refs/heads/b4", 1 }, + { "refs/heads/b5", 1 }, + { "refs/heads/b6", 1 } + }; + expected_ref exp_refs[] = { + { "refs/heads/b2", &_oid_b2 }, + { "refs/heads/b4", &_oid_b4 }, + { "refs/heads/b5", &_oid_b5 }, + { "refs/heads/b6", &_oid_b6 } + }; - /* TODO: Find a more precise way of checking errors than a exit code of -1. */ do_push(specs_left_expr, ARRAY_SIZE(specs_left_expr), - NULL, 0, - NULL, 0, -1, 0, 0); + exp_stats, ARRAY_SIZE(exp_stats), + exp_refs, ARRAY_SIZE(exp_refs), 0, 1, 1); } void test_online_push__notes(void) @@ -859,7 +874,7 @@ void test_online_push__notes(void) expected_ref exp_refs[] = { { "refs/notes/commits", &expected_oid } }; const char *specs_del[] = { ":refs/notes/commits" }; - git_oid_fromstr(&expected_oid, "8461a99b27b7043e58ff6e1f5d2cf07d282534fb"); + git_oid__fromstr(&expected_oid, "8461a99b27b7043e58ff6e1f5d2cf07d282534fb", GIT_OID_SHA1); target_oid = &_oid_b6; @@ -890,7 +905,7 @@ void test_online_push__configured(void) expected_ref exp_refs[] = { { "refs/notes/commits", &expected_oid } }; const char *specs_del[] = { ":refs/notes/commits" }; - git_oid_fromstr(&expected_oid, "8461a99b27b7043e58ff6e1f5d2cf07d282534fb"); + git_oid__fromstr(&expected_oid, "8461a99b27b7043e58ff6e1f5d2cf07d282534fb", GIT_OID_SHA1); target_oid = &_oid_b6; diff --git a/tests/libgit2/online/push_util.c b/tests/libgit2/online/push_util.c index cd1831d4c..94919e9b2 100644 --- a/tests/libgit2/online/push_util.c +++ b/tests/libgit2/online/push_util.c @@ -2,8 +2,6 @@ #include "vector.h" #include "push_util.h" -const git_oid OID_ZERO = {{ 0 }}; - void updated_tip_free(updated_tip *t) { git__free(t->name); diff --git a/tests/libgit2/pack/indexer.c b/tests/libgit2/pack/indexer.c index 94b2cc92e..9722decaf 100644 --- a/tests/libgit2/pack/indexer.c +++ b/tests/libgit2/pack/indexer.c @@ -100,7 +100,12 @@ void test_pack_indexer__out_of_order(void) git_indexer *idx = 0; git_indexer_progress stats = { 0 }; +#ifdef GIT_EXPERIMENTAL_SHA256 + cl_git_pass(git_indexer_new(&idx, ".", GIT_OID_SHA1, NULL)); +#else cl_git_pass(git_indexer_new(&idx, ".", 0, NULL, NULL)); +#endif + cl_git_pass(git_indexer_append( idx, out_of_order_pack, out_of_order_pack_len, &stats)); cl_git_pass(git_indexer_commit(idx, &stats)); @@ -117,7 +122,12 @@ void test_pack_indexer__missing_trailer(void) git_indexer *idx = 0; git_indexer_progress stats = { 0 }; +#ifdef GIT_EXPERIMENTAL_SHA256 + cl_git_pass(git_indexer_new(&idx, ".", GIT_OID_SHA1, NULL)); +#else cl_git_pass(git_indexer_new(&idx, ".", 0, NULL, NULL)); +#endif + cl_git_pass(git_indexer_append( idx, missing_trailer_pack, missing_trailer_pack_len, &stats)); cl_git_fail(git_indexer_commit(idx, &stats)); @@ -133,7 +143,12 @@ void test_pack_indexer__leaky(void) git_indexer *idx = 0; git_indexer_progress stats = { 0 }; +#ifdef GIT_EXPERIMENTAL_SHA256 + cl_git_pass(git_indexer_new(&idx, ".", GIT_OID_SHA1, NULL)); +#else cl_git_pass(git_indexer_new(&idx, ".", 0, NULL, NULL)); +#endif + cl_git_pass(git_indexer_append( idx, leaky_pack, leaky_pack_len, &stats)); cl_git_fail(git_indexer_commit(idx, &stats)); @@ -151,16 +166,23 @@ void test_pack_indexer__fix_thin(void) git_repository *repo; git_odb *odb; git_oid id, should_id; + git_indexer_options opts = GIT_INDEXER_OPTIONS_INIT; cl_git_pass(git_repository_init(&repo, "thin.git", true)); cl_git_pass(git_repository_odb(&odb, repo)); /* Store the missing base into your ODB so the indexer can fix the pack */ cl_git_pass(git_odb_write(&id, odb, base_obj, base_obj_len, GIT_OBJECT_BLOB)); - git_oid_fromstr(&should_id, "e68fe8129b546b101aee9510c5328e7f21ca1d18"); + git_oid__fromstr(&should_id, "e68fe8129b546b101aee9510c5328e7f21ca1d18", GIT_OID_SHA1); cl_assert_equal_oid(&should_id, &id); - cl_git_pass(git_indexer_new(&idx, ".", 0, odb, NULL)); +#ifdef GIT_EXPERIMENTAL_SHA256 + opts.odb = odb; + cl_git_pass(git_indexer_new(&idx, ".", GIT_OID_SHA1, &opts)); +#else + cl_git_pass(git_indexer_new(&idx, ".", 0, odb, &opts)); +#endif + cl_git_pass(git_indexer_append(idx, thin_pack, thin_pack_len, &stats)); cl_git_pass(git_indexer_commit(idx, &stats)); @@ -192,7 +214,12 @@ void test_pack_indexer__fix_thin(void) cl_git_pass(p_stat(name, &st)); +#ifdef GIT_EXPERIMENTAL_SHA256 + cl_git_pass(git_indexer_new(&idx, ".", GIT_OID_SHA1, NULL)); +#else cl_git_pass(git_indexer_new(&idx, ".", 0, NULL, NULL)); +#endif + read = p_read(fd, buffer, sizeof(buffer)); cl_assert(read != -1); p_close(fd); @@ -216,16 +243,23 @@ void test_pack_indexer__corrupt_length(void) git_repository *repo; git_odb *odb; git_oid id, should_id; + git_indexer_options opts = GIT_INDEXER_OPTIONS_INIT; cl_git_pass(git_repository_init(&repo, "thin.git", true)); cl_git_pass(git_repository_odb(&odb, repo)); /* Store the missing base into your ODB so the indexer can fix the pack */ cl_git_pass(git_odb_write(&id, odb, base_obj, base_obj_len, GIT_OBJECT_BLOB)); - git_oid_fromstr(&should_id, "e68fe8129b546b101aee9510c5328e7f21ca1d18"); + git_oid__fromstr(&should_id, "e68fe8129b546b101aee9510c5328e7f21ca1d18", GIT_OID_SHA1); cl_assert_equal_oid(&should_id, &id); - cl_git_pass(git_indexer_new(&idx, ".", 0, odb, NULL)); +#ifdef GIT_EXPERIMENTAL_SHA256 + opts.odb = odb; + cl_git_pass(git_indexer_new(&idx, ".", GIT_OID_SHA1, &opts)); +#else + cl_git_pass(git_indexer_new(&idx, ".", 0, odb, &opts)); +#endif + cl_git_pass(git_indexer_append( idx, corrupt_thin_pack, corrupt_thin_pack_len, &stats)); cl_git_fail(git_indexer_commit(idx, &stats)); @@ -246,7 +280,12 @@ void test_pack_indexer__incomplete_pack_fails_with_strict(void) opts.verify = 1; +#ifdef GIT_EXPERIMENTAL_SHA256 + cl_git_pass(git_indexer_new(&idx, ".", GIT_OID_SHA1, &opts)); +#else cl_git_pass(git_indexer_new(&idx, ".", 0, NULL, &opts)); +#endif + cl_git_pass(git_indexer_append( idx, incomplete_pack, incomplete_pack_len, &stats)); cl_git_fail(git_indexer_commit(idx, &stats)); @@ -266,7 +305,12 @@ void test_pack_indexer__out_of_order_with_connectivity_checks(void) opts.verify = 1; +#ifdef GIT_EXPERIMENTAL_SHA256 + cl_git_pass(git_indexer_new(&idx, ".", GIT_OID_SHA1, &opts)); +#else cl_git_pass(git_indexer_new(&idx, ".", 0, NULL, &opts)); +#endif + cl_git_pass(git_indexer_append( idx, out_of_order_pack, out_of_order_pack_len, &stats)); cl_git_pass(git_indexer_commit(idx, &stats)); @@ -309,7 +353,12 @@ void test_pack_indexer__no_tmp_files(void) git_str_dispose(&path); cl_assert(git_str_len(&first_tmp_file) == 0); +#ifdef GIT_EXPERIMENTAL_SHA256 + cl_git_pass(git_indexer_new(&idx, ".", GIT_OID_SHA1, NULL)); +#else cl_git_pass(git_indexer_new(&idx, ".", 0, NULL, NULL)); +#endif + git_indexer_free(idx); cl_git_pass(git_str_sets(&path, clar_sandbox_path())); diff --git a/tests/libgit2/pack/midx.c b/tests/libgit2/pack/midx.c index 9dd949363..f7d680165 100644 --- a/tests/libgit2/pack/midx.c +++ b/tests/libgit2/pack/midx.c @@ -19,8 +19,8 @@ void test_pack_midx__parse(void) cl_git_pass(git_midx_open(&idx, git_str_cstr(&midx_path))); cl_assert_equal_i(git_midx_needs_refresh(idx, git_str_cstr(&midx_path)), 0); - cl_git_pass(git_oid_fromstr(&id, "5001298e0c09ad9c34e4249bc5801c75e9754fa5")); - cl_git_pass(git_midx_entry_find(&e, idx, &id, GIT_OID_HEXSZ)); + cl_git_pass(git_oid__fromstr(&id, "5001298e0c09ad9c34e4249bc5801c75e9754fa5", GIT_OID_SHA1)); + cl_git_pass(git_midx_entry_find(&e, idx, &id, GIT_OID_SHA1_HEXSIZE)); cl_assert_equal_oid(&e.sha1, &id); cl_assert_equal_s( (const char *)git_vector_get(&idx->packfile_names, e.pack_index), @@ -39,8 +39,8 @@ void test_pack_midx__lookup(void) cl_git_pass(git_repository_open(&repo, cl_fixture("testrepo.git"))); - cl_git_pass(git_oid_fromstr(&id, "5001298e0c09ad9c34e4249bc5801c75e9754fa5")); - cl_git_pass(git_commit_lookup_prefix(&commit, repo, &id, GIT_OID_HEXSZ)); + cl_git_pass(git_oid__fromstr(&id, "5001298e0c09ad9c34e4249bc5801c75e9754fa5", GIT_OID_SHA1)); + cl_git_pass(git_commit_lookup_prefix(&commit, repo, &id, GIT_OID_SHA1_HEXSIZE)); cl_assert_equal_s(git_commit_message(commit), "packed commit one\n"); git_commit_free(commit); diff --git a/tests/libgit2/pack/packbuilder.c b/tests/libgit2/pack/packbuilder.c index 0889f46ed..ff3dc1f68 100644 --- a/tests/libgit2/pack/packbuilder.c +++ b/tests/libgit2/pack/packbuilder.c @@ -104,7 +104,12 @@ void test_pack_packbuilder__create_pack(void) seed_packbuilder(); +#ifdef GIT_EXPERIMENTAL_SHA256 + cl_git_pass(git_indexer_new(&_indexer, ".", GIT_OID_SHA1, NULL)); +#else cl_git_pass(git_indexer_new(&_indexer, ".", 0, NULL, NULL)); +#endif + cl_git_pass(git_packbuilder_foreach(_packbuilder, feed_indexer, &stats)); cl_git_pass(git_indexer_commit(_indexer, &stats)); @@ -244,7 +249,13 @@ void test_pack_packbuilder__foreach(void) git_indexer *idx; seed_packbuilder(); + +#ifdef GIT_EXPERIMENTAL_SHA256 + cl_git_pass(git_indexer_new(&idx, ".", GIT_OID_SHA1, NULL)); +#else cl_git_pass(git_indexer_new(&idx, ".", 0, NULL, NULL)); +#endif + cl_git_pass(git_packbuilder_foreach(_packbuilder, foreach_cb, idx)); cl_git_pass(git_indexer_commit(idx, &_stats)); git_indexer_free(idx); @@ -262,7 +273,13 @@ void test_pack_packbuilder__foreach_with_cancel(void) git_indexer *idx; seed_packbuilder(); + +#ifdef GIT_EXPERIMENTAL_SHA256 + cl_git_pass(git_indexer_new(&idx, ".", GIT_OID_SHA1, NULL)); +#else cl_git_pass(git_indexer_new(&idx, ".", 0, NULL, NULL)); +#endif + cl_git_fail_with( git_packbuilder_foreach(_packbuilder, foreach_cancel_cb, idx), -1111); git_indexer_free(idx); diff --git a/tests/libgit2/pack/sharing.c b/tests/libgit2/pack/sharing.c index eaf7686b7..2e2042d2b 100644 --- a/tests/libgit2/pack/sharing.c +++ b/tests/libgit2/pack/sharing.c @@ -18,7 +18,7 @@ void test_pack_sharing__open_two_repos(void) cl_git_pass(git_repository_open(&repo1, cl_fixture("testrepo.git"))); cl_git_pass(git_repository_open(&repo2, cl_fixture("testrepo.git"))); - git_oid_fromstr(&id, "a65fedf39aefe402d3bb6e24df4d4f5fe4547750"); + git_oid__fromstr(&id, "a65fedf39aefe402d3bb6e24df4d4f5fe4547750", GIT_OID_SHA1); cl_git_pass(git_object_lookup(&obj1, repo1, &id, GIT_OBJECT_ANY)); cl_git_pass(git_object_lookup(&obj2, repo2, &id, GIT_OBJECT_ANY)); diff --git a/tests/libgit2/patch/parse.c b/tests/libgit2/patch/parse.c index a3c4c6730..d90576e46 100644 --- a/tests/libgit2/patch/parse.c +++ b/tests/libgit2/patch/parse.c @@ -7,7 +7,7 @@ static void ensure_patch_validity(git_patch *patch) { const git_diff_delta *delta; - char idstr[GIT_OID_HEXSZ+1] = {0}; + char idstr[GIT_OID_SHA1_HEXSIZE+1] = {0}; cl_assert((delta = git_patch_get_delta(patch)) != NULL); cl_assert_equal_i(2, delta->nfiles); diff --git a/tests/libgit2/perf/helper__perf__do_merge.c b/tests/libgit2/perf/helper__perf__do_merge.c index c77b46a1f..eb10524ec 100644 --- a/tests/libgit2/perf/helper__perf__do_merge.c +++ b/tests/libgit2/perf/helper__perf__do_merge.c @@ -33,7 +33,7 @@ void perf__do_merge(const char *fixture, cl_git_pass(git_clone(&g_repo, fixture, test_name, &clone_opts)); perf__timer__stop(&t_clone); - git_oid_fromstr(&oid_a, id_a); + git_oid__fromstr(&oid_a, id_a, GIT_OID_SHA1); cl_git_pass(git_commit_lookup(&commit_a, g_repo, &oid_a)); cl_git_pass(git_branch_create(&ref_branch_a, g_repo, "A", commit_a, @@ -45,7 +45,7 @@ void perf__do_merge(const char *fixture, cl_git_pass(git_repository_set_head(g_repo, git_reference_name(ref_branch_a))); - git_oid_fromstr(&oid_b, id_b); + git_oid__fromstr(&oid_b, id_b, GIT_OID_SHA1); cl_git_pass(git_commit_lookup(&commit_b, g_repo, &oid_b)); cl_git_pass(git_branch_create(&ref_branch_b, g_repo, "B", commit_b, diff --git a/tests/libgit2/rebase/abort.c b/tests/libgit2/rebase/abort.c index a83c529ce..da0dfe893 100644 --- a/tests/libgit2/rebase/abort.c +++ b/tests/libgit2/rebase/abort.c @@ -128,8 +128,8 @@ void test_rebase_abort__merge_by_id(void) git_oid branch_id, onto_id; git_annotated_commit *branch_head, *onto_head; - cl_git_pass(git_oid_fromstr(&branch_id, "b146bd7608eac53d9bf9e1a6963543588b555c64")); - cl_git_pass(git_oid_fromstr(&onto_id, "efad0b11c47cb2f0220cbd6f5b0f93bb99064b00")); + cl_git_pass(git_oid__fromstr(&branch_id, "b146bd7608eac53d9bf9e1a6963543588b555c64", GIT_OID_SHA1)); + cl_git_pass(git_oid__fromstr(&onto_id, "efad0b11c47cb2f0220cbd6f5b0f93bb99064b00", GIT_OID_SHA1)); cl_git_pass(git_annotated_commit_lookup(&branch_head, repo, &branch_id)); cl_git_pass(git_annotated_commit_lookup(&onto_head, repo, &onto_id)); @@ -170,8 +170,8 @@ void test_rebase_abort__merge_by_id_immediately_after_init(void) git_oid branch_id, onto_id; git_annotated_commit *branch_head, *onto_head; - cl_git_pass(git_oid_fromstr(&branch_id, "b146bd7608eac53d9bf9e1a6963543588b555c64")); - cl_git_pass(git_oid_fromstr(&onto_id, "efad0b11c47cb2f0220cbd6f5b0f93bb99064b00")); + cl_git_pass(git_oid__fromstr(&branch_id, "b146bd7608eac53d9bf9e1a6963543588b555c64", GIT_OID_SHA1)); + cl_git_pass(git_oid__fromstr(&onto_id, "efad0b11c47cb2f0220cbd6f5b0f93bb99064b00", GIT_OID_SHA1)); cl_git_pass(git_annotated_commit_lookup(&branch_head, repo, &branch_id)); cl_git_pass(git_annotated_commit_lookup(&onto_head, repo, &onto_id)); @@ -195,8 +195,8 @@ void test_rebase_abort__detached_head(void) git_signature *signature; git_annotated_commit *branch_head, *onto_head; - git_oid_fromstr(&branch_id, "b146bd7608eac53d9bf9e1a6963543588b555c64"); - git_oid_fromstr(&onto_id, "efad0b11c47cb2f0220cbd6f5b0f93bb99064b00"); + git_oid__fromstr(&branch_id, "b146bd7608eac53d9bf9e1a6963543588b555c64", GIT_OID_SHA1); + git_oid__fromstr(&onto_id, "efad0b11c47cb2f0220cbd6f5b0f93bb99064b00", GIT_OID_SHA1); cl_git_pass(git_annotated_commit_lookup(&branch_head, repo, &branch_id)); cl_git_pass(git_annotated_commit_lookup(&onto_head, repo, &onto_id)); diff --git a/tests/libgit2/rebase/inmemory.c b/tests/libgit2/rebase/inmemory.c index 040a81b1b..287dd9911 100644 --- a/tests/libgit2/rebase/inmemory.c +++ b/tests/libgit2/rebase/inmemory.c @@ -74,7 +74,7 @@ void test_rebase_inmemory__can_resolve_conflicts(void) cl_git_pass(git_rebase_next(&rebase_operation, rebase)); - git_oid_fromstr(&pick_id, "33f915f9e4dbd9f4b24430e48731a59b45b15500"); + git_oid__fromstr(&pick_id, "33f915f9e4dbd9f4b24430e48731a59b45b15500", GIT_OID_SHA1); cl_assert_equal_i(GIT_REBASE_OPERATION_PICK, rebase_operation->type); cl_assert_equal_oid(&pick_id, &rebase_operation->id); @@ -95,14 +95,14 @@ void test_rebase_inmemory__can_resolve_conflicts(void) /* ensure that we can work with the in-memory index to resolve the conflict */ resolution.path = "asparagus.txt"; resolution.mode = GIT_FILEMODE_BLOB; - git_oid_fromstr(&resolution.id, "414dfc71ead79c07acd4ea47fecf91f289afc4b9"); + git_oid__fromstr(&resolution.id, "414dfc71ead79c07acd4ea47fecf91f289afc4b9", GIT_OID_SHA1); cl_git_pass(git_index_conflict_remove(rebase_index, "asparagus.txt")); cl_git_pass(git_index_add(rebase_index, &resolution)); /* and finally create a commit for the resolved rebase operation */ cl_git_pass(git_rebase_commit(&commit_id, rebase, NULL, signature, NULL, NULL)); - cl_git_pass(git_oid_fromstr(&expected_commit_id, "db7af47222181e548810da2ab5fec0e9357c5637")); + cl_git_pass(git_oid__fromstr(&expected_commit_id, "db7af47222181e548810da2ab5fec0e9357c5637", GIT_OID_SHA1)); cl_assert_equal_oid(&commit_id, &expected_commit_id); git_status_list_free(status_list); @@ -156,7 +156,7 @@ void test_rebase_inmemory__no_common_ancestor(void) cl_git_pass(git_rebase_finish(rebase, signature)); - git_oid_fromstr(&expected_final_id, "71e7ee8d4fe7d8bf0d107355197e0a953dfdb7f3"); + git_oid__fromstr(&expected_final_id, "71e7ee8d4fe7d8bf0d107355197e0a953dfdb7f3", GIT_OID_SHA1); cl_assert_equal_oid(&expected_final_id, &commit_id); git_annotated_commit_free(branch_head); @@ -178,7 +178,7 @@ void test_rebase_inmemory__with_directories(void) opts.inmemory = true; - git_oid_fromstr(&tree_id, "a4d6d9c3d57308fd8e320cf2525bae8f1adafa57"); + git_oid__fromstr(&tree_id, "a4d6d9c3d57308fd8e320cf2525bae8f1adafa57", GIT_OID_SHA1); cl_git_pass(git_reference_lookup(&branch_ref, repo, "refs/heads/deep_gravy")); cl_git_pass(git_reference_lookup(&upstream_ref, repo, "refs/heads/veal")); diff --git a/tests/libgit2/rebase/iterator.c b/tests/libgit2/rebase/iterator.c index a120f28ac..79e9f3e58 100644 --- a/tests/libgit2/rebase/iterator.c +++ b/tests/libgit2/rebase/iterator.c @@ -30,11 +30,11 @@ static void test_operations(git_rebase *rebase, size_t expected_current) git_oid expected_oid[5]; git_rebase_operation *operation; - git_oid_fromstr(&expected_oid[0], "da9c51a23d02d931a486f45ad18cda05cf5d2b94"); - git_oid_fromstr(&expected_oid[1], "8d1f13f93c4995760ac07d129246ac1ff64c0be9"); - git_oid_fromstr(&expected_oid[2], "3069cc907e6294623e5917ef6de663928c1febfb"); - git_oid_fromstr(&expected_oid[3], "588e5d2f04d49707fe4aab865e1deacaf7ef6787"); - git_oid_fromstr(&expected_oid[4], "b146bd7608eac53d9bf9e1a6963543588b555c64"); + git_oid__fromstr(&expected_oid[0], "da9c51a23d02d931a486f45ad18cda05cf5d2b94", GIT_OID_SHA1); + git_oid__fromstr(&expected_oid[1], "8d1f13f93c4995760ac07d129246ac1ff64c0be9", GIT_OID_SHA1); + git_oid__fromstr(&expected_oid[2], "3069cc907e6294623e5917ef6de663928c1febfb", GIT_OID_SHA1); + git_oid__fromstr(&expected_oid[3], "588e5d2f04d49707fe4aab865e1deacaf7ef6787", GIT_OID_SHA1); + git_oid__fromstr(&expected_oid[4], "b146bd7608eac53d9bf9e1a6963543588b555c64", GIT_OID_SHA1); cl_assert_equal_i(expected_count, git_rebase_operation_entrycount(rebase)); cl_assert_equal_i(expected_current, git_rebase_operation_current(rebase)); @@ -78,7 +78,7 @@ static void test_iterator(bool inmemory) NULL, NULL)); test_operations(rebase, 0); - git_oid_fromstr(&expected_id, "776e4c48922799f903f03f5f6e51da8b01e4cce0"); + git_oid__fromstr(&expected_id, "776e4c48922799f903f03f5f6e51da8b01e4cce0", GIT_OID_SHA1); cl_assert_equal_oid(&expected_id, &commit_id); cl_git_pass(git_rebase_next(&rebase_operation, rebase)); @@ -86,7 +86,7 @@ static void test_iterator(bool inmemory) NULL, NULL)); test_operations(rebase, 1); - git_oid_fromstr(&expected_id, "ba1f9b4fd5cf8151f7818be2111cc0869f1eb95a"); + git_oid__fromstr(&expected_id, "ba1f9b4fd5cf8151f7818be2111cc0869f1eb95a", GIT_OID_SHA1); cl_assert_equal_oid(&expected_id, &commit_id); cl_git_pass(git_rebase_next(&rebase_operation, rebase)); @@ -94,7 +94,7 @@ static void test_iterator(bool inmemory) NULL, NULL)); test_operations(rebase, 2); - git_oid_fromstr(&expected_id, "948b12fe18b84f756223a61bece4c307787cd5d4"); + git_oid__fromstr(&expected_id, "948b12fe18b84f756223a61bece4c307787cd5d4", GIT_OID_SHA1); cl_assert_equal_oid(&expected_id, &commit_id); if (!inmemory) { @@ -107,7 +107,7 @@ static void test_iterator(bool inmemory) NULL, NULL)); test_operations(rebase, 3); - git_oid_fromstr(&expected_id, "d9d5d59d72c9968687f9462578d79878cd80e781"); + git_oid__fromstr(&expected_id, "d9d5d59d72c9968687f9462578d79878cd80e781", GIT_OID_SHA1); cl_assert_equal_oid(&expected_id, &commit_id); cl_git_pass(git_rebase_next(&rebase_operation, rebase)); @@ -115,7 +115,7 @@ static void test_iterator(bool inmemory) NULL, NULL)); test_operations(rebase, 4); - git_oid_fromstr(&expected_id, "9cf383c0a125d89e742c5dec58ed277dd07588b3"); + git_oid__fromstr(&expected_id, "9cf383c0a125d89e742c5dec58ed277dd07588b3", GIT_OID_SHA1); cl_assert_equal_oid(&expected_id, &commit_id); cl_git_fail(error = git_rebase_next(&rebase_operation, rebase)); diff --git a/tests/libgit2/rebase/merge.c b/tests/libgit2/rebase/merge.c index 5f730f750..870c3ea2f 100644 --- a/tests/libgit2/rebase/merge.c +++ b/tests/libgit2/rebase/merge.c @@ -46,8 +46,8 @@ void test_rebase_merge__next(void) git_oid pick_id, file1_id; git_oid master_id, beef_id; - git_oid_fromstr(&master_id, "efad0b11c47cb2f0220cbd6f5b0f93bb99064b00"); - git_oid_fromstr(&beef_id, "b146bd7608eac53d9bf9e1a6963543588b555c64"); + git_oid__fromstr(&master_id, "efad0b11c47cb2f0220cbd6f5b0f93bb99064b00", GIT_OID_SHA1); + git_oid__fromstr(&beef_id, "b146bd7608eac53d9bf9e1a6963543588b555c64", GIT_OID_SHA1); cl_git_pass(git_reference_lookup(&branch_ref, repo, "refs/heads/beef")); cl_git_pass(git_reference_lookup(&upstream_ref, repo, "refs/heads/master")); @@ -65,7 +65,7 @@ void test_rebase_merge__next(void) cl_git_pass(git_rebase_next(&rebase_operation, rebase)); - git_oid_fromstr(&pick_id, "da9c51a23d02d931a486f45ad18cda05cf5d2b94"); + git_oid__fromstr(&pick_id, "da9c51a23d02d931a486f45ad18cda05cf5d2b94", GIT_OID_SHA1); cl_assert_equal_i(GIT_REBASE_OPERATION_PICK, rebase_operation->type); cl_assert_equal_oid(&pick_id, &rebase_operation->id); @@ -78,7 +78,7 @@ void test_rebase_merge__next(void) cl_assert_equal_s("beef.txt", status_entry->head_to_index->new_file.path); - git_oid_fromstr(&file1_id, "8d95ea62e621f1d38d230d9e7d206e41096d76af"); + git_oid__fromstr(&file1_id, "8d95ea62e621f1d38d230d9e7d206e41096d76af", GIT_OID_SHA1); cl_assert_equal_oid(&file1_id, &status_entry->head_to_index->new_file.id); git_status_list_free(status_list); @@ -129,7 +129,7 @@ void test_rebase_merge__next_with_conflicts(void) cl_git_pass(git_rebase_next(&rebase_operation, rebase)); - git_oid_fromstr(&pick_id, "33f915f9e4dbd9f4b24430e48731a59b45b15500"); + git_oid__fromstr(&pick_id, "33f915f9e4dbd9f4b24430e48731a59b45b15500", GIT_OID_SHA1); cl_assert_equal_i(GIT_REBASE_OPERATION_PICK, rebase_operation->type); cl_assert_equal_oid(&pick_id, &rebase_operation->id); @@ -230,11 +230,11 @@ void test_rebase_merge__commit(void) cl_git_pass(git_commit_lookup(&commit, repo, &commit_id)); - git_oid_fromstr(&parent_id, "efad0b11c47cb2f0220cbd6f5b0f93bb99064b00"); + git_oid__fromstr(&parent_id, "efad0b11c47cb2f0220cbd6f5b0f93bb99064b00", GIT_OID_SHA1); cl_assert_equal_i(1, git_commit_parentcount(commit)); cl_assert_equal_oid(&parent_id, git_commit_parent_id(commit, 0)); - git_oid_fromstr(&tree_id, "4461379789c777d2a6c1f2ee0e9d6c86731b9992"); + git_oid__fromstr(&tree_id, "4461379789c777d2a6c1f2ee0e9d6c86731b9992", GIT_OID_SHA1); cl_assert_equal_oid(&tree_id, git_commit_tree_id(commit)); cl_assert_equal_s(NULL, git_commit_message_encoding(commit)); @@ -275,8 +275,8 @@ void test_rebase_merge__commit_with_id(void) git_reflog *reflog; const git_reflog_entry *reflog_entry; - cl_git_pass(git_oid_fromstr(&branch_id, "b146bd7608eac53d9bf9e1a6963543588b555c64")); - cl_git_pass(git_oid_fromstr(&upstream_id, "efad0b11c47cb2f0220cbd6f5b0f93bb99064b00")); + cl_git_pass(git_oid__fromstr(&branch_id, "b146bd7608eac53d9bf9e1a6963543588b555c64", GIT_OID_SHA1)); + cl_git_pass(git_oid__fromstr(&upstream_id, "efad0b11c47cb2f0220cbd6f5b0f93bb99064b00", GIT_OID_SHA1)); cl_git_pass(git_annotated_commit_lookup(&branch_head, repo, &branch_id)); cl_git_pass(git_annotated_commit_lookup(&upstream_head, repo, &upstream_id)); @@ -289,11 +289,11 @@ void test_rebase_merge__commit_with_id(void) cl_git_pass(git_commit_lookup(&commit, repo, &commit_id)); - git_oid_fromstr(&parent_id, "efad0b11c47cb2f0220cbd6f5b0f93bb99064b00"); + git_oid__fromstr(&parent_id, "efad0b11c47cb2f0220cbd6f5b0f93bb99064b00", GIT_OID_SHA1); cl_assert_equal_i(1, git_commit_parentcount(commit)); cl_assert_equal_oid(&parent_id, git_commit_parent_id(commit, 0)); - git_oid_fromstr(&tree_id, "4461379789c777d2a6c1f2ee0e9d6c86731b9992"); + git_oid__fromstr(&tree_id, "4461379789c777d2a6c1f2ee0e9d6c86731b9992", GIT_OID_SHA1); cl_assert_equal_oid(&tree_id, git_commit_tree_id(commit)); cl_assert_equal_s(NULL, git_commit_message_encoding(commit)); @@ -551,8 +551,8 @@ void test_rebase_merge__finish_with_ids(void) const git_reflog_entry *reflog_entry; int error; - cl_git_pass(git_oid_fromstr(&branch_id, "d616d97082eb7bb2dc6f180a7cca940993b7a56f")); - cl_git_pass(git_oid_fromstr(&upstream_id, "f87d14a4a236582a0278a916340a793714256864")); + cl_git_pass(git_oid__fromstr(&branch_id, "d616d97082eb7bb2dc6f180a7cca940993b7a56f", GIT_OID_SHA1)); + cl_git_pass(git_oid__fromstr(&upstream_id, "f87d14a4a236582a0278a916340a793714256864", GIT_OID_SHA1)); cl_git_pass(git_annotated_commit_lookup(&branch_head, repo, &branch_id)); cl_git_pass(git_annotated_commit_lookup(&upstream_head, repo, &upstream_id)); @@ -627,7 +627,7 @@ void test_rebase_merge__no_common_ancestor(void) cl_git_pass(git_rebase_finish(rebase, signature)); - git_oid_fromstr(&expected_final_id, "71e7ee8d4fe7d8bf0d107355197e0a953dfdb7f3"); + git_oid__fromstr(&expected_final_id, "71e7ee8d4fe7d8bf0d107355197e0a953dfdb7f3", GIT_OID_SHA1); cl_assert_equal_oid(&expected_final_id, &commit_id); git_annotated_commit_free(branch_head); @@ -823,7 +823,7 @@ void test_rebase_merge__with_directories(void) git_oid commit_id, tree_id; git_commit *commit; - git_oid_fromstr(&tree_id, "a4d6d9c3d57308fd8e320cf2525bae8f1adafa57"); + git_oid__fromstr(&tree_id, "a4d6d9c3d57308fd8e320cf2525bae8f1adafa57", GIT_OID_SHA1); cl_git_pass(git_reference_lookup(&branch_ref, repo, "refs/heads/deep_gravy")); cl_git_pass(git_reference_lookup(&upstream_ref, repo, "refs/heads/veal")); diff --git a/tests/libgit2/rebase/setup.c b/tests/libgit2/rebase/setup.c index 34d5edbf6..ac0d087ea 100644 --- a/tests/libgit2/rebase/setup.c +++ b/tests/libgit2/rebase/setup.c @@ -74,7 +74,7 @@ void test_rebase_setup__merge(void) cl_assert_equal_i(GIT_REPOSITORY_STATE_REBASE_MERGE, git_repository_state(repo)); - git_oid_fromstr(&head_id, "efad0b11c47cb2f0220cbd6f5b0f93bb99064b00"); + git_oid__fromstr(&head_id, "efad0b11c47cb2f0220cbd6f5b0f93bb99064b00", GIT_OID_SHA1); cl_git_pass(git_repository_head(&head, repo)); cl_git_pass(git_reference_peel((git_object **)&head_commit, head, GIT_OBJECT_COMMIT)); cl_assert_equal_oid(&head_id, git_commit_id(head_commit)); @@ -120,7 +120,7 @@ void test_rebase_setup__merge_root(void) cl_git_pass(git_rebase_init(&rebase, repo, branch_head, NULL, onto_head, NULL)); - git_oid_fromstr(&head_id, "efad0b11c47cb2f0220cbd6f5b0f93bb99064b00"); + git_oid__fromstr(&head_id, "efad0b11c47cb2f0220cbd6f5b0f93bb99064b00", GIT_OID_SHA1); cl_git_pass(git_repository_head(&head, repo)); cl_git_pass(git_reference_peel((git_object **)&head_commit, head, GIT_OBJECT_COMMIT)); cl_assert_equal_oid(&head_id, git_commit_id(head_commit)); @@ -170,7 +170,7 @@ void test_rebase_setup__merge_onto_and_upstream(void) cl_git_pass(git_rebase_init(&rebase, repo, branch1_head, branch2_head, onto_head, NULL)); - git_oid_fromstr(&head_id, "efad0b11c47cb2f0220cbd6f5b0f93bb99064b00"); + git_oid__fromstr(&head_id, "efad0b11c47cb2f0220cbd6f5b0f93bb99064b00", GIT_OID_SHA1); cl_git_pass(git_repository_head(&head, repo)); cl_git_pass(git_reference_peel((git_object **)&head_commit, head, GIT_OBJECT_COMMIT)); cl_assert_equal_oid(&head_id, git_commit_id(head_commit)); @@ -224,7 +224,7 @@ void test_rebase_setup__merge_onto_upstream_and_branch(void) cl_git_pass(git_rebase_init(&rebase, repo, branch_head, upstream_head, onto_head, NULL)); - git_oid_fromstr(&head_id, "efad0b11c47cb2f0220cbd6f5b0f93bb99064b00"); + git_oid__fromstr(&head_id, "efad0b11c47cb2f0220cbd6f5b0f93bb99064b00", GIT_OID_SHA1); cl_git_pass(git_repository_head(&head, repo)); cl_git_pass(git_reference_peel((git_object **)&head_commit, head, GIT_OBJECT_COMMIT)); cl_assert_equal_oid(&head_id, git_commit_id(head_commit)); @@ -272,9 +272,9 @@ void test_rebase_setup__merge_onto_upstream_and_branch_by_id(void) cl_git_pass(git_repository_set_head(repo, "refs/heads/beef")); cl_git_pass(git_checkout_head(repo, &checkout_opts)); - cl_git_pass(git_oid_fromstr(&upstream_id, "f87d14a4a236582a0278a916340a793714256864")); - cl_git_pass(git_oid_fromstr(&branch_id, "d616d97082eb7bb2dc6f180a7cca940993b7a56f")); - cl_git_pass(git_oid_fromstr(&onto_id, "efad0b11c47cb2f0220cbd6f5b0f93bb99064b00")); + cl_git_pass(git_oid__fromstr(&upstream_id, "f87d14a4a236582a0278a916340a793714256864", GIT_OID_SHA1)); + cl_git_pass(git_oid__fromstr(&branch_id, "d616d97082eb7bb2dc6f180a7cca940993b7a56f", GIT_OID_SHA1)); + cl_git_pass(git_oid__fromstr(&onto_id, "efad0b11c47cb2f0220cbd6f5b0f93bb99064b00", GIT_OID_SHA1)); cl_git_pass(git_annotated_commit_lookup(&upstream_head, repo, &upstream_id)); cl_git_pass(git_annotated_commit_lookup(&branch_head, repo, &branch_id)); @@ -282,7 +282,7 @@ void test_rebase_setup__merge_onto_upstream_and_branch_by_id(void) cl_git_pass(git_rebase_init(&rebase, repo, branch_head, upstream_head, onto_head, NULL)); - git_oid_fromstr(&head_id, "efad0b11c47cb2f0220cbd6f5b0f93bb99064b00"); + git_oid__fromstr(&head_id, "efad0b11c47cb2f0220cbd6f5b0f93bb99064b00", GIT_OID_SHA1); cl_git_pass(git_repository_head(&head, repo)); cl_git_pass(git_reference_peel((git_object **)&head_commit, head, GIT_OBJECT_COMMIT)); cl_assert_equal_oid(&head_id, git_commit_id(head_commit)); @@ -328,7 +328,7 @@ void test_rebase_setup__branch_with_merges(void) cl_assert_equal_i(GIT_REPOSITORY_STATE_REBASE_MERGE, git_repository_state(repo)); - git_oid_fromstr(&head_id, "efad0b11c47cb2f0220cbd6f5b0f93bb99064b00"); + git_oid__fromstr(&head_id, "efad0b11c47cb2f0220cbd6f5b0f93bb99064b00", GIT_OID_SHA1); cl_git_pass(git_repository_head(&head, repo)); cl_git_pass(git_reference_peel((git_object **)&head_commit, head, GIT_OBJECT_COMMIT)); cl_assert_equal_oid(&head_id, git_commit_id(head_commit)); @@ -376,7 +376,7 @@ void test_rebase_setup__orphan_branch(void) cl_assert_equal_i(GIT_REPOSITORY_STATE_REBASE_MERGE, git_repository_state(repo)); - git_oid_fromstr(&head_id, "efad0b11c47cb2f0220cbd6f5b0f93bb99064b00"); + git_oid__fromstr(&head_id, "efad0b11c47cb2f0220cbd6f5b0f93bb99064b00", GIT_OID_SHA1); cl_git_pass(git_repository_head(&head, repo)); cl_git_pass(git_reference_peel((git_object **)&head_commit, head, GIT_OBJECT_COMMIT)); cl_assert_equal_oid(&head_id, git_commit_id(head_commit)); @@ -427,7 +427,7 @@ void test_rebase_setup__merge_null_branch_uses_HEAD(void) cl_assert_equal_i(GIT_REPOSITORY_STATE_REBASE_MERGE, git_repository_state(repo)); - git_oid_fromstr(&head_id, "efad0b11c47cb2f0220cbd6f5b0f93bb99064b00"); + git_oid__fromstr(&head_id, "efad0b11c47cb2f0220cbd6f5b0f93bb99064b00", GIT_OID_SHA1); cl_git_pass(git_repository_head(&head, repo)); cl_git_pass(git_reference_peel((git_object **)&head_commit, head, GIT_OBJECT_COMMIT)); cl_assert_equal_oid(&head_id, git_commit_id(head_commit)); @@ -465,7 +465,7 @@ void test_rebase_setup__merge_from_detached(void) cl_git_pass(git_reference_lookup(&upstream_ref, repo, "refs/heads/master")); - cl_git_pass(git_oid_fromstr(&branch_id, "b146bd7608eac53d9bf9e1a6963543588b555c64")); + cl_git_pass(git_oid__fromstr(&branch_id, "b146bd7608eac53d9bf9e1a6963543588b555c64", GIT_OID_SHA1)); cl_git_pass(git_annotated_commit_lookup(&branch_head, repo, &branch_id)); cl_git_pass(git_annotated_commit_from_ref(&upstream_head, repo, upstream_ref)); @@ -474,7 +474,7 @@ void test_rebase_setup__merge_from_detached(void) cl_assert_equal_i(GIT_REPOSITORY_STATE_REBASE_MERGE, git_repository_state(repo)); - git_oid_fromstr(&head_id, "efad0b11c47cb2f0220cbd6f5b0f93bb99064b00"); + git_oid__fromstr(&head_id, "efad0b11c47cb2f0220cbd6f5b0f93bb99064b00", GIT_OID_SHA1); cl_git_pass(git_repository_head(&head, repo)); cl_git_pass(git_reference_peel((git_object **)&head_commit, head, GIT_OBJECT_COMMIT)); cl_assert_equal_oid(&head_id, git_commit_id(head_commit)); @@ -513,7 +513,7 @@ void test_rebase_setup__merge_branch_by_id(void) cl_git_pass(git_reference_lookup(&branch_ref, repo, "refs/heads/beef")); - cl_git_pass(git_oid_fromstr(&upstream_id, "efad0b11c47cb2f0220cbd6f5b0f93bb99064b00")); + cl_git_pass(git_oid__fromstr(&upstream_id, "efad0b11c47cb2f0220cbd6f5b0f93bb99064b00", GIT_OID_SHA1)); cl_git_pass(git_annotated_commit_from_ref(&branch_head, repo, branch_ref)); cl_git_pass(git_annotated_commit_lookup(&upstream_head, repo, &upstream_id)); @@ -522,7 +522,7 @@ void test_rebase_setup__merge_branch_by_id(void) cl_assert_equal_i(GIT_REPOSITORY_STATE_REBASE_MERGE, git_repository_state(repo)); - git_oid_fromstr(&head_id, "efad0b11c47cb2f0220cbd6f5b0f93bb99064b00"); + git_oid__fromstr(&head_id, "efad0b11c47cb2f0220cbd6f5b0f93bb99064b00", GIT_OID_SHA1); cl_git_pass(git_repository_head(&head, repo)); cl_git_pass(git_reference_peel((git_object **)&head_commit, head, GIT_OBJECT_COMMIT)); cl_assert_equal_oid(&head_id, git_commit_id(head_commit)); diff --git a/tests/libgit2/rebase/sign.c b/tests/libgit2/rebase/sign.c index 4064cf79b..69bb1c6f9 100644 --- a/tests/libgit2/rebase/sign.c +++ b/tests/libgit2/rebase/sign.c @@ -70,7 +70,7 @@ committer Rebaser 1405694510 +0000\n"; cl_git_pass(git_rebase_next(&rebase_operation, rebase)); cl_git_pass(git_rebase_commit(&commit_id, rebase, NULL, signature, NULL, NULL)); - git_oid_fromstr(&expected_id, "129183968a65abd6c52da35bff43325001bfc630"); + git_oid__fromstr(&expected_id, "129183968a65abd6c52da35bff43325001bfc630", GIT_OID_SHA1); cl_assert_equal_oid(&expected_id, &commit_id); cl_git_pass(git_commit_lookup(&commit, repo, &commit_id)); @@ -178,7 +178,7 @@ gpgsig -----BEGIN PGP SIGNATURE-----\n\ cl_git_pass(git_rebase_next(&rebase_operation, rebase)); cl_git_pass(git_rebase_commit(&commit_id, rebase, NULL, signature, NULL, NULL)); - git_oid_fromstr(&expected_id, "bf78348e45c8286f52b760f1db15cb6da030f2ef"); + git_oid__fromstr(&expected_id, "bf78348e45c8286f52b760f1db15cb6da030f2ef", GIT_OID_SHA1); cl_assert_equal_oid(&expected_id, &commit_id); cl_git_pass(git_commit_lookup(&commit, repo, &commit_id)); @@ -300,7 +300,7 @@ committer Rebaser 1405694510 +0000\n"; cl_git_pass(git_rebase_next(&rebase_operation, rebase)); cl_git_pass(git_rebase_commit(&commit_id, rebase, NULL, signature, NULL, NULL)); - git_oid_fromstr(&expected_id, "129183968a65abd6c52da35bff43325001bfc630"); + git_oid__fromstr(&expected_id, "129183968a65abd6c52da35bff43325001bfc630", GIT_OID_SHA1); cl_assert_equal_oid(&expected_id, &commit_id); cl_git_pass(git_commit_lookup(&commit, repo, &commit_id)); @@ -398,7 +398,7 @@ gpgsig -----BEGIN PGP SIGNATURE-----\n\ cl_git_pass(git_rebase_next(&rebase_operation, rebase)); cl_git_pass(git_rebase_commit(&commit_id, rebase, NULL, signature, NULL, NULL)); - git_oid_fromstr(&expected_id, "bf78348e45c8286f52b760f1db15cb6da030f2ef"); + git_oid__fromstr(&expected_id, "bf78348e45c8286f52b760f1db15cb6da030f2ef", GIT_OID_SHA1); cl_assert_equal_oid(&expected_id, &commit_id); cl_git_pass(git_commit_lookup(&commit, repo, &commit_id)); @@ -473,7 +473,7 @@ magicsig magic word: pretty please\n"; cl_git_pass(git_rebase_next(&rebase_operation, rebase)); cl_git_pass(git_rebase_commit(&commit_id, rebase, NULL, signature, NULL, NULL)); - git_oid_fromstr(&expected_id, "f46a4a8d26ae411b02aa61b7d69576627f4a1e1c"); + git_oid__fromstr(&expected_id, "f46a4a8d26ae411b02aa61b7d69576627f4a1e1c", GIT_OID_SHA1); cl_assert_equal_oid(&expected_id, &commit_id); cl_git_pass(git_commit_lookup(&commit, repo, &commit_id)); diff --git a/tests/libgit2/refs/basic.c b/tests/libgit2/refs/basic.c index 32742f9cc..5e41ca074 100644 --- a/tests/libgit2/refs/basic.c +++ b/tests/libgit2/refs/basic.c @@ -53,7 +53,7 @@ void test_refs_basic__longpaths(void) git_reference *one = NULL, *two = NULL; git_oid id; - cl_git_pass(git_oid_fromstr(&id, "099fabac3a9ea935598528c27f866e34089c2eff")); + cl_git_pass(git_oid__fromstr(&id, "099fabac3a9ea935598528c27f866e34089c2eff", GIT_OID_SHA1)); base = git_repository_path(g_repo); base_len = git_utf8_char_length(base, strlen(base)); diff --git a/tests/libgit2/refs/branches/delete.c b/tests/libgit2/refs/branches/delete.c index 27995f9e2..6b3d507a8 100644 --- a/tests/libgit2/refs/branches/delete.c +++ b/tests/libgit2/refs/branches/delete.c @@ -14,7 +14,7 @@ void test_refs_branches_delete__initialize(void) repo = cl_git_sandbox_init("testrepo.git"); - cl_git_pass(git_oid_fromstr(&id, "be3563ae3f795b2b4353bcce3a527ad0a4f7f644")); + cl_git_pass(git_oid__fromstr(&id, "be3563ae3f795b2b4353bcce3a527ad0a4f7f644", GIT_OID_SHA1)); cl_git_pass(git_reference_create(&fake_remote, repo, "refs/remotes/nulltoken/master", &id, 0, NULL)); } @@ -119,7 +119,7 @@ void test_refs_branches_delete__removes_reflog(void) { git_reference *branch; git_reflog *log; - git_oid oidzero = {{0}}; + git_oid oidzero = GIT_OID_SHA1_ZERO; git_signature *sig; /* Ensure the reflog has at least one entry */ @@ -150,14 +150,14 @@ void test_refs_branches_delete__removes_empty_folders(void) git_reference *branch; git_reflog *log; - git_oid oidzero = {{0}}; + git_oid oidzero = GIT_OID_SHA1_ZERO; git_signature *sig; git_str ref_folder = GIT_STR_INIT; git_str reflog_folder = GIT_STR_INIT; /* Create a new branch with a nested name */ - cl_git_pass(git_oid_fromstr(&commit_id, "a65fedf39aefe402d3bb6e24df4d4f5fe4547750")); + cl_git_pass(git_oid__fromstr(&commit_id, "a65fedf39aefe402d3bb6e24df4d4f5fe4547750", GIT_OID_SHA1)); cl_git_pass(git_commit_lookup(&commit, repo, &commit_id)); cl_git_pass(git_branch_create(&branch, repo, "some/deep/ref", commit, 0)); git_commit_free(commit); diff --git a/tests/libgit2/refs/branches/iterator.c b/tests/libgit2/refs/branches/iterator.c index e086681e5..a295d553b 100644 --- a/tests/libgit2/refs/branches/iterator.c +++ b/tests/libgit2/refs/branches/iterator.c @@ -11,7 +11,7 @@ void test_refs_branches_iterator__initialize(void) cl_fixture_sandbox("testrepo.git"); cl_git_pass(git_repository_open(&repo, "testrepo.git")); - cl_git_pass(git_oid_fromstr(&id, "be3563ae3f795b2b4353bcce3a527ad0a4f7f644")); + cl_git_pass(git_oid__fromstr(&id, "be3563ae3f795b2b4353bcce3a527ad0a4f7f644", GIT_OID_SHA1)); cl_git_pass(git_reference_create(&fake_remote, repo, "refs/remotes/nulltoken/master", &id, 0, NULL)); } diff --git a/tests/libgit2/refs/create.c b/tests/libgit2/refs/create.c index 01eb62a52..1dafcf61a 100644 --- a/tests/libgit2/refs/create.c +++ b/tests/libgit2/refs/create.c @@ -34,7 +34,7 @@ void test_refs_create__symbolic(void) const char *new_head_tracker = "ANOTHER_HEAD_TRACKER"; - git_oid_fromstr(&id, current_master_tip); + git_oid__fromstr(&id, current_master_tip, GIT_OID_SHA1); /* Create and write the new symbolic reference */ cl_git_pass(git_reference_symbolic_create(&new_reference, g_repo, new_head_tracker, current_head_target, 0, NULL)); @@ -77,7 +77,7 @@ void test_refs_create__symbolic_with_arbitrary_content(void) const char *new_head_tracker = "ANOTHER_HEAD_TRACKER"; const char *arbitrary_target = "ARBITRARY DATA"; - git_oid_fromstr(&id, current_master_tip); + git_oid__fromstr(&id, current_master_tip, GIT_OID_SHA1); /* Attempt to create symbolic ref with arbitrary data in target * fails by default @@ -124,7 +124,7 @@ void test_refs_create__deep_symbolic(void) const char *new_head_tracker = "deep/rooted/tracker"; - git_oid_fromstr(&id, current_master_tip); + git_oid__fromstr(&id, current_master_tip, GIT_OID_SHA1); cl_git_pass(git_reference_symbolic_create(&new_reference, g_repo, new_head_tracker, current_head_target, 0, NULL)); cl_git_pass(git_reference_lookup(&looked_up_ref, g_repo, new_head_tracker)); @@ -145,7 +145,7 @@ void test_refs_create__oid(void) const char *new_head = "refs/heads/new-head"; - git_oid_fromstr(&id, current_master_tip); + git_oid__fromstr(&id, current_master_tip, GIT_OID_SHA1); /* Create and write the new object id reference */ cl_git_pass(git_reference_create(&new_reference, g_repo, new_head, &id, 0, NULL)); @@ -180,7 +180,7 @@ void test_refs_create__oid_unknown_succeeds_without_strict(void) const char *new_head = "refs/heads/new-head"; - git_oid_fromstr(&id, "deadbeef3f795b2b4353bcce3a527ad0a4f7f644"); + git_oid__fromstr(&id, "deadbeef3f795b2b4353bcce3a527ad0a4f7f644", GIT_OID_SHA1); cl_git_pass(git_libgit2_opts(GIT_OPT_ENABLE_STRICT_OBJECT_CREATION, 0)); @@ -201,7 +201,7 @@ void test_refs_create__oid_unknown_fails_by_default(void) const char *new_head = "refs/heads/new-head"; - git_oid_fromstr(&id, "deadbeef3f795b2b4353bcce3a527ad0a4f7f644"); + git_oid__fromstr(&id, "deadbeef3f795b2b4353bcce3a527ad0a4f7f644", GIT_OID_SHA1); /* Create and write the new object id reference */ cl_git_fail(git_reference_create(&new_reference, g_repo, new_head, &id, 0, NULL)); @@ -215,7 +215,7 @@ void test_refs_create__propagate_eexists(void) git_oid oid; /* Make sure it works for oid and for symbolic both */ - cl_git_pass(git_oid_fromstr(&oid, current_master_tip)); + cl_git_pass(git_oid__fromstr(&oid, current_master_tip, GIT_OID_SHA1)); cl_git_fail_with(GIT_EEXISTS, git_reference_create(NULL, g_repo, current_head_target, &oid, false, NULL)); cl_git_fail_with(GIT_EEXISTS, git_reference_symbolic_create(NULL, g_repo, "HEAD", current_head_target, false, NULL)); } @@ -227,7 +227,7 @@ void test_refs_create__existing_dir_propagates_edirectory(void) const char *dir_head = "refs/heads/new-dir/new-head", *fail_head = "refs/heads/new-dir"; - git_oid_fromstr(&id, current_master_tip); + git_oid__fromstr(&id, current_master_tip, GIT_OID_SHA1); /* Create and write the new object id reference */ cl_git_pass(git_reference_create(&new_reference, g_repo, dir_head, &id, 1, NULL)); @@ -242,7 +242,7 @@ static void test_invalid_name(const char *name) git_reference *new_reference; git_oid id; - git_oid_fromstr(&id, current_master_tip); + git_oid__fromstr(&id, current_master_tip, GIT_OID_SHA1); cl_assert_equal_i(GIT_EINVALIDSPEC, git_reference_create( &new_reference, g_repo, name, &id, 0, NULL)); @@ -272,7 +272,7 @@ static void test_win32_name(const char *name) git_oid id; int ret; - git_oid_fromstr(&id, current_master_tip); + git_oid__fromstr(&id, current_master_tip, GIT_OID_SHA1); ret = git_reference_create(&new_reference, g_repo, name, &id, 0, NULL); @@ -314,7 +314,7 @@ static void count_fsyncs(size_t *create_count, size_t *compress_count) p_fsync__cnt = 0; - git_oid_fromstr(&id, current_master_tip); + git_oid__fromstr(&id, current_master_tip, GIT_OID_SHA1); cl_git_pass(git_reference_create(&ref, g_repo, "refs/heads/fsync_test", &id, 0, "log message")); git_reference_free(ref); diff --git a/tests/libgit2/refs/delete.c b/tests/libgit2/refs/delete.c index 42cc534b5..edb521f4a 100644 --- a/tests/libgit2/refs/delete.c +++ b/tests/libgit2/refs/delete.c @@ -63,7 +63,7 @@ void test_refs_delete__packed_only(void) git_oid id; const char *new_ref = "refs/heads/new_ref"; - git_oid_fromstr(&id, current_master_tip); + git_oid__fromstr(&id, current_master_tip, GIT_OID_SHA1); /* Create and write the new object id reference */ cl_git_pass(git_reference_create(&ref, g_repo, new_ref, &id, 0, NULL)); diff --git a/tests/libgit2/refs/foreachglob.c b/tests/libgit2/refs/foreachglob.c index b208a95a2..a586ca08c 100644 --- a/tests/libgit2/refs/foreachglob.c +++ b/tests/libgit2/refs/foreachglob.c @@ -11,7 +11,7 @@ void test_refs_foreachglob__initialize(void) cl_fixture_sandbox("testrepo.git"); cl_git_pass(git_repository_open(&repo, "testrepo.git")); - cl_git_pass(git_oid_fromstr(&id, "be3563ae3f795b2b4353bcce3a527ad0a4f7f644")); + cl_git_pass(git_oid__fromstr(&id, "be3563ae3f795b2b4353bcce3a527ad0a4f7f644", GIT_OID_SHA1)); cl_git_pass(git_reference_create(&fake_remote, repo, "refs/remotes/nulltoken/master", &id, 0, NULL)); } diff --git a/tests/libgit2/refs/iterator.c b/tests/libgit2/refs/iterator.c index a4f9e62ec..f40d35d11 100644 --- a/tests/libgit2/refs/iterator.c +++ b/tests/libgit2/refs/iterator.c @@ -1,6 +1,7 @@ #include "clar_libgit2.h" #include "refs.h" #include "vector.h" +#include "odb.h" static git_repository *repo; @@ -126,7 +127,7 @@ void test_refs_iterator__empty(void) git_reference *ref; git_repository *empty; - cl_git_pass(git_odb_new(&odb)); + cl_git_pass(git_odb__new(&odb, NULL)); cl_git_pass(git_repository_wrap_odb(&empty, odb)); cl_git_pass(git_reference_iterator_new(&iter, empty)); diff --git a/tests/libgit2/refs/lookup.c b/tests/libgit2/refs/lookup.c index 01e956de2..2b8be77f8 100644 --- a/tests/libgit2/refs/lookup.c +++ b/tests/libgit2/refs/lookup.c @@ -43,7 +43,7 @@ void test_refs_lookup__oid(void) git_oid tag, expected; cl_git_pass(git_reference_name_to_id(&tag, g_repo, "refs/tags/point_to_blob")); - cl_git_pass(git_oid_fromstr(&expected, "1385f264afb75a56a5bec74243be9b367ba4ca08")); + cl_git_pass(git_oid__fromstr(&expected, "1385f264afb75a56a5bec74243be9b367ba4ca08", GIT_OID_SHA1)); cl_assert_equal_oid(&expected, &tag); } diff --git a/tests/libgit2/refs/peel.c b/tests/libgit2/refs/peel.c index 38f3465a0..fefd2d260 100644 --- a/tests/libgit2/refs/peel.c +++ b/tests/libgit2/refs/peel.c @@ -32,7 +32,7 @@ static void assert_peel_generic( cl_git_pass(git_reference_peel(&peeled, ref, requested_type)); - cl_git_pass(git_oid_fromstr(&expected_oid, expected_sha)); + cl_git_pass(git_oid__fromstr(&expected_oid, expected_sha, GIT_OID_SHA1)); cl_assert_equal_oid(&expected_oid, git_object_id(peeled)); cl_assert_equal_i(expected_type, git_object_type(peeled)); diff --git a/tests/libgit2/refs/races.c b/tests/libgit2/refs/races.c index 476789358..bf46b760e 100644 --- a/tests/libgit2/refs/races.c +++ b/tests/libgit2/refs/races.c @@ -27,8 +27,8 @@ void test_refs_races__create_matching_zero_old(void) git_reference *ref; git_oid id, zero_id; - git_oid_fromstr(&id, commit_id); - git_oid_fromstr(&zero_id, "0000000000000000000000000000000000000000"); + git_oid__fromstr(&id, commit_id, GIT_OID_SHA1); + git_oid__fromstr(&zero_id, "0000000000000000000000000000000000000000", GIT_OID_SHA1); cl_git_fail(git_reference_create_matching(&ref, g_repo, refname, &id, 1, &zero_id, NULL)); git_reference_free(ref); @@ -45,8 +45,8 @@ void test_refs_races__create_matching(void) git_reference *ref, *ref2, *ref3; git_oid id, other_id; - git_oid_fromstr(&id, commit_id); - git_oid_fromstr(&other_id, other_commit_id); + git_oid__fromstr(&id, commit_id, GIT_OID_SHA1); + git_oid__fromstr(&other_id, other_commit_id, GIT_OID_SHA1); cl_git_fail_with(GIT_EMODIFIED, git_reference_create_matching(&ref, g_repo, refname, &other_id, 1, &other_id, NULL)); @@ -64,8 +64,8 @@ void test_refs_races__symbolic_create_matching(void) git_reference *ref, *ref2, *ref3; git_oid id, other_id; - git_oid_fromstr(&id, commit_id); - git_oid_fromstr(&other_id, other_commit_id); + git_oid__fromstr(&id, commit_id, GIT_OID_SHA1); + git_oid__fromstr(&other_id, other_commit_id, GIT_OID_SHA1); cl_git_fail_with(GIT_EMODIFIED, git_reference_symbolic_create_matching(&ref, g_repo, "HEAD", other_refname, 1, other_refname, NULL)); @@ -83,8 +83,8 @@ void test_refs_races__delete(void) git_reference *ref, *ref2; git_oid id, other_id; - git_oid_fromstr(&id, commit_id); - git_oid_fromstr(&other_id, other_commit_id); + git_oid__fromstr(&id, commit_id, GIT_OID_SHA1); + git_oid__fromstr(&other_id, other_commit_id, GIT_OID_SHA1); /* We can delete a value that matches */ cl_git_pass(git_reference_lookup(&ref, g_repo, refname)); @@ -116,8 +116,8 @@ void test_refs_races__switch_oid_to_symbolic(void) git_reference *ref, *ref2, *ref3; git_oid id, other_id; - git_oid_fromstr(&id, commit_id); - git_oid_fromstr(&other_id, other_commit_id); + git_oid__fromstr(&id, commit_id, GIT_OID_SHA1); + git_oid__fromstr(&other_id, other_commit_id, GIT_OID_SHA1); /* Removing a direct ref when it's currently symbolic should fail */ cl_git_pass(git_reference_lookup(&ref, g_repo, refname)); @@ -145,8 +145,8 @@ void test_refs_races__switch_symbolic_to_oid(void) git_reference *ref, *ref2, *ref3; git_oid id, other_id; - git_oid_fromstr(&id, commit_id); - git_oid_fromstr(&other_id, other_commit_id); + git_oid__fromstr(&id, commit_id, GIT_OID_SHA1); + git_oid__fromstr(&other_id, other_commit_id, GIT_OID_SHA1); /* Removing a symbolic ref when it's currently direct should fail */ cl_git_pass(git_reference_lookup(&ref, g_repo, "refs/symref")); diff --git a/tests/libgit2/refs/read.c b/tests/libgit2/refs/read.c index a622c770b..7253cf137 100644 --- a/tests/libgit2/refs/read.c +++ b/tests/libgit2/refs/read.c @@ -82,7 +82,7 @@ void test_refs_read__symbolic(void) cl_assert(object != NULL); cl_assert(git_object_type(object) == GIT_OBJECT_COMMIT); - git_oid_fromstr(&id, current_master_tip); + git_oid__fromstr(&id, current_master_tip, GIT_OID_SHA1); cl_assert_equal_oid(&id, git_object_id(object)); git_object_free(object); @@ -110,7 +110,7 @@ void test_refs_read__nested_symbolic(void) cl_assert(object != NULL); cl_assert(git_object_type(object) == GIT_OBJECT_COMMIT); - git_oid_fromstr(&id, current_master_tip); + git_oid__fromstr(&id, current_master_tip, GIT_OID_SHA1); cl_assert_equal_oid(&id, git_object_id(object)); git_object_free(object); diff --git a/tests/libgit2/refs/reflog/drop.c b/tests/libgit2/refs/reflog/drop.c index 916bd9933..2d7193380 100644 --- a/tests/libgit2/refs/reflog/drop.c +++ b/tests/libgit2/refs/reflog/drop.c @@ -70,7 +70,7 @@ void test_refs_reflog_drop__can_drop_the_oldest_entry(void) cl_assert_equal_sz(entrycount - 1, git_reflog_entrycount(g_reflog)); entry = git_reflog_entry_byindex(g_reflog, entrycount - 2); - cl_assert(git_oid_streq(&entry->oid_old, GIT_OID_HEX_ZERO) != 0); + cl_assert(git_oid_streq(&entry->oid_old, GIT_OID_SHA1_HEXZERO) != 0); } void test_refs_reflog_drop__can_drop_the_oldest_entry_and_rewrite_the_log_history(void) @@ -83,7 +83,7 @@ void test_refs_reflog_drop__can_drop_the_oldest_entry_and_rewrite_the_log_histor cl_assert_equal_sz(entrycount - 1, git_reflog_entrycount(g_reflog)); entry = git_reflog_entry_byindex(g_reflog, entrycount - 2); - cl_assert(git_oid_streq(&entry->oid_old, GIT_OID_HEX_ZERO) == 0); + cl_assert(git_oid_streq(&entry->oid_old, GIT_OID_SHA1_HEXZERO) == 0); } void test_refs_reflog_drop__can_drop_all_the_entries(void) diff --git a/tests/libgit2/refs/reflog/messages.c b/tests/libgit2/refs/reflog/messages.c index ed183d2f2..647c00d0d 100644 --- a/tests/libgit2/refs/reflog/messages.c +++ b/tests/libgit2/refs/reflog/messages.c @@ -87,7 +87,7 @@ void test_refs_reflog_messages__detaching_writes_reflog(void) const char *msg; msg = "checkout: moving from master to e90810b8df3e80c413d903f631643c716887138d"; - git_oid_fromstr(&id, "e90810b8df3e80c413d903f631643c716887138d"); + git_oid__fromstr(&id, "e90810b8df3e80c413d903f631643c716887138d", GIT_OID_SHA1); cl_git_pass(git_repository_set_head_detached(g_repo, &id)); cl_reflog_check_entry(g_repo, GIT_HEAD_FILE, 0, "a65fedf39aefe402d3bb6e24df4d4f5fe4547750", @@ -109,7 +109,7 @@ void test_refs_reflog_messages__orphan_branch_does_not_count(void) /* Have something known */ msg = "checkout: moving from master to e90810b8df3e80c413d903f631643c716887138d"; - git_oid_fromstr(&id, "e90810b8df3e80c413d903f631643c716887138d"); + git_oid__fromstr(&id, "e90810b8df3e80c413d903f631643c716887138d", GIT_OID_SHA1); cl_git_pass(git_repository_set_head_detached(g_repo, &id)); cl_reflog_check_entry(g_repo, GIT_HEAD_FILE, 0, "a65fedf39aefe402d3bb6e24df4d4f5fe4547750", @@ -264,7 +264,7 @@ void test_refs_reflog_messages__creating_a_direct_reference(void) cl_assert_equal_sz(1, git_reflog_entrycount(reflog)); entry = git_reflog_entry_byindex(reflog, 0); - cl_assert(git_oid_streq(&entry->oid_old, GIT_OID_HEX_ZERO) == 0); + cl_assert(git_oid_streq(&entry->oid_old, GIT_OID_SHA1_HEXZERO) == 0); cl_assert_equal_oid(&id, &entry->oid_cur); cl_assert_equal_s(message, entry->msg); @@ -280,7 +280,7 @@ void test_refs_reflog_messages__newline_gets_replaced(void) git_oid oid; cl_git_pass(git_signature_now(&signature, "me", "foo@example.com")); - cl_git_pass(git_oid_fromstr(&oid, "a65fedf39aefe402d3bb6e24df4d4f5fe4547750")); + cl_git_pass(git_oid__fromstr(&oid, "a65fedf39aefe402d3bb6e24df4d4f5fe4547750", GIT_OID_SHA1)); cl_git_pass(git_reflog_read(&reflog, g_repo, "HEAD")); cl_assert_equal_sz(7, git_reflog_entrycount(reflog)); @@ -352,7 +352,7 @@ void test_refs_reflog_messages__creating_branches_default_messages(void) cl_git_pass(git_str_printf(&buf, "branch: Created from %s", git_oid_tostr_s(git_commit_id(target)))); cl_reflog_check_entry(g_repo, "refs/heads/" NEW_BRANCH_NAME, 0, - GIT_OID_HEX_ZERO, + GIT_OID_SHA1_HEXZERO, git_oid_tostr_s(git_commit_id(target)), g_email, git_str_cstr(&buf)); @@ -362,7 +362,7 @@ void test_refs_reflog_messages__creating_branches_default_messages(void) cl_git_pass(git_branch_create_from_annotated(&branch2, g_repo, NEW_BRANCH_NAME, annotated, true)); cl_reflog_check_entry(g_repo, "refs/heads/" NEW_BRANCH_NAME, 0, - GIT_OID_HEX_ZERO, + GIT_OID_SHA1_HEXZERO, git_oid_tostr_s(git_commit_id(target)), g_email, "branch: Created from e90810b8df3"); diff --git a/tests/libgit2/refs/reflog/reflog.c b/tests/libgit2/refs/reflog/reflog.c index 32ce7ffb7..774ec6c93 100644 --- a/tests/libgit2/refs/reflog/reflog.c +++ b/tests/libgit2/refs/reflog/reflog.c @@ -52,7 +52,7 @@ static void assert_appends(const git_signature *committer, const git_oid *oid) /* The first one was the creation of the branch */ entry = git_reflog_entry_byindex(reflog, 2); - cl_assert(git_oid_streq(&entry->oid_old, GIT_OID_HEX_ZERO) == 0); + cl_assert(git_oid_streq(&entry->oid_old, GIT_OID_SHA1_HEXZERO) == 0); entry = git_reflog_entry_byindex(reflog, 1); assert_signature(committer, entry->committer); @@ -80,7 +80,7 @@ void test_refs_reflog_reflog__append_then_read(void) git_reflog *reflog; /* Create a new branch pointing at the HEAD */ - git_oid_fromstr(&oid, current_master_tip); + git_oid__fromstr(&oid, current_master_tip, GIT_OID_SHA1); cl_git_pass(git_reference_create(&ref, g_repo, new_ref, &oid, 0, NULL)); git_reference_free(ref); @@ -147,7 +147,7 @@ void test_refs_reflog_reflog__removes_empty_reflog_dir(void) git_oid id; /* Create a new branch pointing at the HEAD */ - git_oid_fromstr(&id, current_master_tip); + git_oid__fromstr(&id, current_master_tip, GIT_OID_SHA1); cl_git_pass(git_reference_create(&ref, g_repo, "refs/heads/new-dir/new-head", &id, 0, NULL)); git_str_joinpath(&log_path, git_repository_path(g_repo), GIT_REFLOG_DIR); @@ -159,7 +159,7 @@ void test_refs_reflog_reflog__removes_empty_reflog_dir(void) git_reference_free(ref); /* new ref creation should succeed since new-dir is empty */ - git_oid_fromstr(&id, current_master_tip); + git_oid__fromstr(&id, current_master_tip, GIT_OID_SHA1); cl_git_pass(git_reference_create(&ref, g_repo, "refs/heads/new-dir", &id, 0, NULL)); git_reference_free(ref); @@ -173,7 +173,7 @@ void test_refs_reflog_reflog__fails_gracefully_on_nonempty_reflog_dir(void) git_oid id; /* Create a new branch pointing at the HEAD */ - git_oid_fromstr(&id, current_master_tip); + git_oid__fromstr(&id, current_master_tip, GIT_OID_SHA1); cl_git_pass(git_reference_create(&ref, g_repo, "refs/heads/new-dir/new-head", &id, 0, NULL)); git_reference_free(ref); @@ -186,7 +186,7 @@ void test_refs_reflog_reflog__fails_gracefully_on_nonempty_reflog_dir(void) cl_must_pass(p_unlink("testrepo.git/refs/heads/new-dir/new-head")); /* new ref creation should fail since new-dir contains reflogs still */ - git_oid_fromstr(&id, current_master_tip); + git_oid__fromstr(&id, current_master_tip, GIT_OID_SHA1); cl_git_fail_with(GIT_EDIRECTORY, git_reference_create(&ref, g_repo, "refs/heads/new-dir", &id, 0, NULL)); git_reference_free(ref); @@ -235,7 +235,7 @@ void test_refs_reflog_reflog__reading_a_reflog_with_invalid_format_succeeds(void char *star; /* Create a new branch. */ - cl_git_pass(git_oid_fromstr(&id, current_master_tip)); + cl_git_pass(git_oid__fromstr(&id, current_master_tip, GIT_OID_SHA1)); cl_git_pass(git_reference_create(&ref, g_repo, refname, &id, 1, refmessage)); /* @@ -298,7 +298,7 @@ void test_refs_reflog_reflog__write_only_std_locations(void) git_reference *ref; git_oid id; - git_oid_fromstr(&id, current_master_tip); + git_oid__fromstr(&id, current_master_tip, GIT_OID_SHA1); cl_git_pass(git_reference_create(&ref, g_repo, "refs/heads/foo", &id, 1, NULL)); git_reference_free(ref); @@ -318,7 +318,7 @@ void test_refs_reflog_reflog__write_when_explicitly_active(void) git_reference *ref; git_oid id; - git_oid_fromstr(&id, current_master_tip); + git_oid__fromstr(&id, current_master_tip, GIT_OID_SHA1); git_reference_ensure_log(g_repo, "refs/tags/foo"); cl_git_pass(git_reference_create(&ref, g_repo, "refs/tags/foo", &id, 1, NULL)); @@ -338,7 +338,7 @@ void test_refs_reflog_reflog__append_to_HEAD_when_changing_current_branch(void) git_reflog_free(log); /* Move it back */ - git_oid_fromstr(&id, "be3563ae3f795b2b4353bcce3a527ad0a4f7f644"); + git_oid__fromstr(&id, "be3563ae3f795b2b4353bcce3a527ad0a4f7f644", GIT_OID_SHA1); cl_git_pass(git_reference_create(&ref, g_repo, "refs/heads/master", &id, 1, NULL)); git_reference_free(ref); @@ -390,7 +390,7 @@ static void assert_no_reflog_update(void) git_reflog_free(log); /* Move it back */ - git_oid_fromstr(&id, "be3563ae3f795b2b4353bcce3a527ad0a4f7f644"); + git_oid__fromstr(&id, "be3563ae3f795b2b4353bcce3a527ad0a4f7f644", GIT_OID_SHA1); cl_git_pass(git_reference_create(&ref, g_repo, "refs/heads/master", &id, 1, NULL)); git_reference_free(ref); @@ -431,7 +431,7 @@ void test_refs_reflog_reflog__logallrefupdates_bare_set_always(void) cl_git_pass(git_config_set_string(config, "core.logallrefupdates", "always")); git_config_free(config); - git_oid_fromstr(&id, "be3563ae3f795b2b4353bcce3a527ad0a4f7f644"); + git_oid__fromstr(&id, "be3563ae3f795b2b4353bcce3a527ad0a4f7f644", GIT_OID_SHA1); cl_git_pass(git_reference_create(&ref, g_repo, "refs/bork", &id, 1, "message")); cl_git_pass(git_reflog_read(&log, g_repo, "refs/bork")); diff --git a/tests/libgit2/refs/reflog/reflog_helpers.c b/tests/libgit2/refs/reflog/reflog_helpers.c index 2ea41ee06..6a7e706d6 100644 --- a/tests/libgit2/refs/reflog/reflog_helpers.c +++ b/tests/libgit2/refs/reflog/reflog_helpers.c @@ -6,12 +6,12 @@ int reflog_entry_tostr(git_str *out, const git_reflog_entry *entry) { - char old_oid[GIT_OID_HEXSZ], new_oid[GIT_OID_HEXSZ]; + char old_oid[GIT_OID_SHA1_HEXSIZE], new_oid[GIT_OID_SHA1_HEXSIZE]; assert(out && entry); - git_oid_tostr((char *)&old_oid, GIT_OID_HEXSZ, git_reflog_entry_id_old(entry)); - git_oid_tostr((char *)&new_oid, GIT_OID_HEXSZ, git_reflog_entry_id_new(entry)); + git_oid_tostr((char *)&old_oid, GIT_OID_SHA1_HEXSIZE, git_reflog_entry_id_old(entry)); + git_oid_tostr((char *)&new_oid, GIT_OID_SHA1_HEXSIZE, git_reflog_entry_id_new(entry)); return git_str_printf(out, "%s %s %s %s", old_oid, new_oid, "somesig", git_reflog_entry_message(entry)); } @@ -46,17 +46,17 @@ void cl_reflog_check_entry_(git_repository *repo, const char *reflog, size_t idx git_object *obj = NULL; if (git_revparse_single(&obj, repo, old_spec) == GIT_OK) { if (git_oid_cmp(git_object_id(obj), git_reflog_entry_id_old(entry)) != 0) { - git_oid__writebuf(&result, "\tOld OID: \"", git_object_id(obj)); - git_oid__writebuf(&result, "\" != \"", git_reflog_entry_id_old(entry)); + git_object__write_oid_header(&result, "\tOld OID: \"", git_object_id(obj)); + git_object__write_oid_header(&result, "\" != \"", git_reflog_entry_id_old(entry)); git_str_puts(&result, "\"\n"); } git_object_free(obj); } else { git_oid *oid = git__calloc(1, sizeof(*oid)); - git_oid_fromstr(oid, old_spec); + git_oid__fromstr(oid, old_spec, GIT_OID_SHA1); if (git_oid_cmp(oid, git_reflog_entry_id_old(entry)) != 0) { - git_oid__writebuf(&result, "\tOld OID: \"", oid); - git_oid__writebuf(&result, "\" != \"", git_reflog_entry_id_old(entry)); + git_object__write_oid_header(&result, "\tOld OID: \"", oid); + git_object__write_oid_header(&result, "\" != \"", git_reflog_entry_id_old(entry)); git_str_puts(&result, "\"\n"); } git__free(oid); @@ -66,17 +66,17 @@ void cl_reflog_check_entry_(git_repository *repo, const char *reflog, size_t idx git_object *obj = NULL; if (git_revparse_single(&obj, repo, new_spec) == GIT_OK) { if (git_oid_cmp(git_object_id(obj), git_reflog_entry_id_new(entry)) != 0) { - git_oid__writebuf(&result, "\tNew OID: \"", git_object_id(obj)); - git_oid__writebuf(&result, "\" != \"", git_reflog_entry_id_new(entry)); + git_object__write_oid_header(&result, "\tNew OID: \"", git_object_id(obj)); + git_object__write_oid_header(&result, "\" != \"", git_reflog_entry_id_new(entry)); git_str_puts(&result, "\"\n"); } git_object_free(obj); } else { git_oid *oid = git__calloc(1, sizeof(*oid)); - git_oid_fromstr(oid, new_spec); + git_oid__fromstr(oid, new_spec, GIT_OID_SHA1); if (git_oid_cmp(oid, git_reflog_entry_id_new(entry)) != 0) { - git_oid__writebuf(&result, "\tNew OID: \"", oid); - git_oid__writebuf(&result, "\" != \"", git_reflog_entry_id_new(entry)); + git_object__write_oid_header(&result, "\tNew OID: \"", oid); + git_object__write_oid_header(&result, "\" != \"", git_reflog_entry_id_new(entry)); git_str_puts(&result, "\"\n"); } git__free(oid); diff --git a/tests/libgit2/refs/revparse.c b/tests/libgit2/refs/revparse.c index 56af3c939..d2f464840 100644 --- a/tests/libgit2/refs/revparse.c +++ b/tests/libgit2/refs/revparse.c @@ -304,6 +304,9 @@ void test_refs_revparse__ordinal(void) test_object("@{0}", "a65fedf39aefe402d3bb6e24df4d4f5fe4547750"); test_object("@{1}", "be3563ae3f795b2b4353bcce3a527ad0a4f7f644"); + test_object("HEAD@{0}", "a65fedf39aefe402d3bb6e24df4d4f5fe4547750"); + test_object("HEAD@{4}", "5b5b025afb0b4c913b4c338a42934a3863bf3644"); + test_object("master@{0}", "a65fedf39aefe402d3bb6e24df4d4f5fe4547750"); test_object("master@{1}", "be3563ae3f795b2b4353bcce3a527ad0a4f7f644"); test_object("heads/master@{1}", "be3563ae3f795b2b4353bcce3a527ad0a4f7f644"); @@ -652,7 +655,7 @@ void test_refs_revparse__try_to_retrieve_branch_before_described_tag(void) git_repository *repo; git_reference *branch; git_object *target; - char sha[GIT_OID_HEXSZ + 1]; + char sha[GIT_OID_SHA1_HEXSIZE + 1]; repo = cl_git_sandbox_init("testrepo.git"); @@ -661,7 +664,7 @@ void test_refs_revparse__try_to_retrieve_branch_before_described_tag(void) cl_git_pass(git_revparse_single(&target, repo, "HEAD~3")); cl_git_pass(git_branch_create(&branch, repo, "blah-7-gc47800c", (git_commit *)target, 0)); - git_oid_tostr(sha, GIT_OID_HEXSZ + 1, git_object_id(target)); + git_oid_tostr(sha, GIT_OID_SHA1_HEXSIZE + 1, git_object_id(target)); test_object_inrepo("blah-7-gc47800c", sha, repo); @@ -690,7 +693,7 @@ void test_refs_revparse__try_to_retrieve_sha_before_branch(void) git_repository *repo; git_reference *branch; git_object *target; - char sha[GIT_OID_HEXSZ + 1]; + char sha[GIT_OID_SHA1_HEXSIZE + 1]; repo = cl_git_sandbox_init("testrepo.git"); @@ -699,7 +702,7 @@ void test_refs_revparse__try_to_retrieve_sha_before_branch(void) cl_git_pass(git_revparse_single(&target, repo, "HEAD~3")); cl_git_pass(git_branch_create(&branch, repo, "a65fedf39aefe402d3bb6e24df4d4f5fe4547750", (git_commit *)target, 0)); - git_oid_tostr(sha, GIT_OID_HEXSZ + 1, git_object_id(target)); + git_oid_tostr(sha, GIT_OID_SHA1_HEXSIZE + 1, git_object_id(target)); test_object_inrepo("a65fedf39aefe402d3bb6e24df4d4f5fe4547750", "a65fedf39aefe402d3bb6e24df4d4f5fe4547750", repo); test_object_inrepo("heads/a65fedf39aefe402d3bb6e24df4d4f5fe4547750", sha, repo); @@ -726,7 +729,7 @@ void test_refs_revparse__try_to_retrieve_branch_before_abbrev_sha(void) git_repository *repo; git_reference *branch; git_object *target; - char sha[GIT_OID_HEXSZ + 1]; + char sha[GIT_OID_SHA1_HEXSIZE + 1]; repo = cl_git_sandbox_init("testrepo.git"); @@ -735,7 +738,7 @@ void test_refs_revparse__try_to_retrieve_branch_before_abbrev_sha(void) cl_git_pass(git_revparse_single(&target, repo, "HEAD~3")); cl_git_pass(git_branch_create(&branch, repo, "c47800", (git_commit *)target, 0)); - git_oid_tostr(sha, GIT_OID_HEXSZ + 1, git_object_id(target)); + git_oid_tostr(sha, GIT_OID_SHA1_HEXSIZE + 1, git_object_id(target)); test_object_inrepo("c47800", sha, repo); diff --git a/tests/libgit2/refs/transactions.c b/tests/libgit2/refs/transactions.c index 50c102ad0..98ae6f73a 100644 --- a/tests/libgit2/refs/transactions.c +++ b/tests/libgit2/refs/transactions.c @@ -21,7 +21,7 @@ void test_refs_transactions__single_ref_oid(void) git_reference *ref; git_oid id; - git_oid_fromstr(&id, "a65fedf39aefe402d3bb6e24df4d4f5fe4547750"); + git_oid__fromstr(&id, "a65fedf39aefe402d3bb6e24df4d4f5fe4547750", GIT_OID_SHA1); cl_git_pass(git_transaction_lock_ref(g_tx, "refs/heads/master")); cl_git_pass(git_transaction_set_target(g_tx, "refs/heads/master", &id, NULL, NULL)); @@ -52,7 +52,7 @@ void test_refs_transactions__single_ref_mix_types(void) git_reference *ref; git_oid id; - git_oid_fromstr(&id, "a65fedf39aefe402d3bb6e24df4d4f5fe4547750"); + git_oid__fromstr(&id, "a65fedf39aefe402d3bb6e24df4d4f5fe4547750", GIT_OID_SHA1); cl_git_pass(git_transaction_lock_ref(g_tx, "refs/heads/master")); cl_git_pass(git_transaction_lock_ref(g_tx, "HEAD")); @@ -90,7 +90,7 @@ void test_refs_transactions__single_create(void) cl_git_pass(git_transaction_lock_ref(g_tx, name)); - git_oid_fromstr(&id, "a65fedf39aefe402d3bb6e24df4d4f5fe4547750"); + git_oid__fromstr(&id, "a65fedf39aefe402d3bb6e24df4d4f5fe4547750", GIT_OID_SHA1); cl_git_pass(git_transaction_set_target(g_tx, name, &id, NULL, NULL)); cl_git_pass(git_transaction_commit(g_tx)); @@ -104,7 +104,7 @@ void test_refs_transactions__unlocked_set(void) git_oid id; cl_git_pass(git_transaction_lock_ref(g_tx, "refs/heads/master")); - git_oid_fromstr(&id, "a65fedf39aefe402d3bb6e24df4d4f5fe4547750"); + git_oid__fromstr(&id, "a65fedf39aefe402d3bb6e24df4d4f5fe4547750", GIT_OID_SHA1); cl_git_fail_with(GIT_ENOTFOUND, git_transaction_set_target(g_tx, "refs/heads/foo", &id, NULL, NULL)); cl_git_pass(git_transaction_commit(g_tx)); } @@ -122,7 +122,7 @@ void test_refs_transactions__error_on_locking_locked_ref(void) cl_git_pass(git_transaction_lock_ref(g_tx_with_lock, "refs/heads/master")); /* lock reference for set_target */ - cl_git_pass(git_oid_fromstr(&id, "a65fedf39aefe402d3bb6e24df4d4f5fe4547750")); + cl_git_pass(git_oid__fromstr(&id, "a65fedf39aefe402d3bb6e24df4d4f5fe4547750", GIT_OID_SHA1)); cl_git_fail_with(GIT_ELOCKED, git_transaction_lock_ref(g_tx, "refs/heads/master")); cl_git_fail_with(GIT_ENOTFOUND, git_transaction_set_target(g_tx, "refs/heads/master", &id, NULL, NULL)); diff --git a/tests/libgit2/remote/httpproxy.c b/tests/libgit2/remote/httpproxy.c index f62a2545b..60fc67dec 100644 --- a/tests/libgit2/remote/httpproxy.c +++ b/tests/libgit2/remote/httpproxy.c @@ -6,7 +6,6 @@ static git_repository *repo; static git_net_url url = GIT_NET_URL_INIT; -static int orig_proxies_need_reset = 0; static char *orig_http_proxy = NULL; static char *orig_https_proxy = NULL; static char *orig_no_proxy = NULL; @@ -21,20 +20,25 @@ void test_remote_httpproxy__initialize(void) git_remote_free(remote); - orig_proxies_need_reset = 0; + /* Clear everything for a fresh start */ + orig_http_proxy = cl_getenv("HTTP_PROXY"); + orig_https_proxy = cl_getenv("HTTPS_PROXY"); + orig_no_proxy = cl_getenv("NO_PROXY"); + + cl_setenv("HTTP_PROXY", NULL); + cl_setenv("HTTPS_PROXY", NULL); + cl_setenv("NO_PROXY", NULL); } void test_remote_httpproxy__cleanup(void) { - if (orig_proxies_need_reset) { - cl_setenv("HTTP_PROXY", orig_http_proxy); - cl_setenv("HTTPS_PROXY", orig_https_proxy); - cl_setenv("NO_PROXY", orig_no_proxy); + cl_setenv("HTTP_PROXY", orig_http_proxy); + cl_setenv("HTTPS_PROXY", orig_https_proxy); + cl_setenv("NO_PROXY", orig_no_proxy); - git__free(orig_http_proxy); - git__free(orig_https_proxy); - git__free(orig_no_proxy); - } + git__free(orig_http_proxy); + git__free(orig_https_proxy); + git__free(orig_no_proxy); git_net_url_dispose(&url); cl_git_sandbox_cleanup(); @@ -132,7 +136,7 @@ static void assert_global_config_match(const char *config, const char *expected) void test_remote_httpproxy__config_overrides_detached_remote(void) { - cl_fake_home(); + cl_fake_globalconfig(NULL); assert_global_config_match(NULL, NULL); assert_global_config_match("http.proxy", "http://localhost:1/"); @@ -141,22 +145,10 @@ void test_remote_httpproxy__config_overrides_detached_remote(void) assert_global_config_match("http.https://github.com/libgit2.proxy", "http://localhost:4/"); assert_global_config_match("http.https://github.com/libgit2/.proxy", "http://localhost:5/"); assert_global_config_match("http.https://github.com/libgit2/libgit2.proxy", "http://localhost:6/"); - - cl_git_pass(git_futils_rmdir_r("home", NULL, GIT_RMDIR_REMOVE_FILES)); } void test_remote_httpproxy__env(void) { - orig_http_proxy = cl_getenv("HTTP_PROXY"); - orig_https_proxy = cl_getenv("HTTPS_PROXY"); - orig_no_proxy = cl_getenv("NO_PROXY"); - orig_proxies_need_reset = 1; - - /* Clear everything for a fresh start */ - cl_setenv("HTTP_PROXY", NULL); - cl_setenv("HTTPS_PROXY", NULL); - cl_setenv("NO_PROXY", NULL); - /* HTTP proxy is ignored for HTTPS */ cl_setenv("HTTP_PROXY", "http://localhost:9/"); assert_proxy_is(NULL); diff --git a/tests/libgit2/repo/env.c b/tests/libgit2/repo/env.c index e3e522480..790ffd40f 100644 --- a/tests/libgit2/repo/env.c +++ b/tests/libgit2/repo/env.c @@ -95,9 +95,9 @@ static void env_check_objects_(bool a, bool t, bool p, const char *file, const c git_repository *repo; git_oid oid_a, oid_t, oid_p; git_object *object; - cl_git_pass(git_oid_fromstr(&oid_a, "45141a79a77842c59a63229403220a4e4be74e3d")); - cl_git_pass(git_oid_fromstr(&oid_t, "1385f264afb75a56a5bec74243be9b367ba4ca08")); - cl_git_pass(git_oid_fromstr(&oid_p, "0df1a5865c8abfc09f1f2182e6a31be550e99f07")); + cl_git_pass(git_oid__fromstr(&oid_a, "45141a79a77842c59a63229403220a4e4be74e3d", GIT_OID_SHA1)); + cl_git_pass(git_oid__fromstr(&oid_t, "1385f264afb75a56a5bec74243be9b367ba4ca08", GIT_OID_SHA1)); + cl_git_pass(git_oid__fromstr(&oid_p, "0df1a5865c8abfc09f1f2182e6a31be550e99f07", GIT_OID_SHA1)); cl_git_expect(git_repository_open_ext(&repo, "attr", GIT_REPOSITORY_OPEN_FROM_ENV, NULL), 0, file, func, line); if (a) { diff --git a/tests/libgit2/repo/extensions.c b/tests/libgit2/repo/extensions.c index e7772acd5..105cdae12 100644 --- a/tests/libgit2/repo/extensions.c +++ b/tests/libgit2/repo/extensions.c @@ -3,7 +3,7 @@ #include "sysdir.h" #include -git_repository *repo; +static git_repository *repo; void test_repo_extensions__initialize(void) { diff --git a/tests/libgit2/repo/hashfile.c b/tests/libgit2/repo/hashfile.c index e23bb77f9..f053cb950 100644 --- a/tests/libgit2/repo/hashfile.c +++ b/tests/libgit2/repo/hashfile.c @@ -1,4 +1,5 @@ #include "clar_libgit2.h" +#include "odb.h" static git_repository *_repo; @@ -20,19 +21,19 @@ void test_repo_hashfile__simple(void) git_str full = GIT_STR_INIT; /* hash with repo relative path */ - cl_git_pass(git_odb_hashfile(&a, "status/current_file", GIT_OBJECT_BLOB)); + cl_git_pass(git_odb__hashfile(&a, "status/current_file", GIT_OBJECT_BLOB, GIT_OID_SHA1)); cl_git_pass(git_repository_hashfile(&b, _repo, "current_file", GIT_OBJECT_BLOB, NULL)); cl_assert_equal_oid(&a, &b); cl_git_pass(git_str_joinpath(&full, git_repository_workdir(_repo), "current_file")); /* hash with full path */ - cl_git_pass(git_odb_hashfile(&a, full.ptr, GIT_OBJECT_BLOB)); + cl_git_pass(git_odb__hashfile(&a, full.ptr, GIT_OBJECT_BLOB, GIT_OID_SHA1)); cl_git_pass(git_repository_hashfile(&b, _repo, full.ptr, GIT_OBJECT_BLOB, NULL)); cl_assert_equal_oid(&a, &b); /* hash with invalid type */ - cl_git_fail(git_odb_hashfile(&a, full.ptr, GIT_OBJECT_ANY)); + cl_git_fail(git_odb__hashfile(&a, full.ptr, GIT_OBJECT_ANY, GIT_OID_SHA1)); cl_git_fail(git_repository_hashfile(&b, _repo, full.ptr, GIT_OBJECT_OFS_DELTA, NULL)); git_str_dispose(&full); @@ -59,64 +60,64 @@ void test_repo_hashfile__filtered_in_workdir(void) cl_git_mkfile("status/testfile.bin", "other\r\nstuff\r\n"); /* not equal hashes because of filtering */ - cl_git_pass(git_odb_hashfile(&a, "status/testfile.txt", GIT_OBJECT_BLOB)); + cl_git_pass(git_odb__hashfile(&a, "status/testfile.txt", GIT_OBJECT_BLOB, GIT_OID_SHA1)); cl_git_pass(git_repository_hashfile(&b, _repo, "testfile.txt", GIT_OBJECT_BLOB, NULL)); cl_assert(git_oid_cmp(&a, &b)); /* not equal hashes because of filtering when specified by absolute path */ - cl_git_pass(git_odb_hashfile(&a, "status/testfile.txt", GIT_OBJECT_BLOB)); + cl_git_pass(git_odb__hashfile(&a, "status/testfile.txt", GIT_OBJECT_BLOB, GIT_OID_SHA1)); cl_git_pass(git_repository_hashfile(&b, _repo, txt.ptr, GIT_OBJECT_BLOB, NULL)); cl_assert(git_oid_cmp(&a, &b)); /* equal hashes because filter is binary */ - cl_git_pass(git_odb_hashfile(&a, "status/testfile.bin", GIT_OBJECT_BLOB)); + cl_git_pass(git_odb__hashfile(&a, "status/testfile.bin", GIT_OBJECT_BLOB, GIT_OID_SHA1)); cl_git_pass(git_repository_hashfile(&b, _repo, "testfile.bin", GIT_OBJECT_BLOB, NULL)); cl_assert_equal_oid(&a, &b); /* equal hashes because filter is binary when specified by absolute path */ - cl_git_pass(git_odb_hashfile(&a, "status/testfile.bin", GIT_OBJECT_BLOB)); + cl_git_pass(git_odb__hashfile(&a, "status/testfile.bin", GIT_OBJECT_BLOB, GIT_OID_SHA1)); cl_git_pass(git_repository_hashfile(&b, _repo, bin.ptr, GIT_OBJECT_BLOB, NULL)); cl_assert_equal_oid(&a, &b); /* equal hashes when 'as_file' points to binary filtering */ - cl_git_pass(git_odb_hashfile(&a, "status/testfile.txt", GIT_OBJECT_BLOB)); + cl_git_pass(git_odb__hashfile(&a, "status/testfile.txt", GIT_OBJECT_BLOB, GIT_OID_SHA1)); cl_git_pass(git_repository_hashfile(&b, _repo, "testfile.txt", GIT_OBJECT_BLOB, "foo.bin")); cl_assert_equal_oid(&a, &b); /* equal hashes when 'as_file' points to binary filtering (absolute path) */ - cl_git_pass(git_odb_hashfile(&a, "status/testfile.txt", GIT_OBJECT_BLOB)); + cl_git_pass(git_odb__hashfile(&a, "status/testfile.txt", GIT_OBJECT_BLOB, GIT_OID_SHA1)); cl_git_pass(git_repository_hashfile(&b, _repo, txt.ptr, GIT_OBJECT_BLOB, "foo.bin")); cl_assert_equal_oid(&a, &b); /* not equal hashes when 'as_file' points to text filtering */ - cl_git_pass(git_odb_hashfile(&a, "status/testfile.bin", GIT_OBJECT_BLOB)); + cl_git_pass(git_odb__hashfile(&a, "status/testfile.bin", GIT_OBJECT_BLOB, GIT_OID_SHA1)); cl_git_pass(git_repository_hashfile(&b, _repo, "testfile.bin", GIT_OBJECT_BLOB, "foo.txt")); cl_assert(git_oid_cmp(&a, &b)); /* not equal hashes when 'as_file' points to text filtering */ - cl_git_pass(git_odb_hashfile(&a, "status/testfile.bin", GIT_OBJECT_BLOB)); + cl_git_pass(git_odb__hashfile(&a, "status/testfile.bin", GIT_OBJECT_BLOB, GIT_OID_SHA1)); cl_git_pass(git_repository_hashfile(&b, _repo, bin.ptr, GIT_OBJECT_BLOB, "foo.txt")); cl_assert(git_oid_cmp(&a, &b)); /* equal hashes when 'as_file' is empty and turns off filtering */ - cl_git_pass(git_odb_hashfile(&a, "status/testfile.txt", GIT_OBJECT_BLOB)); + cl_git_pass(git_odb__hashfile(&a, "status/testfile.txt", GIT_OBJECT_BLOB, GIT_OID_SHA1)); cl_git_pass(git_repository_hashfile(&b, _repo, "testfile.txt", GIT_OBJECT_BLOB, "")); cl_assert_equal_oid(&a, &b); - cl_git_pass(git_odb_hashfile(&a, "status/testfile.bin", GIT_OBJECT_BLOB)); + cl_git_pass(git_odb__hashfile(&a, "status/testfile.bin", GIT_OBJECT_BLOB, GIT_OID_SHA1)); cl_git_pass(git_repository_hashfile(&b, _repo, "testfile.bin", GIT_OBJECT_BLOB, "")); cl_assert_equal_oid(&a, &b); - cl_git_pass(git_odb_hashfile(&a, "status/testfile.txt", GIT_OBJECT_BLOB)); + cl_git_pass(git_odb__hashfile(&a, "status/testfile.txt", GIT_OBJECT_BLOB, GIT_OID_SHA1)); cl_git_pass(git_repository_hashfile(&b, _repo, txt.ptr, GIT_OBJECT_BLOB, "")); cl_assert_equal_oid(&a, &b); - cl_git_pass(git_odb_hashfile(&a, "status/testfile.bin", GIT_OBJECT_BLOB)); + cl_git_pass(git_odb__hashfile(&a, "status/testfile.bin", GIT_OBJECT_BLOB, GIT_OID_SHA1)); cl_git_pass(git_repository_hashfile(&b, _repo, bin.ptr, GIT_OBJECT_BLOB, "")); cl_assert_equal_oid(&a, &b); /* some hash type failures */ - cl_git_fail(git_odb_hashfile(&a, "status/testfile.txt", 0)); + cl_git_fail(git_odb__hashfile(&a, "status/testfile.txt", 0, GIT_OID_SHA1)); cl_git_fail(git_repository_hashfile(&b, _repo, "testfile.txt", GIT_OBJECT_ANY, NULL)); git_str_dispose(&txt); @@ -144,12 +145,12 @@ void test_repo_hashfile__filtered_outside_workdir(void) cl_git_mkfile("absolute/testfile.bin", "other\r\nstuff\r\n"); /* not equal hashes because of filtering */ - cl_git_pass(git_odb_hashfile(&a, "absolute/testfile.txt", GIT_OBJECT_BLOB)); + cl_git_pass(git_odb__hashfile(&a, "absolute/testfile.txt", GIT_OBJECT_BLOB, GIT_OID_SHA1)); cl_git_pass(git_repository_hashfile(&b, _repo, txt.ptr, GIT_OBJECT_BLOB, "testfile.txt")); cl_assert(git_oid_cmp(&a, &b)); /* equal hashes because filter is binary */ - cl_git_pass(git_odb_hashfile(&a, "absolute/testfile.bin", GIT_OBJECT_BLOB)); + cl_git_pass(git_odb__hashfile(&a, "absolute/testfile.bin", GIT_OBJECT_BLOB, GIT_OID_SHA1)); cl_git_pass(git_repository_hashfile(&b, _repo, bin.ptr, GIT_OBJECT_BLOB, "testfile.bin")); cl_assert_equal_oid(&a, &b); @@ -157,11 +158,11 @@ void test_repo_hashfile__filtered_outside_workdir(void) * equal hashes because no filtering occurs for absolute paths outside the working * directory unless as_path is specified */ - cl_git_pass(git_odb_hashfile(&a, "absolute/testfile.txt", GIT_OBJECT_BLOB)); + cl_git_pass(git_odb__hashfile(&a, "absolute/testfile.txt", GIT_OBJECT_BLOB, GIT_OID_SHA1)); cl_git_pass(git_repository_hashfile(&b, _repo, txt.ptr, GIT_OBJECT_BLOB, NULL)); cl_assert_equal_oid(&a, &b); - cl_git_pass(git_odb_hashfile(&a, "absolute/testfile.bin", GIT_OBJECT_BLOB)); + cl_git_pass(git_odb__hashfile(&a, "absolute/testfile.bin", GIT_OBJECT_BLOB, GIT_OID_SHA1)); cl_git_pass(git_repository_hashfile(&b, _repo, bin.ptr, GIT_OBJECT_BLOB, NULL)); cl_assert_equal_oid(&a, &b); diff --git a/tests/libgit2/repo/head.c b/tests/libgit2/repo/head.c index 822990555..c886c3f79 100644 --- a/tests/libgit2/repo/head.c +++ b/tests/libgit2/repo/head.c @@ -99,7 +99,7 @@ void test_repo_head__set_head_detached_Return_ENOTFOUND_when_the_object_doesnt_e { git_oid oid; - cl_git_pass(git_oid_fromstr(&oid, "deadbeefdeadbeefdeadbeefdeadbeefdeadbeef")); + cl_git_pass(git_oid__fromstr(&oid, "deadbeefdeadbeefdeadbeefdeadbeefdeadbeef", GIT_OID_SHA1)); cl_assert_equal_i(GIT_ENOTFOUND, git_repository_set_head_detached(repo, &oid)); } diff --git a/tests/libgit2/repo/init.c b/tests/libgit2/repo/init.c index 7cf6742ca..d78ec063c 100644 --- a/tests/libgit2/repo/init.c +++ b/tests/libgit2/repo/init.c @@ -142,30 +142,49 @@ void test_repo_init__reinit_bare_repo(void) cl_git_pass(git_repository_init(&g_repo, "reinit.git", 1)); } -void test_repo_init__reinit_too_recent_bare_repo(void) +void test_repo_init__reinit_nondefault_version(void) { git_config *config; + cl_set_cleanup(&cleanup_repository, "reinit.git"); + /* Initialize the repository */ cl_git_pass(git_repository_init(&g_repo, "reinit.git", 1)); git_repository_config(&config, g_repo); - /* - * Hack the config of the repository to make it look like it has - * been created by a recenter version of git/libgit2 - */ - cl_git_pass(git_config_set_int32(config, "core.repositoryformatversion", 42)); - + /* Set the config to a supported but not default version */ + cl_repo_set_string(g_repo, "core.repositoryformatversion", "1"); git_config_free(config); git_repository_free(g_repo); g_repo = NULL; /* Try to reinitialize the repository */ - cl_git_fail(git_repository_init(&g_repo, "reinit.git", 1)); + cl_git_pass(git_repository_init(&g_repo, "reinit.git", 1)); + cl_assert_equal_i(1, cl_repo_get_int(g_repo, "core.repositoryformatversion")); cl_fixture_cleanup("reinit.git"); } +void test_repo_init__reinit_unsupported_version(void) +{ + cl_set_cleanup(&cleanup_repository, "reinit.git"); + + /* Initialize the repository */ + cl_git_pass(git_repository_init(&g_repo, "reinit.git", 1)); + + /* + * Hack the config of the repository to make it look like it has + * been created by a too new and unsupported version of git/libgit2 + */ + cl_repo_set_string(g_repo, "core.repositoryformatversion", "42"); + git_repository_free(g_repo); + g_repo = NULL; + + /* Try and fail to reinitialize the repository */ + cl_git_fail(git_repository_init(&g_repo, "reinit.git", 1)); + cl_fixture_cleanup("reinit.git"); +} + void test_repo_init__additional_templates(void) { git_str path = GIT_STR_INIT; @@ -708,7 +727,7 @@ void test_repo_init__defaultbranch_config_empty(void) void test_repo_init__longpath(void) { #ifdef GIT_WIN32 - size_t padding = CONST_STRLEN("objects/pack/pack-.pack.lock") + GIT_OID_HEXSZ; + size_t padding = CONST_STRLEN("objects/pack/pack-.pack.lock") + GIT_OID_MAX_HEXSIZE; size_t max, i; git_str path = GIT_STR_INIT; git_repository *one = NULL, *two = NULL; diff --git a/tests/libgit2/repo/objectformat.c b/tests/libgit2/repo/objectformat.c new file mode 100644 index 000000000..d278e10c4 --- /dev/null +++ b/tests/libgit2/repo/objectformat.c @@ -0,0 +1,69 @@ +#include "clar_libgit2.h" +#include "futils.h" +#include "sysdir.h" +#include "repository.h" +#include + +static git_repository *repo; +static git_config *config; + +void test_repo_objectformat__initialize(void) +{ + repo = cl_git_sandbox_init("empty_bare.git"); + + cl_git_pass(git_repository_config(&config, repo)); + cl_git_pass(git_config_set_int32(config, "core.repositoryformatversion", 1)); +} + +void test_repo_objectformat__cleanup(void) +{ + git_config_free(config); + cl_git_sandbox_cleanup(); +} + +void test_repo_objectformat__unspecified(void) +{ + git_repository *other; + + cl_git_pass(git_repository_open(&other, "empty_bare.git")); + cl_assert_equal_i(GIT_OID_SHA1, git_repository_oid_type(other)); + git_repository_free(other); +} + +void test_repo_objectformat__sha1(void) +{ + git_repository *other; + + cl_git_pass(git_config_set_string(config, "extensions.objectformat", "sha1")); + + cl_git_pass(git_repository_open(&other, "empty_bare.git")); + cl_assert_equal_i(GIT_OID_SHA1, git_repository_oid_type(other)); + git_repository_free(other); +} + +void test_repo_objectformat__sha256(void) +{ +#ifndef GIT_EXPERIMENTAL_SHA256 + cl_skip(); +#else + git_repository *other; + + cl_git_pass(git_config_set_string(config, "extensions.objectformat", "sha256")); + + cl_git_pass(git_repository_open(&other, "empty_bare.git")); + cl_assert_equal_i(GIT_OID_SHA256, git_repository_oid_type(other)); + git_repository_free(other); +#endif +} + +void test_repo_objectformat__invalid(void) +{ + git_repository *other; + + cl_git_pass(git_config_set_string(config, "extensions.objectformat", "bogus")); + + cl_git_fail_with(GIT_EINVALID, git_repository_open(&other, "empty_bare.git")); + cl_assert_equal_s("unknown object format 'bogus'", git_error_last()->message); + git_repository_free(other); +} + diff --git a/tests/libgit2/repo/open.c b/tests/libgit2/repo/open.c index 634ba59d2..3d1a0620b 100644 --- a/tests/libgit2/repo/open.c +++ b/tests/libgit2/repo/open.c @@ -410,6 +410,7 @@ void test_repo_open__no_config(void) git_str_dispose(&path); cl_git_pass(git_repository_open(&repo, "empty_standard_repo")); + cl_assert(git_repository_oid_type(repo) == GIT_OID_SHA1); cl_git_pass(git_repository_config(&config, repo)); cl_git_pass(git_config_set_string(config, "test.set", "42")); @@ -433,11 +434,13 @@ void test_repo_open__force_bare(void) cl_git_pass(git_repository_open(&barerepo, "alternate")); cl_assert(!git_repository_is_bare(barerepo)); + cl_assert(git_repository_oid_type(barerepo) == GIT_OID_SHA1); git_repository_free(barerepo); cl_git_pass(git_repository_open_bare( &barerepo, "empty_standard_repo/.git")); cl_assert(git_repository_is_bare(barerepo)); + cl_assert(git_repository_oid_type(barerepo) == GIT_OID_SHA1); git_repository_free(barerepo); cl_git_fail(git_repository_open_bare(&barerepo, "alternate/.git")); @@ -487,7 +490,7 @@ void test_repo_open__validates_dir_ownership(void) /* When the system user owns the repo config, fail */ git_fs_path__set_owner(GIT_FS_PATH_OWNER_ADMINISTRATOR); - cl_git_fail(git_repository_open(&repo, "empty_standard_repo")); + cl_git_fail_with(GIT_EOWNER, git_repository_open(&repo, "empty_standard_repo")); #ifdef GIT_WIN32 /* When the user is an administrator, succeed on Windows. */ @@ -498,7 +501,7 @@ void test_repo_open__validates_dir_ownership(void) /* When an unknown user owns the repo config, fail */ git_fs_path__set_owner(GIT_FS_PATH_OWNER_OTHER); - cl_git_fail(git_repository_open(&repo, "empty_standard_repo")); + cl_git_fail_with(GIT_EOWNER, git_repository_open(&repo, "empty_standard_repo")); } void test_repo_open__validates_bare_repo_ownership(void) @@ -516,7 +519,7 @@ void test_repo_open__validates_bare_repo_ownership(void) /* When the system user owns the repo config, fail */ git_fs_path__set_owner(GIT_FS_PATH_OWNER_ADMINISTRATOR); - cl_git_fail(git_repository_open(&repo, "testrepo.git")); + cl_git_fail_with(GIT_EOWNER, git_repository_open(&repo, "testrepo.git")); #ifdef GIT_WIN32 /* When the user is an administrator, succeed on Windows. */ @@ -527,7 +530,7 @@ void test_repo_open__validates_bare_repo_ownership(void) /* When an unknown user owns the repo config, fail */ git_fs_path__set_owner(GIT_FS_PATH_OWNER_OTHER); - cl_git_fail(git_repository_open(&repo, "testrepo.git")); + cl_git_fail_with(GIT_EOWNER, git_repository_open(&repo, "testrepo.git")); } void test_repo_open__can_allowlist_dirs_with_problematic_ownership(void) @@ -543,7 +546,7 @@ void test_repo_open__can_allowlist_dirs_with_problematic_ownership(void) cl_git_pass(cl_rename("empty_standard_repo/.gitted", "empty_standard_repo/.git")); git_fs_path__set_owner(GIT_FS_PATH_OWNER_OTHER); - cl_git_fail(git_repository_open(&repo, "empty_standard_repo")); + cl_git_fail_with(GIT_EOWNER, git_repository_open(&repo, "empty_standard_repo")); /* Add safe.directory options to the global configuration */ git_str_joinpath(&config_path, clar_sandbox_path(), "__global_config"); @@ -575,6 +578,45 @@ void test_repo_open__can_allowlist_dirs_with_problematic_ownership(void) git_str_dispose(&config_data); } +void test_repo_open__can_wildcard_allowlist_with_problematic_ownership(void) +{ + git_repository *repo; + git_str config_path = GIT_STR_INIT, config_filename = GIT_STR_INIT; + + cl_git_pass(git_libgit2_opts(GIT_OPT_SET_OWNER_VALIDATION, 1)); + + cl_fixture_sandbox("empty_standard_repo"); + cl_git_pass(cl_rename( + "empty_standard_repo/.gitted", "empty_standard_repo/.git")); + + git_fs_path__set_owner(GIT_FS_PATH_OWNER_OTHER); + cl_git_fail_with( + GIT_EOWNER, git_repository_open(&repo, "empty_standard_repo")); + + /* Add safe.directory options to the global configuration */ + git_str_joinpath(&config_path, clar_sandbox_path(), "__global_config"); + cl_must_pass(p_mkdir(config_path.ptr, 0777)); + git_libgit2_opts( + GIT_OPT_SET_SEARCH_PATH, GIT_CONFIG_LEVEL_GLOBAL, + config_path.ptr); + + git_str_joinpath(&config_filename, config_path.ptr, ".gitconfig"); + + cl_git_rewritefile(config_filename.ptr, "[foo]\n" + "\tbar = Foobar\n" + "\tbaz = Baz!\n" + "[safe]\n" + "\tdirectory = *\n" + "[bar]\n" + "\tfoo = barfoo\n"); + + cl_git_pass(git_repository_open(&repo, "empty_standard_repo")); + git_repository_free(repo); + + git_str_dispose(&config_path); + git_str_dispose(&config_filename); +} + void test_repo_open__can_allowlist_bare_gitdir(void) { git_repository *repo; @@ -587,7 +629,7 @@ void test_repo_open__can_allowlist_bare_gitdir(void) cl_fixture_sandbox("testrepo.git"); git_fs_path__set_owner(GIT_FS_PATH_OWNER_OTHER); - cl_git_fail(git_repository_open(&repo, "testrepo.git")); + cl_git_fail_with(GIT_EOWNER, git_repository_open(&repo, "testrepo.git")); /* Add safe.directory options to the global configuration */ git_str_joinpath(&config_path, clar_sandbox_path(), "__global_config"); @@ -619,6 +661,43 @@ void test_repo_open__can_allowlist_bare_gitdir(void) git_str_dispose(&config_data); } +void test_repo_open__can_wildcard_allowlist_bare_gitdir(void) +{ + git_repository *repo; + git_str config_path = GIT_STR_INIT, config_filename = GIT_STR_INIT; + + cl_git_pass(git_libgit2_opts(GIT_OPT_SET_OWNER_VALIDATION, 1)); + + cl_fixture_sandbox("testrepo.git"); + + git_fs_path__set_owner(GIT_FS_PATH_OWNER_OTHER); + cl_git_fail_with( + GIT_EOWNER, git_repository_open(&repo, "testrepo.git")); + + /* Add safe.directory options to the global configuration */ + git_str_joinpath(&config_path, clar_sandbox_path(), "__global_config"); + cl_must_pass(p_mkdir(config_path.ptr, 0777)); + git_libgit2_opts( + GIT_OPT_SET_SEARCH_PATH, GIT_CONFIG_LEVEL_GLOBAL, + config_path.ptr); + + git_str_joinpath(&config_filename, config_path.ptr, ".gitconfig"); + + cl_git_rewritefile(config_filename.ptr, "[foo]\n" + "\tbar = Foobar\n" + "\tbaz = Baz!\n" + "[safe]\n" + "\tdirectory = *\n" + "[bar]\n" + "\tfoo = barfoo\n"); + + cl_git_pass(git_repository_open(&repo, "testrepo.git")); + git_repository_free(repo); + + git_str_dispose(&config_path); + git_str_dispose(&config_filename); +} + void test_repo_open__can_reset_safe_directory_list(void) { git_repository *repo; @@ -632,7 +711,7 @@ void test_repo_open__can_reset_safe_directory_list(void) cl_git_pass(cl_rename("empty_standard_repo/.gitted", "empty_standard_repo/.git")); git_fs_path__set_owner(GIT_FS_PATH_OWNER_OTHER); - cl_git_fail(git_repository_open(&repo, "empty_standard_repo")); + cl_git_fail_with(GIT_EOWNER, git_repository_open(&repo, "empty_standard_repo")); /* Add safe.directory options to the global configuration */ git_str_joinpath(&config_path, clar_sandbox_path(), "__global_config"); @@ -656,7 +735,7 @@ void test_repo_open__can_reset_safe_directory_list(void) clar_sandbox_path(), "empty_standard_repo"); cl_git_rewritefile(config_filename.ptr, config_data.ptr); - cl_git_fail(git_repository_open(&repo, "empty_standard_repo")); + cl_git_fail_with(GIT_EOWNER, git_repository_open(&repo, "empty_standard_repo")); /* The blank resets tmp and allows subsequent declarations to succeed */ diff --git a/tests/libgit2/repo/setters.c b/tests/libgit2/repo/setters.c index 9a965dec6..66ec7706c 100644 --- a/tests/libgit2/repo/setters.c +++ b/tests/libgit2/repo/setters.c @@ -1,6 +1,7 @@ #include "clar_libgit2.h" #include "git2/sys/repository.h" +#include "odb.h" #include "posix.h" #include "util.h" #include "path.h" @@ -90,7 +91,7 @@ void test_repo_setters__setting_a_new_odb_on_a_repo_which_already_loaded_one_pro { git_odb *new_odb; - cl_git_pass(git_odb_open(&new_odb, "./testrepo.git/objects")); + cl_git_pass(git_odb__open(&new_odb, "./testrepo.git/objects", NULL)); cl_assert(((git_refcount *)new_odb)->refcount.val == 1); git_repository_set_odb(repo, new_odb); diff --git a/tests/libgit2/reset/hard.c b/tests/libgit2/reset/hard.c index 9d177c021..0b6342cb2 100644 --- a/tests/libgit2/reset/hard.c +++ b/tests/libgit2/reset/hard.c @@ -122,9 +122,9 @@ static void unmerged_index_init(git_index *index, int entries) int write_theirs = 4; git_oid ancestor, ours, theirs; - git_oid_fromstr(&ancestor, "452e4244b5d083ddf0460acf1ecc74db9dcfa11a"); - git_oid_fromstr(&ours, "32504b727382542f9f089e24fddac5e78533e96c"); - git_oid_fromstr(&theirs, "061d42a44cacde5726057b67558821d95db96f19"); + git_oid__fromstr(&ancestor, "452e4244b5d083ddf0460acf1ecc74db9dcfa11a", GIT_OID_SHA1); + git_oid__fromstr(&ours, "32504b727382542f9f089e24fddac5e78533e96c", GIT_OID_SHA1); + git_oid__fromstr(&theirs, "061d42a44cacde5726057b67558821d95db96f19", GIT_OID_SHA1); cl_git_rewritefile("status/conflicting_file", "conflicting file\n"); diff --git a/tests/libgit2/reset/soft.c b/tests/libgit2/reset/soft.c index aca0834f2..128905021 100644 --- a/tests/libgit2/reset/soft.c +++ b/tests/libgit2/reset/soft.c @@ -53,11 +53,11 @@ void test_reset_soft__can_reset_the_detached_Head_to_the_specified_commit(void) void test_reset_soft__resetting_to_the_commit_pointed_at_by_the_Head_does_not_change_the_target_of_the_Head(void) { git_oid oid; - char raw_head_oid[GIT_OID_HEXSZ + 1]; + char raw_head_oid[GIT_OID_SHA1_HEXSIZE + 1]; cl_git_pass(git_reference_name_to_id(&oid, repo, "HEAD")); git_oid_fmt(raw_head_oid, &oid); - raw_head_oid[GIT_OID_HEXSZ] = '\0'; + raw_head_oid[GIT_OID_SHA1_HEXSIZE] = '\0'; cl_git_pass(git_revparse_single(&target, repo, raw_head_oid)); diff --git a/tests/libgit2/revert/bare.c b/tests/libgit2/revert/bare.c index 9261cfe86..db443024e 100644 --- a/tests/libgit2/revert/bare.c +++ b/tests/libgit2/revert/bare.c @@ -34,10 +34,10 @@ void test_revert_bare__automerge(void) { 0100644, "0f5bfcf58c558d865da6be0281d7795993646cee", 0, "file6.txt" }, }; - git_oid_fromstr(&head_oid, "72333f47d4e83616630ff3b0ffe4c0faebcc3c45"); + git_oid__fromstr(&head_oid, "72333f47d4e83616630ff3b0ffe4c0faebcc3c45", GIT_OID_SHA1); cl_git_pass(git_commit_lookup(&head_commit, repo, &head_oid)); - git_oid_fromstr(&revert_oid, "d1d403d22cbe24592d725f442835cf46fe60c8ac"); + git_oid__fromstr(&revert_oid, "d1d403d22cbe24592d725f442835cf46fe60c8ac", GIT_OID_SHA1); cl_git_pass(git_commit_lookup(&revert_commit, repo, &revert_oid)); cl_git_pass(git_revert_commit(&index, repo, revert_commit, head_commit, 0, NULL)); @@ -64,7 +64,7 @@ void test_revert_bare__conflicts(void) { 0100644, "0f5bfcf58c558d865da6be0281d7795993646cee", 0, "file6.txt" }, }; - git_oid_fromstr(&revert_oid, "72333f47d4e83616630ff3b0ffe4c0faebcc3c45"); + git_oid__fromstr(&revert_oid, "72333f47d4e83616630ff3b0ffe4c0faebcc3c45", GIT_OID_SHA1); cl_git_pass(git_repository_head(&head_ref, repo)); cl_git_pass(git_reference_peel((git_object **)&head_commit, head_ref, GIT_OBJECT_COMMIT)); @@ -91,10 +91,10 @@ void test_revert_bare__orphan(void) { 0100644, "296a6d3be1dff05c5d1f631d2459389fa7b619eb", 0, "file-mainline.txt" }, }; - git_oid_fromstr(&head_oid, "39467716290f6df775a91cdb9a4eb39295018145"); + git_oid__fromstr(&head_oid, "39467716290f6df775a91cdb9a4eb39295018145", GIT_OID_SHA1); cl_git_pass(git_commit_lookup(&head_commit, repo, &head_oid)); - git_oid_fromstr(&revert_oid, "ebb03002cee5d66c7732dd06241119fe72ab96a5"); + git_oid__fromstr(&revert_oid, "ebb03002cee5d66c7732dd06241119fe72ab96a5", GIT_OID_SHA1); cl_git_pass(git_commit_lookup(&revert_commit, repo, &revert_oid)); cl_git_pass(git_revert_commit(&index, repo, revert_commit, head_commit, 0, NULL)); diff --git a/tests/libgit2/revert/rename.c b/tests/libgit2/revert/rename.c index 0d713c60f..be7a98041 100644 --- a/tests/libgit2/revert/rename.c +++ b/tests/libgit2/revert/rename.c @@ -36,7 +36,7 @@ void test_revert_rename__automerge(void) cl_git_pass(git_repository_head(&head_ref, repo)); cl_git_pass(git_reference_peel((git_object **)&head_commit, head_ref, GIT_OBJECT_COMMIT)); - cl_git_pass(git_oid_fromstr(&revert_oid, "7b4d7c3789b3581973c04087cb774c3c3576de2f")); + cl_git_pass(git_oid__fromstr(&revert_oid, "7b4d7c3789b3581973c04087cb774c3c3576de2f", GIT_OID_SHA1)); cl_git_pass(git_commit_lookup(&revert_commit, repo, &revert_oid)); cl_git_pass(git_revert_commit(&index, repo, revert_commit, head_commit, 0, NULL)); diff --git a/tests/libgit2/revert/workdir.c b/tests/libgit2/revert/workdir.c index 3f54280ca..3e790b77f 100644 --- a/tests/libgit2/revert/workdir.c +++ b/tests/libgit2/revert/workdir.c @@ -45,11 +45,11 @@ void test_revert_workdir__automerge(void) { 0100644, "0f5bfcf58c558d865da6be0281d7795993646cee", 0, "file6.txt" }, }; - git_oid_fromstr(&head_oid, "72333f47d4e83616630ff3b0ffe4c0faebcc3c45"); + git_oid__fromstr(&head_oid, "72333f47d4e83616630ff3b0ffe4c0faebcc3c45", GIT_OID_SHA1); cl_git_pass(git_commit_lookup(&head, repo, &head_oid)); cl_git_pass(git_reset(repo, (git_object *)head, GIT_RESET_HARD, NULL)); - git_oid_fromstr(&revert_oid, "d1d403d22cbe24592d725f442835cf46fe60c8ac"); + git_oid__fromstr(&revert_oid, "d1d403d22cbe24592d725f442835cf46fe60c8ac", GIT_OID_SHA1); cl_git_pass(git_commit_lookup(&commit, repo, &revert_oid)); cl_git_pass(git_revert(repo, commit, NULL)); @@ -76,7 +76,7 @@ void test_revert_workdir__conflicts(void) { 0100644, "0f5bfcf58c558d865da6be0281d7795993646cee", 0, "file6.txt" }, }; - git_oid_fromstr(&revert_oid, "72333f47d4e83616630ff3b0ffe4c0faebcc3c45"); + git_oid__fromstr(&revert_oid, "72333f47d4e83616630ff3b0ffe4c0faebcc3c45", GIT_OID_SHA1); cl_git_pass(git_repository_head(&head_ref, repo)); cl_git_pass(git_reference_peel((git_object **)&head, head_ref, GIT_OBJECT_COMMIT)); @@ -141,11 +141,11 @@ void test_revert_workdir__orphan(void) { 0100644, "296a6d3be1dff05c5d1f631d2459389fa7b619eb", 0, "file-mainline.txt" }, }; - git_oid_fromstr(&head_oid, "39467716290f6df775a91cdb9a4eb39295018145"); + git_oid__fromstr(&head_oid, "39467716290f6df775a91cdb9a4eb39295018145", GIT_OID_SHA1); cl_git_pass(git_commit_lookup(&head, repo, &head_oid)); cl_git_pass(git_reset(repo, (git_object *)head, GIT_RESET_HARD, NULL)); - git_oid_fromstr(&revert_oid, "ebb03002cee5d66c7732dd06241119fe72ab96a5"); + git_oid__fromstr(&revert_oid, "ebb03002cee5d66c7732dd06241119fe72ab96a5", GIT_OID_SHA1); cl_git_pass(git_commit_lookup(&commit, repo, &revert_oid)); cl_git_pass(git_revert(repo, commit, NULL)); @@ -224,11 +224,11 @@ void test_revert_workdir__again_after_automerge(void) { 0100644, "0f5bfcf58c558d865da6be0281d7795993646cee", 0, "file6.txt" }, }; - git_oid_fromstr(&head_oid, "72333f47d4e83616630ff3b0ffe4c0faebcc3c45"); + git_oid__fromstr(&head_oid, "72333f47d4e83616630ff3b0ffe4c0faebcc3c45", GIT_OID_SHA1); cl_git_pass(git_commit_lookup(&head, repo, &head_oid)); cl_git_pass(git_reset(repo, (git_object *)head, GIT_RESET_HARD, NULL)); - git_oid_fromstr(&revert_oid, "d1d403d22cbe24592d725f442835cf46fe60c8ac"); + git_oid__fromstr(&revert_oid, "d1d403d22cbe24592d725f442835cf46fe60c8ac", GIT_OID_SHA1); cl_git_pass(git_commit_lookup(&commit, repo, &revert_oid)); cl_git_pass(git_revert(repo, commit, NULL)); @@ -272,11 +272,11 @@ void test_revert_workdir__again_after_edit(void) cl_git_pass(git_repository_head(&head_ref, repo)); - cl_git_pass(git_oid_fromstr(&orig_head_oid, "399fb3aba3d9d13f7d40a9254ce4402067ef3149")); + cl_git_pass(git_oid__fromstr(&orig_head_oid, "399fb3aba3d9d13f7d40a9254ce4402067ef3149", GIT_OID_SHA1)); cl_git_pass(git_commit_lookup(&orig_head, repo, &orig_head_oid)); cl_git_pass(git_reset(repo, (git_object *)orig_head, GIT_RESET_HARD, NULL)); - cl_git_pass(git_oid_fromstr(&revert_oid, "2d440f2b3147d3dc7ad1085813478d6d869d5a4d")); + cl_git_pass(git_oid__fromstr(&revert_oid, "2d440f2b3147d3dc7ad1085813478d6d869d5a4d", GIT_OID_SHA1)); cl_git_pass(git_commit_lookup(&commit, repo, &revert_oid)); cl_git_pass(git_revert(repo, commit, NULL)); @@ -321,11 +321,11 @@ void test_revert_workdir__again_after_edit_two(void) cl_git_pass(git_repository_config(&config, repo)); cl_git_pass(git_config_set_bool(config, "core.autocrlf", 0)); - cl_git_pass(git_oid_fromstr(&head_commit_oid, "75ec9929465623f17ff3ad68c0438ea56faba815")); + cl_git_pass(git_oid__fromstr(&head_commit_oid, "75ec9929465623f17ff3ad68c0438ea56faba815", GIT_OID_SHA1)); cl_git_pass(git_commit_lookup(&head_commit, repo, &head_commit_oid)); cl_git_pass(git_reset(repo, (git_object *)head_commit, GIT_RESET_HARD, NULL)); - cl_git_pass(git_oid_fromstr(&revert_commit_oid, "97e52d5e81f541080cd6b92829fb85bc4d81d90b")); + cl_git_pass(git_oid__fromstr(&revert_commit_oid, "97e52d5e81f541080cd6b92829fb85bc4d81d90b", GIT_OID_SHA1)); cl_git_pass(git_commit_lookup(&revert_commit, repo, &revert_commit_oid)); cl_git_pass(git_revert(repo, revert_commit, NULL)); @@ -376,11 +376,11 @@ void test_revert_workdir__conflict_use_ours(void) opts.checkout_opts.checkout_strategy = GIT_CHECKOUT_SAFE | GIT_CHECKOUT_USE_OURS; - git_oid_fromstr(&head_oid, "72333f47d4e83616630ff3b0ffe4c0faebcc3c45"); + git_oid__fromstr(&head_oid, "72333f47d4e83616630ff3b0ffe4c0faebcc3c45", GIT_OID_SHA1); cl_git_pass(git_commit_lookup(&head, repo, &head_oid)); cl_git_pass(git_reset(repo, (git_object *)head, GIT_RESET_HARD, NULL)); - git_oid_fromstr(&revert_oid, "d1d403d22cbe24592d725f442835cf46fe60c8ac"); + git_oid__fromstr(&revert_oid, "d1d403d22cbe24592d725f442835cf46fe60c8ac", GIT_OID_SHA1); cl_git_pass(git_commit_lookup(&commit, repo, &revert_oid)); cl_git_pass(git_revert(repo, commit, &opts)); @@ -412,11 +412,11 @@ void test_revert_workdir__rename_1_of_2(void) opts.merge_opts.flags |= GIT_MERGE_FIND_RENAMES; opts.merge_opts.rename_threshold = 50; - git_oid_fromstr(&head_oid, "cef56612d71a6af8d8015691e4865f7fece905b5"); + git_oid__fromstr(&head_oid, "cef56612d71a6af8d8015691e4865f7fece905b5", GIT_OID_SHA1); cl_git_pass(git_commit_lookup(&head, repo, &head_oid)); cl_git_pass(git_reset(repo, (git_object *)head, GIT_RESET_HARD, NULL)); - git_oid_fromstr(&revert_oid, "55568c8de5322ff9a95d72747a239cdb64a19965"); + git_oid__fromstr(&revert_oid, "55568c8de5322ff9a95d72747a239cdb64a19965", GIT_OID_SHA1); cl_git_pass(git_commit_lookup(&commit, repo, &revert_oid)); cl_git_pass(git_revert(repo, commit, &opts)); @@ -446,11 +446,11 @@ void test_revert_workdir__rename(void) opts.merge_opts.flags |= GIT_MERGE_FIND_RENAMES; opts.merge_opts.rename_threshold = 50; - git_oid_fromstr(&head_oid, "55568c8de5322ff9a95d72747a239cdb64a19965"); + git_oid__fromstr(&head_oid, "55568c8de5322ff9a95d72747a239cdb64a19965", GIT_OID_SHA1); cl_git_pass(git_commit_lookup(&head, repo, &head_oid)); cl_git_pass(git_reset(repo, (git_object *)head, GIT_RESET_HARD, NULL)); - git_oid_fromstr(&revert_oid, "0aa8c7e40d342fff78d60b29a4ba8e993ed79c51"); + git_oid__fromstr(&revert_oid, "0aa8c7e40d342fff78d60b29a4ba8e993ed79c51", GIT_OID_SHA1); cl_git_pass(git_commit_lookup(&commit, repo, &revert_oid)); cl_git_pass(git_revert(repo, commit, &opts)); @@ -512,7 +512,7 @@ void test_revert_workdir__merge_fails_without_mainline_specified(void) git_commit *head; git_oid head_oid; - git_oid_fromstr(&head_oid, "5acdc74af27172ec491d213ee36cea7eb9ef2579"); + git_oid__fromstr(&head_oid, "5acdc74af27172ec491d213ee36cea7eb9ef2579", GIT_OID_SHA1); cl_git_pass(git_commit_lookup(&head, repo, &head_oid)); cl_git_pass(git_reset(repo, (git_object *)head, GIT_RESET_HARD, NULL)); @@ -539,7 +539,7 @@ void test_revert_workdir__merge_first_parent(void) opts.mainline = 1; - git_oid_fromstr(&head_oid, "5acdc74af27172ec491d213ee36cea7eb9ef2579"); + git_oid__fromstr(&head_oid, "5acdc74af27172ec491d213ee36cea7eb9ef2579", GIT_OID_SHA1); cl_git_pass(git_commit_lookup(&head, repo, &head_oid)); cl_git_pass(git_reset(repo, (git_object *)head, GIT_RESET_HARD, NULL)); @@ -564,7 +564,7 @@ void test_revert_workdir__merge_second_parent(void) opts.mainline = 2; - git_oid_fromstr(&head_oid, "5acdc74af27172ec491d213ee36cea7eb9ef2579"); + git_oid__fromstr(&head_oid, "5acdc74af27172ec491d213ee36cea7eb9ef2579", GIT_OID_SHA1); cl_git_pass(git_commit_lookup(&head, repo, &head_oid)); cl_git_pass(git_reset(repo, (git_object *)head, GIT_RESET_HARD, NULL)); diff --git a/tests/libgit2/revwalk/basic.c b/tests/libgit2/revwalk/basic.c index 2c8d885e2..41090a1da 100644 --- a/tests/libgit2/revwalk/basic.c +++ b/tests/libgit2/revwalk/basic.c @@ -50,12 +50,12 @@ static const int result_bytes = 24; static int get_commit_index(git_oid *raw_oid) { int i; - char oid[GIT_OID_HEXSZ]; + char oid[GIT_OID_SHA1_HEXSIZE]; git_oid_fmt(oid, raw_oid); for (i = 0; i < commit_count; ++i) - if (memcmp(oid, commit_ids[i], GIT_OID_HEXSZ) == 0) + if (memcmp(oid, commit_ids[i], GIT_OID_SHA1_HEXSIZE) == 0) return i; return -1; @@ -75,9 +75,9 @@ static int test_walk_only(git_revwalk *walk, while (git_revwalk_next(&oid, walk) == 0) { result_array[i++] = get_commit_index(&oid); /*{ - char str[GIT_OID_HEXSZ+1]; + char str[GIT_OID_SHA1_HEXSIZE+1]; git_oid_fmt(str, &oid); - str[GIT_OID_HEXSZ] = 0; + str[GIT_OID_SHA1_HEXSIZE] = 0; printf(" %d) %s\n", i, str); }*/ } @@ -139,7 +139,7 @@ void test_revwalk_basic__sorting_modes(void) revwalk_basic_setup_walk(NULL); - git_oid_fromstr(&id, commit_head); + git_oid__fromstr(&id, commit_head, GIT_OID_SHA1); cl_git_pass(test_walk(_walk, &id, GIT_SORT_TIME, commit_sorting_time, 1)); cl_git_pass(test_walk(_walk, &id, GIT_SORT_TOPOLOGICAL, commit_sorting_topo, 2)); @@ -180,6 +180,23 @@ void test_revwalk_basic__glob_heads_with_invalid(void) cl_assert_equal_i(20, i); } +void test_revwalk_basic__glob_invalid_symbolic_ref(void) +{ + int i; + git_oid oid; + + revwalk_basic_setup_walk("testrepo"); + + cl_git_mkfile("testrepo/.git/refs/heads/broken-sym-ref", "ref: refs/heads/does-not-exist"); + cl_git_pass(git_revwalk_push_glob(_walk, "heads")); + + for (i = 0; !git_revwalk_next(&oid, _walk); ++i) + /* walking */; + + /* git log --branches --oneline | wc -l => 16 */ + cl_assert_equal_i(20, i); +} + void test_revwalk_basic__push_head(void) { int i = 0; @@ -204,7 +221,7 @@ void test_revwalk_basic__sorted_after_reset(void) revwalk_basic_setup_walk(NULL); - git_oid_fromstr(&oid, commit_head); + git_oid__fromstr(&oid, commit_head, GIT_OID_SHA1); /* push, sort, and test the walk */ cl_git_pass(git_revwalk_push(_walk, &oid)); @@ -282,7 +299,7 @@ void test_revwalk_basic__multiple_push_1(void) cl_git_pass(git_revwalk_hide_ref(_walk, "refs/heads/packed-test")); - cl_git_pass(git_oid_fromstr(&oid, "5b5b025afb0b4c913b4c338a42934a3863bf3644")); + cl_git_pass(git_oid__fromstr(&oid, "5b5b025afb0b4c913b4c338a42934a3863bf3644", GIT_OID_SHA1)); cl_git_pass(git_revwalk_push(_walk, &oid)); while (git_revwalk_next(&oid, _walk) == 0) @@ -316,7 +333,7 @@ void test_revwalk_basic__multiple_push_2(void) revwalk_basic_setup_walk(NULL); - cl_git_pass(git_oid_fromstr(&oid, "5b5b025afb0b4c913b4c338a42934a3863bf3644")); + cl_git_pass(git_oid__fromstr(&oid, "5b5b025afb0b4c913b4c338a42934a3863bf3644", GIT_OID_SHA1)); cl_git_pass(git_revwalk_push(_walk, &oid)); cl_git_pass(git_revwalk_hide_ref(_walk, "refs/heads/packed-test")); @@ -335,7 +352,7 @@ void test_revwalk_basic__disallow_non_commit(void) revwalk_basic_setup_walk(NULL); - cl_git_pass(git_oid_fromstr(&oid, "521d87c1ec3aef9824daf6d96cc0ae3710766d91")); + cl_git_pass(git_oid__fromstr(&oid, "521d87c1ec3aef9824daf6d96cc0ae3710766d91", GIT_OID_SHA1)); cl_git_fail(git_revwalk_push(_walk, &oid)); } @@ -345,7 +362,7 @@ void test_revwalk_basic__hide_then_push(void) int i = 0; revwalk_basic_setup_walk(NULL); - cl_git_pass(git_oid_fromstr(&oid, "5b5b025afb0b4c913b4c338a42934a3863bf3644")); + cl_git_pass(git_oid__fromstr(&oid, "5b5b025afb0b4c913b4c338a42934a3863bf3644", GIT_OID_SHA1)); cl_git_pass(git_revwalk_hide(_walk, &oid)); cl_git_pass(git_revwalk_push(_walk, &oid)); @@ -359,7 +376,7 @@ void test_revwalk_basic__hide_then_push(void) void test_revwalk_basic__topo_crash(void) { git_oid oid; - git_oid_fromstr(&oid, "5b5b025afb0b4c913b4c338a42934a3863bf3644"); + git_oid__fromstr(&oid, "5b5b025afb0b4c913b4c338a42934a3863bf3644", GIT_OID_SHA1); revwalk_basic_setup_walk(NULL); git_revwalk_sorting(_walk, GIT_SORT_TOPOLOGICAL); @@ -378,8 +395,8 @@ void test_revwalk_basic__from_new_to_old(void) revwalk_basic_setup_walk(NULL); git_revwalk_sorting(_walk, GIT_SORT_TIME); - cl_git_pass(git_oid_fromstr(&to_oid, "5b5b025afb0b4c913b4c338a42934a3863bf3644")); - cl_git_pass(git_oid_fromstr(&from_oid, "a4a7dce85cf63874e984719f4fdd239f5145052f")); + cl_git_pass(git_oid__fromstr(&to_oid, "5b5b025afb0b4c913b4c338a42934a3863bf3644", GIT_OID_SHA1)); + cl_git_pass(git_oid__fromstr(&from_oid, "a4a7dce85cf63874e984719f4fdd239f5145052f", GIT_OID_SHA1)); cl_git_pass(git_revwalk_push(_walk, &to_oid)); cl_git_pass(git_revwalk_hide(_walk, &from_oid)); @@ -479,7 +496,7 @@ void test_revwalk_basic__mimic_git_rev_list(void) cl_git_pass(git_revwalk_push_ref(_walk, "refs/heads/br2")); cl_git_pass(git_revwalk_push_ref(_walk, "refs/heads/master")); - cl_git_pass(git_oid_fromstr(&oid, "e90810b8df3e80c413d903f631643c716887138d")); + cl_git_pass(git_oid__fromstr(&oid, "e90810b8df3e80c413d903f631643c716887138d", GIT_OID_SHA1)); cl_git_pass(git_revwalk_push(_walk, &oid)); cl_git_pass(git_revwalk_next(&oid, _walk)); @@ -563,10 +580,10 @@ void test_revwalk_basic__old_hidden_commit_one(void) revwalk_basic_setup_walk("testrepo.git"); - cl_git_pass(git_oid_fromstr(&new_id, "bd758010071961f28336333bc41e9c64c9a64866")); + cl_git_pass(git_oid__fromstr(&new_id, "bd758010071961f28336333bc41e9c64c9a64866", GIT_OID_SHA1)); cl_git_pass(git_revwalk_push(_walk, &new_id)); - cl_git_pass(git_oid_fromstr(&old_id, "8e73b769e97678d684b809b163bebdae2911720f")); + cl_git_pass(git_oid__fromstr(&old_id, "8e73b769e97678d684b809b163bebdae2911720f", GIT_OID_SHA1)); cl_git_pass(git_revwalk_hide(_walk, &old_id)); cl_git_pass(git_revwalk_next(&oid, _walk)); @@ -587,10 +604,10 @@ void test_revwalk_basic__old_hidden_commit_two(void) revwalk_basic_setup_walk("testrepo.git"); - cl_git_pass(git_oid_fromstr(&new_id, "bd758010071961f28336333bc41e9c64c9a64866")); + cl_git_pass(git_oid__fromstr(&new_id, "bd758010071961f28336333bc41e9c64c9a64866", GIT_OID_SHA1)); cl_git_pass(git_revwalk_push(_walk, &new_id)); - cl_git_pass(git_oid_fromstr(&old_id, "b91e763008b10db366442469339f90a2b8400d0a")); + cl_git_pass(git_oid__fromstr(&old_id, "b91e763008b10db366442469339f90a2b8400d0a", GIT_OID_SHA1)); cl_git_pass(git_revwalk_hide(_walk, &old_id)); cl_git_pass(git_revwalk_next(&oid, _walk)); diff --git a/tests/libgit2/revwalk/hidecb.c b/tests/libgit2/revwalk/hidecb.c index 54315bc77..2100a54f2 100644 --- a/tests/libgit2/revwalk/hidecb.c +++ b/tests/libgit2/revwalk/hidecb.c @@ -32,10 +32,10 @@ void test_revwalk_hidecb__initialize(void) int i; cl_git_pass(git_repository_open(&_repo, cl_fixture("testrepo.git"))); - cl_git_pass(git_oid_fromstr(&_head_id, commit_head)); + cl_git_pass(git_oid__fromstr(&_head_id, commit_head, GIT_OID_SHA1)); for (i = 0; i < commit_count; i++) - cl_git_pass(git_oid_fromstr(&commit_ids[i], commit_strs[i])); + cl_git_pass(git_oid__fromstr(&commit_ids[i], commit_strs[i], GIT_OID_SHA1)); } diff --git a/tests/libgit2/revwalk/mergebase.c b/tests/libgit2/revwalk/mergebase.c index 0378c869b..d413a1f6e 100644 --- a/tests/libgit2/revwalk/mergebase.c +++ b/tests/libgit2/revwalk/mergebase.c @@ -25,9 +25,9 @@ void test_revwalk_mergebase__single1(void) git_oid result, one, two, expected; size_t ahead, behind; - cl_git_pass(git_oid_fromstr(&one, "c47800c7266a2be04c571c04d5a6614691ea99bd ")); - cl_git_pass(git_oid_fromstr(&two, "9fd738e8f7967c078dceed8190330fc8648ee56a")); - cl_git_pass(git_oid_fromstr(&expected, "5b5b025afb0b4c913b4c338a42934a3863bf3644")); + cl_git_pass(git_oid__fromstr(&one, "c47800c7266a2be04c571c04d5a6614691ea99bd ", GIT_OID_SHA1)); + cl_git_pass(git_oid__fromstr(&two, "9fd738e8f7967c078dceed8190330fc8648ee56a", GIT_OID_SHA1)); + cl_git_pass(git_oid__fromstr(&expected, "5b5b025afb0b4c913b4c338a42934a3863bf3644", GIT_OID_SHA1)); cl_git_pass(git_merge_base(&result, _repo, &one, &two)); cl_assert_equal_oid(&expected, &result); @@ -46,9 +46,9 @@ void test_revwalk_mergebase__single2(void) git_oid result, one, two, expected; size_t ahead, behind; - cl_git_pass(git_oid_fromstr(&one, "763d71aadf09a7951596c9746c024e7eece7c7af")); - cl_git_pass(git_oid_fromstr(&two, "a65fedf39aefe402d3bb6e24df4d4f5fe4547750")); - cl_git_pass(git_oid_fromstr(&expected, "c47800c7266a2be04c571c04d5a6614691ea99bd")); + cl_git_pass(git_oid__fromstr(&one, "763d71aadf09a7951596c9746c024e7eece7c7af", GIT_OID_SHA1)); + cl_git_pass(git_oid__fromstr(&two, "a65fedf39aefe402d3bb6e24df4d4f5fe4547750", GIT_OID_SHA1)); + cl_git_pass(git_oid__fromstr(&expected, "c47800c7266a2be04c571c04d5a6614691ea99bd", GIT_OID_SHA1)); cl_git_pass(git_merge_base(&result, _repo, &one, &two)); cl_assert_equal_oid(&expected, &result); @@ -67,9 +67,9 @@ void test_revwalk_mergebase__merged_branch(void) git_oid result, one, two, expected; size_t ahead, behind; - cl_git_pass(git_oid_fromstr(&one, "a65fedf39aefe402d3bb6e24df4d4f5fe4547750")); - cl_git_pass(git_oid_fromstr(&two, "9fd738e8f7967c078dceed8190330fc8648ee56a")); - cl_git_pass(git_oid_fromstr(&expected, "9fd738e8f7967c078dceed8190330fc8648ee56a")); + cl_git_pass(git_oid__fromstr(&one, "a65fedf39aefe402d3bb6e24df4d4f5fe4547750", GIT_OID_SHA1)); + cl_git_pass(git_oid__fromstr(&two, "9fd738e8f7967c078dceed8190330fc8648ee56a", GIT_OID_SHA1)); + cl_git_pass(git_oid__fromstr(&expected, "9fd738e8f7967c078dceed8190330fc8648ee56a", GIT_OID_SHA1)); cl_git_pass(git_merge_base(&result, _repo, &one, &two)); cl_assert_equal_oid(&expected, &result); @@ -91,8 +91,8 @@ void test_revwalk_mergebase__two_way_merge(void) git_oid one, two; size_t ahead, behind; - cl_git_pass(git_oid_fromstr(&one, "9b219343610c88a1187c996d0dc58330b55cee28")); - cl_git_pass(git_oid_fromstr(&two, "a953a018c5b10b20c86e69fef55ebc8ad4c5a417")); + cl_git_pass(git_oid__fromstr(&one, "9b219343610c88a1187c996d0dc58330b55cee28", GIT_OID_SHA1)); + cl_git_pass(git_oid__fromstr(&two, "a953a018c5b10b20c86e69fef55ebc8ad4c5a417", GIT_OID_SHA1)); cl_git_pass(git_graph_ahead_behind(&ahead, &behind, _repo2, &one, &two)); cl_assert_equal_sz(ahead, 8); @@ -110,8 +110,8 @@ void test_revwalk_mergebase__no_common_ancestor_returns_ENOTFOUND(void) size_t ahead, behind; int error; - cl_git_pass(git_oid_fromstr(&one, "763d71aadf09a7951596c9746c024e7eece7c7af")); - cl_git_pass(git_oid_fromstr(&two, "e90810b8df3e80c413d903f631643c716887138d")); + cl_git_pass(git_oid__fromstr(&one, "763d71aadf09a7951596c9746c024e7eece7c7af", GIT_OID_SHA1)); + cl_git_pass(git_oid__fromstr(&two, "e90810b8df3e80c413d903f631643c716887138d", GIT_OID_SHA1)); error = git_merge_base(&result, _repo, &one, &two); cl_git_fail(error); @@ -127,9 +127,9 @@ void test_revwalk_mergebase__prefer_youngest_merge_base(void) { git_oid result, one, two, expected; - cl_git_pass(git_oid_fromstr(&one, "a4a7dce85cf63874e984719f4fdd239f5145052f")); - cl_git_pass(git_oid_fromstr(&two, "be3563ae3f795b2b4353bcce3a527ad0a4f7f644")); - cl_git_pass(git_oid_fromstr(&expected, "c47800c7266a2be04c571c04d5a6614691ea99bd")); + cl_git_pass(git_oid__fromstr(&one, "a4a7dce85cf63874e984719f4fdd239f5145052f", GIT_OID_SHA1)); + cl_git_pass(git_oid__fromstr(&two, "be3563ae3f795b2b4353bcce3a527ad0a4f7f644", GIT_OID_SHA1)); + cl_git_pass(git_oid__fromstr(&expected, "c47800c7266a2be04c571c04d5a6614691ea99bd", GIT_OID_SHA1)); cl_git_pass(git_merge_base(&result, _repo, &one, &two)); cl_assert_equal_oid(&expected, &result); @@ -140,10 +140,10 @@ void test_revwalk_mergebase__multiple_merge_bases(void) git_oid one, two, expected1, expected2; git_oidarray result = {NULL, 0}; - cl_git_pass(git_oid_fromstr(&one, "a4a7dce85cf63874e984719f4fdd239f5145052f")); - cl_git_pass(git_oid_fromstr(&two, "be3563ae3f795b2b4353bcce3a527ad0a4f7f644")); - cl_git_pass(git_oid_fromstr(&expected1, "c47800c7266a2be04c571c04d5a6614691ea99bd")); - cl_git_pass(git_oid_fromstr(&expected2, "9fd738e8f7967c078dceed8190330fc8648ee56a")); + cl_git_pass(git_oid__fromstr(&one, "a4a7dce85cf63874e984719f4fdd239f5145052f", GIT_OID_SHA1)); + cl_git_pass(git_oid__fromstr(&two, "be3563ae3f795b2b4353bcce3a527ad0a4f7f644", GIT_OID_SHA1)); + cl_git_pass(git_oid__fromstr(&expected1, "c47800c7266a2be04c571c04d5a6614691ea99bd", GIT_OID_SHA1)); + cl_git_pass(git_oid__fromstr(&expected2, "9fd738e8f7967c078dceed8190330fc8648ee56a", GIT_OID_SHA1)); cl_git_pass(git_merge_bases(&result, _repo, &one, &two)); cl_assert_equal_i(2, result.count); @@ -160,10 +160,10 @@ void test_revwalk_mergebase__multiple_merge_bases_many_commits(void) git_oid *input = git__malloc(sizeof(git_oid) * 2); - cl_git_pass(git_oid_fromstr(&input[0], "a4a7dce85cf63874e984719f4fdd239f5145052f")); - cl_git_pass(git_oid_fromstr(&input[1], "be3563ae3f795b2b4353bcce3a527ad0a4f7f644")); - cl_git_pass(git_oid_fromstr(&expected1, "c47800c7266a2be04c571c04d5a6614691ea99bd")); - cl_git_pass(git_oid_fromstr(&expected2, "9fd738e8f7967c078dceed8190330fc8648ee56a")); + cl_git_pass(git_oid__fromstr(&input[0], "a4a7dce85cf63874e984719f4fdd239f5145052f", GIT_OID_SHA1)); + cl_git_pass(git_oid__fromstr(&input[1], "be3563ae3f795b2b4353bcce3a527ad0a4f7f644", GIT_OID_SHA1)); + cl_git_pass(git_oid__fromstr(&expected1, "c47800c7266a2be04c571c04d5a6614691ea99bd", GIT_OID_SHA1)); + cl_git_pass(git_oid__fromstr(&expected2, "9fd738e8f7967c078dceed8190330fc8648ee56a", GIT_OID_SHA1)); cl_git_pass(git_merge_bases_many(&result, _repo, 2, input)); cl_assert_equal_i(2, result.count); @@ -178,8 +178,8 @@ void test_revwalk_mergebase__no_off_by_one_missing(void) { git_oid result, one, two; - cl_git_pass(git_oid_fromstr(&one, "1a443023183e3f2bfbef8ac923cd81c1018a18fd")); - cl_git_pass(git_oid_fromstr(&two, "9f13f7d0a9402c681f91dc590cf7b5470e6a77d2")); + cl_git_pass(git_oid__fromstr(&one, "1a443023183e3f2bfbef8ac923cd81c1018a18fd", GIT_OID_SHA1)); + cl_git_pass(git_oid__fromstr(&two, "9f13f7d0a9402c681f91dc590cf7b5470e6a77d2", GIT_OID_SHA1)); cl_git_pass(git_merge_base(&result, _repo, &one, &two)); } @@ -201,7 +201,7 @@ static void assert_mergebase_many(const char *expected_sha, int count, ...) for (i = 0; i < count; ++i) { partial_oid = va_arg(ap, char *); - cl_git_pass(git_oid_fromstrn(&oid, partial_oid, strlen(partial_oid))); + cl_git_pass(git_oid__fromstrn(&oid, partial_oid, strlen(partial_oid), GIT_OID_SHA1)); cl_git_pass(git_object_lookup_prefix(&object, _repo, &oid, strlen(partial_oid), GIT_OBJECT_COMMIT)); git_oid_cpy(&oids[i], git_object_id(object)); @@ -214,7 +214,7 @@ static void assert_mergebase_many(const char *expected_sha, int count, ...) cl_assert_equal_i(GIT_ENOTFOUND, git_merge_base_many(&oid, _repo, count, oids)); else { cl_git_pass(git_merge_base_many(&oid, _repo, count, oids)); - cl_git_pass(git_oid_fromstr(&expected, expected_sha)); + cl_git_pass(git_oid__fromstr(&expected, expected_sha, GIT_OID_SHA1)); cl_assert_equal_oid(&expected, &oid); } @@ -265,7 +265,7 @@ static void assert_mergebase_octopus(const char *expected_sha, int count, ...) for (i = 0; i < count; ++i) { partial_oid = va_arg(ap, char *); - cl_git_pass(git_oid_fromstrn(&oid, partial_oid, strlen(partial_oid))); + cl_git_pass(git_oid__fromstrn(&oid, partial_oid, strlen(partial_oid), GIT_OID_SHA1)); cl_git_pass(git_object_lookup_prefix(&object, _repo, &oid, strlen(partial_oid), GIT_OBJECT_COMMIT)); git_oid_cpy(&oids[i], git_object_id(object)); @@ -278,7 +278,7 @@ static void assert_mergebase_octopus(const char *expected_sha, int count, ...) cl_assert_equal_i(GIT_ENOTFOUND, git_merge_base_octopus(&oid, _repo, count, oids)); else { cl_git_pass(git_merge_base_octopus(&oid, _repo, count, oids)); - cl_git_pass(git_oid_fromstr(&expected, expected_sha)); + cl_git_pass(git_oid__fromstr(&expected, expected_sha, GIT_OID_SHA1)); cl_assert_equal_oid(&expected, &oid); } @@ -501,9 +501,9 @@ void test_revwalk_mergebase__remove_redundant(void) cl_git_pass(git_repository_open(&repo, cl_fixture("redundant.git"))); - cl_git_pass(git_oid_fromstr(&one, "d89137c93ba1ee749214ff4ce52ae9137bc833f9")); - cl_git_pass(git_oid_fromstr(&two, "91f4b95df4a59504a9813ba66912562931d990e3")); - cl_git_pass(git_oid_fromstr(&base, "6cb1f2352d974e1c5a776093017e8772416ac97a")); + cl_git_pass(git_oid__fromstr(&one, "d89137c93ba1ee749214ff4ce52ae9137bc833f9", GIT_OID_SHA1)); + cl_git_pass(git_oid__fromstr(&two, "91f4b95df4a59504a9813ba66912562931d990e3", GIT_OID_SHA1)); + cl_git_pass(git_oid__fromstr(&base, "6cb1f2352d974e1c5a776093017e8772416ac97a", GIT_OID_SHA1)); cl_git_pass(git_merge_bases(&result, repo, &one, &two)); cl_assert_equal_i(1, result.count); diff --git a/tests/libgit2/revwalk/simplify.c b/tests/libgit2/revwalk/simplify.c index 6dd068a42..824496d7e 100644 --- a/tests/libgit2/revwalk/simplify.c +++ b/tests/libgit2/revwalk/simplify.c @@ -32,13 +32,13 @@ void test_revwalk_simplify__first_parent(void) int i, error; for (i = 0; i < 4; i++) { - git_oid_fromstr(&expected[i], expected_str[i]); + git_oid__fromstr(&expected[i], expected_str[i], GIT_OID_SHA1); } repo = cl_git_sandbox_init("testrepo.git"); cl_git_pass(git_revwalk_new(&walk, repo)); - git_oid_fromstr(&id, commit_head); + git_oid__fromstr(&id, commit_head, GIT_OID_SHA1); cl_git_pass(git_revwalk_push(walk, &id)); git_revwalk_sorting(walk, GIT_SORT_TOPOLOGICAL); git_revwalk_simplify_first_parent(walk); diff --git a/tests/libgit2/stash/save.c b/tests/libgit2/stash/save.c index f574211d7..23f3c1cbb 100644 --- a/tests/libgit2/stash/save.c +++ b/tests/libgit2/stash/save.c @@ -130,6 +130,19 @@ void test_stash_save__can_keep_index(void) assert_status(repo, "just.ignore", GIT_STATUS_IGNORED); } +void test_stash_save__can_keep_all(void) +{ + cl_git_pass(git_stash_save(&stash_tip_oid, repo, signature, NULL, GIT_STASH_KEEP_ALL)); + + assert_status(repo, "what", GIT_STATUS_WT_MODIFIED | GIT_STATUS_INDEX_MODIFIED); + assert_status(repo, "how", GIT_STATUS_INDEX_MODIFIED); + assert_status(repo, "who", GIT_STATUS_WT_MODIFIED); + assert_status(repo, "when", GIT_STATUS_WT_NEW); + assert_status(repo, "why", GIT_STATUS_INDEX_NEW); + assert_status(repo, "where", GIT_STATUS_WT_MODIFIED | GIT_STATUS_INDEX_NEW); + assert_status(repo, "just.ignore", GIT_STATUS_IGNORED); +} + static void assert_commit_message_contains(const char *revision, const char *fragment) { git_commit *commit; @@ -488,3 +501,27 @@ void test_stash_save__deleted_in_index_modified_in_workdir(void) git_index_free(index); } + +void test_stash_save__option_paths(void) +{ + git_stash_save_options options = GIT_STASH_SAVE_OPTIONS_INIT; + char *paths[2] = { "who", "where" }; + + options.paths = (git_strarray){ + paths, + 2 + }; + options.stasher = signature; + + cl_git_pass(git_stash_save_with_opts(&stash_tip_oid, repo, &options)); + + assert_blob_oid("refs/stash:who", "a0400d4954659306a976567af43125a0b1aa8595"); + assert_blob_oid("refs/stash:where", "e3d6434ec12eb76af8dfa843a64ba6ab91014a0b"); + + assert_blob_oid("refs/stash:what", "ce013625030ba8dba906f756967f9e9ca394464a"); + assert_blob_oid("refs/stash:how", "ac790413e2d7a26c3767e78c57bb28716686eebc"); + assert_blob_oid("refs/stash:when", NULL); + assert_blob_oid("refs/stash:why", NULL); + assert_blob_oid("refs/stash:.gitignore", "ac4d88de61733173d9959e4b77c69b9f17a00980"); + assert_blob_oid("refs/stash:just.ignore", NULL); +} diff --git a/tests/libgit2/status/single.c b/tests/libgit2/status/single.c index e7f92097c..b9659a031 100644 --- a/tests/libgit2/status/single.c +++ b/tests/libgit2/status/single.c @@ -1,5 +1,6 @@ #include "clar_libgit2.h" #include "posix.h" +#include "odb.h" static void cleanup__remove_file(void *_file) @@ -17,11 +18,11 @@ void test_status_single__hash_single_file(void) git_oid expected_id, actual_id; /* initialization */ - git_oid_fromstr(&expected_id, file_hash); + git_oid__fromstr(&expected_id, file_hash, GIT_OID_SHA1); cl_git_mkfile(file_name, file_contents); cl_set_cleanup(&cleanup__remove_file, (void *)file_name); - cl_git_pass(git_odb_hashfile(&actual_id, file_name, GIT_OBJECT_BLOB)); + cl_git_pass(git_odb__hashfile(&actual_id, file_name, GIT_OBJECT_BLOB, GIT_OID_SHA1)); cl_assert_equal_oid(&expected_id, &actual_id); } @@ -35,11 +36,11 @@ void test_status_single__hash_single_empty_file(void) git_oid expected_id, actual_id; /* initialization */ - git_oid_fromstr(&expected_id, file_hash); + git_oid__fromstr(&expected_id, file_hash, GIT_OID_SHA1); cl_git_mkfile(file_name, file_contents); cl_set_cleanup(&cleanup__remove_file, (void *)file_name); - cl_git_pass(git_odb_hashfile(&actual_id, file_name, GIT_OBJECT_BLOB)); + cl_git_pass(git_odb__hashfile(&actual_id, file_name, GIT_OBJECT_BLOB, GIT_OID_SHA1)); cl_assert_equal_oid(&expected_id, &actual_id); } diff --git a/tests/libgit2/status/submodules.c b/tests/libgit2/status/submodules.c index d223657b4..90d56d9cc 100644 --- a/tests/libgit2/status/submodules.c +++ b/tests/libgit2/status/submodules.c @@ -142,7 +142,7 @@ void test_status_submodules__moved_head(void) /* move submodule HEAD to c47800c7266a2be04c571c04d5a6614691ea99bd */ cl_git_pass( - git_oid_fromstr(&oid, "c47800c7266a2be04c571c04d5a6614691ea99bd")); + git_oid__fromstr(&oid, "c47800c7266a2be04c571c04d5a6614691ea99bd", GIT_OID_SHA1)); cl_git_pass(git_repository_set_head_detached(smrepo, &oid)); /* first do a normal status, which should now include the submodule */ diff --git a/tests/libgit2/status/worktree.c b/tests/libgit2/status/worktree.c index 00c6ec2d5..efbf597a7 100644 --- a/tests/libgit2/status/worktree.c +++ b/tests/libgit2/status/worktree.c @@ -515,18 +515,21 @@ void test_status_worktree__conflict_with_diff3(void) ancestor_entry.path = "modified_file"; ancestor_entry.mode = 0100644; - git_oid_fromstr(&ancestor_entry.id, - "452e4244b5d083ddf0460acf1ecc74db9dcfa11a"); + git_oid__fromstr(&ancestor_entry.id, + "452e4244b5d083ddf0460acf1ecc74db9dcfa11a", + GIT_OID_SHA1); our_entry.path = "modified_file"; our_entry.mode = 0100644; - git_oid_fromstr(&our_entry.id, - "452e4244b5d083ddf0460acf1ecc74db9dcfa11a"); + git_oid__fromstr(&our_entry.id, + "452e4244b5d083ddf0460acf1ecc74db9dcfa11a", + GIT_OID_SHA1); their_entry.path = "modified_file"; their_entry.mode = 0100644; - git_oid_fromstr(&their_entry.id, - "452e4244b5d083ddf0460acf1ecc74db9dcfa11a"); + git_oid__fromstr(&their_entry.id, + "452e4244b5d083ddf0460acf1ecc74db9dcfa11a", + GIT_OID_SHA1); cl_git_pass(git_status_file(&status, repo, "modified_file")); cl_assert_equal_i(GIT_STATUS_WT_MODIFIED, status); @@ -711,18 +714,21 @@ void test_status_worktree__conflicted_item(void) ancestor_entry.mode = 0100644; ancestor_entry.path = "modified_file"; - git_oid_fromstr(&ancestor_entry.id, - "452e4244b5d083ddf0460acf1ecc74db9dcfa11a"); + git_oid__fromstr(&ancestor_entry.id, + "452e4244b5d083ddf0460acf1ecc74db9dcfa11a", + GIT_OID_SHA1); our_entry.mode = 0100644; our_entry.path = "modified_file"; - git_oid_fromstr(&our_entry.id, - "452e4244b5d083ddf0460acf1ecc74db9dcfa11a"); + git_oid__fromstr(&our_entry.id, + "452e4244b5d083ddf0460acf1ecc74db9dcfa11a", + GIT_OID_SHA1); their_entry.mode = 0100644; their_entry.path = "modified_file"; - git_oid_fromstr(&their_entry.id, - "452e4244b5d083ddf0460acf1ecc74db9dcfa11a"); + git_oid__fromstr(&their_entry.id, + "452e4244b5d083ddf0460acf1ecc74db9dcfa11a", + GIT_OID_SHA1); cl_git_pass(git_status_file(&status, repo, "modified_file")); cl_assert_equal_i(GIT_STATUS_WT_MODIFIED, status); @@ -744,11 +750,11 @@ void test_status_worktree__conflict_has_no_oid(void) git_index_entry entry = {{0}}; git_status_list *statuslist; const git_status_entry *status; - git_oid zero_id = {{0}}; + git_oid zero_id = GIT_OID_SHA1_ZERO; entry.mode = 0100644; entry.path = "modified_file"; - git_oid_fromstr(&entry.id, "452e4244b5d083ddf0460acf1ecc74db9dcfa11a"); + git_oid__fromstr(&entry.id, "452e4244b5d083ddf0460acf1ecc74db9dcfa11a", GIT_OID_SHA1); cl_git_pass(git_repository_index(&index, repo)); cl_git_pass(git_index_conflict_add(index, &entry, &entry, &entry)); diff --git a/tests/libgit2/submodule/add.c b/tests/libgit2/submodule/add.c index ae5507d7f..a2a66e7f5 100644 --- a/tests/libgit2/submodule/add.c +++ b/tests/libgit2/submodule/add.c @@ -139,7 +139,7 @@ static void test_add_entry( { git_index_entry entry = {{0}}; - cl_git_pass(git_oid_fromstr(&entry.id, idstr)); + cl_git_pass(git_oid__fromstr(&entry.id, idstr, GIT_OID_SHA1)); entry.path = path; entry.mode = mode; diff --git a/tests/libgit2/submodule/update.c b/tests/libgit2/submodule/update.c index 4aa959852..052a4a1fe 100644 --- a/tests/libgit2/submodule/update.c +++ b/tests/libgit2/submodule/update.c @@ -206,6 +206,26 @@ void test_submodule_update__update_and_init_submodule(void) git_submodule_free(sm); } +void test_submodule_update__update_skip_configured_missing_submodule(void) +{ + git_submodule *sm; + git_submodule_update_options update_options = GIT_SUBMODULE_UPDATE_OPTIONS_INIT; + unsigned int submodule_status = 0; + + g_repo = setup_fixture_submod2(); + + /* get the submodule */ + cl_git_pass(git_submodule_lookup(&sm, g_repo, "sm_gitmodules_only")); + + cl_git_pass(git_submodule_status(&submodule_status, g_repo, "sm_gitmodules_only", GIT_SUBMODULE_IGNORE_UNSPECIFIED)); + cl_assert_equal_i(submodule_status, GIT_SUBMODULE_STATUS_IN_CONFIG); + + /* update (with option to initialize sub repo) */ + cl_git_pass(git_submodule_update(sm, 1, &update_options)); + + git_submodule_free(sm); +} + void test_submodule_update__update_already_checked_out_submodule(void) { git_submodule *sm = NULL; diff --git a/tests/libgit2/transports/smart/packet.c b/tests/libgit2/transports/smart/packet.c index 5b623a378..2035e3b65 100644 --- a/tests/libgit2/transports/smart/packet.c +++ b/tests/libgit2/transports/smart/packet.c @@ -11,8 +11,9 @@ static void assert_flush_parses(const char *line) size_t linelen = strlen(line) + 1; const char *endptr; git_pkt *pkt; + git_pkt_parse_data pkt_parse_data = { 0 }; - cl_git_pass(git_pkt_parse_line((git_pkt **) &pkt, &endptr, line, linelen)); + cl_git_pass(git_pkt_parse_line((git_pkt **) &pkt, &endptr, line, linelen, &pkt_parse_data)); cl_assert_equal_i(pkt->type, GIT_PKT_FLUSH); cl_assert_equal_strn(endptr, line + 4, linelen - 4); @@ -24,8 +25,9 @@ static void assert_data_pkt_parses(const char *line, const char *expected_data, size_t linelen = strlen(line) + 1; const char *endptr; git_pkt_data *pkt; + git_pkt_parse_data pkt_parse_data = { 0 }; - cl_git_pass(git_pkt_parse_line((git_pkt **) &pkt, &endptr, line, linelen)); + cl_git_pass(git_pkt_parse_line((git_pkt **) &pkt, &endptr, line, linelen, &pkt_parse_data)); cl_assert_equal_i(pkt->type, GIT_PKT_DATA); cl_assert_equal_i(pkt->len, expected_len); cl_assert_equal_strn(pkt->data, expected_data, expected_len); @@ -38,8 +40,9 @@ static void assert_sideband_progress_parses(const char *line, const char *expect size_t linelen = strlen(line) + 1; const char *endptr; git_pkt_progress *pkt; + git_pkt_parse_data pkt_parse_data = { 0 }; - cl_git_pass(git_pkt_parse_line((git_pkt **) &pkt, &endptr, line, linelen)); + cl_git_pass(git_pkt_parse_line((git_pkt **) &pkt, &endptr, line, linelen, &pkt_parse_data)); cl_assert_equal_i(pkt->type, GIT_PKT_PROGRESS); cl_assert_equal_i(pkt->len, expected_len); cl_assert_equal_strn(pkt->data, expected_data, expected_len); @@ -52,8 +55,9 @@ static void assert_error_parses(const char *line, const char *expected_error, si size_t linelen = strlen(line) + 1; const char *endptr; git_pkt_err *pkt; + git_pkt_parse_data pkt_parse_data = { 0 }; - cl_git_pass(git_pkt_parse_line((git_pkt **) &pkt, &endptr, line, linelen)); + cl_git_pass(git_pkt_parse_line((git_pkt **) &pkt, &endptr, line, linelen, &pkt_parse_data)); cl_assert_equal_i(pkt->type, GIT_PKT_ERR); cl_assert_equal_i(pkt->len, expected_len); cl_assert_equal_strn(pkt->error, expected_error, expected_len); @@ -67,10 +71,11 @@ static void assert_ack_parses(const char *line, const char *expected_oid, enum g const char *endptr; git_pkt_ack *pkt; git_oid oid; + git_pkt_parse_data pkt_parse_data = { 0 }; - cl_git_pass(git_oid_fromstr(&oid, expected_oid)); + cl_git_pass(git_oid__fromstr(&oid, expected_oid, GIT_OID_SHA1)); - cl_git_pass(git_pkt_parse_line((git_pkt **) &pkt, &endptr, line, linelen)); + cl_git_pass(git_pkt_parse_line((git_pkt **) &pkt, &endptr, line, linelen, &pkt_parse_data)); cl_assert_equal_i(pkt->type, GIT_PKT_ACK); cl_assert_equal_oid(&pkt->oid, &oid); cl_assert_equal_i(pkt->status, expected_status); @@ -83,8 +88,9 @@ static void assert_nak_parses(const char *line) size_t linelen = strlen(line) + 1; const char *endptr; git_pkt *pkt; + git_pkt_parse_data pkt_parse_data = { 0 }; - cl_git_pass(git_pkt_parse_line((git_pkt **) &pkt, &endptr, line, linelen)); + cl_git_pass(git_pkt_parse_line((git_pkt **) &pkt, &endptr, line, linelen, &pkt_parse_data)); cl_assert_equal_i(pkt->type, GIT_PKT_NAK); cl_assert_equal_strn(endptr, line + 7, linelen - 7); @@ -96,8 +102,9 @@ static void assert_comment_parses(const char *line, const char *expected_comment size_t linelen = strlen(line) + 1; const char *endptr; git_pkt_comment *pkt; + git_pkt_parse_data pkt_parse_data = { 0 }; - cl_git_pass(git_pkt_parse_line((git_pkt **) &pkt, &endptr, line, linelen)); + cl_git_pass(git_pkt_parse_line((git_pkt **) &pkt, &endptr, line, linelen, &pkt_parse_data)); cl_assert_equal_i(pkt->type, GIT_PKT_COMMENT); cl_assert_equal_strn(pkt->comment, expected_comment, strlen(expected_comment)); @@ -109,8 +116,9 @@ static void assert_ok_parses(const char *line, const char *expected_ref) size_t linelen = strlen(line) + 1; const char *endptr; git_pkt_ok *pkt; + git_pkt_parse_data pkt_parse_data = { 0 }; - cl_git_pass(git_pkt_parse_line((git_pkt **) &pkt, &endptr, line, linelen)); + cl_git_pass(git_pkt_parse_line((git_pkt **) &pkt, &endptr, line, linelen, &pkt_parse_data)); cl_assert_equal_i(pkt->type, GIT_PKT_OK); cl_assert_equal_strn(pkt->ref, expected_ref, strlen(expected_ref)); @@ -122,8 +130,9 @@ static void assert_unpack_parses(const char *line, bool ok) size_t linelen = strlen(line) + 1; const char *endptr; git_pkt_unpack *pkt; + git_pkt_parse_data pkt_parse_data = { 0 }; - cl_git_pass(git_pkt_parse_line((git_pkt **) &pkt, &endptr, line, linelen)); + cl_git_pass(git_pkt_parse_line((git_pkt **) &pkt, &endptr, line, linelen, &pkt_parse_data)); cl_assert_equal_i(pkt->type, GIT_PKT_UNPACK); cl_assert_equal_i(pkt->unpack_ok, ok); @@ -135,8 +144,9 @@ static void assert_ng_parses(const char *line, const char *expected_ref, const c size_t linelen = strlen(line) + 1; const char *endptr; git_pkt_ng *pkt; + git_pkt_parse_data pkt_parse_data = { 0 }; - cl_git_pass(git_pkt_parse_line((git_pkt **) &pkt, &endptr, line, linelen)); + cl_git_pass(git_pkt_parse_line((git_pkt **) &pkt, &endptr, line, linelen, &pkt_parse_data)); cl_assert_equal_i(pkt->type, GIT_PKT_NG); cl_assert_equal_strn(pkt->ref, expected_ref, strlen(expected_ref)); cl_assert_equal_strn(pkt->msg, expected_msg, strlen(expected_msg)); @@ -153,10 +163,11 @@ static void assert_ref_parses_(const char *line, size_t linelen, const char *exp const char *endptr; git_pkt_ref *pkt; git_oid oid; + git_pkt_parse_data pkt_parse_data = { 0 }; - cl_git_pass(git_oid_fromstr(&oid, expected_oid)); + cl_git_pass(git_oid__fromstr(&oid, expected_oid, GIT_OID_SHA1)); - cl_git_pass(git_pkt_parse_line((git_pkt **) &pkt, &endptr, line, linelen)); + cl_git_pass(git_pkt_parse_line((git_pkt **) &pkt, &endptr, line, linelen, &pkt_parse_data)); cl_assert_equal_i(pkt->type, GIT_PKT_REF); cl_assert_equal_oid(&pkt->head.oid, &oid); cl_assert_equal_strn(pkt->head.name, expected_ref, strlen(expected_ref)); @@ -171,8 +182,10 @@ static void assert_ref_parses_(const char *line, size_t linelen, const char *exp static void assert_pkt_fails(const char *line) { const char *endptr; + git_pkt_parse_data pkt_parse_data = { 0 }; + git_pkt *pkt; - cl_git_fail(git_pkt_parse_line(&pkt, &endptr, line, strlen(line) + 1)); + cl_git_fail(git_pkt_parse_line(&pkt, &endptr, line, strlen(line) + 1, &pkt_parse_data)); } void test_transports_smart_packet__parsing_garbage_fails(void) diff --git a/tests/libgit2/win32/forbidden.c b/tests/libgit2/win32/forbidden.c index 5c007987b..c4e82e90d 100644 --- a/tests/libgit2/win32/forbidden.c +++ b/tests/libgit2/win32/forbidden.c @@ -37,7 +37,7 @@ void test_win32_forbidden__can_add_forbidden_filename_with_entry(void) entry.path = "aux"; entry.mode = GIT_FILEMODE_BLOB; - git_oid_fromstr(&entry.id, "da623abd956bb2fd8052c708c7ed43f05d192d37"); + git_oid__fromstr(&entry.id, "da623abd956bb2fd8052c708c7ed43f05d192d37", GIT_OID_SHA1); cl_git_pass(git_index_add(index, &entry)); @@ -53,7 +53,7 @@ void test_win32_forbidden__cannot_add_dot_git_even_with_entry(void) entry.path = "foo/.git"; entry.mode = GIT_FILEMODE_BLOB; - git_oid_fromstr(&entry.id, "da623abd956bb2fd8052c708c7ed43f05d192d37"); + git_oid__fromstr(&entry.id, "da623abd956bb2fd8052c708c7ed43f05d192d37", GIT_OID_SHA1); cl_git_fail(git_index_add(index, &entry)); diff --git a/tests/libgit2/win32/systemdir.c b/tests/libgit2/win32/systemdir.c index 52c1784a1..9039f05b2 100644 --- a/tests/libgit2/win32/systemdir.c +++ b/tests/libgit2/win32/systemdir.c @@ -1,7 +1,6 @@ #include "clar_libgit2.h" #include "futils.h" #include "sysdir.h" -#include "win32/findfile.h" #ifdef GIT_WIN32 static char *path_save; diff --git a/tests/libgit2/worktree/worktree.c b/tests/libgit2/worktree/worktree.c index 66273d1cb..9fd27f49c 100644 --- a/tests/libgit2/worktree/worktree.c +++ b/tests/libgit2/worktree/worktree.c @@ -120,7 +120,7 @@ void test_worktree_worktree__lookup_nonexistent_worktree(void) { git_worktree *wt; - cl_git_fail(git_worktree_lookup(&wt, fixture.repo, "nonexistent")); + cl_git_fail_with(GIT_ENOTFOUND, git_worktree_lookup(&wt, fixture.repo, "nonexistent")); cl_assert_equal_p(wt, NULL); } diff --git a/tests/resources/namespace.git/COMMIT_EDITMSG b/tests/resources/namespace.git/COMMIT_EDITMSG new file mode 100644 index 000000000..851066514 Binary files /dev/null and b/tests/resources/namespace.git/COMMIT_EDITMSG differ diff --git a/tests/resources/namespace.git/HEAD b/tests/resources/namespace.git/HEAD new file mode 100644 index 000000000..60cbd742c Binary files /dev/null and b/tests/resources/namespace.git/HEAD differ diff --git a/tests/resources/namespace.git/config b/tests/resources/namespace.git/config new file mode 100644 index 000000000..6c9406b7d Binary files /dev/null and b/tests/resources/namespace.git/config differ diff --git a/tests/resources/namespace.git/description b/tests/resources/namespace.git/description new file mode 100644 index 000000000..498b267a8 Binary files /dev/null and b/tests/resources/namespace.git/description differ diff --git a/tests/resources/namespace.git/index b/tests/resources/namespace.git/index new file mode 100644 index 000000000..5ed27feb0 Binary files /dev/null and b/tests/resources/namespace.git/index differ diff --git a/tests/resources/namespace.git/info/exclude b/tests/resources/namespace.git/info/exclude new file mode 100644 index 000000000..a5196d1be Binary files /dev/null and b/tests/resources/namespace.git/info/exclude differ diff --git a/tests/resources/namespace.git/logs/HEAD b/tests/resources/namespace.git/logs/HEAD new file mode 100644 index 000000000..ca0497615 Binary files /dev/null and b/tests/resources/namespace.git/logs/HEAD differ diff --git a/tests/resources/namespace.git/logs/refs/heads/branch b/tests/resources/namespace.git/logs/refs/heads/branch new file mode 100644 index 000000000..e3dfea400 Binary files /dev/null and b/tests/resources/namespace.git/logs/refs/heads/branch differ diff --git a/tests/resources/namespace.git/logs/refs/heads/four b/tests/resources/namespace.git/logs/refs/heads/four new file mode 100644 index 000000000..2abf339ac Binary files /dev/null and b/tests/resources/namespace.git/logs/refs/heads/four differ diff --git a/tests/resources/namespace.git/logs/refs/heads/main b/tests/resources/namespace.git/logs/refs/heads/main new file mode 100644 index 000000000..04de95a49 Binary files /dev/null and b/tests/resources/namespace.git/logs/refs/heads/main differ diff --git a/tests/resources/namespace.git/logs/refs/heads/one b/tests/resources/namespace.git/logs/refs/heads/one new file mode 100644 index 000000000..bd3c5fa25 Binary files /dev/null and b/tests/resources/namespace.git/logs/refs/heads/one differ diff --git a/tests/resources/namespace.git/objects/04/433ff5b52d6ad534fd6288de4a57b81cc12188 b/tests/resources/namespace.git/objects/04/433ff5b52d6ad534fd6288de4a57b81cc12188 new file mode 100644 index 000000000..be49bee0e Binary files /dev/null and b/tests/resources/namespace.git/objects/04/433ff5b52d6ad534fd6288de4a57b81cc12188 differ diff --git a/tests/resources/namespace.git/objects/0a/890bd10328d68f6d85efd2535e3a4c588ee8e6 b/tests/resources/namespace.git/objects/0a/890bd10328d68f6d85efd2535e3a4c588ee8e6 new file mode 100644 index 000000000..41f340b2a Binary files /dev/null and b/tests/resources/namespace.git/objects/0a/890bd10328d68f6d85efd2535e3a4c588ee8e6 differ diff --git a/tests/resources/namespace.git/objects/10/fcb1c85bd6b3bc6f43e0a3932ff5859121a84e b/tests/resources/namespace.git/objects/10/fcb1c85bd6b3bc6f43e0a3932ff5859121a84e new file mode 100644 index 000000000..3005ed15a Binary files /dev/null and b/tests/resources/namespace.git/objects/10/fcb1c85bd6b3bc6f43e0a3932ff5859121a84e differ diff --git a/tests/resources/namespace.git/objects/24/bbdca8b223aaa3384d78312f730c58492aa30a b/tests/resources/namespace.git/objects/24/bbdca8b223aaa3384d78312f730c58492aa30a new file mode 100644 index 000000000..c1e97d5e3 Binary files /dev/null and b/tests/resources/namespace.git/objects/24/bbdca8b223aaa3384d78312f730c58492aa30a differ diff --git a/tests/resources/namespace.git/objects/27/0c611ee72c567bc1b2abec4cbc345bab9f15ba b/tests/resources/namespace.git/objects/27/0c611ee72c567bc1b2abec4cbc345bab9f15ba new file mode 100644 index 000000000..300fb6715 Binary files /dev/null and b/tests/resources/namespace.git/objects/27/0c611ee72c567bc1b2abec4cbc345bab9f15ba differ diff --git a/tests/resources/namespace.git/objects/2b/df67abb163a4ffb2d7f3f0880c9fe5068ce782 b/tests/resources/namespace.git/objects/2b/df67abb163a4ffb2d7f3f0880c9fe5068ce782 new file mode 100644 index 000000000..d0398e6e3 Binary files /dev/null and b/tests/resources/namespace.git/objects/2b/df67abb163a4ffb2d7f3f0880c9fe5068ce782 differ diff --git a/tests/resources/namespace.git/objects/3d/669d1b33ec8add4609d8043d025527db4989eb b/tests/resources/namespace.git/objects/3d/669d1b33ec8add4609d8043d025527db4989eb new file mode 100644 index 000000000..a926c9ea7 Binary files /dev/null and b/tests/resources/namespace.git/objects/3d/669d1b33ec8add4609d8043d025527db4989eb differ diff --git a/tests/resources/namespace.git/objects/42/0d51ce75a87909e29659da2072ffd3d5daf5b7 b/tests/resources/namespace.git/objects/42/0d51ce75a87909e29659da2072ffd3d5daf5b7 new file mode 100644 index 000000000..fb91b1b12 Binary files /dev/null and b/tests/resources/namespace.git/objects/42/0d51ce75a87909e29659da2072ffd3d5daf5b7 differ diff --git a/tests/resources/namespace.git/objects/56/26abf0f72e58d7a153368ba57db4c673c0e171 b/tests/resources/namespace.git/objects/56/26abf0f72e58d7a153368ba57db4c673c0e171 new file mode 100644 index 000000000..4d5447467 Binary files /dev/null and b/tests/resources/namespace.git/objects/56/26abf0f72e58d7a153368ba57db4c673c0e171 differ diff --git a/tests/resources/namespace.git/objects/56/300b5eae653453102ac1213e921973c066425b b/tests/resources/namespace.git/objects/56/300b5eae653453102ac1213e921973c066425b new file mode 100644 index 000000000..59f5649d2 Binary files /dev/null and b/tests/resources/namespace.git/objects/56/300b5eae653453102ac1213e921973c066425b differ diff --git a/tests/resources/namespace.git/objects/7e/eaa70d7c5592db920a2e107ce3918bd4c8a425 b/tests/resources/namespace.git/objects/7e/eaa70d7c5592db920a2e107ce3918bd4c8a425 new file mode 100644 index 000000000..55706bf88 Binary files /dev/null and b/tests/resources/namespace.git/objects/7e/eaa70d7c5592db920a2e107ce3918bd4c8a425 differ diff --git a/tests/resources/namespace.git/objects/85/10665149157c2bc901848c3e0b746954e9cbd9 b/tests/resources/namespace.git/objects/85/10665149157c2bc901848c3e0b746954e9cbd9 new file mode 100644 index 000000000..2f2fef743 Binary files /dev/null and b/tests/resources/namespace.git/objects/85/10665149157c2bc901848c3e0b746954e9cbd9 differ diff --git a/tests/resources/namespace.git/objects/9e/bfa6bdc9d38075d29d26aa5df89b1cf635b269 b/tests/resources/namespace.git/objects/9e/bfa6bdc9d38075d29d26aa5df89b1cf635b269 new file mode 100644 index 000000000..33ec05881 Binary files /dev/null and b/tests/resources/namespace.git/objects/9e/bfa6bdc9d38075d29d26aa5df89b1cf635b269 differ diff --git a/tests/resources/namespace.git/objects/9e/f15e3c5c0c8c6913936f843ad967cbe5541f0d b/tests/resources/namespace.git/objects/9e/f15e3c5c0c8c6913936f843ad967cbe5541f0d new file mode 100644 index 000000000..0759911e0 Binary files /dev/null and b/tests/resources/namespace.git/objects/9e/f15e3c5c0c8c6913936f843ad967cbe5541f0d differ diff --git a/tests/resources/namespace.git/objects/af/5626b4a114abcb82d63db7c8082c3c4756e51b b/tests/resources/namespace.git/objects/af/5626b4a114abcb82d63db7c8082c3c4756e51b new file mode 100644 index 000000000..822bc1518 Binary files /dev/null and b/tests/resources/namespace.git/objects/af/5626b4a114abcb82d63db7c8082c3c4756e51b differ diff --git a/tests/resources/namespace.git/objects/af/81e4bd99cbfe6f05a501f1e4c82db2bf803e02 b/tests/resources/namespace.git/objects/af/81e4bd99cbfe6f05a501f1e4c82db2bf803e02 new file mode 100644 index 000000000..a5e8ecb33 Binary files /dev/null and b/tests/resources/namespace.git/objects/af/81e4bd99cbfe6f05a501f1e4c82db2bf803e02 differ diff --git a/tests/resources/namespace.git/objects/bf/d17f429f4e2d121769213171ad57ca2e5173f9 b/tests/resources/namespace.git/objects/bf/d17f429f4e2d121769213171ad57ca2e5173f9 new file mode 100644 index 000000000..ebd27b88e Binary files /dev/null and b/tests/resources/namespace.git/objects/bf/d17f429f4e2d121769213171ad57ca2e5173f9 differ diff --git a/tests/resources/namespace.git/objects/ec/947e3dd7a7752d078f1ed0cfde7457b21fef58 b/tests/resources/namespace.git/objects/ec/947e3dd7a7752d078f1ed0cfde7457b21fef58 new file mode 100644 index 000000000..a6e1d1d8e Binary files /dev/null and b/tests/resources/namespace.git/objects/ec/947e3dd7a7752d078f1ed0cfde7457b21fef58 differ diff --git a/tests/resources/namespace.git/objects/f7/19efd430d52bcfc8566a43b2eb655688d38871 b/tests/resources/namespace.git/objects/f7/19efd430d52bcfc8566a43b2eb655688d38871 new file mode 100644 index 000000000..b2d51d93b Binary files /dev/null and b/tests/resources/namespace.git/objects/f7/19efd430d52bcfc8566a43b2eb655688d38871 differ diff --git a/tests/resources/namespace.git/objects/f7/5ba05f340c51065cbea2e1fdbfe5fe13144c97 b/tests/resources/namespace.git/objects/f7/5ba05f340c51065cbea2e1fdbfe5fe13144c97 new file mode 100644 index 000000000..044001e9f Binary files /dev/null and b/tests/resources/namespace.git/objects/f7/5ba05f340c51065cbea2e1fdbfe5fe13144c97 differ diff --git a/tests/resources/namespace.git/refs/heads/branch b/tests/resources/namespace.git/refs/heads/branch new file mode 100644 index 000000000..69625465e Binary files /dev/null and b/tests/resources/namespace.git/refs/heads/branch differ diff --git a/tests/resources/namespace.git/refs/heads/main b/tests/resources/namespace.git/refs/heads/main new file mode 100644 index 000000000..b8697694e Binary files /dev/null and b/tests/resources/namespace.git/refs/heads/main differ diff --git a/tests/resources/namespace.git/refs/namespaces/name1/refs/heads/four b/tests/resources/namespace.git/refs/namespaces/name1/refs/heads/four new file mode 100644 index 000000000..86fdb418b Binary files /dev/null and b/tests/resources/namespace.git/refs/namespaces/name1/refs/heads/four differ diff --git a/tests/resources/namespace.git/refs/namespaces/name1/refs/heads/one b/tests/resources/namespace.git/refs/namespaces/name1/refs/heads/one new file mode 100644 index 000000000..22d81378d Binary files /dev/null and b/tests/resources/namespace.git/refs/namespaces/name1/refs/heads/one differ diff --git a/tests/resources/packfile-sha256/pack-b4a043c0ec5e079e8ac67d823776d752efc71661592db317474a0cf292915f31.idx b/tests/resources/packfile-sha256/pack-b4a043c0ec5e079e8ac67d823776d752efc71661592db317474a0cf292915f31.idx new file mode 100644 index 000000000..7aa472cea Binary files /dev/null and b/tests/resources/packfile-sha256/pack-b4a043c0ec5e079e8ac67d823776d752efc71661592db317474a0cf292915f31.idx differ diff --git a/tests/resources/packfile-sha256/pack-b4a043c0ec5e079e8ac67d823776d752efc71661592db317474a0cf292915f31.pack b/tests/resources/packfile-sha256/pack-b4a043c0ec5e079e8ac67d823776d752efc71661592db317474a0cf292915f31.pack new file mode 100644 index 000000000..adbe70ad3 Binary files /dev/null and b/tests/resources/packfile-sha256/pack-b4a043c0ec5e079e8ac67d823776d752efc71661592db317474a0cf292915f31.pack differ diff --git a/tests/resources/testrepo_256.git/FETCH_HEAD b/tests/resources/testrepo_256.git/FETCH_HEAD new file mode 100644 index 000000000..4562d9026 Binary files /dev/null and b/tests/resources/testrepo_256.git/FETCH_HEAD differ diff --git a/tests/resources/testrepo_256.git/HEAD b/tests/resources/testrepo_256.git/HEAD new file mode 100644 index 000000000..cb089cd89 Binary files /dev/null and b/tests/resources/testrepo_256.git/HEAD differ diff --git a/tests/resources/testrepo_256.git/HEAD_TRACKER b/tests/resources/testrepo_256.git/HEAD_TRACKER new file mode 100644 index 000000000..40d876b4c Binary files /dev/null and b/tests/resources/testrepo_256.git/HEAD_TRACKER differ diff --git a/tests/resources/testrepo_256.git/config b/tests/resources/testrepo_256.git/config new file mode 100644 index 000000000..c1aac4a03 Binary files /dev/null and b/tests/resources/testrepo_256.git/config differ diff --git a/tests/resources/testrepo_256.git/description b/tests/resources/testrepo_256.git/description new file mode 100644 index 000000000..498b267a8 Binary files /dev/null and b/tests/resources/testrepo_256.git/description differ diff --git a/tests/resources/testrepo_256.git/hooks/applypatch-msg.sample b/tests/resources/testrepo_256.git/hooks/applypatch-msg.sample new file mode 100755 index 000000000..a5d7b84a6 Binary files /dev/null and b/tests/resources/testrepo_256.git/hooks/applypatch-msg.sample differ diff --git a/tests/resources/testrepo_256.git/hooks/commit-msg.sample b/tests/resources/testrepo_256.git/hooks/commit-msg.sample new file mode 100755 index 000000000..b58d1184a Binary files /dev/null and b/tests/resources/testrepo_256.git/hooks/commit-msg.sample differ diff --git a/tests/resources/testrepo_256.git/hooks/fsmonitor-watchman.sample b/tests/resources/testrepo_256.git/hooks/fsmonitor-watchman.sample new file mode 100755 index 000000000..14ed0aa42 Binary files /dev/null and b/tests/resources/testrepo_256.git/hooks/fsmonitor-watchman.sample differ diff --git a/tests/resources/testrepo_256.git/hooks/post-update.sample b/tests/resources/testrepo_256.git/hooks/post-update.sample new file mode 100755 index 000000000..ec17ec193 Binary files /dev/null and b/tests/resources/testrepo_256.git/hooks/post-update.sample differ diff --git a/tests/resources/testrepo_256.git/hooks/pre-applypatch.sample b/tests/resources/testrepo_256.git/hooks/pre-applypatch.sample new file mode 100755 index 000000000..4142082bc Binary files /dev/null and b/tests/resources/testrepo_256.git/hooks/pre-applypatch.sample differ diff --git a/tests/resources/testrepo_256.git/hooks/pre-commit.sample b/tests/resources/testrepo_256.git/hooks/pre-commit.sample new file mode 100755 index 000000000..e144712c8 Binary files /dev/null and b/tests/resources/testrepo_256.git/hooks/pre-commit.sample differ diff --git a/tests/resources/testrepo_256.git/hooks/pre-merge-commit.sample b/tests/resources/testrepo_256.git/hooks/pre-merge-commit.sample new file mode 100755 index 000000000..399eab192 Binary files /dev/null and b/tests/resources/testrepo_256.git/hooks/pre-merge-commit.sample differ diff --git a/tests/resources/testrepo_256.git/hooks/pre-push.sample b/tests/resources/testrepo_256.git/hooks/pre-push.sample new file mode 100755 index 000000000..4ce688d32 Binary files /dev/null and b/tests/resources/testrepo_256.git/hooks/pre-push.sample differ diff --git a/tests/resources/testrepo_256.git/hooks/pre-rebase.sample b/tests/resources/testrepo_256.git/hooks/pre-rebase.sample new file mode 100755 index 000000000..6cbef5c37 Binary files /dev/null and b/tests/resources/testrepo_256.git/hooks/pre-rebase.sample differ diff --git a/tests/resources/testrepo_256.git/hooks/pre-receive.sample b/tests/resources/testrepo_256.git/hooks/pre-receive.sample new file mode 100755 index 000000000..a1fd29ec1 Binary files /dev/null and b/tests/resources/testrepo_256.git/hooks/pre-receive.sample differ diff --git a/tests/resources/testrepo_256.git/hooks/prepare-commit-msg.sample b/tests/resources/testrepo_256.git/hooks/prepare-commit-msg.sample new file mode 100755 index 000000000..10fa14c5a Binary files /dev/null and b/tests/resources/testrepo_256.git/hooks/prepare-commit-msg.sample differ diff --git a/tests/resources/testrepo_256.git/hooks/push-to-checkout.sample b/tests/resources/testrepo_256.git/hooks/push-to-checkout.sample new file mode 100755 index 000000000..af5a0c001 Binary files /dev/null and b/tests/resources/testrepo_256.git/hooks/push-to-checkout.sample differ diff --git a/tests/resources/testrepo_256.git/hooks/update.sample b/tests/resources/testrepo_256.git/hooks/update.sample new file mode 100755 index 000000000..c4d426bc6 Binary files /dev/null and b/tests/resources/testrepo_256.git/hooks/update.sample differ diff --git a/tests/resources/testrepo_256.git/index b/tests/resources/testrepo_256.git/index new file mode 100644 index 000000000..838e73883 Binary files /dev/null and b/tests/resources/testrepo_256.git/index differ diff --git a/tests/resources/testrepo_256.git/info/exclude b/tests/resources/testrepo_256.git/info/exclude new file mode 100644 index 000000000..a5196d1be Binary files /dev/null and b/tests/resources/testrepo_256.git/info/exclude differ diff --git a/tests/resources/testrepo_256.git/logs/HEAD b/tests/resources/testrepo_256.git/logs/HEAD new file mode 100644 index 000000000..59a4bb5f0 Binary files /dev/null and b/tests/resources/testrepo_256.git/logs/HEAD differ diff --git a/tests/resources/testrepo_256.git/logs/refs/heads/br2 b/tests/resources/testrepo_256.git/logs/refs/heads/br2 new file mode 100644 index 000000000..e8ada8193 Binary files /dev/null and b/tests/resources/testrepo_256.git/logs/refs/heads/br2 differ diff --git a/tests/resources/testrepo_256.git/logs/refs/heads/master b/tests/resources/testrepo_256.git/logs/refs/heads/master new file mode 100644 index 000000000..4b4c53f42 Binary files /dev/null and b/tests/resources/testrepo_256.git/logs/refs/heads/master differ diff --git a/tests/resources/testrepo_256.git/logs/refs/heads/not-good b/tests/resources/testrepo_256.git/logs/refs/heads/not-good new file mode 100644 index 000000000..6bac45bec Binary files /dev/null and b/tests/resources/testrepo_256.git/logs/refs/heads/not-good differ diff --git a/tests/resources/testrepo_256.git/logs/refs/heads/with-empty-log b/tests/resources/testrepo_256.git/logs/refs/heads/with-empty-log new file mode 100644 index 000000000..e69de29bb diff --git a/tests/resources/testrepo_256.git/logs/refs/remotes/origin/HEAD b/tests/resources/testrepo_256.git/logs/refs/remotes/origin/HEAD new file mode 100644 index 000000000..c1c020cff Binary files /dev/null and b/tests/resources/testrepo_256.git/logs/refs/remotes/origin/HEAD differ diff --git a/tests/resources/testrepo_256.git/logs/refs/remotes/test/master b/tests/resources/testrepo_256.git/logs/refs/remotes/test/master new file mode 100644 index 000000000..42bdaa27f Binary files /dev/null and b/tests/resources/testrepo_256.git/logs/refs/remotes/test/master differ diff --git a/tests/resources/testrepo_256.git/object-idx b/tests/resources/testrepo_256.git/object-idx new file mode 100644 index 000000000..c4ce7c4bf Binary files /dev/null and b/tests/resources/testrepo_256.git/object-idx differ diff --git a/tests/resources/testrepo_256.git/objects/00/404e6179d86039bbc01a925bdc34ccdab778bd1d824f5562aaa319c6c8f045 b/tests/resources/testrepo_256.git/objects/00/404e6179d86039bbc01a925bdc34ccdab778bd1d824f5562aaa319c6c8f045 new file mode 100644 index 000000000..8d8d1d8e8 Binary files /dev/null and b/tests/resources/testrepo_256.git/objects/00/404e6179d86039bbc01a925bdc34ccdab778bd1d824f5562aaa319c6c8f045 differ diff --git a/tests/resources/testrepo_256.git/objects/01/18010feb81fe41b9df646d13866742a9070b56fd0ba9ab8dff828fc36c1f78 b/tests/resources/testrepo_256.git/objects/01/18010feb81fe41b9df646d13866742a9070b56fd0ba9ab8dff828fc36c1f78 new file mode 100644 index 000000000..c7fbd7e9e Binary files /dev/null and b/tests/resources/testrepo_256.git/objects/01/18010feb81fe41b9df646d13866742a9070b56fd0ba9ab8dff828fc36c1f78 differ diff --git a/tests/resources/testrepo_256.git/objects/02/df938cfb169b0b6ba0dd16acdd727ea9364f7d48c55afed2f7dd889804065b b/tests/resources/testrepo_256.git/objects/02/df938cfb169b0b6ba0dd16acdd727ea9364f7d48c55afed2f7dd889804065b new file mode 100644 index 000000000..cdfafaca7 Binary files /dev/null and b/tests/resources/testrepo_256.git/objects/02/df938cfb169b0b6ba0dd16acdd727ea9364f7d48c55afed2f7dd889804065b differ diff --git a/tests/resources/testrepo_256.git/objects/05/f7b70a01b0ade8afa5a5fcd19f12cc38faf337d10ec03ef4363d1a86f63750 b/tests/resources/testrepo_256.git/objects/05/f7b70a01b0ade8afa5a5fcd19f12cc38faf337d10ec03ef4363d1a86f63750 new file mode 100644 index 000000000..b135eccda Binary files /dev/null and b/tests/resources/testrepo_256.git/objects/05/f7b70a01b0ade8afa5a5fcd19f12cc38faf337d10ec03ef4363d1a86f63750 differ diff --git a/tests/resources/testrepo_256.git/objects/14/bd335f9d7188c778d44eba8801fe9bda46b66593291f5b9f7cd5f8888af12f b/tests/resources/testrepo_256.git/objects/14/bd335f9d7188c778d44eba8801fe9bda46b66593291f5b9f7cd5f8888af12f new file mode 100644 index 000000000..58b2d0932 Binary files /dev/null and b/tests/resources/testrepo_256.git/objects/14/bd335f9d7188c778d44eba8801fe9bda46b66593291f5b9f7cd5f8888af12f differ diff --git a/tests/resources/testrepo_256.git/objects/17/9496410f66032c03bd2b7e8ddfc9c8c47820fab5615cc04d904989ce800498 b/tests/resources/testrepo_256.git/objects/17/9496410f66032c03bd2b7e8ddfc9c8c47820fab5615cc04d904989ce800498 new file mode 100644 index 000000000..97157644b Binary files /dev/null and b/tests/resources/testrepo_256.git/objects/17/9496410f66032c03bd2b7e8ddfc9c8c47820fab5615cc04d904989ce800498 differ diff --git a/tests/resources/testrepo_256.git/objects/19/0a1349522cc11f8682e34acca4ce4e1ea8508dfd77c24cefd461b65cead09e b/tests/resources/testrepo_256.git/objects/19/0a1349522cc11f8682e34acca4ce4e1ea8508dfd77c24cefd461b65cead09e new file mode 100644 index 000000000..554d191b3 Binary files /dev/null and b/tests/resources/testrepo_256.git/objects/19/0a1349522cc11f8682e34acca4ce4e1ea8508dfd77c24cefd461b65cead09e differ diff --git a/tests/resources/testrepo_256.git/objects/1b/4b74772bd83ff28bf44cda9be93f4afc2279623bb5b36c9194a660b7623c24 b/tests/resources/testrepo_256.git/objects/1b/4b74772bd83ff28bf44cda9be93f4afc2279623bb5b36c9194a660b7623c24 new file mode 100644 index 000000000..d5c518ecc Binary files /dev/null and b/tests/resources/testrepo_256.git/objects/1b/4b74772bd83ff28bf44cda9be93f4afc2279623bb5b36c9194a660b7623c24 differ diff --git a/tests/resources/testrepo_256.git/objects/21/e1e1ebe45b2c1ef79ab050334e36a8015a546f0740bea4505e10d81a946f61 b/tests/resources/testrepo_256.git/objects/21/e1e1ebe45b2c1ef79ab050334e36a8015a546f0740bea4505e10d81a946f61 new file mode 100644 index 000000000..31aa9e5f5 Binary files /dev/null and b/tests/resources/testrepo_256.git/objects/21/e1e1ebe45b2c1ef79ab050334e36a8015a546f0740bea4505e10d81a946f61 differ diff --git a/tests/resources/testrepo_256.git/objects/23/8a501cf11a036f2f248008d88e14af624bb07fced6390997a0fa6abdad950a b/tests/resources/testrepo_256.git/objects/23/8a501cf11a036f2f248008d88e14af624bb07fced6390997a0fa6abdad950a new file mode 100644 index 000000000..66dc15db4 Binary files /dev/null and b/tests/resources/testrepo_256.git/objects/23/8a501cf11a036f2f248008d88e14af624bb07fced6390997a0fa6abdad950a differ diff --git a/tests/resources/testrepo_256.git/objects/26/149bf1ac4612f24b532ae50a12b15f26aace3718749624f008bde68670352a b/tests/resources/testrepo_256.git/objects/26/149bf1ac4612f24b532ae50a12b15f26aace3718749624f008bde68670352a new file mode 100644 index 000000000..bee6a42d7 Binary files /dev/null and b/tests/resources/testrepo_256.git/objects/26/149bf1ac4612f24b532ae50a12b15f26aace3718749624f008bde68670352a differ diff --git a/tests/resources/testrepo_256.git/objects/2d/b6069c27ca4c08b784048644c307e17d0afe29b55f6488398cb59f13feb2f2 b/tests/resources/testrepo_256.git/objects/2d/b6069c27ca4c08b784048644c307e17d0afe29b55f6488398cb59f13feb2f2 new file mode 100644 index 000000000..3dfd5463b Binary files /dev/null and b/tests/resources/testrepo_256.git/objects/2d/b6069c27ca4c08b784048644c307e17d0afe29b55f6488398cb59f13feb2f2 differ diff --git a/tests/resources/testrepo_256.git/objects/33/e415b835a670bb5c3c760efa0433ac0cbd2d44679f68f2df3a9ae7014cf2a8 b/tests/resources/testrepo_256.git/objects/33/e415b835a670bb5c3c760efa0433ac0cbd2d44679f68f2df3a9ae7014cf2a8 new file mode 100644 index 000000000..cedb2a22e Binary files /dev/null and b/tests/resources/testrepo_256.git/objects/33/e415b835a670bb5c3c760efa0433ac0cbd2d44679f68f2df3a9ae7014cf2a8 differ diff --git a/tests/resources/testrepo_256.git/objects/34/f79ad1c813b93d2ee11c830c2134815a31d9629e6aa9773338fedaab90976b b/tests/resources/testrepo_256.git/objects/34/f79ad1c813b93d2ee11c830c2134815a31d9629e6aa9773338fedaab90976b new file mode 100644 index 000000000..3abc52f41 Binary files /dev/null and b/tests/resources/testrepo_256.git/objects/34/f79ad1c813b93d2ee11c830c2134815a31d9629e6aa9773338fedaab90976b differ diff --git a/tests/resources/testrepo_256.git/objects/36/eac24505d4c4405864ccf2f30d79af178374166daeceefbf11e2f058d30d60 b/tests/resources/testrepo_256.git/objects/36/eac24505d4c4405864ccf2f30d79af178374166daeceefbf11e2f058d30d60 new file mode 100644 index 000000000..df40d99af Binary files /dev/null and b/tests/resources/testrepo_256.git/objects/36/eac24505d4c4405864ccf2f30d79af178374166daeceefbf11e2f058d30d60 differ diff --git a/tests/resources/testrepo_256.git/objects/39/bf1ac28cc3f8432ba7cfeeca6bfffd9a0fe641784db85de2eb0f57b7553869 b/tests/resources/testrepo_256.git/objects/39/bf1ac28cc3f8432ba7cfeeca6bfffd9a0fe641784db85de2eb0f57b7553869 new file mode 100644 index 000000000..c05cacfed Binary files /dev/null and b/tests/resources/testrepo_256.git/objects/39/bf1ac28cc3f8432ba7cfeeca6bfffd9a0fe641784db85de2eb0f57b7553869 differ diff --git a/tests/resources/testrepo_256.git/objects/3b/58565ee067f13349cd4f89aa396d10f71c69e168d5c48ea23de59734ec3ab1 b/tests/resources/testrepo_256.git/objects/3b/58565ee067f13349cd4f89aa396d10f71c69e168d5c48ea23de59734ec3ab1 new file mode 100644 index 000000000..1b299dc25 Binary files /dev/null and b/tests/resources/testrepo_256.git/objects/3b/58565ee067f13349cd4f89aa396d10f71c69e168d5c48ea23de59734ec3ab1 differ diff --git a/tests/resources/testrepo_256.git/objects/43/e084a4599ca42c476919917e3db8fde0045ee66305fd5e634b0c793c536a1b b/tests/resources/testrepo_256.git/objects/43/e084a4599ca42c476919917e3db8fde0045ee66305fd5e634b0c793c536a1b new file mode 100644 index 000000000..2acf1b607 Binary files /dev/null and b/tests/resources/testrepo_256.git/objects/43/e084a4599ca42c476919917e3db8fde0045ee66305fd5e634b0c793c536a1b differ diff --git a/tests/resources/testrepo_256.git/objects/47/3a0f4c3be8a93681a267e3b1e9a7dcda1185436fe141f7749120a303721813 b/tests/resources/testrepo_256.git/objects/47/3a0f4c3be8a93681a267e3b1e9a7dcda1185436fe141f7749120a303721813 new file mode 100644 index 000000000..711223894 Binary files /dev/null and b/tests/resources/testrepo_256.git/objects/47/3a0f4c3be8a93681a267e3b1e9a7dcda1185436fe141f7749120a303721813 differ diff --git a/tests/resources/testrepo_256.git/objects/4b/c142808884e472ee6cc331b132e66ef18f564d41efb055804ec1dd28efb3f5 b/tests/resources/testrepo_256.git/objects/4b/c142808884e472ee6cc331b132e66ef18f564d41efb055804ec1dd28efb3f5 new file mode 100644 index 000000000..d0d7e736e Binary files /dev/null and b/tests/resources/testrepo_256.git/objects/4b/c142808884e472ee6cc331b132e66ef18f564d41efb055804ec1dd28efb3f5 differ diff --git a/tests/resources/testrepo_256.git/objects/4d/f8ed86acaac5dc82b5652170996ce459d39e3a441e9759b635b0bc4ecc43fd b/tests/resources/testrepo_256.git/objects/4d/f8ed86acaac5dc82b5652170996ce459d39e3a441e9759b635b0bc4ecc43fd new file mode 100644 index 000000000..8dc193282 Binary files /dev/null and b/tests/resources/testrepo_256.git/objects/4d/f8ed86acaac5dc82b5652170996ce459d39e3a441e9759b635b0bc4ecc43fd differ diff --git a/tests/resources/testrepo_256.git/objects/5a/2d5699fea33657b42ba98c22b7898baaa0eda205a21cafdcb7e0f94b07bb9b b/tests/resources/testrepo_256.git/objects/5a/2d5699fea33657b42ba98c22b7898baaa0eda205a21cafdcb7e0f94b07bb9b new file mode 100644 index 000000000..dd9931316 Binary files /dev/null and b/tests/resources/testrepo_256.git/objects/5a/2d5699fea33657b42ba98c22b7898baaa0eda205a21cafdcb7e0f94b07bb9b differ diff --git a/tests/resources/testrepo_256.git/objects/5c/a8959deb2b8327458e0344523eb1ddeeef4bce03e35864640b452f84d26848 b/tests/resources/testrepo_256.git/objects/5c/a8959deb2b8327458e0344523eb1ddeeef4bce03e35864640b452f84d26848 new file mode 100644 index 000000000..39e27c06a Binary files /dev/null and b/tests/resources/testrepo_256.git/objects/5c/a8959deb2b8327458e0344523eb1ddeeef4bce03e35864640b452f84d26848 differ diff --git a/tests/resources/testrepo_256.git/objects/5d/bb1fff5c0094b31b25b4635ab9fbee66d65fe5dda47dd0ac5f01dd69a84c6f b/tests/resources/testrepo_256.git/objects/5d/bb1fff5c0094b31b25b4635ab9fbee66d65fe5dda47dd0ac5f01dd69a84c6f new file mode 100644 index 000000000..17fae64f4 Binary files /dev/null and b/tests/resources/testrepo_256.git/objects/5d/bb1fff5c0094b31b25b4635ab9fbee66d65fe5dda47dd0ac5f01dd69a84c6f differ diff --git a/tests/resources/testrepo_256.git/objects/61/489e9e831f1d9001084d39b79f964c293db8620d679ea3596673c8a326446e b/tests/resources/testrepo_256.git/objects/61/489e9e831f1d9001084d39b79f964c293db8620d679ea3596673c8a326446e new file mode 100644 index 000000000..0bece845b Binary files /dev/null and b/tests/resources/testrepo_256.git/objects/61/489e9e831f1d9001084d39b79f964c293db8620d679ea3596673c8a326446e differ diff --git a/tests/resources/testrepo_256.git/objects/6d/5fd291bb0f67444e99ab492f1bf1fcdf5dca09dab24cf331e05111b4cfc1a3 b/tests/resources/testrepo_256.git/objects/6d/5fd291bb0f67444e99ab492f1bf1fcdf5dca09dab24cf331e05111b4cfc1a3 new file mode 100644 index 000000000..112998d42 Binary files /dev/null and b/tests/resources/testrepo_256.git/objects/6d/5fd291bb0f67444e99ab492f1bf1fcdf5dca09dab24cf331e05111b4cfc1a3 differ diff --git a/tests/resources/testrepo_256.git/objects/70/30f925768d9beb65654ab8f436e3ca0a82b25eddefd237bf5a26a0441c2aa7 b/tests/resources/testrepo_256.git/objects/70/30f925768d9beb65654ab8f436e3ca0a82b25eddefd237bf5a26a0441c2aa7 new file mode 100644 index 000000000..860cad13c Binary files /dev/null and b/tests/resources/testrepo_256.git/objects/70/30f925768d9beb65654ab8f436e3ca0a82b25eddefd237bf5a26a0441c2aa7 differ diff --git a/tests/resources/testrepo_256.git/objects/73/8ff86401dbc5af692c83e660a4d510603c3f36e782a1a32ebd0388db6411ed b/tests/resources/testrepo_256.git/objects/73/8ff86401dbc5af692c83e660a4d510603c3f36e782a1a32ebd0388db6411ed new file mode 100644 index 000000000..4c973ea83 Binary files /dev/null and b/tests/resources/testrepo_256.git/objects/73/8ff86401dbc5af692c83e660a4d510603c3f36e782a1a32ebd0388db6411ed differ diff --git a/tests/resources/testrepo_256.git/objects/73/b4f3c4f3182e6c8dd2c98aeb2c7811556538e7673e4b325307c71685fbf5b6 b/tests/resources/testrepo_256.git/objects/73/b4f3c4f3182e6c8dd2c98aeb2c7811556538e7673e4b325307c71685fbf5b6 new file mode 100644 index 000000000..67b84c462 Binary files /dev/null and b/tests/resources/testrepo_256.git/objects/73/b4f3c4f3182e6c8dd2c98aeb2c7811556538e7673e4b325307c71685fbf5b6 differ diff --git a/tests/resources/testrepo_256.git/objects/7e/4633ae1b0e83503dbea4417f9d5ccaf22b877c5a4522b6d1d2b16090ee2f6f b/tests/resources/testrepo_256.git/objects/7e/4633ae1b0e83503dbea4417f9d5ccaf22b877c5a4522b6d1d2b16090ee2f6f new file mode 100644 index 000000000..993a62b16 Binary files /dev/null and b/tests/resources/testrepo_256.git/objects/7e/4633ae1b0e83503dbea4417f9d5ccaf22b877c5a4522b6d1d2b16090ee2f6f differ diff --git a/tests/resources/testrepo_256.git/objects/7e/9424c06052ca33bfc599bccadee60065d8664a9af7648a1455100c4f772e1c b/tests/resources/testrepo_256.git/objects/7e/9424c06052ca33bfc599bccadee60065d8664a9af7648a1455100c4f772e1c new file mode 100644 index 000000000..70bf64e16 Binary files /dev/null and b/tests/resources/testrepo_256.git/objects/7e/9424c06052ca33bfc599bccadee60065d8664a9af7648a1455100c4f772e1c differ diff --git a/tests/resources/testrepo_256.git/objects/80/91b686de8bf697ef632dda9b3179f2419717275e3bfd2055b303489dbbfa47 b/tests/resources/testrepo_256.git/objects/80/91b686de8bf697ef632dda9b3179f2419717275e3bfd2055b303489dbbfa47 new file mode 100644 index 000000000..dec3810fa Binary files /dev/null and b/tests/resources/testrepo_256.git/objects/80/91b686de8bf697ef632dda9b3179f2419717275e3bfd2055b303489dbbfa47 differ diff --git a/tests/resources/testrepo_256.git/objects/81/55958bbda08eed88c8ac908dc44452ed38911cffa54ccc06076f30a1ffb1bf b/tests/resources/testrepo_256.git/objects/81/55958bbda08eed88c8ac908dc44452ed38911cffa54ccc06076f30a1ffb1bf new file mode 100644 index 000000000..e610e3be8 Binary files /dev/null and b/tests/resources/testrepo_256.git/objects/81/55958bbda08eed88c8ac908dc44452ed38911cffa54ccc06076f30a1ffb1bf differ diff --git a/tests/resources/testrepo_256.git/objects/90/1505c3355518bee35475c5d3f23bac1dded688b2bd314cc32b7f157e100724 b/tests/resources/testrepo_256.git/objects/90/1505c3355518bee35475c5d3f23bac1dded688b2bd314cc32b7f157e100724 new file mode 100644 index 000000000..09d0abfa7 Binary files /dev/null and b/tests/resources/testrepo_256.git/objects/90/1505c3355518bee35475c5d3f23bac1dded688b2bd314cc32b7f157e100724 differ diff --git a/tests/resources/testrepo_256.git/objects/93/1093620e5f050e2127fb0b96786ebaa9ee6535fb698ec01b5f7a800fa27cbe b/tests/resources/testrepo_256.git/objects/93/1093620e5f050e2127fb0b96786ebaa9ee6535fb698ec01b5f7a800fa27cbe new file mode 100644 index 000000000..70431af81 Binary files /dev/null and b/tests/resources/testrepo_256.git/objects/93/1093620e5f050e2127fb0b96786ebaa9ee6535fb698ec01b5f7a800fa27cbe differ diff --git a/tests/resources/testrepo_256.git/objects/94/ed253efa9e86fc636805c294c441d08b89b455903c0c14e9b16587fec081f5 b/tests/resources/testrepo_256.git/objects/94/ed253efa9e86fc636805c294c441d08b89b455903c0c14e9b16587fec081f5 new file mode 100644 index 000000000..41bcd18af Binary files /dev/null and b/tests/resources/testrepo_256.git/objects/94/ed253efa9e86fc636805c294c441d08b89b455903c0c14e9b16587fec081f5 differ diff --git a/tests/resources/testrepo_256.git/objects/96/c18f0297e38d01f4b2dacddea4259aea6b2961eb0822bd2c0c3f6029030045 b/tests/resources/testrepo_256.git/objects/96/c18f0297e38d01f4b2dacddea4259aea6b2961eb0822bd2c0c3f6029030045 new file mode 100644 index 000000000..7ca4ceed5 Binary files /dev/null and b/tests/resources/testrepo_256.git/objects/96/c18f0297e38d01f4b2dacddea4259aea6b2961eb0822bd2c0c3f6029030045 differ diff --git a/tests/resources/testrepo_256.git/objects/9c/cfa556cd7f73b426a7bedb7fc3a850e94f8c5ac1d71b9afa365a89005aff54 b/tests/resources/testrepo_256.git/objects/9c/cfa556cd7f73b426a7bedb7fc3a850e94f8c5ac1d71b9afa365a89005aff54 new file mode 100644 index 000000000..6e585cdb2 Binary files /dev/null and b/tests/resources/testrepo_256.git/objects/9c/cfa556cd7f73b426a7bedb7fc3a850e94f8c5ac1d71b9afa365a89005aff54 differ diff --git a/tests/resources/testrepo_256.git/objects/9d/aab17c25f647d652c72c8cc3cf4602c270a369beebc7d0b67238897bbc426b b/tests/resources/testrepo_256.git/objects/9d/aab17c25f647d652c72c8cc3cf4602c270a369beebc7d0b67238897bbc426b new file mode 100644 index 000000000..74b8385ed Binary files /dev/null and b/tests/resources/testrepo_256.git/objects/9d/aab17c25f647d652c72c8cc3cf4602c270a369beebc7d0b67238897bbc426b differ diff --git a/tests/resources/testrepo_256.git/objects/a4/813ef6708e6011e8187224297e83e4a285f58bf5eabb1db270351388603c95 b/tests/resources/testrepo_256.git/objects/a4/813ef6708e6011e8187224297e83e4a285f58bf5eabb1db270351388603c95 new file mode 100644 index 000000000..2419974cb Binary files /dev/null and b/tests/resources/testrepo_256.git/objects/a4/813ef6708e6011e8187224297e83e4a285f58bf5eabb1db270351388603c95 differ diff --git a/tests/resources/testrepo_256.git/objects/ab/ee32b3339d1566d75613ea61f40c14bdfc5b101b60fde4f44b58dd06667640 b/tests/resources/testrepo_256.git/objects/ab/ee32b3339d1566d75613ea61f40c14bdfc5b101b60fde4f44b58dd06667640 new file mode 100644 index 000000000..b390250e3 Binary files /dev/null and b/tests/resources/testrepo_256.git/objects/ab/ee32b3339d1566d75613ea61f40c14bdfc5b101b60fde4f44b58dd06667640 differ diff --git a/tests/resources/testrepo_256.git/objects/ae/a29dc305d40e362df25c3fdeed5502fd56b182af01b7740d297a24459333c5 b/tests/resources/testrepo_256.git/objects/ae/a29dc305d40e362df25c3fdeed5502fd56b182af01b7740d297a24459333c5 new file mode 100644 index 000000000..18a7f61c2 Binary files /dev/null and b/tests/resources/testrepo_256.git/objects/ae/a29dc305d40e362df25c3fdeed5502fd56b182af01b7740d297a24459333c5 differ diff --git a/tests/resources/testrepo_256.git/objects/b1/95873b48c824d995c974a3497ade7f62d2cd818bf388775cfa721de4068ebd b/tests/resources/testrepo_256.git/objects/b1/95873b48c824d995c974a3497ade7f62d2cd818bf388775cfa721de4068ebd new file mode 100644 index 000000000..d1c032fce Binary files /dev/null and b/tests/resources/testrepo_256.git/objects/b1/95873b48c824d995c974a3497ade7f62d2cd818bf388775cfa721de4068ebd differ diff --git a/tests/resources/testrepo_256.git/objects/b2/1c8c27a05a3f0bf9f0f44ebf05e11d9c591b04cfdaff7cc860310356d71827 b/tests/resources/testrepo_256.git/objects/b2/1c8c27a05a3f0bf9f0f44ebf05e11d9c591b04cfdaff7cc860310356d71827 new file mode 100644 index 000000000..c6da2ff7a Binary files /dev/null and b/tests/resources/testrepo_256.git/objects/b2/1c8c27a05a3f0bf9f0f44ebf05e11d9c591b04cfdaff7cc860310356d71827 differ diff --git a/tests/resources/testrepo_256.git/objects/b6/1b940a8cd979a32e005682c5c09c22053675e2db24ea6b4b28cc75e9c10890 b/tests/resources/testrepo_256.git/objects/b6/1b940a8cd979a32e005682c5c09c22053675e2db24ea6b4b28cc75e9c10890 new file mode 100644 index 000000000..b1df3bdd5 Binary files /dev/null and b/tests/resources/testrepo_256.git/objects/b6/1b940a8cd979a32e005682c5c09c22053675e2db24ea6b4b28cc75e9c10890 differ diff --git a/tests/resources/testrepo_256.git/objects/b8/3624f6ac0995273c0034a7ab8c68929bdc91b69ad54ef94979b93eba3f6022 b/tests/resources/testrepo_256.git/objects/b8/3624f6ac0995273c0034a7ab8c68929bdc91b69ad54ef94979b93eba3f6022 new file mode 100644 index 000000000..3e36331ea Binary files /dev/null and b/tests/resources/testrepo_256.git/objects/b8/3624f6ac0995273c0034a7ab8c68929bdc91b69ad54ef94979b93eba3f6022 differ diff --git a/tests/resources/testrepo_256.git/objects/bd/f2066a28e11603a1af04157ee4aad97814279fe500340eb3465797cbd3be23 b/tests/resources/testrepo_256.git/objects/bd/f2066a28e11603a1af04157ee4aad97814279fe500340eb3465797cbd3be23 new file mode 100644 index 000000000..9bb5b623b Binary files /dev/null and b/tests/resources/testrepo_256.git/objects/bd/f2066a28e11603a1af04157ee4aad97814279fe500340eb3465797cbd3be23 differ diff --git a/tests/resources/testrepo_256.git/objects/bf/a3b3b9a161d354e2254a444b12c412210e9689c17e51bfc318ce4bb4360f19 b/tests/resources/testrepo_256.git/objects/bf/a3b3b9a161d354e2254a444b12c412210e9689c17e51bfc318ce4bb4360f19 new file mode 100644 index 000000000..3cbf7e6b7 Binary files /dev/null and b/tests/resources/testrepo_256.git/objects/bf/a3b3b9a161d354e2254a444b12c412210e9689c17e51bfc318ce4bb4360f19 differ diff --git a/tests/resources/testrepo_256.git/objects/bf/cc4074ac517ed24d61b0aaa96359f304c3dc97e95f336269ed474ea846ada5 b/tests/resources/testrepo_256.git/objects/bf/cc4074ac517ed24d61b0aaa96359f304c3dc97e95f336269ed474ea846ada5 new file mode 100644 index 000000000..be8b99bba Binary files /dev/null and b/tests/resources/testrepo_256.git/objects/bf/cc4074ac517ed24d61b0aaa96359f304c3dc97e95f336269ed474ea846ada5 differ diff --git a/tests/resources/testrepo_256.git/objects/c2/58f010a08328a29cde33411d955520e0375fcbbcc14b7636a70f7536c32ef6 b/tests/resources/testrepo_256.git/objects/c2/58f010a08328a29cde33411d955520e0375fcbbcc14b7636a70f7536c32ef6 new file mode 100644 index 000000000..9d2ceb1ff Binary files /dev/null and b/tests/resources/testrepo_256.git/objects/c2/58f010a08328a29cde33411d955520e0375fcbbcc14b7636a70f7536c32ef6 differ diff --git a/tests/resources/testrepo_256.git/objects/ca/31f7336e882a233a2943787c5e94ba024ac9a4f763cb1d9bfd8e63aa7f7269 b/tests/resources/testrepo_256.git/objects/ca/31f7336e882a233a2943787c5e94ba024ac9a4f763cb1d9bfd8e63aa7f7269 new file mode 100644 index 000000000..cfcdac306 Binary files /dev/null and b/tests/resources/testrepo_256.git/objects/ca/31f7336e882a233a2943787c5e94ba024ac9a4f763cb1d9bfd8e63aa7f7269 differ diff --git a/tests/resources/testrepo_256.git/objects/cb/282e7c15fd8aeb2265cd621f5a228cb33dc84192980ca426cf9ab2a48cb9f0 b/tests/resources/testrepo_256.git/objects/cb/282e7c15fd8aeb2265cd621f5a228cb33dc84192980ca426cf9ab2a48cb9f0 new file mode 100644 index 000000000..77d9ec27d Binary files /dev/null and b/tests/resources/testrepo_256.git/objects/cb/282e7c15fd8aeb2265cd621f5a228cb33dc84192980ca426cf9ab2a48cb9f0 differ diff --git a/tests/resources/testrepo_256.git/objects/cc/b5a03da85607c230d111abfa899655d1b00e6529101a40d42f6acb059dff9f b/tests/resources/testrepo_256.git/objects/cc/b5a03da85607c230d111abfa899655d1b00e6529101a40d42f6acb059dff9f new file mode 100644 index 000000000..a67d6e647 Binary files /dev/null and b/tests/resources/testrepo_256.git/objects/cc/b5a03da85607c230d111abfa899655d1b00e6529101a40d42f6acb059dff9f differ diff --git a/tests/resources/testrepo_256.git/objects/cf/84e5be57f8d5d51f136d3d137b654c602721c469c1b0a58e7e95647a9cf1c0 b/tests/resources/testrepo_256.git/objects/cf/84e5be57f8d5d51f136d3d137b654c602721c469c1b0a58e7e95647a9cf1c0 new file mode 100644 index 000000000..ec37060e3 Binary files /dev/null and b/tests/resources/testrepo_256.git/objects/cf/84e5be57f8d5d51f136d3d137b654c602721c469c1b0a58e7e95647a9cf1c0 differ diff --git a/tests/resources/testrepo_256.git/objects/d8/8b60d2641df3656381dc8e201abb820a414de03eb63c065b06a2ab37d3f5ca b/tests/resources/testrepo_256.git/objects/d8/8b60d2641df3656381dc8e201abb820a414de03eb63c065b06a2ab37d3f5ca new file mode 100644 index 000000000..6845087e5 Binary files /dev/null and b/tests/resources/testrepo_256.git/objects/d8/8b60d2641df3656381dc8e201abb820a414de03eb63c065b06a2ab37d3f5ca differ diff --git a/tests/resources/testrepo_256.git/objects/de/caff3051968d1f3a2defd3d4a80ced03101555e1fd8913b3544026c0717d4f b/tests/resources/testrepo_256.git/objects/de/caff3051968d1f3a2defd3d4a80ced03101555e1fd8913b3544026c0717d4f new file mode 100644 index 000000000..a53ab84cf Binary files /dev/null and b/tests/resources/testrepo_256.git/objects/de/caff3051968d1f3a2defd3d4a80ced03101555e1fd8913b3544026c0717d4f differ diff --git a/tests/resources/testrepo_256.git/objects/eb/ead5965196dfaeab52b1a5d92b78e54493fdaa78f72268d4cc69b61d5feee1 b/tests/resources/testrepo_256.git/objects/eb/ead5965196dfaeab52b1a5d92b78e54493fdaa78f72268d4cc69b61d5feee1 new file mode 100644 index 000000000..225c45734 Binary files /dev/null and b/tests/resources/testrepo_256.git/objects/eb/ead5965196dfaeab52b1a5d92b78e54493fdaa78f72268d4cc69b61d5feee1 differ diff --git a/tests/resources/testrepo_256.git/objects/f2/a108f86a3b4fd9ad75ed55e9cb3cb46e348fca3b9dba3db64f7c9f64b8a736 b/tests/resources/testrepo_256.git/objects/f2/a108f86a3b4fd9ad75ed55e9cb3cb46e348fca3b9dba3db64f7c9f64b8a736 new file mode 100644 index 000000000..58d51e502 Binary files /dev/null and b/tests/resources/testrepo_256.git/objects/f2/a108f86a3b4fd9ad75ed55e9cb3cb46e348fca3b9dba3db64f7c9f64b8a736 differ diff --git a/tests/resources/testrepo_256.git/objects/f2/c8da1a7c2eb49ff25c47441f0b3f387faeddde1b37d0ad2f3f6a63f5327978 b/tests/resources/testrepo_256.git/objects/f2/c8da1a7c2eb49ff25c47441f0b3f387faeddde1b37d0ad2f3f6a63f5327978 new file mode 100644 index 000000000..04bf5eb06 Binary files /dev/null and b/tests/resources/testrepo_256.git/objects/f2/c8da1a7c2eb49ff25c47441f0b3f387faeddde1b37d0ad2f3f6a63f5327978 differ diff --git a/tests/resources/testrepo_256.git/objects/f3/1459efb9367c5a19c9dd24c75107423d5773066922ea5e55eaeb6490979562 b/tests/resources/testrepo_256.git/objects/f3/1459efb9367c5a19c9dd24c75107423d5773066922ea5e55eaeb6490979562 new file mode 100644 index 000000000..37a289ecc Binary files /dev/null and b/tests/resources/testrepo_256.git/objects/f3/1459efb9367c5a19c9dd24c75107423d5773066922ea5e55eaeb6490979562 differ diff --git a/tests/resources/testrepo_256.git/objects/pack/pack-b87f1f214098b19ce092afb9ef6e7643653c03e7f91faa27b767e3eb8225f0f6.idx b/tests/resources/testrepo_256.git/objects/pack/pack-b87f1f214098b19ce092afb9ef6e7643653c03e7f91faa27b767e3eb8225f0f6.idx new file mode 100644 index 000000000..897e8a478 Binary files /dev/null and b/tests/resources/testrepo_256.git/objects/pack/pack-b87f1f214098b19ce092afb9ef6e7643653c03e7f91faa27b767e3eb8225f0f6.idx differ diff --git a/tests/resources/testrepo_256.git/objects/pack/pack-b87f1f214098b19ce092afb9ef6e7643653c03e7f91faa27b767e3eb8225f0f6.pack b/tests/resources/testrepo_256.git/objects/pack/pack-b87f1f214098b19ce092afb9ef6e7643653c03e7f91faa27b767e3eb8225f0f6.pack new file mode 100644 index 000000000..9c8557886 Binary files /dev/null and b/tests/resources/testrepo_256.git/objects/pack/pack-b87f1f214098b19ce092afb9ef6e7643653c03e7f91faa27b767e3eb8225f0f6.pack differ diff --git a/tests/resources/testrepo_256.git/objects/pack/pack-e2f07f30db7e480ea84a0e64ee791b9b270067124b2609019b74f33f256f33fa.idx b/tests/resources/testrepo_256.git/objects/pack/pack-e2f07f30db7e480ea84a0e64ee791b9b270067124b2609019b74f33f256f33fa.idx new file mode 100644 index 000000000..9e2ec99c5 Binary files /dev/null and b/tests/resources/testrepo_256.git/objects/pack/pack-e2f07f30db7e480ea84a0e64ee791b9b270067124b2609019b74f33f256f33fa.idx differ diff --git a/tests/resources/testrepo_256.git/objects/pack/pack-e2f07f30db7e480ea84a0e64ee791b9b270067124b2609019b74f33f256f33fa.pack b/tests/resources/testrepo_256.git/objects/pack/pack-e2f07f30db7e480ea84a0e64ee791b9b270067124b2609019b74f33f256f33fa.pack new file mode 100644 index 000000000..66cd292a2 Binary files /dev/null and b/tests/resources/testrepo_256.git/objects/pack/pack-e2f07f30db7e480ea84a0e64ee791b9b270067124b2609019b74f33f256f33fa.pack differ diff --git a/tests/resources/testrepo_256.git/objects/pack/pack-f72bbfa35af982c2a60735152c80b24ee981cf102db76764c383f9b87935d0d3.idx b/tests/resources/testrepo_256.git/objects/pack/pack-f72bbfa35af982c2a60735152c80b24ee981cf102db76764c383f9b87935d0d3.idx new file mode 100644 index 000000000..1d197e870 Binary files /dev/null and b/tests/resources/testrepo_256.git/objects/pack/pack-f72bbfa35af982c2a60735152c80b24ee981cf102db76764c383f9b87935d0d3.idx differ diff --git a/tests/resources/testrepo_256.git/objects/pack/pack-f72bbfa35af982c2a60735152c80b24ee981cf102db76764c383f9b87935d0d3.pack b/tests/resources/testrepo_256.git/objects/pack/pack-f72bbfa35af982c2a60735152c80b24ee981cf102db76764c383f9b87935d0d3.pack new file mode 100644 index 000000000..5b615e15c Binary files /dev/null and b/tests/resources/testrepo_256.git/objects/pack/pack-f72bbfa35af982c2a60735152c80b24ee981cf102db76764c383f9b87935d0d3.pack differ diff --git a/tests/resources/testrepo_256.git/packed-refs b/tests/resources/testrepo_256.git/packed-refs new file mode 100644 index 000000000..995685f08 Binary files /dev/null and b/tests/resources/testrepo_256.git/packed-refs differ diff --git a/tests/resources/testrepo_256.git/refs/blobs/annotated_tag_to_blob b/tests/resources/testrepo_256.git/refs/blobs/annotated_tag_to_blob new file mode 100644 index 000000000..2723f8909 Binary files /dev/null and b/tests/resources/testrepo_256.git/refs/blobs/annotated_tag_to_blob differ diff --git a/tests/resources/testrepo_256.git/refs/heads/br2 b/tests/resources/testrepo_256.git/refs/heads/br2 new file mode 100644 index 000000000..2abd96e09 Binary files /dev/null and b/tests/resources/testrepo_256.git/refs/heads/br2 differ diff --git a/tests/resources/testrepo_256.git/refs/heads/cannot-fetch b/tests/resources/testrepo_256.git/refs/heads/cannot-fetch new file mode 100644 index 000000000..2abd96e09 Binary files /dev/null and b/tests/resources/testrepo_256.git/refs/heads/cannot-fetch differ diff --git a/tests/resources/testrepo_256.git/refs/heads/chomped b/tests/resources/testrepo_256.git/refs/heads/chomped new file mode 100644 index 000000000..de0d95305 Binary files /dev/null and b/tests/resources/testrepo_256.git/refs/heads/chomped differ diff --git a/tests/resources/testrepo_256.git/refs/heads/haacked b/tests/resources/testrepo_256.git/refs/heads/haacked new file mode 100644 index 000000000..5feda4d41 Binary files /dev/null and b/tests/resources/testrepo_256.git/refs/heads/haacked differ diff --git a/tests/resources/testrepo_256.git/refs/heads/master b/tests/resources/testrepo_256.git/refs/heads/master new file mode 100644 index 000000000..106231c4c Binary files /dev/null and b/tests/resources/testrepo_256.git/refs/heads/master differ diff --git a/tests/resources/testrepo_256.git/refs/heads/not-good b/tests/resources/testrepo_256.git/refs/heads/not-good new file mode 100644 index 000000000..106231c4c Binary files /dev/null and b/tests/resources/testrepo_256.git/refs/heads/not-good differ diff --git a/tests/resources/testrepo_256.git/refs/heads/packed-test b/tests/resources/testrepo_256.git/refs/heads/packed-test new file mode 100644 index 000000000..7c2c5e438 Binary files /dev/null and b/tests/resources/testrepo_256.git/refs/heads/packed-test differ diff --git a/tests/resources/testrepo_256.git/refs/heads/subtrees b/tests/resources/testrepo_256.git/refs/heads/subtrees new file mode 100644 index 000000000..3b352e1ad Binary files /dev/null and b/tests/resources/testrepo_256.git/refs/heads/subtrees differ diff --git a/tests/resources/testrepo_256.git/refs/heads/test b/tests/resources/testrepo_256.git/refs/heads/test new file mode 100644 index 000000000..de0d95305 Binary files /dev/null and b/tests/resources/testrepo_256.git/refs/heads/test differ diff --git a/tests/resources/testrepo_256.git/refs/heads/track-local b/tests/resources/testrepo_256.git/refs/heads/track-local new file mode 100644 index 000000000..8f6ecbe2b Binary files /dev/null and b/tests/resources/testrepo_256.git/refs/heads/track-local differ diff --git a/tests/resources/testrepo_256.git/refs/heads/trailing b/tests/resources/testrepo_256.git/refs/heads/trailing new file mode 100644 index 000000000..de0d95305 Binary files /dev/null and b/tests/resources/testrepo_256.git/refs/heads/trailing differ diff --git a/tests/resources/testrepo_256.git/refs/heads/with-empty-log b/tests/resources/testrepo_256.git/refs/heads/with-empty-log new file mode 100644 index 000000000..bd392a7d2 Binary files /dev/null and b/tests/resources/testrepo_256.git/refs/heads/with-empty-log differ diff --git a/tests/resources/testrepo_256.git/refs/notes/fanout b/tests/resources/testrepo_256.git/refs/notes/fanout new file mode 100644 index 000000000..307abb49c Binary files /dev/null and b/tests/resources/testrepo_256.git/refs/notes/fanout differ diff --git a/tests/resources/testrepo_256.git/refs/remotes/test/master b/tests/resources/testrepo_256.git/refs/remotes/test/master new file mode 100644 index 000000000..ee4aa140b Binary files /dev/null and b/tests/resources/testrepo_256.git/refs/remotes/test/master differ diff --git a/tests/resources/testrepo_256.git/refs/tags/annotated_tag_to_blob b/tests/resources/testrepo_256.git/refs/tags/annotated_tag_to_blob new file mode 100644 index 000000000..2723f8909 Binary files /dev/null and b/tests/resources/testrepo_256.git/refs/tags/annotated_tag_to_blob differ diff --git a/tests/resources/testrepo_256.git/refs/tags/e90810b b/tests/resources/testrepo_256.git/refs/tags/e90810b new file mode 100644 index 000000000..eb8846a05 Binary files /dev/null and b/tests/resources/testrepo_256.git/refs/tags/e90810b differ diff --git a/tests/resources/testrepo_256.git/refs/tags/hard_tag b/tests/resources/testrepo_256.git/refs/tags/hard_tag new file mode 100644 index 000000000..05dfe0615 Binary files /dev/null and b/tests/resources/testrepo_256.git/refs/tags/hard_tag differ diff --git a/tests/resources/testrepo_256.git/refs/tags/point_to_blob b/tests/resources/testrepo_256.git/refs/tags/point_to_blob new file mode 100644 index 000000000..5efdc777d Binary files /dev/null and b/tests/resources/testrepo_256.git/refs/tags/point_to_blob differ diff --git a/tests/resources/testrepo_256.git/refs/tags/taggerless b/tests/resources/testrepo_256.git/refs/tags/taggerless new file mode 100644 index 000000000..45547b7fa Binary files /dev/null and b/tests/resources/testrepo_256.git/refs/tags/taggerless differ diff --git a/tests/resources/testrepo_256.git/refs/tags/test b/tests/resources/testrepo_256.git/refs/tags/test new file mode 100644 index 000000000..a7d2fef64 Binary files /dev/null and b/tests/resources/testrepo_256.git/refs/tags/test differ diff --git a/tests/resources/testrepo_256.git/refs/tags/wrapped_tag b/tests/resources/testrepo_256.git/refs/tags/wrapped_tag new file mode 100644 index 000000000..05dfe0615 Binary files /dev/null and b/tests/resources/testrepo_256.git/refs/tags/wrapped_tag differ diff --git a/tests/util/path.c b/tests/util/path.c index 2c39e0887..02ec42fce 100644 --- a/tests/util/path.c +++ b/tests/util/path.c @@ -2,6 +2,10 @@ #include "futils.h" #include "fs_path.h" +#ifndef GIT_WIN32 +# include +#endif + static char *path_save; void test_path__initialize(void) @@ -757,7 +761,7 @@ void test_path__validate_current_user_ownership(void) cl_git_fail(git_fs_path_owner_is_current_user(&is_cur, "c:\\path\\does\\not\\exist")); #else cl_git_pass(git_fs_path_owner_is_current_user(&is_cur, "/")); - cl_assert_equal_i(is_cur, 0); + cl_assert_equal_i(is_cur, (geteuid() == 0)); cl_git_fail(git_fs_path_owner_is_current_user(&is_cur, "/path/does/not/exist")); #endif diff --git a/tests/libgit2/network/url/joinpath.c b/tests/util/url/joinpath.c similarity index 93% rename from tests/libgit2/network/url/joinpath.c rename to tests/util/url/joinpath.c index bf4557138..9fc02cde4 100644 --- a/tests/libgit2/network/url/joinpath.c +++ b/tests/util/url/joinpath.c @@ -4,19 +4,19 @@ static git_net_url source, target; -void test_network_url_joinpath__initialize(void) +void test_url_joinpath__initialize(void) { memset(&source, 0, sizeof(source)); memset(&target, 0, sizeof(target)); } -void test_network_url_joinpath__cleanup(void) +void test_url_joinpath__cleanup(void) { git_net_url_dispose(&source); git_net_url_dispose(&target); } -void test_network_url_joinpath__target_paths_and_queries(void) +void test_url_joinpath__target_paths_and_queries(void) { cl_git_pass(git_net_url_parse(&source, "http://example.com/a/b")); @@ -31,7 +31,7 @@ void test_network_url_joinpath__target_paths_and_queries(void) git_net_url_dispose(&target); } -void test_network_url_joinpath__source_query_removed(void) +void test_url_joinpath__source_query_removed(void) { cl_git_pass(git_net_url_parse(&source, "http://example.com/a/b?query&one&two")); @@ -46,7 +46,7 @@ void test_network_url_joinpath__source_query_removed(void) git_net_url_dispose(&target); } -void test_network_url_joinpath__source_lacks_path(void) +void test_url_joinpath__source_lacks_path(void) { cl_git_pass(git_net_url_parse(&source, "http://example.com")); @@ -91,7 +91,7 @@ void test_network_url_joinpath__source_lacks_path(void) git_net_url_dispose(&target); } -void test_network_url_joinpath__source_is_slash(void) +void test_url_joinpath__source_is_slash(void) { cl_git_pass(git_net_url_parse(&source, "http://example.com/")); @@ -137,7 +137,7 @@ void test_network_url_joinpath__source_is_slash(void) } -void test_network_url_joinpath__source_has_query(void) +void test_url_joinpath__source_has_query(void) { cl_git_pass(git_net_url_parse(&source, "http://example.com?query")); @@ -183,7 +183,7 @@ void test_network_url_joinpath__source_has_query(void) } -void test_network_url_joinpath__empty_query_ignored(void) +void test_url_joinpath__empty_query_ignored(void) { cl_git_pass(git_net_url_parse(&source, "http://example.com/foo")); diff --git a/tests/libgit2/network/url/parse.c b/tests/util/url/parse.c similarity index 64% rename from tests/libgit2/network/url/parse.c rename to tests/util/url/parse.c index 8149ba52c..631d9b456 100644 --- a/tests/libgit2/network/url/parse.c +++ b/tests/util/url/parse.c @@ -3,19 +3,19 @@ static git_net_url conndata; -void test_network_url_parse__initialize(void) +void test_url_parse__initialize(void) { memset(&conndata, 0, sizeof(conndata)); } -void test_network_url_parse__cleanup(void) +void test_url_parse__cleanup(void) { git_net_url_dispose(&conndata); } /* Hostname */ -void test_network_url_parse__hostname_trivial(void) +void test_url_parse__hostname_trivial(void) { cl_git_pass(git_net_url_parse(&conndata, "http://example.com/resource")); cl_assert_equal_s(conndata.scheme, "http"); @@ -24,10 +24,12 @@ void test_network_url_parse__hostname_trivial(void) cl_assert_equal_s(conndata.path, "/resource"); cl_assert_equal_p(conndata.username, NULL); cl_assert_equal_p(conndata.password, NULL); + cl_assert_equal_p(conndata.query, NULL); + cl_assert_equal_p(conndata.fragment, NULL); cl_assert_equal_i(git_net_url_is_default_port(&conndata), 1); } -void test_network_url_parse__hostname_root(void) +void test_url_parse__hostname_root(void) { cl_git_pass(git_net_url_parse(&conndata, "http://example.com/")); cl_assert_equal_s(conndata.scheme, "http"); @@ -36,10 +38,12 @@ void test_network_url_parse__hostname_root(void) cl_assert_equal_s(conndata.path, "/"); cl_assert_equal_p(conndata.username, NULL); cl_assert_equal_p(conndata.password, NULL); + cl_assert_equal_p(conndata.query, NULL); + cl_assert_equal_p(conndata.fragment, NULL); cl_assert_equal_i(git_net_url_is_default_port(&conndata), 1); } -void test_network_url_parse__hostname_implied_root(void) +void test_url_parse__hostname_implied_root(void) { cl_git_pass(git_net_url_parse(&conndata, "http://example.com")); cl_assert_equal_s(conndata.scheme, "http"); @@ -48,10 +52,26 @@ void test_network_url_parse__hostname_implied_root(void) cl_assert_equal_s(conndata.path, "/"); cl_assert_equal_p(conndata.username, NULL); cl_assert_equal_p(conndata.password, NULL); + cl_assert_equal_p(conndata.query, NULL); + cl_assert_equal_p(conndata.fragment, NULL); cl_assert_equal_i(git_net_url_is_default_port(&conndata), 1); } -void test_network_url_parse__hostname_implied_root_custom_port(void) +void test_url_parse__hostname_numeric(void) +{ + cl_git_pass(git_net_url_parse(&conndata, "http://8888888/")); + cl_assert_equal_s(conndata.scheme, "http"); + cl_assert_equal_s(conndata.host, "8888888"); + cl_assert_equal_s(conndata.port, "80"); + cl_assert_equal_s(conndata.path, "/"); + cl_assert_equal_p(conndata.username, NULL); + cl_assert_equal_p(conndata.password, NULL); + cl_assert_equal_p(conndata.query, NULL); + cl_assert_equal_p(conndata.fragment, NULL); + cl_assert_equal_i(git_net_url_is_default_port(&conndata), 1); +} + +void test_url_parse__hostname_implied_root_custom_port(void) { cl_git_pass(git_net_url_parse(&conndata, "http://example.com:42")); cl_assert_equal_s(conndata.scheme, "http"); @@ -60,10 +80,12 @@ void test_network_url_parse__hostname_implied_root_custom_port(void) cl_assert_equal_s(conndata.path, "/"); cl_assert_equal_p(conndata.username, NULL); cl_assert_equal_p(conndata.password, NULL); + cl_assert_equal_p(conndata.query, NULL); + cl_assert_equal_p(conndata.fragment, NULL); cl_assert_equal_i(git_net_url_is_default_port(&conndata), 0); } -void test_network_url_parse__hostname_implied_root_empty_port(void) +void test_url_parse__hostname_implied_root_empty_port(void) { cl_git_pass(git_net_url_parse(&conndata, "http://example.com:")); cl_assert_equal_s(conndata.scheme, "http"); @@ -72,10 +94,12 @@ void test_network_url_parse__hostname_implied_root_empty_port(void) cl_assert_equal_s(conndata.path, "/"); cl_assert_equal_p(conndata.username, NULL); cl_assert_equal_p(conndata.password, NULL); + cl_assert_equal_p(conndata.query, NULL); + cl_assert_equal_p(conndata.fragment, NULL); cl_assert_equal_i(git_net_url_is_default_port(&conndata), 1); } -void test_network_url_parse__hostname_encoded_password(void) +void test_url_parse__hostname_encoded_password(void) { cl_git_pass(git_net_url_parse(&conndata, "https://user:pass%2fis%40bad@hostname.com:1234/")); @@ -85,10 +109,12 @@ void test_network_url_parse__hostname_encoded_password(void) cl_assert_equal_s(conndata.path, "/"); cl_assert_equal_s(conndata.username, "user"); cl_assert_equal_s(conndata.password, "pass/is@bad"); + cl_assert_equal_p(conndata.query, NULL); + cl_assert_equal_p(conndata.fragment, NULL); cl_assert_equal_i(git_net_url_is_default_port(&conndata), 0); } -void test_network_url_parse__hostname_user(void) +void test_url_parse__hostname_user(void) { cl_git_pass(git_net_url_parse(&conndata, "https://user@example.com/resource")); @@ -98,10 +124,12 @@ void test_network_url_parse__hostname_user(void) cl_assert_equal_s(conndata.path, "/resource"); cl_assert_equal_s(conndata.username, "user"); cl_assert_equal_p(conndata.password, NULL); + cl_assert_equal_p(conndata.query, NULL); + cl_assert_equal_p(conndata.fragment, NULL); cl_assert_equal_i(git_net_url_is_default_port(&conndata), 1); } -void test_network_url_parse__hostname_user_pass(void) +void test_url_parse__hostname_user_pass(void) { /* user:pass@hostname.tld/resource */ cl_git_pass(git_net_url_parse(&conndata, @@ -112,10 +140,12 @@ void test_network_url_parse__hostname_user_pass(void) cl_assert_equal_s(conndata.path, "/resource"); cl_assert_equal_s(conndata.username, "user"); cl_assert_equal_s(conndata.password, "pass"); + cl_assert_equal_p(conndata.query, NULL); + cl_assert_equal_p(conndata.fragment, NULL); cl_assert_equal_i(git_net_url_is_default_port(&conndata), 1); } -void test_network_url_parse__hostname_port(void) +void test_url_parse__hostname_port(void) { /* hostname.tld:port/resource */ cl_git_pass(git_net_url_parse(&conndata, @@ -126,10 +156,12 @@ void test_network_url_parse__hostname_port(void) cl_assert_equal_s(conndata.path, "/resource"); cl_assert_equal_p(conndata.username, NULL); cl_assert_equal_p(conndata.password, NULL); + cl_assert_equal_p(conndata.query, NULL); + cl_assert_equal_p(conndata.fragment, NULL); cl_assert_equal_i(git_net_url_is_default_port(&conndata), 0); } -void test_network_url_parse__hostname_empty_port(void) +void test_url_parse__hostname_empty_port(void) { cl_git_pass(git_net_url_parse(&conndata, "http://example.com:/resource")); cl_assert_equal_s(conndata.scheme, "http"); @@ -138,10 +170,12 @@ void test_network_url_parse__hostname_empty_port(void) cl_assert_equal_s(conndata.path, "/resource"); cl_assert_equal_p(conndata.username, NULL); cl_assert_equal_p(conndata.password, NULL); + cl_assert_equal_p(conndata.query, NULL); + cl_assert_equal_p(conndata.fragment, NULL); cl_assert_equal_i(git_net_url_is_default_port(&conndata), 1); } -void test_network_url_parse__hostname_user_port(void) +void test_url_parse__hostname_user_port(void) { /* user@hostname.tld:port/resource */ cl_git_pass(git_net_url_parse(&conndata, @@ -152,10 +186,12 @@ void test_network_url_parse__hostname_user_port(void) cl_assert_equal_s(conndata.path, "/resource"); cl_assert_equal_s(conndata.username, "user"); cl_assert_equal_p(conndata.password, NULL); + cl_assert_equal_p(conndata.query, NULL); + cl_assert_equal_p(conndata.fragment, NULL); cl_assert_equal_i(git_net_url_is_default_port(&conndata), 0); } -void test_network_url_parse__hostname_user_pass_port(void) +void test_url_parse__hostname_user_pass_port(void) { /* user:pass@hostname.tld:port/resource */ cl_git_pass(git_net_url_parse(&conndata, @@ -166,12 +202,78 @@ void test_network_url_parse__hostname_user_pass_port(void) cl_assert_equal_s(conndata.path, "/resource"); cl_assert_equal_s(conndata.username, "user"); cl_assert_equal_s(conndata.password, "pass"); + cl_assert_equal_p(conndata.query, NULL); + cl_assert_equal_p(conndata.fragment, NULL); + cl_assert_equal_i(git_net_url_is_default_port(&conndata), 0); +} + +void test_url_parse__hostname_user_pass_port_query(void) +{ + /* user:pass@hostname.tld:port/resource */ + cl_git_pass(git_net_url_parse(&conndata, + "https://user:pass@example.com:9191/resource?query=q&foo=bar&z=asdf")); + cl_assert_equal_s(conndata.scheme, "https"); + cl_assert_equal_s(conndata.host, "example.com"); + cl_assert_equal_s(conndata.port, "9191"); + cl_assert_equal_s(conndata.path, "/resource"); + cl_assert_equal_s(conndata.username, "user"); + cl_assert_equal_s(conndata.password, "pass"); + cl_assert_equal_s(conndata.query, "query=q&foo=bar&z=asdf"); + cl_assert_equal_p(conndata.fragment, NULL); + cl_assert_equal_i(git_net_url_is_default_port(&conndata), 0); +} + +void test_url_parse__hostname_user_pass_port_fragment(void) +{ + /* user:pass@hostname.tld:port/resource */ + cl_git_pass(git_net_url_parse(&conndata, + "https://user:pass@example.com:9191/resource#fragment")); + cl_assert_equal_s(conndata.scheme, "https"); + cl_assert_equal_s(conndata.host, "example.com"); + cl_assert_equal_s(conndata.port, "9191"); + cl_assert_equal_s(conndata.path, "/resource"); + cl_assert_equal_s(conndata.username, "user"); + cl_assert_equal_s(conndata.password, "pass"); + cl_assert_equal_p(conndata.query, NULL); + cl_assert_equal_s(conndata.fragment, "fragment"); + cl_assert_equal_i(git_net_url_is_default_port(&conndata), 0); +} + +void test_url_parse__hostname_user_pass_port_query_fragment(void) +{ + /* user:pass@hostname.tld:port/resource */ + cl_git_pass(git_net_url_parse(&conndata, + "https://user:pass@example.com:9191/resource?query=q&foo=bar&z=asdf#fragment")); + cl_assert_equal_s(conndata.scheme, "https"); + cl_assert_equal_s(conndata.host, "example.com"); + cl_assert_equal_s(conndata.port, "9191"); + cl_assert_equal_s(conndata.path, "/resource"); + cl_assert_equal_s(conndata.username, "user"); + cl_assert_equal_s(conndata.password, "pass"); + cl_assert_equal_s(conndata.query, "query=q&foo=bar&z=asdf"); + cl_assert_equal_s(conndata.fragment, "fragment"); + cl_assert_equal_i(git_net_url_is_default_port(&conndata), 0); +} + +void test_url_parse__fragment_with_question_mark(void) +{ + /* user:pass@hostname.tld:port/resource */ + cl_git_pass(git_net_url_parse(&conndata, + "https://user:pass@example.com:9191/resource#fragment_with?question_mark")); + cl_assert_equal_s(conndata.scheme, "https"); + cl_assert_equal_s(conndata.host, "example.com"); + cl_assert_equal_s(conndata.port, "9191"); + cl_assert_equal_s(conndata.path, "/resource"); + cl_assert_equal_s(conndata.username, "user"); + cl_assert_equal_s(conndata.password, "pass"); + cl_assert_equal_p(conndata.query, NULL); + cl_assert_equal_s(conndata.fragment, "fragment_with?question_mark"); cl_assert_equal_i(git_net_url_is_default_port(&conndata), 0); } /* IPv4 addresses */ -void test_network_url_parse__ipv4_trivial(void) +void test_url_parse__ipv4_trivial(void) { cl_git_pass(git_net_url_parse(&conndata, "http://192.168.1.1/resource")); cl_assert_equal_s(conndata.scheme, "http"); @@ -183,7 +285,7 @@ void test_network_url_parse__ipv4_trivial(void) cl_assert_equal_i(git_net_url_is_default_port(&conndata), 1); } -void test_network_url_parse__ipv4_root(void) +void test_url_parse__ipv4_root(void) { cl_git_pass(git_net_url_parse(&conndata, "http://192.168.1.1/")); cl_assert_equal_s(conndata.scheme, "http"); @@ -195,7 +297,7 @@ void test_network_url_parse__ipv4_root(void) cl_assert_equal_i(git_net_url_is_default_port(&conndata), 1); } -void test_network_url_parse__ipv4_implied_root(void) +void test_url_parse__ipv4_implied_root(void) { cl_git_pass(git_net_url_parse(&conndata, "http://192.168.1.1")); cl_assert_equal_s(conndata.scheme, "http"); @@ -207,7 +309,7 @@ void test_network_url_parse__ipv4_implied_root(void) cl_assert_equal_i(git_net_url_is_default_port(&conndata), 1); } -void test_network_url_parse__ipv4_implied_root_custom_port(void) +void test_url_parse__ipv4_implied_root_custom_port(void) { cl_git_pass(git_net_url_parse(&conndata, "http://192.168.1.1:42")); cl_assert_equal_s(conndata.scheme, "http"); @@ -219,7 +321,7 @@ void test_network_url_parse__ipv4_implied_root_custom_port(void) cl_assert_equal_i(git_net_url_is_default_port(&conndata), 0); } -void test_network_url_parse__ipv4_implied_root_empty_port(void) +void test_url_parse__ipv4_implied_root_empty_port(void) { cl_git_pass(git_net_url_parse(&conndata, "http://192.168.1.1:")); cl_assert_equal_s(conndata.scheme, "http"); @@ -231,7 +333,7 @@ void test_network_url_parse__ipv4_implied_root_empty_port(void) cl_assert_equal_i(git_net_url_is_default_port(&conndata), 1); } -void test_network_url_parse__ipv4_encoded_password(void) +void test_url_parse__ipv4_encoded_password(void) { cl_git_pass(git_net_url_parse(&conndata, "https://user:pass%2fis%40bad@192.168.1.1:1234/")); @@ -244,7 +346,7 @@ void test_network_url_parse__ipv4_encoded_password(void) cl_assert_equal_i(git_net_url_is_default_port(&conndata), 0); } -void test_network_url_parse__ipv4_user(void) +void test_url_parse__ipv4_user(void) { cl_git_pass(git_net_url_parse(&conndata, "https://user@192.168.1.1/resource")); @@ -257,7 +359,7 @@ void test_network_url_parse__ipv4_user(void) cl_assert_equal_i(git_net_url_is_default_port(&conndata), 1); } -void test_network_url_parse__ipv4_user_pass(void) +void test_url_parse__ipv4_user_pass(void) { cl_git_pass(git_net_url_parse(&conndata, "https://user:pass@192.168.1.1/resource")); @@ -270,7 +372,7 @@ void test_network_url_parse__ipv4_user_pass(void) cl_assert_equal_i(git_net_url_is_default_port(&conndata), 1); } -void test_network_url_parse__ipv4_port(void) +void test_url_parse__ipv4_port(void) { cl_git_pass(git_net_url_parse(&conndata, "https://192.168.1.1:9191/resource")); @@ -283,7 +385,7 @@ void test_network_url_parse__ipv4_port(void) cl_assert_equal_i(git_net_url_is_default_port(&conndata), 0); } -void test_network_url_parse__ipv4_empty_port(void) +void test_url_parse__ipv4_empty_port(void) { cl_git_pass(git_net_url_parse(&conndata, "http://192.168.1.1:/resource")); cl_assert_equal_s(conndata.scheme, "http"); @@ -295,7 +397,7 @@ void test_network_url_parse__ipv4_empty_port(void) cl_assert_equal_i(git_net_url_is_default_port(&conndata), 1); } -void test_network_url_parse__ipv4_user_port(void) +void test_url_parse__ipv4_user_port(void) { cl_git_pass(git_net_url_parse(&conndata, "https://user@192.168.1.1:9191/resource")); @@ -308,7 +410,7 @@ void test_network_url_parse__ipv4_user_port(void) cl_assert_equal_i(git_net_url_is_default_port(&conndata), 0); } -void test_network_url_parse__ipv4_user_pass_port(void) +void test_url_parse__ipv4_user_pass_port(void) { cl_git_pass(git_net_url_parse(&conndata, "https://user:pass@192.168.1.1:9191/resource")); @@ -323,7 +425,7 @@ void test_network_url_parse__ipv4_user_pass_port(void) /* IPv6 addresses */ -void test_network_url_parse__ipv6_trivial(void) +void test_url_parse__ipv6_trivial(void) { cl_git_pass(git_net_url_parse(&conndata, "http://[fe80::dcad:beff:fe00:0001]/resource")); cl_assert_equal_s(conndata.scheme, "http"); @@ -335,7 +437,7 @@ void test_network_url_parse__ipv6_trivial(void) cl_assert_equal_i(git_net_url_is_default_port(&conndata), 1); } -void test_network_url_parse__ipv6_root(void) +void test_url_parse__ipv6_root(void) { cl_git_pass(git_net_url_parse(&conndata, "http://[fe80::dcad:beff:fe00:0001]/")); cl_assert_equal_s(conndata.scheme, "http"); @@ -347,7 +449,7 @@ void test_network_url_parse__ipv6_root(void) cl_assert_equal_i(git_net_url_is_default_port(&conndata), 1); } -void test_network_url_parse__ipv6_implied_root(void) +void test_url_parse__ipv6_implied_root(void) { cl_git_pass(git_net_url_parse(&conndata, "http://[fe80::dcad:beff:fe00:0001]")); cl_assert_equal_s(conndata.scheme, "http"); @@ -359,7 +461,7 @@ void test_network_url_parse__ipv6_implied_root(void) cl_assert_equal_i(git_net_url_is_default_port(&conndata), 1); } -void test_network_url_parse__ipv6_implied_root_custom_port(void) +void test_url_parse__ipv6_implied_root_custom_port(void) { cl_git_pass(git_net_url_parse(&conndata, "http://[fe80::dcad:beff:fe00:0001]:42")); cl_assert_equal_s(conndata.scheme, "http"); @@ -371,7 +473,7 @@ void test_network_url_parse__ipv6_implied_root_custom_port(void) cl_assert_equal_i(git_net_url_is_default_port(&conndata), 0); } -void test_network_url_parse__ipv6_implied_root_empty_port(void) +void test_url_parse__ipv6_implied_root_empty_port(void) { cl_git_pass(git_net_url_parse(&conndata, "http://[fe80::dcad:beff:fe00:0001]:")); cl_assert_equal_s(conndata.scheme, "http"); @@ -383,7 +485,7 @@ void test_network_url_parse__ipv6_implied_root_empty_port(void) cl_assert_equal_i(git_net_url_is_default_port(&conndata), 1); } -void test_network_url_parse__ipv6_encoded_password(void) +void test_url_parse__ipv6_encoded_password(void) { cl_git_pass(git_net_url_parse(&conndata, "https://user:pass%2fis%40bad@[fe80::dcad:beff:fe00:0001]:1234/")); @@ -396,7 +498,7 @@ void test_network_url_parse__ipv6_encoded_password(void) cl_assert_equal_i(git_net_url_is_default_port(&conndata), 0); } -void test_network_url_parse__ipv6_user(void) +void test_url_parse__ipv6_user(void) { cl_git_pass(git_net_url_parse(&conndata, "https://user@[fe80::dcad:beff:fe00:0001]/resource")); @@ -409,7 +511,7 @@ void test_network_url_parse__ipv6_user(void) cl_assert_equal_i(git_net_url_is_default_port(&conndata), 1); } -void test_network_url_parse__ipv6_user_pass(void) +void test_url_parse__ipv6_user_pass(void) { cl_git_pass(git_net_url_parse(&conndata, "https://user:pass@[fe80::dcad:beff:fe00:0001]/resource")); @@ -422,7 +524,7 @@ void test_network_url_parse__ipv6_user_pass(void) cl_assert_equal_i(git_net_url_is_default_port(&conndata), 1); } -void test_network_url_parse__ipv6_port(void) +void test_url_parse__ipv6_port(void) { cl_git_pass(git_net_url_parse(&conndata, "https://[fe80::dcad:beff:fe00:0001]:9191/resource")); @@ -435,7 +537,7 @@ void test_network_url_parse__ipv6_port(void) cl_assert_equal_i(git_net_url_is_default_port(&conndata), 0); } -void test_network_url_parse__ipv6_empty_port(void) +void test_url_parse__ipv6_empty_port(void) { cl_git_pass(git_net_url_parse(&conndata, "http://[fe80::dcad:beff:fe00:0001]:/resource")); cl_assert_equal_s(conndata.scheme, "http"); @@ -447,7 +549,7 @@ void test_network_url_parse__ipv6_empty_port(void) cl_assert_equal_i(git_net_url_is_default_port(&conndata), 1); } -void test_network_url_parse__ipv6_user_port(void) +void test_url_parse__ipv6_user_port(void) { cl_git_pass(git_net_url_parse(&conndata, "https://user@[fe80::dcad:beff:fe00:0001]:9191/resource")); @@ -460,7 +562,7 @@ void test_network_url_parse__ipv6_user_port(void) cl_assert_equal_i(git_net_url_is_default_port(&conndata), 0); } -void test_network_url_parse__ipv6_user_pass_port(void) +void test_url_parse__ipv6_user_pass_port(void) { cl_git_pass(git_net_url_parse(&conndata, "https://user:pass@[fe80::dcad:beff:fe00:0001]:9191/resource")); @@ -473,7 +575,7 @@ void test_network_url_parse__ipv6_user_pass_port(void) cl_assert_equal_i(git_net_url_is_default_port(&conndata), 0); } -void test_network_url_parse__ipv6_invalid_addresses(void) +void test_url_parse__ipv6_invalid_addresses(void) { /* Opening bracket missing */ cl_git_fail_with(GIT_EINVALIDSPEC, git_net_url_parse(&conndata, @@ -526,6 +628,7 @@ void test_network_url_parse__ipv6_invalid_addresses(void) "https://user@[fe80::dcad:beff:fe00:0001:9191/resource")); cl_git_fail_with(GIT_EINVALIDSPEC, git_net_url_parse(&conndata, "https://user:pass@[fe80::dcad:beff:fe00:0001:9191/resource")); + /* Both brackets missing */ cl_git_fail_with(GIT_EINVALIDSPEC, git_net_url_parse(&conndata, "http://fe80::dcad:beff:fe00:0001/resource")); @@ -554,4 +657,135 @@ void test_network_url_parse__ipv6_invalid_addresses(void) /* Invalid character inside address */ cl_git_fail_with(GIT_EINVALIDSPEC, git_net_url_parse(&conndata, "http://[fe8o::dcad:beff:fe00:0001]/resource")); + + /* Characters before/after braces */ + cl_git_fail_with(GIT_EINVALIDSPEC, git_net_url_parse(&conndata, + "http://fe80::[dcad:beff:fe00:0001]/resource")); + cl_git_fail_with(GIT_EINVALIDSPEC, git_net_url_parse(&conndata, + "http://cafe[fe80::dcad:beff:fe00:0001]/resource")); + cl_git_fail_with(GIT_EINVALIDSPEC, git_net_url_parse(&conndata, + "http://[fe80::dcad:beff:fe00:0001]cafe/resource")); +} + +/* Oddities */ + +void test_url_parse__invalid_scheme_is_relative(void) +{ + cl_git_pass(git_net_url_parse(&conndata, "foo!bar://host:42/path/to/project?query_string=yes")); + cl_assert_equal_p(conndata.scheme, NULL); + cl_assert_equal_p(conndata.host, NULL); + cl_assert_equal_p(conndata.port, NULL); + cl_assert_equal_s(conndata.path, "foo!bar://host:42/path/to/project"); + cl_assert_equal_p(conndata.username, NULL); + cl_assert_equal_p(conndata.password, NULL); + cl_assert_equal_s(conndata.query, "query_string=yes"); + cl_assert_equal_p(conndata.fragment, NULL); + cl_assert_equal_i(git_net_url_is_default_port(&conndata), 0); +} + +void test_url_parse__scheme_case_is_normalized(void) +{ + cl_git_pass(git_net_url_parse(&conndata, "GIT+SSH://host:42/path/to/project")); + cl_assert_equal_s(conndata.scheme, "git+ssh"); +} + +void test_url_parse__nonhierarchical_scheme(void) +{ + cl_git_pass(git_net_url_parse(&conndata, "mailto:foobar@example.com")); + cl_assert_equal_s(conndata.scheme, "mailto"); + cl_assert_equal_p(conndata.host, NULL); + cl_assert_equal_p(conndata.port, NULL); + cl_assert_equal_s(conndata.path, "foobar@example.com"); + cl_assert_equal_p(conndata.username, NULL); + cl_assert_equal_p(conndata.password, NULL); + cl_assert_equal_i(git_net_url_is_default_port(&conndata), 0); +} + +void test_url_parse__no_scheme_relative_path(void) +{ + cl_git_pass(git_net_url_parse(&conndata, "path")); + cl_assert_equal_p(conndata.scheme, NULL); + cl_assert_equal_p(conndata.host, NULL); + cl_assert_equal_p(conndata.port, NULL); + cl_assert_equal_s(conndata.path, "path"); + cl_assert_equal_p(conndata.username, NULL); + cl_assert_equal_p(conndata.password, NULL); + cl_assert_equal_i(git_net_url_is_default_port(&conndata), 0); +} + +void test_url_parse__no_scheme_absolute_path(void) +{ + cl_git_pass(git_net_url_parse(&conndata, "/path")); + cl_assert_equal_p(conndata.scheme, NULL); + cl_assert_equal_p(conndata.host, NULL); + cl_assert_equal_p(conndata.port, NULL); + cl_assert_equal_s(conndata.path, "/path"); + cl_assert_equal_p(conndata.username, NULL); + cl_assert_equal_p(conndata.password, NULL); + cl_assert_equal_i(git_net_url_is_default_port(&conndata), 0); +} + +void test_url_parse__empty_path(void) +{ + cl_git_pass(git_net_url_parse(&conndata, "mailto:")); + cl_assert_equal_s(conndata.scheme, "mailto"); + cl_assert_equal_p(conndata.host, NULL); + cl_assert_equal_p(conndata.port, NULL); + cl_assert_equal_s(conndata.path, NULL); + cl_assert_equal_p(conndata.username, NULL); + cl_assert_equal_p(conndata.password, NULL); + cl_assert_equal_i(git_net_url_is_default_port(&conndata), 0); +} + +void test_url_parse__empty_path_with_empty_authority(void) +{ + cl_git_pass(git_net_url_parse(&conndata, "http://")); + cl_assert_equal_s(conndata.scheme, "http"); + cl_assert_equal_p(conndata.host, NULL); + cl_assert_equal_s(conndata.port, "80"); + cl_assert_equal_s(conndata.path, "/"); + cl_assert_equal_p(conndata.username, NULL); + cl_assert_equal_p(conndata.password, NULL); + cl_assert_equal_i(git_net_url_is_default_port(&conndata), 1); +} + +void test_url_parse__http_follows_the_rfc(void) +{ + cl_git_fail(git_net_url_parse(&conndata, "https://my.email.address@gmail.com@source.developers.google.com:4433/p/my-project/r/my-repository")); +} + +void test_url_parse__ssh_from_terrible_google_rfc_violating_products(void) +{ + cl_git_pass(git_net_url_parse(&conndata, "ssh://my.email.address@gmail.com@source.developers.google.com:2022/p/my-project/r/my-repository")); + cl_assert_equal_s(conndata.scheme, "ssh"); + cl_assert_equal_s(conndata.host, "source.developers.google.com"); + cl_assert_equal_s(conndata.port, "2022"); + cl_assert_equal_s(conndata.path, "/p/my-project/r/my-repository"); + cl_assert_equal_s(conndata.username, "my.email.address@gmail.com"); + cl_assert_equal_p(conndata.password, NULL); + cl_assert_equal_i(git_net_url_is_default_port(&conndata), 0); +} + +void test_url_parse__ssh_with_password_from_terrible_google_rfc_violating_products(void) +{ + cl_git_pass(git_net_url_parse(&conndata, "ssh://my.email.address@gmail.com:seekret@source.developers.google.com:2022/p/my-project/r/my-repository")); + cl_assert_equal_s(conndata.scheme, "ssh"); + cl_assert_equal_s(conndata.host, "source.developers.google.com"); + cl_assert_equal_s(conndata.port, "2022"); + cl_assert_equal_s(conndata.path, "/p/my-project/r/my-repository"); + cl_assert_equal_s(conndata.username, "my.email.address@gmail.com"); + cl_assert_equal_s(conndata.password, "seekret"); + cl_assert_equal_i(git_net_url_is_default_port(&conndata), 0); +} + +void test_url_parse__spaces_in_the_name(void) +{ + cl_git_pass(git_net_url_parse(&conndata, "https://libgit2@dev.azure.com/libgit2/test/_git/spaces%20in%20the%20name")); + cl_assert_equal_s(conndata.scheme, "https"); + cl_assert_equal_s(conndata.host, "dev.azure.com"); + cl_assert_equal_s(conndata.port, "443"); + cl_assert_equal_s(conndata.path, "/libgit2/test/_git/spaces%20in%20the%20name"); + cl_assert_equal_s(conndata.username, "libgit2"); + cl_assert_equal_p(conndata.password, NULL); + cl_assert_equal_i(git_net_url_is_default_port(&conndata), 1); } diff --git a/tests/libgit2/network/url/pattern.c b/tests/util/url/pattern.c similarity index 97% rename from tests/libgit2/network/url/pattern.c rename to tests/util/url/pattern.c index 5e4495f70..f183d7f5f 100644 --- a/tests/libgit2/network/url/pattern.c +++ b/tests/util/url/pattern.c @@ -7,7 +7,7 @@ struct url_pattern { bool matches; }; -void test_network_url_pattern__single(void) +void test_url_pattern__single(void) { git_net_url url; size_t i; @@ -53,7 +53,7 @@ void test_network_url_pattern__single(void) } } -void test_network_url_pattern__list(void) +void test_url_pattern__list(void) { git_net_url url; size_t i; diff --git a/tests/libgit2/network/url/redirect.c b/tests/util/url/redirect.c similarity index 84% rename from tests/libgit2/network/url/redirect.c rename to tests/util/url/redirect.c index a94db7daf..540177861 100644 --- a/tests/libgit2/network/url/redirect.c +++ b/tests/util/url/redirect.c @@ -4,17 +4,17 @@ static git_net_url conndata; -void test_network_url_redirect__initialize(void) +void test_url_redirect__initialize(void) { memset(&conndata, 0, sizeof(conndata)); } -void test_network_url_redirect__cleanup(void) +void test_url_redirect__cleanup(void) { git_net_url_dispose(&conndata); } -void test_network_url_redirect__redirect_http(void) +void test_url_redirect__redirect_http(void) { cl_git_pass(git_net_url_parse(&conndata, "http://example.com/foo/bar/baz")); @@ -28,7 +28,7 @@ void test_network_url_redirect__redirect_http(void) cl_assert_equal_p(conndata.password, NULL); } -void test_network_url_redirect__redirect_ssl(void) +void test_url_redirect__redirect_ssl(void) { cl_git_pass(git_net_url_parse(&conndata, "https://example.com/foo/bar/baz")); @@ -42,7 +42,7 @@ void test_network_url_redirect__redirect_ssl(void) cl_assert_equal_p(conndata.password, NULL); } -void test_network_url_redirect__redirect_leaves_root_path(void) +void test_url_redirect__redirect_leaves_root_path(void) { cl_git_pass(git_net_url_parse(&conndata, "https://example.com/foo/bar/baz")); @@ -56,7 +56,7 @@ void test_network_url_redirect__redirect_leaves_root_path(void) cl_assert_equal_p(conndata.password, NULL); } -void test_network_url_redirect__redirect_encoded_username_password(void) +void test_url_redirect__redirect_encoded_username_password(void) { cl_git_pass(git_net_url_parse(&conndata, "https://user%2fname:pass%40word%zyx%v@example.com/foo/bar/baz")); @@ -70,7 +70,7 @@ void test_network_url_redirect__redirect_encoded_username_password(void) cl_assert_equal_s(conndata.password, "pass@word%zyx%v"); } -void test_network_url_redirect__redirect_cross_host_allowed(void) +void test_url_redirect__redirect_cross_host_allowed(void) { cl_git_pass(git_net_url_parse(&conndata, "https://bar.com/bar/baz")); @@ -84,7 +84,7 @@ void test_network_url_redirect__redirect_cross_host_allowed(void) cl_assert_equal_p(conndata.password, NULL); } -void test_network_url_redirect__redirect_cross_host_denied(void) +void test_url_redirect__redirect_cross_host_denied(void) { cl_git_pass(git_net_url_parse(&conndata, "https://bar.com/bar/baz")); @@ -92,7 +92,7 @@ void test_network_url_redirect__redirect_cross_host_denied(void) "https://foo.com/bar/baz", false, NULL), -1); } -void test_network_url_redirect__redirect_http_downgrade_denied(void) +void test_url_redirect__redirect_http_downgrade_denied(void) { cl_git_pass(git_net_url_parse(&conndata, "https://foo.com/bar/baz")); @@ -100,7 +100,7 @@ void test_network_url_redirect__redirect_http_downgrade_denied(void) "http://foo.com/bar/baz", true, NULL), -1); } -void test_network_url_redirect__redirect_relative(void) +void test_url_redirect__redirect_relative(void) { cl_git_pass(git_net_url_parse(&conndata, "http://foo.com/bar/baz/biff")); @@ -114,7 +114,7 @@ void test_network_url_redirect__redirect_relative(void) cl_assert_equal_p(conndata.password, NULL); } -void test_network_url_redirect__redirect_relative_ssl(void) +void test_url_redirect__redirect_relative_ssl(void) { cl_git_pass(git_net_url_parse(&conndata, "https://foo.com/bar/baz/biff")); @@ -128,7 +128,7 @@ void test_network_url_redirect__redirect_relative_ssl(void) cl_assert_equal_p(conndata.password, NULL); } -void test_network_url_redirect__service_query_no_query_params_in_location(void) +void test_url_redirect__service_query_no_query_params_in_location(void) { cl_git_pass(git_net_url_parse(&conndata, "https://foo.com/bar/info/refs?service=git-upload-pack")); @@ -137,7 +137,7 @@ void test_network_url_redirect__service_query_no_query_params_in_location(void) cl_assert_equal_s(conndata.path, "/baz"); } -void test_network_url_redirect__service_query_with_query_params_in_location(void) +void test_url_redirect__service_query_with_query_params_in_location(void) { cl_git_pass(git_net_url_parse(&conndata, "https://foo.com/bar/info/refs?service=git-upload-pack")); diff --git a/tests/libgit2/network/url/scp.c b/tests/util/url/scp.c similarity index 89% rename from tests/libgit2/network/url/scp.c rename to tests/util/url/scp.c index 8cdc832ae..0e0dce17e 100644 --- a/tests/libgit2/network/url/scp.c +++ b/tests/util/url/scp.c @@ -3,19 +3,19 @@ static git_net_url conndata; -void test_network_url_scp__initialize(void) +void test_url_scp__initialize(void) { memset(&conndata, 0, sizeof(conndata)); } -void test_network_url_scp__cleanup(void) +void test_url_scp__cleanup(void) { git_net_url_dispose(&conndata); } /* Hostname */ -void test_network_url_scp__hostname_trivial(void) +void test_url_scp__hostname_trivial(void) { cl_git_pass(git_net_url_parse_scp(&conndata, "example.com:/resource")); cl_assert_equal_s(conndata.scheme, "ssh"); @@ -27,7 +27,7 @@ void test_network_url_scp__hostname_trivial(void) cl_assert_equal_i(git_net_url_is_default_port(&conndata), 1); } -void test_network_url_scp__hostname_bracketed(void) +void test_url_scp__hostname_bracketed(void) { cl_git_pass(git_net_url_parse_scp(&conndata, "[example.com]:/resource")); cl_assert_equal_s(conndata.scheme, "ssh"); @@ -39,7 +39,7 @@ void test_network_url_scp__hostname_bracketed(void) cl_assert_equal_i(git_net_url_is_default_port(&conndata), 1); } -void test_network_url_scp__hostname_root(void) +void test_url_scp__hostname_root(void) { cl_git_pass(git_net_url_parse_scp(&conndata, "example.com:/")); cl_assert_equal_s(conndata.scheme, "ssh"); @@ -51,7 +51,7 @@ void test_network_url_scp__hostname_root(void) cl_assert_equal_i(git_net_url_is_default_port(&conndata), 1); } -void test_network_url_scp__hostname_user(void) +void test_url_scp__hostname_user(void) { cl_git_pass(git_net_url_parse_scp(&conndata, "git@example.com:/resource")); cl_assert_equal_s(conndata.scheme, "ssh"); @@ -63,7 +63,7 @@ void test_network_url_scp__hostname_user(void) cl_assert_equal_i(git_net_url_is_default_port(&conndata), 1); } -void test_network_url_scp__hostname_user_bracketed(void) +void test_url_scp__hostname_user_bracketed(void) { cl_git_pass(git_net_url_parse_scp(&conndata, "[git@example.com]:/resource")); cl_assert_equal_s(conndata.scheme, "ssh"); @@ -75,7 +75,7 @@ void test_network_url_scp__hostname_user_bracketed(void) cl_assert_equal_i(git_net_url_is_default_port(&conndata), 1); } -void test_network_url_scp__hostname_port(void) +void test_url_scp__hostname_port(void) { cl_git_pass(git_net_url_parse_scp(&conndata, "[example.com:42]:/resource")); cl_assert_equal_s(conndata.scheme, "ssh"); @@ -87,7 +87,7 @@ void test_network_url_scp__hostname_port(void) cl_assert_equal_i(git_net_url_is_default_port(&conndata), 0); } -void test_network_url_scp__hostname_user_port(void) +void test_url_scp__hostname_user_port(void) { cl_git_pass(git_net_url_parse_scp(&conndata, "[git@example.com:42]:/resource")); cl_assert_equal_s(conndata.scheme, "ssh"); @@ -99,7 +99,7 @@ void test_network_url_scp__hostname_user_port(void) cl_assert_equal_i(git_net_url_is_default_port(&conndata), 0); } -void test_network_url_scp__ipv4_trivial(void) +void test_url_scp__ipv4_trivial(void) { cl_git_pass(git_net_url_parse_scp(&conndata, "192.168.99.88:/resource/a/b/c")); cl_assert_equal_s(conndata.scheme, "ssh"); @@ -111,7 +111,7 @@ void test_network_url_scp__ipv4_trivial(void) cl_assert_equal_i(git_net_url_is_default_port(&conndata), 1); } -void test_network_url_scp__ipv4_bracketed(void) +void test_url_scp__ipv4_bracketed(void) { cl_git_pass(git_net_url_parse_scp(&conndata, "[192.168.99.88]:/resource/a/b/c")); cl_assert_equal_s(conndata.scheme, "ssh"); @@ -123,7 +123,7 @@ void test_network_url_scp__ipv4_bracketed(void) cl_assert_equal_i(git_net_url_is_default_port(&conndata), 1); } -void test_network_url_scp__ipv4_user(void) +void test_url_scp__ipv4_user(void) { cl_git_pass(git_net_url_parse_scp(&conndata, "git@192.168.99.88:/resource/a/b/c")); cl_assert_equal_s(conndata.scheme, "ssh"); @@ -135,7 +135,7 @@ void test_network_url_scp__ipv4_user(void) cl_assert_equal_i(git_net_url_is_default_port(&conndata), 1); } -void test_network_url_scp__ipv4_port(void) +void test_url_scp__ipv4_port(void) { cl_git_pass(git_net_url_parse_scp(&conndata, "[192.168.99.88:1111]:/resource/a/b/c")); cl_assert_equal_s(conndata.scheme, "ssh"); @@ -147,7 +147,7 @@ void test_network_url_scp__ipv4_port(void) cl_assert_equal_i(git_net_url_is_default_port(&conndata), 0); } -void test_network_url_scp__ipv4_user_port(void) +void test_url_scp__ipv4_user_port(void) { cl_git_pass(git_net_url_parse_scp(&conndata, "[git@192.168.99.88:1111]:/resource/a/b/c")); cl_assert_equal_s(conndata.scheme, "ssh"); @@ -159,7 +159,7 @@ void test_network_url_scp__ipv4_user_port(void) cl_assert_equal_i(git_net_url_is_default_port(&conndata), 0); } -void test_network_url_scp__ipv6_trivial(void) +void test_url_scp__ipv6_trivial(void) { cl_git_pass(git_net_url_parse_scp(&conndata, "[fe80::dcad:beff:fe00:0001]:/resource/foo")); cl_assert_equal_s(conndata.scheme, "ssh"); @@ -171,7 +171,7 @@ void test_network_url_scp__ipv6_trivial(void) cl_assert_equal_i(git_net_url_is_default_port(&conndata), 1); } -void test_network_url_scp__ipv6_user(void) +void test_url_scp__ipv6_user(void) { cl_git_pass(git_net_url_parse_scp(&conndata, "git@[fe80::dcad:beff:fe00:0001]:/resource/foo")); cl_assert_equal_s(conndata.scheme, "ssh"); @@ -183,7 +183,7 @@ void test_network_url_scp__ipv6_user(void) cl_assert_equal_i(git_net_url_is_default_port(&conndata), 1); } -void test_network_url_scp__ipv6_port(void) +void test_url_scp__ipv6_port(void) { cl_git_pass(git_net_url_parse_scp(&conndata, "[[fe80::dcad:beff:fe00:0001]:99]:/resource/foo")); cl_assert_equal_s(conndata.scheme, "ssh"); @@ -195,7 +195,7 @@ void test_network_url_scp__ipv6_port(void) cl_assert_equal_i(git_net_url_is_default_port(&conndata), 0); } -void test_network_url_scp__ipv6_user_port(void) +void test_url_scp__ipv6_user_port(void) { cl_git_pass(git_net_url_parse_scp(&conndata, "[git@[fe80::dcad:beff:fe00:0001]:99]:/resource/foo")); cl_assert_equal_s(conndata.scheme, "ssh"); @@ -207,7 +207,7 @@ void test_network_url_scp__ipv6_user_port(void) cl_assert_equal_i(git_net_url_is_default_port(&conndata), 0); } -void test_network_url_scp__hexhost_and_port(void) +void test_url_scp__hexhost_and_port(void) { cl_git_pass(git_net_url_parse_scp(&conndata, "[fe:22]:/resource/foo")); cl_assert_equal_s(conndata.scheme, "ssh"); @@ -219,7 +219,7 @@ void test_network_url_scp__hexhost_and_port(void) cl_assert_equal_i(git_net_url_is_default_port(&conndata), 1); } -void test_network_url_scp__malformed_ipv6_one(void) +void test_url_scp__malformed_ipv6_one(void) { cl_git_pass(git_net_url_parse_scp(&conndata, "fe80::dcad:beff:fe00:0001]:/resource")); cl_assert_equal_s(conndata.scheme, "ssh"); @@ -231,7 +231,7 @@ void test_network_url_scp__malformed_ipv6_one(void) cl_assert_equal_i(git_net_url_is_default_port(&conndata), 1); } -void test_network_url_scp__malformed_ipv6_two(void) +void test_url_scp__malformed_ipv6_two(void) { cl_git_pass(git_net_url_parse_scp(&conndata, "[fe80::dcad:beff:fe00:0001]:42]:/resource")); cl_assert_equal_s(conndata.scheme, "ssh"); @@ -243,7 +243,7 @@ void test_network_url_scp__malformed_ipv6_two(void) cl_assert_equal_i(git_net_url_is_default_port(&conndata), 1); } -void test_network_url_scp__malformed_ipv6_with_user(void) +void test_url_scp__malformed_ipv6_with_user(void) { cl_git_pass(git_net_url_parse_scp(&conndata, "git@[fe80::dcad:beff:fe00:0001]:42]:/resource")); cl_assert_equal_s(conndata.scheme, "ssh"); @@ -255,7 +255,7 @@ void test_network_url_scp__malformed_ipv6_with_user(void) cl_assert_equal_i(git_net_url_is_default_port(&conndata), 1); } -void test_network_url_scp__invalid_addresses(void) +void test_url_scp__invalid_addresses(void) { /* Path is required */ cl_git_fail_with(GIT_EINVALIDSPEC, git_net_url_parse_scp(&conndata, @@ -314,8 +314,4 @@ void test_network_url_scp__invalid_addresses(void) "[git@[fe80::dcad:beff:fe00:0001]:42:/resource")); cl_git_fail_with(GIT_EINVALIDSPEC, git_net_url_parse_scp(&conndata, "[git@[fe80::dcad:beff:fe00:0001:42]:/resource")); - - /* Invalid character inside address */ - cl_git_fail_with(GIT_EINVALIDSPEC, git_net_url_parse(&conndata, - "[fe8o::dcad:beff:fe00:0001]:/resource")); } diff --git a/tests/libgit2/network/url/valid.c b/tests/util/url/valid.c similarity index 94% rename from tests/libgit2/network/url/valid.c rename to tests/util/url/valid.c index 2b2cb7ba4..797b697bd 100644 --- a/tests/libgit2/network/url/valid.c +++ b/tests/util/url/valid.c @@ -1,7 +1,7 @@ #include "clar_libgit2.h" #include "net.h" -void test_network_url_valid__test(void) +void test_url_valid__test(void) { cl_assert(git_net_str_is_url("http://example.com/")); cl_assert(git_net_str_is_url("file://localhost/tmp/foo/"));