diff --git a/CMakeLists.txt b/CMakeLists.txt index eb137ecdd62..763bd437bc4 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,5 +1,8 @@ -# CMake build script for the libgit2 project +# libgit2: the cross-platform, linkable library implementation of git. # See `README.md` for build instructions. +# +# This top-level CMakeLists.txt sets up configuration options and +# determines which subprojects to build. cmake_minimum_required(VERSION 3.5.1) @@ -15,6 +18,7 @@ set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${PROJECT_SOURCE_DIR}/cmake") # Optional subsystems option(BUILD_SHARED_LIBS "Build Shared Library (OFF for Static)" ON) option(BUILD_TESTS "Build Tests using the Clar suite" ON) +option(BUILD_CLI "Build the command-line interface" ON) option(BUILD_EXAMPLES "Build library usage example apps" OFF) option(BUILD_FUZZERS "Build the fuzz targets" OFF) diff --git a/ci/test.sh b/ci/test.sh index a9483977883..0815522a952 100755 --- a/ci/test.sh +++ b/ci/test.sh @@ -159,10 +159,18 @@ fi if [ -z "$SKIP_OFFLINE_TESTS" ]; then echo "" echo "##############################################################################" - echo "## Running (offline) tests" + echo "## Running core tests" echo "##############################################################################" + echo "" + echo "Running libgit2 integration (offline) tests" + echo "" run_test offline + + echo "" + echo "Running utility tests" + echo "" + run_test util fi if [ -n "$RUN_INVASIVE_TESTS" ]; then @@ -186,7 +194,7 @@ if [ -z "$SKIP_ONLINE_TESTS" ]; then echo "" echo "##############################################################################" - echo "## Running (online) tests" + echo "## Running networking (online) tests" echo "##############################################################################" export GITTEST_REMOTE_REDIRECT_INITIAL="http://localhost:9000/initial-redirect/libgit2/TestGitRepository" @@ -198,9 +206,9 @@ if [ -z "$SKIP_ONLINE_TESTS" ]; then # Run the online tests that immutably change global state separately # to avoid polluting the test environment. echo "" - echo "##############################################################################" - echo "## Running (online_customcert) tests" - echo "##############################################################################" + echo "Running custom certificate (online_customcert) tests" + echo "" + run_test online_customcert fi diff --git a/cmake/AddClarTest.cmake b/cmake/AddClarTest.cmake new file mode 100644 index 00000000000..74394163825 --- /dev/null +++ b/cmake/AddClarTest.cmake @@ -0,0 +1,7 @@ +function(ADD_CLAR_TEST project name) + if(NOT USE_LEAK_CHECKER STREQUAL "OFF") + add_test(${name} "${PROJECT_SOURCE_DIR}/script/${USE_LEAK_CHECKER}.sh" "${PROJECT_BINARY_DIR}/${project}" ${ARGN}) + else() + add_test(${name} "${PROJECT_BINARY_DIR}/${project}" ${ARGN}) + endif() +endfunction(ADD_CLAR_TEST) diff --git a/cmake/SelectHashes.cmake b/cmake/SelectHashes.cmake index bedd8c4e332..575ae8f8d27 100644 --- a/cmake/SelectHashes.cmake +++ b/cmake/SelectHashes.cmake @@ -21,9 +21,6 @@ endif() if(USE_SHA1 STREQUAL "CollisionDetection") set(GIT_SHA1_COLLISIONDETECT 1) - add_definitions(-DSHA1DC_NO_STANDARD_INCLUDES=1) - add_definitions(-DSHA1DC_CUSTOM_INCLUDE_SHA1_C=\"common.h\") - add_definitions(-DSHA1DC_CUSTOM_INCLUDE_UBC_CHECK_C=\"common.h\") elseif(USE_SHA1 STREQUAL "OpenSSL") # OPENSSL_FOUND should already be set, we're checking USE_HTTPS diff --git a/examples/CMakeLists.txt b/examples/CMakeLists.txt index 235e72adaed..8e38c7d4e66 100644 --- a/examples/CMakeLists.txt +++ b/examples/CMakeLists.txt @@ -1,3 +1,5 @@ +# examples: code usage examples of libgit2 + file(GLOB SRC_EXAMPLES *.c *.h) add_executable(lg2 ${SRC_EXAMPLES}) @@ -10,7 +12,7 @@ target_include_directories(lg2 PRIVATE ${LIBGIT2_INCLUDES} ${LIBGIT2_DEPENDENCY_ target_include_directories(lg2 SYSTEM PRIVATE ${LIBGIT2_SYSTEM_INCLUDES}) if(WIN32 OR ANDROID) - target_link_libraries(lg2 git2) + target_link_libraries(lg2 libgit2package) else() - target_link_libraries(lg2 git2 pthread) + target_link_libraries(lg2 libgit2package pthread) endif() diff --git a/fuzzers/CMakeLists.txt b/fuzzers/CMakeLists.txt index eaa490fd9b4..a2c19ed408a 100644 --- a/fuzzers/CMakeLists.txt +++ b/fuzzers/CMakeLists.txt @@ -1,3 +1,5 @@ +# fuzzers: libFuzzer and standalone fuzzing utilities + if(BUILD_FUZZERS AND NOT USE_STANDALONE_FUZZERS) set(CMAKE_REQUIRED_FLAGS "-fsanitize=fuzzer-no-link") add_c_flag(-fsanitize=fuzzer) diff --git a/include/git2/errors.h b/include/git2/errors.h index 5a5f8c5a249..62f363507b8 100644 --- a/include/git2/errors.h +++ b/include/git2/errors.h @@ -130,7 +130,8 @@ GIT_EXTERN(const git_error *) git_error_last(void); GIT_EXTERN(void) git_error_clear(void); /** - * Set the error message string for this thread. + * Set the error message string for this thread, using `printf`-style + * formatting. * * This function is public so that custom ODB backends and the like can * relay an error message through libgit2. Most regular users of libgit2 @@ -143,7 +144,20 @@ GIT_EXTERN(void) git_error_clear(void); * * @param error_class One of the `git_error_t` enum above describing the * general subsystem that is responsible for the error. - * @param string The formatted error message to keep + * @param fmt The `printf`-style format string; subsequent arguments must + * be the arguments for the format string. + */ +GIT_EXTERN(void) git_error_set(int error_class, const char *fmt, ...) + GIT_FORMAT_PRINTF(2, 3); + +/** + * Set the error message string for this thread. This function is like + * `git_error_set` but takes a static string instead of a `printf`-style + * format. + * + * @param error_class One of the `git_error_t` enum above describing the + * general subsystem that is responsible for the error. + * @param string The error message to keep * @return 0 on success or -1 on failure */ GIT_EXTERN(int) git_error_set_str(int error_class, const char *string); diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index e7b54d036ab..72ec410fcae 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -1,12 +1,22 @@ -add_library(git2internal OBJECT) -set_target_properties(git2internal PROPERTIES C_STANDARD 90) -set_target_properties(git2internal PROPERTIES C_EXTENSIONS OFF) +# The main libgit2 source tree: this CMakeLists.txt identifies platform +# support and includes the subprojects that make up core libgit2 support. +# +# Optional build configuration settings +# if(DEPRECATE_HARD) add_definitions(-DGIT_DEPRECATE_HARD) endif() +if(USE_LEAK_CHECKER STREQUAL "valgrind") + add_definitions(-DVALGRIND) +endif() + +# +# Optional debugging functionality +# + if(DEBUG_POOL) set(GIT_DEBUG_POOL 1) endif() @@ -22,29 +32,32 @@ if(DEBUG_STRICT_OPEN) endif() add_feature_info(debugopen GIT_DEBUG_STRICT_OPEN "path validation in open") +# +# Optional feature enablement +# -include(PkgBuildConfig) -include(SanitizeBool) +include(SelectGSSAPI) +include(SelectHTTPSBackend) +include(SelectHashes) +include(SelectHTTPParser) +include(SelectRegex) +include(SelectSSH) +include(SelectWinHTTP) +include(SelectZlib) -# This variable will contain the libraries we need to put into -# libgit2.pc's Requires.private. That is, what we're linking to or -# what someone who's statically linking us needs to link to. -set(LIBGIT2_PC_REQUIRES "") -# This will be set later if we use the system's http-parser library or -# use iconv (OSX) and will be written to the Libs.private field in the -# pc file. -set(LIBGIT2_PC_LIBS "") +# +# Platform support +# -set(LIBGIT2_INCLUDES - "${CMAKE_CURRENT_BINARY_DIR}" - "${PROJECT_SOURCE_DIR}/src" - "${PROJECT_SOURCE_DIR}/include") +# futimes/futimens if(HAVE_FUTIMENS) set(GIT_USE_FUTIMENS 1) endif () add_feature_info(futimens GIT_USE_FUTIMENS "futimens support") +# qsort + check_prototype_definition(qsort_r "void qsort_r(void *base, size_t nmemb, size_t size, void *thunk, int (*compar)(void *, const void *, const void *))" "" "stdlib.h" GIT_QSORT_R_BSD) @@ -55,69 +68,80 @@ check_prototype_definition(qsort_r check_function_exists(qsort_s GIT_QSORT_S) -check_function_exists(getentropy GIT_RAND_GETENTROPY) +# determine architecture of the machine -# Find required dependencies +if(CMAKE_SIZEOF_VOID_P EQUAL 8) + set(GIT_ARCH_64 1) +elseif(CMAKE_SIZEOF_VOID_P EQUAL 4) + set(GIT_ARCH_32 1) +elseif(CMAKE_SIZEOF_VOID_P) + message(FATAL_ERROR "Unsupported architecture (pointer size is ${CMAKE_SIZEOF_VOID_P} bytes)") +else() + message(FATAL_ERROR "Unsupported architecture (CMAKE_SIZEOF_VOID_P is unset)") +endif() -if(WIN32) - list(APPEND LIBGIT2_SYSTEM_LIBS ws2_32) -elseif(CMAKE_SYSTEM_NAME MATCHES "(Solaris|SunOS)") - list(APPEND LIBGIT2_SYSTEM_LIBS socket nsl) - list(APPEND LIBGIT2_PC_LIBS "-lsocket" "-lnsl") -elseif(CMAKE_SYSTEM_NAME MATCHES "Haiku") - list(APPEND LIBGIT2_SYSTEM_LIBS network) - list(APPEND LIBGIT2_PC_LIBS "-lnetwork") +# nanosecond mtime/ctime support + +if(USE_NSEC) + set(GIT_USE_NSEC 1) endif() +# high-resolution stat support + +if(HAVE_STRUCT_STAT_ST_MTIM) + set(GIT_USE_STAT_MTIM 1) +elseif(HAVE_STRUCT_STAT_ST_MTIMESPEC) + set(GIT_USE_STAT_MTIMESPEC 1) +elseif(HAVE_STRUCT_STAT_ST_MTIME_NSEC) + set(GIT_USE_STAT_MTIME_NSEC 1) +endif() + +# realtime support + check_library_exists(rt clock_gettime "time.h" NEED_LIBRT) if(NEED_LIBRT) list(APPEND LIBGIT2_SYSTEM_LIBS rt) list(APPEND LIBGIT2_PC_LIBS "-lrt") endif() -if(USE_THREADS) - list(APPEND LIBGIT2_SYSTEM_LIBS ${CMAKE_THREAD_LIBS_INIT}) - list(APPEND LIBGIT2_PC_LIBS ${CMAKE_THREAD_LIBS_INIT}) +# platform libraries + +if(WIN32) + list(APPEND LIBGIT2_SYSTEM_LIBS ws2_32) endif() -add_feature_info(threadsafe USE_THREADS "threadsafe support") +if(CMAKE_SYSTEM_NAME MATCHES "(Solaris|SunOS)") + list(APPEND LIBGIT2_SYSTEM_LIBS socket nsl) + list(APPEND LIBGIT2_PC_LIBS "-lsocket" "-lnsl") +endif() -if(WIN32 AND EMBED_SSH_PATH) - file(GLOB SRC_SSH "${EMBED_SSH_PATH}/src/*.c") - list(SORT SRC_SSH) - target_sources(git2internal PRIVATE ${SRC_SSH}) +if(CMAKE_SYSTEM_NAME MATCHES "Haiku") + list(APPEND LIBGIT2_SYSTEM_LIBS network) + list(APPEND LIBGIT2_PC_LIBS "-lnetwork") +endif() - 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) +if(AMIGA) + add_definitions(-DNO_ADDRINFO -DNO_READDIR_R -DNO_MMAP) endif() -include(SelectHTTPSBackend) -include(SelectHashes) -include(SelectHTTPParser) -include(SelectRegex) -include(SelectSSH) -include(SelectWinHTTP) -include(SelectZlib) +# threads +if(USE_THREADS) + if(NOT WIN32) + find_package(Threads REQUIRED) + list(APPEND LIBGIT2_SYSTEM_LIBS ${CMAKE_THREAD_LIBS_INIT}) + list(APPEND LIBGIT2_PC_LIBS ${CMAKE_THREAD_LIBS_INIT}) + endif() -if(USE_SHA1 STREQUAL "CollisionDetection") - file(GLOB SRC_SHA1 hash/sha1/collisiondetect.* hash/sha1/sha1dc/*) -elseif(USE_SHA1 STREQUAL "OpenSSL") - file(GLOB SRC_SHA1 hash/sha1/openssl.*) -elseif(USE_SHA1 STREQUAL "CommonCrypto") - file(GLOB SRC_SHA1 hash/sha1/common_crypto.*) -elseif(USE_SHA1 STREQUAL "mbedTLS") - file(GLOB SRC_SHA1 hash/sha1/mbedtls.*) -elseif(USE_SHA1 STREQUAL "Win32") - file(GLOB SRC_SHA1 hash/sha1/win32.*) -elseif(USE_SHA1 STREQUAL "Generic") - file(GLOB SRC_SHA1 hash/sha1/generic.*) + set(GIT_THREADS 1) endif() -list(APPEND SRC_SHA1 "hash/sha1.h") -target_sources(git2internal PRIVATE ${SRC_SHA1}) +add_feature_info(threadsafe USE_THREADS "threadsafe support") -# Optional external dependency: ntlmclient +# +# Optional bundled features +# + +# ntlmclient if(USE_NTLMCLIENT) set(GIT_NTLM 1) add_subdirectory("${PROJECT_SOURCE_DIR}/deps/ntlmclient" "${PROJECT_BINARY_DIR}/deps/ntlmclient") @@ -126,11 +150,10 @@ if(USE_NTLMCLIENT) endif() add_feature_info(ntlmclient GIT_NTLM "NTLM authentication support for Unix") -# Optional external dependency: GSSAPI - -include(SelectGSSAPI) +# +# Optional external dependencies -# Optional external dependency: iconv +# iconv if(USE_ICONV) find_package(Iconv) endif() @@ -142,166 +165,28 @@ if(ICONV_FOUND) endif() add_feature_info(iconv GIT_USE_ICONV "iconv encoding conversion support") +# +# Configure support +# -if(USE_THREADS) - if(NOT WIN32) - find_package(Threads REQUIRED) - endif() - - set(GIT_THREADS 1) -endif() - -if(USE_NSEC) - set(GIT_USE_NSEC 1) -endif() - -if(HAVE_STRUCT_STAT_ST_MTIM) - set(GIT_USE_STAT_MTIM 1) -elseif(HAVE_STRUCT_STAT_ST_MTIMESPEC) - set(GIT_USE_STAT_MTIMESPEC 1) -elseif(HAVE_STRUCT_STAT_ST_MTIME_NSEC) - set(GIT_USE_STAT_MTIME_NSEC 1) -endif() - -target_compile_definitions(git2internal PRIVATE _FILE_OFFSET_BITS=64) - -# Collect sourcefiles -file(GLOB SRC_H - "${PROJECT_SOURCE_DIR}/include/git2.h" - "${PROJECT_SOURCE_DIR}/include/git2/*.h" - "${PROJECT_SOURCE_DIR}/include/git2/sys/*.h") -list(SORT SRC_H) -target_sources(git2internal PRIVATE ${SRC_H}) - -# On Windows use specific platform sources -if(WIN32 AND NOT CYGWIN) - set(WIN_RC "win32/git2.rc") - - file(GLOB SRC_OS win32/*.c win32/*.h) - list(SORT SRC_OS) - target_sources(git2internal PRIVATE ${SRC_OS}) -elseif(AMIGA) - target_compile_definitions(git2internal PRIVATE NO_ADDRINFO NO_READDIR_R NO_MMAP) -else() - file(GLOB SRC_OS unix/*.c unix/*.h) - list(SORT SRC_OS) - target_sources(git2internal PRIVATE ${SRC_OS}) -endif() - -if(USE_LEAK_CHECKER STREQUAL "valgrind") - target_compile_definitions(git2internal PRIVATE VALGRIND) -endif() +configure_file(features.h.in git2/sys/features.h) -file(GLOB SRC_GIT2 *.c *.h - allocators/*.c allocators/*.h - streams/*.c streams/*.h - transports/*.c transports/*.h - xdiff/*.c xdiff/*.h) -list(SORT SRC_GIT2) -target_sources(git2internal PRIVATE ${SRC_GIT2}) - -if(APPLE) - # The old Secure Transport API has been deprecated in macOS 10.15. - set_source_files_properties(streams/stransport.c PROPERTIES COMPILE_FLAGS -Wno-deprecated) -endif() +# +# Include child projects +# -# the xdiff dependency is not (yet) warning-free, disable warnings as -# errors for the xdiff sources until we've sorted them out -if(MSVC) - set_source_files_properties(xdiff/xdiffi.c PROPERTIES COMPILE_FLAGS -WX-) - set_source_files_properties(xdiff/xemit.c PROPERTIES COMPILE_FLAGS -WX-) - set_source_files_properties(xdiff/xhistogram.c PROPERTIES COMPILE_FLAGS -WX-) - set_source_files_properties(xdiff/xmerge.c PROPERTIES COMPILE_FLAGS -WX-) - set_source_files_properties(xdiff/xutils.c PROPERTIES COMPILE_FLAGS -WX-) - set_source_files_properties(xdiff/xpatience.c PROPERTIES COMPILE_FLAGS -WX-) -else() - set_source_files_properties(xdiff/xdiffi.c PROPERTIES COMPILE_FLAGS "-Wno-sign-compare -Wno-unused-parameter") - set_source_files_properties(xdiff/xemit.c PROPERTIES COMPILE_FLAGS "-Wno-sign-compare -Wno-unused-parameter") - set_source_files_properties(xdiff/xhistogram.c PROPERTIES COMPILE_FLAGS "-Wno-sign-compare") - set_source_files_properties(xdiff/xutils.c PROPERTIES COMPILE_FLAGS "-Wno-sign-compare") - set_source_files_properties(xdiff/xpatience.c PROPERTIES COMPILE_FLAGS "-Wno-sign-compare") -endif() +add_subdirectory(libgit2) +add_subdirectory(util) -# Determine architecture of the machine -if(CMAKE_SIZEOF_VOID_P EQUAL 8) - set(GIT_ARCH_64 1) -elseif(CMAKE_SIZEOF_VOID_P EQUAL 4) - set(GIT_ARCH_32 1) -elseif(CMAKE_SIZEOF_VOID_P) - message(FATAL_ERROR "Unsupported architecture (pointer size is ${CMAKE_SIZEOF_VOID_P} bytes)") -else() - message(FATAL_ERROR "Unsupported architecture (CMAKE_SIZEOF_VOID_P is unset)") +if(BUILD_CLI) + add_subdirectory(cli) endif() -configure_file(features.h.in git2/sys/features.h) - -ide_split_sources(git2internal) -list(APPEND LIBGIT2_OBJECTS $ ${LIBGIT2_DEPENDENCY_OBJECTS}) - -target_include_directories(git2internal PRIVATE ${LIBGIT2_INCLUDES} ${LIBGIT2_DEPENDENCY_INCLUDES} PUBLIC ${PROJECT_SOURCE_DIR}/include) -target_include_directories(git2internal SYSTEM PRIVATE ${LIBGIT2_SYSTEM_INCLUDES}) - +# re-export these to the root so that peer projects (tests, fuzzers, +# examples) can use them set(LIBGIT2_INCLUDES ${LIBGIT2_INCLUDES} PARENT_SCOPE) set(LIBGIT2_OBJECTS ${LIBGIT2_OBJECTS} PARENT_SCOPE) set(LIBGIT2_DEPENDENCY_INCLUDES ${LIBGIT2_DEPENDENCY_INCLUDES} PARENT_SCOPE) set(LIBGIT2_DEPENDENCY_OBJECTS ${LIBGIT2_DEPENDENCY_OBJECTS} PARENT_SCOPE) set(LIBGIT2_SYSTEM_INCLUDES ${LIBGIT2_SYSTEM_INCLUDES} PARENT_SCOPE) set(LIBGIT2_SYSTEM_LIBS ${LIBGIT2_SYSTEM_LIBS} PARENT_SCOPE) - -if(XCODE_VERSION) - # This is required for Xcode to actually link the libgit2 library - # when using only object libraries. - file(WRITE ${CMAKE_CURRENT_BINARY_DIR}/dummy.c "") - list(APPEND LIBGIT2_OBJECTS ${CMAKE_CURRENT_BINARY_DIR}/dummy.c) -endif() - -# Compile and link libgit2 -add_library(git2 ${WIN_RC} ${LIBGIT2_OBJECTS}) -target_link_libraries(git2 ${LIBGIT2_SYSTEM_LIBS}) - -set_target_properties(git2 PROPERTIES C_STANDARD 90) -set_target_properties(git2 PROPERTIES LIBRARY_OUTPUT_DIRECTORY ${PROJECT_BINARY_DIR}) -set_target_properties(git2 PROPERTIES RUNTIME_OUTPUT_DIRECTORY ${PROJECT_BINARY_DIR}) -set_target_properties(git2 PROPERTIES ARCHIVE_OUTPUT_DIRECTORY ${PROJECT_BINARY_DIR}) - -# Workaround for Cmake bug #0011240 (see http://public.kitware.com/Bug/view.php?id=11240) -# Win64+MSVC+static libs = linker error -if(MSVC AND GIT_ARCH_64 AND NOT BUILD_SHARED_LIBS) - set_target_properties(git2 PROPERTIES STATIC_LIBRARY_FLAGS "/MACHINE:x64") -endif() - -ide_split_sources(git2) - -if(SONAME) - set_target_properties(git2 PROPERTIES VERSION ${libgit2_VERSION}) - set_target_properties(git2 PROPERTIES SOVERSION "${libgit2_VERSION_MAJOR}.${libgit2_VERSION_MINOR}") - if(LIBGIT2_FILENAME) - target_compile_definitions(git2 PRIVATE LIBGIT2_FILENAME=\"${LIBGIT2_FILENAME}\") - set_target_properties(git2 PROPERTIES OUTPUT_NAME ${LIBGIT2_FILENAME}) - elseif(DEFINED LIBGIT2_PREFIX) - set_target_properties(git2 PROPERTIES PREFIX "${LIBGIT2_PREFIX}") - endif() -endif() - -pkg_build_config(NAME libgit2 - VERSION ${libgit2_VERSION} - DESCRIPTION "The git library, take 2" - LIBS_SELF git2 - PRIVATE_LIBS ${LIBGIT2_PC_LIBS} - REQUIRES ${LIBGIT2_PC_REQUIRES} -) - -if(MSVC_IDE) - # Precompiled headers - set_target_properties(git2 PROPERTIES COMPILE_FLAGS "/Yuprecompiled.h /FIprecompiled.h") - set_source_files_properties(win32/precompiled.c COMPILE_FLAGS "/Ycprecompiled.h") -endif() - -# Install -install(TARGETS git2 - 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}) diff --git a/src/README.md b/src/README.md new file mode 100644 index 00000000000..10b86c1dcf0 --- /dev/null +++ b/src/README.md @@ -0,0 +1,12 @@ +# libgit2 sources + +This is the source that makes up the core of libgit2 and its related +projects. + +* `cli` + A git-compatible command-line interface that uses libgit2. +* `libgit2` + This is the libgit2 project, a cross-platform, linkable library + implementation of Git that you can use in your application. +* `util` + A shared utility library for these projects. diff --git a/src/cli/CMakeLists.txt b/src/cli/CMakeLists.txt new file mode 100644 index 00000000000..4f347e93f0b --- /dev/null +++ b/src/cli/CMakeLists.txt @@ -0,0 +1,53 @@ +set(CLI_INCLUDES + "${libgit2_BINARY_DIR}/src" + "${libgit2_SOURCE_DIR}/src/util" + "${libgit2_SOURCE_DIR}/src/cli" + "${libgit2_SOURCE_DIR}/include") + +if(WIN32 AND NOT CYGWIN) + file(GLOB CLI_SRC_OS win32/*.c) + list(SORT CLI_SRC_OS) +else() + file(GLOB CLI_SRC_OS unix/*.c) + list(SORT CLI_SRC_OS) +endif() + +file(GLOB CLI_SRC_C *.c *.h) +list(SORT CLI_SRC_C) + +# +# The CLI currently needs to be statically linked against libgit2 because +# the utility library uses libgit2's thread-local error buffers. TODO: +# remove this dependency and allow us to dynamically link against libgit2. +# + +if(BUILD_CLI STREQUAL "dynamic") + set(CLI_LIBGIT2_LIBRARY libgit2package) +else() + set(CLI_LIBGIT2_OBJECTS $) +endif() + +# +# Compile and link the CLI +# + +add_executable(git2_cli ${CLI_SRC_C} ${CLI_SRC_OS} ${CLI_OBJECTS} + $ + ${CLI_LIBGIT2_OBJECTS} + ${LIBGIT2_DEPENDENCY_OBJECTS}) +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}) + +ide_split_sources(git2_cli) + +target_include_directories(git2_cli PRIVATE ${CLI_INCLUDES}) + +if(MSVC_IDE) + # Precompiled headers + set_target_properties(git2_cli PROPERTIES COMPILE_FLAGS "/Yuprecompiled.h /FIprecompiled.h") + set_source_files_properties(win32/precompiled.c COMPILE_FLAGS "/Ycprecompiled.h") +endif() + +install(TARGETS git2_cli RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}) diff --git a/src/cli/README.md b/src/cli/README.md new file mode 100644 index 00000000000..3087c39c425 --- /dev/null +++ b/src/cli/README.md @@ -0,0 +1,26 @@ +# cli + +A git-compatible command-line interface that uses libgit2. + +## Adding commands + +1. Individual commands have a `main`-like top-level entrypoint. For example: + + ```c + int cmd_help(int argc, char **argv) + ``` + + Although this is the same signature as `main`, commands are not built as + individual standalone executables, they'll be linked into the main cli. + (Though there may be an option for command executables to be built as + standalone executables in the future.) + +2. Commands are prototyped in `cmd.h` and added to `main.c`'s list of + commands (`cli_cmds[]`). Commands should be specified with their name, + entrypoint and a brief description that can be printed in `git help`. + This is done because commands are linked into the main cli. + +3. Commands should accept a `--help` option that displays their help + information. This will be shown when a user runs ` --help` and + when a user runs `help `. + diff --git a/src/cli/cli.h b/src/cli/cli.h new file mode 100644 index 00000000000..222d53a7446 --- /dev/null +++ b/src/cli/cli.h @@ -0,0 +1,19 @@ +/* + * 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 CLI_cli_h__ +#define CLI_cli_h__ + +#define PROGRAM_NAME "git2" + +#include "git2_util.h" + +#include "error.h" +#include "opt.h" +#include "opt_usage.h" + +#endif /* CLI_cli_h__ */ diff --git a/src/cli/cmd.c b/src/cli/cmd.c new file mode 100644 index 00000000000..2a7e71cdbcb --- /dev/null +++ b/src/cli/cmd.c @@ -0,0 +1,21 @@ +/* + * 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 "cli.h" +#include "cmd.h" + +const cli_cmd_spec *cli_cmd_spec_byname(const char *name) +{ + const cli_cmd_spec *cmd; + + for (cmd = cli_cmds; cmd->name; cmd++) { + if (!strcmp(cmd->name, name)) + return cmd; + } + + return NULL; +} diff --git a/src/cli/cmd.h b/src/cli/cmd.h new file mode 100644 index 00000000000..664b5021a75 --- /dev/null +++ b/src/cli/cmd.h @@ -0,0 +1,32 @@ +/* + * 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 CLI_cmd_h__ +#define CLI_cmd_h__ + +/* Command definitions */ +typedef struct { + const char *name; + int (*fn)(int argc, char **argv); + const char *desc; +} cli_cmd_spec; + +/* Options that are common to all commands (eg --help, --git-dir) */ +extern const cli_opt_spec cli_common_opts[]; + +/* All the commands supported by the CLI */ +extern const cli_cmd_spec cli_cmds[]; + +/* Find a command by name */ +extern const cli_cmd_spec *cli_cmd_spec_byname(const char *name); + +/* Commands */ +extern int cmd_cat_file(int argc, char **argv); +extern int cmd_hash_object(int argc, char **argv); +extern int cmd_help(int argc, char **argv); + +#endif /* CLI_cmd_h__ */ diff --git a/src/cli/cmd_cat_file.c b/src/cli/cmd_cat_file.c new file mode 100644 index 00000000000..fb53a722ba2 --- /dev/null +++ b/src/cli/cmd_cat_file.c @@ -0,0 +1,204 @@ +/* + * 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 +#include "cli.h" +#include "cmd.h" + +#define COMMAND_NAME "cat-file" + +typedef enum { + DISPLAY_CONTENT = 0, + DISPLAY_EXISTS, + DISPLAY_PRETTY, + DISPLAY_SIZE, + DISPLAY_TYPE +} display_t; + +static int show_help; +static int display = DISPLAY_CONTENT; +static char *type_name, *object_spec; + +static const cli_opt_spec opts[] = { + { CLI_OPT_TYPE_SWITCH, "help", 0, &show_help, 1, + CLI_OPT_USAGE_HIDDEN | CLI_OPT_USAGE_STOP_PARSING, NULL, + "display help about the " COMMAND_NAME " command" }, + + { CLI_OPT_TYPE_SWITCH, NULL, 't', &display, DISPLAY_TYPE, + CLI_OPT_USAGE_REQUIRED, NULL, "display the type of the object" }, + { CLI_OPT_TYPE_SWITCH, NULL, 's', &display, DISPLAY_SIZE, + CLI_OPT_USAGE_CHOICE, NULL, "display the size of the object" }, + { CLI_OPT_TYPE_SWITCH, NULL, 'e', &display, DISPLAY_EXISTS, + CLI_OPT_USAGE_CHOICE, NULL, "displays nothing unless the object is corrupt" }, + { CLI_OPT_TYPE_SWITCH, NULL, 'p', &display, DISPLAY_PRETTY, + CLI_OPT_USAGE_CHOICE, NULL, "pretty-print the object" }, + { CLI_OPT_TYPE_ARG, "type", 0, &type_name, 0, + CLI_OPT_USAGE_CHOICE, "type", "the type of object to display" }, + { CLI_OPT_TYPE_ARG, "object", 0, &object_spec, 0, + CLI_OPT_USAGE_REQUIRED, "object", "the object to display" }, + { 0 }, +}; + +static void print_help(void) +{ + cli_opt_usage_fprint(stdout, PROGRAM_NAME, COMMAND_NAME, opts); + printf("\n"); + + printf("Display the content for the given object in the repository.\n"); + printf("\n"); + + printf("Options:\n"); + + cli_opt_help_fprint(stdout, opts); +} + +static int print_odb(git_object *object, display_t display) +{ + git_odb *odb = NULL; + git_odb_object *odb_object = NULL; + const unsigned char *content; + git_object_size_t size; + int ret = 0; + + /* + * Our parsed blobs retain the raw content; all other objects are + * parsed into a working representation. To get the raw content, + * we need to do an ODB lookup. (Thankfully, this should be cached + * in-memory from our last call.) + */ + if (git_object_type(object) == GIT_OBJECT_BLOB) { + content = git_blob_rawcontent((git_blob *)object); + size = git_blob_rawsize((git_blob *)object); + } else { + if (git_repository_odb(&odb, git_object_owner(object)) < 0 || + git_odb_read(&odb_object, odb, git_object_id(object)) < 0) { + ret = cli_error_git(); + goto done; + } + + content = git_odb_object_data(odb_object); + size = git_odb_object_size(odb_object); + } + + switch (display) { + case DISPLAY_SIZE: + if (printf("%" PRIu64 "\n", size) < 0) + ret = cli_error_os(); + break; + case DISPLAY_CONTENT: + if (p_write(fileno(stdout), content, (size_t)size) < 0) + ret = cli_error_os(); + break; + default: + GIT_ASSERT(0); + } + +done: + git_odb_object_free(odb_object); + git_odb_free(odb); + return ret; +} + +static int print_type(git_object *object) +{ + if (printf("%s\n", git_object_type2string(git_object_type(object))) < 0) + return cli_error_os(); + + return 0; +} + +static int print_pretty(git_object *object) +{ + const git_tree_entry *entry; + size_t i, count; + + /* + * Only trees are stored in an unreadable format and benefit from + * pretty-printing. + */ + if (git_object_type(object) != GIT_OBJECT_TREE) + return print_odb(object, DISPLAY_CONTENT); + + for (i = 0, count = git_tree_entrycount((git_tree *)object); i < count; i++) { + entry = git_tree_entry_byindex((git_tree *)object, i); + + if (printf("%06o %s %s\t%s\n", + git_tree_entry_filemode_raw(entry), + git_object_type2string(git_tree_entry_type(entry)), + git_oid_tostr_s(git_tree_entry_id(entry)), + git_tree_entry_name(entry)) < 0) + return cli_error_os(); + } + + return 0; +} + +int cmd_cat_file(int argc, char **argv) +{ + git_repository *repo = NULL; + git_object *object = NULL; + git_object_t type; + cli_opt invalid_opt; + int giterr, ret = 0; + + if (cli_opt_parse(&invalid_opt, opts, argv + 1, argc - 1, CLI_OPT_PARSE_GNU)) + return cli_opt_usage_error(COMMAND_NAME, opts, &invalid_opt); + + if (show_help) { + print_help(); + return 0; + } + + if (git_repository_open_ext(&repo, ".", GIT_REPOSITORY_OPEN_FROM_ENV, NULL) < 0) + return cli_error_git(); + + if ((giterr = git_revparse_single(&object, repo, object_spec)) < 0) { + if (display == DISPLAY_EXISTS && giterr == GIT_ENOTFOUND) + ret = 1; + else + ret = cli_error_git(); + + goto done; + } + + if (type_name) { + git_object *peeled; + + if ((type = git_object_string2type(type_name)) == GIT_OBJECT_INVALID) { + ret = cli_error_usage("invalid object type '%s'", type_name); + goto done; + } + + if (git_object_peel(&peeled, object, type) < 0) { + ret = cli_error_git(); + goto done; + } + + git_object_free(object); + object = peeled; + } + + switch (display) { + case DISPLAY_EXISTS: + ret = 0; + break; + case DISPLAY_TYPE: + ret = print_type(object); + break; + case DISPLAY_PRETTY: + ret = print_pretty(object); + break; + default: + ret = print_odb(object, display); + break; + } + +done: + git_object_free(object); + git_repository_free(repo); + return ret; +} diff --git a/src/cli/cmd_hash_object.c b/src/cli/cmd_hash_object.c new file mode 100644 index 00000000000..5cfe9146a6b --- /dev/null +++ b/src/cli/cmd_hash_object.c @@ -0,0 +1,135 @@ +/* + * 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 +#include "cli.h" +#include "cmd.h" + +#include "futils.h" + +#define COMMAND_NAME "hash-object" + +static int show_help; +static char *type_name; +static int write_object, read_stdin, literally; +static char **filenames; + +static const cli_opt_spec opts[] = { + { CLI_OPT_TYPE_SWITCH, "help", 0, &show_help, 1, + CLI_OPT_USAGE_HIDDEN | CLI_OPT_USAGE_STOP_PARSING, NULL, + "display help about the " COMMAND_NAME " command" }, + + { CLI_OPT_TYPE_VALUE, NULL, 't', &type_name, 0, + CLI_OPT_USAGE_DEFAULT, "type", "the type of object to hash (default: \"blob\")" }, + { CLI_OPT_TYPE_SWITCH, NULL, 'w', &write_object, 1, + CLI_OPT_USAGE_DEFAULT, NULL, "write the object to the object database" }, + { CLI_OPT_TYPE_SWITCH, "literally", 0, &literally, 1, + CLI_OPT_USAGE_DEFAULT, NULL, "do not validate the object contents" }, + { CLI_OPT_TYPE_SWITCH, "stdin", 0, &read_stdin, 1, + CLI_OPT_USAGE_REQUIRED, NULL, "read content from stdin" }, + { CLI_OPT_TYPE_ARGS, "file", 0, &filenames, 0, + CLI_OPT_USAGE_CHOICE, "file", "the file (or files) to read and hash" }, + { 0 }, +}; + +static void print_help(void) +{ + cli_opt_usage_fprint(stdout, PROGRAM_NAME, COMMAND_NAME, opts); + printf("\n"); + + printf("Compute the object ID for a given file and optionally write that file\nto the object database.\n"); + printf("\n"); + + printf("Options:\n"); + + cli_opt_help_fprint(stdout, opts); +} + +static int hash_buf(git_odb *odb, git_str *buf, git_object_t type) +{ + git_oid oid; + + if (!literally) { + int valid = 0; + + if (git_object_rawcontent_is_valid(&valid, buf->ptr, buf->size, type) < 0 || !valid) + return cli_error_git(); + } + + if (write_object) { + if (git_odb_write(&oid, odb, buf->ptr, buf->size, type) < 0) + return cli_error_git(); + } else { + if (git_odb_hash(&oid, buf->ptr, buf->size, type) < 0) + return cli_error_git(); + } + + if (printf("%s\n", git_oid_tostr_s(&oid)) < 0) + return cli_error_os(); + + return 0; +} + +int cmd_hash_object(int argc, char **argv) +{ + git_repository *repo = NULL; + git_odb *odb = NULL; + git_str buf = GIT_STR_INIT; + cli_opt invalid_opt; + git_object_t type = GIT_OBJECT_BLOB; + char **filename; + int ret = 0; + + if (cli_opt_parse(&invalid_opt, opts, argv + 1, argc - 1, CLI_OPT_PARSE_GNU)) + return cli_opt_usage_error(COMMAND_NAME, opts, &invalid_opt); + + if (show_help) { + print_help(); + return 0; + } + + if (type_name && (type = git_object_string2type(type_name)) == GIT_OBJECT_INVALID) + return cli_error_usage("invalid object type '%s'", type_name); + + if (write_object && + (git_repository_open_ext(&repo, ".", GIT_REPOSITORY_OPEN_FROM_ENV, NULL) < 0 || + git_repository_odb(&odb, repo) < 0)) { + ret = cli_error_git(); + goto done; + } + + /* + * TODO: we're reading blobs, we shouldn't pull them all into main + * memory, we should just stream them into the odb instead. + * (Or create a `git_odb_writefile` API.) + */ + if (read_stdin) { + if (git_futils_readbuffer_fd_full(&buf, fileno(stdin)) < 0) { + ret = cli_error_git(); + goto done; + } + + if ((ret = hash_buf(odb, &buf, type)) != 0) + goto done; + } else { + for (filename = filenames; *filename; filename++) { + if (git_futils_readbuffer(&buf, *filename) < 0) { + ret = cli_error_git(); + goto done; + } + + if ((ret = hash_buf(odb, &buf, type)) != 0) + goto done; + } + } + +done: + git_str_dispose(&buf); + git_odb_free(odb); + git_repository_free(repo); + return ret; +} diff --git a/src/cli/cmd_help.c b/src/cli/cmd_help.c new file mode 100644 index 00000000000..7ee9822427c --- /dev/null +++ b/src/cli/cmd_help.c @@ -0,0 +1,86 @@ +/* + * 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 +#include +#include "cli.h" +#include "cmd.h" + +#define COMMAND_NAME "help" + +static char *command; +static int show_help; + +static const cli_opt_spec opts[] = { + { CLI_OPT_TYPE_SWITCH, "help", 0, &show_help, 1, + CLI_OPT_USAGE_HIDDEN, NULL, "display help about the help command" }, + { CLI_OPT_TYPE_ARG, "command", 0, &command, 0, + CLI_OPT_USAGE_DEFAULT, "command", "the command to show help for" }, + { 0 }, +}; + +static int print_help(void) +{ + cli_opt_usage_fprint(stdout, PROGRAM_NAME, COMMAND_NAME, opts); + printf("\n"); + + printf("Display help information about %s. If a command is specified, help\n", PROGRAM_NAME); + printf("about that command will be shown. Otherwise, general information about\n"); + printf("%s will be shown, including the commands available.\n", PROGRAM_NAME); + + return 0; +} + +static int print_commands(void) +{ + const cli_cmd_spec *cmd; + + cli_opt_usage_fprint(stdout, PROGRAM_NAME, NULL, cli_common_opts); + printf("\n"); + + printf("These are the %s commands available:\n\n", PROGRAM_NAME); + + for (cmd = cli_cmds; cmd->name; cmd++) + printf(" %-11s %s\n", cmd->name, cmd->desc); + + printf("\nSee '%s help ' for more information on a specific command.\n", PROGRAM_NAME); + + return 0; +} + +int cmd_help(int argc, char **argv) +{ + char *fake_args[2]; + const cli_cmd_spec *cmd; + cli_opt invalid_opt; + + if (cli_opt_parse(&invalid_opt, opts, argv + 1, argc - 1, CLI_OPT_PARSE_GNU)) + return cli_opt_usage_error(COMMAND_NAME, opts, &invalid_opt); + + /* Show the meta-help */ + if (show_help) + return print_help(); + + /* We were not asked to show help for a specific command. */ + if (!command) + return print_commands(); + + /* + * If we were asked for help for a command (eg, `help `), + * delegate back to that command's `--help` option. This lets + * commands own their help. Emulate the command-line arguments + * that would invoke ` --help` and invoke that command. + */ + fake_args[0] = command; + fake_args[1] = "--help"; + + if ((cmd = cli_cmd_spec_byname(command)) == NULL) + return cli_error("'%s' is not a %s command. See '%s help'.", + command, PROGRAM_NAME, PROGRAM_NAME); + + return cmd->fn(2, fake_args); +} diff --git a/src/cli/error.h b/src/cli/error.h new file mode 100644 index 00000000000..cce7a54c093 --- /dev/null +++ b/src/cli/error.h @@ -0,0 +1,51 @@ +/* + * 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 CLI_error_h__ +#define CLI_error_h__ + +#include "cli.h" +#include + +#define CLI_EXIT_OK 0 +#define CLI_EXIT_ERROR 1 +#define CLI_EXIT_OS 128 +#define CLI_EXIT_GIT 128 +#define CLI_EXIT_USAGE 129 + +#define cli_error__print(fmt) do { \ + va_list ap; \ + va_start(ap, fmt); \ + fprintf(stderr, "%s: ", PROGRAM_NAME); \ + vfprintf(stderr, fmt, ap); \ + fprintf(stderr, "\n"); \ + va_end(ap); \ + } while(0) + +GIT_INLINE(int) cli_error(const char *fmt, ...) +{ + cli_error__print(fmt); + return CLI_EXIT_ERROR; +} + +GIT_INLINE(int) cli_error_usage(const char *fmt, ...) +{ + cli_error__print(fmt); + return CLI_EXIT_USAGE; +} + +GIT_INLINE(int) cli_error_git(void) +{ + const git_error *err = git_error_last(); + fprintf(stderr, "%s: %s\n", PROGRAM_NAME, + err ? err->message : "unknown error"); + return CLI_EXIT_GIT; +} + +#define cli_error_os() (perror(PROGRAM_NAME), CLI_EXIT_OS) + +#endif /* CLI_error_h__ */ diff --git a/src/cli/main.c b/src/cli/main.c new file mode 100644 index 00000000000..08abb324f87 --- /dev/null +++ b/src/cli/main.c @@ -0,0 +1,105 @@ +/* + * 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 +#include +#include "cli.h" +#include "cmd.h" + +static int show_help = 0; +static int show_version = 0; +static char *command = NULL; +static char **args = NULL; + +const cli_opt_spec cli_common_opts[] = { + { CLI_OPT_TYPE_SWITCH, "help", 0, &show_help, 1, + CLI_OPT_USAGE_DEFAULT, NULL, "display help information" }, + { CLI_OPT_TYPE_SWITCH, "version", 0, &show_version, 1, + CLI_OPT_USAGE_DEFAULT, NULL, "display the version" }, + { CLI_OPT_TYPE_ARG, "command", 0, &command, 0, + CLI_OPT_USAGE_REQUIRED, "command", "the command to run" }, + { CLI_OPT_TYPE_ARGS, "args", 0, &args, 0, + CLI_OPT_USAGE_DEFAULT, "args", "arguments for the command" }, + { 0 } +}; + +const cli_cmd_spec cli_cmds[] = { + { "cat-file", cmd_cat_file, "Display an object in the repository" }, + { "hash-object", cmd_hash_object, "Hash a raw object and product its object ID" }, + { "help", cmd_help, "Display help information" }, + { NULL } +}; + +int main(int argc, char **argv) +{ + const cli_cmd_spec *cmd; + cli_opt_parser optparser; + cli_opt opt; + char *help_args[3] = { NULL }; + int help_args_len; + int args_len = 0; + int ret = 0; + + if (git_libgit2_init() < 0) { + cli_error("failed to initialize libgit2"); + exit(CLI_EXIT_GIT); + } + + cli_opt_parser_init(&optparser, cli_common_opts, argv + 1, argc - 1, CLI_OPT_PARSE_GNU); + + /* Parse the top-level (common) options and command information */ + while (cli_opt_parser_next(&opt, &optparser)) { + if (!opt.spec) { + cli_opt_status_fprint(stderr, PROGRAM_NAME, &opt); + cli_opt_usage_fprint(stderr, PROGRAM_NAME, NULL, cli_common_opts); + ret = CLI_EXIT_USAGE; + goto done; + } + + /* + * When we see a command, stop parsing and capture the + * remaining arguments as args for the command itself. + */ + if (command) { + args = &argv[optparser.idx]; + args_len = (int)(argc - optparser.idx); + break; + } + } + + if (show_version) { + printf("%s version %s\n", PROGRAM_NAME, LIBGIT2_VERSION); + goto done; + } + + /* + * If `--help ` is specified, delegate to that command's + * `--help` option. If no command is specified, run the `help` + * command. Do this by updating the args to emulate that behavior. + */ + if (!command || show_help) { + help_args[0] = command ? (char *)command : "help"; + help_args[1] = command ? "--help" : NULL; + help_args_len = command ? 2 : 1; + + command = help_args[0]; + args = help_args; + args_len = help_args_len; + } + + if ((cmd = cli_cmd_spec_byname(command)) == NULL) { + ret = cli_error("'%s' is not a %s command. See '%s help'.", + command, PROGRAM_NAME, PROGRAM_NAME); + goto done; + } + + ret = cmd->fn(args_len, args); + +done: + git_libgit2_shutdown(); + return ret; +} diff --git a/src/cli/opt.c b/src/cli/opt.c new file mode 100644 index 00000000000..72df5877fbf --- /dev/null +++ b/src/cli/opt.c @@ -0,0 +1,669 @@ +/* + * Copyright (c), Edward Thomson + * All rights reserved. + * + * This file is part of adopt, distributed under the MIT license. + * For full terms and conditions, see the included LICENSE file. + * + * THIS FILE IS AUTOMATICALLY GENERATED; DO NOT EDIT. + * + * This file was produced by using the `rename.pl` script included with + * adopt. The command-line specified was: + * + * ./rename.pl cli_opt --filename=opt --include=cli.h --inline=GIT_INLINE --header-guard=CLI_opt_h__ --lowercase-status --without-usage + */ + +#include +#include +#include +#include +#include + +#include "cli.h" +#include "opt.h" + +#ifdef _WIN32 +# include +#else +# include +# include +#endif + +#ifdef _MSC_VER +# define alloca _alloca +#endif + +#define spec_is_option_type(x) \ + ((x)->type == CLI_OPT_TYPE_BOOL || \ + (x)->type == CLI_OPT_TYPE_SWITCH || \ + (x)->type == CLI_OPT_TYPE_VALUE) + +GIT_INLINE(const cli_opt_spec *) spec_for_long( + int *is_negated, + int *has_value, + const char **value, + const cli_opt_parser *parser, + const char *arg) +{ + const cli_opt_spec *spec; + char *eql; + size_t eql_pos; + + eql = strchr(arg, '='); + eql_pos = (eql = strchr(arg, '=')) ? (size_t)(eql - arg) : strlen(arg); + + for (spec = parser->specs; spec->type; ++spec) { + /* Handle -- (everything after this is literal) */ + if (spec->type == CLI_OPT_TYPE_LITERAL && arg[0] == '\0') + return spec; + + /* Handle --no-option arguments for bool types */ + if (spec->type == CLI_OPT_TYPE_BOOL && + strncmp(arg, "no-", 3) == 0 && + strcmp(arg + 3, spec->name) == 0) { + *is_negated = 1; + return spec; + } + + /* Handle the typical --option arguments */ + if (spec_is_option_type(spec) && + spec->name && + strcmp(arg, spec->name) == 0) + return spec; + + /* Handle --option=value arguments */ + if (spec->type == CLI_OPT_TYPE_VALUE && + eql && + strncmp(arg, spec->name, eql_pos) == 0 && + spec->name[eql_pos] == '\0') { + *has_value = 1; + *value = arg[eql_pos + 1] ? &arg[eql_pos + 1] : NULL; + return spec; + } + } + + return NULL; +} + +GIT_INLINE(const cli_opt_spec *) spec_for_short( + const char **value, + const cli_opt_parser *parser, + const char *arg) +{ + const cli_opt_spec *spec; + + for (spec = parser->specs; spec->type; ++spec) { + /* Handle -svalue short options with a value */ + if (spec->type == CLI_OPT_TYPE_VALUE && + arg[0] == spec->alias && + arg[1] != '\0') { + *value = &arg[1]; + return spec; + } + + /* Handle typical -s short options */ + if (arg[0] == spec->alias) { + *value = NULL; + return spec; + } + } + + return NULL; +} + +GIT_INLINE(const cli_opt_spec *) spec_for_arg(cli_opt_parser *parser) +{ + const cli_opt_spec *spec; + size_t args = 0; + + for (spec = parser->specs; spec->type; ++spec) { + if (spec->type == CLI_OPT_TYPE_ARG) { + if (args == parser->arg_idx) { + parser->arg_idx++; + return spec; + } + + args++; + } + + if (spec->type == CLI_OPT_TYPE_ARGS && args == parser->arg_idx) + return spec; + } + + return NULL; +} + +GIT_INLINE(int) spec_is_choice(const cli_opt_spec *spec) +{ + return ((spec + 1)->type && + ((spec + 1)->usage & CLI_OPT_USAGE_CHOICE)); +} + +/* + * If we have a choice with switches and bare arguments, and we see + * the switch, then we no longer expect the bare argument. + */ +GIT_INLINE(void) consume_choices(const cli_opt_spec *spec, cli_opt_parser *parser) +{ + /* back up to the beginning of the choices */ + while (spec->type && (spec->usage & CLI_OPT_USAGE_CHOICE)) + --spec; + + if (!spec_is_choice(spec)) + return; + + do { + if (spec->type == CLI_OPT_TYPE_ARG) + parser->arg_idx++; + ++spec; + } while(spec->type && (spec->usage & CLI_OPT_USAGE_CHOICE)); +} + +static cli_opt_status_t parse_long(cli_opt *opt, cli_opt_parser *parser) +{ + const cli_opt_spec *spec; + char *arg = parser->args[parser->idx++]; + const char *value = NULL; + int is_negated = 0, has_value = 0; + + opt->arg = arg; + + if ((spec = spec_for_long(&is_negated, &has_value, &value, parser, &arg[2])) == NULL) { + opt->spec = NULL; + opt->status = CLI_OPT_STATUS_UNKNOWN_OPTION; + goto done; + } + + opt->spec = spec; + + /* Future options parsed as literal */ + if (spec->type == CLI_OPT_TYPE_LITERAL) + parser->in_literal = 1; + + /* --bool or --no-bool */ + else if (spec->type == CLI_OPT_TYPE_BOOL && spec->value) + *((int *)spec->value) = !is_negated; + + /* --accumulate */ + else if (spec->type == CLI_OPT_TYPE_ACCUMULATOR && spec->value) + *((int *)spec->value) += spec->switch_value ? spec->switch_value : 1; + + /* --switch */ + else if (spec->type == CLI_OPT_TYPE_SWITCH && spec->value) + *((int *)spec->value) = spec->switch_value; + + /* Parse values as "--foo=bar" or "--foo bar" */ + else if (spec->type == CLI_OPT_TYPE_VALUE) { + if (has_value) + opt->value = (char *)value; + else if ((parser->idx + 1) <= parser->args_len) + opt->value = parser->args[parser->idx++]; + + if (spec->value) + *((char **)spec->value) = opt->value; + } + + /* Required argument was not provided */ + if (spec->type == CLI_OPT_TYPE_VALUE && + !opt->value && + !(spec->usage & CLI_OPT_USAGE_VALUE_OPTIONAL)) + opt->status = CLI_OPT_STATUS_MISSING_VALUE; + else + opt->status = CLI_OPT_STATUS_OK; + + consume_choices(opt->spec, parser); + +done: + return opt->status; +} + +static cli_opt_status_t parse_short(cli_opt *opt, cli_opt_parser *parser) +{ + const cli_opt_spec *spec; + char *arg = parser->args[parser->idx++]; + const char *value; + + opt->arg = arg; + + if ((spec = spec_for_short(&value, parser, &arg[1 + parser->in_short])) == NULL) { + opt->spec = NULL; + opt->status = CLI_OPT_STATUS_UNKNOWN_OPTION; + goto done; + } + + opt->spec = spec; + + if (spec->type == CLI_OPT_TYPE_BOOL && spec->value) + *((int *)spec->value) = 1; + + else if (spec->type == CLI_OPT_TYPE_ACCUMULATOR && spec->value) + *((int *)spec->value) += spec->switch_value ? spec->switch_value : 1; + + else if (spec->type == CLI_OPT_TYPE_SWITCH && spec->value) + *((int *)spec->value) = spec->switch_value; + + /* Parse values as "-ifoo" or "-i foo" */ + else if (spec->type == CLI_OPT_TYPE_VALUE) { + if (value) + opt->value = (char *)value; + else if ((parser->idx + 1) <= parser->args_len) + opt->value = parser->args[parser->idx++]; + + if (spec->value) + *((char **)spec->value) = opt->value; + } + + /* + * Handle compressed short arguments, like "-fbcd"; see if there's + * another character after the one we processed. If not, advance + * the parser index. + */ + if (spec->type != CLI_OPT_TYPE_VALUE && arg[2 + parser->in_short] != '\0') { + parser->in_short++; + parser->idx--; + } else { + parser->in_short = 0; + } + + /* Required argument was not provided */ + if (spec->type == CLI_OPT_TYPE_VALUE && !opt->value) + opt->status = CLI_OPT_STATUS_MISSING_VALUE; + else + opt->status = CLI_OPT_STATUS_OK; + + consume_choices(opt->spec, parser); + +done: + return opt->status; +} + +static cli_opt_status_t parse_arg(cli_opt *opt, cli_opt_parser *parser) +{ + const cli_opt_spec *spec = spec_for_arg(parser); + + opt->spec = spec; + opt->arg = parser->args[parser->idx]; + + if (!spec) { + parser->idx++; + opt->status = CLI_OPT_STATUS_UNKNOWN_OPTION; + } else if (spec->type == CLI_OPT_TYPE_ARGS) { + if (spec->value) + *((char ***)spec->value) = &parser->args[parser->idx]; + + /* + * We have started a list of arguments; the remainder of + * given arguments need not be examined. + */ + parser->in_args = (parser->args_len - parser->idx); + parser->idx = parser->args_len; + opt->args_len = parser->in_args; + opt->status = CLI_OPT_STATUS_OK; + } else { + if (spec->value) + *((char **)spec->value) = parser->args[parser->idx]; + + parser->idx++; + opt->status = CLI_OPT_STATUS_OK; + } + + return opt->status; +} + +static int support_gnu_style(unsigned int flags) +{ + if ((flags & CLI_OPT_PARSE_FORCE_GNU) != 0) + return 1; + + if ((flags & CLI_OPT_PARSE_GNU) == 0) + return 0; + + /* TODO: Windows */ +#if defined(_WIN32) && defined(UNICODE) + if (_wgetenv(L"POSIXLY_CORRECT") != NULL) + return 0; +#else + if (getenv("POSIXLY_CORRECT") != NULL) + return 0; +#endif + + return 1; +} + +void cli_opt_parser_init( + cli_opt_parser *parser, + const cli_opt_spec specs[], + char **args, + size_t args_len, + unsigned int flags) +{ + assert(parser); + + memset(parser, 0x0, sizeof(cli_opt_parser)); + + parser->specs = specs; + parser->args = args; + parser->args_len = args_len; + parser->flags = flags; + + parser->needs_sort = support_gnu_style(flags); +} + +GIT_INLINE(const cli_opt_spec *) spec_for_sort( + int *needs_value, + const cli_opt_parser *parser, + const char *arg) +{ + int is_negated, has_value = 0; + const char *value; + const cli_opt_spec *spec = NULL; + size_t idx = 0; + + *needs_value = 0; + + if (strncmp(arg, "--", 2) == 0) { + spec = spec_for_long(&is_negated, &has_value, &value, parser, &arg[2]); + *needs_value = !has_value; + } + + else if (strncmp(arg, "-", 1) == 0) { + spec = spec_for_short(&value, parser, &arg[1]); + + /* + * Advance through compressed short arguments to see if + * the last one has a value, eg "-xvffilename". + */ + while (spec && !value && arg[1 + ++idx] != '\0') + spec = spec_for_short(&value, parser, &arg[1 + idx]); + + *needs_value = (value == NULL); + } + + return spec; +} + +/* + * Some parsers allow for handling arguments like "file1 --help file2"; + * this is done by re-sorting the arguments in-place; emulate that. + */ +static int sort_gnu_style(cli_opt_parser *parser) +{ + size_t i, j, insert_idx = parser->idx, offset; + const cli_opt_spec *spec; + char *option, *value; + int needs_value, changed = 0; + + parser->needs_sort = 0; + + for (i = parser->idx; i < parser->args_len; i++) { + spec = spec_for_sort(&needs_value, parser, parser->args[i]); + + /* Not a "-" or "--" prefixed option. No change. */ + if (!spec) + continue; + + /* A "--" alone means remaining args are literal. */ + if (spec->type == CLI_OPT_TYPE_LITERAL) + break; + + option = parser->args[i]; + + /* + * If the argument is a value type and doesn't already + * have a value (eg "--foo=bar" or "-fbar") then we need + * to copy the next argument as its value. + */ + if (spec->type == CLI_OPT_TYPE_VALUE && needs_value) { + /* + * A required value is not provided; set parser + * index to this value so that we fail on it. + */ + if (i + 1 >= parser->args_len) { + parser->idx = i; + return 1; + } + + value = parser->args[i + 1]; + offset = 1; + } else { + value = NULL; + offset = 0; + } + + /* Caller error if args[0] is an option. */ + if (i == 0) + return 0; + + /* Shift args up one (or two) and insert the option */ + for (j = i; j > insert_idx; j--) + parser->args[j + offset] = parser->args[j - 1]; + + parser->args[insert_idx] = option; + + if (value) + parser->args[insert_idx + 1] = value; + + insert_idx += (1 + offset); + i += offset; + + changed = 1; + } + + return changed; +} + +cli_opt_status_t cli_opt_parser_next(cli_opt *opt, cli_opt_parser *parser) +{ + assert(opt && parser); + + memset(opt, 0x0, sizeof(cli_opt)); + + if (parser->idx >= parser->args_len) { + opt->args_len = parser->in_args; + return CLI_OPT_STATUS_DONE; + } + + /* Handle options in long form, those beginning with "--" */ + if (strncmp(parser->args[parser->idx], "--", 2) == 0 && + !parser->in_short && + !parser->in_literal) + return parse_long(opt, parser); + + /* Handle options in short form, those beginning with "-" */ + else if (parser->in_short || + (strncmp(parser->args[parser->idx], "-", 1) == 0 && + !parser->in_literal)) + return parse_short(opt, parser); + + /* + * We've reached the first "bare" argument. In POSIX mode, all + * remaining items on the command line are arguments. In GNU + * mode, there may be long or short options after this. Sort any + * options up to this position then re-parse the current position. + */ + if (parser->needs_sort && sort_gnu_style(parser)) + return cli_opt_parser_next(opt, parser); + + return parse_arg(opt, parser); +} + +GIT_INLINE(int) spec_included(const cli_opt_spec **specs, const cli_opt_spec *spec) +{ + const cli_opt_spec **i; + + for (i = specs; *i; ++i) { + if (spec == *i) + return 1; + } + + return 0; +} + +static cli_opt_status_t validate_required( + cli_opt *opt, + const cli_opt_spec specs[], + const cli_opt_spec **given_specs) +{ + const cli_opt_spec *spec, *required; + int given; + + /* + * Iterate over the possible specs to identify requirements and + * ensure that those have been given on the command-line. + * Note that we can have required *choices*, where one in a + * list of choices must be specified. + */ + for (spec = specs, required = NULL, given = 0; spec->type; ++spec) { + if (!required && (spec->usage & CLI_OPT_USAGE_REQUIRED)) { + required = spec; + given = 0; + } else if (!required) { + continue; + } + + if (!given) + given = spec_included(given_specs, spec); + + /* + * Validate the requirement unless we're in a required + * choice. In that case, keep the required state and + * validate at the end of the choice list. + */ + if (!spec_is_choice(spec)) { + if (!given) { + opt->spec = required; + opt->status = CLI_OPT_STATUS_MISSING_ARGUMENT; + break; + } + + required = NULL; + given = 0; + } + } + + return opt->status; +} + +cli_opt_status_t cli_opt_parse( + cli_opt *opt, + const cli_opt_spec specs[], + char **args, + size_t args_len, + unsigned int flags) +{ + cli_opt_parser parser; + const cli_opt_spec **given_specs; + size_t given_idx = 0; + + cli_opt_parser_init(&parser, specs, args, args_len, flags); + + given_specs = alloca(sizeof(const cli_opt_spec *) * (args_len + 1)); + + while (cli_opt_parser_next(opt, &parser)) { + if (opt->status != CLI_OPT_STATUS_OK && + opt->status != CLI_OPT_STATUS_DONE) + return opt->status; + + if ((opt->spec->usage & CLI_OPT_USAGE_STOP_PARSING)) + return (opt->status = CLI_OPT_STATUS_DONE); + + given_specs[given_idx++] = opt->spec; + } + + given_specs[given_idx] = NULL; + + return validate_required(opt, specs, given_specs); +} + +static int spec_name_fprint(FILE *file, const cli_opt_spec *spec) +{ + int error; + + if (spec->type == CLI_OPT_TYPE_ARG) + error = fprintf(file, "%s", spec->value_name); + else if (spec->type == CLI_OPT_TYPE_ARGS) + error = fprintf(file, "%s", spec->value_name); + else if (spec->alias && !(spec->usage & CLI_OPT_USAGE_SHOW_LONG)) + error = fprintf(file, "-%c", spec->alias); + else + error = fprintf(file, "--%s", spec->name); + + return error; +} + +int cli_opt_status_fprint( + FILE *file, + const char *command, + const cli_opt *opt) +{ + const cli_opt_spec *choice; + int error; + + if (command && (error = fprintf(file, "%s: ", command)) < 0) + return error; + + switch (opt->status) { + case CLI_OPT_STATUS_DONE: + error = fprintf(file, "finished processing arguments (no error)\n"); + break; + case CLI_OPT_STATUS_OK: + error = fprintf(file, "no error\n"); + break; + case CLI_OPT_STATUS_UNKNOWN_OPTION: + error = fprintf(file, "unknown option: %s\n", opt->arg); + break; + case CLI_OPT_STATUS_MISSING_VALUE: + if ((error = fprintf(file, "argument '")) < 0 || + (error = spec_name_fprint(file, opt->spec)) < 0 || + (error = fprintf(file, "' requires a value.\n")) < 0) + break; + break; + case CLI_OPT_STATUS_MISSING_ARGUMENT: + if (spec_is_choice(opt->spec)) { + int is_choice = 1; + + if (spec_is_choice((opt->spec)+1)) + error = fprintf(file, "one of"); + else + error = fprintf(file, "either"); + + if (error < 0) + break; + + for (choice = opt->spec; is_choice; ++choice) { + is_choice = spec_is_choice(choice); + + if (!is_choice) + error = fprintf(file, " or"); + else if (choice != opt->spec) + error = fprintf(file, ","); + + if ((error < 0) || + (error = fprintf(file, " '")) < 0 || + (error = spec_name_fprint(file, choice)) < 0 || + (error = fprintf(file, "'")) < 0) + break; + + if (!spec_is_choice(choice)) + break; + } + + if ((error < 0) || + (error = fprintf(file, " is required.\n")) < 0) + break; + } else { + if ((error = fprintf(file, "argument '")) < 0 || + (error = spec_name_fprint(file, opt->spec)) < 0 || + (error = fprintf(file, "' is required.\n")) < 0) + break; + } + + break; + default: + error = fprintf(file, "unknown status: %d\n", opt->status); + break; + } + + return error; +} + diff --git a/src/cli/opt.h b/src/cli/opt.h new file mode 100644 index 00000000000..6c1d4603ecd --- /dev/null +++ b/src/cli/opt.h @@ -0,0 +1,349 @@ +/* + * Copyright (c), Edward Thomson + * All rights reserved. + * + * This file is part of adopt, distributed under the MIT license. + * For full terms and conditions, see the included LICENSE file. + * + * THIS FILE IS AUTOMATICALLY GENERATED; DO NOT EDIT. + * + * This file was produced by using the `rename.pl` script included with + * adopt. The command-line specified was: + * + * ./rename.pl cli_opt --filename=opt --include=cli.h --inline=GIT_INLINE --header-guard=CLI_opt_h__ --lowercase-status --without-usage + */ + +#ifndef CLI_opt_h__ +#define CLI_opt_h__ + +#include +#include + +/** + * The type of argument to be parsed. + */ +typedef enum { + CLI_OPT_TYPE_NONE = 0, + + /** + * An option that, when specified, sets a given value to true. + * This is useful for options like "--debug". A negation + * option (beginning with "no-") is implicitly specified; for + * example "--no-debug". The `value` pointer in the returned + * option will be set to `1` when this is specified, and set to + * `0` when the negation "no-" option is specified. + */ + CLI_OPT_TYPE_BOOL, + + /** + * An option that, when specified, sets the given `value` pointer + * to the specified `switch_value`. This is useful for booleans + * where you do not want the implicit negation that comes with an + * `CLI_OPT_TYPE_BOOL`, or for switches that multiplex a value, like + * setting a mode. For example, `--read` may set the `value` to + * `MODE_READ` and `--write` may set the `value` to `MODE_WRITE`. + */ + CLI_OPT_TYPE_SWITCH, + + /** + * An option that, when specified, increments the given + * `value` by the given `switch_value`. This can be specified + * multiple times to continue to increment the `value`. + * (For example, "-vvv" to set verbosity to 3.) + */ + CLI_OPT_TYPE_ACCUMULATOR, + + /** + * An option that takes a value, for example `-n value`, + * `-nvalue`, `--name value` or `--name=value`. + */ + CLI_OPT_TYPE_VALUE, + + /** + * A bare "--" that indicates that arguments following this are + * literal. This allows callers to specify things that might + * otherwise look like options, for example to operate on a file + * named "-rf" then you can invoke "program -- -rf" to treat + * "-rf" as an argument not an option. + */ + CLI_OPT_TYPE_LITERAL, + + /** + * A single argument, not an option. When options are exhausted, + * arguments will be matches in the order that they're specified + * in the spec list. For example, if two `CLI_OPT_TYPE_ARGS` are + * specified, `input_file` and `output_file`, then the first bare + * argument on the command line will be `input_file` and the + * second will be `output_file`. + */ + CLI_OPT_TYPE_ARG, + + /** + * A collection of arguments. This is useful when you want to take + * a list of arguments, for example, multiple paths. When specified, + * the value will be set to the first argument in the list. + */ + CLI_OPT_TYPE_ARGS, +} cli_opt_type_t; + +/** + * Additional information about an option, including parsing + * restrictions and usage information to be displayed to the end-user. + */ +typedef enum { + /** Defaults for the argument. */ + CLI_OPT_USAGE_DEFAULT = 0, + + /** This argument is required. */ + CLI_OPT_USAGE_REQUIRED = (1u << 0), + + /** + * This is a multiple choice argument, combined with the previous + * argument. For example, when the previous argument is `-f` and + * this optional is applied to an argument of type `-b` then one + * of `-f` or `-b` may be specified. + */ + CLI_OPT_USAGE_CHOICE = (1u << 1), + + /** + * This argument short-circuits the remainder of parsing. + * Useful for arguments like `--help`. + */ + CLI_OPT_USAGE_STOP_PARSING = (1u << 2), + + /** The argument's value is optional ("-n" or "-n foo") */ + CLI_OPT_USAGE_VALUE_OPTIONAL = (1u << 3), + + /** This argument should not be displayed in usage. */ + CLI_OPT_USAGE_HIDDEN = (1u << 4), + + /** In usage, show the long format instead of the abbreviated format. */ + CLI_OPT_USAGE_SHOW_LONG = (1u << 5), +} cli_opt_usage_t; + +typedef enum { + /** Default parsing behavior. */ + CLI_OPT_PARSE_DEFAULT = 0, + + /** + * Parse with GNU `getopt_long` style behavior, where options can + * be intermixed with arguments at any position (for example, + * "file1 --help file2".) Like `getopt_long`, this can mutate the + * arguments given. + */ + CLI_OPT_PARSE_GNU = (1u << 0), + + /** + * Force GNU `getopt_long` style behavior; the `POSIXLY_CORRECT` + * environment variable is ignored. + */ + CLI_OPT_PARSE_FORCE_GNU = (1u << 1), +} cli_opt_flag_t; + +/** Specification for an available option. */ +typedef struct cli_opt_spec { + /** Type of option expected. */ + cli_opt_type_t type; + + /** Name of the long option. */ + const char *name; + + /** The alias is the short (one-character) option alias. */ + const char alias; + + /** + * If this spec is of type `CLI_OPT_TYPE_BOOL`, this is a pointer + * to an `int` that will be set to `1` if the option is specified. + * + * If this spec is of type `CLI_OPT_TYPE_SWITCH`, this is a pointer + * to an `int` that will be set to the opt's `switch_value` (below) + * when this option is specified. + * + * If this spec is of type `CLI_OPT_TYPE_ACCUMULATOR`, this is a + * pointer to an `int` that will be incremented by the opt's + * `switch_value` (below). If no `switch_value` is provided then + * the value will be incremented by 1. + * + * If this spec is of type `CLI_OPT_TYPE_VALUE`, + * `CLI_OPT_TYPE_VALUE_OPTIONAL`, or `CLI_OPT_TYPE_ARG`, this is + * a pointer to a `char *` that will be set to the value + * specified on the command line. + * + * If this spec is of type `CLI_OPT_TYPE_ARGS`, this is a pointer + * to a `char **` that will be set to the remaining values + * specified on the command line. + */ + void *value; + + /** + * If this spec is of type `CLI_OPT_TYPE_SWITCH`, this is the value + * to set in the option's `value` pointer when it is specified. If + * this spec is of type `CLI_OPT_TYPE_ACCUMULATOR`, this is the value + * to increment in the option's `value` pointer when it is + * specified. This is ignored for other opt types. + */ + int switch_value; + + /** + * Optional usage flags that change parsing behavior and how + * usage information is shown to the end-user. + */ + uint32_t usage; + + /** + * The name of the value, provided when creating usage information. + * This is required only for the functions that display usage + * information and only when a spec is of type `CLI_OPT_TYPE_VALUE, + * `CLI_OPT_TYPE_ARG` or `CLI_OPT_TYPE_ARGS``. + */ + const char *value_name; + + /** + * Optional short description of the option to display to the + * end-user. This is only used when creating usage information. + */ + const char *help; +} cli_opt_spec; + +/** Return value for `cli_opt_parser_next`. */ +typedef enum { + /** Parsing is complete; there are no more arguments. */ + CLI_OPT_STATUS_DONE = 0, + + /** + * This argument was parsed correctly; the `opt` structure is + * populated and the value pointer has been set. + */ + CLI_OPT_STATUS_OK = 1, + + /** + * The argument could not be parsed correctly, it does not match + * any of the specifications provided. + */ + CLI_OPT_STATUS_UNKNOWN_OPTION = 2, + + /** + * The argument matched a spec of type `CLI_OPT_VALUE`, but no value + * was provided. + */ + CLI_OPT_STATUS_MISSING_VALUE = 3, + + /** A required argument was not provided. */ + CLI_OPT_STATUS_MISSING_ARGUMENT = 4, +} cli_opt_status_t; + +/** An option provided on the command-line. */ +typedef struct cli_opt { + /** The status of parsing the most recent argument. */ + cli_opt_status_t status; + + /** + * The specification that was provided on the command-line, or + * `NULL` if the argument did not match an `cli_opt_spec`. + */ + const cli_opt_spec *spec; + + /** + * The argument as it was specified on the command-line, including + * dashes, eg, `-f` or `--foo`. + */ + char *arg; + + /** + * If the spec is of type `CLI_OPT_VALUE` or `CLI_OPT_VALUE_OPTIONAL`, + * this is the value provided to the argument. + */ + char *value; + + /** + * If the argument is of type `CLI_OPT_ARGS`, this is the number of + * arguments remaining. This value is persisted even when parsing + * is complete and `status` == `CLI_OPT_STATUS_DONE`. + */ + size_t args_len; +} cli_opt; + +/* The internal parser state. Callers should not modify this structure. */ +typedef struct cli_opt_parser { + const cli_opt_spec *specs; + char **args; + size_t args_len; + unsigned int flags; + + /* Parser state */ + size_t idx; + size_t arg_idx; + size_t in_args; + size_t in_short; + int needs_sort : 1, + in_literal : 1; +} cli_opt_parser; + +/** + * Parses all the command-line arguments and updates all the options using + * the pointers provided. Parsing stops on any invalid argument and + * information about the failure will be provided in the opt argument. + * + * This is the simplest way to parse options; it handles the initialization + * (`parser_init`) and looping (`parser_next`). + * + * @param opt The The `cli_opt` information that failed parsing + * @param specs A NULL-terminated array of `cli_opt_spec`s that can be parsed + * @param args The arguments that will be parsed + * @param args_len The length of arguments to be parsed + * @param flags The `cli_opt_flag_t flags for parsing + */ +cli_opt_status_t cli_opt_parse( + cli_opt *opt, + const cli_opt_spec specs[], + char **args, + size_t args_len, + unsigned int flags); + +/** + * Initializes a parser that parses the given arguments according to the + * given specifications. + * + * @param parser The `cli_opt_parser` that will be initialized + * @param specs A NULL-terminated array of `cli_opt_spec`s that can be parsed + * @param args The arguments that will be parsed + * @param args_len The length of arguments to be parsed + * @param flags The `cli_opt_flag_t flags for parsing + */ +void cli_opt_parser_init( + cli_opt_parser *parser, + const cli_opt_spec specs[], + char **args, + size_t args_len, + unsigned int flags); + +/** + * Parses the next command-line argument and places the information about + * the argument into the given `opt` data. + * + * @param opt The `cli_opt` information parsed from the argument + * @param parser An `cli_opt_parser` that has been initialized with + * `cli_opt_parser_init` + * @return true if the caller should continue iterating, or 0 if there are + * no arguments left to process. + */ +cli_opt_status_t cli_opt_parser_next( + cli_opt *opt, + cli_opt_parser *parser); + +/** + * Prints the status after parsing the most recent argument. This is + * useful for printing an error message when an unknown argument was + * specified, or when an argument was specified without a value. + * + * @param file The file to print information to + * @param command The name of the command to use when printing (optional) + * @param opt The option that failed to parse + * @return 0 on success, -1 on failure + */ +int cli_opt_status_fprint( + FILE *file, + const char *command, + const cli_opt *opt); + +#endif /* CLI_opt_h__ */ diff --git a/src/cli/opt_usage.c b/src/cli/opt_usage.c new file mode 100644 index 00000000000..6e5d6006ee1 --- /dev/null +++ b/src/cli/opt_usage.c @@ -0,0 +1,194 @@ +/* + * 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 "cli.h" +#include "str.h" + +static int print_spec_name(git_str *out, const cli_opt_spec *spec) +{ + if (spec->type == CLI_OPT_TYPE_VALUE && spec->alias && + !(spec->usage & CLI_OPT_USAGE_VALUE_OPTIONAL) && + !(spec->usage & CLI_OPT_USAGE_SHOW_LONG)) + return git_str_printf(out, "-%c <%s>", spec->alias, spec->value_name); + if (spec->type == CLI_OPT_TYPE_VALUE && spec->alias && + !(spec->usage & CLI_OPT_USAGE_SHOW_LONG)) + return git_str_printf(out, "-%c [<%s>]", spec->alias, spec->value_name); + if (spec->type == CLI_OPT_TYPE_VALUE && + !(spec->usage & CLI_OPT_USAGE_VALUE_OPTIONAL)) + return git_str_printf(out, "--%s[=<%s>]", spec->name, spec->value_name); + if (spec->type == CLI_OPT_TYPE_VALUE) + return git_str_printf(out, "--%s=<%s>", spec->name, spec->value_name); + if (spec->type == CLI_OPT_TYPE_ARG) + return git_str_printf(out, "<%s>", spec->value_name); + if (spec->type == CLI_OPT_TYPE_ARGS) + return git_str_printf(out, "<%s>...", spec->value_name); + if (spec->type == CLI_OPT_TYPE_LITERAL) + return git_str_printf(out, "--"); + if (spec->alias && !(spec->usage & CLI_OPT_USAGE_SHOW_LONG)) + return git_str_printf(out, "-%c", spec->alias); + if (spec->name) + return git_str_printf(out, "--%s", spec->name); + + GIT_ASSERT(0); +} + +/* + * This is similar to adopt's function, but modified to understand + * that we have a command ("git") and a "subcommand" ("checkout"). + * It also understands a terminal's line length and wrap appropriately, + * using a `git_str` for storage. + */ +int cli_opt_usage_fprint( + FILE *file, + const char *command, + const char *subcommand, + const cli_opt_spec specs[]) +{ + git_str usage = GIT_BUF_INIT, opt = GIT_BUF_INIT; + const cli_opt_spec *spec; + size_t i, prefixlen, linelen; + bool choice = false, next_choice = false, optional = false; + int error; + + /* TODO: query actual console width. */ + int console_width = 80; + + if ((error = git_str_printf(&usage, "usage: %s", command)) < 0) + goto done; + + if (subcommand && + (error = git_str_printf(&usage, " %s", subcommand)) < 0) + goto done; + + linelen = git_str_len(&usage); + prefixlen = linelen + 1; + + for (spec = specs; spec->type; ++spec) { + if (!choice) + optional = !(spec->usage & CLI_OPT_USAGE_REQUIRED); + + next_choice = !!((spec + 1)->usage & CLI_OPT_USAGE_CHOICE); + + if (spec->usage & CLI_OPT_USAGE_HIDDEN) + continue; + + if (choice) + git_str_putc(&opt, '|'); + else + git_str_clear(&opt); + + if (optional && !choice) + git_str_putc(&opt, '['); + if (!optional && !choice && next_choice) + git_str_putc(&opt, '('); + + if ((error = print_spec_name(&opt, spec)) < 0) + goto done; + + if (!optional && choice && !next_choice) + git_str_putc(&opt, ')'); + else if (optional && !next_choice) + git_str_putc(&opt, ']'); + + if ((choice = next_choice)) + continue; + + if (git_str_oom(&opt)) { + error = -1; + goto done; + } + + if (linelen > prefixlen && + console_width > 0 && + linelen + git_str_len(&opt) + 1 > (size_t)console_width) { + git_str_putc(&usage, '\n'); + + for (i = 0; i < prefixlen; i++) + git_str_putc(&usage, ' '); + + linelen = prefixlen; + } else { + git_str_putc(&usage, ' '); + linelen += git_str_len(&opt) + 1; + } + + git_str_puts(&usage, git_str_cstr(&opt)); + + if (git_str_oom(&usage)) { + error = -1; + goto done; + } + } + + error = fprintf(file, "%s\n", git_str_cstr(&usage)); + +done: + error = (error < 0) ? -1 : 0; + + git_str_dispose(&usage); + git_str_dispose(&opt); + return error; +} + +int cli_opt_usage_error( + const char *subcommand, + const cli_opt_spec specs[], + const cli_opt *invalid_opt) +{ + cli_opt_status_fprint(stderr, PROGRAM_NAME, invalid_opt); + cli_opt_usage_fprint(stderr, PROGRAM_NAME, subcommand, specs); + return CLI_EXIT_USAGE; +} + +int cli_opt_help_fprint( + FILE *file, + const cli_opt_spec specs[]) +{ + git_str help = GIT_BUF_INIT; + const cli_opt_spec *spec; + int error; + + /* Display required arguments first */ + for (spec = specs; spec->type; ++spec) { + if (! (spec->usage & CLI_OPT_USAGE_REQUIRED) || + (spec->usage & CLI_OPT_USAGE_HIDDEN)) + continue; + + git_str_printf(&help, " "); + + if ((error = print_spec_name(&help, spec)) < 0) + goto done; + + git_str_printf(&help, ": %s\n", spec->help); + } + + /* Display the remaining arguments */ + for (spec = specs; spec->type; ++spec) { + if ((spec->usage & CLI_OPT_USAGE_REQUIRED) || + (spec->usage & CLI_OPT_USAGE_HIDDEN)) + continue; + + git_str_printf(&help, " "); + + if ((error = print_spec_name(&help, spec)) < 0) + goto done; + + git_str_printf(&help, ": %s\n", spec->help); + + } + + if (git_str_oom(&help) || + p_write(fileno(file), help.ptr, help.size) < 0) + error = -1; + +done: + error = (error < 0) ? -1 : 0; + + git_str_dispose(&help); + return error; +} + diff --git a/src/cli/opt_usage.h b/src/cli/opt_usage.h new file mode 100644 index 00000000000..c752494e1aa --- /dev/null +++ b/src/cli/opt_usage.h @@ -0,0 +1,35 @@ +/* + * 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 CLI_opt_usage_h__ +#define CLI_opt_usage_h__ + +/** + * Prints usage information to the given file handle. + * + * @param file The file to print information to + * @param command The name of the command to use when printing + * @param subcommand The name of the subcommand (eg "checkout") to use when printing, or NULL to skip + * @param specs The specifications allowed by the command + * @return 0 on success, -1 on failure + */ +int cli_opt_usage_fprint( + FILE *file, + const char *command, + const char *subcommand, + const cli_opt_spec specs[]); + +int cli_opt_usage_error( + const char *subcommand, + const cli_opt_spec specs[], + const cli_opt *invalid_opt); + +int cli_opt_help_fprint( + FILE *file, + const cli_opt_spec specs[]); + +#endif /* CLI_opt_usage_h__ */ diff --git a/src/win32/precompiled.c b/src/cli/win32/precompiled.c similarity index 100% rename from src/win32/precompiled.c rename to src/cli/win32/precompiled.c diff --git a/src/cli/win32/precompiled.h b/src/cli/win32/precompiled.h new file mode 100644 index 00000000000..b0309b864ad --- /dev/null +++ b/src/cli/win32/precompiled.h @@ -0,0 +1,3 @@ +#include + +#include "cli.h" diff --git a/src/libgit2/CMakeLists.txt b/src/libgit2/CMakeLists.txt new file mode 100644 index 00000000000..0c7ddddbad7 --- /dev/null +++ b/src/libgit2/CMakeLists.txt @@ -0,0 +1,131 @@ +# libgit2: the shared library: this CMakeLists.txt compiles the core +# git library functionality. + +add_library(libgit2 OBJECT) +set_target_properties(libgit2 PROPERTIES C_STANDARD 90) +set_target_properties(libgit2 PROPERTIES C_EXTENSIONS OFF) + +include(PkgBuildConfig) + +set(LIBGIT2_INCLUDES + "${PROJECT_BINARY_DIR}/src" + "${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" + "${PROJECT_SOURCE_DIR}/include/git2/*.h" + "${PROJECT_SOURCE_DIR}/include/git2/sys/*.h") +list(SORT SRC_H) +target_sources(libgit2 PRIVATE ${SRC_H}) + +file(GLOB SRC_GIT2 *.c *.h + streams/*.c streams/*.h + transports/*.c transports/*.h + xdiff/*.c xdiff/*.h) +list(SORT SRC_GIT2) +target_sources(libgit2 PRIVATE ${SRC_GIT2}) + +if(WIN32 AND NOT CYGWIN) + # Add resource information on Windows + set(SRC_RC "git2.rc") +endif() + +if(APPLE) + # The old Secure Transport API has been deprecated in macOS 10.15. + set_source_files_properties(streams/stransport.c PROPERTIES COMPILE_FLAGS -Wno-deprecated) +endif() + +# the xdiff dependency is not (yet) warning-free, disable warnings +# as errors for the xdiff sources until we've sorted them out +if(MSVC) + set_source_files_properties(xdiff/xdiffi.c PROPERTIES COMPILE_FLAGS -WX-) + set_source_files_properties(xdiff/xemit.c PROPERTIES COMPILE_FLAGS -WX-) + set_source_files_properties(xdiff/xhistogram.c PROPERTIES COMPILE_FLAGS -WX-) + set_source_files_properties(xdiff/xmerge.c PROPERTIES COMPILE_FLAGS -WX-) + set_source_files_properties(xdiff/xutils.c PROPERTIES COMPILE_FLAGS -WX-) + set_source_files_properties(xdiff/xpatience.c PROPERTIES COMPILE_FLAGS -WX-) +else() + set_source_files_properties(xdiff/xdiffi.c PROPERTIES COMPILE_FLAGS "-Wno-sign-compare -Wno-unused-parameter") + set_source_files_properties(xdiff/xemit.c PROPERTIES COMPILE_FLAGS "-Wno-sign-compare -Wno-unused-parameter") + set_source_files_properties(xdiff/xhistogram.c PROPERTIES COMPILE_FLAGS "-Wno-sign-compare") + set_source_files_properties(xdiff/xutils.c PROPERTIES COMPILE_FLAGS "-Wno-sign-compare") + set_source_files_properties(xdiff/xpatience.c PROPERTIES COMPILE_FLAGS "-Wno-sign-compare") +endif() + +ide_split_sources(libgit2) +list(APPEND LIBGIT2_OBJECTS $ $ ${LIBGIT2_DEPENDENCY_OBJECTS}) + +target_include_directories(libgit2 PRIVATE ${LIBGIT2_INCLUDES} ${LIBGIT2_DEPENDENCY_INCLUDES} PUBLIC ${PROJECT_SOURCE_DIR}/include) +target_include_directories(libgit2 SYSTEM PRIVATE ${LIBGIT2_SYSTEM_INCLUDES}) + +set(LIBGIT2_INCLUDES ${LIBGIT2_INCLUDES} PARENT_SCOPE) +set(LIBGIT2_OBJECTS ${LIBGIT2_OBJECTS} PARENT_SCOPE) +set(LIBGIT2_DEPENDENCY_INCLUDES ${LIBGIT2_DEPENDENCY_INCLUDES} PARENT_SCOPE) +set(LIBGIT2_DEPENDENCY_OBJECTS ${LIBGIT2_DEPENDENCY_OBJECTS} PARENT_SCOPE) +set(LIBGIT2_SYSTEM_INCLUDES ${LIBGIT2_SYSTEM_INCLUDES} PARENT_SCOPE) +set(LIBGIT2_SYSTEM_LIBS ${LIBGIT2_SYSTEM_LIBS} PARENT_SCOPE) + +# +# Compile and link libgit2 +# + +add_library(libgit2package ${SRC_RC} ${LIBGIT2_OBJECTS}) +target_link_libraries(libgit2package ${LIBGIT2_SYSTEM_LIBS}) + +set_target_properties(libgit2package PROPERTIES C_STANDARD 90) +set_target_properties(libgit2package PROPERTIES LIBRARY_OUTPUT_DIRECTORY ${PROJECT_BINARY_DIR}) +set_target_properties(libgit2package PROPERTIES RUNTIME_OUTPUT_DIRECTORY ${PROJECT_BINARY_DIR}) +set_target_properties(libgit2package PROPERTIES ARCHIVE_OUTPUT_DIRECTORY ${PROJECT_BINARY_DIR}) + +# Workaround for Cmake bug #0011240 (see http://public.kitware.com/Bug/view.php?id=11240) +# Win64+MSVC+static libs = linker error +if(MSVC AND GIT_ARCH_64 AND NOT BUILD_SHARED_LIBS) + set_target_properties(libgit2package PROPERTIES STATIC_LIBRARY_FLAGS "/MACHINE:x64") +endif() + +ide_split_sources(libgit2package) + +if(SONAME) + set_target_properties(libgit2package PROPERTIES VERSION ${libgit2_VERSION}) + set_target_properties(libgit2package PROPERTIES SOVERSION "${libgit2_VERSION_MAJOR}.${libgit2_VERSION_MINOR}") + if(LIBGIT2_FILENAME) + target_compile_definitions(libgit2package PRIVATE LIBGIT2_FILENAME=\"${LIBGIT2_FILENAME}\") + set_target_properties(libgit2package PROPERTIES OUTPUT_NAME ${LIBGIT2_FILENAME}) + elseif(DEFINED LIBGIT2_PREFIX) + set_target_properties(libgit2package PROPERTIES PREFIX "${LIBGIT2_PREFIX}") + endif() +endif() + +pkg_build_config(NAME libgit2 + VERSION ${libgit2_VERSION} + DESCRIPTION "The git library, take 2" + LIBS_SELF git2 + PRIVATE_LIBS ${LIBGIT2_PC_LIBS} + REQUIRES ${LIBGIT2_PC_REQUIRES}) + +if(MSVC_IDE) + # Precompiled headers + set_target_properties(libgit2package PROPERTIES COMPILE_FLAGS "/Yuprecompiled.h /FIprecompiled.h") + set_source_files_properties(win32/precompiled.c COMPILE_FLAGS "/Ycprecompiled.h") +endif() + +# 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}) diff --git a/src/annotated_commit.c b/src/libgit2/annotated_commit.c similarity index 100% rename from src/annotated_commit.c rename to src/libgit2/annotated_commit.c diff --git a/src/annotated_commit.h b/src/libgit2/annotated_commit.h similarity index 100% rename from src/annotated_commit.h rename to src/libgit2/annotated_commit.h diff --git a/src/apply.c b/src/libgit2/apply.c similarity index 100% rename from src/apply.c rename to src/libgit2/apply.c diff --git a/src/apply.h b/src/libgit2/apply.h similarity index 100% rename from src/apply.h rename to src/libgit2/apply.h diff --git a/src/attr.c b/src/libgit2/attr.c similarity index 100% rename from src/attr.c rename to src/libgit2/attr.c diff --git a/src/attr.h b/src/libgit2/attr.h similarity index 100% rename from src/attr.h rename to src/libgit2/attr.h diff --git a/src/attr_file.c b/src/libgit2/attr_file.c similarity index 100% rename from src/attr_file.c rename to src/libgit2/attr_file.c diff --git a/src/attr_file.h b/src/libgit2/attr_file.h similarity index 100% rename from src/attr_file.h rename to src/libgit2/attr_file.h diff --git a/src/attrcache.c b/src/libgit2/attrcache.c similarity index 100% rename from src/attrcache.c rename to src/libgit2/attrcache.c diff --git a/src/attrcache.h b/src/libgit2/attrcache.h similarity index 100% rename from src/attrcache.h rename to src/libgit2/attrcache.h diff --git a/src/blame.c b/src/libgit2/blame.c similarity index 100% rename from src/blame.c rename to src/libgit2/blame.c diff --git a/src/blame.h b/src/libgit2/blame.h similarity index 100% rename from src/blame.h rename to src/libgit2/blame.h diff --git a/src/blame_git.c b/src/libgit2/blame_git.c similarity index 100% rename from src/blame_git.c rename to src/libgit2/blame_git.c diff --git a/src/blame_git.h b/src/libgit2/blame_git.h similarity index 100% rename from src/blame_git.h rename to src/libgit2/blame_git.h diff --git a/src/blob.c b/src/libgit2/blob.c similarity index 99% rename from src/blob.c rename to src/libgit2/blob.c index 19ce8b3b50b..b1680d3a80c 100644 --- a/src/blob.c +++ b/src/libgit2/blob.c @@ -101,7 +101,7 @@ static int write_file_stream( git_oid *id, git_odb *odb, const char *path, git_object_size_t file_size) { int fd, error; - char buffer[FILEIO_BUFSIZE]; + char buffer[GIT_BUFSIZE_FILEIO]; git_odb_stream *stream = NULL; ssize_t read_len = -1; git_object_size_t written = 0; diff --git a/src/blob.h b/src/libgit2/blob.h similarity index 100% rename from src/blob.h rename to src/libgit2/blob.h diff --git a/src/branch.c b/src/libgit2/branch.c similarity index 100% rename from src/branch.c rename to src/libgit2/branch.c diff --git a/src/branch.h b/src/libgit2/branch.h similarity index 100% rename from src/branch.h rename to src/libgit2/branch.h diff --git a/src/buf.c b/src/libgit2/buf.c similarity index 100% rename from src/buf.c rename to src/libgit2/buf.c diff --git a/src/buf.h b/src/libgit2/buf.h similarity index 100% rename from src/buf.h rename to src/libgit2/buf.h diff --git a/src/cache.c b/src/libgit2/cache.c similarity index 100% rename from src/cache.c rename to src/libgit2/cache.c diff --git a/src/cache.h b/src/libgit2/cache.h similarity index 100% rename from src/cache.h rename to src/libgit2/cache.h diff --git a/src/checkout.c b/src/libgit2/checkout.c similarity index 100% rename from src/checkout.c rename to src/libgit2/checkout.c diff --git a/src/checkout.h b/src/libgit2/checkout.h similarity index 100% rename from src/checkout.h rename to src/libgit2/checkout.h diff --git a/src/cherrypick.c b/src/libgit2/cherrypick.c similarity index 100% rename from src/cherrypick.c rename to src/libgit2/cherrypick.c diff --git a/src/clone.c b/src/libgit2/clone.c similarity index 100% rename from src/clone.c rename to src/libgit2/clone.c diff --git a/src/clone.h b/src/libgit2/clone.h similarity index 100% rename from src/clone.h rename to src/libgit2/clone.h diff --git a/src/commit.c b/src/libgit2/commit.c similarity index 100% rename from src/commit.c rename to src/libgit2/commit.c diff --git a/src/commit.h b/src/libgit2/commit.h similarity index 100% rename from src/commit.h rename to src/libgit2/commit.h diff --git a/src/commit_graph.c b/src/libgit2/commit_graph.c similarity index 100% rename from src/commit_graph.c rename to src/libgit2/commit_graph.c diff --git a/src/commit_graph.h b/src/libgit2/commit_graph.h similarity index 100% rename from src/commit_graph.h rename to src/libgit2/commit_graph.h diff --git a/src/commit_list.c b/src/libgit2/commit_list.c similarity index 100% rename from src/commit_list.c rename to src/libgit2/commit_list.c diff --git a/src/commit_list.h b/src/libgit2/commit_list.h similarity index 100% rename from src/commit_list.h rename to src/libgit2/commit_list.h diff --git a/src/libgit2/common.h b/src/libgit2/common.h new file mode 100644 index 00000000000..bb9ec5ac1fe --- /dev/null +++ b/src/libgit2/common.h @@ -0,0 +1,55 @@ +/* + * 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_common_h__ +#define INCLUDE_common_h__ + +#include "git2_util.h" +#include "errors.h" + +/* +* Include the declarations for deprecated functions; this ensures +* that they're decorated with the proper extern/visibility attributes. +*/ +#include "git2/deprecated.h" + +#include "posix.h" + +/** + * Initialize a structure with a version. + */ +GIT_INLINE(void) git__init_structure(void *structure, size_t len, unsigned int version) +{ + memset(structure, 0, len); + *((int*)structure) = version; +} +#define GIT_INIT_STRUCTURE(S,V) git__init_structure(S, sizeof(*S), V) + +#define GIT_INIT_STRUCTURE_FROM_TEMPLATE(PTR,VERSION,TYPE,TPL) do { \ + TYPE _tmpl = TPL; \ + GIT_ERROR_CHECK_VERSION(&(VERSION), _tmpl.version, #TYPE); \ + memcpy((PTR), &_tmpl, sizeof(_tmpl)); } while (0) + +/** + * Check a versioned structure for validity + */ +GIT_INLINE(int) git_error__check_version(const void *structure, unsigned int expected_max, const char *name) +{ + unsigned int actual; + + if (!structure) + return 0; + + actual = *(const unsigned int*)structure; + if (actual > 0 && actual <= expected_max) + return 0; + + git_error_set(GIT_ERROR_INVALID, "invalid version %d on %s", actual, name); + return -1; +} +#define GIT_ERROR_CHECK_VERSION(S,V,N) if (git_error__check_version(S,V,N) < 0) return -1 + +#endif diff --git a/src/config.c b/src/libgit2/config.c similarity index 100% rename from src/config.c rename to src/libgit2/config.c diff --git a/src/config.h b/src/libgit2/config.h similarity index 100% rename from src/config.h rename to src/libgit2/config.h diff --git a/src/config_backend.h b/src/libgit2/config_backend.h similarity index 100% rename from src/config_backend.h rename to src/libgit2/config_backend.h diff --git a/src/config_cache.c b/src/libgit2/config_cache.c similarity index 100% rename from src/config_cache.c rename to src/libgit2/config_cache.c diff --git a/src/config_entries.c b/src/libgit2/config_entries.c similarity index 100% rename from src/config_entries.c rename to src/libgit2/config_entries.c diff --git a/src/config_entries.h b/src/libgit2/config_entries.h similarity index 100% rename from src/config_entries.h rename to src/libgit2/config_entries.h diff --git a/src/config_file.c b/src/libgit2/config_file.c similarity index 100% rename from src/config_file.c rename to src/libgit2/config_file.c diff --git a/src/config_mem.c b/src/libgit2/config_mem.c similarity index 100% rename from src/config_mem.c rename to src/libgit2/config_mem.c diff --git a/src/config_parse.c b/src/libgit2/config_parse.c similarity index 100% rename from src/config_parse.c rename to src/libgit2/config_parse.c diff --git a/src/config_parse.h b/src/libgit2/config_parse.h similarity index 100% rename from src/config_parse.h rename to src/libgit2/config_parse.h diff --git a/src/config_snapshot.c b/src/libgit2/config_snapshot.c similarity index 100% rename from src/config_snapshot.c rename to src/libgit2/config_snapshot.c diff --git a/src/crlf.c b/src/libgit2/crlf.c similarity index 100% rename from src/crlf.c rename to src/libgit2/crlf.c diff --git a/src/delta.c b/src/libgit2/delta.c similarity index 100% rename from src/delta.c rename to src/libgit2/delta.c diff --git a/src/delta.h b/src/libgit2/delta.h similarity index 100% rename from src/delta.h rename to src/libgit2/delta.h diff --git a/src/describe.c b/src/libgit2/describe.c similarity index 100% rename from src/describe.c rename to src/libgit2/describe.c diff --git a/src/diff.c b/src/libgit2/diff.c similarity index 100% rename from src/diff.c rename to src/libgit2/diff.c diff --git a/src/diff.h b/src/libgit2/diff.h similarity index 100% rename from src/diff.h rename to src/libgit2/diff.h diff --git a/src/diff_driver.c b/src/libgit2/diff_driver.c similarity index 100% rename from src/diff_driver.c rename to src/libgit2/diff_driver.c diff --git a/src/diff_driver.h b/src/libgit2/diff_driver.h similarity index 100% rename from src/diff_driver.h rename to src/libgit2/diff_driver.h diff --git a/src/diff_file.c b/src/libgit2/diff_file.c similarity index 100% rename from src/diff_file.c rename to src/libgit2/diff_file.c diff --git a/src/diff_file.h b/src/libgit2/diff_file.h similarity index 100% rename from src/diff_file.h rename to src/libgit2/diff_file.h diff --git a/src/diff_generate.c b/src/libgit2/diff_generate.c similarity index 100% rename from src/diff_generate.c rename to src/libgit2/diff_generate.c diff --git a/src/diff_generate.h b/src/libgit2/diff_generate.h similarity index 100% rename from src/diff_generate.h rename to src/libgit2/diff_generate.h diff --git a/src/diff_parse.c b/src/libgit2/diff_parse.c similarity index 100% rename from src/diff_parse.c rename to src/libgit2/diff_parse.c diff --git a/src/diff_parse.h b/src/libgit2/diff_parse.h similarity index 100% rename from src/diff_parse.h rename to src/libgit2/diff_parse.h diff --git a/src/diff_print.c b/src/libgit2/diff_print.c similarity index 100% rename from src/diff_print.c rename to src/libgit2/diff_print.c diff --git a/src/diff_stats.c b/src/libgit2/diff_stats.c similarity index 100% rename from src/diff_stats.c rename to src/libgit2/diff_stats.c diff --git a/src/diff_stats.h b/src/libgit2/diff_stats.h similarity index 100% rename from src/diff_stats.h rename to src/libgit2/diff_stats.h diff --git a/src/diff_tform.c b/src/libgit2/diff_tform.c similarity index 100% rename from src/diff_tform.c rename to src/libgit2/diff_tform.c diff --git a/src/diff_tform.h b/src/libgit2/diff_tform.h similarity index 100% rename from src/diff_tform.h rename to src/libgit2/diff_tform.h diff --git a/src/diff_xdiff.c b/src/libgit2/diff_xdiff.c similarity index 99% rename from src/diff_xdiff.c rename to src/libgit2/diff_xdiff.c index 3f6eccac13d..5f56c5209a0 100644 --- a/src/diff_xdiff.c +++ b/src/libgit2/diff_xdiff.c @@ -11,6 +11,7 @@ #include "diff.h" #include "diff_driver.h" #include "patch_generate.h" +#include "utf8.h" static int git_xdiff_scan_int(const char **str, int *value) { diff --git a/src/diff_xdiff.h b/src/libgit2/diff_xdiff.h similarity index 100% rename from src/diff_xdiff.h rename to src/libgit2/diff_xdiff.h diff --git a/src/email.c b/src/libgit2/email.c similarity index 100% rename from src/email.c rename to src/libgit2/email.c diff --git a/src/email.h b/src/libgit2/email.h similarity index 100% rename from src/email.h rename to src/libgit2/email.h diff --git a/src/errors.c b/src/libgit2/errors.c similarity index 100% rename from src/errors.c rename to src/libgit2/errors.c diff --git a/src/errors.h b/src/libgit2/errors.h similarity index 93% rename from src/errors.h rename to src/libgit2/errors.h index a2f60f752d8..772c7bad18b 100644 --- a/src/errors.h +++ b/src/libgit2/errors.h @@ -11,9 +11,8 @@ #include "common.h" /* - * Set the error message for this thread, formatting as needed. + * `vprintf`-style formatting for the error message for this thread. */ -void git_error_set(int error_class, const char *fmt, ...) GIT_FORMAT_PRINTF(2, 3); void git_error_vset(int error_class, const char *fmt, va_list ap); /** diff --git a/src/fetch.c b/src/libgit2/fetch.c similarity index 100% rename from src/fetch.c rename to src/libgit2/fetch.c diff --git a/src/fetch.h b/src/libgit2/fetch.h similarity index 100% rename from src/fetch.h rename to src/libgit2/fetch.h diff --git a/src/fetchhead.c b/src/libgit2/fetchhead.c similarity index 100% rename from src/fetchhead.c rename to src/libgit2/fetchhead.c diff --git a/src/fetchhead.h b/src/libgit2/fetchhead.h similarity index 100% rename from src/fetchhead.h rename to src/libgit2/fetchhead.h diff --git a/src/filter.c b/src/libgit2/filter.c similarity index 99% rename from src/filter.c rename to src/libgit2/filter.c index 2712e8c6044..20b21572934 100644 --- a/src/filter.c +++ b/src/libgit2/filter.c @@ -1085,7 +1085,7 @@ int git_filter_list_stream_file( const char *path, git_writestream *target) { - char buf[FILTERIO_BUFSIZE]; + char buf[GIT_BUFSIZE_FILTERIO]; git_str abspath = GIT_STR_INIT; const char *base = repo ? git_repository_workdir(repo) : NULL; git_vector filter_streams = GIT_VECTOR_INIT; diff --git a/src/filter.h b/src/libgit2/filter.h similarity index 100% rename from src/filter.h rename to src/libgit2/filter.h diff --git a/src/win32/git2.rc b/src/libgit2/git2.rc similarity index 100% rename from src/win32/git2.rc rename to src/libgit2/git2.rc diff --git a/src/graph.c b/src/libgit2/graph.c similarity index 100% rename from src/graph.c rename to src/libgit2/graph.c diff --git a/src/hashsig.c b/src/libgit2/hashsig.c similarity index 100% rename from src/hashsig.c rename to src/libgit2/hashsig.c diff --git a/src/ident.c b/src/libgit2/ident.c similarity index 100% rename from src/ident.c rename to src/libgit2/ident.c diff --git a/src/idxmap.c b/src/libgit2/idxmap.c similarity index 100% rename from src/idxmap.c rename to src/libgit2/idxmap.c diff --git a/src/idxmap.h b/src/libgit2/idxmap.h similarity index 100% rename from src/idxmap.h rename to src/libgit2/idxmap.h diff --git a/src/ignore.c b/src/libgit2/ignore.c similarity index 100% rename from src/ignore.c rename to src/libgit2/ignore.c diff --git a/src/ignore.h b/src/libgit2/ignore.h similarity index 100% rename from src/ignore.h rename to src/libgit2/ignore.h diff --git a/src/index.c b/src/libgit2/index.c similarity index 100% rename from src/index.c rename to src/libgit2/index.c diff --git a/src/index.h b/src/libgit2/index.h similarity index 100% rename from src/index.h rename to src/libgit2/index.h diff --git a/src/indexer.c b/src/libgit2/indexer.c similarity index 100% rename from src/indexer.c rename to src/libgit2/indexer.c diff --git a/src/indexer.h b/src/libgit2/indexer.h similarity index 100% rename from src/indexer.h rename to src/libgit2/indexer.h diff --git a/src/iterator.c b/src/libgit2/iterator.c similarity index 100% rename from src/iterator.c rename to src/libgit2/iterator.c diff --git a/src/iterator.h b/src/libgit2/iterator.h similarity index 100% rename from src/iterator.h rename to src/libgit2/iterator.h diff --git a/src/libgit2.c b/src/libgit2/libgit2.c similarity index 100% rename from src/libgit2.c rename to src/libgit2/libgit2.c diff --git a/src/libgit2.h b/src/libgit2/libgit2.h similarity index 100% rename from src/libgit2.h rename to src/libgit2/libgit2.h diff --git a/src/mailmap.c b/src/libgit2/mailmap.c similarity index 100% rename from src/mailmap.c rename to src/libgit2/mailmap.c diff --git a/src/mailmap.h b/src/libgit2/mailmap.h similarity index 100% rename from src/mailmap.h rename to src/libgit2/mailmap.h diff --git a/src/merge.c b/src/libgit2/merge.c similarity index 100% rename from src/merge.c rename to src/libgit2/merge.c diff --git a/src/merge.h b/src/libgit2/merge.h similarity index 100% rename from src/merge.h rename to src/libgit2/merge.h diff --git a/src/merge_driver.c b/src/libgit2/merge_driver.c similarity index 100% rename from src/merge_driver.c rename to src/libgit2/merge_driver.c diff --git a/src/merge_driver.h b/src/libgit2/merge_driver.h similarity index 100% rename from src/merge_driver.h rename to src/libgit2/merge_driver.h diff --git a/src/merge_file.c b/src/libgit2/merge_file.c similarity index 100% rename from src/merge_file.c rename to src/libgit2/merge_file.c diff --git a/src/message.c b/src/libgit2/message.c similarity index 100% rename from src/message.c rename to src/libgit2/message.c diff --git a/src/midx.c b/src/libgit2/midx.c similarity index 100% rename from src/midx.c rename to src/libgit2/midx.c diff --git a/src/midx.h b/src/libgit2/midx.h similarity index 100% rename from src/midx.h rename to src/libgit2/midx.h diff --git a/src/mwindow.c b/src/libgit2/mwindow.c similarity index 100% rename from src/mwindow.c rename to src/libgit2/mwindow.c diff --git a/src/mwindow.h b/src/libgit2/mwindow.h similarity index 100% rename from src/mwindow.h rename to src/libgit2/mwindow.h diff --git a/src/netops.c b/src/libgit2/netops.c similarity index 99% rename from src/netops.c rename to src/libgit2/netops.c index 0a27365b8ae..00640c600ee 100644 --- a/src/netops.c +++ b/src/libgit2/netops.c @@ -12,7 +12,6 @@ #include "posix.h" #include "str.h" -#include "http_parser.h" #include "runtime.h" int gitno_recv(gitno_buffer *buf) diff --git a/src/netops.h b/src/libgit2/netops.h similarity index 100% rename from src/netops.h rename to src/libgit2/netops.h diff --git a/src/notes.c b/src/libgit2/notes.c similarity index 100% rename from src/notes.c rename to src/libgit2/notes.c diff --git a/src/notes.h b/src/libgit2/notes.h similarity index 100% rename from src/notes.h rename to src/libgit2/notes.h diff --git a/src/object.c b/src/libgit2/object.c similarity index 100% rename from src/object.c rename to src/libgit2/object.c diff --git a/src/object.h b/src/libgit2/object.h similarity index 100% rename from src/object.h rename to src/libgit2/object.h diff --git a/src/object_api.c b/src/libgit2/object_api.c similarity index 100% rename from src/object_api.c rename to src/libgit2/object_api.c diff --git a/src/odb.c b/src/libgit2/odb.c similarity index 99% rename from src/odb.c rename to src/libgit2/odb.c index 14eff53c7b8..7b98c72ee8e 100644 --- a/src/odb.c +++ b/src/libgit2/odb.c @@ -198,7 +198,7 @@ void git_odb_object_free(git_odb_object *object) int git_odb__hashfd(git_oid *out, git_file fd, size_t size, git_object_t type) { size_t hdr_len; - char hdr[64], buffer[FILEIO_BUFSIZE]; + char hdr[64], buffer[GIT_BUFSIZE_FILEIO]; git_hash_ctx ctx; ssize_t read_len = 0; int error = 0; @@ -1067,7 +1067,7 @@ int git_odb_expand_ids( int git_odb_read_header(size_t *len_p, git_object_t *type_p, git_odb *db, const git_oid *id) { int error; - git_odb_object *object; + git_odb_object *object = NULL; error = git_odb__read_header_or_object(&object, len_p, type_p, db, id); diff --git a/src/odb.h b/src/libgit2/odb.h similarity index 100% rename from src/odb.h rename to src/libgit2/odb.h diff --git a/src/odb_loose.c b/src/libgit2/odb_loose.c similarity index 100% rename from src/odb_loose.c rename to src/libgit2/odb_loose.c diff --git a/src/odb_mempack.c b/src/libgit2/odb_mempack.c similarity index 100% rename from src/odb_mempack.c rename to src/libgit2/odb_mempack.c diff --git a/src/odb_pack.c b/src/libgit2/odb_pack.c similarity index 100% rename from src/odb_pack.c rename to src/libgit2/odb_pack.c diff --git a/src/offmap.c b/src/libgit2/offmap.c similarity index 100% rename from src/offmap.c rename to src/libgit2/offmap.c diff --git a/src/offmap.h b/src/libgit2/offmap.h similarity index 100% rename from src/offmap.h rename to src/libgit2/offmap.h diff --git a/src/oid.c b/src/libgit2/oid.c similarity index 100% rename from src/oid.c rename to src/libgit2/oid.c diff --git a/src/oid.h b/src/libgit2/oid.h similarity index 100% rename from src/oid.h rename to src/libgit2/oid.h diff --git a/src/oidarray.c b/src/libgit2/oidarray.c similarity index 100% rename from src/oidarray.c rename to src/libgit2/oidarray.c diff --git a/src/oidarray.h b/src/libgit2/oidarray.h similarity index 100% rename from src/oidarray.h rename to src/libgit2/oidarray.h diff --git a/src/oidmap.c b/src/libgit2/oidmap.c similarity index 100% rename from src/oidmap.c rename to src/libgit2/oidmap.c diff --git a/src/oidmap.h b/src/libgit2/oidmap.h similarity index 100% rename from src/oidmap.h rename to src/libgit2/oidmap.h diff --git a/src/pack-objects.c b/src/libgit2/pack-objects.c similarity index 100% rename from src/pack-objects.c rename to src/libgit2/pack-objects.c diff --git a/src/pack-objects.h b/src/libgit2/pack-objects.h similarity index 100% rename from src/pack-objects.h rename to src/libgit2/pack-objects.h diff --git a/src/pack.c b/src/libgit2/pack.c similarity index 100% rename from src/pack.c rename to src/libgit2/pack.c diff --git a/src/pack.h b/src/libgit2/pack.h similarity index 100% rename from src/pack.h rename to src/libgit2/pack.h diff --git a/src/parse.c b/src/libgit2/parse.c similarity index 100% rename from src/parse.c rename to src/libgit2/parse.c diff --git a/src/parse.h b/src/libgit2/parse.h similarity index 100% rename from src/parse.h rename to src/libgit2/parse.h diff --git a/src/patch.c b/src/libgit2/patch.c similarity index 100% rename from src/patch.c rename to src/libgit2/patch.c diff --git a/src/patch.h b/src/libgit2/patch.h similarity index 100% rename from src/patch.h rename to src/libgit2/patch.h diff --git a/src/patch_generate.c b/src/libgit2/patch_generate.c similarity index 100% rename from src/patch_generate.c rename to src/libgit2/patch_generate.c diff --git a/src/patch_generate.h b/src/libgit2/patch_generate.h similarity index 100% rename from src/patch_generate.h rename to src/libgit2/patch_generate.h diff --git a/src/patch_parse.c b/src/libgit2/patch_parse.c similarity index 100% rename from src/patch_parse.c rename to src/libgit2/patch_parse.c diff --git a/src/patch_parse.h b/src/libgit2/patch_parse.h similarity index 100% rename from src/patch_parse.h rename to src/libgit2/patch_parse.h diff --git a/src/path.c b/src/libgit2/path.c similarity index 99% rename from src/path.c rename to src/libgit2/path.c index 05a3dc2cf90..a19340efe6f 100644 --- a/src/path.c +++ b/src/libgit2/path.c @@ -9,6 +9,7 @@ #include "repository.h" #include "fs_path.h" +#include "utf8.h" typedef struct { git_repository *repo; diff --git a/src/path.h b/src/libgit2/path.h similarity index 100% rename from src/path.h rename to src/libgit2/path.h diff --git a/src/pathspec.c b/src/libgit2/pathspec.c similarity index 100% rename from src/pathspec.c rename to src/libgit2/pathspec.c diff --git a/src/pathspec.h b/src/libgit2/pathspec.h similarity index 100% rename from src/pathspec.h rename to src/libgit2/pathspec.h diff --git a/src/proxy.c b/src/libgit2/proxy.c similarity index 100% rename from src/proxy.c rename to src/libgit2/proxy.c diff --git a/src/proxy.h b/src/libgit2/proxy.h similarity index 100% rename from src/proxy.h rename to src/libgit2/proxy.h diff --git a/src/push.c b/src/libgit2/push.c similarity index 100% rename from src/push.c rename to src/libgit2/push.c diff --git a/src/push.h b/src/libgit2/push.h similarity index 100% rename from src/push.h rename to src/libgit2/push.h diff --git a/src/reader.c b/src/libgit2/reader.c similarity index 100% rename from src/reader.c rename to src/libgit2/reader.c diff --git a/src/reader.h b/src/libgit2/reader.h similarity index 100% rename from src/reader.h rename to src/libgit2/reader.h diff --git a/src/rebase.c b/src/libgit2/rebase.c similarity index 100% rename from src/rebase.c rename to src/libgit2/rebase.c diff --git a/src/refdb.c b/src/libgit2/refdb.c similarity index 100% rename from src/refdb.c rename to src/libgit2/refdb.c diff --git a/src/refdb.h b/src/libgit2/refdb.h similarity index 100% rename from src/refdb.h rename to src/libgit2/refdb.h diff --git a/src/refdb_fs.c b/src/libgit2/refdb_fs.c similarity index 100% rename from src/refdb_fs.c rename to src/libgit2/refdb_fs.c diff --git a/src/reflog.c b/src/libgit2/reflog.c similarity index 100% rename from src/reflog.c rename to src/libgit2/reflog.c diff --git a/src/reflog.h b/src/libgit2/reflog.h similarity index 100% rename from src/reflog.h rename to src/libgit2/reflog.h diff --git a/src/refs.c b/src/libgit2/refs.c similarity index 100% rename from src/refs.c rename to src/libgit2/refs.c diff --git a/src/refs.h b/src/libgit2/refs.h similarity index 100% rename from src/refs.h rename to src/libgit2/refs.h diff --git a/src/refspec.c b/src/libgit2/refspec.c similarity index 100% rename from src/refspec.c rename to src/libgit2/refspec.c diff --git a/src/refspec.h b/src/libgit2/refspec.h similarity index 100% rename from src/refspec.h rename to src/libgit2/refspec.h diff --git a/src/remote.c b/src/libgit2/remote.c similarity index 100% rename from src/remote.c rename to src/libgit2/remote.c diff --git a/src/remote.h b/src/libgit2/remote.h similarity index 100% rename from src/remote.h rename to src/libgit2/remote.h diff --git a/src/repo_template.h b/src/libgit2/repo_template.h similarity index 100% rename from src/repo_template.h rename to src/libgit2/repo_template.h diff --git a/src/repository.c b/src/libgit2/repository.c similarity index 100% rename from src/repository.c rename to src/libgit2/repository.c diff --git a/src/repository.h b/src/libgit2/repository.h similarity index 100% rename from src/repository.h rename to src/libgit2/repository.h diff --git a/src/reset.c b/src/libgit2/reset.c similarity index 100% rename from src/reset.c rename to src/libgit2/reset.c diff --git a/src/revert.c b/src/libgit2/revert.c similarity index 100% rename from src/revert.c rename to src/libgit2/revert.c diff --git a/src/revparse.c b/src/libgit2/revparse.c similarity index 100% rename from src/revparse.c rename to src/libgit2/revparse.c diff --git a/src/revwalk.c b/src/libgit2/revwalk.c similarity index 100% rename from src/revwalk.c rename to src/libgit2/revwalk.c diff --git a/src/revwalk.h b/src/libgit2/revwalk.h similarity index 100% rename from src/revwalk.h rename to src/libgit2/revwalk.h diff --git a/src/settings.h b/src/libgit2/settings.h similarity index 100% rename from src/settings.h rename to src/libgit2/settings.h diff --git a/src/signature.c b/src/libgit2/signature.c similarity index 100% rename from src/signature.c rename to src/libgit2/signature.c diff --git a/src/signature.h b/src/libgit2/signature.h similarity index 100% rename from src/signature.h rename to src/libgit2/signature.h diff --git a/src/stash.c b/src/libgit2/stash.c similarity index 100% rename from src/stash.c rename to src/libgit2/stash.c diff --git a/src/status.c b/src/libgit2/status.c similarity index 100% rename from src/status.c rename to src/libgit2/status.c diff --git a/src/status.h b/src/libgit2/status.h similarity index 100% rename from src/status.h rename to src/libgit2/status.h diff --git a/src/strarray.c b/src/libgit2/strarray.c similarity index 100% rename from src/strarray.c rename to src/libgit2/strarray.c diff --git a/src/stream.h b/src/libgit2/stream.h similarity index 100% rename from src/stream.h rename to src/libgit2/stream.h diff --git a/src/streams/mbedtls.c b/src/libgit2/streams/mbedtls.c similarity index 100% rename from src/streams/mbedtls.c rename to src/libgit2/streams/mbedtls.c diff --git a/src/streams/mbedtls.h b/src/libgit2/streams/mbedtls.h similarity index 100% rename from src/streams/mbedtls.h rename to src/libgit2/streams/mbedtls.h diff --git a/src/streams/openssl.c b/src/libgit2/streams/openssl.c similarity index 100% rename from src/streams/openssl.c rename to src/libgit2/streams/openssl.c diff --git a/src/streams/openssl.h b/src/libgit2/streams/openssl.h similarity index 100% rename from src/streams/openssl.h rename to src/libgit2/streams/openssl.h diff --git a/src/streams/openssl_dynamic.c b/src/libgit2/streams/openssl_dynamic.c similarity index 100% rename from src/streams/openssl_dynamic.c rename to src/libgit2/streams/openssl_dynamic.c diff --git a/src/streams/openssl_dynamic.h b/src/libgit2/streams/openssl_dynamic.h similarity index 100% rename from src/streams/openssl_dynamic.h rename to src/libgit2/streams/openssl_dynamic.h diff --git a/src/streams/openssl_legacy.c b/src/libgit2/streams/openssl_legacy.c similarity index 100% rename from src/streams/openssl_legacy.c rename to src/libgit2/streams/openssl_legacy.c diff --git a/src/streams/openssl_legacy.h b/src/libgit2/streams/openssl_legacy.h similarity index 100% rename from src/streams/openssl_legacy.h rename to src/libgit2/streams/openssl_legacy.h diff --git a/src/streams/registry.c b/src/libgit2/streams/registry.c similarity index 100% rename from src/streams/registry.c rename to src/libgit2/streams/registry.c diff --git a/src/streams/registry.h b/src/libgit2/streams/registry.h similarity index 100% rename from src/streams/registry.h rename to src/libgit2/streams/registry.h diff --git a/src/streams/socket.c b/src/libgit2/streams/socket.c similarity index 100% rename from src/streams/socket.c rename to src/libgit2/streams/socket.c diff --git a/src/streams/socket.h b/src/libgit2/streams/socket.h similarity index 100% rename from src/streams/socket.h rename to src/libgit2/streams/socket.h diff --git a/src/streams/stransport.c b/src/libgit2/streams/stransport.c similarity index 100% rename from src/streams/stransport.c rename to src/libgit2/streams/stransport.c diff --git a/src/streams/stransport.h b/src/libgit2/streams/stransport.h similarity index 100% rename from src/streams/stransport.h rename to src/libgit2/streams/stransport.h diff --git a/src/streams/tls.c b/src/libgit2/streams/tls.c similarity index 100% rename from src/streams/tls.c rename to src/libgit2/streams/tls.c diff --git a/src/streams/tls.h b/src/libgit2/streams/tls.h similarity index 100% rename from src/streams/tls.h rename to src/libgit2/streams/tls.h diff --git a/src/submodule.c b/src/libgit2/submodule.c similarity index 100% rename from src/submodule.c rename to src/libgit2/submodule.c diff --git a/src/submodule.h b/src/libgit2/submodule.h similarity index 100% rename from src/submodule.h rename to src/libgit2/submodule.h diff --git a/src/sysdir.c b/src/libgit2/sysdir.c similarity index 100% rename from src/sysdir.c rename to src/libgit2/sysdir.c diff --git a/src/sysdir.h b/src/libgit2/sysdir.h similarity index 100% rename from src/sysdir.h rename to src/libgit2/sysdir.h diff --git a/src/tag.c b/src/libgit2/tag.c similarity index 100% rename from src/tag.c rename to src/libgit2/tag.c diff --git a/src/tag.h b/src/libgit2/tag.h similarity index 100% rename from src/tag.h rename to src/libgit2/tag.h diff --git a/src/threadstate.c b/src/libgit2/threadstate.c similarity index 100% rename from src/threadstate.c rename to src/libgit2/threadstate.c diff --git a/src/threadstate.h b/src/libgit2/threadstate.h similarity index 100% rename from src/threadstate.h rename to src/libgit2/threadstate.h diff --git a/src/trace.c b/src/libgit2/trace.c similarity index 100% rename from src/trace.c rename to src/libgit2/trace.c diff --git a/src/trace.h b/src/libgit2/trace.h similarity index 100% rename from src/trace.h rename to src/libgit2/trace.h diff --git a/src/trailer.c b/src/libgit2/trailer.c similarity index 100% rename from src/trailer.c rename to src/libgit2/trailer.c diff --git a/src/transaction.c b/src/libgit2/transaction.c similarity index 100% rename from src/transaction.c rename to src/libgit2/transaction.c diff --git a/src/transaction.h b/src/libgit2/transaction.h similarity index 100% rename from src/transaction.h rename to src/libgit2/transaction.h diff --git a/src/transport.c b/src/libgit2/transport.c similarity index 100% rename from src/transport.c rename to src/libgit2/transport.c diff --git a/src/transports/auth.c b/src/libgit2/transports/auth.c similarity index 100% rename from src/transports/auth.c rename to src/libgit2/transports/auth.c diff --git a/src/transports/auth.h b/src/libgit2/transports/auth.h similarity index 100% rename from src/transports/auth.h rename to src/libgit2/transports/auth.h diff --git a/src/transports/auth_negotiate.c b/src/libgit2/transports/auth_negotiate.c similarity index 100% rename from src/transports/auth_negotiate.c rename to src/libgit2/transports/auth_negotiate.c diff --git a/src/transports/auth_negotiate.h b/src/libgit2/transports/auth_negotiate.h similarity index 100% rename from src/transports/auth_negotiate.h rename to src/libgit2/transports/auth_negotiate.h diff --git a/src/transports/auth_ntlm.c b/src/libgit2/transports/auth_ntlm.c similarity index 100% rename from src/transports/auth_ntlm.c rename to src/libgit2/transports/auth_ntlm.c diff --git a/src/transports/auth_ntlm.h b/src/libgit2/transports/auth_ntlm.h similarity index 100% rename from src/transports/auth_ntlm.h rename to src/libgit2/transports/auth_ntlm.h diff --git a/src/transports/credential.c b/src/libgit2/transports/credential.c similarity index 100% rename from src/transports/credential.c rename to src/libgit2/transports/credential.c diff --git a/src/transports/credential_helpers.c b/src/libgit2/transports/credential_helpers.c similarity index 100% rename from src/transports/credential_helpers.c rename to src/libgit2/transports/credential_helpers.c diff --git a/src/transports/git.c b/src/libgit2/transports/git.c similarity index 100% rename from src/transports/git.c rename to src/libgit2/transports/git.c diff --git a/src/transports/http.c b/src/libgit2/transports/http.c similarity index 100% rename from src/transports/http.c rename to src/libgit2/transports/http.c diff --git a/src/transports/http.h b/src/libgit2/transports/http.h similarity index 100% rename from src/transports/http.h rename to src/libgit2/transports/http.h diff --git a/src/transports/httpclient.c b/src/libgit2/transports/httpclient.c similarity index 100% rename from src/transports/httpclient.c rename to src/libgit2/transports/httpclient.c diff --git a/src/transports/httpclient.h b/src/libgit2/transports/httpclient.h similarity index 100% rename from src/transports/httpclient.h rename to src/libgit2/transports/httpclient.h diff --git a/src/transports/local.c b/src/libgit2/transports/local.c similarity index 100% rename from src/transports/local.c rename to src/libgit2/transports/local.c diff --git a/src/transports/smart.c b/src/libgit2/transports/smart.c similarity index 100% rename from src/transports/smart.c rename to src/libgit2/transports/smart.c diff --git a/src/transports/smart.h b/src/libgit2/transports/smart.h similarity index 100% rename from src/transports/smart.h rename to src/libgit2/transports/smart.h diff --git a/src/transports/smart_pkt.c b/src/libgit2/transports/smart_pkt.c similarity index 100% rename from src/transports/smart_pkt.c rename to src/libgit2/transports/smart_pkt.c diff --git a/src/transports/smart_protocol.c b/src/libgit2/transports/smart_protocol.c similarity index 100% rename from src/transports/smart_protocol.c rename to src/libgit2/transports/smart_protocol.c diff --git a/src/transports/ssh.c b/src/libgit2/transports/ssh.c similarity index 100% rename from src/transports/ssh.c rename to src/libgit2/transports/ssh.c diff --git a/src/transports/ssh.h b/src/libgit2/transports/ssh.h similarity index 100% rename from src/transports/ssh.h rename to src/libgit2/transports/ssh.h diff --git a/src/transports/winhttp.c b/src/libgit2/transports/winhttp.c similarity index 100% rename from src/transports/winhttp.c rename to src/libgit2/transports/winhttp.c diff --git a/src/tree-cache.c b/src/libgit2/tree-cache.c similarity index 100% rename from src/tree-cache.c rename to src/libgit2/tree-cache.c diff --git a/src/tree-cache.h b/src/libgit2/tree-cache.h similarity index 100% rename from src/tree-cache.h rename to src/libgit2/tree-cache.h diff --git a/src/tree.c b/src/libgit2/tree.c similarity index 100% rename from src/tree.c rename to src/libgit2/tree.c diff --git a/src/tree.h b/src/libgit2/tree.h similarity index 100% rename from src/tree.h rename to src/libgit2/tree.h diff --git a/src/userdiff.h b/src/libgit2/userdiff.h similarity index 100% rename from src/userdiff.h rename to src/libgit2/userdiff.h diff --git a/src/worktree.c b/src/libgit2/worktree.c similarity index 100% rename from src/worktree.c rename to src/libgit2/worktree.c diff --git a/src/worktree.h b/src/libgit2/worktree.h similarity index 100% rename from src/worktree.h rename to src/libgit2/worktree.h diff --git a/src/xdiff/git-xdiff.h b/src/libgit2/xdiff/git-xdiff.h similarity index 100% rename from src/xdiff/git-xdiff.h rename to src/libgit2/xdiff/git-xdiff.h diff --git a/src/xdiff/xdiff.h b/src/libgit2/xdiff/xdiff.h similarity index 100% rename from src/xdiff/xdiff.h rename to src/libgit2/xdiff/xdiff.h diff --git a/src/xdiff/xdiffi.c b/src/libgit2/xdiff/xdiffi.c similarity index 100% rename from src/xdiff/xdiffi.c rename to src/libgit2/xdiff/xdiffi.c diff --git a/src/xdiff/xdiffi.h b/src/libgit2/xdiff/xdiffi.h similarity index 100% rename from src/xdiff/xdiffi.h rename to src/libgit2/xdiff/xdiffi.h diff --git a/src/xdiff/xemit.c b/src/libgit2/xdiff/xemit.c similarity index 100% rename from src/xdiff/xemit.c rename to src/libgit2/xdiff/xemit.c diff --git a/src/xdiff/xemit.h b/src/libgit2/xdiff/xemit.h similarity index 100% rename from src/xdiff/xemit.h rename to src/libgit2/xdiff/xemit.h diff --git a/src/xdiff/xhistogram.c b/src/libgit2/xdiff/xhistogram.c similarity index 100% rename from src/xdiff/xhistogram.c rename to src/libgit2/xdiff/xhistogram.c diff --git a/src/xdiff/xinclude.h b/src/libgit2/xdiff/xinclude.h similarity index 100% rename from src/xdiff/xinclude.h rename to src/libgit2/xdiff/xinclude.h diff --git a/src/xdiff/xmacros.h b/src/libgit2/xdiff/xmacros.h similarity index 100% rename from src/xdiff/xmacros.h rename to src/libgit2/xdiff/xmacros.h diff --git a/src/xdiff/xmerge.c b/src/libgit2/xdiff/xmerge.c similarity index 100% rename from src/xdiff/xmerge.c rename to src/libgit2/xdiff/xmerge.c diff --git a/src/xdiff/xpatience.c b/src/libgit2/xdiff/xpatience.c similarity index 100% rename from src/xdiff/xpatience.c rename to src/libgit2/xdiff/xpatience.c diff --git a/src/xdiff/xprepare.c b/src/libgit2/xdiff/xprepare.c similarity index 100% rename from src/xdiff/xprepare.c rename to src/libgit2/xdiff/xprepare.c diff --git a/src/xdiff/xprepare.h b/src/libgit2/xdiff/xprepare.h similarity index 100% rename from src/xdiff/xprepare.h rename to src/libgit2/xdiff/xprepare.h diff --git a/src/xdiff/xtypes.h b/src/libgit2/xdiff/xtypes.h similarity index 100% rename from src/xdiff/xtypes.h rename to src/libgit2/xdiff/xtypes.h diff --git a/src/xdiff/xutils.c b/src/libgit2/xdiff/xutils.c similarity index 100% rename from src/xdiff/xutils.c rename to src/libgit2/xdiff/xutils.c diff --git a/src/xdiff/xutils.h b/src/libgit2/xdiff/xutils.h similarity index 100% rename from src/xdiff/xutils.h rename to src/libgit2/xdiff/xutils.h diff --git a/src/util/CMakeLists.txt b/src/util/CMakeLists.txt new file mode 100644 index 00000000000..b725d54269d --- /dev/null +++ b/src/util/CMakeLists.txt @@ -0,0 +1,60 @@ +# util: a shared library for common utility functions for libgit2 projects + +add_library(util OBJECT) +set_target_properties(util PROPERTIES C_STANDARD 90) +set_target_properties(util PROPERTIES C_EXTENSIONS OFF) + +set(UTIL_INCLUDES + "${PROJECT_BINARY_DIR}/src" + "${PROJECT_SOURCE_DIR}/src/util" + "${PROJECT_SOURCE_DIR}/include") + +file(GLOB UTIL_SRC *.c *.h allocators/*.c allocators/*.h hash/sha1.h) +list(SORT UTIL_SRC) + +# +# Platform specific sources +# + +if(WIN32 AND NOT CYGWIN) + file(GLOB UTIL_SRC_OS win32/*.c win32/*.h) + list(SORT UTIL_SRC_OS) +elseif(NOT AMIGA) + file(GLOB UTIL_SRC_OS unix/*.c unix/*.h) + list(SORT UTIL_SRC_OS) +endif() + +# +# Hash backend selection +# + +if(USE_SHA1 STREQUAL "CollisionDetection") + file(GLOB UTIL_SRC_HASH hash/sha1/collisiondetect.* hash/sha1/sha1dc/*) + target_compile_definitions(util PRIVATE SHA1DC_NO_STANDARD_INCLUDES=1) + 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") + file(GLOB UTIL_SRC_HASH hash/sha1/openssl.*) +elseif(USE_SHA1 STREQUAL "CommonCrypto") + file(GLOB UTIL_SRC_HASH hash/sha1/common_crypto.*) +elseif(USE_SHA1 STREQUAL "mbedTLS") + file(GLOB UTIL_SRC_HASH hash/sha1/mbedtls.*) +elseif(USE_SHA1 STREQUAL "Win32") + file(GLOB UTIL_SRC_HASH hash/sha1/win32.*) +elseif(USE_SHA1 STREQUAL "Generic") + file(GLOB UTIL_SRC_HASH hash/sha1/generic.*) +else() + message(FATAL_ERROR "Asked for unknown SHA1 backend: ${USE_SHA1}") +endif() + +list(SORT UTIL_SRC_HASH) + +# +# Build the library +# + +target_sources(util PRIVATE ${UTIL_SRC} ${UTIL_SRC_OS} ${UTIL_SRC_HASH}) +ide_split_sources(util) + +target_include_directories(util PRIVATE ${UTIL_INCLUDES} ${LIBGIT2_DEPENDENCY_INCLUDES} PUBLIC ${libgit2_SOURCE_DIR}/include) +target_include_directories(util SYSTEM PRIVATE ${LIBGIT2_SYSTEM_INCLUDES}) diff --git a/src/alloc.c b/src/util/alloc.c similarity index 100% rename from src/alloc.c rename to src/util/alloc.c diff --git a/src/alloc.h b/src/util/alloc.h similarity index 100% rename from src/alloc.h rename to src/util/alloc.h diff --git a/src/allocators/failalloc.c b/src/util/allocators/failalloc.c similarity index 100% rename from src/allocators/failalloc.c rename to src/util/allocators/failalloc.c diff --git a/src/allocators/failalloc.h b/src/util/allocators/failalloc.h similarity index 97% rename from src/allocators/failalloc.h rename to src/util/allocators/failalloc.h index 6115e51e78f..91264a0bb91 100644 --- a/src/allocators/failalloc.h +++ b/src/util/allocators/failalloc.h @@ -8,7 +8,7 @@ #ifndef INCLUDE_allocators_failalloc_h__ #define INCLUDE_allocators_failalloc_h__ -#include "common.h" +#include "git2_util.h" extern void *git_failalloc_malloc(size_t len, const char *file, int line); extern void *git_failalloc_calloc(size_t nelem, size_t elsize, const char *file, int line); diff --git a/src/allocators/stdalloc.c b/src/util/allocators/stdalloc.c similarity index 100% rename from src/allocators/stdalloc.c rename to src/util/allocators/stdalloc.c diff --git a/src/allocators/stdalloc.h b/src/util/allocators/stdalloc.h similarity index 94% rename from src/allocators/stdalloc.h rename to src/util/allocators/stdalloc.h index fa23fe6e346..955038cb0d5 100644 --- a/src/allocators/stdalloc.h +++ b/src/util/allocators/stdalloc.h @@ -8,7 +8,7 @@ #ifndef INCLUDE_allocators_stdalloc_h__ #define INCLUDE_allocators_stdalloc_h__ -#include "common.h" +#include "git2_util.h" #include "alloc.h" diff --git a/src/allocators/win32_leakcheck.c b/src/util/allocators/win32_leakcheck.c similarity index 100% rename from src/allocators/win32_leakcheck.c rename to src/util/allocators/win32_leakcheck.c diff --git a/src/allocators/win32_leakcheck.h b/src/util/allocators/win32_leakcheck.h similarity index 94% rename from src/allocators/win32_leakcheck.h rename to src/util/allocators/win32_leakcheck.h index 089690f90a2..edcd9307f90 100644 --- a/src/allocators/win32_leakcheck.h +++ b/src/util/allocators/win32_leakcheck.h @@ -8,7 +8,7 @@ #ifndef INCLUDE_allocators_win32_leakcheck_h #define INCLUDE_allocators_win32_leakcheck_h -#include "common.h" +#include "git2_util.h" #include "alloc.h" diff --git a/src/array.h b/src/util/array.h similarity index 99% rename from src/array.h rename to src/util/array.h index e97688b365f..cbab52ad1f3 100644 --- a/src/array.h +++ b/src/util/array.h @@ -7,7 +7,7 @@ #ifndef INCLUDE_array_h__ #define INCLUDE_array_h__ -#include "common.h" +#include "git2_util.h" /* * Use this to declare a typesafe resizable array of items, a la: diff --git a/src/assert_safe.h b/src/util/assert_safe.h similarity index 100% rename from src/assert_safe.h rename to src/util/assert_safe.h diff --git a/src/bitvec.h b/src/util/bitvec.h similarity index 100% rename from src/bitvec.h rename to src/util/bitvec.h diff --git a/src/cc-compat.h b/src/util/cc-compat.h similarity index 100% rename from src/cc-compat.h rename to src/util/cc-compat.h diff --git a/src/date.c b/src/util/date.c similarity index 98% rename from src/date.c rename to src/util/date.c index 0e5ffc96b06..4d757e21a00 100644 --- a/src/date.c +++ b/src/util/date.c @@ -1,10 +1,11 @@ /* - * GIT - The information manager from hell + * Copyright (C) the libgit2 contributors. All rights reserved. * - * Copyright (C) Linus Torvalds, 2005 + * 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 "common.h" +#include "git2_util.h" #ifndef GIT_WIN32 #include diff --git a/src/date.h b/src/util/date.h similarity index 100% rename from src/date.h rename to src/util/date.h diff --git a/src/filebuf.c b/src/util/filebuf.c similarity index 99% rename from src/filebuf.c rename to src/util/filebuf.c index eafcba3bd6f..e014d43b25f 100644 --- a/src/filebuf.c +++ b/src/util/filebuf.c @@ -65,7 +65,7 @@ static int lock_file(git_filebuf *file, int flags, mode_t mode) if ((flags & GIT_FILEBUF_APPEND) && git_fs_path_exists(file->path_original) == true) { git_file source; - char buffer[FILEIO_BUFSIZE]; + char buffer[GIT_BUFSIZE_FILEIO]; ssize_t read_bytes; int error = 0; diff --git a/src/filebuf.h b/src/util/filebuf.h similarity index 99% rename from src/filebuf.h rename to src/util/filebuf.h index adbb19936ad..4a61ae4e3bf 100644 --- a/src/filebuf.h +++ b/src/util/filebuf.h @@ -7,7 +7,7 @@ #ifndef INCLUDE_filebuf_h__ #define INCLUDE_filebuf_h__ -#include "common.h" +#include "git2_util.h" #include "futils.h" #include "hash.h" diff --git a/src/fs_path.c b/src/util/fs_path.c similarity index 99% rename from src/fs_path.c rename to src/util/fs_path.c index 7a657778a3b..920c3907349 100644 --- a/src/fs_path.c +++ b/src/util/fs_path.c @@ -7,8 +7,9 @@ #include "fs_path.h" +#include "git2_util.h" +#include "futils.h" #include "posix.h" -#include "repository.h" #ifdef GIT_WIN32 #include "win32/posix.h" #include "win32/w32_buffer.h" @@ -21,6 +22,13 @@ #include #include +#define ensure_error_set(code) do { \ + const git_error *e = git_error_last(); \ + if (!e || !e->message) \ + git_error_set(e ? e->klass : GIT_ERROR_CALLBACK, \ + "filesystem callback returned %d", code); \ + } while(0) + static int dos_drive_prefix_length(const char *path) { int i; @@ -530,7 +538,7 @@ int git_fs_path_walk_up( if (!scan) { error = cb(data, ""); if (error) - git_error_set_after_callback(error); + ensure_error_set(error); return error; } @@ -543,7 +551,7 @@ int git_fs_path_walk_up( iter.ptr[scan] = oldc; if (error) { - git_error_set_after_callback(error); + ensure_error_set(error); break; } @@ -563,7 +571,7 @@ int git_fs_path_walk_up( if (!error && stop == 0 && iter.ptr[0] != '/') { error = cb(data, ""); if (error) - git_error_set_after_callback(error); + ensure_error_set(error); } return error; @@ -1167,7 +1175,7 @@ int git_fs_path_direach( /* Only set our own error if the callback did not set one already */ if (error != 0) { if (!git_error_last()) - git_error_set_after_callback(error); + ensure_error_set(error); break; } diff --git a/src/fs_path.h b/src/util/fs_path.h similarity index 99% rename from src/fs_path.h rename to src/util/fs_path.h index 222c44abcee..bb840c43c6b 100644 --- a/src/fs_path.h +++ b/src/util/fs_path.h @@ -7,7 +7,7 @@ #ifndef INCLUDE_fs_path_h__ #define INCLUDE_fs_path_h__ -#include "common.h" +#include "git2_util.h" #include "posix.h" #include "str.h" diff --git a/src/futils.c b/src/util/futils.c similarity index 96% rename from src/futils.c rename to src/util/futils.c index 42c35955e30..cb872de09f6 100644 --- a/src/futils.c +++ b/src/util/futils.c @@ -167,18 +167,60 @@ int git_futils_readbuffer_fd(git_str *buf, git_file fd, size_t len) /* p_read loops internally to read len bytes */ read_size = p_read(fd, buf->ptr, len); - if (read_size != (ssize_t)len) { + if (read_size < 0) { git_error_set(GIT_ERROR_OS, "failed to read descriptor"); git_str_dispose(buf); return -1; } + if ((size_t)read_size != len) { + git_error_set(GIT_ERROR_FILESYSTEM, "could not read (expected %" PRIuZ " bytes, read %" PRIuZ ")", len, (size_t)read_size); + git_str_dispose(buf); + return -1; + } + buf->ptr[read_size] = '\0'; buf->size = read_size; return 0; } +int git_futils_readbuffer_fd_full(git_str *buf, git_file fd) +{ + static size_t blocksize = 10240; + size_t alloc_len = 0, total_size = 0; + ssize_t read_size = 0; + + git_str_clear(buf); + + while (true) { + GIT_ERROR_CHECK_ALLOC_ADD(&alloc_len, alloc_len, blocksize); + + if (git_str_grow(buf, alloc_len) < 0) + return -1; + + /* p_read loops internally to read blocksize bytes */ + read_size = p_read(fd, buf->ptr, blocksize); + + if (read_size < 0) { + git_error_set(GIT_ERROR_OS, "failed to read descriptor"); + git_str_dispose(buf); + return -1; + } + + total_size += read_size; + + if ((size_t)read_size < blocksize) { + break; + } + } + + buf->ptr[total_size] = '\0'; + buf->size = total_size; + + return 0; +} + int git_futils_readbuffer_updated( git_str *out, const char *path, @@ -856,7 +898,7 @@ int git_futils_fake_symlink(const char *target, const char *path) static int cp_by_fd(int ifd, int ofd, bool close_fd_when_done) { int error = 0; - char buffer[FILEIO_BUFSIZE]; + char buffer[GIT_BUFSIZE_FILEIO]; ssize_t len = 0; while (!error && (len = p_read(ifd, buffer, sizeof(buffer))) > 0) diff --git a/src/futils.h b/src/util/futils.h similarity index 99% rename from src/futils.h rename to src/util/futils.h index a82ec41cc63..3f207afb2f2 100644 --- a/src/futils.h +++ b/src/util/futils.h @@ -7,7 +7,7 @@ #ifndef INCLUDE_futils_h__ #define INCLUDE_futils_h__ -#include "common.h" +#include "git2_util.h" #include "map.h" #include "posix.h" @@ -27,6 +27,7 @@ extern int git_futils_readbuffer_updated( const char *path, unsigned char checksum[GIT_HASH_SHA1_SIZE], int *updated); +extern int git_futils_readbuffer_fd_full(git_str *obj, git_file fd); extern int git_futils_readbuffer_fd(git_str *obj, git_file fd, size_t len); /* Additional constants for `git_futils_writebuffer`'s `open_flags`. We diff --git a/src/common.h b/src/util/git2_util.h similarity index 71% rename from src/common.h rename to src/util/git2_util.h index 549bddb5932..ad3f1c71fc3 100644 --- a/src/common.h +++ b/src/util/git2_util.h @@ -4,8 +4,8 @@ * 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_common_h__ -#define INCLUDE_common_h__ +#ifndef INCLUDE_git2_util_h__ +#define INCLUDE_git2_util_h__ #ifndef LIBGIT2_NO_FEATURES_H # include "git2/sys/features.h" @@ -14,13 +14,13 @@ #include "git2/common.h" #include "cc-compat.h" +typedef struct git_str git_str; + /** Declare a function as always inlined. */ #if defined(_MSC_VER) # define GIT_INLINE(type) static __inline type #elif defined(__GNUC__) # define GIT_INLINE(type) static __inline__ type -#elif defined(__STDC_VERSION__) && (__STDC_VERSION__ >= 199901L) -# define GIT_INLINE(type) static inline type #else # define GIT_INLINE(type) static type #endif @@ -67,12 +67,12 @@ # include # include "win32/msvc-compat.h" # include "win32/mingw-compat.h" -# include "win32/w32_common.h" # include "win32/win32-compat.h" -# include "win32/error.h" +# include "win32/w32_common.h" # include "win32/version.h" +# include "win32/error.h" # ifdef GIT_THREADS -# include "win32/thread.h" +# include "win32/thread.h" # endif #else @@ -99,24 +99,17 @@ #include "git2/types.h" #include "git2/errors.h" -#include "errors.h" #include "thread.h" #include "integer.h" #include "assert_safe.h" -#include "utf8.h" - -/* - * Include the declarations for deprecated functions; this ensures - * that they're decorated with the proper extern/visibility attributes. - */ -#include "git2/deprecated.h" #include "posix.h" -#define DEFAULT_BUFSIZE 65536 -#define FILEIO_BUFSIZE DEFAULT_BUFSIZE -#define FILTERIO_BUFSIZE DEFAULT_BUFSIZE -#define NETIO_BUFSIZE DEFAULT_BUFSIZE +#define GIT_BUFSIZE_DEFAULT 65536 +#define GIT_BUFSIZE_FILEIO GIT_BUFSIZE_DEFAULT +#define GIT_BUFSIZE_FILTERIO GIT_BUFSIZE_DEFAULT +#define GIT_BUFSIZE_NETIO GIT_BUFSIZE_DEFAULT + /** * Check a pointer allocation result, returning -1 if it failed. @@ -126,7 +119,7 @@ } while(0) /** - * Check a string buffer allocation result, returning -1 if it failed. + * Check a buffer allocation result, returning -1 if it failed. */ #define GIT_ERROR_CHECK_ALLOC_STR(buf) do { \ if ((void *)(buf) == NULL || git_str_oom(buf)) { return -1; } \ @@ -138,40 +131,6 @@ #define GIT_ERROR_CHECK_ERROR(code) \ do { int _err = (code); if (_err) return _err; } while (0) -/** - * Check a versioned structure for validity - */ -GIT_INLINE(int) git_error__check_version(const void *structure, unsigned int expected_max, const char *name) -{ - unsigned int actual; - - if (!structure) - return 0; - - actual = *(const unsigned int*)structure; - if (actual > 0 && actual <= expected_max) - return 0; - - git_error_set(GIT_ERROR_INVALID, "invalid version %d on %s", actual, name); - return -1; -} -#define GIT_ERROR_CHECK_VERSION(S,V,N) if (git_error__check_version(S,V,N) < 0) return -1 - -/** - * Initialize a structure with a version. - */ -GIT_INLINE(void) git__init_structure(void *structure, size_t len, unsigned int version) -{ - memset(structure, 0, len); - *((int*)structure) = version; -} -#define GIT_INIT_STRUCTURE(S,V) git__init_structure(S, sizeof(*S), V) - -#define GIT_INIT_STRUCTURE_FROM_TEMPLATE(PTR,VERSION,TYPE,TPL) do { \ - TYPE _tmpl = TPL; \ - GIT_ERROR_CHECK_VERSION(&(VERSION), _tmpl.version, #TYPE); \ - memcpy((PTR), &_tmpl, sizeof(_tmpl)); } while (0) - /** Check for additive overflow, setting an error if would occur. */ #define GIT_ADD_SIZET_OVERFLOW(out, one, two) \ @@ -204,11 +163,6 @@ GIT_INLINE(void) git__init_structure(void *structure, size_t len, unsigned int v #define GIT_ERROR_CHECK_ALLOC_MULTIPLY(out, nelem, elsize) \ if (GIT_MULTIPLY_SIZET_OVERFLOW(out, nelem, elsize)) { return -1; } -/* NOTE: other git_error functions are in the public errors.h header file */ - -/* Forward declare git_str */ -typedef struct git_str git_str; - #include "util.h" #endif diff --git a/src/hash.c b/src/util/hash.c similarity index 100% rename from src/hash.c rename to src/util/hash.c diff --git a/src/hash.h b/src/util/hash.h similarity index 98% rename from src/hash.h rename to src/util/hash.h index 507c1cb256f..5f138656349 100644 --- a/src/hash.h +++ b/src/util/hash.h @@ -8,7 +8,7 @@ #ifndef INCLUDE_hash_h__ #define INCLUDE_hash_h__ -#include "common.h" +#include "git2_util.h" #include "hash/sha1.h" diff --git a/src/hash/sha1.h b/src/util/hash/sha1.h similarity index 97% rename from src/hash/sha1.h rename to src/util/hash/sha1.h index 4b4dae3f831..9d32bce42e5 100644 --- a/src/hash/sha1.h +++ b/src/util/hash/sha1.h @@ -8,7 +8,7 @@ #ifndef INCLUDE_hash_sha1_h__ #define INCLUDE_hash_sha1_h__ -#include "common.h" +#include "git2_util.h" typedef struct git_hash_sha1_ctx git_hash_sha1_ctx; diff --git a/src/hash/sha1/collisiondetect.c b/src/util/hash/sha1/collisiondetect.c similarity index 100% rename from src/hash/sha1/collisiondetect.c rename to src/util/hash/sha1/collisiondetect.c diff --git a/src/hash/sha1/collisiondetect.h b/src/util/hash/sha1/collisiondetect.h similarity index 100% rename from src/hash/sha1/collisiondetect.h rename to src/util/hash/sha1/collisiondetect.h diff --git a/src/hash/sha1/common_crypto.c b/src/util/hash/sha1/common_crypto.c similarity index 100% rename from src/hash/sha1/common_crypto.c rename to src/util/hash/sha1/common_crypto.c diff --git a/src/hash/sha1/common_crypto.h b/src/util/hash/sha1/common_crypto.h similarity index 100% rename from src/hash/sha1/common_crypto.h rename to src/util/hash/sha1/common_crypto.h diff --git a/src/hash/sha1/generic.c b/src/util/hash/sha1/generic.c similarity index 100% rename from src/hash/sha1/generic.c rename to src/util/hash/sha1/generic.c diff --git a/src/hash/sha1/generic.h b/src/util/hash/sha1/generic.h similarity index 100% rename from src/hash/sha1/generic.h rename to src/util/hash/sha1/generic.h diff --git a/src/hash/sha1/mbedtls.c b/src/util/hash/sha1/mbedtls.c similarity index 100% rename from src/hash/sha1/mbedtls.c rename to src/util/hash/sha1/mbedtls.c diff --git a/src/hash/sha1/mbedtls.h b/src/util/hash/sha1/mbedtls.h similarity index 100% rename from src/hash/sha1/mbedtls.h rename to src/util/hash/sha1/mbedtls.h diff --git a/src/hash/sha1/openssl.c b/src/util/hash/sha1/openssl.c similarity index 100% rename from src/hash/sha1/openssl.c rename to src/util/hash/sha1/openssl.c diff --git a/src/hash/sha1/openssl.h b/src/util/hash/sha1/openssl.h similarity index 100% rename from src/hash/sha1/openssl.h rename to src/util/hash/sha1/openssl.h diff --git a/src/hash/sha1/sha1dc/sha1.c b/src/util/hash/sha1/sha1dc/sha1.c similarity index 100% rename from src/hash/sha1/sha1dc/sha1.c rename to src/util/hash/sha1/sha1dc/sha1.c diff --git a/src/hash/sha1/sha1dc/sha1.h b/src/util/hash/sha1/sha1dc/sha1.h similarity index 100% rename from src/hash/sha1/sha1dc/sha1.h rename to src/util/hash/sha1/sha1dc/sha1.h diff --git a/src/hash/sha1/sha1dc/ubc_check.c b/src/util/hash/sha1/sha1dc/ubc_check.c similarity index 100% rename from src/hash/sha1/sha1dc/ubc_check.c rename to src/util/hash/sha1/sha1dc/ubc_check.c diff --git a/src/hash/sha1/sha1dc/ubc_check.h b/src/util/hash/sha1/sha1dc/ubc_check.h similarity index 100% rename from src/hash/sha1/sha1dc/ubc_check.h rename to src/util/hash/sha1/sha1dc/ubc_check.h diff --git a/src/hash/sha1/win32.c b/src/util/hash/sha1/win32.c similarity index 100% rename from src/hash/sha1/win32.c rename to src/util/hash/sha1/win32.c diff --git a/src/hash/sha1/win32.h b/src/util/hash/sha1/win32.h similarity index 100% rename from src/hash/sha1/win32.h rename to src/util/hash/sha1/win32.h diff --git a/src/integer.h b/src/util/integer.h similarity index 100% rename from src/integer.h rename to src/util/integer.h diff --git a/src/khash.h b/src/util/khash.h similarity index 100% rename from src/khash.h rename to src/util/khash.h diff --git a/src/map.h b/src/util/map.h similarity index 98% rename from src/map.h rename to src/util/map.h index 01931d199c0..c101e46f6a6 100644 --- a/src/map.h +++ b/src/util/map.h @@ -7,7 +7,7 @@ #ifndef INCLUDE_map_h__ #define INCLUDE_map_h__ -#include "common.h" +#include "git2_util.h" /* p_mmap() prot values */ diff --git a/src/net.c b/src/util/net.c similarity index 99% rename from src/net.c rename to src/util/net.c index a76fd1d7c5b..b2236daf8a1 100644 --- a/src/net.c +++ b/src/util/net.c @@ -6,7 +6,6 @@ */ #include "net.h" -#include "netops.h" #include diff --git a/src/net.h b/src/util/net.h similarity index 99% rename from src/net.h rename to src/util/net.h index 499315e6ce2..88030a95295 100644 --- a/src/net.h +++ b/src/util/net.h @@ -7,7 +7,7 @@ #ifndef INCLUDE_net_h__ #define INCLUDE_net_h__ -#include "common.h" +#include "git2_util.h" typedef struct git_net_url { char *scheme; diff --git a/src/pool.c b/src/util/pool.c similarity index 100% rename from src/pool.c rename to src/util/pool.c diff --git a/src/pool.h b/src/util/pool.h similarity index 99% rename from src/pool.h rename to src/util/pool.h index cecb84665ff..0238431b0a0 100644 --- a/src/pool.h +++ b/src/util/pool.h @@ -7,7 +7,7 @@ #ifndef INCLUDE_pool_h__ #define INCLUDE_pool_h__ -#include "common.h" +#include "git2_util.h" #include "vector.h" diff --git a/src/posix.c b/src/util/posix.c similarity index 100% rename from src/posix.c rename to src/util/posix.c diff --git a/src/posix.h b/src/util/posix.h similarity index 99% rename from src/posix.h rename to src/util/posix.h index e6f60307811..c8f8cd9d2cc 100644 --- a/src/posix.h +++ b/src/util/posix.h @@ -7,7 +7,7 @@ #ifndef INCLUDE_posix_h__ #define INCLUDE_posix_h__ -#include "common.h" +#include "git2_util.h" #include #include diff --git a/src/pqueue.c b/src/util/pqueue.c similarity index 100% rename from src/pqueue.c rename to src/util/pqueue.c diff --git a/src/pqueue.h b/src/util/pqueue.h similarity index 98% rename from src/pqueue.h rename to src/util/pqueue.h index 4db74ea0371..97232b4a9fd 100644 --- a/src/pqueue.h +++ b/src/util/pqueue.h @@ -7,7 +7,7 @@ #ifndef INCLUDE_pqueue_h__ #define INCLUDE_pqueue_h__ -#include "common.h" +#include "git2_util.h" #include "vector.h" diff --git a/src/rand.c b/src/util/rand.c similarity index 99% rename from src/rand.c rename to src/util/rand.c index 0a208134e4c..4324949023b 100644 --- a/src/rand.c +++ b/src/util/rand.c @@ -6,7 +6,7 @@ worldwide. This software is distributed without any warranty. See . */ -#include "common.h" +#include "git2_util.h" #include "rand.h" #include "runtime.h" diff --git a/src/rand.h b/src/util/rand.h similarity index 97% rename from src/rand.h rename to src/util/rand.h index 2e60561e51d..fa0619aa27d 100644 --- a/src/rand.h +++ b/src/util/rand.h @@ -7,7 +7,7 @@ #ifndef INCLUDE_rand_h__ #define INCLUDE_rand_h__ -#include "common.h" +#include "git2_util.h" /** * Initialize the random number generation subsystem. This will diff --git a/src/regexp.c b/src/util/regexp.c similarity index 100% rename from src/regexp.c rename to src/util/regexp.c diff --git a/src/regexp.h b/src/util/regexp.h similarity index 99% rename from src/regexp.h rename to src/util/regexp.h index 2592ef38352..d0862b10786 100644 --- a/src/regexp.h +++ b/src/util/regexp.h @@ -8,7 +8,7 @@ #ifndef INCLUDE_regexp_h__ #define INCLUDE_regexp_h__ -#include "common.h" +#include "git2_util.h" #if defined(GIT_REGEX_BUILTIN) || defined(GIT_REGEX_PCRE) # include "pcre.h" diff --git a/src/runtime.c b/src/util/runtime.c similarity index 99% rename from src/runtime.c rename to src/util/runtime.c index c05dee8b96d..a7711ffc44c 100644 --- a/src/runtime.c +++ b/src/util/runtime.c @@ -5,7 +5,7 @@ * a Linking Exception. For full terms see the included COPYING file. */ -#include "common.h" +#include "git2_util.h" #include "runtime.h" static git_runtime_shutdown_fn shutdown_callback[32]; diff --git a/src/runtime.h b/src/util/runtime.h similarity index 98% rename from src/runtime.h rename to src/util/runtime.h index 24ac58ee96c..6cbfd6043a4 100644 --- a/src/runtime.h +++ b/src/util/runtime.h @@ -7,7 +7,7 @@ #ifndef INCLUDE_runtime_h__ #define INCLUDE_runtime_h__ -#include "common.h" +#include "git2_util.h" typedef int (*git_runtime_init_fn)(void); typedef void (*git_runtime_shutdown_fn)(void); diff --git a/src/sortedcache.c b/src/util/sortedcache.c similarity index 100% rename from src/sortedcache.c rename to src/util/sortedcache.c diff --git a/src/sortedcache.h b/src/util/sortedcache.h similarity index 99% rename from src/sortedcache.h rename to src/util/sortedcache.h index ef260a093a5..3eee4659f58 100644 --- a/src/sortedcache.h +++ b/src/util/sortedcache.h @@ -7,7 +7,7 @@ #ifndef INCLUDE_sorted_cache_h__ #define INCLUDE_sorted_cache_h__ -#include "common.h" +#include "git2_util.h" #include "util.h" #include "futils.h" diff --git a/src/str.c b/src/util/str.c similarity index 100% rename from src/str.c rename to src/util/str.c diff --git a/src/str.h b/src/util/str.h similarity index 99% rename from src/str.h rename to src/util/str.h index ef769ce2f98..588e6fc22bc 100644 --- a/src/str.h +++ b/src/util/str.h @@ -7,7 +7,7 @@ #ifndef INCLUDE_str_h__ #define INCLUDE_str_h__ -#include "common.h" +#include "git2_util.h" struct git_str { char *ptr; diff --git a/src/strmap.c b/src/util/strmap.c similarity index 100% rename from src/strmap.c rename to src/util/strmap.c diff --git a/src/strmap.h b/src/util/strmap.h similarity index 99% rename from src/strmap.h rename to src/util/strmap.h index 9f5e4cc8bab..b64d3dcb55d 100644 --- a/src/strmap.h +++ b/src/util/strmap.h @@ -7,7 +7,7 @@ #ifndef INCLUDE_strmap_h__ #define INCLUDE_strmap_h__ -#include "common.h" +#include "git2_util.h" /** A map with C strings as key. */ typedef struct kh_str_s git_strmap; diff --git a/src/strnlen.h b/src/util/strnlen.h similarity index 100% rename from src/strnlen.h rename to src/util/strnlen.h diff --git a/src/thread.c b/src/util/thread.c similarity index 99% rename from src/thread.c rename to src/util/thread.c index 3171771d7f3..bc7364f8c1a 100644 --- a/src/thread.c +++ b/src/util/thread.c @@ -5,7 +5,7 @@ * a Linking Exception. For full terms see the included COPYING file. */ -#include "common.h" +#include "git2_util.h" #if !defined(GIT_THREADS) diff --git a/src/thread.h b/src/util/thread.h similarity index 100% rename from src/thread.h rename to src/util/thread.h diff --git a/src/tsort.c b/src/util/tsort.c similarity index 99% rename from src/tsort.c rename to src/util/tsort.c index 045efad23f6..2ef03d03a88 100644 --- a/src/tsort.c +++ b/src/util/tsort.c @@ -5,7 +5,7 @@ * a Linking Exception. For full terms see the included COPYING file. */ -#include "common.h" +#include "git2_util.h" /** * An array-of-pointers implementation of Python's Timsort diff --git a/src/unix/map.c b/src/util/unix/map.c similarity index 98% rename from src/unix/map.c rename to src/util/unix/map.c index 23fcb786e5a..93307768947 100644 --- a/src/unix/map.c +++ b/src/util/unix/map.c @@ -5,7 +5,7 @@ * a Linking Exception. For full terms see the included COPYING file. */ -#include "common.h" +#include "git2_util.h" #if !defined(GIT_WIN32) && !defined(NO_MMAP) diff --git a/src/unix/posix.h b/src/util/unix/posix.h similarity index 99% rename from src/unix/posix.h rename to src/util/unix/posix.h index 49065e5336c..778477e8e2f 100644 --- a/src/unix/posix.h +++ b/src/util/unix/posix.h @@ -7,7 +7,7 @@ #ifndef INCLUDE_unix_posix_h__ #define INCLUDE_unix_posix_h__ -#include "common.h" +#include "git2_util.h" #include #include diff --git a/src/unix/pthread.h b/src/util/unix/pthread.h similarity index 100% rename from src/unix/pthread.h rename to src/util/unix/pthread.h diff --git a/src/unix/realpath.c b/src/util/unix/realpath.c similarity index 96% rename from src/unix/realpath.c rename to src/util/unix/realpath.c index f1ca669f74d..9e31a63b9f4 100644 --- a/src/unix/realpath.c +++ b/src/util/unix/realpath.c @@ -5,7 +5,7 @@ * a Linking Exception. For full terms see the included COPYING file. */ -#include "common.h" +#include "git2_util.h" #ifndef GIT_WIN32 diff --git a/src/utf8.c b/src/util/utf8.c similarity index 99% rename from src/utf8.c rename to src/util/utf8.c index 77065cb710e..c566fdf2084 100644 --- a/src/utf8.c +++ b/src/util/utf8.c @@ -7,7 +7,7 @@ #include "utf8.h" -#include "common.h" +#include "git2_util.h" /* * git_utf8_iterate is taken from the utf8proc project, diff --git a/src/utf8.h b/src/util/utf8.h similarity index 98% rename from src/utf8.h rename to src/util/utf8.h index dff91b2945a..753ab07e2a5 100644 --- a/src/utf8.h +++ b/src/util/utf8.h @@ -7,7 +7,7 @@ #ifndef INCLUDE_utf8_h__ #define INCLUDE_utf8_h__ -#include "common.h" +#include "git2_util.h" /* * Iterate through an UTF-8 string, yielding one codepoint at a time. diff --git a/src/util.c b/src/util/util.c similarity index 99% rename from src/util.c rename to src/util/util.c index e06d4ca0913..aee95fddfb5 100644 --- a/src/util.c +++ b/src/util/util.c @@ -7,7 +7,7 @@ #include "util.h" -#include "common.h" +#include "git2_util.h" #ifdef GIT_WIN32 # include "win32/utf-conv.h" diff --git a/src/util.h b/src/util/util.h similarity index 99% rename from src/util.h rename to src/util/util.h index 141779ade85..8d6d1d6b683 100644 --- a/src/util.h +++ b/src/util/util.h @@ -12,7 +12,7 @@ #endif #include "str.h" -#include "common.h" +#include "git2_util.h" #include "strnlen.h" #include "thread.h" diff --git a/src/varint.c b/src/util/varint.c similarity index 100% rename from src/varint.c rename to src/util/varint.c diff --git a/src/varint.h b/src/util/varint.h similarity index 94% rename from src/varint.h rename to src/util/varint.h index 652e2248657..79b8f5548a9 100644 --- a/src/varint.h +++ b/src/util/varint.h @@ -7,7 +7,7 @@ #ifndef INCLUDE_varint_h__ #define INCLUDE_varint_h__ -#include "common.h" +#include "git2_util.h" #include diff --git a/src/vector.c b/src/util/vector.c similarity index 100% rename from src/vector.c rename to src/util/vector.c diff --git a/src/vector.h b/src/util/vector.h similarity index 99% rename from src/vector.h rename to src/util/vector.h index ae3c79a4cdb..e50cdfefcbd 100644 --- a/src/vector.h +++ b/src/util/vector.h @@ -7,7 +7,7 @@ #ifndef INCLUDE_vector_h__ #define INCLUDE_vector_h__ -#include "common.h" +#include "git2_util.h" typedef int (*git_vector_cmp)(const void *, const void *); diff --git a/src/wildmatch.c b/src/util/wildmatch.c similarity index 100% rename from src/wildmatch.c rename to src/util/wildmatch.c diff --git a/src/wildmatch.h b/src/util/wildmatch.h similarity index 95% rename from src/wildmatch.h rename to src/util/wildmatch.h index 44bb575a611..f2064050025 100644 --- a/src/wildmatch.h +++ b/src/util/wildmatch.h @@ -8,7 +8,7 @@ #ifndef INCLUDE_wildmatch_h__ #define INCLUDE_wildmatch_h__ -#include "common.h" +#include "git2_util.h" #define WM_CASEFOLD 1 #define WM_PATHNAME 2 diff --git a/src/win32/dir.c b/src/util/win32/dir.c similarity index 100% rename from src/win32/dir.c rename to src/util/win32/dir.c diff --git a/src/win32/dir.h b/src/util/win32/dir.h similarity index 97% rename from src/win32/dir.h rename to src/util/win32/dir.h index acd64729eb9..810111534df 100644 --- a/src/win32/dir.h +++ b/src/util/win32/dir.h @@ -7,7 +7,7 @@ #ifndef INCLUDE_win32_dir_h__ #define INCLUDE_win32_dir_h__ -#include "common.h" +#include "git2_util.h" #include "w32_util.h" diff --git a/src/win32/error.c b/src/util/win32/error.c similarity index 100% rename from src/win32/error.c rename to src/util/win32/error.c diff --git a/src/win32/error.h b/src/util/win32/error.h similarity index 93% rename from src/win32/error.h rename to src/util/win32/error.h index 9e81141ce1d..fd53b7f99a8 100644 --- a/src/win32/error.h +++ b/src/util/win32/error.h @@ -8,7 +8,7 @@ #ifndef INCLUDE_win32_error_h__ #define INCLUDE_win32_error_h__ -#include "common.h" +#include "git2_util.h" extern char *git_win32_get_error_message(DWORD error_code); diff --git a/src/win32/findfile.c b/src/util/win32/findfile.c similarity index 100% rename from src/win32/findfile.c rename to src/util/win32/findfile.c diff --git a/src/win32/findfile.h b/src/util/win32/findfile.h similarity index 96% rename from src/win32/findfile.h rename to src/util/win32/findfile.h index 61fb7dbad79..7b191d1feff 100644 --- a/src/win32/findfile.h +++ b/src/util/win32/findfile.h @@ -8,7 +8,7 @@ #ifndef INCLUDE_win32_findfile_h__ #define INCLUDE_win32_findfile_h__ -#include "common.h" +#include "git2_util.h" /** Sets the mock registry root for Git for Windows for testing. */ extern int git_win32__set_registry_system_dir(const wchar_t *mock_sysdir); diff --git a/src/win32/map.c b/src/util/win32/map.c similarity index 99% rename from src/win32/map.c rename to src/util/win32/map.c index 2aabc9b153d..52e1363eac9 100644 --- a/src/win32/map.c +++ b/src/util/win32/map.c @@ -5,7 +5,7 @@ * a Linking Exception. For full terms see the included COPYING file. */ -#include "common.h" +#include "git2_util.h" #include "map.h" #include diff --git a/src/win32/mingw-compat.h b/src/util/win32/mingw-compat.h similarity index 100% rename from src/win32/mingw-compat.h rename to src/util/win32/mingw-compat.h diff --git a/src/win32/msvc-compat.h b/src/util/win32/msvc-compat.h similarity index 100% rename from src/win32/msvc-compat.h rename to src/util/win32/msvc-compat.h diff --git a/src/win32/path_w32.c b/src/util/win32/path_w32.c similarity index 100% rename from src/win32/path_w32.c rename to src/util/win32/path_w32.c diff --git a/src/win32/path_w32.h b/src/util/win32/path_w32.h similarity index 99% rename from src/win32/path_w32.h rename to src/util/win32/path_w32.h index 837b11ebd72..b241d5c8a6f 100644 --- a/src/win32/path_w32.h +++ b/src/util/win32/path_w32.h @@ -7,7 +7,7 @@ #ifndef INCLUDE_win32_path_w32_h__ #define INCLUDE_win32_path_w32_h__ -#include "common.h" +#include "git2_util.h" /** * Create a Win32 path (in UCS-2 format) from a UTF-8 string. If the given diff --git a/src/win32/posix.h b/src/util/win32/posix.h similarity index 99% rename from src/win32/posix.h rename to src/util/win32/posix.h index 578347f1527..03fa2ac52b6 100644 --- a/src/win32/posix.h +++ b/src/util/win32/posix.h @@ -7,7 +7,7 @@ #ifndef INCLUDE_win32_posix_h__ #define INCLUDE_win32_posix_h__ -#include "common.h" +#include "git2_util.h" #include "../posix.h" #include "win32-compat.h" #include "path_w32.h" diff --git a/src/win32/posix_w32.c b/src/util/win32/posix_w32.c similarity index 99% rename from src/win32/posix_w32.c rename to src/util/win32/posix_w32.c index 5f7cd0c2645..5862e5c9ad6 100644 --- a/src/win32/posix_w32.c +++ b/src/util/win32/posix_w32.c @@ -5,7 +5,7 @@ * a Linking Exception. For full terms see the included COPYING file. */ -#include "common.h" +#include "git2_util.h" #include "../posix.h" #include "../futils.h" diff --git a/tests/precompiled.c b/src/util/win32/precompiled.c similarity index 100% rename from tests/precompiled.c rename to src/util/win32/precompiled.c diff --git a/src/win32/precompiled.h b/src/util/win32/precompiled.h similarity index 93% rename from src/win32/precompiled.h rename to src/util/win32/precompiled.h index 806b1698a09..1163c3d63eb 100644 --- a/src/win32/precompiled.h +++ b/src/util/win32/precompiled.h @@ -1,4 +1,4 @@ -#include "common.h" +#include "git2_util.h" #include #include diff --git a/src/win32/reparse.h b/src/util/win32/reparse.h similarity index 100% rename from src/win32/reparse.h rename to src/util/win32/reparse.h diff --git a/src/win32/thread.c b/src/util/win32/thread.c similarity index 100% rename from src/win32/thread.c rename to src/util/win32/thread.c diff --git a/src/win32/thread.h b/src/util/win32/thread.h similarity index 98% rename from src/win32/thread.h rename to src/util/win32/thread.h index 8305036b4d6..184762e2aa9 100644 --- a/src/win32/thread.h +++ b/src/util/win32/thread.h @@ -8,7 +8,7 @@ #ifndef INCLUDE_win32_thread_h__ #define INCLUDE_win32_thread_h__ -#include "common.h" +#include "git2_util.h" #if defined (_MSC_VER) # define GIT_RESTRICT __restrict diff --git a/src/win32/utf-conv.c b/src/util/win32/utf-conv.c similarity index 100% rename from src/win32/utf-conv.c rename to src/util/win32/utf-conv.c diff --git a/src/win32/utf-conv.h b/src/util/win32/utf-conv.h similarity index 98% rename from src/win32/utf-conv.h rename to src/util/win32/utf-conv.h index 6090a4b356a..120d647efdf 100644 --- a/src/win32/utf-conv.h +++ b/src/util/win32/utf-conv.h @@ -7,7 +7,7 @@ #ifndef INCLUDE_win32_utf_conv_h__ #define INCLUDE_win32_utf_conv_h__ -#include "common.h" +#include "git2_util.h" #include diff --git a/src/win32/version.h b/src/util/win32/version.h similarity index 100% rename from src/win32/version.h rename to src/util/win32/version.h diff --git a/src/win32/w32_buffer.c b/src/util/win32/w32_buffer.c similarity index 100% rename from src/win32/w32_buffer.c rename to src/util/win32/w32_buffer.c diff --git a/src/win32/w32_buffer.h b/src/util/win32/w32_buffer.h similarity index 95% rename from src/win32/w32_buffer.h rename to src/util/win32/w32_buffer.h index 4227296d8f5..68ea9603567 100644 --- a/src/win32/w32_buffer.h +++ b/src/util/win32/w32_buffer.h @@ -7,7 +7,7 @@ #ifndef INCLUDE_win32_w32_buffer_h__ #define INCLUDE_win32_w32_buffer_h__ -#include "common.h" +#include "git2_util.h" #include "str.h" /** diff --git a/src/win32/w32_common.h b/src/util/win32/w32_common.h similarity index 100% rename from src/win32/w32_common.h rename to src/util/win32/w32_common.h diff --git a/src/win32/w32_leakcheck.c b/src/util/win32/w32_leakcheck.c similarity index 100% rename from src/win32/w32_leakcheck.c rename to src/util/win32/w32_leakcheck.c diff --git a/src/win32/w32_leakcheck.h b/src/util/win32/w32_leakcheck.h similarity index 99% rename from src/win32/w32_leakcheck.h rename to src/util/win32/w32_leakcheck.h index cb45e3675be..82d863851ee 100644 --- a/src/win32/w32_leakcheck.h +++ b/src/util/win32/w32_leakcheck.h @@ -8,7 +8,7 @@ #ifndef INCLUDE_win32_leakcheck_h__ #define INCLUDE_win32_leakcheck_h__ -#include "common.h" +#include "git2_util.h" /* Initialize the win32 leak checking system. */ int git_win32_leakcheck_global_init(void); diff --git a/src/win32/w32_util.c b/src/util/win32/w32_util.c similarity index 100% rename from src/win32/w32_util.c rename to src/util/win32/w32_util.c diff --git a/src/win32/w32_util.h b/src/util/win32/w32_util.h similarity index 99% rename from src/win32/w32_util.h rename to src/util/win32/w32_util.h index 1321d30e66b..519663720d5 100644 --- a/src/win32/w32_util.h +++ b/src/util/win32/w32_util.h @@ -8,7 +8,7 @@ #ifndef INCLUDE_win32_w32_util_h__ #define INCLUDE_win32_w32_util_h__ -#include "common.h" +#include "git2_util.h" #include "utf-conv.h" #include "posix.h" diff --git a/src/win32/win32-compat.h b/src/util/win32/win32-compat.h similarity index 100% rename from src/win32/win32-compat.h rename to src/util/win32/win32-compat.h diff --git a/src/zstream.c b/src/util/zstream.c similarity index 100% rename from src/zstream.c rename to src/util/zstream.c diff --git a/src/zstream.h b/src/util/zstream.h similarity index 98% rename from src/zstream.h rename to src/util/zstream.h index 3f8b1c72ff4..d78b1129145 100644 --- a/src/zstream.h +++ b/src/util/zstream.h @@ -7,7 +7,7 @@ #ifndef INCLUDE_zstream_h__ #define INCLUDE_zstream_h__ -#include "common.h" +#include "git2_util.h" #include diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt index f293c158da1..df100e980a9 100644 --- a/tests/CMakeLists.txt +++ b/tests/CMakeLists.txt @@ -1,96 +1,6 @@ -set(Python_ADDITIONAL_VERSIONS 3 2.7) -find_package(PythonInterp) +# The main libgit2 tests tree: this CMakeLists.txt includes the +# subprojects that make up core libgit2 support. -if(NOT PYTHONINTERP_FOUND) - message(FATAL_ERROR "Could not find a python interpreter, which is needed to build the tests. " - "Make sure python is available, or pass -DBUILD_TESTS=OFF to skip building the tests") -ENDIF() - -set(CLAR_FIXTURES "${CMAKE_CURRENT_SOURCE_DIR}/resources/") -set(CLAR_PATH "${CMAKE_CURRENT_SOURCE_DIR}") -add_definitions(-DCLAR_FIXTURE_PATH=\"${CLAR_FIXTURES}\") -add_definitions(-DCLAR_TMPDIR=\"libgit2_tests\") -add_definitions(-DCLAR_WIN32_LONGPATHS) -add_definitions(-D_FILE_OFFSET_BITS=64) - -# Ensure that we do not use deprecated functions internally -add_definitions(-DGIT_DEPRECATE_HARD) - -set(TEST_INCLUDES "${CLAR_PATH}" "${CMAKE_CURRENT_BINARY_DIR}") -file(GLOB_RECURSE SRC_TEST ${CLAR_PATH}/*/*.c ${CLAR_PATH}/*/*.h) -set(SRC_CLAR "main.c" "clar_libgit2.c" "clar_libgit2_trace.c" "clar_libgit2_timer.c" "clar.c") - -if(MSVC_IDE) - list(APPEND SRC_CLAR "precompiled.c") -endif() - -add_custom_command( - OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/clar.suite ${CMAKE_CURRENT_BINARY_DIR}/clar_suite.h - COMMAND ${PYTHON_EXECUTABLE} generate.py -o "${CMAKE_CURRENT_BINARY_DIR}" -f -xonline -xstress -xperf . - DEPENDS ${SRC_TEST} - WORKING_DIRECTORY ${CLAR_PATH} -) - -set_source_files_properties( - ${CLAR_PATH}/clar.c - PROPERTIES OBJECT_DEPENDS ${CMAKE_CURRENT_BINARY_DIR}/clar.suite) - -add_executable(libgit2_tests ${SRC_CLAR} ${SRC_TEST} ${LIBGIT2_OBJECTS}) - -set_target_properties(libgit2_tests PROPERTIES C_STANDARD 90) -set_target_properties(libgit2_tests PROPERTIES RUNTIME_OUTPUT_DIRECTORY ${PROJECT_BINARY_DIR}) - -target_include_directories(libgit2_tests PRIVATE ${TEST_INCLUDES} ${LIBGIT2_INCLUDES} ${LIBGIT2_DEPENDENCY_INCLUDES}) -target_include_directories(libgit2_tests SYSTEM PRIVATE ${LIBGIT2_SYSTEM_INCLUDES}) -target_link_libraries(libgit2_tests ${LIBGIT2_SYSTEM_LIBS}) - -ide_split_sources(libgit2_tests) - -# -# Old versions of gcc require us to declare our test functions; don't do -# this on newer compilers to avoid unnecessary recompilation. -# -if(CMAKE_COMPILER_IS_GNUCC AND CMAKE_CXX_COMPILER_VERSION VERSION_LESS 6.0) - target_compile_options(libgit2_tests PRIVATE -include "clar_suite.h") -endif() - -if(MSVC_IDE) - # Precompiled headers - set_target_properties(libgit2_tests PROPERTIES COMPILE_FLAGS "/Yuprecompiled.h /FIprecompiled.h") - set_source_files_properties("precompiled.c" COMPILE_FLAGS "/Ycprecompiled.h") -endif() - -function(ADD_CLAR_TEST name) - if(NOT USE_LEAK_CHECKER STREQUAL "OFF") - add_test(${name} "${PROJECT_SOURCE_DIR}/script/${USE_LEAK_CHECKER}.sh" "${PROJECT_BINARY_DIR}/libgit2_tests" ${ARGN}) - else() - add_test(${name} "${PROJECT_BINARY_DIR}/libgit2_tests" ${ARGN}) - endif() -endfunction(ADD_CLAR_TEST) - -add_clar_test(offline -v -xonline) -add_clar_test(invasive -v -score::ftruncate -sfilter::stream::bigfile -sodb::largefiles -siterator::workdir::filesystem_gunk -srepo::init -srepo::init::at_filesystem_root) -add_clar_test(online -v -sonline -xonline::customcert) -add_clar_test(online_customcert -v -sonline::customcert) -add_clar_test(gitdaemon -v -sonline::push) -add_clar_test(ssh -v -sonline::push -sonline::clone::ssh_cert -sonline::clone::ssh_with_paths -sonline::clone::path_whitespace_ssh) -add_clar_test(proxy -v -sonline::clone::proxy) -add_clar_test(auth_clone -v -sonline::clone::cred) -add_clar_test(auth_clone_and_push -v -sonline::clone::push -sonline::push) - -# -# Header file validation project: ensure that we do not publish any sloppy -# definitions in our headers and that a consumer can include -# even when they have aggressive C90 warnings enabled. -# - -add_executable(headertest headertest.c) -set_target_properties(headertest PROPERTIES C_STANDARD 90) -set_target_properties(headertest PROPERTIES C_EXTENSIONS OFF) -target_include_directories(headertest PRIVATE ${LIBGIT2_INCLUDES}) - -if (MSVC) - target_compile_options(headertest PUBLIC /W4 /WX) -else() - target_compile_options(headertest PUBLIC -Wall -Wextra -pedantic -Werror) -endif() +add_subdirectory(headertest) +add_subdirectory(libgit2) +add_subdirectory(util) diff --git a/tests/README.md b/tests/README.md index 4369a8f3381..5920b154706 100644 --- a/tests/README.md +++ b/tests/README.md @@ -1,33 +1,56 @@ -Writing Clar tests for libgit2 -============================== - -For information on the Clar testing framework and a detailed introduction -please visit: - -https://github.com/vmg/clar - - -* Write your modules and tests. Use good, meaningful names. - -* Make sure you actually build the tests by setting: - - cmake -DBUILD_TESTS=ON build/ - -* Test: - - ./build/libgit2_tests - -* Make sure everything is fine. - -* Send your pull request. That's it. - - -Memory leak checks ------------------- +# libgit2 tests + +These are the unit and integration tests for the libgit2 projects. + +* `clar` + This is [clar](https://github.com/clar-test/clar) the common test framework. +* `headertest` + This is a simple project that ensures that our public headers are + compatible with extremely strict compilation options. +* `libgit2` + These tests exercise the core git functionality in libgit2 itself. +* `resources` + These are the resources for the tests, including files and git + repositories. +* `util` + These are tests of the common utility library. + +## Writing tests for libgit2 + +libgit2 uses the [clar test framework](http://github.com/clar-test/clar), a +C testing framework. + +The best resources for learning clar are [clar itself](https://github.com/clar-test/clar) +and the existing tests within libgit2. In general: + +* If you place a `.c` file into a test directory, it is eligible to contain +test cases. +* The function name for your test is important; test function names begin + with `test_`, followed by the folder path (underscore separated), two + underscores as a delimiter, then the test name. For example, a file + `merge/analysis.c` may contain a test `uptodate`: + + ``` + void test_merge_analysis__uptodate(void) + { + ... + } + ``` + +* You can run an individual test by passing `-s` to the test runner. Tests + are referred to by their function names; for example, the function + `test_merge_analysis__uptodate` is referred to as `merge::analysis::uptodate`. + To run only that function you can use the `-s` option on the test runner: + + ``` + libgit2_tests -smerge::analysis::uptodate + ``` + +## Memory leak checking These are automatically run as part of CI, but if you want to check locally: -#### Linux +### Linux Uses [`valgrind`](http://www.valgrind.org/): @@ -38,7 +61,7 @@ $ valgrind --leak-check=full --show-reachable=yes --num-callers=50 --suppression ./libgit2_tests ``` -#### macOS +### macOS Uses [`leaks`](https://developer.apple.com/library/archive/documentation/Performance/Conceptual/ManagingMemory/Articles/FindingLeaks.html), which requires XCode installed: @@ -46,3 +69,13 @@ Uses [`leaks`](https://developer.apple.com/library/archive/documentation/Perform $ MallocStackLogging=1 MallocScribble=1 MallocLogFile=/dev/null CLAR_AT_EXIT="leaks -quiet \$PPID" \ ./libgit2_tests ``` + +### Windows + +Build with the `WIN32_LEAKCHECK` option: + +```console +$ cmake -DBUILD_TESTS=ON -DWIN32_LEAKCHECK=ON .. +$ cmake --build . +$ ./libgit2_tests +``` diff --git a/tests/clar.c b/tests/clar/clar.c similarity index 100% rename from tests/clar.c rename to tests/clar/clar.c diff --git a/tests/clar.h b/tests/clar/clar.h similarity index 100% rename from tests/clar.h rename to tests/clar/clar.h diff --git a/tests/clar/fixtures.h b/tests/clar/clar/fixtures.h similarity index 100% rename from tests/clar/fixtures.h rename to tests/clar/clar/fixtures.h diff --git a/tests/clar/fs.h b/tests/clar/clar/fs.h similarity index 100% rename from tests/clar/fs.h rename to tests/clar/clar/fs.h diff --git a/tests/clar/print.h b/tests/clar/clar/print.h similarity index 100% rename from tests/clar/print.h rename to tests/clar/clar/print.h diff --git a/tests/clar/sandbox.h b/tests/clar/clar/sandbox.h similarity index 100% rename from tests/clar/sandbox.h rename to tests/clar/clar/sandbox.h diff --git a/tests/clar/summary.h b/tests/clar/clar/summary.h similarity index 100% rename from tests/clar/summary.h rename to tests/clar/clar/summary.h diff --git a/tests/clar_libgit2.c b/tests/clar/clar_libgit2.c similarity index 100% rename from tests/clar_libgit2.c rename to tests/clar/clar_libgit2.c diff --git a/tests/clar_libgit2.h b/tests/clar/clar_libgit2.h similarity index 100% rename from tests/clar_libgit2.h rename to tests/clar/clar_libgit2.h diff --git a/tests/clar_libgit2_timer.c b/tests/clar/clar_libgit2_timer.c similarity index 100% rename from tests/clar_libgit2_timer.c rename to tests/clar/clar_libgit2_timer.c diff --git a/tests/clar_libgit2_timer.h b/tests/clar/clar_libgit2_timer.h similarity index 100% rename from tests/clar_libgit2_timer.h rename to tests/clar/clar_libgit2_timer.h diff --git a/tests/clar_libgit2_trace.c b/tests/clar/clar_libgit2_trace.c similarity index 100% rename from tests/clar_libgit2_trace.c rename to tests/clar/clar_libgit2_trace.c diff --git a/tests/clar_libgit2_trace.h b/tests/clar/clar_libgit2_trace.h similarity index 100% rename from tests/clar_libgit2_trace.h rename to tests/clar/clar_libgit2_trace.h diff --git a/tests/generate.py b/tests/clar/generate.py similarity index 100% rename from tests/generate.py rename to tests/clar/generate.py diff --git a/tests/main.c b/tests/clar/main.c similarity index 100% rename from tests/main.c rename to tests/clar/main.c diff --git a/tests/headertest/CMakeLists.txt b/tests/headertest/CMakeLists.txt new file mode 100644 index 00000000000..c70ce1ae19c --- /dev/null +++ b/tests/headertest/CMakeLists.txt @@ -0,0 +1,14 @@ +# Header file validation project: ensure that we do not publish any sloppy +# definitions in our headers and that a consumer can include +# even when they have aggressive C90 warnings enabled. + +add_executable(headertest headertest.c) +set_target_properties(headertest PROPERTIES C_STANDARD 90) +set_target_properties(headertest PROPERTIES C_EXTENSIONS OFF) +target_include_directories(headertest PRIVATE ${LIBGIT2_INCLUDES}) + +if (MSVC) + target_compile_options(headertest PUBLIC /W4 /WX) +else() + target_compile_options(headertest PUBLIC -Wall -Wextra -pedantic -Werror) +endif() diff --git a/tests/headertest.c b/tests/headertest/headertest.c similarity index 100% rename from tests/headertest.c rename to tests/headertest/headertest.c diff --git a/tests/libgit2/CMakeLists.txt b/tests/libgit2/CMakeLists.txt new file mode 100644 index 00000000000..27f421ad629 --- /dev/null +++ b/tests/libgit2/CMakeLists.txt @@ -0,0 +1,75 @@ +# tests: the unit and integration tests for libgit2 + +set(Python_ADDITIONAL_VERSIONS 3 2.7) +find_package(PythonInterp) + +if(NOT PYTHONINTERP_FOUND) + message(FATAL_ERROR "Could not find a python interpreter, which is needed to build the tests. " + "Make sure python is available, or pass -DBUILD_TESTS=OFF to skip building the tests") +ENDIF() + +set(CLAR_PATH "${PROJECT_SOURCE_DIR}/tests/clar") +set(CLAR_FIXTURES "${PROJECT_SOURCE_DIR}/tests/resources/") +set(TEST_PATH "${CMAKE_CURRENT_SOURCE_DIR}") +add_definitions(-DCLAR_FIXTURE_PATH=\"${CLAR_FIXTURES}\") +add_definitions(-DCLAR_TMPDIR=\"libgit2_tests\") +add_definitions(-DCLAR_WIN32_LONGPATHS) +add_definitions(-D_FILE_OFFSET_BITS=64) + +# Ensure that we do not use deprecated functions internally +add_definitions(-DGIT_DEPRECATE_HARD) + +set(TEST_INCLUDES "${CLAR_PATH}" "${TEST_PATH}" "${CMAKE_CURRENT_BINARY_DIR}") +file(GLOB_RECURSE SRC_TEST ${TEST_PATH}/*/*.c ${TEST_PATH}/*/*.h) +file(GLOB_RECURSE SRC_CLAR ${CLAR_PATH}/*.c ${CLAR_PATH}/*.h) + +if(MSVC_IDE) + list(APPEND SRC_TEST "precompiled.c") +endif() + +add_custom_command( + OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/clar.suite ${CMAKE_CURRENT_BINARY_DIR}/clar_suite.h + COMMAND ${PYTHON_EXECUTABLE} ${CLAR_PATH}/generate.py -o "${CMAKE_CURRENT_BINARY_DIR}" -f -xonline -xstress -xperf . + DEPENDS ${SRC_TEST} + WORKING_DIRECTORY ${TEST_PATH} +) + +set_source_files_properties( + ${CLAR_PATH}/clar.c + PROPERTIES OBJECT_DEPENDS ${CMAKE_CURRENT_BINARY_DIR}/clar.suite) + +add_executable(libgit2_tests ${SRC_CLAR} ${SRC_TEST} ${LIBGIT2_OBJECTS}) + +set_target_properties(libgit2_tests PROPERTIES C_STANDARD 90) +set_target_properties(libgit2_tests PROPERTIES RUNTIME_OUTPUT_DIRECTORY ${PROJECT_BINARY_DIR}) + +target_include_directories(libgit2_tests PRIVATE ${TEST_INCLUDES} ${LIBGIT2_INCLUDES} ${LIBGIT2_DEPENDENCY_INCLUDES}) +target_include_directories(libgit2_tests SYSTEM PRIVATE ${LIBGIT2_SYSTEM_INCLUDES}) +target_link_libraries(libgit2_tests ${LIBGIT2_SYSTEM_LIBS}) + +ide_split_sources(libgit2_tests) + +# +# Old versions of gcc require us to declare our test functions; don't do +# this on newer compilers to avoid unnecessary recompilation. +# +if(CMAKE_COMPILER_IS_GNUCC AND CMAKE_CXX_COMPILER_VERSION VERSION_LESS 6.0) + target_compile_options(libgit2_tests PRIVATE -include "clar_suite.h") +endif() + +if(MSVC_IDE) + # Precompiled headers + set_target_properties(libgit2_tests PROPERTIES COMPILE_FLAGS "/Yuprecompiled.h /FIprecompiled.h") + set_source_files_properties("precompiled.c" COMPILE_FLAGS "/Ycprecompiled.h") +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) +add_clar_test(libgit2_tests online_customcert -v -sonline::customcert) +add_clar_test(libgit2_tests gitdaemon -v -sonline::push) +add_clar_test(libgit2_tests ssh -v -sonline::push -sonline::clone::ssh_cert -sonline::clone::ssh_with_paths -sonline::clone::path_whitespace_ssh) +add_clar_test(libgit2_tests proxy -v -sonline::clone::proxy) +add_clar_test(libgit2_tests auth_clone -v -sonline::clone::cred) +add_clar_test(libgit2_tests auth_clone_and_push -v -sonline::clone::push -sonline::push) diff --git a/tests/apply/apply_helpers.c b/tests/libgit2/apply/apply_helpers.c similarity index 100% rename from tests/apply/apply_helpers.c rename to tests/libgit2/apply/apply_helpers.c diff --git a/tests/apply/apply_helpers.h b/tests/libgit2/apply/apply_helpers.h similarity index 100% rename from tests/apply/apply_helpers.h rename to tests/libgit2/apply/apply_helpers.h diff --git a/tests/apply/both.c b/tests/libgit2/apply/both.c similarity index 100% rename from tests/apply/both.c rename to tests/libgit2/apply/both.c diff --git a/tests/apply/callbacks.c b/tests/libgit2/apply/callbacks.c similarity index 100% rename from tests/apply/callbacks.c rename to tests/libgit2/apply/callbacks.c diff --git a/tests/apply/check.c b/tests/libgit2/apply/check.c similarity index 100% rename from tests/apply/check.c rename to tests/libgit2/apply/check.c diff --git a/tests/apply/fromdiff.c b/tests/libgit2/apply/fromdiff.c similarity index 100% rename from tests/apply/fromdiff.c rename to tests/libgit2/apply/fromdiff.c diff --git a/tests/apply/fromfile.c b/tests/libgit2/apply/fromfile.c similarity index 100% rename from tests/apply/fromfile.c rename to tests/libgit2/apply/fromfile.c diff --git a/tests/apply/index.c b/tests/libgit2/apply/index.c similarity index 100% rename from tests/apply/index.c rename to tests/libgit2/apply/index.c diff --git a/tests/apply/partial.c b/tests/libgit2/apply/partial.c similarity index 100% rename from tests/apply/partial.c rename to tests/libgit2/apply/partial.c diff --git a/tests/apply/tree.c b/tests/libgit2/apply/tree.c similarity index 100% rename from tests/apply/tree.c rename to tests/libgit2/apply/tree.c diff --git a/tests/apply/workdir.c b/tests/libgit2/apply/workdir.c similarity index 100% rename from tests/apply/workdir.c rename to tests/libgit2/apply/workdir.c diff --git a/tests/attr/attr_expect.h b/tests/libgit2/attr/attr_expect.h similarity index 100% rename from tests/attr/attr_expect.h rename to tests/libgit2/attr/attr_expect.h diff --git a/tests/attr/file.c b/tests/libgit2/attr/file.c similarity index 100% rename from tests/attr/file.c rename to tests/libgit2/attr/file.c diff --git a/tests/attr/flags.c b/tests/libgit2/attr/flags.c similarity index 100% rename from tests/attr/flags.c rename to tests/libgit2/attr/flags.c diff --git a/tests/attr/lookup.c b/tests/libgit2/attr/lookup.c similarity index 100% rename from tests/attr/lookup.c rename to tests/libgit2/attr/lookup.c diff --git a/tests/attr/macro.c b/tests/libgit2/attr/macro.c similarity index 100% rename from tests/attr/macro.c rename to tests/libgit2/attr/macro.c diff --git a/tests/attr/repo.c b/tests/libgit2/attr/repo.c similarity index 100% rename from tests/attr/repo.c rename to tests/libgit2/attr/repo.c diff --git a/tests/blame/blame_helpers.c b/tests/libgit2/blame/blame_helpers.c similarity index 100% rename from tests/blame/blame_helpers.c rename to tests/libgit2/blame/blame_helpers.c diff --git a/tests/blame/blame_helpers.h b/tests/libgit2/blame/blame_helpers.h similarity index 100% rename from tests/blame/blame_helpers.h rename to tests/libgit2/blame/blame_helpers.h diff --git a/tests/blame/buffer.c b/tests/libgit2/blame/buffer.c similarity index 100% rename from tests/blame/buffer.c rename to tests/libgit2/blame/buffer.c diff --git a/tests/blame/getters.c b/tests/libgit2/blame/getters.c similarity index 100% rename from tests/blame/getters.c rename to tests/libgit2/blame/getters.c diff --git a/tests/blame/harder.c b/tests/libgit2/blame/harder.c similarity index 100% rename from tests/blame/harder.c rename to tests/libgit2/blame/harder.c diff --git a/tests/blame/simple.c b/tests/libgit2/blame/simple.c similarity index 100% rename from tests/blame/simple.c rename to tests/libgit2/blame/simple.c diff --git a/tests/checkout/binaryunicode.c b/tests/libgit2/checkout/binaryunicode.c similarity index 100% rename from tests/checkout/binaryunicode.c rename to tests/libgit2/checkout/binaryunicode.c diff --git a/tests/checkout/checkout_helpers.c b/tests/libgit2/checkout/checkout_helpers.c similarity index 100% rename from tests/checkout/checkout_helpers.c rename to tests/libgit2/checkout/checkout_helpers.c diff --git a/tests/checkout/checkout_helpers.h b/tests/libgit2/checkout/checkout_helpers.h similarity index 100% rename from tests/checkout/checkout_helpers.h rename to tests/libgit2/checkout/checkout_helpers.h diff --git a/tests/checkout/conflict.c b/tests/libgit2/checkout/conflict.c similarity index 100% rename from tests/checkout/conflict.c rename to tests/libgit2/checkout/conflict.c diff --git a/tests/checkout/crlf.c b/tests/libgit2/checkout/crlf.c similarity index 100% rename from tests/checkout/crlf.c rename to tests/libgit2/checkout/crlf.c diff --git a/tests/checkout/head.c b/tests/libgit2/checkout/head.c similarity index 100% rename from tests/checkout/head.c rename to tests/libgit2/checkout/head.c diff --git a/tests/checkout/icase.c b/tests/libgit2/checkout/icase.c similarity index 100% rename from tests/checkout/icase.c rename to tests/libgit2/checkout/icase.c diff --git a/tests/checkout/index.c b/tests/libgit2/checkout/index.c similarity index 100% rename from tests/checkout/index.c rename to tests/libgit2/checkout/index.c diff --git a/tests/checkout/nasty.c b/tests/libgit2/checkout/nasty.c similarity index 100% rename from tests/checkout/nasty.c rename to tests/libgit2/checkout/nasty.c diff --git a/tests/checkout/tree.c b/tests/libgit2/checkout/tree.c similarity index 100% rename from tests/checkout/tree.c rename to tests/libgit2/checkout/tree.c diff --git a/tests/checkout/typechange.c b/tests/libgit2/checkout/typechange.c similarity index 100% rename from tests/checkout/typechange.c rename to tests/libgit2/checkout/typechange.c diff --git a/tests/cherrypick/bare.c b/tests/libgit2/cherrypick/bare.c similarity index 100% rename from tests/cherrypick/bare.c rename to tests/libgit2/cherrypick/bare.c diff --git a/tests/cherrypick/workdir.c b/tests/libgit2/cherrypick/workdir.c similarity index 100% rename from tests/cherrypick/workdir.c rename to tests/libgit2/cherrypick/workdir.c diff --git a/tests/clone/empty.c b/tests/libgit2/clone/empty.c similarity index 100% rename from tests/clone/empty.c rename to tests/libgit2/clone/empty.c diff --git a/tests/clone/local.c b/tests/libgit2/clone/local.c similarity index 100% rename from tests/clone/local.c rename to tests/libgit2/clone/local.c diff --git a/tests/clone/nonetwork.c b/tests/libgit2/clone/nonetwork.c similarity index 100% rename from tests/clone/nonetwork.c rename to tests/libgit2/clone/nonetwork.c diff --git a/tests/clone/transport.c b/tests/libgit2/clone/transport.c similarity index 100% rename from tests/clone/transport.c rename to tests/libgit2/clone/transport.c diff --git a/tests/commit/commit.c b/tests/libgit2/commit/commit.c similarity index 100% rename from tests/commit/commit.c rename to tests/libgit2/commit/commit.c diff --git a/tests/commit/parent.c b/tests/libgit2/commit/parent.c similarity index 100% rename from tests/commit/parent.c rename to tests/libgit2/commit/parent.c diff --git a/tests/commit/parse.c b/tests/libgit2/commit/parse.c similarity index 100% rename from tests/commit/parse.c rename to tests/libgit2/commit/parse.c diff --git a/tests/commit/signature.c b/tests/libgit2/commit/signature.c similarity index 100% rename from tests/commit/signature.c rename to tests/libgit2/commit/signature.c diff --git a/tests/commit/write.c b/tests/libgit2/commit/write.c similarity index 100% rename from tests/commit/write.c rename to tests/libgit2/commit/write.c diff --git a/tests/config/add.c b/tests/libgit2/config/add.c similarity index 100% rename from tests/config/add.c rename to tests/libgit2/config/add.c diff --git a/tests/config/backend.c b/tests/libgit2/config/backend.c similarity index 100% rename from tests/config/backend.c rename to tests/libgit2/config/backend.c diff --git a/tests/config/conditionals.c b/tests/libgit2/config/conditionals.c similarity index 100% rename from tests/config/conditionals.c rename to tests/libgit2/config/conditionals.c diff --git a/tests/config/config_helpers.c b/tests/libgit2/config/config_helpers.c similarity index 100% rename from tests/config/config_helpers.c rename to tests/libgit2/config/config_helpers.c diff --git a/tests/config/config_helpers.h b/tests/libgit2/config/config_helpers.h similarity index 100% rename from tests/config/config_helpers.h rename to tests/libgit2/config/config_helpers.h diff --git a/tests/config/configlevel.c b/tests/libgit2/config/configlevel.c similarity index 100% rename from tests/config/configlevel.c rename to tests/libgit2/config/configlevel.c diff --git a/tests/config/global.c b/tests/libgit2/config/global.c similarity index 100% rename from tests/config/global.c rename to tests/libgit2/config/global.c diff --git a/tests/config/include.c b/tests/libgit2/config/include.c similarity index 100% rename from tests/config/include.c rename to tests/libgit2/config/include.c diff --git a/tests/config/memory.c b/tests/libgit2/config/memory.c similarity index 100% rename from tests/config/memory.c rename to tests/libgit2/config/memory.c diff --git a/tests/config/multivar.c b/tests/libgit2/config/multivar.c similarity index 100% rename from tests/config/multivar.c rename to tests/libgit2/config/multivar.c diff --git a/tests/config/new.c b/tests/libgit2/config/new.c similarity index 100% rename from tests/config/new.c rename to tests/libgit2/config/new.c diff --git a/tests/config/read.c b/tests/libgit2/config/read.c similarity index 100% rename from tests/config/read.c rename to tests/libgit2/config/read.c diff --git a/tests/config/readonly.c b/tests/libgit2/config/readonly.c similarity index 100% rename from tests/config/readonly.c rename to tests/libgit2/config/readonly.c diff --git a/tests/config/rename.c b/tests/libgit2/config/rename.c similarity index 100% rename from tests/config/rename.c rename to tests/libgit2/config/rename.c diff --git a/tests/config/snapshot.c b/tests/libgit2/config/snapshot.c similarity index 100% rename from tests/config/snapshot.c rename to tests/libgit2/config/snapshot.c diff --git a/tests/config/stress.c b/tests/libgit2/config/stress.c similarity index 100% rename from tests/config/stress.c rename to tests/libgit2/config/stress.c diff --git a/tests/config/validkeyname.c b/tests/libgit2/config/validkeyname.c similarity index 100% rename from tests/config/validkeyname.c rename to tests/libgit2/config/validkeyname.c diff --git a/tests/config/write.c b/tests/libgit2/config/write.c similarity index 100% rename from tests/config/write.c rename to tests/libgit2/config/write.c diff --git a/tests/core/buf.c b/tests/libgit2/core/buf.c similarity index 100% rename from tests/core/buf.c rename to tests/libgit2/core/buf.c diff --git a/tests/core/env.c b/tests/libgit2/core/env.c similarity index 100% rename from tests/core/env.c rename to tests/libgit2/core/env.c diff --git a/tests/core/features.c b/tests/libgit2/core/features.c similarity index 100% rename from tests/core/features.c rename to tests/libgit2/core/features.c diff --git a/tests/libgit2/core/hashsig.c b/tests/libgit2/core/hashsig.c new file mode 100644 index 00000000000..6cadb1c1a4b --- /dev/null +++ b/tests/libgit2/core/hashsig.c @@ -0,0 +1,182 @@ +#include "clar_libgit2.h" +#include "git2/sys/hashsig.h" +#include "futils.h" + +#define SIMILARITY_TEST_DATA_1 \ + "000\n001\n002\n003\n004\n005\n006\n007\n008\n009\n" \ + "010\n011\n012\n013\n014\n015\n016\n017\n018\n019\n" \ + "020\n021\n022\n023\n024\n025\n026\n027\n028\n029\n" \ + "030\n031\n032\n033\n034\n035\n036\n037\n038\n039\n" \ + "040\n041\n042\n043\n044\n045\n046\n047\n048\n049\n" + +void test_core_hashsig__similarity_metric(void) +{ + git_hashsig *a, *b; + git_str buf = GIT_STR_INIT; + int sim; + + /* in the first case, we compare data to itself and expect 100% match */ + + cl_git_pass(git_str_sets(&buf, SIMILARITY_TEST_DATA_1)); + cl_git_pass(git_hashsig_create(&a, buf.ptr, buf.size, GIT_HASHSIG_NORMAL)); + cl_git_pass(git_hashsig_create(&b, buf.ptr, buf.size, GIT_HASHSIG_NORMAL)); + + cl_assert_equal_i(100, git_hashsig_compare(a, b)); + + git_hashsig_free(a); + git_hashsig_free(b); + + /* if we change just a single byte, how much does that change magnify? */ + + cl_git_pass(git_str_sets(&buf, SIMILARITY_TEST_DATA_1)); + cl_git_pass(git_hashsig_create(&a, buf.ptr, buf.size, GIT_HASHSIG_NORMAL)); + cl_git_pass(git_str_sets(&buf, + "000\n001\n002\n003\n004\n005\n006\n007\n008\n009\n" \ + "010\n011\n012\n013\n014\n015\n016\n017\n018\n019\n" \ + "x020x\n021\n022\n023\n024\n025\n026\n027\n028\n029\n" \ + "030\n031\n032\n033\n034\n035\n036\n037\n038\n039\n" \ + "040\n041\n042\n043\n044\n045\n046\n047\n048\n049\n" + )); + cl_git_pass(git_hashsig_create(&b, buf.ptr, buf.size, GIT_HASHSIG_NORMAL)); + + sim = git_hashsig_compare(a, b); + + cl_assert_in_range(95, sim, 100); /* expect >95% similarity */ + + git_hashsig_free(a); + git_hashsig_free(b); + + /* let's try comparing data to a superset of itself */ + + cl_git_pass(git_str_sets(&buf, SIMILARITY_TEST_DATA_1)); + cl_git_pass(git_hashsig_create(&a, buf.ptr, buf.size, GIT_HASHSIG_NORMAL)); + cl_git_pass(git_str_sets(&buf, SIMILARITY_TEST_DATA_1 + "050\n051\n052\n053\n054\n055\n056\n057\n058\n059\n")); + cl_git_pass(git_hashsig_create(&b, buf.ptr, buf.size, GIT_HASHSIG_NORMAL)); + + sim = git_hashsig_compare(a, b); + /* 20% lines added ~= 10% lines changed */ + + cl_assert_in_range(85, sim, 95); /* expect similarity around 90% */ + + git_hashsig_free(a); + git_hashsig_free(b); + + /* what if we keep about half the original data and add half new */ + + cl_git_pass(git_str_sets(&buf, SIMILARITY_TEST_DATA_1)); + cl_git_pass(git_hashsig_create(&a, buf.ptr, buf.size, GIT_HASHSIG_NORMAL)); + cl_git_pass(git_str_sets(&buf, + "000\n001\n002\n003\n004\n005\n006\n007\n008\n009\n" \ + "010\n011\n012\n013\n014\n015\n016\n017\n018\n019\n" \ + "020x\n021\n022\n023\n024\n" \ + "x25\nx26\nx27\nx28\nx29\n" \ + "x30\nx31\nx32\nx33\nx34\nx35\nx36\nx37\nx38\nx39\n" \ + "x40\nx41\nx42\nx43\nx44\nx45\nx46\nx47\nx48\nx49\n" + )); + cl_git_pass(git_hashsig_create(&b, buf.ptr, buf.size, GIT_HASHSIG_NORMAL)); + + sim = git_hashsig_compare(a, b); + /* 50% lines changed */ + + cl_assert_in_range(40, sim, 60); /* expect in the 40-60% similarity range */ + + git_hashsig_free(a); + git_hashsig_free(b); + + /* lastly, let's check that we can hash file content as well */ + + cl_git_pass(git_str_sets(&buf, SIMILARITY_TEST_DATA_1)); + cl_git_pass(git_hashsig_create(&a, buf.ptr, buf.size, GIT_HASHSIG_NORMAL)); + + cl_git_pass(git_futils_mkdir("scratch", 0755, GIT_MKDIR_PATH)); + cl_git_mkfile("scratch/testdata", SIMILARITY_TEST_DATA_1); + cl_git_pass(git_hashsig_create_fromfile( + &b, "scratch/testdata", GIT_HASHSIG_NORMAL)); + + cl_assert_equal_i(100, git_hashsig_compare(a, b)); + + git_hashsig_free(a); + git_hashsig_free(b); + + git_str_dispose(&buf); + git_futils_rmdir_r("scratch", NULL, GIT_RMDIR_REMOVE_FILES); +} + +void test_core_hashsig__similarity_metric_whitespace(void) +{ + git_hashsig *a, *b; + git_str buf = GIT_STR_INIT; + int sim, i, j; + git_hashsig_option_t opt; + const char *tabbed = + " for (s = 0; s < sizeof(sep) / sizeof(char); ++s) {\n" + " separator = sep[s];\n" + " expect = expect_values[s];\n" + "\n" + " for (j = 0; j < sizeof(b) / sizeof(char*); ++j) {\n" + " for (i = 0; i < sizeof(a) / sizeof(char*); ++i) {\n" + " git_str_join(&buf, separator, a[i], b[j]);\n" + " cl_assert_equal_s(*expect, buf.ptr);\n" + " expect++;\n" + " }\n" + " }\n" + " }\n"; + const char *spaced = + " for (s = 0; s < sizeof(sep) / sizeof(char); ++s) {\n" + " separator = sep[s];\n" + " expect = expect_values[s];\n" + "\n" + " for (j = 0; j < sizeof(b) / sizeof(char*); ++j) {\n" + " for (i = 0; i < sizeof(a) / sizeof(char*); ++i) {\n" + " git_str_join(&buf, separator, a[i], b[j]);\n" + " cl_assert_equal_s(*expect, buf.ptr);\n" + " expect++;\n" + " }\n" + " }\n" + " }\n"; + const char *crlf_spaced2 = + " for (s = 0; s < sizeof(sep) / sizeof(char); ++s) {\r\n" + " separator = sep[s];\r\n" + " expect = expect_values[s];\r\n" + "\r\n" + " for (j = 0; j < sizeof(b) / sizeof(char*); ++j) {\r\n" + " for (i = 0; i < sizeof(a) / sizeof(char*); ++i) {\r\n" + " git_str_join(&buf, separator, a[i], b[j]);\r\n" + " cl_assert_equal_s(*expect, buf.ptr);\r\n" + " expect++;\r\n" + " }\r\n" + " }\r\n" + " }\r\n"; + const char *text[3] = { tabbed, spaced, crlf_spaced2 }; + + /* let's try variations of our own code with whitespace changes */ + + for (opt = GIT_HASHSIG_NORMAL; opt <= GIT_HASHSIG_SMART_WHITESPACE; ++opt) { + for (i = 0; i < 3; ++i) { + for (j = 0; j < 3; ++j) { + cl_git_pass(git_str_sets(&buf, text[i])); + cl_git_pass(git_hashsig_create(&a, buf.ptr, buf.size, opt)); + + cl_git_pass(git_str_sets(&buf, text[j])); + cl_git_pass(git_hashsig_create(&b, buf.ptr, buf.size, opt)); + + sim = git_hashsig_compare(a, b); + + if (opt == GIT_HASHSIG_NORMAL) { + if (i == j) + cl_assert_equal_i(100, sim); + else + cl_assert_in_range(0, sim, 30); /* pretty different */ + } else { + cl_assert_equal_i(100, sim); + } + + git_hashsig_free(a); + git_hashsig_free(b); + } + } + } + + git_str_dispose(&buf); +} diff --git a/tests/core/oid.c b/tests/libgit2/core/oid.c similarity index 100% rename from tests/core/oid.c rename to tests/libgit2/core/oid.c diff --git a/tests/core/oidmap.c b/tests/libgit2/core/oidmap.c similarity index 100% rename from tests/core/oidmap.c rename to tests/libgit2/core/oidmap.c diff --git a/tests/core/opts.c b/tests/libgit2/core/opts.c similarity index 100% rename from tests/core/opts.c rename to tests/libgit2/core/opts.c diff --git a/tests/libgit2/core/pool.c b/tests/libgit2/core/pool.c new file mode 100644 index 00000000000..5746e35b840 --- /dev/null +++ b/tests/libgit2/core/pool.c @@ -0,0 +1,33 @@ +#include "clar_libgit2.h" +#include "pool.h" +#include "git2/oid.h" + +static char to_hex[] = "0123456789abcdef"; + +void test_core_pool__oid(void) +{ + git_pool p; + char oid_hex[GIT_OID_HEXSZ]; + git_oid *oid; + int i, j; + + memset(oid_hex, '0', sizeof(oid_hex)); + + git_pool_init(&p, sizeof(git_oid)); + p.page_size = 4000; + + for (i = 1000; i < 10000; i++) { + oid = git_pool_malloc(&p, 1); + cl_assert(oid != NULL); + + for (j = 0; j < 8; j++) + oid_hex[j] = to_hex[(i >> (4 * j)) & 0x0f]; + cl_git_pass(git_oid_fromstr(oid, oid_hex)); + } + +#ifndef GIT_DEBUG_POOL + /* with fixed page size, allocation must end up with these values */ + cl_assert_equal_i(sizeof(void *) == 8 ? 55 : 45, git_pool__open_pages(&p)); +#endif + git_pool_clear(&p); +} diff --git a/tests/core/structinit.c b/tests/libgit2/core/structinit.c similarity index 100% rename from tests/core/structinit.c rename to tests/libgit2/core/structinit.c diff --git a/tests/core/useragent.c b/tests/libgit2/core/useragent.c similarity index 100% rename from tests/core/useragent.c rename to tests/libgit2/core/useragent.c diff --git a/tests/date/date.c b/tests/libgit2/date/date.c similarity index 100% rename from tests/date/date.c rename to tests/libgit2/date/date.c diff --git a/tests/date/rfc2822.c b/tests/libgit2/date/rfc2822.c similarity index 100% rename from tests/date/rfc2822.c rename to tests/libgit2/date/rfc2822.c diff --git a/tests/delta/apply.c b/tests/libgit2/delta/apply.c similarity index 100% rename from tests/delta/apply.c rename to tests/libgit2/delta/apply.c diff --git a/tests/describe/describe.c b/tests/libgit2/describe/describe.c similarity index 100% rename from tests/describe/describe.c rename to tests/libgit2/describe/describe.c diff --git a/tests/describe/describe_helpers.c b/tests/libgit2/describe/describe_helpers.c similarity index 100% rename from tests/describe/describe_helpers.c rename to tests/libgit2/describe/describe_helpers.c diff --git a/tests/describe/describe_helpers.h b/tests/libgit2/describe/describe_helpers.h similarity index 100% rename from tests/describe/describe_helpers.h rename to tests/libgit2/describe/describe_helpers.h diff --git a/tests/describe/t6120.c b/tests/libgit2/describe/t6120.c similarity index 100% rename from tests/describe/t6120.c rename to tests/libgit2/describe/t6120.c diff --git a/tests/diff/binary.c b/tests/libgit2/diff/binary.c similarity index 100% rename from tests/diff/binary.c rename to tests/libgit2/diff/binary.c diff --git a/tests/diff/blob.c b/tests/libgit2/diff/blob.c similarity index 100% rename from tests/diff/blob.c rename to tests/libgit2/diff/blob.c diff --git a/tests/diff/diff_helpers.c b/tests/libgit2/diff/diff_helpers.c similarity index 100% rename from tests/diff/diff_helpers.c rename to tests/libgit2/diff/diff_helpers.c diff --git a/tests/diff/diff_helpers.h b/tests/libgit2/diff/diff_helpers.h similarity index 100% rename from tests/diff/diff_helpers.h rename to tests/libgit2/diff/diff_helpers.h diff --git a/tests/diff/diffiter.c b/tests/libgit2/diff/diffiter.c similarity index 100% rename from tests/diff/diffiter.c rename to tests/libgit2/diff/diffiter.c diff --git a/tests/diff/drivers.c b/tests/libgit2/diff/drivers.c similarity index 100% rename from tests/diff/drivers.c rename to tests/libgit2/diff/drivers.c diff --git a/tests/diff/externalmodifications.c b/tests/libgit2/diff/externalmodifications.c similarity index 100% rename from tests/diff/externalmodifications.c rename to tests/libgit2/diff/externalmodifications.c diff --git a/tests/diff/format_email.c b/tests/libgit2/diff/format_email.c similarity index 100% rename from tests/diff/format_email.c rename to tests/libgit2/diff/format_email.c diff --git a/tests/diff/index.c b/tests/libgit2/diff/index.c similarity index 100% rename from tests/diff/index.c rename to tests/libgit2/diff/index.c diff --git a/tests/diff/notify.c b/tests/libgit2/diff/notify.c similarity index 100% rename from tests/diff/notify.c rename to tests/libgit2/diff/notify.c diff --git a/tests/diff/parse.c b/tests/libgit2/diff/parse.c similarity index 100% rename from tests/diff/parse.c rename to tests/libgit2/diff/parse.c diff --git a/tests/diff/patch.c b/tests/libgit2/diff/patch.c similarity index 100% rename from tests/diff/patch.c rename to tests/libgit2/diff/patch.c diff --git a/tests/diff/patchid.c b/tests/libgit2/diff/patchid.c similarity index 100% rename from tests/diff/patchid.c rename to tests/libgit2/diff/patchid.c diff --git a/tests/diff/pathspec.c b/tests/libgit2/diff/pathspec.c similarity index 100% rename from tests/diff/pathspec.c rename to tests/libgit2/diff/pathspec.c diff --git a/tests/diff/racediffiter.c b/tests/libgit2/diff/racediffiter.c similarity index 100% rename from tests/diff/racediffiter.c rename to tests/libgit2/diff/racediffiter.c diff --git a/tests/diff/rename.c b/tests/libgit2/diff/rename.c similarity index 100% rename from tests/diff/rename.c rename to tests/libgit2/diff/rename.c diff --git a/tests/diff/stats.c b/tests/libgit2/diff/stats.c similarity index 100% rename from tests/diff/stats.c rename to tests/libgit2/diff/stats.c diff --git a/tests/diff/submodules.c b/tests/libgit2/diff/submodules.c similarity index 100% rename from tests/diff/submodules.c rename to tests/libgit2/diff/submodules.c diff --git a/tests/diff/tree.c b/tests/libgit2/diff/tree.c similarity index 100% rename from tests/diff/tree.c rename to tests/libgit2/diff/tree.c diff --git a/tests/libgit2/diff/userdiff.c b/tests/libgit2/diff/userdiff.c new file mode 100644 index 00000000000..23049400934 --- /dev/null +++ b/tests/libgit2/diff/userdiff.c @@ -0,0 +1,25 @@ +#include "clar_libgit2.h" + +#include "userdiff.h" + +static git_regexp regex; + +void test_diff_userdiff__cleanup(void) +{ + git_regexp_dispose(®ex); +} + +void test_diff_userdiff__compile_userdiff_regexps(void) +{ + size_t idx; + + for (idx = 0; idx < ARRAY_SIZE(builtin_defs); ++idx) { + git_diff_driver_definition ddef = builtin_defs[idx]; + + cl_git_pass(git_regexp_compile(®ex, ddef.fns, ddef.flags)); + git_regexp_dispose(®ex); + + cl_git_pass(git_regexp_compile(®ex, ddef.words, 0)); + git_regexp_dispose(®ex); + } +} diff --git a/tests/diff/workdir.c b/tests/libgit2/diff/workdir.c similarity index 100% rename from tests/diff/workdir.c rename to tests/libgit2/diff/workdir.c diff --git a/tests/email/create.c b/tests/libgit2/email/create.c similarity index 100% rename from tests/email/create.c rename to tests/libgit2/email/create.c diff --git a/tests/email/create.c.bak b/tests/libgit2/email/create.c.bak similarity index 100% rename from tests/email/create.c.bak rename to tests/libgit2/email/create.c.bak diff --git a/tests/fetch/local.c b/tests/libgit2/fetch/local.c similarity index 100% rename from tests/fetch/local.c rename to tests/libgit2/fetch/local.c diff --git a/tests/fetchhead/fetchhead_data.h b/tests/libgit2/fetchhead/fetchhead_data.h similarity index 100% rename from tests/fetchhead/fetchhead_data.h rename to tests/libgit2/fetchhead/fetchhead_data.h diff --git a/tests/fetchhead/nonetwork.c b/tests/libgit2/fetchhead/nonetwork.c similarity index 100% rename from tests/fetchhead/nonetwork.c rename to tests/libgit2/fetchhead/nonetwork.c diff --git a/tests/filter/bare.c b/tests/libgit2/filter/bare.c similarity index 100% rename from tests/filter/bare.c rename to tests/libgit2/filter/bare.c diff --git a/tests/filter/blob.c b/tests/libgit2/filter/blob.c similarity index 100% rename from tests/filter/blob.c rename to tests/libgit2/filter/blob.c diff --git a/tests/filter/crlf.c b/tests/libgit2/filter/crlf.c similarity index 100% rename from tests/filter/crlf.c rename to tests/libgit2/filter/crlf.c diff --git a/tests/filter/crlf.h b/tests/libgit2/filter/crlf.h similarity index 100% rename from tests/filter/crlf.h rename to tests/libgit2/filter/crlf.h diff --git a/tests/filter/custom.c b/tests/libgit2/filter/custom.c similarity index 100% rename from tests/filter/custom.c rename to tests/libgit2/filter/custom.c diff --git a/tests/filter/custom_helpers.c b/tests/libgit2/filter/custom_helpers.c similarity index 100% rename from tests/filter/custom_helpers.c rename to tests/libgit2/filter/custom_helpers.c diff --git a/tests/filter/custom_helpers.h b/tests/libgit2/filter/custom_helpers.h similarity index 100% rename from tests/filter/custom_helpers.h rename to tests/libgit2/filter/custom_helpers.h diff --git a/tests/filter/file.c b/tests/libgit2/filter/file.c similarity index 100% rename from tests/filter/file.c rename to tests/libgit2/filter/file.c diff --git a/tests/filter/ident.c b/tests/libgit2/filter/ident.c similarity index 100% rename from tests/filter/ident.c rename to tests/libgit2/filter/ident.c diff --git a/tests/filter/query.c b/tests/libgit2/filter/query.c similarity index 100% rename from tests/filter/query.c rename to tests/libgit2/filter/query.c diff --git a/tests/filter/stream.c b/tests/libgit2/filter/stream.c similarity index 100% rename from tests/filter/stream.c rename to tests/libgit2/filter/stream.c diff --git a/tests/filter/systemattrs.c b/tests/libgit2/filter/systemattrs.c similarity index 100% rename from tests/filter/systemattrs.c rename to tests/libgit2/filter/systemattrs.c diff --git a/tests/filter/wildcard.c b/tests/libgit2/filter/wildcard.c similarity index 100% rename from tests/filter/wildcard.c rename to tests/libgit2/filter/wildcard.c diff --git a/tests/graph/ahead_behind.c b/tests/libgit2/graph/ahead_behind.c similarity index 100% rename from tests/graph/ahead_behind.c rename to tests/libgit2/graph/ahead_behind.c diff --git a/tests/graph/commitgraph.c b/tests/libgit2/graph/commitgraph.c similarity index 100% rename from tests/graph/commitgraph.c rename to tests/libgit2/graph/commitgraph.c diff --git a/tests/graph/descendant_of.c b/tests/libgit2/graph/descendant_of.c similarity index 100% rename from tests/graph/descendant_of.c rename to tests/libgit2/graph/descendant_of.c diff --git a/tests/graph/reachable_from_any.c b/tests/libgit2/graph/reachable_from_any.c similarity index 100% rename from tests/graph/reachable_from_any.c rename to tests/libgit2/graph/reachable_from_any.c diff --git a/tests/ignore/path.c b/tests/libgit2/ignore/path.c similarity index 100% rename from tests/ignore/path.c rename to tests/libgit2/ignore/path.c diff --git a/tests/ignore/status.c b/tests/libgit2/ignore/status.c similarity index 100% rename from tests/ignore/status.c rename to tests/libgit2/ignore/status.c diff --git a/tests/index/add.c b/tests/libgit2/index/add.c similarity index 100% rename from tests/index/add.c rename to tests/libgit2/index/add.c diff --git a/tests/index/addall.c b/tests/libgit2/index/addall.c similarity index 100% rename from tests/index/addall.c rename to tests/libgit2/index/addall.c diff --git a/tests/index/bypath.c b/tests/libgit2/index/bypath.c similarity index 100% rename from tests/index/bypath.c rename to tests/libgit2/index/bypath.c diff --git a/tests/index/cache.c b/tests/libgit2/index/cache.c similarity index 100% rename from tests/index/cache.c rename to tests/libgit2/index/cache.c diff --git a/tests/index/collision.c b/tests/libgit2/index/collision.c similarity index 100% rename from tests/index/collision.c rename to tests/libgit2/index/collision.c diff --git a/tests/index/conflicts.c b/tests/libgit2/index/conflicts.c similarity index 100% rename from tests/index/conflicts.c rename to tests/libgit2/index/conflicts.c diff --git a/tests/index/conflicts.h b/tests/libgit2/index/conflicts.h similarity index 100% rename from tests/index/conflicts.h rename to tests/libgit2/index/conflicts.h diff --git a/tests/index/crlf.c b/tests/libgit2/index/crlf.c similarity index 100% rename from tests/index/crlf.c rename to tests/libgit2/index/crlf.c diff --git a/tests/index/filemodes.c b/tests/libgit2/index/filemodes.c similarity index 100% rename from tests/index/filemodes.c rename to tests/libgit2/index/filemodes.c diff --git a/tests/index/inmemory.c b/tests/libgit2/index/inmemory.c similarity index 100% rename from tests/index/inmemory.c rename to tests/libgit2/index/inmemory.c diff --git a/tests/index/names.c b/tests/libgit2/index/names.c similarity index 100% rename from tests/index/names.c rename to tests/libgit2/index/names.c diff --git a/tests/index/nsec.c b/tests/libgit2/index/nsec.c similarity index 100% rename from tests/index/nsec.c rename to tests/libgit2/index/nsec.c diff --git a/tests/index/racy.c b/tests/libgit2/index/racy.c similarity index 100% rename from tests/index/racy.c rename to tests/libgit2/index/racy.c diff --git a/tests/index/read_index.c b/tests/libgit2/index/read_index.c similarity index 100% rename from tests/index/read_index.c rename to tests/libgit2/index/read_index.c diff --git a/tests/index/read_tree.c b/tests/libgit2/index/read_tree.c similarity index 100% rename from tests/index/read_tree.c rename to tests/libgit2/index/read_tree.c diff --git a/tests/index/rename.c b/tests/libgit2/index/rename.c similarity index 100% rename from tests/index/rename.c rename to tests/libgit2/index/rename.c diff --git a/tests/index/reuc.c b/tests/libgit2/index/reuc.c similarity index 100% rename from tests/index/reuc.c rename to tests/libgit2/index/reuc.c diff --git a/tests/index/splitindex.c b/tests/libgit2/index/splitindex.c similarity index 100% rename from tests/index/splitindex.c rename to tests/libgit2/index/splitindex.c diff --git a/tests/index/stage.c b/tests/libgit2/index/stage.c similarity index 100% rename from tests/index/stage.c rename to tests/libgit2/index/stage.c diff --git a/tests/index/tests.c b/tests/libgit2/index/tests.c similarity index 100% rename from tests/index/tests.c rename to tests/libgit2/index/tests.c diff --git a/tests/index/version.c b/tests/libgit2/index/version.c similarity index 100% rename from tests/index/version.c rename to tests/libgit2/index/version.c diff --git a/tests/iterator/index.c b/tests/libgit2/iterator/index.c similarity index 100% rename from tests/iterator/index.c rename to tests/libgit2/iterator/index.c diff --git a/tests/iterator/iterator_helpers.c b/tests/libgit2/iterator/iterator_helpers.c similarity index 100% rename from tests/iterator/iterator_helpers.c rename to tests/libgit2/iterator/iterator_helpers.c diff --git a/tests/iterator/iterator_helpers.h b/tests/libgit2/iterator/iterator_helpers.h similarity index 100% rename from tests/iterator/iterator_helpers.h rename to tests/libgit2/iterator/iterator_helpers.h diff --git a/tests/iterator/tree.c b/tests/libgit2/iterator/tree.c similarity index 100% rename from tests/iterator/tree.c rename to tests/libgit2/iterator/tree.c diff --git a/tests/iterator/workdir.c b/tests/libgit2/iterator/workdir.c similarity index 100% rename from tests/iterator/workdir.c rename to tests/libgit2/iterator/workdir.c diff --git a/tests/mailmap/basic.c b/tests/libgit2/mailmap/basic.c similarity index 100% rename from tests/mailmap/basic.c rename to tests/libgit2/mailmap/basic.c diff --git a/tests/mailmap/blame.c b/tests/libgit2/mailmap/blame.c similarity index 100% rename from tests/mailmap/blame.c rename to tests/libgit2/mailmap/blame.c diff --git a/tests/mailmap/mailmap_testdata.h b/tests/libgit2/mailmap/mailmap_testdata.h similarity index 100% rename from tests/mailmap/mailmap_testdata.h rename to tests/libgit2/mailmap/mailmap_testdata.h diff --git a/tests/mailmap/parsing.c b/tests/libgit2/mailmap/parsing.c similarity index 100% rename from tests/mailmap/parsing.c rename to tests/libgit2/mailmap/parsing.c diff --git a/tests/merge/analysis.c b/tests/libgit2/merge/analysis.c similarity index 100% rename from tests/merge/analysis.c rename to tests/libgit2/merge/analysis.c diff --git a/tests/merge/annotated_commit.c b/tests/libgit2/merge/annotated_commit.c similarity index 100% rename from tests/merge/annotated_commit.c rename to tests/libgit2/merge/annotated_commit.c diff --git a/tests/merge/conflict_data.h b/tests/libgit2/merge/conflict_data.h similarity index 100% rename from tests/merge/conflict_data.h rename to tests/libgit2/merge/conflict_data.h diff --git a/tests/merge/driver.c b/tests/libgit2/merge/driver.c similarity index 100% rename from tests/merge/driver.c rename to tests/libgit2/merge/driver.c diff --git a/tests/merge/files.c b/tests/libgit2/merge/files.c similarity index 100% rename from tests/merge/files.c rename to tests/libgit2/merge/files.c diff --git a/tests/merge/merge_helpers.c b/tests/libgit2/merge/merge_helpers.c similarity index 100% rename from tests/merge/merge_helpers.c rename to tests/libgit2/merge/merge_helpers.c diff --git a/tests/merge/merge_helpers.h b/tests/libgit2/merge/merge_helpers.h similarity index 100% rename from tests/merge/merge_helpers.h rename to tests/libgit2/merge/merge_helpers.h diff --git a/tests/merge/trees/automerge.c b/tests/libgit2/merge/trees/automerge.c similarity index 100% rename from tests/merge/trees/automerge.c rename to tests/libgit2/merge/trees/automerge.c diff --git a/tests/merge/trees/commits.c b/tests/libgit2/merge/trees/commits.c similarity index 100% rename from tests/merge/trees/commits.c rename to tests/libgit2/merge/trees/commits.c diff --git a/tests/merge/trees/modeconflict.c b/tests/libgit2/merge/trees/modeconflict.c similarity index 100% rename from tests/merge/trees/modeconflict.c rename to tests/libgit2/merge/trees/modeconflict.c diff --git a/tests/merge/trees/recursive.c b/tests/libgit2/merge/trees/recursive.c similarity index 100% rename from tests/merge/trees/recursive.c rename to tests/libgit2/merge/trees/recursive.c diff --git a/tests/merge/trees/renames.c b/tests/libgit2/merge/trees/renames.c similarity index 100% rename from tests/merge/trees/renames.c rename to tests/libgit2/merge/trees/renames.c diff --git a/tests/merge/trees/treediff.c b/tests/libgit2/merge/trees/treediff.c similarity index 100% rename from tests/merge/trees/treediff.c rename to tests/libgit2/merge/trees/treediff.c diff --git a/tests/merge/trees/trivial.c b/tests/libgit2/merge/trees/trivial.c similarity index 100% rename from tests/merge/trees/trivial.c rename to tests/libgit2/merge/trees/trivial.c diff --git a/tests/merge/trees/whitespace.c b/tests/libgit2/merge/trees/whitespace.c similarity index 100% rename from tests/merge/trees/whitespace.c rename to tests/libgit2/merge/trees/whitespace.c diff --git a/tests/merge/workdir/dirty.c b/tests/libgit2/merge/workdir/dirty.c similarity index 100% rename from tests/merge/workdir/dirty.c rename to tests/libgit2/merge/workdir/dirty.c diff --git a/tests/merge/workdir/recursive.c b/tests/libgit2/merge/workdir/recursive.c similarity index 100% rename from tests/merge/workdir/recursive.c rename to tests/libgit2/merge/workdir/recursive.c diff --git a/tests/merge/workdir/renames.c b/tests/libgit2/merge/workdir/renames.c similarity index 100% rename from tests/merge/workdir/renames.c rename to tests/libgit2/merge/workdir/renames.c diff --git a/tests/merge/workdir/setup.c b/tests/libgit2/merge/workdir/setup.c similarity index 100% rename from tests/merge/workdir/setup.c rename to tests/libgit2/merge/workdir/setup.c diff --git a/tests/merge/workdir/simple.c b/tests/libgit2/merge/workdir/simple.c similarity index 100% rename from tests/merge/workdir/simple.c rename to tests/libgit2/merge/workdir/simple.c diff --git a/tests/merge/workdir/submodules.c b/tests/libgit2/merge/workdir/submodules.c similarity index 100% rename from tests/merge/workdir/submodules.c rename to tests/libgit2/merge/workdir/submodules.c diff --git a/tests/merge/workdir/trivial.c b/tests/libgit2/merge/workdir/trivial.c similarity index 100% rename from tests/merge/workdir/trivial.c rename to tests/libgit2/merge/workdir/trivial.c diff --git a/tests/message/trailer.c b/tests/libgit2/message/trailer.c similarity index 100% rename from tests/message/trailer.c rename to tests/libgit2/message/trailer.c diff --git a/tests/network/cred.c b/tests/libgit2/network/cred.c similarity index 100% rename from tests/network/cred.c rename to tests/libgit2/network/cred.c diff --git a/tests/network/fetchlocal.c b/tests/libgit2/network/fetchlocal.c similarity index 100% rename from tests/network/fetchlocal.c rename to tests/libgit2/network/fetchlocal.c diff --git a/tests/network/matchhost.c b/tests/libgit2/network/matchhost.c similarity index 100% rename from tests/network/matchhost.c rename to tests/libgit2/network/matchhost.c diff --git a/tests/network/refspecs.c b/tests/libgit2/network/refspecs.c similarity index 100% rename from tests/network/refspecs.c rename to tests/libgit2/network/refspecs.c diff --git a/tests/network/remote/defaultbranch.c b/tests/libgit2/network/remote/defaultbranch.c similarity index 100% rename from tests/network/remote/defaultbranch.c rename to tests/libgit2/network/remote/defaultbranch.c diff --git a/tests/network/remote/delete.c b/tests/libgit2/network/remote/delete.c similarity index 100% rename from tests/network/remote/delete.c rename to tests/libgit2/network/remote/delete.c diff --git a/tests/network/remote/isvalidname.c b/tests/libgit2/network/remote/isvalidname.c similarity index 100% rename from tests/network/remote/isvalidname.c rename to tests/libgit2/network/remote/isvalidname.c diff --git a/tests/network/remote/local.c b/tests/libgit2/network/remote/local.c similarity index 100% rename from tests/network/remote/local.c rename to tests/libgit2/network/remote/local.c diff --git a/tests/network/remote/push.c b/tests/libgit2/network/remote/push.c similarity index 100% rename from tests/network/remote/push.c rename to tests/libgit2/network/remote/push.c diff --git a/tests/network/remote/remotes.c b/tests/libgit2/network/remote/remotes.c similarity index 100% rename from tests/network/remote/remotes.c rename to tests/libgit2/network/remote/remotes.c diff --git a/tests/network/remote/rename.c b/tests/libgit2/network/remote/rename.c similarity index 100% rename from tests/network/remote/rename.c rename to tests/libgit2/network/remote/rename.c diff --git a/tests/network/url/joinpath.c b/tests/libgit2/network/url/joinpath.c similarity index 100% rename from tests/network/url/joinpath.c rename to tests/libgit2/network/url/joinpath.c diff --git a/tests/network/url/parse.c b/tests/libgit2/network/url/parse.c similarity index 100% rename from tests/network/url/parse.c rename to tests/libgit2/network/url/parse.c diff --git a/tests/network/url/pattern.c b/tests/libgit2/network/url/pattern.c similarity index 100% rename from tests/network/url/pattern.c rename to tests/libgit2/network/url/pattern.c diff --git a/tests/network/url/redirect.c b/tests/libgit2/network/url/redirect.c similarity index 100% rename from tests/network/url/redirect.c rename to tests/libgit2/network/url/redirect.c diff --git a/tests/network/url/scp.c b/tests/libgit2/network/url/scp.c similarity index 100% rename from tests/network/url/scp.c rename to tests/libgit2/network/url/scp.c diff --git a/tests/network/url/valid.c b/tests/libgit2/network/url/valid.c similarity index 100% rename from tests/network/url/valid.c rename to tests/libgit2/network/url/valid.c diff --git a/tests/notes/notes.c b/tests/libgit2/notes/notes.c similarity index 100% rename from tests/notes/notes.c rename to tests/libgit2/notes/notes.c diff --git a/tests/notes/notesref.c b/tests/libgit2/notes/notesref.c similarity index 100% rename from tests/notes/notesref.c rename to tests/libgit2/notes/notesref.c diff --git a/tests/object/blob/filter.c b/tests/libgit2/object/blob/filter.c similarity index 100% rename from tests/object/blob/filter.c rename to tests/libgit2/object/blob/filter.c diff --git a/tests/object/blob/fromstream.c b/tests/libgit2/object/blob/fromstream.c similarity index 100% rename from tests/object/blob/fromstream.c rename to tests/libgit2/object/blob/fromstream.c diff --git a/tests/object/blob/write.c b/tests/libgit2/object/blob/write.c similarity index 100% rename from tests/object/blob/write.c rename to tests/libgit2/object/blob/write.c diff --git a/tests/object/cache.c b/tests/libgit2/object/cache.c similarity index 100% rename from tests/object/cache.c rename to tests/libgit2/object/cache.c diff --git a/tests/object/commit/commitstagedfile.c b/tests/libgit2/object/commit/commitstagedfile.c similarity index 100% rename from tests/object/commit/commitstagedfile.c rename to tests/libgit2/object/commit/commitstagedfile.c diff --git a/tests/object/commit/parse.c b/tests/libgit2/object/commit/parse.c similarity index 100% rename from tests/object/commit/parse.c rename to tests/libgit2/object/commit/parse.c diff --git a/tests/object/lookup.c b/tests/libgit2/object/lookup.c similarity index 100% rename from tests/object/lookup.c rename to tests/libgit2/object/lookup.c diff --git a/tests/object/lookupbypath.c b/tests/libgit2/object/lookupbypath.c similarity index 100% rename from tests/object/lookupbypath.c rename to tests/libgit2/object/lookupbypath.c diff --git a/tests/object/message.c b/tests/libgit2/object/message.c similarity index 100% rename from tests/object/message.c rename to tests/libgit2/object/message.c diff --git a/tests/object/peel.c b/tests/libgit2/object/peel.c similarity index 100% rename from tests/object/peel.c rename to tests/libgit2/object/peel.c diff --git a/tests/object/raw/chars.c b/tests/libgit2/object/raw/chars.c similarity index 100% rename from tests/object/raw/chars.c rename to tests/libgit2/object/raw/chars.c diff --git a/tests/object/raw/compare.c b/tests/libgit2/object/raw/compare.c similarity index 100% rename from tests/object/raw/compare.c rename to tests/libgit2/object/raw/compare.c diff --git a/tests/object/raw/convert.c b/tests/libgit2/object/raw/convert.c similarity index 100% rename from tests/object/raw/convert.c rename to tests/libgit2/object/raw/convert.c diff --git a/tests/object/raw/data.h b/tests/libgit2/object/raw/data.h similarity index 100% rename from tests/object/raw/data.h rename to tests/libgit2/object/raw/data.h diff --git a/tests/object/raw/fromstr.c b/tests/libgit2/object/raw/fromstr.c similarity index 100% rename from tests/object/raw/fromstr.c rename to tests/libgit2/object/raw/fromstr.c diff --git a/tests/object/raw/hash.c b/tests/libgit2/object/raw/hash.c similarity index 100% rename from tests/object/raw/hash.c rename to tests/libgit2/object/raw/hash.c diff --git a/tests/object/raw/short.c b/tests/libgit2/object/raw/short.c similarity index 100% rename from tests/object/raw/short.c rename to tests/libgit2/object/raw/short.c diff --git a/tests/object/raw/size.c b/tests/libgit2/object/raw/size.c similarity index 100% rename from tests/object/raw/size.c rename to tests/libgit2/object/raw/size.c diff --git a/tests/object/raw/type2string.c b/tests/libgit2/object/raw/type2string.c similarity index 100% rename from tests/object/raw/type2string.c rename to tests/libgit2/object/raw/type2string.c diff --git a/tests/object/raw/write.c b/tests/libgit2/object/raw/write.c similarity index 100% rename from tests/object/raw/write.c rename to tests/libgit2/object/raw/write.c diff --git a/tests/object/shortid.c b/tests/libgit2/object/shortid.c similarity index 100% rename from tests/object/shortid.c rename to tests/libgit2/object/shortid.c diff --git a/tests/object/tag/list.c b/tests/libgit2/object/tag/list.c similarity index 100% rename from tests/object/tag/list.c rename to tests/libgit2/object/tag/list.c diff --git a/tests/object/tag/parse.c b/tests/libgit2/object/tag/parse.c similarity index 100% rename from tests/object/tag/parse.c rename to tests/libgit2/object/tag/parse.c diff --git a/tests/object/tag/peel.c b/tests/libgit2/object/tag/peel.c similarity index 100% rename from tests/object/tag/peel.c rename to tests/libgit2/object/tag/peel.c diff --git a/tests/object/tag/read.c b/tests/libgit2/object/tag/read.c similarity index 100% rename from tests/object/tag/read.c rename to tests/libgit2/object/tag/read.c diff --git a/tests/object/tag/write.c b/tests/libgit2/object/tag/write.c similarity index 100% rename from tests/object/tag/write.c rename to tests/libgit2/object/tag/write.c diff --git a/tests/object/tree/attributes.c b/tests/libgit2/object/tree/attributes.c similarity index 100% rename from tests/object/tree/attributes.c rename to tests/libgit2/object/tree/attributes.c diff --git a/tests/object/tree/duplicateentries.c b/tests/libgit2/object/tree/duplicateentries.c similarity index 100% rename from tests/object/tree/duplicateentries.c rename to tests/libgit2/object/tree/duplicateentries.c diff --git a/tests/object/tree/frompath.c b/tests/libgit2/object/tree/frompath.c similarity index 100% rename from tests/object/tree/frompath.c rename to tests/libgit2/object/tree/frompath.c diff --git a/tests/object/tree/parse.c b/tests/libgit2/object/tree/parse.c similarity index 100% rename from tests/object/tree/parse.c rename to tests/libgit2/object/tree/parse.c diff --git a/tests/object/tree/read.c b/tests/libgit2/object/tree/read.c similarity index 100% rename from tests/object/tree/read.c rename to tests/libgit2/object/tree/read.c diff --git a/tests/object/tree/update.c b/tests/libgit2/object/tree/update.c similarity index 100% rename from tests/object/tree/update.c rename to tests/libgit2/object/tree/update.c diff --git a/tests/object/tree/walk.c b/tests/libgit2/object/tree/walk.c similarity index 100% rename from tests/object/tree/walk.c rename to tests/libgit2/object/tree/walk.c diff --git a/tests/object/tree/write.c b/tests/libgit2/object/tree/write.c similarity index 100% rename from tests/object/tree/write.c rename to tests/libgit2/object/tree/write.c diff --git a/tests/object/validate.c b/tests/libgit2/object/validate.c similarity index 100% rename from tests/object/validate.c rename to tests/libgit2/object/validate.c diff --git a/tests/odb/alternates.c b/tests/libgit2/odb/alternates.c similarity index 100% rename from tests/odb/alternates.c rename to tests/libgit2/odb/alternates.c diff --git a/tests/odb/backend/backend_helpers.c b/tests/libgit2/odb/backend/backend_helpers.c similarity index 100% rename from tests/odb/backend/backend_helpers.c rename to tests/libgit2/odb/backend/backend_helpers.c diff --git a/tests/odb/backend/backend_helpers.h b/tests/libgit2/odb/backend/backend_helpers.h similarity index 100% rename from tests/odb/backend/backend_helpers.h rename to tests/libgit2/odb/backend/backend_helpers.h diff --git a/tests/odb/backend/mempack.c b/tests/libgit2/odb/backend/mempack.c similarity index 100% rename from tests/odb/backend/mempack.c rename to tests/libgit2/odb/backend/mempack.c diff --git a/tests/odb/backend/multiple.c b/tests/libgit2/odb/backend/multiple.c similarity index 100% rename from tests/odb/backend/multiple.c rename to tests/libgit2/odb/backend/multiple.c diff --git a/tests/odb/backend/nobackend.c b/tests/libgit2/odb/backend/nobackend.c similarity index 100% rename from tests/odb/backend/nobackend.c rename to tests/libgit2/odb/backend/nobackend.c diff --git a/tests/odb/backend/nonrefreshing.c b/tests/libgit2/odb/backend/nonrefreshing.c similarity index 100% rename from tests/odb/backend/nonrefreshing.c rename to tests/libgit2/odb/backend/nonrefreshing.c diff --git a/tests/odb/backend/refreshing.c b/tests/libgit2/odb/backend/refreshing.c similarity index 100% rename from tests/odb/backend/refreshing.c rename to tests/libgit2/odb/backend/refreshing.c diff --git a/tests/odb/backend/simple.c b/tests/libgit2/odb/backend/simple.c similarity index 100% rename from tests/odb/backend/simple.c rename to tests/libgit2/odb/backend/simple.c diff --git a/tests/odb/emptyobjects.c b/tests/libgit2/odb/emptyobjects.c similarity index 100% rename from tests/odb/emptyobjects.c rename to tests/libgit2/odb/emptyobjects.c diff --git a/tests/odb/foreach.c b/tests/libgit2/odb/foreach.c similarity index 100% rename from tests/odb/foreach.c rename to tests/libgit2/odb/foreach.c diff --git a/tests/odb/freshen.c b/tests/libgit2/odb/freshen.c similarity index 100% rename from tests/odb/freshen.c rename to tests/libgit2/odb/freshen.c diff --git a/tests/odb/largefiles.c b/tests/libgit2/odb/largefiles.c similarity index 100% rename from tests/odb/largefiles.c rename to tests/libgit2/odb/largefiles.c diff --git a/tests/odb/loose.c b/tests/libgit2/odb/loose.c similarity index 100% rename from tests/odb/loose.c rename to tests/libgit2/odb/loose.c diff --git a/tests/odb/loose_data.h b/tests/libgit2/odb/loose_data.h similarity index 100% rename from tests/odb/loose_data.h rename to tests/libgit2/odb/loose_data.h diff --git a/tests/odb/mixed.c b/tests/libgit2/odb/mixed.c similarity index 100% rename from tests/odb/mixed.c rename to tests/libgit2/odb/mixed.c diff --git a/tests/odb/pack_data.h b/tests/libgit2/odb/pack_data.h similarity index 100% rename from tests/odb/pack_data.h rename to tests/libgit2/odb/pack_data.h diff --git a/tests/odb/pack_data_one.h b/tests/libgit2/odb/pack_data_one.h similarity index 100% rename from tests/odb/pack_data_one.h rename to tests/libgit2/odb/pack_data_one.h diff --git a/tests/odb/packed.c b/tests/libgit2/odb/packed.c similarity index 100% rename from tests/odb/packed.c rename to tests/libgit2/odb/packed.c diff --git a/tests/odb/packed_one.c b/tests/libgit2/odb/packed_one.c similarity index 100% rename from tests/odb/packed_one.c rename to tests/libgit2/odb/packed_one.c diff --git a/tests/odb/sorting.c b/tests/libgit2/odb/sorting.c similarity index 100% rename from tests/odb/sorting.c rename to tests/libgit2/odb/sorting.c diff --git a/tests/odb/streamwrite.c b/tests/libgit2/odb/streamwrite.c similarity index 100% rename from tests/odb/streamwrite.c rename to tests/libgit2/odb/streamwrite.c diff --git a/tests/online/badssl.c b/tests/libgit2/online/badssl.c similarity index 100% rename from tests/online/badssl.c rename to tests/libgit2/online/badssl.c diff --git a/tests/online/clone.c b/tests/libgit2/online/clone.c similarity index 100% rename from tests/online/clone.c rename to tests/libgit2/online/clone.c diff --git a/tests/online/customcert.c b/tests/libgit2/online/customcert.c similarity index 100% rename from tests/online/customcert.c rename to tests/libgit2/online/customcert.c diff --git a/tests/online/fetch.c b/tests/libgit2/online/fetch.c similarity index 100% rename from tests/online/fetch.c rename to tests/libgit2/online/fetch.c diff --git a/tests/online/fetchhead.c b/tests/libgit2/online/fetchhead.c similarity index 100% rename from tests/online/fetchhead.c rename to tests/libgit2/online/fetchhead.c diff --git a/tests/online/push.c b/tests/libgit2/online/push.c similarity index 100% rename from tests/online/push.c rename to tests/libgit2/online/push.c diff --git a/tests/online/push_util.c b/tests/libgit2/online/push_util.c similarity index 100% rename from tests/online/push_util.c rename to tests/libgit2/online/push_util.c diff --git a/tests/online/push_util.h b/tests/libgit2/online/push_util.h similarity index 100% rename from tests/online/push_util.h rename to tests/libgit2/online/push_util.h diff --git a/tests/online/remotes.c b/tests/libgit2/online/remotes.c similarity index 100% rename from tests/online/remotes.c rename to tests/libgit2/online/remotes.c diff --git a/tests/pack/filelimit.c b/tests/libgit2/pack/filelimit.c similarity index 100% rename from tests/pack/filelimit.c rename to tests/libgit2/pack/filelimit.c diff --git a/tests/pack/indexer.c b/tests/libgit2/pack/indexer.c similarity index 100% rename from tests/pack/indexer.c rename to tests/libgit2/pack/indexer.c diff --git a/tests/pack/midx.c b/tests/libgit2/pack/midx.c similarity index 100% rename from tests/pack/midx.c rename to tests/libgit2/pack/midx.c diff --git a/tests/pack/packbuilder.c b/tests/libgit2/pack/packbuilder.c similarity index 100% rename from tests/pack/packbuilder.c rename to tests/libgit2/pack/packbuilder.c diff --git a/tests/pack/sharing.c b/tests/libgit2/pack/sharing.c similarity index 100% rename from tests/pack/sharing.c rename to tests/libgit2/pack/sharing.c diff --git a/tests/pack/threadsafety.c b/tests/libgit2/pack/threadsafety.c similarity index 100% rename from tests/pack/threadsafety.c rename to tests/libgit2/pack/threadsafety.c diff --git a/tests/patch/parse.c b/tests/libgit2/patch/parse.c similarity index 100% rename from tests/patch/parse.c rename to tests/libgit2/patch/parse.c diff --git a/tests/patch/patch_common.h b/tests/libgit2/patch/patch_common.h similarity index 100% rename from tests/patch/patch_common.h rename to tests/libgit2/patch/patch_common.h diff --git a/tests/patch/print.c b/tests/libgit2/patch/print.c similarity index 100% rename from tests/patch/print.c rename to tests/libgit2/patch/print.c diff --git a/tests/libgit2/path/validate.c b/tests/libgit2/path/validate.c new file mode 100644 index 00000000000..df92194538b --- /dev/null +++ b/tests/libgit2/path/validate.c @@ -0,0 +1,63 @@ +#include "clar_libgit2.h" +#include "path.h" + +void test_path_validate__cleanup(void) +{ + cl_git_sandbox_cleanup(); +} + +void test_path_validate__length(void) +{ + cl_must_pass(git_path_validate_length(NULL, "/foo/bar")); + cl_must_pass(git_path_validate_length(NULL, "C:\\Foo\\Bar")); + cl_must_pass(git_path_validate_length(NULL, "\\\\?\\C:\\Foo\\Bar")); + cl_must_pass(git_path_validate_length(NULL, "\\\\?\\C:\\Foo\\Bar")); + cl_must_pass(git_path_validate_length(NULL, "\\\\?\\UNC\\server\\C$\\folder")); + +#ifdef GIT_WIN32 + /* + * In the absence of a repo configuration, 259 character paths + * succeed. >= 260 character paths fail. + */ + cl_must_pass(git_path_validate_length(NULL, "C:\\aaaaaaaaa\\aaaaaaaaa\\aaaaaaaaa\\aaaaaaaaa\\aaaaaaaaa\\aaaaaaaaa\\aaaaaaaaa\\aaaaaaaaa\\aaaaaaaaa\\aaaaaaaaa\\aaaaaaaaa\\aaaaaaaaa\\aaaaaaaaa\\aaaaaaaaa\\aaaaaaaaa\\aaaaaaaaa\\aaaaaaaaa\\aaaaaaaaa\\aaaaaaaaa\\aaaaaaaaa\\aaaaaaaaa\\aaaaaaaaa\\aaaaaaaaa\\aaaaaaaaa\\aaaaaaaaa\\ok.txt")); + cl_must_pass(git_path_validate_length(NULL, "C:\\aaaaaaaaa\\aaaaaaaaa\\aaaaaaaaa\\aaaaaaaaa\\aaaaaaaaa\\aaaaaaaaa\\aaaaaaaaa\\aaaaaaaaa\\aaaaaaaaa\\aaaaaaaaa\\aaaaaaaaa\\aaaaaaaaa\\aaaaaaaaa\\aaaaaaaaa\\aaaaaaaaa\\aaaaaaaaa\\aaaaaaaaa\\aaaaaaaaa\\aaaaaaaaa\\aaaaaaaaa\\aaaaaaaaa\\aaaaaaaaa\\aaaaaaaaa\\aaaaaaaaa\\aaaaaaaaa\\260.txt")); + cl_must_fail(git_path_validate_length(NULL, "C:\\aaaaaaaaa\\aaaaaaaaa\\aaaaaaaaa\\aaaaaaaaa\\aaaaaaaaa\\aaaaaaaaa\\aaaaaaaaa\\aaaaaaaaa\\aaaaaaaaa\\aaaaaaaaa\\aaaaaaaaa\\aaaaaaaaa\\aaaaaaaaa\\aaaaaaaaa\\aaaaaaaaa\\aaaaaaaaa\\aaaaaaaaa\\aaaaaaaaa\\aaaaaaaaa\\aaaaaaaaa\\aaaaaaaaa\\aaaaaaaaa\\aaaaaaaaa\\aaaaaaaaa\\aaaaaaaaa\\longer_than_260.txt")); + + /* count characters, not bytes */ + cl_must_pass(git_path_validate_length(NULL, "C:\\aaaaaaaaa\\aaaaaaaaa\\aaaaaaaaa\\aaaaaaaaa\\aaaaaaaaa\\aaaaaaaaa\\aaaaaaaaa\\aaaaaaaaa\\aaaaaaaaa\\aaaaaaaaa\\aaaaaaaaa\\aaaaaaaaa\\aaaaaaaaa\\aaaaaaaaa\\aaaaaaaaa\\aaaaaaaaa\\aaaaaaaaa\\aaaaaaaaa\\aaaaaaaaa\\aaaaaaaaa\\aaaaaaaaa\\aaaaaaaaa\\aaaaaaaaa\\aaaaaaaaa\\\xc2\xa2\xc2\xa2\xc2\xa2\xc2\xa2\xc2\xa2\xc2\xa2\xc2\xa2\xc2\xa2\xc2\xa2\\260.txt")); + cl_must_fail(git_path_validate_length(NULL, "C:\\aaaaaaaaa\\aaaaaaaaa\\aaaaaaaaa\\aaaaaaaaa\\aaaaaaaaa\\aaaaaaaaa\\aaaaaaaaa\\aaaaaaaaa\\aaaaaaaaa\\aaaaaaaaa\\aaaaaaaaa\\aaaaaaaaa\\aaaaaaaaa\\aaaaaaaaa\\aaaaaaaaa\\aaaaaaaaa\\aaaaaaaaa\\aaaaaaaaa\\aaaaaaaaa\\aaaaaaaaa\\aaaaaaaaa\\aaaaaaaaa\\aaaaaaaaa\\aaaaaaaaa\\\xc2\xa2\xc2\xa2\xc2\xa2\xc2\xa2\xc2\xa2\xc2\xa2\xc2\xa2\xc2\xa2\xc2\xa2\\long.txt")); +#else + cl_must_pass(git_path_validate_length(NULL, "/c/aaaaaaaaa/aaaaaaaaa/aaaaaaaaa/aaaaaaaaa/aaaaaaaaa/aaaaaaaaa/aaaaaaaaa/aaaaaaaaa/aaaaaaaaa/aaaaaaaaa/aaaaaaaaa/aaaaaaaaa/aaaaaaaaa/aaaaaaaaa/aaaaaaaaa/aaaaaaaaa/aaaaaaaaa/aaaaaaaaa/aaaaaaaaa/aaaaaaaaa/aaaaaaaaa/aaaaaaaaa/aaaaaaaaa/aaaaaaaaa/aaaaaaaaa/ok.txt")); + cl_must_pass(git_path_validate_length(NULL, "/c/aaaaaaaaa/aaaaaaaaa/aaaaaaaaa/aaaaaaaaa/aaaaaaaaa/aaaaaaaaa/aaaaaaaaa/aaaaaaaaa/aaaaaaaaa/aaaaaaaaa/aaaaaaaaa/aaaaaaaaa/aaaaaaaaa/aaaaaaaaa/aaaaaaaaa/aaaaaaaaa/aaaaaaaaa/aaaaaaaaa/aaaaaaaaa/aaaaaaaaa/aaaaaaaaa/aaaaaaaaa/aaaaaaaaa/aaaaaaaaa/aaaaaaaaa/260.txt")); + cl_must_pass(git_path_validate_length(NULL, "/c/aaaaaaaaa/aaaaaaaaa/aaaaaaaaa/aaaaaaaaa/aaaaaaaaa/aaaaaaaaa/aaaaaaaaa/aaaaaaaaa/aaaaaaaaa/aaaaaaaaa/aaaaaaaaa/aaaaaaaaa/aaaaaaaaa/aaaaaaaaa/aaaaaaaaa/aaaaaaaaa/aaaaaaaaa/aaaaaaaaa/aaaaaaaaa/aaaaaaaaa/aaaaaaaaa/aaaaaaaaa/aaaaaaaaa/aaaaaaaaa/aaaaaaaaa/longer_than_260.txt")); + cl_must_pass(git_path_validate_length(NULL, "C:\\aaaaaaaaa\\aaaaaaaaa\\aaaaaaaaa\\aaaaaaaaa\\aaaaaaaaa\\aaaaaaaaa\\aaaaaaaaa\\aaaaaaaaa\\aaaaaaaaa\\aaaaaaaaa\\aaaaaaaaa\\aaaaaaaaa\\aaaaaaaaa\\aaaaaaaaa\\aaaaaaaaa\\aaaaaaaaa\\aaaaaaaaa\\aaaaaaaaa\\aaaaaaaaa\\aaaaaaaaa\\aaaaaaaaa\\aaaaaaaaa\\aaaaaaaaa\\aaaaaaaaa\\\xc2\xa2\xc2\xa2\xc2\xa2\xc2\xa2\xc2\xa2\xc2\xa2\xc2\xa2\xc2\xa2\xc2\xa2\\260.txt")); + cl_must_pass(git_path_validate_length(NULL, "C:\\aaaaaaaaa\\aaaaaaaaa\\aaaaaaaaa\\aaaaaaaaa\\aaaaaaaaa\\aaaaaaaaa\\aaaaaaaaa\\aaaaaaaaa\\aaaaaaaaa\\aaaaaaaaa\\aaaaaaaaa\\aaaaaaaaa\\aaaaaaaaa\\aaaaaaaaa\\aaaaaaaaa\\aaaaaaaaa\\aaaaaaaaa\\aaaaaaaaa\\aaaaaaaaa\\aaaaaaaaa\\aaaaaaaaa\\aaaaaaaaa\\aaaaaaaaa\\aaaaaaaaa\\\xc2\xa2\xc2\xa2\xc2\xa2\xc2\xa2\xc2\xa2\xc2\xa2\xc2\xa2\xc2\xa2\xc2\xa2\\long.txt")); +#endif +} + +void test_path_validate__length_with_core_longpath(void) +{ +#ifdef GIT_WIN32 + git_repository *repo; + git_config *config; + + repo = cl_git_sandbox_init("empty_bare.git"); + + cl_git_pass(git_repository_open(&repo, "empty_bare.git")); + cl_git_pass(git_repository_config(&config, repo)); + + /* fail by default */ + cl_must_fail(git_path_validate_length(repo, "/c/aaaaaaaaa/aaaaaaaaa/aaaaaaaaa/aaaaaaaaa/aaaaaaaaa/aaaaaaaaa/aaaaaaaaa/aaaaaaaaa/aaaaaaaaa/aaaaaaaaa/aaaaaaaaa/aaaaaaaaa/aaaaaaaaa/aaaaaaaaa/aaaaaaaaa/aaaaaaaaa/aaaaaaaaa/aaaaaaaaa/aaaaaaaaa/aaaaaaaaa/aaaaaaaaa/aaaaaaaaa/aaaaaaaaa/aaaaaaaaa/aaaaaaaaa/longer_than_260.txt")); + + /* set core.longpaths explicitly on */ + cl_git_pass(git_config_set_bool(config, "core.longpaths", 1)); + cl_must_pass(git_path_validate_length(repo, "/c/aaaaaaaaa/aaaaaaaaa/aaaaaaaaa/aaaaaaaaa/aaaaaaaaa/aaaaaaaaa/aaaaaaaaa/aaaaaaaaa/aaaaaaaaa/aaaaaaaaa/aaaaaaaaa/aaaaaaaaa/aaaaaaaaa/aaaaaaaaa/aaaaaaaaa/aaaaaaaaa/aaaaaaaaa/aaaaaaaaa/aaaaaaaaa/aaaaaaaaa/aaaaaaaaa/aaaaaaaaa/aaaaaaaaa/aaaaaaaaa/aaaaaaaaa/longer_than_260.txt")); + + /* set core.longpaths explicitly off */ + cl_git_pass(git_config_set_bool(config, "core.longpaths", 0)); + cl_must_fail(git_path_validate_length(repo, "/c/aaaaaaaaa/aaaaaaaaa/aaaaaaaaa/aaaaaaaaa/aaaaaaaaa/aaaaaaaaa/aaaaaaaaa/aaaaaaaaa/aaaaaaaaa/aaaaaaaaa/aaaaaaaaa/aaaaaaaaa/aaaaaaaaa/aaaaaaaaa/aaaaaaaaa/aaaaaaaaa/aaaaaaaaa/aaaaaaaaa/aaaaaaaaa/aaaaaaaaa/aaaaaaaaa/aaaaaaaaa/aaaaaaaaa/aaaaaaaaa/aaaaaaaaa/longer_than_260.txt")); + + git_config_free(config); + git_repository_free(repo); +#endif +} diff --git a/tests/perf/helper__perf__do_merge.c b/tests/libgit2/perf/helper__perf__do_merge.c similarity index 100% rename from tests/perf/helper__perf__do_merge.c rename to tests/libgit2/perf/helper__perf__do_merge.c diff --git a/tests/perf/helper__perf__do_merge.h b/tests/libgit2/perf/helper__perf__do_merge.h similarity index 100% rename from tests/perf/helper__perf__do_merge.h rename to tests/libgit2/perf/helper__perf__do_merge.h diff --git a/tests/perf/helper__perf__timer.c b/tests/libgit2/perf/helper__perf__timer.c similarity index 100% rename from tests/perf/helper__perf__timer.c rename to tests/libgit2/perf/helper__perf__timer.c diff --git a/tests/perf/helper__perf__timer.h b/tests/libgit2/perf/helper__perf__timer.h similarity index 100% rename from tests/perf/helper__perf__timer.h rename to tests/libgit2/perf/helper__perf__timer.h diff --git a/tests/perf/merge.c b/tests/libgit2/perf/merge.c similarity index 100% rename from tests/perf/merge.c rename to tests/libgit2/perf/merge.c diff --git a/tests/libgit2/precompiled.c b/tests/libgit2/precompiled.c new file mode 100644 index 00000000000..5f656a45da8 --- /dev/null +++ b/tests/libgit2/precompiled.c @@ -0,0 +1 @@ +#include "precompiled.h" diff --git a/tests/precompiled.h b/tests/libgit2/precompiled.h similarity index 100% rename from tests/precompiled.h rename to tests/libgit2/precompiled.h diff --git a/tests/rebase/abort.c b/tests/libgit2/rebase/abort.c similarity index 100% rename from tests/rebase/abort.c rename to tests/libgit2/rebase/abort.c diff --git a/tests/rebase/inmemory.c b/tests/libgit2/rebase/inmemory.c similarity index 100% rename from tests/rebase/inmemory.c rename to tests/libgit2/rebase/inmemory.c diff --git a/tests/rebase/iterator.c b/tests/libgit2/rebase/iterator.c similarity index 100% rename from tests/rebase/iterator.c rename to tests/libgit2/rebase/iterator.c diff --git a/tests/rebase/merge.c b/tests/libgit2/rebase/merge.c similarity index 100% rename from tests/rebase/merge.c rename to tests/libgit2/rebase/merge.c diff --git a/tests/rebase/setup.c b/tests/libgit2/rebase/setup.c similarity index 100% rename from tests/rebase/setup.c rename to tests/libgit2/rebase/setup.c diff --git a/tests/rebase/sign.c b/tests/libgit2/rebase/sign.c similarity index 100% rename from tests/rebase/sign.c rename to tests/libgit2/rebase/sign.c diff --git a/tests/rebase/submodule.c b/tests/libgit2/rebase/submodule.c similarity index 100% rename from tests/rebase/submodule.c rename to tests/libgit2/rebase/submodule.c diff --git a/tests/refs/basic.c b/tests/libgit2/refs/basic.c similarity index 100% rename from tests/refs/basic.c rename to tests/libgit2/refs/basic.c diff --git a/tests/refs/branches/checkedout.c b/tests/libgit2/refs/branches/checkedout.c similarity index 100% rename from tests/refs/branches/checkedout.c rename to tests/libgit2/refs/branches/checkedout.c diff --git a/tests/refs/branches/create.c b/tests/libgit2/refs/branches/create.c similarity index 100% rename from tests/refs/branches/create.c rename to tests/libgit2/refs/branches/create.c diff --git a/tests/refs/branches/delete.c b/tests/libgit2/refs/branches/delete.c similarity index 100% rename from tests/refs/branches/delete.c rename to tests/libgit2/refs/branches/delete.c diff --git a/tests/refs/branches/ishead.c b/tests/libgit2/refs/branches/ishead.c similarity index 100% rename from tests/refs/branches/ishead.c rename to tests/libgit2/refs/branches/ishead.c diff --git a/tests/refs/branches/iterator.c b/tests/libgit2/refs/branches/iterator.c similarity index 100% rename from tests/refs/branches/iterator.c rename to tests/libgit2/refs/branches/iterator.c diff --git a/tests/refs/branches/lookup.c b/tests/libgit2/refs/branches/lookup.c similarity index 100% rename from tests/refs/branches/lookup.c rename to tests/libgit2/refs/branches/lookup.c diff --git a/tests/refs/branches/move.c b/tests/libgit2/refs/branches/move.c similarity index 100% rename from tests/refs/branches/move.c rename to tests/libgit2/refs/branches/move.c diff --git a/tests/refs/branches/name.c b/tests/libgit2/refs/branches/name.c similarity index 100% rename from tests/refs/branches/name.c rename to tests/libgit2/refs/branches/name.c diff --git a/tests/refs/branches/remote.c b/tests/libgit2/refs/branches/remote.c similarity index 100% rename from tests/refs/branches/remote.c rename to tests/libgit2/refs/branches/remote.c diff --git a/tests/refs/branches/upstream.c b/tests/libgit2/refs/branches/upstream.c similarity index 100% rename from tests/refs/branches/upstream.c rename to tests/libgit2/refs/branches/upstream.c diff --git a/tests/refs/branches/upstreamname.c b/tests/libgit2/refs/branches/upstreamname.c similarity index 100% rename from tests/refs/branches/upstreamname.c rename to tests/libgit2/refs/branches/upstreamname.c diff --git a/tests/refs/crashes.c b/tests/libgit2/refs/crashes.c similarity index 100% rename from tests/refs/crashes.c rename to tests/libgit2/refs/crashes.c diff --git a/tests/refs/create.c b/tests/libgit2/refs/create.c similarity index 100% rename from tests/refs/create.c rename to tests/libgit2/refs/create.c diff --git a/tests/refs/delete.c b/tests/libgit2/refs/delete.c similarity index 100% rename from tests/refs/delete.c rename to tests/libgit2/refs/delete.c diff --git a/tests/refs/dup.c b/tests/libgit2/refs/dup.c similarity index 100% rename from tests/refs/dup.c rename to tests/libgit2/refs/dup.c diff --git a/tests/refs/foreachglob.c b/tests/libgit2/refs/foreachglob.c similarity index 100% rename from tests/refs/foreachglob.c rename to tests/libgit2/refs/foreachglob.c diff --git a/tests/refs/isvalidname.c b/tests/libgit2/refs/isvalidname.c similarity index 100% rename from tests/refs/isvalidname.c rename to tests/libgit2/refs/isvalidname.c diff --git a/tests/refs/iterator.c b/tests/libgit2/refs/iterator.c similarity index 100% rename from tests/refs/iterator.c rename to tests/libgit2/refs/iterator.c diff --git a/tests/refs/list.c b/tests/libgit2/refs/list.c similarity index 100% rename from tests/refs/list.c rename to tests/libgit2/refs/list.c diff --git a/tests/refs/listall.c b/tests/libgit2/refs/listall.c similarity index 100% rename from tests/refs/listall.c rename to tests/libgit2/refs/listall.c diff --git a/tests/refs/lookup.c b/tests/libgit2/refs/lookup.c similarity index 100% rename from tests/refs/lookup.c rename to tests/libgit2/refs/lookup.c diff --git a/tests/refs/namespaces.c b/tests/libgit2/refs/namespaces.c similarity index 100% rename from tests/refs/namespaces.c rename to tests/libgit2/refs/namespaces.c diff --git a/tests/refs/normalize.c b/tests/libgit2/refs/normalize.c similarity index 100% rename from tests/refs/normalize.c rename to tests/libgit2/refs/normalize.c diff --git a/tests/refs/overwrite.c b/tests/libgit2/refs/overwrite.c similarity index 100% rename from tests/refs/overwrite.c rename to tests/libgit2/refs/overwrite.c diff --git a/tests/refs/pack.c b/tests/libgit2/refs/pack.c similarity index 100% rename from tests/refs/pack.c rename to tests/libgit2/refs/pack.c diff --git a/tests/refs/peel.c b/tests/libgit2/refs/peel.c similarity index 100% rename from tests/refs/peel.c rename to tests/libgit2/refs/peel.c diff --git a/tests/refs/races.c b/tests/libgit2/refs/races.c similarity index 100% rename from tests/refs/races.c rename to tests/libgit2/refs/races.c diff --git a/tests/refs/read.c b/tests/libgit2/refs/read.c similarity index 100% rename from tests/refs/read.c rename to tests/libgit2/refs/read.c diff --git a/tests/refs/ref_helpers.c b/tests/libgit2/refs/ref_helpers.c similarity index 100% rename from tests/refs/ref_helpers.c rename to tests/libgit2/refs/ref_helpers.c diff --git a/tests/refs/ref_helpers.h b/tests/libgit2/refs/ref_helpers.h similarity index 100% rename from tests/refs/ref_helpers.h rename to tests/libgit2/refs/ref_helpers.h diff --git a/tests/refs/reflog/drop.c b/tests/libgit2/refs/reflog/drop.c similarity index 100% rename from tests/refs/reflog/drop.c rename to tests/libgit2/refs/reflog/drop.c diff --git a/tests/refs/reflog/messages.c b/tests/libgit2/refs/reflog/messages.c similarity index 100% rename from tests/refs/reflog/messages.c rename to tests/libgit2/refs/reflog/messages.c diff --git a/tests/refs/reflog/reflog.c b/tests/libgit2/refs/reflog/reflog.c similarity index 100% rename from tests/refs/reflog/reflog.c rename to tests/libgit2/refs/reflog/reflog.c diff --git a/tests/refs/reflog/reflog_helpers.c b/tests/libgit2/refs/reflog/reflog_helpers.c similarity index 100% rename from tests/refs/reflog/reflog_helpers.c rename to tests/libgit2/refs/reflog/reflog_helpers.c diff --git a/tests/refs/reflog/reflog_helpers.h b/tests/libgit2/refs/reflog/reflog_helpers.h similarity index 100% rename from tests/refs/reflog/reflog_helpers.h rename to tests/libgit2/refs/reflog/reflog_helpers.h diff --git a/tests/refs/rename.c b/tests/libgit2/refs/rename.c similarity index 100% rename from tests/refs/rename.c rename to tests/libgit2/refs/rename.c diff --git a/tests/refs/revparse.c b/tests/libgit2/refs/revparse.c similarity index 100% rename from tests/refs/revparse.c rename to tests/libgit2/refs/revparse.c diff --git a/tests/refs/setter.c b/tests/libgit2/refs/setter.c similarity index 100% rename from tests/refs/setter.c rename to tests/libgit2/refs/setter.c diff --git a/tests/refs/shorthand.c b/tests/libgit2/refs/shorthand.c similarity index 100% rename from tests/refs/shorthand.c rename to tests/libgit2/refs/shorthand.c diff --git a/tests/refs/tags/name.c b/tests/libgit2/refs/tags/name.c similarity index 100% rename from tests/refs/tags/name.c rename to tests/libgit2/refs/tags/name.c diff --git a/tests/refs/transactions.c b/tests/libgit2/refs/transactions.c similarity index 100% rename from tests/refs/transactions.c rename to tests/libgit2/refs/transactions.c diff --git a/tests/refs/unicode.c b/tests/libgit2/refs/unicode.c similarity index 100% rename from tests/refs/unicode.c rename to tests/libgit2/refs/unicode.c diff --git a/tests/refs/update.c b/tests/libgit2/refs/update.c similarity index 100% rename from tests/refs/update.c rename to tests/libgit2/refs/update.c diff --git a/tests/remote/create.c b/tests/libgit2/remote/create.c similarity index 100% rename from tests/remote/create.c rename to tests/libgit2/remote/create.c diff --git a/tests/remote/fetch.c b/tests/libgit2/remote/fetch.c similarity index 98% rename from tests/remote/fetch.c rename to tests/libgit2/remote/fetch.c index 3700462676f..85e99206fdc 100644 --- a/tests/remote/fetch.c +++ b/tests/libgit2/remote/fetch.c @@ -1,4 +1,4 @@ -#include "../clar_libgit2.h" +#include "clar_libgit2.h" #include "remote.h" #include "repository.h" @@ -82,9 +82,9 @@ static void do_time_travelling_fetch(git_oid *commit1id, git_oid *commit2id, cl_git_pass(git_treebuilder_write(&empty_tree_id, tb)); cl_git_pass(git_tree_lookup(&empty_tree, repo1, &empty_tree_id)); cl_git_pass(git_signature_default(&sig, repo1)); - cl_git_pass(git_commit_create(commit1id, repo1, REPO1_REFNAME, sig, + cl_git_pass(git_commit_create(commit1id, repo1, REPO1_REFNAME, sig, sig, NULL, "one", empty_tree, 0, NULL)); - cl_git_pass(git_commit_create_v(commit2id, repo1, REPO1_REFNAME, sig, + cl_git_pass(git_commit_create_v(commit2id, repo1, REPO1_REFNAME, sig, sig, NULL, "two", empty_tree, 1, commit1id)); git_tree_free(empty_tree); @@ -118,7 +118,7 @@ static void do_time_travelling_fetch(git_oid *commit1id, git_oid *commit2id, git_reference *ref; git_reference *ref2; cl_git_pass(git_reference_lookup(&ref, repo1, REPO1_REFNAME)); - cl_git_pass(git_reference_set_target(&ref2, ref, commit1id, + cl_git_pass(git_reference_set_target(&ref2, ref, commit1id, "rollback")); git_reference_free(ref); git_reference_free(ref2); diff --git a/tests/remote/httpproxy.c b/tests/libgit2/remote/httpproxy.c similarity index 100% rename from tests/remote/httpproxy.c rename to tests/libgit2/remote/httpproxy.c diff --git a/tests/remote/insteadof.c b/tests/libgit2/remote/insteadof.c similarity index 100% rename from tests/remote/insteadof.c rename to tests/libgit2/remote/insteadof.c diff --git a/tests/remote/list.c b/tests/libgit2/remote/list.c similarity index 100% rename from tests/remote/list.c rename to tests/libgit2/remote/list.c diff --git a/tests/repo/config.c b/tests/libgit2/repo/config.c similarity index 100% rename from tests/repo/config.c rename to tests/libgit2/repo/config.c diff --git a/tests/repo/discover.c b/tests/libgit2/repo/discover.c similarity index 100% rename from tests/repo/discover.c rename to tests/libgit2/repo/discover.c diff --git a/tests/repo/env.c b/tests/libgit2/repo/env.c similarity index 100% rename from tests/repo/env.c rename to tests/libgit2/repo/env.c diff --git a/tests/repo/extensions.c b/tests/libgit2/repo/extensions.c similarity index 100% rename from tests/repo/extensions.c rename to tests/libgit2/repo/extensions.c diff --git a/tests/repo/getters.c b/tests/libgit2/repo/getters.c similarity index 100% rename from tests/repo/getters.c rename to tests/libgit2/repo/getters.c diff --git a/tests/repo/hashfile.c b/tests/libgit2/repo/hashfile.c similarity index 100% rename from tests/repo/hashfile.c rename to tests/libgit2/repo/hashfile.c diff --git a/tests/repo/head.c b/tests/libgit2/repo/head.c similarity index 100% rename from tests/repo/head.c rename to tests/libgit2/repo/head.c diff --git a/tests/repo/headtree.c b/tests/libgit2/repo/headtree.c similarity index 100% rename from tests/repo/headtree.c rename to tests/libgit2/repo/headtree.c diff --git a/tests/repo/init.c b/tests/libgit2/repo/init.c similarity index 100% rename from tests/repo/init.c rename to tests/libgit2/repo/init.c diff --git a/tests/repo/message.c b/tests/libgit2/repo/message.c similarity index 100% rename from tests/repo/message.c rename to tests/libgit2/repo/message.c diff --git a/tests/repo/new.c b/tests/libgit2/repo/new.c similarity index 100% rename from tests/repo/new.c rename to tests/libgit2/repo/new.c diff --git a/tests/repo/open.c b/tests/libgit2/repo/open.c similarity index 100% rename from tests/repo/open.c rename to tests/libgit2/repo/open.c diff --git a/tests/repo/pathspec.c b/tests/libgit2/repo/pathspec.c similarity index 100% rename from tests/repo/pathspec.c rename to tests/libgit2/repo/pathspec.c diff --git a/tests/repo/repo_helpers.c b/tests/libgit2/repo/repo_helpers.c similarity index 100% rename from tests/repo/repo_helpers.c rename to tests/libgit2/repo/repo_helpers.c diff --git a/tests/repo/repo_helpers.h b/tests/libgit2/repo/repo_helpers.h similarity index 100% rename from tests/repo/repo_helpers.h rename to tests/libgit2/repo/repo_helpers.h diff --git a/tests/repo/reservedname.c b/tests/libgit2/repo/reservedname.c similarity index 100% rename from tests/repo/reservedname.c rename to tests/libgit2/repo/reservedname.c diff --git a/tests/repo/setters.c b/tests/libgit2/repo/setters.c similarity index 100% rename from tests/repo/setters.c rename to tests/libgit2/repo/setters.c diff --git a/tests/repo/shallow.c b/tests/libgit2/repo/shallow.c similarity index 100% rename from tests/repo/shallow.c rename to tests/libgit2/repo/shallow.c diff --git a/tests/repo/state.c b/tests/libgit2/repo/state.c similarity index 100% rename from tests/repo/state.c rename to tests/libgit2/repo/state.c diff --git a/tests/repo/template.c b/tests/libgit2/repo/template.c similarity index 100% rename from tests/repo/template.c rename to tests/libgit2/repo/template.c diff --git a/tests/reset/default.c b/tests/libgit2/reset/default.c similarity index 100% rename from tests/reset/default.c rename to tests/libgit2/reset/default.c diff --git a/tests/reset/hard.c b/tests/libgit2/reset/hard.c similarity index 100% rename from tests/reset/hard.c rename to tests/libgit2/reset/hard.c diff --git a/tests/reset/mixed.c b/tests/libgit2/reset/mixed.c similarity index 100% rename from tests/reset/mixed.c rename to tests/libgit2/reset/mixed.c diff --git a/tests/reset/reset_helpers.c b/tests/libgit2/reset/reset_helpers.c similarity index 100% rename from tests/reset/reset_helpers.c rename to tests/libgit2/reset/reset_helpers.c diff --git a/tests/reset/reset_helpers.h b/tests/libgit2/reset/reset_helpers.h similarity index 100% rename from tests/reset/reset_helpers.h rename to tests/libgit2/reset/reset_helpers.h diff --git a/tests/reset/soft.c b/tests/libgit2/reset/soft.c similarity index 100% rename from tests/reset/soft.c rename to tests/libgit2/reset/soft.c diff --git a/tests/revert/bare.c b/tests/libgit2/revert/bare.c similarity index 100% rename from tests/revert/bare.c rename to tests/libgit2/revert/bare.c diff --git a/tests/revert/rename.c b/tests/libgit2/revert/rename.c similarity index 100% rename from tests/revert/rename.c rename to tests/libgit2/revert/rename.c diff --git a/tests/revert/workdir.c b/tests/libgit2/revert/workdir.c similarity index 100% rename from tests/revert/workdir.c rename to tests/libgit2/revert/workdir.c diff --git a/tests/revwalk/basic.c b/tests/libgit2/revwalk/basic.c similarity index 100% rename from tests/revwalk/basic.c rename to tests/libgit2/revwalk/basic.c diff --git a/tests/revwalk/hidecb.c b/tests/libgit2/revwalk/hidecb.c similarity index 100% rename from tests/revwalk/hidecb.c rename to tests/libgit2/revwalk/hidecb.c diff --git a/tests/revwalk/mergebase.c b/tests/libgit2/revwalk/mergebase.c similarity index 100% rename from tests/revwalk/mergebase.c rename to tests/libgit2/revwalk/mergebase.c diff --git a/tests/revwalk/signatureparsing.c b/tests/libgit2/revwalk/signatureparsing.c similarity index 100% rename from tests/revwalk/signatureparsing.c rename to tests/libgit2/revwalk/signatureparsing.c diff --git a/tests/revwalk/simplify.c b/tests/libgit2/revwalk/simplify.c similarity index 100% rename from tests/revwalk/simplify.c rename to tests/libgit2/revwalk/simplify.c diff --git a/tests/stash/apply.c b/tests/libgit2/stash/apply.c similarity index 100% rename from tests/stash/apply.c rename to tests/libgit2/stash/apply.c diff --git a/tests/stash/drop.c b/tests/libgit2/stash/drop.c similarity index 100% rename from tests/stash/drop.c rename to tests/libgit2/stash/drop.c diff --git a/tests/stash/foreach.c b/tests/libgit2/stash/foreach.c similarity index 100% rename from tests/stash/foreach.c rename to tests/libgit2/stash/foreach.c diff --git a/tests/stash/save.c b/tests/libgit2/stash/save.c similarity index 100% rename from tests/stash/save.c rename to tests/libgit2/stash/save.c diff --git a/tests/stash/stash_helpers.c b/tests/libgit2/stash/stash_helpers.c similarity index 100% rename from tests/stash/stash_helpers.c rename to tests/libgit2/stash/stash_helpers.c diff --git a/tests/stash/stash_helpers.h b/tests/libgit2/stash/stash_helpers.h similarity index 100% rename from tests/stash/stash_helpers.h rename to tests/libgit2/stash/stash_helpers.h diff --git a/tests/stash/submodules.c b/tests/libgit2/stash/submodules.c similarity index 100% rename from tests/stash/submodules.c rename to tests/libgit2/stash/submodules.c diff --git a/tests/status/renames.c b/tests/libgit2/status/renames.c similarity index 100% rename from tests/status/renames.c rename to tests/libgit2/status/renames.c diff --git a/tests/status/single.c b/tests/libgit2/status/single.c similarity index 100% rename from tests/status/single.c rename to tests/libgit2/status/single.c diff --git a/tests/status/status_data.h b/tests/libgit2/status/status_data.h similarity index 100% rename from tests/status/status_data.h rename to tests/libgit2/status/status_data.h diff --git a/tests/status/status_helpers.c b/tests/libgit2/status/status_helpers.c similarity index 100% rename from tests/status/status_helpers.c rename to tests/libgit2/status/status_helpers.c diff --git a/tests/status/status_helpers.h b/tests/libgit2/status/status_helpers.h similarity index 100% rename from tests/status/status_helpers.h rename to tests/libgit2/status/status_helpers.h diff --git a/tests/status/submodules.c b/tests/libgit2/status/submodules.c similarity index 100% rename from tests/status/submodules.c rename to tests/libgit2/status/submodules.c diff --git a/tests/status/worktree.c b/tests/libgit2/status/worktree.c similarity index 100% rename from tests/status/worktree.c rename to tests/libgit2/status/worktree.c diff --git a/tests/status/worktree_init.c b/tests/libgit2/status/worktree_init.c similarity index 100% rename from tests/status/worktree_init.c rename to tests/libgit2/status/worktree_init.c diff --git a/tests/stream/deprecated.c b/tests/libgit2/stream/deprecated.c similarity index 100% rename from tests/stream/deprecated.c rename to tests/libgit2/stream/deprecated.c diff --git a/tests/stream/registration.c b/tests/libgit2/stream/registration.c similarity index 100% rename from tests/stream/registration.c rename to tests/libgit2/stream/registration.c diff --git a/tests/stress/diff.c b/tests/libgit2/stress/diff.c similarity index 100% rename from tests/stress/diff.c rename to tests/libgit2/stress/diff.c diff --git a/tests/submodule/add.c b/tests/libgit2/submodule/add.c similarity index 100% rename from tests/submodule/add.c rename to tests/libgit2/submodule/add.c diff --git a/tests/submodule/escape.c b/tests/libgit2/submodule/escape.c similarity index 100% rename from tests/submodule/escape.c rename to tests/libgit2/submodule/escape.c diff --git a/tests/submodule/init.c b/tests/libgit2/submodule/init.c similarity index 100% rename from tests/submodule/init.c rename to tests/libgit2/submodule/init.c diff --git a/tests/submodule/inject_option.c b/tests/libgit2/submodule/inject_option.c similarity index 100% rename from tests/submodule/inject_option.c rename to tests/libgit2/submodule/inject_option.c diff --git a/tests/submodule/lookup.c b/tests/libgit2/submodule/lookup.c similarity index 100% rename from tests/submodule/lookup.c rename to tests/libgit2/submodule/lookup.c diff --git a/tests/submodule/modify.c b/tests/libgit2/submodule/modify.c similarity index 100% rename from tests/submodule/modify.c rename to tests/libgit2/submodule/modify.c diff --git a/tests/submodule/nosubs.c b/tests/libgit2/submodule/nosubs.c similarity index 100% rename from tests/submodule/nosubs.c rename to tests/libgit2/submodule/nosubs.c diff --git a/tests/submodule/open.c b/tests/libgit2/submodule/open.c similarity index 100% rename from tests/submodule/open.c rename to tests/libgit2/submodule/open.c diff --git a/tests/submodule/repository_init.c b/tests/libgit2/submodule/repository_init.c similarity index 100% rename from tests/submodule/repository_init.c rename to tests/libgit2/submodule/repository_init.c diff --git a/tests/submodule/status.c b/tests/libgit2/submodule/status.c similarity index 100% rename from tests/submodule/status.c rename to tests/libgit2/submodule/status.c diff --git a/tests/submodule/submodule_helpers.c b/tests/libgit2/submodule/submodule_helpers.c similarity index 100% rename from tests/submodule/submodule_helpers.c rename to tests/libgit2/submodule/submodule_helpers.c diff --git a/tests/submodule/submodule_helpers.h b/tests/libgit2/submodule/submodule_helpers.h similarity index 100% rename from tests/submodule/submodule_helpers.h rename to tests/libgit2/submodule/submodule_helpers.h diff --git a/tests/submodule/update.c b/tests/libgit2/submodule/update.c similarity index 100% rename from tests/submodule/update.c rename to tests/libgit2/submodule/update.c diff --git a/tests/threads/atomic.c b/tests/libgit2/threads/atomic.c similarity index 100% rename from tests/threads/atomic.c rename to tests/libgit2/threads/atomic.c diff --git a/tests/threads/basic.c b/tests/libgit2/threads/basic.c similarity index 100% rename from tests/threads/basic.c rename to tests/libgit2/threads/basic.c diff --git a/tests/threads/diff.c b/tests/libgit2/threads/diff.c similarity index 100% rename from tests/threads/diff.c rename to tests/libgit2/threads/diff.c diff --git a/tests/threads/iterator.c b/tests/libgit2/threads/iterator.c similarity index 100% rename from tests/threads/iterator.c rename to tests/libgit2/threads/iterator.c diff --git a/tests/threads/refdb.c b/tests/libgit2/threads/refdb.c similarity index 100% rename from tests/threads/refdb.c rename to tests/libgit2/threads/refdb.c diff --git a/tests/threads/thread_helpers.c b/tests/libgit2/threads/thread_helpers.c similarity index 100% rename from tests/threads/thread_helpers.c rename to tests/libgit2/threads/thread_helpers.c diff --git a/tests/threads/thread_helpers.h b/tests/libgit2/threads/thread_helpers.h similarity index 100% rename from tests/threads/thread_helpers.h rename to tests/libgit2/threads/thread_helpers.h diff --git a/tests/threads/tlsdata.c b/tests/libgit2/threads/tlsdata.c similarity index 100% rename from tests/threads/tlsdata.c rename to tests/libgit2/threads/tlsdata.c diff --git a/tests/trace/trace.c b/tests/libgit2/trace/trace.c similarity index 100% rename from tests/trace/trace.c rename to tests/libgit2/trace/trace.c diff --git a/tests/trace/windows/stacktrace.c b/tests/libgit2/trace/windows/stacktrace.c similarity index 100% rename from tests/trace/windows/stacktrace.c rename to tests/libgit2/trace/windows/stacktrace.c diff --git a/tests/transport/register.c b/tests/libgit2/transport/register.c similarity index 100% rename from tests/transport/register.c rename to tests/libgit2/transport/register.c diff --git a/tests/transports/smart/packet.c b/tests/libgit2/transports/smart/packet.c similarity index 100% rename from tests/transports/smart/packet.c rename to tests/libgit2/transports/smart/packet.c diff --git a/tests/valgrind-supp-mac.txt b/tests/libgit2/valgrind-supp-mac.txt similarity index 100% rename from tests/valgrind-supp-mac.txt rename to tests/libgit2/valgrind-supp-mac.txt diff --git a/tests/win32/forbidden.c b/tests/libgit2/win32/forbidden.c similarity index 100% rename from tests/win32/forbidden.c rename to tests/libgit2/win32/forbidden.c diff --git a/tests/win32/longpath.c b/tests/libgit2/win32/longpath.c similarity index 100% rename from tests/win32/longpath.c rename to tests/libgit2/win32/longpath.c diff --git a/tests/win32/systemdir.c b/tests/libgit2/win32/systemdir.c similarity index 100% rename from tests/win32/systemdir.c rename to tests/libgit2/win32/systemdir.c diff --git a/tests/worktree/bare.c b/tests/libgit2/worktree/bare.c similarity index 100% rename from tests/worktree/bare.c rename to tests/libgit2/worktree/bare.c diff --git a/tests/worktree/config.c b/tests/libgit2/worktree/config.c similarity index 100% rename from tests/worktree/config.c rename to tests/libgit2/worktree/config.c diff --git a/tests/worktree/merge.c b/tests/libgit2/worktree/merge.c similarity index 100% rename from tests/worktree/merge.c rename to tests/libgit2/worktree/merge.c diff --git a/tests/worktree/open.c b/tests/libgit2/worktree/open.c similarity index 100% rename from tests/worktree/open.c rename to tests/libgit2/worktree/open.c diff --git a/tests/worktree/reflog.c b/tests/libgit2/worktree/reflog.c similarity index 100% rename from tests/worktree/reflog.c rename to tests/libgit2/worktree/reflog.c diff --git a/tests/worktree/refs.c b/tests/libgit2/worktree/refs.c similarity index 100% rename from tests/worktree/refs.c rename to tests/libgit2/worktree/refs.c diff --git a/tests/worktree/repository.c b/tests/libgit2/worktree/repository.c similarity index 100% rename from tests/worktree/repository.c rename to tests/libgit2/worktree/repository.c diff --git a/tests/worktree/submodule.c b/tests/libgit2/worktree/submodule.c similarity index 100% rename from tests/worktree/submodule.c rename to tests/libgit2/worktree/submodule.c diff --git a/tests/worktree/worktree.c b/tests/libgit2/worktree/worktree.c similarity index 100% rename from tests/worktree/worktree.c rename to tests/libgit2/worktree/worktree.c diff --git a/tests/worktree/worktree_helpers.c b/tests/libgit2/worktree/worktree_helpers.c similarity index 100% rename from tests/worktree/worktree_helpers.c rename to tests/libgit2/worktree/worktree_helpers.c diff --git a/tests/worktree/worktree_helpers.h b/tests/libgit2/worktree/worktree_helpers.h similarity index 100% rename from tests/worktree/worktree_helpers.h rename to tests/libgit2/worktree/worktree_helpers.h diff --git a/tests/path/dotgit.c b/tests/path/dotgit.c deleted file mode 100644 index 855145f420b..00000000000 --- a/tests/path/dotgit.c +++ /dev/null @@ -1,206 +0,0 @@ -#include "clar_libgit2.h" - -#include "path.h" - -static char *gitmodules_altnames[] = { - ".gitmodules", - - /* - * Equivalent to the ".git\u200cmodules" string from git but hard-coded - * as a UTF-8 sequence - */ - ".git\xe2\x80\x8cmodules", - - ".Gitmodules", - ".gitmoduleS", - - ".gitmodules ", - ".gitmodules.", - ".gitmodules ", - ".gitmodules. ", - ".gitmodules .", - ".gitmodules..", - ".gitmodules ", - ".gitmodules. ", - ".gitmodules . ", - ".gitmodules .", - - ".Gitmodules ", - ".Gitmodules.", - ".Gitmodules ", - ".Gitmodules. ", - ".Gitmodules .", - ".Gitmodules..", - ".Gitmodules ", - ".Gitmodules. ", - ".Gitmodules . ", - ".Gitmodules .", - - "GITMOD~1", - "gitmod~1", - "GITMOD~2", - "gitmod~3", - "GITMOD~4", - - "GITMOD~1 ", - "gitmod~2.", - "GITMOD~3 ", - "gitmod~4. ", - "GITMOD~1 .", - "gitmod~2 ", - "GITMOD~3. ", - "gitmod~4 . ", - - "GI7EBA~1", - "gi7eba~9", - - "GI7EB~10", - "GI7EB~11", - "GI7EB~99", - "GI7EB~10", - "GI7E~100", - "GI7E~101", - "GI7E~999", - "~1000000", - "~9999999", -}; - -static char *gitmodules_not_altnames[] = { - ".gitmodules x", - ".gitmodules .x", - - " .gitmodules", - - "..gitmodules", - - "gitmodules", - - ".gitmodule", - - ".gitmodules x ", - ".gitmodules .x", - - "GI7EBA~", - "GI7EBA~0", - "GI7EBA~~1", - "GI7EBA~X", - "Gx7EBA~1", - "GI7EBX~1", - - "GI7EB~1", - "GI7EB~01", - "GI7EB~1", -}; - -void test_path_dotgit__dotgit_modules(void) -{ - size_t i; - - cl_assert_equal_i(1, git_path_is_gitfile(".gitmodules", strlen(".gitmodules"), GIT_PATH_GITFILE_GITMODULES, GIT_PATH_FS_GENERIC)); - cl_assert_equal_i(1, git_path_is_gitfile(".git\xe2\x80\x8cmodules", strlen(".git\xe2\x80\x8cmodules"), GIT_PATH_GITFILE_GITMODULES, GIT_PATH_FS_GENERIC)); - - for (i = 0; i < ARRAY_SIZE(gitmodules_altnames); i++) { - const char *name = gitmodules_altnames[i]; - if (!git_path_is_gitfile(name, strlen(name), GIT_PATH_GITFILE_GITMODULES, GIT_PATH_FS_GENERIC)) - cl_fail(name); - } - - for (i = 0; i < ARRAY_SIZE(gitmodules_not_altnames); i++) { - const char *name = gitmodules_not_altnames[i]; - if (git_path_is_gitfile(name, strlen(name), GIT_PATH_GITFILE_GITMODULES, GIT_PATH_FS_GENERIC)) - cl_fail(name); - } -} - -void test_path_dotgit__dotgit_modules_symlink(void) -{ - cl_assert_equal_b(true, git_path_is_valid(NULL, ".gitmodules", 0, GIT_PATH_REJECT_DOT_GIT_HFS|GIT_PATH_REJECT_DOT_GIT_NTFS)); - cl_assert_equal_b(false, git_path_is_valid(NULL, ".gitmodules", S_IFLNK, GIT_PATH_REJECT_DOT_GIT_HFS)); - cl_assert_equal_b(false, git_path_is_valid(NULL, ".gitmodules", S_IFLNK, GIT_PATH_REJECT_DOT_GIT_NTFS)); - cl_assert_equal_b(false, git_path_is_valid(NULL, ".gitmodules . .::$DATA", S_IFLNK, GIT_PATH_REJECT_DOT_GIT_NTFS)); -} - -void test_path_dotgit__git_fs_path_is_file(void) -{ - cl_git_fail(git_path_is_gitfile("blob", 4, -1, GIT_PATH_FS_HFS)); - cl_git_pass(git_path_is_gitfile("blob", 4, GIT_PATH_GITFILE_GITIGNORE, GIT_PATH_FS_HFS)); - cl_git_pass(git_path_is_gitfile("blob", 4, GIT_PATH_GITFILE_GITMODULES, GIT_PATH_FS_HFS)); - cl_git_pass(git_path_is_gitfile("blob", 4, GIT_PATH_GITFILE_GITATTRIBUTES, GIT_PATH_FS_HFS)); - cl_git_fail(git_path_is_gitfile("blob", 4, 3, GIT_PATH_FS_HFS)); -} - -void test_path_dotgit__isvalid_dot_git(void) -{ - cl_assert_equal_b(true, git_path_is_valid(NULL, ".git", 0, 0)); - cl_assert_equal_b(true, git_path_is_valid(NULL, ".git/foo", 0, 0)); - cl_assert_equal_b(true, git_path_is_valid(NULL, "foo/.git", 0, 0)); - cl_assert_equal_b(true, git_path_is_valid(NULL, "foo/.git/bar", 0, 0)); - cl_assert_equal_b(true, git_path_is_valid(NULL, "foo/.GIT/bar", 0, 0)); - cl_assert_equal_b(true, git_path_is_valid(NULL, "foo/bar/.Git", 0, 0)); - - cl_assert_equal_b(false, git_path_is_valid(NULL, ".git", 0, GIT_PATH_REJECT_DOT_GIT_LITERAL)); - cl_assert_equal_b(false, git_path_is_valid(NULL, ".git/foo", 0, GIT_PATH_REJECT_DOT_GIT_LITERAL)); - cl_assert_equal_b(false, git_path_is_valid(NULL, "foo/.git", 0, GIT_PATH_REJECT_DOT_GIT_LITERAL)); - cl_assert_equal_b(false, git_path_is_valid(NULL, "foo/.git/bar", 0, GIT_PATH_REJECT_DOT_GIT_LITERAL)); - cl_assert_equal_b(false, git_path_is_valid(NULL, "foo/.GIT/bar", 0, GIT_PATH_REJECT_DOT_GIT_LITERAL)); - cl_assert_equal_b(false, git_path_is_valid(NULL, "foo/bar/.Git", 0, GIT_PATH_REJECT_DOT_GIT_LITERAL)); - - cl_assert_equal_b(true, git_path_is_valid(NULL, "!git", 0, 0)); - cl_assert_equal_b(true, git_path_is_valid(NULL, "foo/!git", 0, 0)); - cl_assert_equal_b(true, git_path_is_valid(NULL, "!git/bar", 0, 0)); - cl_assert_equal_b(true, git_path_is_valid(NULL, ".tig", 0, 0)); - cl_assert_equal_b(true, git_path_is_valid(NULL, "foo/.tig", 0, 0)); - cl_assert_equal_b(true, git_path_is_valid(NULL, ".tig/bar", 0, 0)); -} - -void test_path_dotgit__isvalid_dotgit_ntfs(void) -{ - cl_assert_equal_b(true, git_path_is_valid(NULL, ".git", 0, 0)); - cl_assert_equal_b(true, git_path_is_valid(NULL, ".git ", 0, 0)); - cl_assert_equal_b(true, git_path_is_valid(NULL, ".git.", 0, 0)); - cl_assert_equal_b(true, git_path_is_valid(NULL, ".git.. .", 0, 0)); - - cl_assert_equal_b(true, git_path_is_valid(NULL, "git~1", 0, 0)); - cl_assert_equal_b(true, git_path_is_valid(NULL, "git~1 ", 0, 0)); - cl_assert_equal_b(true, git_path_is_valid(NULL, "git~1.", 0, 0)); - cl_assert_equal_b(true, git_path_is_valid(NULL, "git~1.. .", 0, 0)); - - cl_assert_equal_b(false, git_path_is_valid(NULL, ".git", 0, GIT_PATH_REJECT_DOT_GIT_NTFS)); - cl_assert_equal_b(false, git_path_is_valid(NULL, ".git ", 0, GIT_PATH_REJECT_DOT_GIT_NTFS)); - cl_assert_equal_b(false, git_path_is_valid(NULL, ".git.", 0, GIT_PATH_REJECT_DOT_GIT_NTFS)); - cl_assert_equal_b(false, git_path_is_valid(NULL, ".git.. .", 0, GIT_PATH_REJECT_DOT_GIT_NTFS)); - - cl_assert_equal_b(false, git_path_is_valid(NULL, "git~1", 0, GIT_PATH_REJECT_DOT_GIT_NTFS)); - cl_assert_equal_b(false, git_path_is_valid(NULL, "git~1 ", 0, GIT_PATH_REJECT_DOT_GIT_NTFS)); - cl_assert_equal_b(false, git_path_is_valid(NULL, "git~1.", 0, GIT_PATH_REJECT_DOT_GIT_NTFS)); - cl_assert_equal_b(false, git_path_is_valid(NULL, "git~1.. .", 0, GIT_PATH_REJECT_DOT_GIT_NTFS)); -} - -void test_path_dotgit__isvalid_dotgit_with_hfs_ignorables(void) -{ - cl_assert_equal_b(false, git_path_is_valid(NULL, ".git", 0, GIT_PATH_REJECT_DOT_GIT_HFS)); - cl_assert_equal_b(false, git_path_is_valid(NULL, ".git\xe2\x80\x8c", 0, GIT_PATH_REJECT_DOT_GIT_HFS)); - cl_assert_equal_b(false, git_path_is_valid(NULL, ".gi\xe2\x80\x8dT", 0, GIT_PATH_REJECT_DOT_GIT_HFS)); - cl_assert_equal_b(false, git_path_is_valid(NULL, ".g\xe2\x80\x8eIt", 0, GIT_PATH_REJECT_DOT_GIT_HFS)); - cl_assert_equal_b(false, git_path_is_valid(NULL, ".\xe2\x80\x8fgIt", 0, GIT_PATH_REJECT_DOT_GIT_HFS)); - cl_assert_equal_b(false, git_path_is_valid(NULL, "\xe2\x80\xaa.gIt", 0, GIT_PATH_REJECT_DOT_GIT_HFS)); - - cl_assert_equal_b(false, git_path_is_valid(NULL, "\xe2\x80\xab.\xe2\x80\xacG\xe2\x80\xadI\xe2\x80\xaet", 0, GIT_PATH_REJECT_DOT_GIT_HFS)); - cl_assert_equal_b(false, git_path_is_valid(NULL, "\xe2\x81\xab.\xe2\x80\xaaG\xe2\x81\xabI\xe2\x80\xact", 0, GIT_PATH_REJECT_DOT_GIT_HFS)); - cl_assert_equal_b(false, git_path_is_valid(NULL, "\xe2\x81\xad.\xe2\x80\xaeG\xef\xbb\xbfIT", 0, GIT_PATH_REJECT_DOT_GIT_HFS)); - - cl_assert_equal_b(true, git_path_is_valid(NULL, ".", 0, GIT_PATH_REJECT_DOT_GIT_HFS)); - cl_assert_equal_b(true, git_path_is_valid(NULL, ".g", 0, GIT_PATH_REJECT_DOT_GIT_HFS)); - cl_assert_equal_b(true, git_path_is_valid(NULL, ".gi", 0, GIT_PATH_REJECT_DOT_GIT_HFS)); - cl_assert_equal_b(true, git_path_is_valid(NULL, " .git", 0, GIT_PATH_REJECT_DOT_GIT_HFS)); - cl_assert_equal_b(true, git_path_is_valid(NULL, "..git\xe2\x80\x8c", 0, GIT_PATH_REJECT_DOT_GIT_HFS)); - cl_assert_equal_b(true, git_path_is_valid(NULL, ".gi\xe2\x80\x8dT.", 0, GIT_PATH_REJECT_DOT_GIT_HFS)); - cl_assert_equal_b(true, git_path_is_valid(NULL, ".g\xe2\x80It", 0, GIT_PATH_REJECT_DOT_GIT_HFS)); - cl_assert_equal_b(true, git_path_is_valid(NULL, ".\xe2gIt", 0, GIT_PATH_REJECT_DOT_GIT_HFS)); - cl_assert_equal_b(true, git_path_is_valid(NULL, "\xe2\x80\xaa.gi", 0, GIT_PATH_REJECT_DOT_GIT_HFS)); - cl_assert_equal_b(true, git_path_is_valid(NULL, ".gi\x80\x8dT", 0, GIT_PATH_REJECT_DOT_GIT_HFS)); - cl_assert_equal_b(true, git_path_is_valid(NULL, ".gi\x8dT", 0, GIT_PATH_REJECT_DOT_GIT_HFS)); - cl_assert_equal_b(true, git_path_is_valid(NULL, ".g\xe2i\x80T\x8e", 0, GIT_PATH_REJECT_DOT_GIT_HFS)); - cl_assert_equal_b(true, git_path_is_valid(NULL, ".git\xe2\x80\xbf", 0, GIT_PATH_REJECT_DOT_GIT_HFS)); - cl_assert_equal_b(true, git_path_is_valid(NULL, ".git\xe2\xab\x81", 0, GIT_PATH_REJECT_DOT_GIT_HFS)); -} diff --git a/tests/util/CMakeLists.txt b/tests/util/CMakeLists.txt new file mode 100644 index 00000000000..232590ffdfc --- /dev/null +++ b/tests/util/CMakeLists.txt @@ -0,0 +1,68 @@ +# util: the unit tests for libgit2's utility library + +set(Python_ADDITIONAL_VERSIONS 3 2.7) +find_package(PythonInterp) + +if(NOT PYTHONINTERP_FOUND) + message(FATAL_ERROR "Could not find a python interpeter, which is needed to build the tests. " + "Make sure python is available, or pass -DBUILD_TESTS=OFF to skip building the tests") +ENDIF() + +set(CLAR_PATH "${libgit2_SOURCE_DIR}/tests/clar") +set(CLAR_FIXTURES "${libgit2_SOURCE_DIR}/tests/resources/") +set(TEST_PATH "${CMAKE_CURRENT_SOURCE_DIR}") +add_definitions(-DCLAR_FIXTURE_PATH=\"${CLAR_FIXTURES}\") +add_definitions(-DCLAR_TMPDIR=\"libgit2_tests\") +add_definitions(-DCLAR_WIN32_LONGPATHS) +add_definitions(-D_FILE_OFFSET_BITS=64) + +# Ensure that we do not use deprecated functions internally +add_definitions(-DGIT_DEPRECATE_HARD) + +set(TEST_INCLUDES "${CLAR_PATH}" "${TEST_PATH}" "${CMAKE_CURRENT_BINARY_DIR}") +file(GLOB_RECURSE SRC_TEST ${TEST_PATH}/*.c ${TEST_PATH}/*.h ${TEST_PATH}/*/*.c ${TEST_PATH}/*/*.h) +file(GLOB_RECURSE SRC_CLAR ${CLAR_PATH}/*.c ${CLAR_PATH}/*.h) + +if(MSVC_IDE) + list(APPEND SRC_TEST "precompiled.c") +endif() + +add_custom_command( + OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/clar.suite ${CMAKE_CURRENT_BINARY_DIR}/clar_suite.h + COMMAND ${PYTHON_EXECUTABLE} ${CLAR_PATH}/generate.py -o "${CMAKE_CURRENT_BINARY_DIR}" -f . + DEPENDS ${SRC_TEST} + WORKING_DIRECTORY ${TEST_PATH}) + +set_source_files_properties( + ${CLAR_PATH}/clar.c + PROPERTIES OBJECT_DEPENDS ${CMAKE_CURRENT_BINARY_DIR}/clar.suite) + +add_executable(util_tests ${SRC_CLAR} ${SRC_TEST} ${LIBGIT2_OBJECTS}) + +set_target_properties(util_tests PROPERTIES C_STANDARD 90) +set_target_properties(util_tests PROPERTIES RUNTIME_OUTPUT_DIRECTORY ${libgit2_BINARY_DIR}) + +target_include_directories(util_tests PRIVATE ${TEST_INCLUDES} ${LIBGIT2_INCLUDES} ${LIBGIT2_DEPENDENCY_INCLUDES}) +target_include_directories(util_tests SYSTEM PRIVATE ${LIBGIT2_SYSTEM_INCLUDES}) +target_link_libraries(util_tests ${LIBGIT2_SYSTEM_LIBS}) + +ide_split_sources(util_tests) + +# +# Old versions of gcc require us to declare our test functions; don't do +# this on newer compilers to avoid unnecessary recompilation. +# +if(CMAKE_COMPILER_IS_GNUCC AND CMAKE_CXX_COMPILER_VERSION VERSION_LESS 6.0) + target_compile_options(util_tests PRIVATE -include "clar_suite.h") +endif() + +if(MSVC_IDE) + # Precompiled headers + set_target_properties(util_tests PROPERTIES COMPILE_FLAGS "/Yuprecompiled.h /FIprecompiled.h") + set_source_files_properties("precompiled.c" COMPILE_FLAGS "/Ycprecompiled.h") +endif() + +enable_testing() + +include(AddClarTest) +add_clar_test(util_tests util -v) diff --git a/tests/core/array.c b/tests/util/array.c similarity index 97% rename from tests/core/array.c rename to tests/util/array.c index 8e626a50613..39fbc811dc4 100644 --- a/tests/core/array.c +++ b/tests/util/array.c @@ -15,7 +15,7 @@ static int int_lookup(const void *k, const void *a) git_array_search(&p, integers, int_lookup, &key)); \ cl_assert_equal_i((n), p); -void test_core_array__bsearch2(void) +void test_array__bsearch2(void) { git_array_t(int) integers = GIT_ARRAY_INIT; int *i, key; diff --git a/tests/core/assert.c b/tests/util/assert.c similarity index 92% rename from tests/core/assert.c rename to tests/util/assert.c index ef75624b9f7..26c42978754 100644 --- a/tests/core/assert.c +++ b/tests/util/assert.c @@ -36,7 +36,7 @@ static const char *bad_returns_string(void) return hello_world; } -void test_core_assert__argument(void) +void test_assert__argument(void) { cl_git_fail(dummy_fn(NULL)); cl_assert(git_error_last()); @@ -51,7 +51,7 @@ void test_core_assert__argument(void) cl_git_pass(dummy_fn("foo")); } -void test_core_assert__argument_with_non_int_return_type(void) +void test_assert__argument_with_non_int_return_type(void) { const char *foo = "foo"; @@ -66,7 +66,7 @@ void test_core_assert__argument_with_non_int_return_type(void) cl_assert_equal_p(foo, fn_returns_string(foo)); } -void test_core_assert__argument_with_void_return_type(void) +void test_assert__argument_with_void_return_type(void) { const char *foo = "foo"; @@ -80,7 +80,7 @@ void test_core_assert__argument_with_void_return_type(void) cl_assert_equal_p(NULL, git_error_last()); } -void test_core_assert__internal(void) +void test_assert__internal(void) { cl_git_fail(bad_math()); cl_assert(git_error_last()); diff --git a/tests/core/bitvec.c b/tests/util/bitvec.c similarity index 97% rename from tests/core/bitvec.c rename to tests/util/bitvec.c index 48d7b99f093..f7845895bab 100644 --- a/tests/core/bitvec.c +++ b/tests/util/bitvec.c @@ -35,7 +35,7 @@ static void check_some_bits(git_bitvec *bv, size_t length) cl_assert_equal_b(i % 3 == 0 || i % 7 == 0, git_bitvec_get(bv, i)); } -void test_core_bitvec__0(void) +void test_bitvec__0(void) { git_bitvec bv; diff --git a/tests/core/copy.c b/tests/util/copy.c similarity index 97% rename from tests/core/copy.c rename to tests/util/copy.c index 6d22b503d46..9b9f6bafc39 100644 --- a/tests/core/copy.c +++ b/tests/util/copy.c @@ -2,7 +2,7 @@ #include "futils.h" #include "posix.h" -void test_core_copy__file(void) +void test_copy__file(void) { struct stat st; const char *content = "This is some stuff to copy\n"; @@ -19,7 +19,7 @@ void test_core_copy__file(void) cl_git_pass(p_unlink("copy_me")); } -void test_core_copy__file_in_dir(void) +void test_copy__file_in_dir(void) { struct stat st; const char *content = "This is some other stuff to copy\n"; @@ -56,7 +56,7 @@ static void assert_hard_link(const char *path) } #endif -void test_core_copy__tree(void) +void test_copy__tree(void) { struct stat st; const char *content = "File content\n"; diff --git a/tests/util/crlf.h b/tests/util/crlf.h new file mode 100644 index 00000000000..786edfc96fa --- /dev/null +++ b/tests/util/crlf.h @@ -0,0 +1,30 @@ +#ifndef INCLUDE_filter_crlf_h__ +#define INCLUDE_filter_crlf_h__ + +/* + * file content for files in the resources/crlf repository + */ + +#define UTF8_BOM "\xEF\xBB\xBF" + +#define ALL_CRLF_TEXT_RAW "crlf\r\ncrlf\r\ncrlf\r\ncrlf\r\n" +#define ALL_LF_TEXT_RAW "lf\nlf\nlf\nlf\nlf\n" +#define MORE_CRLF_TEXT_RAW "crlf\r\ncrlf\r\nlf\ncrlf\r\ncrlf\r\n" +#define MORE_LF_TEXT_RAW "lf\nlf\ncrlf\r\nlf\nlf\n" + +#define ALL_CRLF_TEXT_AS_CRLF ALL_CRLF_TEXT_RAW +#define ALL_LF_TEXT_AS_CRLF "lf\r\nlf\r\nlf\r\nlf\r\nlf\r\n" +#define MORE_CRLF_TEXT_AS_CRLF "crlf\r\ncrlf\r\nlf\r\ncrlf\r\ncrlf\r\n" +#define MORE_LF_TEXT_AS_CRLF "lf\r\nlf\r\ncrlf\r\nlf\r\nlf\r\n" + +#define ALL_CRLF_TEXT_AS_LF "crlf\ncrlf\ncrlf\ncrlf\n" +#define ALL_LF_TEXT_AS_LF ALL_LF_TEXT_RAW +#define MORE_CRLF_TEXT_AS_LF "crlf\ncrlf\nlf\ncrlf\ncrlf\n" +#define MORE_LF_TEXT_AS_LF "lf\nlf\ncrlf\nlf\nlf\n" + +#define FEW_UTF8_CRLF_RAW "\xe2\x9a\xbdThe rest is ASCII01.\r\nThe rest is ASCII02.\r\nThe rest is ASCII03.\r\nThe rest is ASCII04.\r\nThe rest is ASCII05.\r\nThe rest is ASCII06.\r\nThe rest is ASCII07.\r\nThe rest is ASCII08.\r\nThe rest is ASCII09.\r\nThe rest is ASCII10.\r\nThe rest is ASCII11.\r\nThe rest is ASCII12.\r\nThe rest is ASCII13.\r\nThe rest is ASCII14.\r\nThe rest is ASCII15.\r\nThe rest is ASCII16.\r\nThe rest is ASCII17.\r\nThe rest is ASCII18.\r\nThe rest is ASCII19.\r\nThe rest is ASCII20.\r\nThe rest is ASCII21.\r\nThe rest is ASCII22.\r\n" +#define FEW_UTF8_LF_RAW "\xe2\x9a\xbdThe rest is ASCII01.\nThe rest is ASCII02.\nThe rest is ASCII03.\nThe rest is ASCII04.\nThe rest is ASCII05.\nThe rest is ASCII06.\nThe rest is ASCII07.\nThe rest is ASCII08.\nThe rest is ASCII09.\nThe rest is ASCII10.\nThe rest is ASCII11.\nThe rest is ASCII12.\nThe rest is ASCII13.\nThe rest is ASCII14.\nThe rest is ASCII15.\nThe rest is ASCII16.\nThe rest is ASCII17.\nThe rest is ASCII18.\nThe rest is ASCII19.\nThe rest is ASCII20.\nThe rest is ASCII21.\nThe rest is ASCII22.\n" +#define MANY_UTF8_CRLF_RAW "Lets sing!\r\n\xe2\x99\xab\xe2\x99\xaa\xe2\x99\xac\xe2\x99\xa9\r\nEat food\r\n\xf0\x9f\x8d\x85\xf0\x9f\x8d\x95\r\n" +#define MANY_UTF8_LF_RAW "Lets sing!\n\xe2\x99\xab\xe2\x99\xaa\xe2\x99\xac\xe2\x99\xa9\nEat food\n\xf0\x9f\x8d\x85\xf0\x9f\x8d\x95\n" + +#endif diff --git a/tests/core/dirent.c b/tests/util/dirent.c similarity index 92% rename from tests/core/dirent.c rename to tests/util/dirent.c index 2419ec7ab92..5840c67e046 100644 --- a/tests/core/dirent.c +++ b/tests/util/dirent.c @@ -108,7 +108,7 @@ static walk_data dot = { }; /* make sure that the '.' folder is not traversed */ -void test_core_dirent__dont_traverse_dot(void) +void test_dirent__dont_traverse_dot(void) { cl_set_cleanup(&dirent_cleanup__cb, &dot); setup(&dot); @@ -132,7 +132,7 @@ static walk_data sub = { }; /* traverse a subfolder */ -void test_core_dirent__traverse_subfolder(void) +void test_dirent__traverse_subfolder(void) { cl_set_cleanup(&dirent_cleanup__cb, &sub); setup(&sub); @@ -150,7 +150,7 @@ static walk_data sub_slash = { }; /* traverse a slash-terminated subfolder */ -void test_core_dirent__traverse_slash_terminated_folder(void) +void test_dirent__traverse_slash_terminated_folder(void) { cl_set_cleanup(&dirent_cleanup__cb, &sub_slash); setup(&sub_slash); @@ -171,7 +171,7 @@ static walk_data empty = { }; /* make sure that empty folders are not traversed */ -void test_core_dirent__dont_traverse_empty_folders(void) +void test_dirent__dont_traverse_empty_folders(void) { cl_set_cleanup(&dirent_cleanup__cb, &empty); setup(&empty); @@ -199,7 +199,7 @@ static walk_data odd = { }; /* make sure that strange looking filenames ('..c') are traversed */ -void test_core_dirent__traverse_weird_filenames(void) +void test_dirent__traverse_weird_filenames(void) { cl_set_cleanup(&dirent_cleanup__cb, &odd); setup(&odd); @@ -210,7 +210,7 @@ void test_core_dirent__traverse_weird_filenames(void) } /* test filename length limits */ -void test_core_dirent__length_limits(void) +void test_dirent__length_limits(void) { char *big_filename = (char *)git__malloc(FILENAME_MAX + 1); memset(big_filename, 'a', FILENAME_MAX + 1); @@ -221,7 +221,7 @@ void test_core_dirent__length_limits(void) git__free(big_filename); } -void test_core_dirent__empty_dir(void) +void test_dirent__empty_dir(void) { cl_must_pass(p_mkdir("empty_dir", 0777)); cl_assert(git_fs_path_is_empty_dir("empty_dir")); @@ -256,7 +256,7 @@ static void handle_next(git_fs_path_diriter *diriter, walk_data *walk) } /* test directory iterator */ -void test_core_dirent__diriter_with_fullname(void) +void test_dirent__diriter_with_fullname(void) { git_fs_path_diriter diriter = GIT_FS_PATH_DIRITER_INIT; int error; @@ -276,7 +276,7 @@ void test_core_dirent__diriter_with_fullname(void) check_counts(&sub); } -void test_core_dirent__diriter_at_directory_root(void) +void test_dirent__diriter_at_directory_root(void) { git_fs_path_diriter diriter = GIT_FS_PATH_DIRITER_INIT; const char *sandbox_path, *path; diff --git a/tests/core/encoding.c b/tests/util/encoding.c similarity index 93% rename from tests/core/encoding.c rename to tests/util/encoding.c index 6cec24679dc..a25a3344393 100644 --- a/tests/core/encoding.c +++ b/tests/util/encoding.c @@ -1,7 +1,7 @@ #include "clar_libgit2.h" #include "varint.h" -void test_core_encoding__decode(void) +void test_encoding__decode(void) { const unsigned char *buf = (unsigned char *)"AB"; size_t size; @@ -23,7 +23,7 @@ void test_core_encoding__decode(void) } -void test_core_encoding__encode(void) +void test_encoding__encode(void) { unsigned char buf[100]; cl_assert(git_encode_varint(buf, 100, 65) == 1); diff --git a/tests/core/errors.c b/tests/util/errors.c similarity index 93% rename from tests/core/errors.c rename to tests/util/errors.c index 386ecdc5f4d..78654a753ae 100644 --- a/tests/core/errors.c +++ b/tests/util/errors.c @@ -1,6 +1,6 @@ #include "clar_libgit2.h" -void test_core_errors__public_api(void) +void test_errors__public_api(void) { char *str_in_error; @@ -30,7 +30,7 @@ void test_core_errors__public_api(void) #include "util.h" #include "posix.h" -void test_core_errors__new_school(void) +void test_errors__new_school(void) { char *str_in_error; @@ -86,7 +86,7 @@ void test_core_errors__new_school(void) git_error_clear(); } -void test_core_errors__restore(void) +void test_errors__restore(void) { git_error_state err_state = {0}; @@ -110,7 +110,7 @@ void test_core_errors__restore(void) cl_assert_equal_s("Foo: bar", git_error_last()->message); } -void test_core_errors__free_state(void) +void test_errors__free_state(void) { git_error_state err_state = {0}; @@ -131,7 +131,7 @@ void test_core_errors__free_state(void) cl_assert(git_error_last() == NULL); } -void test_core_errors__restore_oom(void) +void test_errors__restore_oom(void) { git_error_state err_state = {0}; const git_error *oom_error = NULL; @@ -163,7 +163,7 @@ static int test_arraysize_multiply(size_t nelem, size_t size) return 0; } -void test_core_errors__integer_overflow_alloc_multiply(void) +void test_errors__integer_overflow_alloc_multiply(void) { cl_git_pass(test_arraysize_multiply(10, 10)); cl_git_pass(test_arraysize_multiply(1000, 1000)); @@ -185,7 +185,7 @@ static int test_arraysize_add(size_t one, size_t two) return 0; } -void test_core_errors__integer_overflow_alloc_add(void) +void test_errors__integer_overflow_alloc_add(void) { cl_git_pass(test_arraysize_add(10, 10)); cl_git_pass(test_arraysize_add(1000, 1000)); @@ -198,7 +198,7 @@ void test_core_errors__integer_overflow_alloc_add(void) cl_assert_equal_s("Out of memory", git_error_last()->message); } -void test_core_errors__integer_overflow_sets_oom(void) +void test_errors__integer_overflow_sets_oom(void) { size_t out; diff --git a/tests/core/filebuf.c b/tests/util/filebuf.c similarity index 93% rename from tests/core/filebuf.c rename to tests/util/filebuf.c index 6f40c24569f..29b821144da 100644 --- a/tests/core/filebuf.c +++ b/tests/util/filebuf.c @@ -2,7 +2,7 @@ #include "filebuf.h" /* make sure git_filebuf_open doesn't delete an existing lock */ -void test_core_filebuf__0(void) +void test_filebuf__0(void) { git_filebuf file = GIT_FILEBUF_INIT; int fd; @@ -21,7 +21,7 @@ void test_core_filebuf__0(void) /* make sure GIT_FILEBUF_APPEND works as expected */ -void test_core_filebuf__1(void) +void test_filebuf__1(void) { git_filebuf file = GIT_FILEBUF_INIT; char test[] = "test"; @@ -39,7 +39,7 @@ void test_core_filebuf__1(void) /* make sure git_filebuf_write writes large buffer correctly */ -void test_core_filebuf__2(void) +void test_filebuf__2(void) { git_filebuf file = GIT_FILEBUF_INIT; char test[] = "test"; @@ -57,7 +57,7 @@ void test_core_filebuf__2(void) } /* make sure git_filebuf_cleanup clears the buffer */ -void test_core_filebuf__4(void) +void test_filebuf__4(void) { git_filebuf file = GIT_FILEBUF_INIT; char test[] = "test"; @@ -73,7 +73,7 @@ void test_core_filebuf__4(void) /* make sure git_filebuf_commit clears the buffer */ -void test_core_filebuf__5(void) +void test_filebuf__5(void) { git_filebuf file = GIT_FILEBUF_INIT; char test[] = "test"; @@ -93,7 +93,7 @@ void test_core_filebuf__5(void) /* make sure git_filebuf_commit takes umask into account */ -void test_core_filebuf__umask(void) +void test_filebuf__umask(void) { git_filebuf file = GIT_FILEBUF_INIT; char test[] = "test"; @@ -124,7 +124,7 @@ void test_core_filebuf__umask(void) cl_must_pass(p_unlink(test)); } -void test_core_filebuf__rename_error(void) +void test_filebuf__rename_error(void) { git_filebuf file = GIT_FILEBUF_INIT; char *dir = "subdir", *test = "subdir/test", *test_lock = "subdir/test.lock"; @@ -152,7 +152,7 @@ void test_core_filebuf__rename_error(void) cl_assert_equal_i(false, git_fs_path_exists(test_lock)); } -void test_core_filebuf__symlink_follow(void) +void test_filebuf__symlink_follow(void) { git_filebuf file = GIT_FILEBUF_INIT; const char *dir = "linkdir", *source = "linkdir/link"; @@ -186,7 +186,7 @@ void test_core_filebuf__symlink_follow(void) cl_git_pass(git_futils_rmdir_r(dir, NULL, GIT_RMDIR_REMOVE_FILES)); } -void test_core_filebuf__symlink_follow_absolute_paths(void) +void test_filebuf__symlink_follow_absolute_paths(void) { git_filebuf file = GIT_FILEBUF_INIT; git_str source = GIT_STR_INIT, target = GIT_STR_INIT; @@ -214,7 +214,7 @@ void test_core_filebuf__symlink_follow_absolute_paths(void) cl_git_pass(git_futils_rmdir_r("linkdir", NULL, GIT_RMDIR_REMOVE_FILES)); } -void test_core_filebuf__symlink_depth(void) +void test_filebuf__symlink_depth(void) { git_filebuf file = GIT_FILEBUF_INIT; const char *dir = "linkdir", *source = "linkdir/link"; @@ -231,7 +231,7 @@ void test_core_filebuf__symlink_depth(void) cl_git_pass(git_futils_rmdir_r(dir, NULL, GIT_RMDIR_REMOVE_FILES)); } -void test_core_filebuf__hidden_file(void) +void test_filebuf__hidden_file(void) { #ifndef GIT_WIN32 cl_skip(); @@ -257,7 +257,7 @@ void test_core_filebuf__hidden_file(void) #endif } -void test_core_filebuf__detects_directory(void) +void test_filebuf__detects_directory(void) { git_filebuf file = GIT_FILEBUF_INIT; diff --git a/tests/core/ftruncate.c b/tests/util/ftruncate.c similarity index 80% rename from tests/core/ftruncate.c rename to tests/util/ftruncate.c index 0c731cb1e34..e60e5d96dfe 100644 --- a/tests/core/ftruncate.c +++ b/tests/util/ftruncate.c @@ -8,7 +8,7 @@ static const char *filename = "core_ftruncate.txt"; static int fd = -1; -void test_core_ftruncate__initialize(void) +void test_ftruncate__initialize(void) { if (!cl_is_env_set("GITTEST_INVASIVE_FS_SIZE")) cl_skip(); @@ -16,7 +16,7 @@ void test_core_ftruncate__initialize(void) cl_must_pass((fd = p_open(filename, O_CREAT | O_RDWR, 0644))); } -void test_core_ftruncate__cleanup(void) +void test_ftruncate__cleanup(void) { if (fd < 0) return; @@ -37,12 +37,12 @@ static void _extend(off64_t i64len) cl_assert(st.st_size == i64len); } -void test_core_ftruncate__2gb(void) +void test_ftruncate__2gb(void) { _extend(0x80000001); } -void test_core_ftruncate__4gb(void) +void test_ftruncate__4gb(void) { _extend(0x100000001); } diff --git a/tests/core/futils.c b/tests/util/futils.c similarity index 90% rename from tests/core/futils.c rename to tests/util/futils.c index 3501765f621..993b14d9b03 100644 --- a/tests/core/futils.c +++ b/tests/util/futils.c @@ -2,17 +2,17 @@ #include "futils.h" /* Fixture setup and teardown */ -void test_core_futils__initialize(void) +void test_futils__initialize(void) { cl_must_pass(p_mkdir("futils", 0777)); } -void test_core_futils__cleanup(void) +void test_futils__cleanup(void) { cl_fixture_cleanup("futils"); } -void test_core_futils__writebuffer(void) +void test_futils__writebuffer(void) { git_str out = GIT_STR_INIT, append = GIT_STR_INIT; @@ -37,7 +37,7 @@ void test_core_futils__writebuffer(void) git_str_dispose(&append); } -void test_core_futils__write_hidden_file(void) +void test_futils__write_hidden_file(void) { #ifndef GIT_WIN32 cl_skip(); @@ -66,7 +66,7 @@ void test_core_futils__write_hidden_file(void) #endif } -void test_core_futils__recursive_rmdir_keeps_symlink_targets(void) +void test_futils__recursive_rmdir_keeps_symlink_targets(void) { if (!git_fs_path_supports_symlinks(clar_sandbox_path())) cl_skip(); @@ -88,7 +88,7 @@ void test_core_futils__recursive_rmdir_keeps_symlink_targets(void) cl_must_pass(p_unlink("file-target")); } -void test_core_futils__mktmp_umask(void) +void test_futils__mktmp_umask(void) { #ifdef GIT_WIN32 cl_skip(); diff --git a/tests/core/gitstr.c b/tests/util/gitstr.c similarity index 80% rename from tests/core/gitstr.c rename to tests/util/gitstr.c index 0a624e28c02..aea35565bed 100644 --- a/tests/core/gitstr.c +++ b/tests/util/gitstr.c @@ -1,5 +1,4 @@ #include "clar_libgit2.h" -#include "git2/sys/hashsig.h" #include "futils.h" #define TESTSTR "Have you seen that? Have you seeeen that??" @@ -12,7 +11,7 @@ const char *test_4096 = TESTSTR_4096; const char *test_8192 = TESTSTR_8192; /* test basic data concatenation */ -void test_core_gitstr__0(void) +void test_gitstr__0(void) { git_str buf = GIT_STR_INIT; @@ -30,7 +29,7 @@ void test_core_gitstr__0(void) } /* test git_str_printf */ -void test_core_gitstr__1(void) +void test_gitstr__1(void) { git_str buf = GIT_STR_INIT; @@ -46,7 +45,7 @@ void test_core_gitstr__1(void) } /* more thorough test of concatenation options */ -void test_core_gitstr__2(void) +void test_gitstr__2(void) { git_str buf = GIT_STR_INIT; int i; @@ -158,7 +157,7 @@ void test_core_gitstr__2(void) } /* let's do some tests with larger buffers to push our limits */ -void test_core_gitstr__3(void) +void test_gitstr__3(void) { git_str buf = GIT_STR_INIT; @@ -181,7 +180,7 @@ void test_core_gitstr__3(void) } /* let's try some producer/consumer tests */ -void test_core_gitstr__4(void) +void test_gitstr__4(void) { git_str buf = GIT_STR_INIT; int i; @@ -277,7 +276,7 @@ check_buf_append_abc( } /* more variations on append tests */ -void test_core_gitstr__5(void) +void test_gitstr__5(void) { check_buf_append("", "", "", 0, 0); check_buf_append("a", "", "a", 1, 0); @@ -320,7 +319,7 @@ void test_core_gitstr__5(void) } /* test swap */ -void test_core_gitstr__6(void) +void test_gitstr__6(void) { git_str a = GIT_STR_INIT; git_str b = GIT_STR_INIT; @@ -344,7 +343,7 @@ void test_core_gitstr__6(void) /* test detach/attach data */ -void test_core_gitstr__7(void) +void test_gitstr__7(void) { const char *fun = "This is fun"; git_str a = GIT_STR_INIT; @@ -455,7 +454,7 @@ check_joinbuf_n_4( } /* test join */ -void test_core_gitstr__8(void) +void test_gitstr__8(void) { git_str a = GIT_STR_INIT; @@ -536,7 +535,7 @@ void test_core_gitstr__8(void) check_joinbuf_n_4(";abcd;", ";efgh;", ";ijkl;", ";mnop;", ";abcd;efgh;ijkl;mnop;"); } -void test_core_gitstr__9(void) +void test_gitstr__9(void) { git_str buf = GIT_STR_INIT; @@ -579,7 +578,7 @@ void test_core_gitstr__9(void) git_str_dispose(&buf); } -void test_core_gitstr__10(void) +void test_gitstr__10(void) { git_str a = GIT_STR_INIT; @@ -596,7 +595,7 @@ void test_core_gitstr__10(void) git_str_dispose(&a); } -void test_core_gitstr__join3(void) +void test_gitstr__join3(void) { git_str a = GIT_STR_INIT; @@ -628,7 +627,7 @@ void test_core_gitstr__join3(void) git_str_dispose(&a); } -void test_core_gitstr__11(void) +void test_gitstr__11(void) { git_str a = GIT_STR_INIT; char *t1[] = { "nothing", "in", "common" }; @@ -663,7 +662,7 @@ void test_core_gitstr__11(void) git_str_dispose(&a); } -void test_core_gitstr__rfind_variants(void) +void test_gitstr__rfind_variants(void) { git_str a = GIT_STR_INIT; ssize_t len; @@ -687,7 +686,7 @@ void test_core_gitstr__rfind_variants(void) git_str_dispose(&a); } -void test_core_gitstr__puts_escaped(void) +void test_gitstr__puts_escaped(void) { git_str a = GIT_STR_INIT; @@ -721,7 +720,7 @@ static void assert_unescape(char *expected, char *to_unescape) { git_str_dispose(&buf); } -void test_core_gitstr__unescape(void) +void test_gitstr__unescape(void) { assert_unescape("Escaped\\", "Es\\ca\\ped\\"); assert_unescape("Es\\caped\\", "Es\\\\ca\\ped\\\\"); @@ -730,7 +729,7 @@ void test_core_gitstr__unescape(void) assert_unescape("", ""); } -void test_core_gitstr__encode_base64(void) +void test_gitstr__encode_base64(void) { git_str buf = GIT_STR_INIT; @@ -755,7 +754,7 @@ void test_core_gitstr__encode_base64(void) git_str_dispose(&buf); } -void test_core_gitstr__decode_base64(void) +void test_gitstr__decode_base64(void) { git_str buf = GIT_STR_INIT; @@ -776,7 +775,7 @@ void test_core_gitstr__decode_base64(void) git_str_dispose(&buf); } -void test_core_gitstr__encode_base85(void) +void test_gitstr__encode_base85(void) { git_str buf = GIT_STR_INIT; @@ -796,7 +795,7 @@ void test_core_gitstr__encode_base85(void) git_str_dispose(&buf); } -void test_core_gitstr__decode_base85(void) +void test_gitstr__decode_base85(void) { git_str buf = GIT_STR_INIT; @@ -818,7 +817,7 @@ void test_core_gitstr__decode_base85(void) git_str_dispose(&buf); } -void test_core_gitstr__decode_base85_fails_gracefully(void) +void test_gitstr__decode_base85_fails_gracefully(void) { git_str buf = GIT_STR_INIT; @@ -834,7 +833,7 @@ void test_core_gitstr__decode_base85_fails_gracefully(void) git_str_dispose(&buf); } -void test_core_gitstr__classify_with_utf8(void) +void test_gitstr__classify_with_utf8(void) { char *data0 = "Simple text\n"; size_t data0len = 12; @@ -863,193 +862,13 @@ void test_core_gitstr__classify_with_utf8(void) cl_assert(!git_str_contains_nul(&b)); } -#define SIMILARITY_TEST_DATA_1 \ - "000\n001\n002\n003\n004\n005\n006\n007\n008\n009\n" \ - "010\n011\n012\n013\n014\n015\n016\n017\n018\n019\n" \ - "020\n021\n022\n023\n024\n025\n026\n027\n028\n029\n" \ - "030\n031\n032\n033\n034\n035\n036\n037\n038\n039\n" \ - "040\n041\n042\n043\n044\n045\n046\n047\n048\n049\n" - -void test_core_gitstr__similarity_metric(void) -{ - git_hashsig *a, *b; - git_str buf = GIT_STR_INIT; - int sim; - - /* in the first case, we compare data to itself and expect 100% match */ - - cl_git_pass(git_str_sets(&buf, SIMILARITY_TEST_DATA_1)); - cl_git_pass(git_hashsig_create(&a, buf.ptr, buf.size, GIT_HASHSIG_NORMAL)); - cl_git_pass(git_hashsig_create(&b, buf.ptr, buf.size, GIT_HASHSIG_NORMAL)); - - cl_assert_equal_i(100, git_hashsig_compare(a, b)); - - git_hashsig_free(a); - git_hashsig_free(b); - - /* if we change just a single byte, how much does that change magnify? */ - - cl_git_pass(git_str_sets(&buf, SIMILARITY_TEST_DATA_1)); - cl_git_pass(git_hashsig_create(&a, buf.ptr, buf.size, GIT_HASHSIG_NORMAL)); - cl_git_pass(git_str_sets(&buf, - "000\n001\n002\n003\n004\n005\n006\n007\n008\n009\n" \ - "010\n011\n012\n013\n014\n015\n016\n017\n018\n019\n" \ - "x020x\n021\n022\n023\n024\n025\n026\n027\n028\n029\n" \ - "030\n031\n032\n033\n034\n035\n036\n037\n038\n039\n" \ - "040\n041\n042\n043\n044\n045\n046\n047\n048\n049\n" - )); - cl_git_pass(git_hashsig_create(&b, buf.ptr, buf.size, GIT_HASHSIG_NORMAL)); - - sim = git_hashsig_compare(a, b); - - cl_assert_in_range(95, sim, 100); /* expect >95% similarity */ - - git_hashsig_free(a); - git_hashsig_free(b); - - /* let's try comparing data to a superset of itself */ - - cl_git_pass(git_str_sets(&buf, SIMILARITY_TEST_DATA_1)); - cl_git_pass(git_hashsig_create(&a, buf.ptr, buf.size, GIT_HASHSIG_NORMAL)); - cl_git_pass(git_str_sets(&buf, SIMILARITY_TEST_DATA_1 - "050\n051\n052\n053\n054\n055\n056\n057\n058\n059\n")); - cl_git_pass(git_hashsig_create(&b, buf.ptr, buf.size, GIT_HASHSIG_NORMAL)); - - sim = git_hashsig_compare(a, b); - /* 20% lines added ~= 10% lines changed */ - - cl_assert_in_range(85, sim, 95); /* expect similarity around 90% */ - - git_hashsig_free(a); - git_hashsig_free(b); - - /* what if we keep about half the original data and add half new */ - - cl_git_pass(git_str_sets(&buf, SIMILARITY_TEST_DATA_1)); - cl_git_pass(git_hashsig_create(&a, buf.ptr, buf.size, GIT_HASHSIG_NORMAL)); - cl_git_pass(git_str_sets(&buf, - "000\n001\n002\n003\n004\n005\n006\n007\n008\n009\n" \ - "010\n011\n012\n013\n014\n015\n016\n017\n018\n019\n" \ - "020x\n021\n022\n023\n024\n" \ - "x25\nx26\nx27\nx28\nx29\n" \ - "x30\nx31\nx32\nx33\nx34\nx35\nx36\nx37\nx38\nx39\n" \ - "x40\nx41\nx42\nx43\nx44\nx45\nx46\nx47\nx48\nx49\n" - )); - cl_git_pass(git_hashsig_create(&b, buf.ptr, buf.size, GIT_HASHSIG_NORMAL)); - - sim = git_hashsig_compare(a, b); - /* 50% lines changed */ - - cl_assert_in_range(40, sim, 60); /* expect in the 40-60% similarity range */ - - git_hashsig_free(a); - git_hashsig_free(b); - - /* lastly, let's check that we can hash file content as well */ - - cl_git_pass(git_str_sets(&buf, SIMILARITY_TEST_DATA_1)); - cl_git_pass(git_hashsig_create(&a, buf.ptr, buf.size, GIT_HASHSIG_NORMAL)); - - cl_git_pass(git_futils_mkdir("scratch", 0755, GIT_MKDIR_PATH)); - cl_git_mkfile("scratch/testdata", SIMILARITY_TEST_DATA_1); - cl_git_pass(git_hashsig_create_fromfile( - &b, "scratch/testdata", GIT_HASHSIG_NORMAL)); - - cl_assert_equal_i(100, git_hashsig_compare(a, b)); - - git_hashsig_free(a); - git_hashsig_free(b); - - git_str_dispose(&buf); - git_futils_rmdir_r("scratch", NULL, GIT_RMDIR_REMOVE_FILES); -} - - -void test_core_gitstr__similarity_metric_whitespace(void) -{ - git_hashsig *a, *b; - git_str buf = GIT_STR_INIT; - int sim, i, j; - git_hashsig_option_t opt; - const char *tabbed = - " for (s = 0; s < sizeof(sep) / sizeof(char); ++s) {\n" - " separator = sep[s];\n" - " expect = expect_values[s];\n" - "\n" - " for (j = 0; j < sizeof(b) / sizeof(char*); ++j) {\n" - " for (i = 0; i < sizeof(a) / sizeof(char*); ++i) {\n" - " git_str_join(&buf, separator, a[i], b[j]);\n" - " cl_assert_equal_s(*expect, buf.ptr);\n" - " expect++;\n" - " }\n" - " }\n" - " }\n"; - const char *spaced = - " for (s = 0; s < sizeof(sep) / sizeof(char); ++s) {\n" - " separator = sep[s];\n" - " expect = expect_values[s];\n" - "\n" - " for (j = 0; j < sizeof(b) / sizeof(char*); ++j) {\n" - " for (i = 0; i < sizeof(a) / sizeof(char*); ++i) {\n" - " git_str_join(&buf, separator, a[i], b[j]);\n" - " cl_assert_equal_s(*expect, buf.ptr);\n" - " expect++;\n" - " }\n" - " }\n" - " }\n"; - const char *crlf_spaced2 = - " for (s = 0; s < sizeof(sep) / sizeof(char); ++s) {\r\n" - " separator = sep[s];\r\n" - " expect = expect_values[s];\r\n" - "\r\n" - " for (j = 0; j < sizeof(b) / sizeof(char*); ++j) {\r\n" - " for (i = 0; i < sizeof(a) / sizeof(char*); ++i) {\r\n" - " git_str_join(&buf, separator, a[i], b[j]);\r\n" - " cl_assert_equal_s(*expect, buf.ptr);\r\n" - " expect++;\r\n" - " }\r\n" - " }\r\n" - " }\r\n"; - const char *text[3] = { tabbed, spaced, crlf_spaced2 }; - - /* let's try variations of our own code with whitespace changes */ - - for (opt = GIT_HASHSIG_NORMAL; opt <= GIT_HASHSIG_SMART_WHITESPACE; ++opt) { - for (i = 0; i < 3; ++i) { - for (j = 0; j < 3; ++j) { - cl_git_pass(git_str_sets(&buf, text[i])); - cl_git_pass(git_hashsig_create(&a, buf.ptr, buf.size, opt)); - - cl_git_pass(git_str_sets(&buf, text[j])); - cl_git_pass(git_hashsig_create(&b, buf.ptr, buf.size, opt)); - - sim = git_hashsig_compare(a, b); - - if (opt == GIT_HASHSIG_NORMAL) { - if (i == j) - cl_assert_equal_i(100, sim); - else - cl_assert_in_range(0, sim, 30); /* pretty different */ - } else { - cl_assert_equal_i(100, sim); - } - - git_hashsig_free(a); - git_hashsig_free(b); - } - } - } - - git_str_dispose(&buf); -} - -#include "../filter/crlf.h" +#include "crlf.h" #define check_buf(expected,buf) do { \ cl_assert_equal_s(expected, buf.ptr); \ cl_assert_equal_sz(strlen(expected), buf.size); } while (0) -void test_core_gitstr__lf_and_crlf_conversions(void) +void test_gitstr__lf_and_crlf_conversions(void) { git_str src = GIT_STR_INIT, tgt = GIT_STR_INIT; @@ -1175,7 +994,7 @@ void test_core_gitstr__lf_and_crlf_conversions(void) git_str_dispose(&tgt); } -void test_core_gitstr__dont_grow_borrowed(void) +void test_gitstr__dont_grow_borrowed(void) { const char *somestring = "blah blah"; git_str buf = GIT_STR_INIT; @@ -1188,7 +1007,7 @@ void test_core_gitstr__dont_grow_borrowed(void) cl_git_fail_with(GIT_EINVALID, git_str_grow(&buf, 1024)); } -void test_core_gitstr__dont_hit_infinite_loop_when_resizing(void) +void test_gitstr__dont_hit_infinite_loop_when_resizing(void) { git_str buf = GIT_STR_INIT; @@ -1204,7 +1023,7 @@ void test_core_gitstr__dont_hit_infinite_loop_when_resizing(void) git_str_dispose(&buf); } -void test_core_gitstr__avoid_printing_into_oom_buffer(void) +void test_gitstr__avoid_printing_into_oom_buffer(void) { git_str buf = GIT_STR_INIT; diff --git a/tests/core/hex.c b/tests/util/hex.c similarity index 94% rename from tests/core/hex.c rename to tests/util/hex.c index 930af16706c..c5fea0a42f5 100644 --- a/tests/core/hex.c +++ b/tests/util/hex.c @@ -1,7 +1,7 @@ #include "clar_libgit2.h" #include "util.h" -void test_core_hex__fromhex(void) +void test_hex__fromhex(void) { /* Passing cases */ cl_assert(git__fromhex('0') == 0x0); diff --git a/tests/core/iconv.c b/tests/util/iconv.c similarity index 88% rename from tests/core/iconv.c rename to tests/util/iconv.c index af1b4eabf48..e14aebb9908 100644 --- a/tests/core/iconv.c +++ b/tests/util/iconv.c @@ -7,21 +7,21 @@ static char *nfc = "\xC3\x85\x73\x74\x72\xC3\xB6\x6D"; static char *nfd = "\x41\xCC\x8A\x73\x74\x72\x6F\xCC\x88\x6D"; #endif -void test_core_iconv__initialize(void) +void test_iconv__initialize(void) { #ifdef GIT_USE_ICONV cl_git_pass(git_fs_path_iconv_init_precompose(&ic)); #endif } -void test_core_iconv__cleanup(void) +void test_iconv__cleanup(void) { #ifdef GIT_USE_ICONV git_fs_path_iconv_clear(&ic); #endif } -void test_core_iconv__unchanged(void) +void test_iconv__unchanged(void) { #ifdef GIT_USE_ICONV const char *data = "Ascii data", *original = data; @@ -35,7 +35,7 @@ void test_core_iconv__unchanged(void) #endif } -void test_core_iconv__decomposed_to_precomposed(void) +void test_iconv__decomposed_to_precomposed(void) { #ifdef GIT_USE_ICONV const char *data = nfd; @@ -61,7 +61,7 @@ void test_core_iconv__decomposed_to_precomposed(void) #endif } -void test_core_iconv__precomposed_is_unmodified(void) +void test_iconv__precomposed_is_unmodified(void) { #ifdef GIT_USE_ICONV const char *data = nfc; diff --git a/tests/core/init.c b/tests/util/init.c similarity index 88% rename from tests/core/init.c rename to tests/util/init.c index eba77ef522f..78b3dd039c7 100644 --- a/tests/core/init.c +++ b/tests/util/init.c @@ -1,6 +1,6 @@ #include "clar_libgit2.h" -void test_core_init__returns_count(void) +void test_init__returns_count(void) { /* libgit2_tests initializes us first, so we have an existing * initialization. @@ -12,7 +12,7 @@ void test_core_init__returns_count(void) cl_assert_equal_i(1, git_libgit2_shutdown()); } -void test_core_init__reinit_succeeds(void) +void test_init__reinit_succeeds(void) { cl_assert_equal_i(0, git_libgit2_shutdown()); cl_assert_equal_i(1, git_libgit2_init()); @@ -33,7 +33,7 @@ static void *reinit(void *unused) } #endif -void test_core_init__concurrent_init_succeeds(void) +void test_init__concurrent_init_succeeds(void) { #ifdef GIT_THREADS git_thread threads[10]; diff --git a/tests/core/integer.c b/tests/util/integer.c similarity index 99% rename from tests/core/integer.c rename to tests/util/integer.c index 18364ba6225..2226ab41e41 100644 --- a/tests/core/integer.c +++ b/tests/util/integer.c @@ -1,6 +1,6 @@ #include "clar_libgit2.h" -void test_core_integer__multiply_int64_no_overflow(void) +void test_integer__multiply_int64_no_overflow(void) { #if !defined(git__multiply_int64_overflow) int64_t result = 0; @@ -169,7 +169,7 @@ void test_core_integer__multiply_int64_no_overflow(void) #endif } -void test_core_integer__multiply_int64_overflow(void) +void test_integer__multiply_int64_overflow(void) { #if !defined(git__multiply_int64_overflow) int64_t result = 0; @@ -239,7 +239,7 @@ void test_core_integer__multiply_int64_overflow(void) #endif } -void test_core_integer__multiply_int64_edge_cases(void) +void test_integer__multiply_int64_edge_cases(void) { #if !defined(git__multiply_int64_overflow) int64_t result = 0; diff --git a/tests/core/link.c b/tests/util/link.c similarity index 92% rename from tests/core/link.c rename to tests/util/link.c index a1e2706b270..46cafada7e9 100644 --- a/tests/core/link.c +++ b/tests/util/link.c @@ -5,7 +5,7 @@ # include "win32/reparse.h" #endif -void test_core_link__cleanup(void) +void test_link__cleanup(void) { #ifdef GIT_WIN32 RemoveDirectory("lstat_junction"); @@ -195,7 +195,7 @@ static void do_custom_reparse(const char *path) #endif -void test_core_link__stat_regular_file(void) +void test_link__stat_regular_file(void) { struct stat st; @@ -206,7 +206,7 @@ void test_core_link__stat_regular_file(void) cl_assert_equal_i(24, st.st_size); } -void test_core_link__lstat_regular_file(void) +void test_link__lstat_regular_file(void) { struct stat st; @@ -217,7 +217,7 @@ void test_core_link__lstat_regular_file(void) cl_assert_equal_i(24, st.st_size); } -void test_core_link__stat_symlink(void) +void test_link__stat_symlink(void) { struct stat st; @@ -236,7 +236,7 @@ void test_core_link__stat_symlink(void) cl_assert_equal_i(39, st.st_size); } -void test_core_link__stat_symlink_directory(void) +void test_link__stat_symlink_directory(void) { struct stat st; @@ -253,7 +253,7 @@ void test_core_link__stat_symlink_directory(void) cl_assert(S_ISDIR(st.st_mode)); } -void test_core_link__stat_symlink_chain(void) +void test_link__stat_symlink_chain(void) { struct stat st; @@ -270,7 +270,7 @@ void test_core_link__stat_symlink_chain(void) cl_assert_equal_i(39, st.st_size); } -void test_core_link__stat_dangling_symlink(void) +void test_link__stat_dangling_symlink(void) { struct stat st; @@ -283,7 +283,7 @@ void test_core_link__stat_dangling_symlink(void) cl_must_fail(p_stat("stat_dangling", &st)); } -void test_core_link__stat_dangling_symlink_directory(void) +void test_link__stat_dangling_symlink_directory(void) { struct stat st; @@ -296,7 +296,7 @@ void test_core_link__stat_dangling_symlink_directory(void) cl_must_fail(p_stat("stat_dangling", &st)); } -void test_core_link__lstat_symlink(void) +void test_link__lstat_symlink(void) { git_str target_path = GIT_STR_INIT; struct stat st; @@ -323,7 +323,7 @@ void test_core_link__lstat_symlink(void) git_str_dispose(&target_path); } -void test_core_link__lstat_symlink_directory(void) +void test_link__lstat_symlink_directory(void) { git_str target_path = GIT_STR_INIT; struct stat st; @@ -346,7 +346,7 @@ void test_core_link__lstat_symlink_directory(void) git_str_dispose(&target_path); } -void test_core_link__lstat_dangling_symlink(void) +void test_link__lstat_dangling_symlink(void) { struct stat st; @@ -362,7 +362,7 @@ void test_core_link__lstat_dangling_symlink(void) cl_assert_equal_i(strlen("lstat_nonexistent"), st.st_size); } -void test_core_link__lstat_dangling_symlink_directory(void) +void test_link__lstat_dangling_symlink_directory(void) { struct stat st; @@ -378,7 +378,7 @@ void test_core_link__lstat_dangling_symlink_directory(void) cl_assert_equal_i(strlen("lstat_nonexistent"), st.st_size); } -void test_core_link__stat_junction(void) +void test_link__stat_junction(void) { #ifdef GIT_WIN32 git_str target_path = GIT_STR_INIT; @@ -399,7 +399,7 @@ void test_core_link__stat_junction(void) #endif } -void test_core_link__stat_dangling_junction(void) +void test_link__stat_dangling_junction(void) { #ifdef GIT_WIN32 git_str target_path = GIT_STR_INIT; @@ -419,7 +419,7 @@ void test_core_link__stat_dangling_junction(void) #endif } -void test_core_link__lstat_junction(void) +void test_link__lstat_junction(void) { #ifdef GIT_WIN32 git_str target_path = GIT_STR_INIT; @@ -440,7 +440,7 @@ void test_core_link__lstat_junction(void) #endif } -void test_core_link__lstat_dangling_junction(void) +void test_link__lstat_dangling_junction(void) { #ifdef GIT_WIN32 git_str target_path = GIT_STR_INIT; @@ -463,7 +463,7 @@ void test_core_link__lstat_dangling_junction(void) #endif } -void test_core_link__stat_hardlink(void) +void test_link__stat_hardlink(void) { struct stat st; @@ -482,7 +482,7 @@ void test_core_link__stat_hardlink(void) cl_assert_equal_i(26, st.st_size); } -void test_core_link__lstat_hardlink(void) +void test_link__lstat_hardlink(void) { struct stat st; @@ -501,7 +501,7 @@ void test_core_link__lstat_hardlink(void) cl_assert_equal_i(26, st.st_size); } -void test_core_link__stat_reparse_point(void) +void test_link__stat_reparse_point(void) { #ifdef GIT_WIN32 struct stat st; @@ -519,7 +519,7 @@ void test_core_link__stat_reparse_point(void) #endif } -void test_core_link__lstat_reparse_point(void) +void test_link__lstat_reparse_point(void) { #ifdef GIT_WIN32 struct stat st; @@ -533,7 +533,7 @@ void test_core_link__lstat_reparse_point(void) #endif } -void test_core_link__readlink_nonexistent_file(void) +void test_link__readlink_nonexistent_file(void) { char buf[2048]; @@ -541,7 +541,7 @@ void test_core_link__readlink_nonexistent_file(void) cl_assert_equal_i(ENOENT, errno); } -void test_core_link__readlink_normal_file(void) +void test_link__readlink_normal_file(void) { char buf[2048]; @@ -550,7 +550,7 @@ void test_core_link__readlink_normal_file(void) cl_assert_equal_i(EINVAL, errno); } -void test_core_link__readlink_symlink(void) +void test_link__readlink_symlink(void) { git_str target_path = GIT_STR_INIT; int len; @@ -574,7 +574,7 @@ void test_core_link__readlink_symlink(void) git_str_dispose(&target_path); } -void test_core_link__readlink_dangling(void) +void test_link__readlink_dangling(void) { git_str target_path = GIT_STR_INIT; int len; @@ -597,7 +597,7 @@ void test_core_link__readlink_dangling(void) git_str_dispose(&target_path); } -void test_core_link__readlink_multiple(void) +void test_link__readlink_multiple(void) { git_str target_path = GIT_STR_INIT, path3 = GIT_STR_INIT, path2 = GIT_STR_INIT, path1 = GIT_STR_INIT; diff --git a/tests/core/memmem.c b/tests/util/memmem.c similarity index 90% rename from tests/core/memmem.c rename to tests/util/memmem.c index fd9986d01b4..1c713e8bd64 100644 --- a/tests/core/memmem.c +++ b/tests/util/memmem.c @@ -14,7 +14,7 @@ static void assert_absent(const char *haystack, const char *needle) NULL); } -void test_core_memmem__found(void) +void test_memmem__found(void) { assert_found("a", "a", 0); assert_found("ab", "a", 0); @@ -26,7 +26,7 @@ void test_core_memmem__found(void) assert_found("abababc", "abc", 4); } -void test_core_memmem__absent(void) +void test_memmem__absent(void) { assert_absent("a", "b"); assert_absent("a", "aa"); @@ -36,7 +36,7 @@ void test_core_memmem__absent(void) assert_absent("abcabcabc", "bcac"); } -void test_core_memmem__edgecases(void) +void test_memmem__edgecases(void) { assert_absent(NULL, NULL); assert_absent("a", NULL); diff --git a/tests/core/mkdir.c b/tests/util/mkdir.c similarity index 97% rename from tests/core/mkdir.c rename to tests/util/mkdir.c index 58a4cfcdb81..8658eec0df2 100644 --- a/tests/core/mkdir.c +++ b/tests/util/mkdir.c @@ -12,7 +12,7 @@ static void cleanup_basic_dirs(void *ref) git_futils_rmdir_r("d4", NULL, GIT_RMDIR_EMPTY_HIERARCHY); } -void test_core_mkdir__absolute(void) +void test_mkdir__absolute(void) { git_str path = GIT_STR_INIT; @@ -51,7 +51,7 @@ void test_core_mkdir__absolute(void) git_str_dispose(&path); } -void test_core_mkdir__basic(void) +void test_mkdir__basic(void) { cl_set_cleanup(cleanup_basic_dirs, NULL); @@ -97,7 +97,7 @@ static void cleanup_basedir(void *ref) git_futils_rmdir_r("base", NULL, GIT_RMDIR_EMPTY_HIERARCHY); } -void test_core_mkdir__with_base(void) +void test_mkdir__with_base(void) { #define BASEDIR "base/dir/here" @@ -166,7 +166,7 @@ static void check_mode_at_line( "%07o", (int)expected, (int)(actual & 0777)); } -void test_core_mkdir__chmods(void) +void test_mkdir__chmods(void) { struct stat st; mode_t *old = git__malloc(sizeof(mode_t)); @@ -226,7 +226,7 @@ void test_core_mkdir__chmods(void) check_mode(0777, st.st_mode); } -void test_core_mkdir__keeps_parent_symlinks(void) +void test_mkdir__keeps_parent_symlinks(void) { #ifndef GIT_WIN32 git_str path = GIT_STR_INIT; @@ -260,7 +260,7 @@ void test_core_mkdir__keeps_parent_symlinks(void) #endif } -void test_core_mkdir__mkdir_path_inside_unwriteable_parent(void) +void test_mkdir__mkdir_path_inside_unwriteable_parent(void) { struct stat st; mode_t *old; diff --git a/tests/core/path.c b/tests/util/path.c similarity index 96% rename from tests/core/path.c rename to tests/util/path.c index a0ae77f1c76..404c17a2b75 100644 --- a/tests/core/path.c +++ b/tests/util/path.c @@ -4,12 +4,12 @@ static char *path_save; -void test_core_path__initialize(void) +void test_path__initialize(void) { path_save = cl_getenv("PATH"); } -void test_core_path__cleanup(void) +void test_path__cleanup(void) { cl_setenv("PATH", path_save); git__free(path_save); @@ -90,7 +90,7 @@ static void check_setenv(const char* name, const char* value) } /* get the dirname of a path */ -void test_core_path__00_dirname(void) +void test_path__00_dirname(void) { check_dirname(NULL, "."); check_dirname("", "."); @@ -123,7 +123,7 @@ void test_core_path__00_dirname(void) } /* get the base name of a path */ -void test_core_path__01_basename(void) +void test_path__01_basename(void) { check_basename(NULL, "."); check_basename("", "."); @@ -140,7 +140,7 @@ void test_core_path__01_basename(void) } /* properly join path components */ -void test_core_path__05_joins(void) +void test_path__05_joins(void) { check_joinpath("", "", ""); check_joinpath("", "a", "a"); @@ -175,7 +175,7 @@ void test_core_path__05_joins(void) } /* properly join path components for more than one path */ -void test_core_path__06_long_joins(void) +void test_path__06_long_joins(void) { check_joinpath_n("", "", "", "", ""); check_joinpath_n("", "a", "", "", "a/"); @@ -230,7 +230,7 @@ check_string_to_dir( } /* convert paths to dirs */ -void test_core_path__07_path_to_dir(void) +void test_path__07_path_to_dir(void) { check_path_to_dir("", ""); check_path_to_dir(".", "./"); @@ -258,7 +258,7 @@ void test_core_path__07_path_to_dir(void) } /* join path to itself */ -void test_core_path__08_self_join(void) +void test_path__08_self_join(void) { git_str path = GIT_STR_INIT; size_t asize = 0; @@ -302,7 +302,7 @@ static void check_percent_decoding(const char *expected_result, const char *inpu git_str_dispose(&buf); } -void test_core_path__09_percent_decode(void) +void test_path__09_percent_decode(void) { check_percent_decoding("abcd", "abcd"); check_percent_decoding("a2%", "a2%"); @@ -337,7 +337,7 @@ static void check_fromurl(const char *expected_result, const char *input, int sh #define ABS_PATH_MARKER "/" #endif -void test_core_path__10_fromurl(void) +void test_path__10_fromurl(void) { /* Failing cases */ check_fromurl(NULL, "a", 1); @@ -380,7 +380,7 @@ static int check_one_walkup_step(void *ref, const char *path) return 0; } -void test_core_path__11_walkup(void) +void test_path__11_walkup(void) { git_str p = GIT_STR_INIT; @@ -442,7 +442,7 @@ void test_core_path__11_walkup(void) git_str_dispose(&p); } -void test_core_path__11a_walkup_cancel(void) +void test_path__11a_walkup_cancel(void) { git_str p = GIT_STR_INIT; int cancel[] = { 3, 2, 1, 0 }; @@ -478,7 +478,7 @@ void test_core_path__11a_walkup_cancel(void) git_str_dispose(&p); } -void test_core_path__12_offset_to_path_root(void) +void test_path__12_offset_to_path_root(void) { cl_assert(git_fs_path_root("non/rooted/path") == -1); cl_assert(git_fs_path_root("/rooted/path") == 0); @@ -495,7 +495,7 @@ void test_core_path__12_offset_to_path_root(void) #define NON_EXISTING_FILEPATH "i_hope_i_do_not_exist" -void test_core_path__13_cannot_prettify_a_non_existing_file(void) +void test_path__13_cannot_prettify_a_non_existing_file(void) { git_str p = GIT_STR_INIT; @@ -506,7 +506,7 @@ void test_core_path__13_cannot_prettify_a_non_existing_file(void) git_str_dispose(&p); } -void test_core_path__14_apply_relative(void) +void test_path__14_apply_relative(void) { git_str p = GIT_STR_INIT; @@ -575,7 +575,7 @@ static void assert_resolve_relative( cl_assert_equal_s(expected, buf->ptr); } -void test_core_path__15_resolve_relative(void) +void test_path__15_resolve_relative(void) { git_str buf = GIT_STR_INIT; @@ -663,7 +663,7 @@ void test_core_path__15_resolve_relative(void) #define assert_common_dirlen(i, p, q) \ cl_assert_equal_i((i), git_fs_path_common_dirlen((p), (q))); -void test_core_path__16_resolve_relative(void) +void test_path__16_resolve_relative(void) { assert_common_dirlen(0, "", ""); assert_common_dirlen(0, "", "bar.txt"); @@ -694,7 +694,7 @@ static void fix_path(git_str *s) #endif } -void test_core_path__find_exe_in_path(void) +void test_path__find_exe_in_path(void) { char *orig_path; git_str sandbox_path = GIT_STR_INIT; diff --git a/tests/path/core.c b/tests/util/path/core.c similarity index 73% rename from tests/path/core.c rename to tests/util/path/core.c index db5359af8b5..f30f6c01b0d 100644 --- a/tests/path/core.c +++ b/tests/util/path/core.c @@ -1,11 +1,5 @@ #include "clar_libgit2.h" #include "fs_path.h" -#include "path.h" - -void test_path_core__cleanup(void) -{ - cl_git_sandbox_cleanup(); -} static void test_make_relative( const char *expected_path, @@ -280,62 +274,6 @@ void test_path_core__isvalid_nt_chars(void) cl_assert_equal_b(false, git_fs_path_is_valid("asdf*bar", GIT_FS_PATH_REJECT_NT_CHARS)); } -void test_path_core__validate_workdir(void) -{ - cl_must_pass(git_path_validate_length(NULL, "/foo/bar")); - cl_must_pass(git_path_validate_length(NULL, "C:\\Foo\\Bar")); - cl_must_pass(git_path_validate_length(NULL, "\\\\?\\C:\\Foo\\Bar")); - cl_must_pass(git_path_validate_length(NULL, "\\\\?\\C:\\Foo\\Bar")); - cl_must_pass(git_path_validate_length(NULL, "\\\\?\\UNC\\server\\C$\\folder")); - -#ifdef GIT_WIN32 - /* - * In the absence of a repo configuration, 259 character paths - * succeed. >= 260 character paths fail. - */ - cl_must_pass(git_path_validate_length(NULL, "C:\\aaaaaaaaa\\aaaaaaaaa\\aaaaaaaaa\\aaaaaaaaa\\aaaaaaaaa\\aaaaaaaaa\\aaaaaaaaa\\aaaaaaaaa\\aaaaaaaaa\\aaaaaaaaa\\aaaaaaaaa\\aaaaaaaaa\\aaaaaaaaa\\aaaaaaaaa\\aaaaaaaaa\\aaaaaaaaa\\aaaaaaaaa\\aaaaaaaaa\\aaaaaaaaa\\aaaaaaaaa\\aaaaaaaaa\\aaaaaaaaa\\aaaaaaaaa\\aaaaaaaaa\\aaaaaaaaa\\ok.txt")); - cl_must_pass(git_path_validate_length(NULL, "C:\\aaaaaaaaa\\aaaaaaaaa\\aaaaaaaaa\\aaaaaaaaa\\aaaaaaaaa\\aaaaaaaaa\\aaaaaaaaa\\aaaaaaaaa\\aaaaaaaaa\\aaaaaaaaa\\aaaaaaaaa\\aaaaaaaaa\\aaaaaaaaa\\aaaaaaaaa\\aaaaaaaaa\\aaaaaaaaa\\aaaaaaaaa\\aaaaaaaaa\\aaaaaaaaa\\aaaaaaaaa\\aaaaaaaaa\\aaaaaaaaa\\aaaaaaaaa\\aaaaaaaaa\\aaaaaaaaa\\260.txt")); - cl_must_fail(git_path_validate_length(NULL, "C:\\aaaaaaaaa\\aaaaaaaaa\\aaaaaaaaa\\aaaaaaaaa\\aaaaaaaaa\\aaaaaaaaa\\aaaaaaaaa\\aaaaaaaaa\\aaaaaaaaa\\aaaaaaaaa\\aaaaaaaaa\\aaaaaaaaa\\aaaaaaaaa\\aaaaaaaaa\\aaaaaaaaa\\aaaaaaaaa\\aaaaaaaaa\\aaaaaaaaa\\aaaaaaaaa\\aaaaaaaaa\\aaaaaaaaa\\aaaaaaaaa\\aaaaaaaaa\\aaaaaaaaa\\aaaaaaaaa\\longer_than_260.txt")); - - /* count characters, not bytes */ - cl_must_pass(git_path_validate_length(NULL, "C:\\aaaaaaaaa\\aaaaaaaaa\\aaaaaaaaa\\aaaaaaaaa\\aaaaaaaaa\\aaaaaaaaa\\aaaaaaaaa\\aaaaaaaaa\\aaaaaaaaa\\aaaaaaaaa\\aaaaaaaaa\\aaaaaaaaa\\aaaaaaaaa\\aaaaaaaaa\\aaaaaaaaa\\aaaaaaaaa\\aaaaaaaaa\\aaaaaaaaa\\aaaaaaaaa\\aaaaaaaaa\\aaaaaaaaa\\aaaaaaaaa\\aaaaaaaaa\\aaaaaaaaa\\\xc2\xa2\xc2\xa2\xc2\xa2\xc2\xa2\xc2\xa2\xc2\xa2\xc2\xa2\xc2\xa2\xc2\xa2\\260.txt")); - cl_must_fail(git_path_validate_length(NULL, "C:\\aaaaaaaaa\\aaaaaaaaa\\aaaaaaaaa\\aaaaaaaaa\\aaaaaaaaa\\aaaaaaaaa\\aaaaaaaaa\\aaaaaaaaa\\aaaaaaaaa\\aaaaaaaaa\\aaaaaaaaa\\aaaaaaaaa\\aaaaaaaaa\\aaaaaaaaa\\aaaaaaaaa\\aaaaaaaaa\\aaaaaaaaa\\aaaaaaaaa\\aaaaaaaaa\\aaaaaaaaa\\aaaaaaaaa\\aaaaaaaaa\\aaaaaaaaa\\aaaaaaaaa\\\xc2\xa2\xc2\xa2\xc2\xa2\xc2\xa2\xc2\xa2\xc2\xa2\xc2\xa2\xc2\xa2\xc2\xa2\\long.txt")); -#else - cl_must_pass(git_path_validate_length(NULL, "/c/aaaaaaaaa/aaaaaaaaa/aaaaaaaaa/aaaaaaaaa/aaaaaaaaa/aaaaaaaaa/aaaaaaaaa/aaaaaaaaa/aaaaaaaaa/aaaaaaaaa/aaaaaaaaa/aaaaaaaaa/aaaaaaaaa/aaaaaaaaa/aaaaaaaaa/aaaaaaaaa/aaaaaaaaa/aaaaaaaaa/aaaaaaaaa/aaaaaaaaa/aaaaaaaaa/aaaaaaaaa/aaaaaaaaa/aaaaaaaaa/aaaaaaaaa/ok.txt")); - cl_must_pass(git_path_validate_length(NULL, "/c/aaaaaaaaa/aaaaaaaaa/aaaaaaaaa/aaaaaaaaa/aaaaaaaaa/aaaaaaaaa/aaaaaaaaa/aaaaaaaaa/aaaaaaaaa/aaaaaaaaa/aaaaaaaaa/aaaaaaaaa/aaaaaaaaa/aaaaaaaaa/aaaaaaaaa/aaaaaaaaa/aaaaaaaaa/aaaaaaaaa/aaaaaaaaa/aaaaaaaaa/aaaaaaaaa/aaaaaaaaa/aaaaaaaaa/aaaaaaaaa/aaaaaaaaa/260.txt")); - cl_must_pass(git_path_validate_length(NULL, "/c/aaaaaaaaa/aaaaaaaaa/aaaaaaaaa/aaaaaaaaa/aaaaaaaaa/aaaaaaaaa/aaaaaaaaa/aaaaaaaaa/aaaaaaaaa/aaaaaaaaa/aaaaaaaaa/aaaaaaaaa/aaaaaaaaa/aaaaaaaaa/aaaaaaaaa/aaaaaaaaa/aaaaaaaaa/aaaaaaaaa/aaaaaaaaa/aaaaaaaaa/aaaaaaaaa/aaaaaaaaa/aaaaaaaaa/aaaaaaaaa/aaaaaaaaa/longer_than_260.txt")); - cl_must_pass(git_path_validate_length(NULL, "C:\\aaaaaaaaa\\aaaaaaaaa\\aaaaaaaaa\\aaaaaaaaa\\aaaaaaaaa\\aaaaaaaaa\\aaaaaaaaa\\aaaaaaaaa\\aaaaaaaaa\\aaaaaaaaa\\aaaaaaaaa\\aaaaaaaaa\\aaaaaaaaa\\aaaaaaaaa\\aaaaaaaaa\\aaaaaaaaa\\aaaaaaaaa\\aaaaaaaaa\\aaaaaaaaa\\aaaaaaaaa\\aaaaaaaaa\\aaaaaaaaa\\aaaaaaaaa\\aaaaaaaaa\\\xc2\xa2\xc2\xa2\xc2\xa2\xc2\xa2\xc2\xa2\xc2\xa2\xc2\xa2\xc2\xa2\xc2\xa2\\260.txt")); - cl_must_pass(git_path_validate_length(NULL, "C:\\aaaaaaaaa\\aaaaaaaaa\\aaaaaaaaa\\aaaaaaaaa\\aaaaaaaaa\\aaaaaaaaa\\aaaaaaaaa\\aaaaaaaaa\\aaaaaaaaa\\aaaaaaaaa\\aaaaaaaaa\\aaaaaaaaa\\aaaaaaaaa\\aaaaaaaaa\\aaaaaaaaa\\aaaaaaaaa\\aaaaaaaaa\\aaaaaaaaa\\aaaaaaaaa\\aaaaaaaaa\\aaaaaaaaa\\aaaaaaaaa\\aaaaaaaaa\\aaaaaaaaa\\\xc2\xa2\xc2\xa2\xc2\xa2\xc2\xa2\xc2\xa2\xc2\xa2\xc2\xa2\xc2\xa2\xc2\xa2\\long.txt")); -#endif -} - -void test_path_core__validate_workdir_with_core_longpath(void) -{ -#ifdef GIT_WIN32 - git_repository *repo; - git_config *config; - - repo = cl_git_sandbox_init("empty_bare.git"); - - cl_git_pass(git_repository_open(&repo, "empty_bare.git")); - cl_git_pass(git_repository_config(&config, repo)); - - /* fail by default */ - cl_must_fail(git_path_validate_length(repo, "/c/aaaaaaaaa/aaaaaaaaa/aaaaaaaaa/aaaaaaaaa/aaaaaaaaa/aaaaaaaaa/aaaaaaaaa/aaaaaaaaa/aaaaaaaaa/aaaaaaaaa/aaaaaaaaa/aaaaaaaaa/aaaaaaaaa/aaaaaaaaa/aaaaaaaaa/aaaaaaaaa/aaaaaaaaa/aaaaaaaaa/aaaaaaaaa/aaaaaaaaa/aaaaaaaaa/aaaaaaaaa/aaaaaaaaa/aaaaaaaaa/aaaaaaaaa/longer_than_260.txt")); - - /* set core.longpaths explicitly on */ - cl_git_pass(git_config_set_bool(config, "core.longpaths", 1)); - cl_must_pass(git_path_validate_length(repo, "/c/aaaaaaaaa/aaaaaaaaa/aaaaaaaaa/aaaaaaaaa/aaaaaaaaa/aaaaaaaaa/aaaaaaaaa/aaaaaaaaa/aaaaaaaaa/aaaaaaaaa/aaaaaaaaa/aaaaaaaaa/aaaaaaaaa/aaaaaaaaa/aaaaaaaaa/aaaaaaaaa/aaaaaaaaa/aaaaaaaaa/aaaaaaaaa/aaaaaaaaa/aaaaaaaaa/aaaaaaaaa/aaaaaaaaa/aaaaaaaaa/aaaaaaaaa/longer_than_260.txt")); - - /* set core.longpaths explicitly off */ - cl_git_pass(git_config_set_bool(config, "core.longpaths", 0)); - cl_must_fail(git_path_validate_length(repo, "/c/aaaaaaaaa/aaaaaaaaa/aaaaaaaaa/aaaaaaaaa/aaaaaaaaa/aaaaaaaaa/aaaaaaaaa/aaaaaaaaa/aaaaaaaaa/aaaaaaaaa/aaaaaaaaa/aaaaaaaaa/aaaaaaaaa/aaaaaaaaa/aaaaaaaaa/aaaaaaaaa/aaaaaaaaa/aaaaaaaaa/aaaaaaaaa/aaaaaaaaa/aaaaaaaaa/aaaaaaaaa/aaaaaaaaa/aaaaaaaaa/aaaaaaaaa/longer_than_260.txt")); - - git_config_free(config); - git_repository_free(repo); -#endif -} - static void test_join_unrooted( const char *expected_result, ssize_t expected_rootlen, diff --git a/tests/path/win32.c b/tests/util/path/win32.c similarity index 100% rename from tests/path/win32.c rename to tests/util/path/win32.c diff --git a/tests/core/pool.c b/tests/util/pool.c similarity index 59% rename from tests/core/pool.c rename to tests/util/pool.c index b07da0abd07..464aad73370 100644 --- a/tests/core/pool.c +++ b/tests/util/pool.c @@ -2,7 +2,7 @@ #include "pool.h" #include "git2/oid.h" -void test_core_pool__0(void) +void test_pool__0(void) { int i; git_pool p; @@ -20,7 +20,7 @@ void test_core_pool__0(void) git_pool_clear(&p); } -void test_core_pool__1(void) +void test_pool__1(void) { int i; git_pool p; @@ -50,37 +50,7 @@ void test_core_pool__1(void) git_pool_clear(&p); } -static char to_hex[] = "0123456789abcdef"; - -void test_core_pool__2(void) -{ - git_pool p; - char oid_hex[GIT_OID_HEXSZ]; - git_oid *oid; - int i, j; - - memset(oid_hex, '0', sizeof(oid_hex)); - - git_pool_init(&p, sizeof(git_oid)); - p.page_size = 4000; - - for (i = 1000; i < 10000; i++) { - oid = git_pool_malloc(&p, 1); - cl_assert(oid != NULL); - - for (j = 0; j < 8; j++) - oid_hex[j] = to_hex[(i >> (4 * j)) & 0x0f]; - cl_git_pass(git_oid_fromstr(oid, oid_hex)); - } - -#ifndef GIT_DEBUG_POOL - /* with fixed page size, allocation must end up with these values */ - cl_assert_equal_i(sizeof(void *) == 8 ? 55 : 45, git_pool__open_pages(&p)); -#endif - git_pool_clear(&p); -} - -void test_core_pool__strndup_limit(void) +void test_pool__strndup_limit(void) { git_pool p; diff --git a/tests/core/posix.c b/tests/util/posix.c similarity index 95% rename from tests/core/posix.c rename to tests/util/posix.c index cba312913f4..155f03a952b 100644 --- a/tests/core/posix.c +++ b/tests/util/posix.c @@ -13,7 +13,7 @@ #include "futils.h" #include "posix.h" -void test_core_posix__initialize(void) +void test_posix__initialize(void) { #ifdef GIT_WIN32 /* on win32, the WSA context needs to be initialized @@ -35,7 +35,7 @@ static bool supports_ipv6(void) #endif } -void test_core_posix__inet_pton(void) +void test_posix__inet_pton(void) { struct in_addr addr; struct in6_addr addr6; @@ -96,7 +96,7 @@ void test_core_posix__inet_pton(void) cl_assert_equal_i(EAFNOSUPPORT, errno); } -void test_core_posix__utimes(void) +void test_posix__utimes(void) { struct p_timeval times[2]; struct stat st; @@ -145,7 +145,7 @@ void test_core_posix__utimes(void) cl_must_pass(p_unlink("foo")); } -void test_core_posix__unlink_removes_symlink(void) +void test_posix__unlink_removes_symlink(void) { if (!git_fs_path_supports_symlinks(clar_sandbox_path())) clar__skip(); @@ -166,7 +166,7 @@ void test_core_posix__unlink_removes_symlink(void) cl_must_pass(p_rmdir("dir")); } -void test_core_posix__symlink_resolves_to_correct_type(void) +void test_posix__symlink_resolves_to_correct_type(void) { git_str contents = GIT_STR_INIT; @@ -190,7 +190,7 @@ void test_core_posix__symlink_resolves_to_correct_type(void) git_str_dispose(&contents); } -void test_core_posix__relative_symlink(void) +void test_posix__relative_symlink(void) { git_str contents = GIT_STR_INIT; @@ -210,7 +210,7 @@ void test_core_posix__relative_symlink(void) git_str_dispose(&contents); } -void test_core_posix__symlink_to_file_across_dirs(void) +void test_posix__symlink_to_file_across_dirs(void) { git_str contents = GIT_STR_INIT; diff --git a/tests/core/pqueue.c b/tests/util/pqueue.c similarity index 91% rename from tests/core/pqueue.c rename to tests/util/pqueue.c index 2b90f41721e..38931ecfd74 100644 --- a/tests/core/pqueue.c +++ b/tests/util/pqueue.c @@ -7,7 +7,7 @@ static int cmp_ints(const void *v1, const void *v2) return (i1 < i2) ? -1 : (i1 > i2) ? 1 : 0; } -void test_core_pqueue__items_are_put_in_order(void) +void test_pqueue__items_are_put_in_order(void) { git_pqueue pq; int i, vals[20]; @@ -36,7 +36,7 @@ void test_core_pqueue__items_are_put_in_order(void) git_pqueue_free(&pq); } -void test_core_pqueue__interleave_inserts_and_pops(void) +void test_pqueue__interleave_inserts_and_pops(void) { git_pqueue pq; int chunk, v, i, vals[200]; @@ -70,7 +70,7 @@ void test_core_pqueue__interleave_inserts_and_pops(void) git_pqueue_free(&pq); } -void test_core_pqueue__max_heap_size(void) +void test_pqueue__max_heap_size(void) { git_pqueue pq; int i, vals[100]; @@ -95,7 +95,7 @@ void test_core_pqueue__max_heap_size(void) git_pqueue_free(&pq); } -void test_core_pqueue__max_heap_size_without_comparison(void) +void test_pqueue__max_heap_size_without_comparison(void) { git_pqueue pq; int i, vals[100] = { 0 }; @@ -123,7 +123,7 @@ static int cmp_ints_like_commit_time(const void *a, const void *b) return *((const int *)a) < *((const int *)b); } -void test_core_pqueue__interleaved_pushes_and_pops(void) +void test_pqueue__interleaved_pushes_and_pops(void) { git_pqueue pq; int i, j, *val; diff --git a/tests/util/precompiled.c b/tests/util/precompiled.c new file mode 100644 index 00000000000..5f656a45da8 --- /dev/null +++ b/tests/util/precompiled.c @@ -0,0 +1 @@ +#include "precompiled.h" diff --git a/tests/util/precompiled.h b/tests/util/precompiled.h new file mode 100644 index 00000000000..6fa21423b4b --- /dev/null +++ b/tests/util/precompiled.h @@ -0,0 +1,3 @@ +#include "common.h" +#include "clar.h" +#include "clar_libgit2.h" diff --git a/tests/core/qsort.c b/tests/util/qsort.c similarity index 87% rename from tests/core/qsort.c rename to tests/util/qsort.c index efb79e6e97a..d8fa20a0a5d 100644 --- a/tests/core/qsort.c +++ b/tests/util/qsort.c @@ -38,37 +38,37 @@ static int cmp_str(const void *_a, const void *_b, void *payload) return strcmp((const char *) _a, (const char *) _b); } -void test_core_qsort__array_with_single_entry(void) +void test_qsort__array_with_single_entry(void) { int a[] = { 10 }; assert_sorted(a, cmp_int); } -void test_core_qsort__array_with_equal_entries(void) +void test_qsort__array_with_equal_entries(void) { int a[] = { 4, 4, 4, 4 }; assert_sorted(a, cmp_int); } -void test_core_qsort__sorted_array(void) +void test_qsort__sorted_array(void) { int a[] = { 1, 10 }; assert_sorted(a, cmp_int); } -void test_core_qsort__unsorted_array(void) +void test_qsort__unsorted_array(void) { int a[] = { 123, 9, 412938, 10, 234, 89 }; assert_sorted(a, cmp_int); } -void test_core_qsort__sorting_strings(void) +void test_qsort__sorting_strings(void) { char *a[] = { "foo", "bar", "baz" }; assert_sorted(a, cmp_str); } -void test_core_qsort__sorting_big_entries(void) +void test_qsort__sorting_big_entries(void) { struct big_entries a[5]; diff --git a/tests/core/regexp.c b/tests/util/regexp.c similarity index 75% rename from tests/core/regexp.c rename to tests/util/regexp.c index 8db5641e5e4..a76955d59ce 100644 --- a/tests/core/regexp.c +++ b/tests/util/regexp.c @@ -3,7 +3,6 @@ #include #include "regexp.h" -#include "userdiff.h" #if LC_ALL > 0 static const char *old_locales[LC_ALL]; @@ -11,14 +10,14 @@ static const char *old_locales[LC_ALL]; static git_regexp regex; -void test_core_regexp__initialize(void) +void test_regexp__initialize(void) { #if LC_ALL > 0 memset(&old_locales, 0, sizeof(old_locales)); #endif } -void test_core_regexp__cleanup(void) +void test_regexp__cleanup(void) { git_regexp_dispose(®ex); } @@ -39,13 +38,13 @@ static void try_set_locale(int category) } -void test_core_regexp__compile_ignores_global_locale_ctype(void) +void test_regexp__compile_ignores_global_locale_ctype(void) { try_set_locale(LC_CTYPE); cl_git_pass(git_regexp_compile(®ex, "[\xc0-\xff][\x80-\xbf]", 0)); } -void test_core_regexp__compile_ignores_global_locale_collate(void) +void test_regexp__compile_ignores_global_locale_collate(void) { #ifdef GIT_WIN32 cl_skip(); @@ -55,7 +54,7 @@ void test_core_regexp__compile_ignores_global_locale_collate(void) cl_git_pass(git_regexp_compile(®ex, "[\xc0-\xff][\x80-\xbf]", 0)); } -void test_core_regexp__regex_matches_digits_with_locale(void) +void test_regexp__regex_matches_digits_with_locale(void) { char c, str[2]; @@ -75,7 +74,7 @@ void test_core_regexp__regex_matches_digits_with_locale(void) } } -void test_core_regexp__regex_matches_alphabet_with_locale(void) +void test_regexp__regex_matches_alphabet_with_locale(void) { char c, str[2]; @@ -99,40 +98,25 @@ void test_core_regexp__regex_matches_alphabet_with_locale(void) } } -void test_core_regexp__compile_userdiff_regexps(void) -{ - size_t idx; - - for (idx = 0; idx < ARRAY_SIZE(builtin_defs); ++idx) { - git_diff_driver_definition ddef = builtin_defs[idx]; - - cl_git_pass(git_regexp_compile(®ex, ddef.fns, ddef.flags)); - git_regexp_dispose(®ex); - - cl_git_pass(git_regexp_compile(®ex, ddef.words, 0)); - git_regexp_dispose(®ex); - } -} - -void test_core_regexp__simple_search_matches(void) +void test_regexp__simple_search_matches(void) { cl_git_pass(git_regexp_compile(®ex, "a", 0)); cl_git_pass(git_regexp_search(®ex, "a", 0, NULL)); } -void test_core_regexp__case_insensitive_search_matches(void) +void test_regexp__case_insensitive_search_matches(void) { cl_git_pass(git_regexp_compile(®ex, "a", GIT_REGEXP_ICASE)); cl_git_pass(git_regexp_search(®ex, "A", 0, NULL)); } -void test_core_regexp__nonmatching_search_returns_error(void) +void test_regexp__nonmatching_search_returns_error(void) { cl_git_pass(git_regexp_compile(®ex, "a", 0)); cl_git_fail(git_regexp_search(®ex, "b", 0, NULL)); } -void test_core_regexp__search_finds_complete_match(void) +void test_regexp__search_finds_complete_match(void) { git_regmatch matches[1]; @@ -142,7 +126,7 @@ void test_core_regexp__search_finds_complete_match(void) cl_assert_equal_i(matches[0].end, 3); } -void test_core_regexp__search_finds_correct_offsets(void) +void test_regexp__search_finds_correct_offsets(void) { git_regmatch matches[3]; @@ -156,7 +140,7 @@ void test_core_regexp__search_finds_correct_offsets(void) cl_assert_equal_i(matches[2].end, 2); } -void test_core_regexp__search_finds_empty_group(void) +void test_regexp__search_finds_empty_group(void) { git_regmatch matches[3]; @@ -170,7 +154,7 @@ void test_core_regexp__search_finds_empty_group(void) cl_assert_equal_i(matches[2].end, 1); } -void test_core_regexp__search_fills_matches_with_first_matching_groups(void) +void test_regexp__search_fills_matches_with_first_matching_groups(void) { git_regmatch matches[2]; @@ -182,7 +166,7 @@ void test_core_regexp__search_fills_matches_with_first_matching_groups(void) cl_assert_equal_i(matches[1].end, 1); } -void test_core_regexp__search_skips_nonmatching_group(void) +void test_regexp__search_skips_nonmatching_group(void) { git_regmatch matches[4]; @@ -198,7 +182,7 @@ void test_core_regexp__search_skips_nonmatching_group(void) cl_assert_equal_i(matches[3].end, 2); } -void test_core_regexp__search_initializes_trailing_nonmatching_groups(void) +void test_regexp__search_initializes_trailing_nonmatching_groups(void) { git_regmatch matches[3]; diff --git a/tests/core/rmdir.c b/tests/util/rmdir.c similarity index 91% rename from tests/core/rmdir.c rename to tests/util/rmdir.c index f6c66b3a44a..71ec05f9bab 100644 --- a/tests/core/rmdir.c +++ b/tests/util/rmdir.c @@ -3,7 +3,7 @@ static const char *empty_tmp_dir = "test_gitfo_rmdir_recurs_test"; -void test_core_rmdir__initialize(void) +void test_rmdir__initialize(void) { git_str path = GIT_STR_INIT; @@ -27,14 +27,14 @@ void test_core_rmdir__initialize(void) git_str_dispose(&path); } -void test_core_rmdir__cleanup(void) +void test_rmdir__cleanup(void) { if (git_fs_path_exists(empty_tmp_dir)) cl_git_pass(git_futils_rmdir_r(empty_tmp_dir, NULL, GIT_RMDIR_REMOVE_FILES)); } /* make sure empty dir can be deleted recursively */ -void test_core_rmdir__delete_recursive(void) +void test_rmdir__delete_recursive(void) { git_str path = GIT_STR_INIT; cl_git_pass(git_str_joinpath(&path, empty_tmp_dir, "/one")); @@ -48,7 +48,7 @@ void test_core_rmdir__delete_recursive(void) } /* make sure non-empty dir cannot be deleted recursively */ -void test_core_rmdir__fail_to_delete_non_empty_dir(void) +void test_rmdir__fail_to_delete_non_empty_dir(void) { git_str file = GIT_STR_INIT; @@ -66,13 +66,13 @@ void test_core_rmdir__fail_to_delete_non_empty_dir(void) git_str_dispose(&file); } -void test_core_rmdir__keep_base(void) +void test_rmdir__keep_base(void) { cl_git_pass(git_futils_rmdir_r(empty_tmp_dir, NULL, GIT_RMDIR_SKIP_ROOT)); cl_assert(git_fs_path_exists(empty_tmp_dir)); } -void test_core_rmdir__can_skip_non_empty_dir(void) +void test_rmdir__can_skip_non_empty_dir(void) { git_str file = GIT_STR_INIT; @@ -89,7 +89,7 @@ void test_core_rmdir__can_skip_non_empty_dir(void) git_str_dispose(&file); } -void test_core_rmdir__can_remove_empty_parents(void) +void test_rmdir__can_remove_empty_parents(void) { git_str file = GIT_STR_INIT; diff --git a/tests/core/sha1.c b/tests/util/sha1.c similarity index 91% rename from tests/core/sha1.c rename to tests/util/sha1.c index 9ccdaab3ce5..68982758e9c 100644 --- a/tests/core/sha1.c +++ b/tests/util/sha1.c @@ -3,12 +3,12 @@ #define FIXTURE_DIR "sha1" -void test_core_sha1__initialize(void) +void test_sha1__initialize(void) { cl_fixture_sandbox(FIXTURE_DIR); } -void test_core_sha1__cleanup(void) +void test_sha1__cleanup(void) { cl_fixture_cleanup(FIXTURE_DIR); } @@ -37,7 +37,7 @@ static int sha1_file(unsigned char *out, const char *filename) return ret; } -void test_core_sha1__sum(void) +void test_sha1__sum(void) { unsigned char expected[GIT_HASH_SHA1_SIZE] = { 0x4e, 0x72, 0x67, 0x9e, 0x3e, 0xa4, 0xd0, 0x4e, 0x0c, 0x64, @@ -50,7 +50,7 @@ void test_core_sha1__sum(void) } /* test that sha1 collision detection works when enabled */ -void test_core_sha1__detect_collision_attack(void) +void test_sha1__detect_collision_attack(void) { unsigned char actual[GIT_HASH_SHA1_SIZE]; unsigned char expected[GIT_HASH_SHA1_SIZE] = { diff --git a/tests/core/sortedcache.c b/tests/util/sortedcache.c similarity index 98% rename from tests/core/sortedcache.c rename to tests/util/sortedcache.c index cb4e34efaaf..72da7aeb1f1 100644 --- a/tests/core/sortedcache.c +++ b/tests/util/sortedcache.c @@ -6,7 +6,7 @@ static int name_only_cmp(const void *a, const void *b) return strcmp(a, b); } -void test_core_sortedcache__name_only(void) +void test_sortedcache__name_only(void) { git_sortedcache *sc; void *item; @@ -84,7 +84,7 @@ static void sortedcache_test_struct_free(void *payload, void *item_) item->smaller_value = 0; } -void test_core_sortedcache__in_memory(void) +void test_sortedcache__in_memory(void) { git_sortedcache *sc; sortedcache_test_struct *item; @@ -269,7 +269,7 @@ static void sortedcache_test_reload(git_sortedcache *sc) git_str_dispose(&buf); } -void test_core_sortedcache__on_disk(void) +void test_sortedcache__on_disk(void) { git_sortedcache *sc; sortedcache_test_struct *item; diff --git a/tests/core/stat.c b/tests/util/stat.c similarity index 95% rename from tests/core/stat.c rename to tests/util/stat.c index 210072fe3a2..84c23fb21eb 100644 --- a/tests/core/stat.c +++ b/tests/util/stat.c @@ -2,14 +2,14 @@ #include "futils.h" #include "posix.h" -void test_core_stat__initialize(void) +void test_stat__initialize(void) { cl_git_pass(git_futils_mkdir("root/d1/d2", 0755, GIT_MKDIR_PATH)); cl_git_mkfile("root/file", "whatever\n"); cl_git_mkfile("root/d1/file", "whatever\n"); } -void test_core_stat__cleanup(void) +void test_stat__cleanup(void) { git_futils_rmdir_r("root", NULL, GIT_RMDIR_REMOVE_FILES); } @@ -17,7 +17,7 @@ void test_core_stat__cleanup(void) #define cl_assert_error(val) \ do { err = errno; cl_assert_equal_i((val), err); } while (0) -void test_core_stat__0(void) +void test_stat__0(void) { struct stat st; int err; @@ -94,7 +94,7 @@ void test_core_stat__0(void) cl_assert_error(ENOTDIR); } -void test_core_stat__root(void) +void test_stat__root(void) { const char *sandbox = clar_sandbox_path(); git_str root = GIT_STR_INIT; diff --git a/tests/str/basic.c b/tests/util/str/basic.c similarity index 100% rename from tests/str/basic.c rename to tests/util/str/basic.c diff --git a/tests/str/oom.c b/tests/util/str/oom.c similarity index 90% rename from tests/str/oom.c rename to tests/util/str/oom.c index 3d59ead0197..dd3796674f6 100644 --- a/tests/str/oom.c +++ b/tests/util/str/oom.c @@ -25,12 +25,12 @@ void test_str_oom__initialize(void) oom_alloc.gmalloc = oom_malloc; oom_alloc.grealloc = oom_realloc; - cl_git_pass(git_libgit2_opts(GIT_OPT_SET_ALLOCATOR, &oom_alloc)); + cl_git_pass(git_allocator_setup(&oom_alloc)); } void test_str_oom__cleanup(void) { - cl_git_pass(git_libgit2_opts(GIT_OPT_SET_ALLOCATOR, NULL)); + cl_git_pass(git_allocator_setup(NULL)); } void test_str_oom__grow(void) diff --git a/tests/str/percent.c b/tests/util/str/percent.c similarity index 100% rename from tests/str/percent.c rename to tests/util/str/percent.c diff --git a/tests/str/quote.c b/tests/util/str/quote.c similarity index 100% rename from tests/str/quote.c rename to tests/util/str/quote.c diff --git a/tests/str/splice.c b/tests/util/str/splice.c similarity index 100% rename from tests/str/splice.c rename to tests/util/str/splice.c diff --git a/tests/core/string.c b/tests/util/string.c similarity index 94% rename from tests/core/string.c rename to tests/util/string.c index 928dfbcc1fc..de04dea6983 100644 --- a/tests/core/string.c +++ b/tests/util/string.c @@ -1,7 +1,7 @@ #include "clar_libgit2.h" /* compare prefixes */ -void test_core_string__0(void) +void test_string__0(void) { cl_assert(git__prefixcmp("", "") == 0); cl_assert(git__prefixcmp("a", "") == 0); @@ -14,7 +14,7 @@ void test_core_string__0(void) } /* compare suffixes */ -void test_core_string__1(void) +void test_string__1(void) { cl_assert(git__suffixcmp("", "") == 0); cl_assert(git__suffixcmp("a", "") == 0); @@ -27,7 +27,7 @@ void test_core_string__1(void) } /* compare icase sorting with case equality */ -void test_core_string__2(void) +void test_string__2(void) { cl_assert(git__strcasesort_cmp("", "") == 0); cl_assert(git__strcasesort_cmp("foo", "foo") == 0); @@ -41,7 +41,7 @@ void test_core_string__2(void) } /* compare prefixes with len */ -void test_core_string__prefixncmp(void) +void test_string__prefixncmp(void) { cl_assert(git__prefixncmp("", 0, "") == 0); cl_assert(git__prefixncmp("a", 1, "") == 0); @@ -58,7 +58,7 @@ void test_core_string__prefixncmp(void) } /* compare prefixes with len */ -void test_core_string__prefixncmp_icase(void) +void test_string__prefixncmp_icase(void) { cl_assert(git__prefixncmp_icase("", 0, "") == 0); cl_assert(git__prefixncmp_icase("a", 1, "") == 0); @@ -82,7 +82,7 @@ void test_core_string__prefixncmp_icase(void) cl_assert(git__prefixncmp_icase("ab", 1, "aa") < 0); } -void test_core_string__strcmp(void) +void test_string__strcmp(void) { cl_assert(git__strcmp("", "") == 0); cl_assert(git__strcmp("foo", "foo") == 0); @@ -103,7 +103,7 @@ void test_core_string__strcmp(void) cl_assert(git__strcmp("\303\215", "\303\255") < 0); } -void test_core_string__strcasecmp(void) +void test_string__strcasecmp(void) { cl_assert(git__strcasecmp("", "") == 0); cl_assert(git__strcasecmp("foo", "foo") == 0); @@ -124,7 +124,7 @@ void test_core_string__strcasecmp(void) cl_assert(git__strcasecmp("\303\215", "\303\255") < 0); } -void test_core_string__strlcmp(void) +void test_string__strlcmp(void) { const char foo[3] = { 'f', 'o', 'o' }; diff --git a/tests/core/strmap.c b/tests/util/strmap.c similarity index 85% rename from tests/core/strmap.c rename to tests/util/strmap.c index ba118ae1e56..c4f5c864704 100644 --- a/tests/core/strmap.c +++ b/tests/util/strmap.c @@ -3,18 +3,18 @@ static git_strmap *g_table; -void test_core_strmap__initialize(void) +void test_strmap__initialize(void) { cl_git_pass(git_strmap_new(&g_table)); cl_assert(g_table != NULL); } -void test_core_strmap__cleanup(void) +void test_strmap__cleanup(void) { git_strmap_free(g_table); } -void test_core_strmap__0(void) +void test_strmap__0(void) { cl_assert(git_strmap_size(g_table) == 0); } @@ -40,7 +40,7 @@ static void insert_strings(git_strmap *table, size_t count) cl_assert_equal_i(git_strmap_size(table), count); } -void test_core_strmap__inserted_strings_can_be_retrieved(void) +void test_strmap__inserted_strings_can_be_retrieved(void) { char *str; int i; @@ -57,7 +57,7 @@ void test_core_strmap__inserted_strings_can_be_retrieved(void) cl_assert(i == 20); } -void test_core_strmap__deleted_entry_cannot_be_retrieved(void) +void test_strmap__deleted_entry_cannot_be_retrieved(void) { char *str; int i; @@ -77,7 +77,7 @@ void test_core_strmap__deleted_entry_cannot_be_retrieved(void) cl_assert_equal_i(i, 19); } -void test_core_strmap__inserting_many_keys_succeeds(void) +void test_strmap__inserting_many_keys_succeeds(void) { char *str; int i; @@ -89,7 +89,7 @@ void test_core_strmap__inserting_many_keys_succeeds(void) cl_assert_equal_i(i, 10000); } -void test_core_strmap__get_succeeds_with_existing_entries(void) +void test_strmap__get_succeeds_with_existing_entries(void) { const char *keys[] = { "foo", "bar", "gobble" }; char *values[] = { "oof", "rab", "elbbog" }; @@ -103,7 +103,7 @@ void test_core_strmap__get_succeeds_with_existing_entries(void) cl_assert_equal_s(git_strmap_get(g_table, "gobble"), "elbbog"); } -void test_core_strmap__get_returns_null_on_nonexisting_key(void) +void test_strmap__get_returns_null_on_nonexisting_key(void) { const char *keys[] = { "foo", "bar", "gobble" }; char *values[] = { "oof", "rab", "elbbog" }; @@ -115,13 +115,13 @@ void test_core_strmap__get_returns_null_on_nonexisting_key(void) cl_assert_equal_p(git_strmap_get(g_table, "other"), NULL); } -void test_core_strmap__set_persists_key(void) +void test_strmap__set_persists_key(void) { cl_git_pass(git_strmap_set(g_table, "foo", "oof")); cl_assert_equal_s(git_strmap_get(g_table, "foo"), "oof"); } -void test_core_strmap__set_persists_multpile_keys(void) +void test_strmap__set_persists_multpile_keys(void) { cl_git_pass(git_strmap_set(g_table, "foo", "oof")); cl_git_pass(git_strmap_set(g_table, "bar", "rab")); @@ -129,7 +129,7 @@ void test_core_strmap__set_persists_multpile_keys(void) cl_assert_equal_s(git_strmap_get(g_table, "bar"), "rab"); } -void test_core_strmap__set_updates_existing_key(void) +void test_strmap__set_updates_existing_key(void) { cl_git_pass(git_strmap_set(g_table, "foo", "oof")); cl_git_pass(git_strmap_set(g_table, "bar", "rab")); @@ -142,7 +142,7 @@ void test_core_strmap__set_updates_existing_key(void) cl_assert_equal_s(git_strmap_get(g_table, "foo"), "other"); } -void test_core_strmap__iteration(void) +void test_strmap__iteration(void) { struct { char *key; @@ -182,7 +182,7 @@ void test_core_strmap__iteration(void) cl_assert_equal_i(n, ARRAY_SIZE(entries)); } -void test_core_strmap__iterating_empty_map_stops_immediately(void) +void test_strmap__iterating_empty_map_stops_immediately(void) { size_t i = 0; diff --git a/tests/core/strtol.c b/tests/util/strtol.c similarity index 88% rename from tests/core/strtol.c rename to tests/util/strtol.c index 851b91b0a40..54c63ca08fd 100644 --- a/tests/core/strtol.c +++ b/tests/util/strtol.c @@ -26,7 +26,7 @@ static void assert_l64_fails(const char *string, int base) cl_git_fail(git__strntol64(&i, string, strlen(string), NULL, base)); } -void test_core_strtol__int32(void) +void test_strtol__int32(void) { assert_l32_parses("123", 123, 10); assert_l32_parses(" +123 ", 123, 10); @@ -43,7 +43,7 @@ void test_core_strtol__int32(void) assert_l32_fails(" -2147483657 ", 10); } -void test_core_strtol__int64(void) +void test_strtol__int64(void) { assert_l64_parses("123", 123, 10); assert_l64_parses(" +123 ", 123, 10); @@ -66,7 +66,7 @@ void test_core_strtol__int64(void) assert_l64_fails("-0x8000000000000001", 16); } -void test_core_strtol__base_autodetection(void) +void test_strtol__base_autodetection(void) { assert_l64_parses("0", 0, 0); assert_l64_parses("00", 0, 0); @@ -78,7 +78,7 @@ void test_core_strtol__base_autodetection(void) assert_l64_parses("0x18", 24, 0); } -void test_core_strtol__buffer_length_with_autodetection_truncates(void) +void test_strtol__buffer_length_with_autodetection_truncates(void) { int64_t i64; @@ -88,7 +88,7 @@ void test_core_strtol__buffer_length_with_autodetection_truncates(void) cl_assert_equal_i(i64, 1); } -void test_core_strtol__buffer_length_truncates(void) +void test_strtol__buffer_length_truncates(void) { int32_t i32; int64_t i64; @@ -100,7 +100,7 @@ void test_core_strtol__buffer_length_truncates(void) cl_assert_equal_i(i64, 1); } -void test_core_strtol__buffer_length_with_leading_ws_truncates(void) +void test_strtol__buffer_length_with_leading_ws_truncates(void) { int64_t i64; @@ -110,7 +110,7 @@ void test_core_strtol__buffer_length_with_leading_ws_truncates(void) cl_assert_equal_i(i64, 1); } -void test_core_strtol__buffer_length_with_leading_sign_truncates(void) +void test_strtol__buffer_length_with_leading_sign_truncates(void) { int64_t i64; @@ -120,7 +120,7 @@ void test_core_strtol__buffer_length_with_leading_sign_truncates(void) cl_assert_equal_i(i64, -1); } -void test_core_strtol__error_message_cuts_off(void) +void test_strtol__error_message_cuts_off(void) { assert_l32_fails("2147483657foobar", 10); cl_assert(strstr(git_error_last()->message, "2147483657") != NULL); diff --git a/tests/core/utf8.c b/tests/util/utf8.c similarity index 95% rename from tests/core/utf8.c rename to tests/util/utf8.c index e1987b8d631..3987603bb1a 100644 --- a/tests/core/utf8.c +++ b/tests/util/utf8.c @@ -1,7 +1,7 @@ #include "clar_libgit2.h" #include "utf8.h" -void test_core_utf8__char_length(void) +void test_utf8__char_length(void) { cl_assert_equal_i(0, git_utf8_char_length("", 0)); cl_assert_equal_i(1, git_utf8_char_length("$", 1)); diff --git a/tests/core/vector.c b/tests/util/vector.c similarity index 96% rename from tests/core/vector.c rename to tests/util/vector.c index 08cd2c19bf9..04afaa49658 100644 --- a/tests/core/vector.c +++ b/tests/util/vector.c @@ -4,7 +4,7 @@ #include "vector.h" /* initial size of 1 would cause writing past array bounds */ -void test_core_vector__0(void) +void test_vector__0(void) { git_vector x; int i; @@ -17,7 +17,7 @@ void test_core_vector__0(void) /* don't read past array bounds on remove() */ -void test_core_vector__1(void) +void test_vector__1(void) { git_vector x; /* make initial capacity exact for our insertions. */ @@ -37,7 +37,7 @@ static int test_cmp(const void *a, const void *b) } /* remove duplicates */ -void test_core_vector__2(void) +void test_vector__2(void) { git_vector x; int *ptrs[2]; @@ -72,7 +72,7 @@ static int compare_them(const void *a, const void *b) } /* insert_sorted */ -void test_core_vector__3(void) +void test_vector__3(void) { git_vector x; intptr_t i; @@ -95,7 +95,7 @@ void test_core_vector__3(void) } /* insert_sorted with duplicates */ -void test_core_vector__4(void) +void test_vector__4(void) { git_vector x; intptr_t i; @@ -158,7 +158,7 @@ static my_struct *alloc_struct(int value) } /* insert_sorted with duplicates and special handling */ -void test_core_vector__5(void) +void test_vector__5(void) { git_vector x; int i; @@ -199,7 +199,7 @@ static int remove_ones(const git_vector *v, size_t idx, void *p) } /* Test removal based on callback */ -void test_core_vector__remove_matching(void) +void test_vector__remove_matching(void) { git_vector x; size_t i; @@ -287,7 +287,7 @@ static void assert_vector(git_vector *x, void *expected[], size_t len) cl_assert(expected[i] == x->contents[i]); } -void test_core_vector__grow_and_shrink(void) +void test_vector__grow_and_shrink(void) { git_vector x = GIT_VECTOR_INIT; void *expected1[] = { @@ -379,7 +379,7 @@ void test_core_vector__grow_and_shrink(void) git_vector_free(&x); } -void test_core_vector__reverse(void) +void test_vector__reverse(void) { git_vector v = GIT_VECTOR_INIT; size_t i; @@ -410,7 +410,7 @@ void test_core_vector__reverse(void) git_vector_free(&v); } -void test_core_vector__dup_empty_vector(void) +void test_vector__dup_empty_vector(void) { git_vector v = GIT_VECTOR_INIT; git_vector dup = GIT_VECTOR_INIT; diff --git a/tests/core/wildmatch.c b/tests/util/wildmatch.c similarity index 96% rename from tests/core/wildmatch.c rename to tests/util/wildmatch.c index 7c56ee7b836..a5af61ab4b3 100644 --- a/tests/core/wildmatch.c +++ b/tests/util/wildmatch.c @@ -26,7 +26,7 @@ static void assert_matches_(const char *string, const char *pattern, * tests for git-ls-files. */ -void test_core_wildmatch__basic_wildmatch(void) +void test_wildmatch__basic_wildmatch(void) { assert_matches("foo", "foo", 1, 1, 1, 1); assert_matches("foo", "bar", 0, 0, 0, 0); @@ -58,7 +58,7 @@ void test_core_wildmatch__basic_wildmatch(void) assert_matches("]", "]", 1, 1, 1, 1); } -void test_core_wildmatch__slash_matching_features(void) +void test_wildmatch__slash_matching_features(void) { assert_matches("foo/baz/bar", "foo*bar", 0, 0, 1, 1); assert_matches("foo/baz/bar", "foo**bar", 0, 0, 1, 1); @@ -90,7 +90,7 @@ void test_core_wildmatch__slash_matching_features(void) assert_matches("deep/foo/bar/baz/x", "**/bar/*/*", 1, 1, 1, 1); } -void test_core_wildmatch__various_additional(void) +void test_wildmatch__various_additional(void) { assert_matches("acrt", "a[c-c]st", 0, 0, 0, 0); assert_matches("acrt", "a[c-c]rt", 1, 1, 1, 1); @@ -115,7 +115,7 @@ void test_core_wildmatch__various_additional(void) assert_matches("foo/bar/baz/to", "**/t[o]", 1, 1, 1, 1); } -void test_core_wildmatch__character_classes(void) +void test_wildmatch__character_classes(void) { assert_matches("a1B", "[[:alpha:]][[:digit:]][[:upper:]]", 1, 1, 1, 1); assert_matches("a", "[[:digit:][:upper:][:space:]]", 0, 1, 0, 1); @@ -136,7 +136,7 @@ void test_core_wildmatch__character_classes(void) assert_matches("q", "[a-c[:digit:]x-z]", 0, 0, 0, 0); } -void test_core_wildmatch__additional_with_malformed(void) +void test_wildmatch__additional_with_malformed(void) { assert_matches("]", "[\\\\-^]", 1, 1, 1, 1); assert_matches("[", "[\\\\-^]", 0, 0, 0, 0); @@ -190,7 +190,7 @@ void test_core_wildmatch__additional_with_malformed(void) assert_matches("-", "[[-\\]]", 0, 0, 0, 0); } -void test_core_wildmatch__recursion(void) +void test_wildmatch__recursion(void) { assert_matches("-adobe-courier-bold-o-normal--12-120-75-75-m-70-iso8859-1", "-*-*-*-*-*-*-12-*-*-*-m-*-*-*", 1, 1, 1, 1); assert_matches("-adobe-courier-bold-o-normal--12-120-75-75-X-70-iso8859-1", "-*-*-*-*-*-*-12-*-*-*-m-*-*-*", 0, 0, 0, 0); @@ -210,7 +210,7 @@ void test_core_wildmatch__recursion(void) assert_matches("ab/cXd/efXg/hi", "**/*X*/**/*i", 1, 1, 1, 1); } -void test_core_wildmatch__pathmatch(void) +void test_wildmatch__pathmatch(void) { assert_matches("foo", "fo", 0, 0, 0, 0); assert_matches("foo/bar", "foo/bar", 1, 1, 1, 1); @@ -229,7 +229,7 @@ void test_core_wildmatch__pathmatch(void) assert_matches("ab/cXd/efXg/hi", "*Xg*i", 0, 0, 1, 1); } -void test_core_wildmatch__case_sensitivity(void) +void test_wildmatch__case_sensitivity(void) { assert_matches("a", "[A-Z]", 0, 1, 0, 1); assert_matches("A", "[A-Z]", 1, 1, 1, 1); diff --git a/tests/core/zstream.c b/tests/util/zstream.c similarity index 96% rename from tests/core/zstream.c rename to tests/util/zstream.c index c22e81008b6..5c89895c7ce 100644 --- a/tests/core/zstream.c +++ b/tests/util/zstream.c @@ -41,7 +41,7 @@ static void assert_zlib_equal_( #define assert_zlib_equal(E,EL,C,CL) \ assert_zlib_equal_(E, EL, C, CL, #EL " != " #CL, __FILE__, __func__, (int)__LINE__) -void test_core_zstream__basic(void) +void test_zstream__basic(void) { git_zstream z = GIT_ZSTREAM_INIT; char out[128]; @@ -57,7 +57,7 @@ void test_core_zstream__basic(void) assert_zlib_equal(data, strlen(data) + 1, out, outlen); } -void test_core_zstream__fails_on_trailing_garbage(void) +void test_zstream__fails_on_trailing_garbage(void) { git_str deflated = GIT_STR_INIT, inflated = GIT_STR_INIT; char i = 0; @@ -76,7 +76,7 @@ void test_core_zstream__fails_on_trailing_garbage(void) git_str_dispose(&inflated); } -void test_core_zstream__buffer(void) +void test_zstream__buffer(void) { git_str out = GIT_STR_INIT; cl_git_pass(git_zstream_deflatebuf(&out, data, strlen(data) + 1)); @@ -140,7 +140,7 @@ static void compress_and_decompress_input_various_ways(git_str *input) git__free(fixed); } -void test_core_zstream__big_data(void) +void test_zstream__big_data(void) { git_str in = GIT_STR_INIT; size_t scan, target;