Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -8,3 +8,7 @@ rust-version = "1.49.0"
crate-type = ["staticlib"]

[dependencies]
sha1dc = { version = "0.1.5", optional = true }

[features]
sha1dc-rs = ["sha1dc"]
8 changes: 8 additions & 0 deletions Documentation/config/core.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -382,6 +382,14 @@ core.repositoryFormatVersion::
Internal variable identifying the repository format and layout
version. See linkgit:gitrepository-layout[5].

core.sha1dcBackend::
Select the collision-detecting SHA-1 implementation: `c` keeps the
original C code and is the default, `accel` selects accelerated C,
and `rust` selects the Rust implementation. Rust is available only
in builds with `DC_SHA1_RS`, and accelerated C can be omitted at build
time. Selecting an unavailable implementation is an error.
This setting has no effect with other SHA-1 backends.

core.sharedRepository::
When 'group' (or 'true'), the repository is made shareable between
several users in a group (making sure all the files and objects are
Expand Down
50 changes: 50 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -572,6 +572,13 @@ include shared.mak
# by the git project to migrate to using sha1collisiondetection as a
# submodule.
#
# Define DC_SHA1_RS to make the sha1dc Rust crate available via
# core.sha1dcBackend=rust. This requires Rust 1.87 or newer.
#
# The original C implementation remains the default. Select the faster
# sha1dc-accel code with core.sha1dcBackend=accel. Define DC_SHA1_NO_ACCEL
# to omit that implementation.
#
# === SHA-256 backend ===
#
# ==== Security ====
Expand Down Expand Up @@ -1564,6 +1571,7 @@ CLAR_TEST_SUITES += u-reftable-readwrite
CLAR_TEST_SUITES += u-reftable-stack
CLAR_TEST_SUITES += u-reftable-table
CLAR_TEST_SUITES += u-reftable-tree
CLAR_TEST_SUITES += u-sha1dc
CLAR_TEST_SUITES += u-strbuf
CLAR_TEST_SUITES += u-strcmp-offset
CLAR_TEST_SUITES += u-string-list
Expand Down Expand Up @@ -2159,6 +2167,23 @@ ifdef PPC_SHA1
$(error the PPC_SHA1 flag has been removed along with the PowerPC-specific SHA-1 implementation.)
endif

ifdef DC_SHA1_RS
ifdef NO_RUST
$(error DC_SHA1_RS requires Rust support)
endif
ifneq ($(strip $(OPENSSL_SHA1)$(BLK_SHA1)$(APPLE_COMMON_CRYPTO_SHA1)),)
$(error DC_SHA1_RS cannot be combined with another SHA-1 backend)
endif
ifdef DC_SHA1_EXTERNAL
$(error Only set DC_SHA1_RS or DC_SHA1_EXTERNAL, not both)
endif
ifdef DC_SHA1_SUBMODULE
ifneq ($(DC_SHA1_SUBMODULE),auto)
$(error Only set DC_SHA1_RS or DC_SHA1_SUBMODULE, not both)
endif
endif
endif

ifdef OPENSSL_SHA1
EXTLIBS += $(LIB_4_CRYPTO)
BASIC_CFLAGS += -DSHA1_OPENSSL
Expand All @@ -2173,6 +2198,14 @@ ifdef APPLE_COMMON_CRYPTO_SHA1
else
BASIC_CFLAGS += -DSHA1_DC
LIB_OBJS += sha1dc_git.o
ifdef DC_SHA1_RS
BASIC_CFLAGS += -DDC_SHA1_RS
CARGO_ARGS += --features sha1dc-rs
RUST_SOURCES += src/sha1dc_rs.rs
ifeq ($(uname_S),MINGW)
EXTLIBS += -luserenv
endif
endif
ifdef DC_SHA1_EXTERNAL
ifdef DC_SHA1_SUBMODULE
ifneq ($(DC_SHA1_SUBMODULE),auto)
Expand All @@ -2189,6 +2222,14 @@ ifdef DC_SHA1_SUBMODULE
else
LIB_OBJS += sha1dc/sha1.o
LIB_OBJS += sha1dc/ubc_check.o
endif
ifdef DC_SHA1_NO_ACCEL
BASIC_CFLAGS += -DDC_SHA1_NO_ACCEL
else
LIB_OBJS += sha1dc-accel/arm.o
LIB_OBJS += sha1dc-accel/sha1.o
LIB_OBJS += sha1dc-accel/ubc_check.o
LIB_OBJS += sha1dc-accel/x86.o
endif
BASIC_CFLAGS += \
-DSHA1DC_NO_STANDARD_INCLUDES \
Expand Down Expand Up @@ -3466,6 +3507,15 @@ check-sha1:: t/helper/test-tool$X
SP_SRC = $(filter-out $(THIRD_PARTY_SOURCES),$(patsubst %.o,%.c,$(OBJECTS)))
SP_OBJ = $(patsubst %.c,%.sp,$(SP_SRC))

# Sparse cannot suppress this warning only in the intrinsic headers.
sha1dc-accel/arm.sp sha1dc-accel/sha1.sp \
sha1dc-accel/ubc_check.sp sha1dc-accel/x86.sp \
$(UNIT_TEST_DIR)/u-sha1dc.sp: SP_EXTRA_FLAGS += -Wno-declaration-after-statement

# Sparse 0.6.4 cannot evaluate GCC's SIMD builtins.
sha1dc-accel/ubc_check.sp sha1dc-accel/x86.sp: \
SP_EXTRA_FLAGS += -DSHA1DC_ACCEL_PORTABLE_ONLY

$(SP_OBJ): %.sp: %.c %.o $(GENERATED_H)
$(QUIET_SP)cgcc -no-compile $(ALL_CFLAGS) $(EXTRA_CPPFLAGS) \
-Wsparse-error \
Expand Down
16 changes: 16 additions & 0 deletions compat/win32/pthread.c
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,22 @@ pthread_t pthread_self(void)
return t;
}

static BOOL CALLBACK win32_pthread_once(PINIT_ONCE once UNUSED,
PVOID parameter,
PVOID *context UNUSED)
{
(*(void (**)(void))parameter)();
return TRUE;
}

int pthread_once(pthread_once_t *once_control, void (*init_routine)(void))
{
if (!InitOnceExecuteOnce(once_control, win32_pthread_once,
&init_routine, NULL))
return err_win_to_posix(GetLastError());
return 0;
}

int pthread_cond_wait(pthread_cond_t *cond, pthread_mutex_t *mutex)
{
if (SleepConditionVariableCS(cond, mutex, INFINITE) == 0)
Expand Down
5 changes: 5 additions & 0 deletions compat/win32/pthread.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,11 @@ static inline int return_0(int i UNUSED) {
#define pthread_mutex_lock EnterCriticalSection
#define pthread_mutex_unlock LeaveCriticalSection

typedef INIT_ONCE pthread_once_t;
#define PTHREAD_ONCE_INIT INIT_ONCE_STATIC_INIT

int pthread_once(pthread_once_t *once_control, void (*init_routine)(void));

typedef int pthread_mutexattr_t;
#define pthread_mutexattr_init(a) (*(a) = 0)
#define pthread_mutexattr_destroy(a) do {} while (0)
Expand Down
2 changes: 1 addition & 1 deletion contrib/buildsystems/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -244,7 +244,7 @@ add_compile_definitions(NO_OPENSSL SHA1_DC SHA1DC_NO_STANDARD_INCLUDES
SHA1DC_INIT_SAFE_HASH_DEFAULT=0
SHA1DC_CUSTOM_INCLUDE_SHA1_C="git-compat-util.h"
SHA1DC_CUSTOM_INCLUDE_UBC_CHECK_C="git-compat-util.h" )
list(APPEND compat_SOURCES sha1dc_git.c sha1dc/sha1.c sha1dc/ubc_check.c block-sha1/sha1.c sha256/block/sha256.c compat/qsort_s.c)
list(APPEND compat_SOURCES sha1dc_git.c sha1dc/sha1.c sha1dc/ubc_check.c sha1dc-accel/arm.c sha1dc-accel/sha1.c sha1dc-accel/ubc_check.c sha1dc-accel/x86.c block-sha1/sha1.c sha256/block/sha256.c compat/qsort_s.c)


add_compile_definitions(PAGER_ENV="LESS=FRX LV=-c"
Expand Down
5 changes: 5 additions & 0 deletions hash.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,13 @@
# include "sha1/openssl.h"
# endif
#elif defined(SHA1_DC)
#ifdef DC_SHA1_RS
#define SHA1_BACKEND "SHA1_DC-rs"
#include "sha1dc_rs.h"
#else
#define SHA1_BACKEND "SHA1_DC"
#include "sha1dc_git.h"
#endif
#else /* SHA1_BLK */
#define SHA1_BACKEND "SHA1_BLK (No collision detection)"
#include "block-sha1/sha1.h"
Expand Down
4 changes: 4 additions & 0 deletions meson.build
Original file line number Diff line number Diff line change
Expand Up @@ -1634,6 +1634,10 @@ if sha1_backend == 'sha1dc'
'sha1dc_git.c',
'sha1dc/sha1.c',
'sha1dc/ubc_check.c',
'sha1dc-accel/arm.c',
'sha1dc-accel/sha1.c',
'sha1dc-accel/ubc_check.c',
'sha1dc-accel/x86.c',
]
endif
if sha1_backend == 'CommonCrypto' or sha1_unsafe_backend == 'CommonCrypto'
Expand Down
Loading
Loading