Skip to content

Commit 80742e1

Browse files
authored
Merge pull request libgit2#6456 from libgit2/ethomson/sha256_experimental
SHA256: more SHA256 support
2 parents f7963f2 + e3cd859 commit 80742e1

File tree

196 files changed

+5143
-530
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

196 files changed

+5143
-530
lines changed

.github/workflows/main.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -232,7 +232,7 @@ jobs:
232232
env:
233233
CC: clang
234234
CMAKE_GENERATOR: Ninja
235-
CMAKE_OPTIONS: -DUSE_HTTPS=OpenSSL -DDEPRECATE_HARD=ON -DUSE_LEAK_CHECKER=valgrind -DUSE_GSSAPI=ON -DUSE_SSH=ON
235+
CMAKE_OPTIONS: -DUSE_HTTPS=OpenSSL -DDEPRECATE_HARD=ON -DUSE_LEAK_CHECKER=valgrind -DUSE_GSSAPI=ON -DUSE_SSH=ON -DEXPERIMENTAL_SHA256=ON
236236
os: ubuntu-latest
237237
- name: "macOS (SHA256)"
238238
id: macos

.github/workflows/nightly.yml

Lines changed: 31 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -265,10 +265,40 @@ jobs:
265265
RUN_INVASIVE_TESTS: true
266266
SKIP_PROXY_TESTS: true
267267
os: ubuntu-latest
268+
269+
# Experimental: SHA256 support
270+
- name: "Linux (SHA256, Xenial, Clang, OpenSSL)"
271+
id: xenial-clang-openssl
272+
container:
273+
name: xenial
274+
env:
275+
CC: clang
276+
CMAKE_GENERATOR: Ninja
277+
CMAKE_OPTIONS: -DUSE_HTTPS=OpenSSL -DDEPRECATE_HARD=ON -DUSE_LEAK_CHECKER=valgrind -DUSE_GSSAPI=ON -DUSE_SSH=ON
278+
os: ubuntu-latest
279+
- name: "macOS (SHA256)"
280+
id: macos
281+
os: macos-10.15
282+
env:
283+
CC: clang
284+
CMAKE_OPTIONS: -DREGEX_BACKEND=regcomp_l -DDEPRECATE_HARD=ON -DUSE_LEAK_CHECKER=leaks -DUSE_GSSAPI=ON -DEXPERIMENTAL_SHA256=ON
285+
PKG_CONFIG_PATH: /usr/local/opt/openssl/lib/pkgconfig
286+
SKIP_SSH_TESTS: true
287+
SKIP_NEGOTIATE_TESTS: true
288+
setup-script: osx
289+
- name: "Windows (SHA256, amd64, Visual Studio)"
290+
id: windows-amd64-vs
291+
os: windows-2019
292+
env:
293+
ARCH: amd64
294+
CMAKE_GENERATOR: Visual Studio 16 2019
295+
CMAKE_OPTIONS: -A x64 -DWIN32_LEAKCHECK=ON -DDEPRECATE_HARD=ON -DEXPERIMENTAL_SHA256=ON
296+
SKIP_SSH_TESTS: true
297+
SKIP_NEGOTIATE_TESTS: true
268298
fail-fast: false
269-
name: "Build ${{ matrix.platform.name }}"
270299
env: ${{ matrix.platform.env }}
271300
runs-on: ${{ matrix.platform.os }}
301+
name: "Build ${{ matrix.platform.name }}"
272302
steps:
273303
- name: Check out repository
274304
uses: actions/checkout@v3

ci/docker/xenial

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,13 @@ RUN apt-get update && \
77
clang \
88
cmake \
99
curl \
10+
gettext \
1011
gcc \
11-
git \
1212
krb5-user \
1313
libcurl4-gnutls-dev \
14+
libexpat1-dev \
1415
libgcrypt20-dev \
16+
libintl-perl \
1517
libkrb5-dev \
1618
libpcre3-dev \
1719
libssl-dev \
@@ -28,7 +30,17 @@ RUN apt-get update && \
2830
&& \
2931
rm -rf /var/lib/apt/lists/*
3032

31-
FROM apt AS mbedtls
33+
FROM apt AS git
34+
RUN cd /tmp && \
35+
curl --location --silent --show-error https://github.com/git/git/archive/refs/tags/v2.39.1.tar.gz | \
36+
tar -xz && \
37+
cd git-2.39.1 && \
38+
make && \
39+
make prefix=/usr install && \
40+
cd .. && \
41+
rm -rf git-2.39.1
42+
43+
FROM git AS mbedtls
3244
RUN cd /tmp && \
3345
curl --location --silent --show-error https://github.com/Mbed-TLS/mbedtls/archive/refs/tags/mbedtls-2.16.2.tar.gz | \
3446
tar -xz && \

ci/test.sh

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,11 @@ cleanup() {
3737
kill $GIT_NAMESPACE_PID
3838
fi
3939

40+
if [ ! -z "$GIT_SHA256_PID" ]; then
41+
echo "Stopping git daemon (sha256)..."
42+
kill $GIT_SHA256_PID
43+
fi
44+
4045
if [ ! -z "$PROXY_BASIC_PID" ]; then
4146
echo "Stopping proxy (Basic)..."
4247
kill $PROXY_BASIC_PID
@@ -145,6 +150,12 @@ if [ -z "$SKIP_GITDAEMON_TESTS" ]; then
145150
cp -R "${SOURCE_DIR}/tests/resources/namespace.git" "${GIT_NAMESPACE_DIR}/namespace.git"
146151
GIT_NAMESPACE="name1" git daemon --listen=localhost --port=9419 --export-all --enable=receive-pack --base-path="${GIT_NAMESPACE_DIR}" "${GIT_NAMESPACE_DIR}" &
147152
GIT_NAMESPACE_PID=$!
153+
154+
echo "Starting git daemon (sha256)..."
155+
GIT_SHA256_DIR=`mktemp -d ${TMPDIR}/git_sha256.XXXXXXXX`
156+
cp -R "${SOURCE_DIR}/tests/resources/testrepo_256.git" "${GIT_SHA256_DIR}/testrepo_256.git"
157+
git daemon --listen=localhost --port=9420 --export-all --enable=receive-pack --base-path="${GIT_SHA256_DIR}" "${GIT_SHA256_DIR}" &
158+
GIT_SHA256_PID=$!
148159
fi
149160
150161
if [ -z "$SKIP_PROXY_TESTS" ]; then
@@ -291,6 +302,14 @@ if [ -z "$SKIP_GITDAEMON_TESTS" ]; then
291302
run_test gitdaemon_namespace
292303
unset GITTEST_REMOTE_URL
293304
unset GITTEST_REMOTE_BRANCH
305+
306+
echo ""
307+
echo "Running gitdaemon (sha256) tests"
308+
echo ""
309+
310+
export GITTEST_REMOTE_URL="git://localhost:9420/testrepo_256.git"
311+
run_test gitdaemon_sha256
312+
unset GITTEST_REMOTE_URL
294313
fi
295314
296315
if [ -z "$SKIP_PROXY_TESTS" ]; then

cmake/ExperimentalFeatures.cmake

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ if(EXPERIMENTAL_SHA256)
1313

1414
set(EXPERIMENTAL 1)
1515
set(GIT_EXPERIMENTAL_SHA256 1)
16-
add_compile_definitions(GIT_EXPERIMENTAL_SHA256)
16+
add_definitions(-DGIT_EXPERIMENTAL_SHA256=1)
1717
else()
1818
add_feature_info("SHA256 API" OFF "experimental SHA256 APIs")
1919
endif()

examples/index-pack.c

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,11 +28,18 @@ int lg2_index_pack(git_repository *repo, int argc, char **argv)
2828
return EXIT_FAILURE;
2929
}
3030

31-
if (git_indexer_new(&idx, ".", 0, NULL, NULL) < 0) {
31+
#ifdef GIT_EXPERIMENTAL_SHA256
32+
error = git_indexer_new(&idx, ".", git_repository_oid_type(repo), NULL);
33+
#else
34+
error = git_indexer_new(&idx, ".", 0, NULL, NULL);
35+
#endif
36+
37+
if (error < 0) {
3238
puts("bad idx");
3339
return -1;
3440
}
3541

42+
3643
if ((fd = open(argv[1], 0)) < 0) {
3744
perror("open");
3845
return -1;

fuzzers/objects_fuzzer.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size)
3939
* to do.
4040
*/
4141
for (i = 0; i < ARRAY_SIZE(types); i++) {
42-
if (git_object__from_raw(&object, (const char *) data, size, types[i]) < 0)
42+
if (git_object__from_raw(&object, (const char *) data, size, types[i], GIT_OID_SHA1) < 0)
4343
continue;
4444
git_object_free(object);
4545
object = NULL;

fuzzers/packfile_fuzzer.c

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,7 @@ int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size)
6767
git_str path = GIT_STR_INIT;
6868
git_oid oid;
6969
bool append_hash = false;
70+
int error;
7071

7172
if (size == 0)
7273
return 0;
@@ -82,7 +83,13 @@ int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size)
8283
abort();
8384
}
8485

85-
if (git_indexer_new(&indexer, ".", 0, odb, NULL) < 0) {
86+
#ifdef GIT_EXPERIMENTAL_SHA256
87+
error = git_indexer_new(&indexer, ".", GIT_OID_SHA1, NULL);
88+
#else
89+
error = git_indexer_new(&indexer, ".", 0, odb, NULL);
90+
#endif
91+
92+
if (error < 0) {
8693
fprintf(stderr, "Failed to create the indexer: %s\n",
8794
git_error_last()->message);
8895
abort();

include/git2/indexer.h

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,19 @@ typedef int GIT_CALLBACK(git_indexer_progress_cb)(const git_indexer_progress *st
6262
typedef struct git_indexer_options {
6363
unsigned int version;
6464

65+
#ifdef GIT_EXPERIMENTAL_SHA256
66+
/** permissions to use creating packfile or 0 for defaults */
67+
unsigned int mode;
68+
69+
/**
70+
* object database from which to read base objects when
71+
* fixing thin packs. This can be NULL if there are no thin
72+
* packs; if a thin pack is encountered, an error will be
73+
* returned if there are bases missing.
74+
*/
75+
git_odb *odb;
76+
#endif
77+
6578
/** progress_cb function to call with progress information */
6679
git_indexer_progress_cb progress_cb;
6780

@@ -87,6 +100,21 @@ GIT_EXTERN(int) git_indexer_options_init(
87100
git_indexer_options *opts,
88101
unsigned int version);
89102

103+
#ifdef GIT_EXPERIMENTAL_SHA256
104+
/**
105+
* Create a new indexer instance
106+
*
107+
* @param out where to store the indexer instance
108+
* @param path to the directory where the packfile should be stored
109+
* @param oid_type the oid type to use for objects
110+
* @return 0 or an error code.
111+
*/
112+
GIT_EXTERN(int) git_indexer_new(
113+
git_indexer **out,
114+
const char *path,
115+
git_oid_t oid_type,
116+
git_indexer_options *opts);
117+
#else
90118
/**
91119
* Create a new indexer instance
92120
*
@@ -106,6 +134,7 @@ GIT_EXTERN(int) git_indexer_new(
106134
unsigned int mode,
107135
git_odb *odb,
108136
git_indexer_options *opts);
137+
#endif
109138

110139
/**
111140
* Add data to the indexer

include/git2/object.h

Lines changed: 28 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -225,6 +225,7 @@ GIT_EXTERN(int) git_object_peel(
225225
*/
226226
GIT_EXTERN(int) git_object_dup(git_object **dest, git_object *source);
227227

228+
#ifdef GIT_EXPERIMENTAL_SHA256
228229
/**
229230
* Analyzes a buffer of raw object content and determines its validity.
230231
* Tree, commit, and tag objects will be parsed and ensured that they
@@ -238,14 +239,39 @@ GIT_EXTERN(int) git_object_dup(git_object **dest, git_object *source);
238239
* @param valid Output pointer to set with validity of the object content
239240
* @param buf The contents to validate
240241
* @param len The length of the buffer
241-
* @param type The type of the object in the buffer
242+
* @param object_type The type of the object in the buffer
243+
* @param oid_type The object ID type for the OIDs in the given buffer
242244
* @return 0 on success or an error code
243245
*/
244246
GIT_EXTERN(int) git_object_rawcontent_is_valid(
245247
int *valid,
246248
const char *buf,
247249
size_t len,
248-
git_object_t type);
250+
git_object_t object_type,
251+
git_oid_t oid_type);
252+
#else
253+
/**
254+
* Analyzes a buffer of raw object content and determines its validity.
255+
* Tree, commit, and tag objects will be parsed and ensured that they
256+
* are valid, parseable content. (Blobs are always valid by definition.)
257+
* An error message will be set with an informative message if the object
258+
* is not valid.
259+
*
260+
* @warning This function is experimental and its signature may change in
261+
* the future.
262+
*
263+
* @param valid Output pointer to set with validity of the object content
264+
* @param buf The contents to validate
265+
* @param len The length of the buffer
266+
* @param object_type The type of the object in the buffer
267+
* @return 0 on success or an error code
268+
*/
269+
GIT_EXTERN(int) git_object_rawcontent_is_valid(
270+
int *valid,
271+
const char *buf,
272+
size_t len,
273+
git_object_t object_type);
274+
#endif
249275

250276
/** @} */
251277
GIT_END_DECL

0 commit comments

Comments
 (0)