Skip to content

Commit 433a133

Browse files
authored
Merge pull request libgit2#6191 from libgit2/ethomson/sha256_poc
RFC: SHA256 proof of concept
2 parents 21b70f0 + 6013b6a commit 433a133

File tree

254 files changed

+2924
-1722
lines changed

Some content is hidden

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

254 files changed

+2924
-1722
lines changed

.github/workflows/main.yml

Lines changed: 72 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,61 @@ jobs:
120120
CMAKE_OPTIONS: -DUSE_HTTPS=mbedTLS -DUSE_SHA1=HTTPS -DREGEX_BACKEND=pcre -DDEPRECATE_HARD=ON -DUSE_LEAK_CHECKER=valgrind -DUSE_GSSAPI=ON -DUSE_SSH=ON
121121
CMAKE_GENERATOR: Ninja
122122
os: ubuntu-latest
123-
- name: "Linux (MemorySanitizer)"
123+
- name: "macOS"
124+
id: macos
125+
os: macos-10.15
126+
env:
127+
CC: clang
128+
CMAKE_OPTIONS: -DREGEX_BACKEND=regcomp_l -DDEPRECATE_HARD=ON -DUSE_LEAK_CHECKER=leaks -DUSE_GSSAPI=ON
129+
PKG_CONFIG_PATH: /usr/local/opt/openssl/lib/pkgconfig
130+
SKIP_SSH_TESTS: true
131+
SKIP_NEGOTIATE_TESTS: true
132+
setup-script: osx
133+
- name: "Windows (amd64, Visual Studio)"
134+
id: windows-amd64-vs
135+
os: windows-2019
136+
env:
137+
ARCH: amd64
138+
CMAKE_GENERATOR: Visual Studio 16 2019
139+
CMAKE_OPTIONS: -A x64 -DWIN32_LEAKCHECK=ON -DDEPRECATE_HARD=ON
140+
SKIP_SSH_TESTS: true
141+
SKIP_NEGOTIATE_TESTS: true
142+
- name: "Windows (x86, Visual Studio)"
143+
id: windows-x86-vs
144+
os: windows-2019
145+
env:
146+
ARCH: x86
147+
CMAKE_GENERATOR: Visual Studio 16 2019
148+
CMAKE_OPTIONS: -A Win32 -DWIN32_LEAKCHECK=ON -DDEPRECATE_HARD=ON -DUSE_SHA1=HTTPS -DUSE_BUNDLED_ZLIB=ON
149+
SKIP_SSH_TESTS: true
150+
SKIP_NEGOTIATE_TESTS: true
151+
- name: "Windows (amd64, mingw)"
152+
id: windows-amd64-mingw
153+
os: windows-2019
154+
setup-script: mingw
155+
env:
156+
ARCH: amd64
157+
CMAKE_GENERATOR: MinGW Makefiles
158+
CMAKE_OPTIONS: -DDEPRECATE_HARD=ON
159+
BUILD_TEMP: D:\Temp
160+
BUILD_PATH: D:\Temp\mingw64\bin;C:\Windows\system32;C:\Windows;C:\Windows\System32\Wbem;C:\Program Files (x86)\CMake\bin
161+
SKIP_SSH_TESTS: true
162+
SKIP_NEGOTIATE_TESTS: true
163+
- name: "Windows (x86, mingw)"
164+
id: windows-x86-mingw
165+
os: windows-2019
166+
setup-script: mingw
167+
env:
168+
ARCH: x86
169+
CMAKE_GENERATOR: MinGW Makefiles
170+
CMAKE_OPTIONS: -DDEPRECATE_HARD=ON
171+
BUILD_TEMP: D:\Temp
172+
BUILD_PATH: D:\Temp\mingw32\bin;C:\Windows\system32;C:\Windows;C:\Windows\System32\Wbem;C:\Program Files (x86)\CMake\bin
173+
SKIP_SSH_TESTS: true
174+
SKIP_NEGOTIATE_TESTS: true
175+
176+
# Sanitizers
177+
- name: "Sanitizer (Memory)"
124178
id: memorysanitizer
125179
container:
126180
name: focal
@@ -134,7 +188,7 @@ jobs:
134188
ASAN_SYMBOLIZER_PATH: /usr/bin/llvm-symbolizer-10
135189
UBSAN_OPTIONS: print_stacktrace=1
136190
os: ubuntu-latest
137-
- name: "Linux (UndefinedBehaviorSanitizer)"
191+
- name: "Sanitizer (UndefinedBehavior)"
138192
id: ubsanitizer
139193
container:
140194
name: focal
@@ -148,7 +202,7 @@ jobs:
148202
ASAN_SYMBOLIZER_PATH: /usr/bin/llvm-symbolizer-10
149203
UBSAN_OPTIONS: print_stacktrace=1
150204
os: ubuntu-latest
151-
- name: "Linux (ThreadSanitizer)"
205+
- name: "Sanitizer (Thread)"
152206
id: threadsanitizer
153207
container:
154208
name: focal
@@ -163,56 +217,34 @@ jobs:
163217
UBSAN_OPTIONS: print_stacktrace=1
164218
TSAN_OPTIONS: suppressions=/home/libgit2/source/script/thread-sanitizer.supp second_deadlock_stack=1
165219
os: ubuntu-latest
166-
- name: "macOS"
220+
221+
# Experimental: SHA256 support
222+
- name: "Linux (SHA256, Xenial, Clang, OpenSSL)"
223+
id: xenial-clang-openssl
224+
container:
225+
name: xenial
226+
env:
227+
CC: clang
228+
CMAKE_GENERATOR: Ninja
229+
CMAKE_OPTIONS: -DUSE_HTTPS=OpenSSL -DDEPRECATE_HARD=ON -DUSE_LEAK_CHECKER=valgrind -DUSE_GSSAPI=ON -DUSE_SSH=ON
230+
os: ubuntu-latest
231+
- name: "macOS (SHA256)"
167232
id: macos
168233
os: macos-10.15
169234
env:
170235
CC: clang
171-
CMAKE_OPTIONS: -DREGEX_BACKEND=regcomp_l -DDEPRECATE_HARD=ON -DUSE_LEAK_CHECKER=leaks -DUSE_GSSAPI=ON
236+
CMAKE_OPTIONS: -DREGEX_BACKEND=regcomp_l -DDEPRECATE_HARD=ON -DUSE_LEAK_CHECKER=leaks -DUSE_GSSAPI=ON -DEXPERIMENTAL_SHA256=ON
172237
PKG_CONFIG_PATH: /usr/local/opt/openssl/lib/pkgconfig
173238
SKIP_SSH_TESTS: true
174239
SKIP_NEGOTIATE_TESTS: true
175240
setup-script: osx
176-
- name: "Windows (amd64, Visual Studio)"
241+
- name: "Windows (SHA256, amd64, Visual Studio)"
177242
id: windows-amd64-vs
178243
os: windows-2019
179244
env:
180245
ARCH: amd64
181246
CMAKE_GENERATOR: Visual Studio 16 2019
182-
CMAKE_OPTIONS: -A x64 -DWIN32_LEAKCHECK=ON -DDEPRECATE_HARD=ON
183-
SKIP_SSH_TESTS: true
184-
SKIP_NEGOTIATE_TESTS: true
185-
- name: "Windows (x86, Visual Studio)"
186-
id: windows-x86-vs
187-
os: windows-2019
188-
env:
189-
ARCH: x86
190-
CMAKE_GENERATOR: Visual Studio 16 2019
191-
CMAKE_OPTIONS: -A Win32 -DWIN32_LEAKCHECK=ON -DDEPRECATE_HARD=ON -DUSE_SHA1=HTTPS -DUSE_BUNDLED_ZLIB=ON
192-
SKIP_SSH_TESTS: true
193-
SKIP_NEGOTIATE_TESTS: true
194-
- name: "Windows (amd64, mingw)"
195-
id: windows-amd64-mingw
196-
os: windows-2019
197-
setup-script: mingw
198-
env:
199-
ARCH: amd64
200-
CMAKE_GENERATOR: MinGW Makefiles
201-
CMAKE_OPTIONS: -DDEPRECATE_HARD=ON
202-
BUILD_TEMP: D:\Temp
203-
BUILD_PATH: D:\Temp\mingw64\bin;C:\Windows\system32;C:\Windows;C:\Windows\System32\Wbem;C:\Program Files (x86)\CMake\bin
204-
SKIP_SSH_TESTS: true
205-
SKIP_NEGOTIATE_TESTS: true
206-
- name: "Windows (x86, mingw)"
207-
id: windows-x86-mingw
208-
os: windows-2019
209-
setup-script: mingw
210-
env:
211-
ARCH: x86
212-
CMAKE_GENERATOR: MinGW Makefiles
213-
CMAKE_OPTIONS: -DDEPRECATE_HARD=ON
214-
BUILD_TEMP: D:\Temp
215-
BUILD_PATH: D:\Temp\mingw32\bin;C:\Windows\system32;C:\Windows;C:\Windows\System32\Wbem;C:\Program Files (x86)\CMake\bin
247+
CMAKE_OPTIONS: -A x64 -DWIN32_LEAKCHECK=ON -DDEPRECATE_HARD=ON -DEXPERIMENTAL_SHA256=ON
216248
SKIP_SSH_TESTS: true
217249
SKIP_NEGOTIATE_TESTS: true
218250
fail-fast: false

CMakeLists.txt

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,9 @@ set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${PROJECT_SOURCE_DIR}/cmake")
1515
# Build options
1616
#
1717

18+
# Experimental features
19+
option(EXPERIMENTAL_SHA256 "Enable experimental SHA256 support (for R&D/testing)" OFF)
20+
1821
# Optional subsystems
1922
option(BUILD_SHARED_LIBS "Build Shared Library (OFF for Static)" ON)
2023
option(BUILD_TESTS "Build Tests using the Clar suite" ON)
@@ -107,6 +110,7 @@ include(IdeSplitSources)
107110
include(FeatureSummary)
108111
include(EnableWarnings)
109112
include(DefaultCFlags)
113+
include(ExperimentalFeatures)
110114

111115

112116
#

cmake/ExperimentalFeatures.cmake

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
if(EXPERIMENTAL_SHA256)
2+
add_feature_info("SHA256 API" ON "experimental SHA256 APIs")
3+
4+
set(EXPERIMENTAL 1)
5+
set(GIT_EXPERIMENTAL_SHA256 1)
6+
else()
7+
add_feature_info("SHA256 API" OFF "experimental SHA256 APIs")
8+
endif()
9+
10+
if(EXPERIMENTAL)
11+
set(LIBGIT2_FILENAME "${LIBGIT2_FILENAME}-experimental")
12+
endif()

examples/cat-file.c

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ static void show_blob(const git_blob *blob)
4949
static void show_tree(const git_tree *tree)
5050
{
5151
size_t i, max_i = (int)git_tree_entrycount(tree);
52-
char oidstr[GIT_OID_HEXSZ + 1];
52+
char oidstr[GIT_OID_SHA1_HEXSIZE + 1];
5353
const git_tree_entry *te;
5454

5555
for (i = 0; i < max_i; ++i) {
@@ -70,7 +70,7 @@ static void show_tree(const git_tree *tree)
7070
static void show_commit(const git_commit *commit)
7171
{
7272
unsigned int i, max_i;
73-
char oidstr[GIT_OID_HEXSZ + 1];
73+
char oidstr[GIT_OID_SHA1_HEXSIZE + 1];
7474

7575
git_oid_tostr(oidstr, sizeof(oidstr), git_commit_tree_id(commit));
7676
printf("tree %s\n", oidstr);
@@ -90,7 +90,7 @@ static void show_commit(const git_commit *commit)
9090

9191
static void show_tag(const git_tag *tag)
9292
{
93-
char oidstr[GIT_OID_HEXSZ + 1];
93+
char oidstr[GIT_OID_SHA1_HEXSIZE + 1];
9494

9595
git_oid_tostr(oidstr, sizeof(oidstr), git_tag_target_id(tag));;
9696
printf("object %s\n", oidstr);
@@ -125,15 +125,15 @@ int lg2_cat_file(git_repository *repo, int argc, char *argv[])
125125
{
126126
struct catfile_options o = { ".", NULL, 0, 0 };
127127
git_object *obj = NULL;
128-
char oidstr[GIT_OID_HEXSZ + 1];
128+
char oidstr[GIT_OID_SHA1_HEXSIZE + 1];
129129

130130
parse_opts(&o, argc, argv);
131131

132132
check_lg2(git_revparse_single(&obj, repo, o.rev),
133133
"Could not resolve", o.rev);
134134

135135
if (o.verbose) {
136-
char oidstr[GIT_OID_HEXSZ + 1];
136+
char oidstr[GIT_OID_SHA1_HEXSIZE + 1];
137137
git_oid_tostr(oidstr, sizeof(oidstr), git_object_id(obj));
138138

139139
printf("%s %s\n--\n",

examples/fetch.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,17 +15,17 @@ static int progress_cb(const char *str, int len, void *data)
1515
*/
1616
static int update_cb(const char *refname, const git_oid *a, const git_oid *b, void *data)
1717
{
18-
char a_str[GIT_OID_HEXSZ+1], b_str[GIT_OID_HEXSZ+1];
18+
char a_str[GIT_OID_SHA1_HEXSIZE+1], b_str[GIT_OID_SHA1_HEXSIZE+1];
1919
(void)data;
2020

2121
git_oid_fmt(b_str, b);
22-
b_str[GIT_OID_HEXSZ] = '\0';
22+
b_str[GIT_OID_SHA1_HEXSIZE] = '\0';
2323

2424
if (git_oid_is_zero(a)) {
2525
printf("[new] %.20s %s\n", b_str, refname);
2626
} else {
2727
git_oid_fmt(a_str, a);
28-
a_str[GIT_OID_HEXSZ] = '\0';
28+
a_str[GIT_OID_SHA1_HEXSIZE] = '\0';
2929
printf("[updated] %.10s..%.10s %s\n", a_str, b_str, refname);
3030
}
3131

examples/for-each-ref.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ static int show_ref(git_reference *ref, void *data)
55
{
66
git_repository *repo = data;
77
git_reference *resolved = NULL;
8-
char hex[GIT_OID_HEXSZ+1];
8+
char hex[GIT_OID_SHA1_HEXSIZE+1];
99
const git_oid *oid;
1010
git_object *obj;
1111

@@ -16,7 +16,7 @@ static int show_ref(git_reference *ref, void *data)
1616

1717
oid = git_reference_target(resolved ? resolved : ref);
1818
git_oid_fmt(hex, oid);
19-
hex[GIT_OID_HEXSZ] = 0;
19+
hex[GIT_OID_SHA1_HEXSIZE] = 0;
2020
check_lg2(git_object_lookup(&obj, repo, oid, GIT_OBJECT_ANY),
2121
"Unable to lookup object", hex);
2222

examples/general.c

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -129,7 +129,7 @@ int lg2_general(git_repository *repo, int argc, char** argv)
129129
*/
130130
static void oid_parsing(git_oid *oid)
131131
{
132-
char out[GIT_OID_HEXSZ+1];
132+
char out[GIT_OID_SHA1_HEXSIZE+1];
133133
char hex[] = "4a202b346bb0fb0db7eff3cffeb3c70babbd2045";
134134

135135
printf("*Hex to Raw*\n");
@@ -142,7 +142,7 @@ static void oid_parsing(git_oid *oid)
142142
* this throughout the example for storing the value of the current SHA
143143
* key we're working with.
144144
*/
145-
git_oid_fromstr(oid, hex);
145+
git_oid_fromstr(oid, hex, GIT_OID_SHA1);
146146

147147
/*
148148
* Once we've converted the string into the oid value, we can get the raw
@@ -152,7 +152,7 @@ static void oid_parsing(git_oid *oid)
152152
* char hex value.
153153
*/
154154
printf("\n*Raw to Hex*\n");
155-
out[GIT_OID_HEXSZ] = '\0';
155+
out[GIT_OID_SHA1_HEXSIZE] = '\0';
156156

157157
/**
158158
* If you have a oid, you can easily get the hex value of the SHA as well.
@@ -173,7 +173,7 @@ static void oid_parsing(git_oid *oid)
173173
*/
174174
static void object_database(git_repository *repo, git_oid *oid)
175175
{
176-
char oid_hex[GIT_OID_HEXSZ+1] = { 0 };
176+
char oid_hex[GIT_OID_SHA1_HEXSIZE+1] = { 0 };
177177
const unsigned char *data;
178178
const char *str_type;
179179
int error;
@@ -266,7 +266,7 @@ static void commit_writing(git_repository *repo)
266266
git_tree *tree;
267267
git_commit *parent;
268268
git_signature *author, *committer;
269-
char oid_hex[GIT_OID_HEXSZ+1] = { 0 };
269+
char oid_hex[GIT_OID_SHA1_HEXSIZE+1] = { 0 };
270270

271271
printf("\n*Commit Writing*\n");
272272

@@ -287,9 +287,9 @@ static void commit_writing(git_repository *repo)
287287
* parents. Here we're creating oid objects to create the commit with,
288288
* but you can also use
289289
*/
290-
git_oid_fromstr(&tree_id, "f60079018b664e4e79329a7ef9559c8d9e0378d1");
290+
git_oid_fromstr(&tree_id, "f60079018b664e4e79329a7ef9559c8d9e0378d1", GIT_OID_SHA1);
291291
git_tree_lookup(&tree, repo, &tree_id);
292-
git_oid_fromstr(&parent_id, "5b5b025afb0b4c913b4c338a42934a3863bf3644");
292+
git_oid_fromstr(&parent_id, "5b5b025afb0b4c913b4c338a42934a3863bf3644", GIT_OID_SHA1);
293293
git_commit_lookup(&parent, repo, &parent_id);
294294

295295
/**
@@ -345,15 +345,15 @@ static void commit_parsing(git_repository *repo)
345345
const git_signature *author, *cmtter;
346346
git_commit *commit, *parent;
347347
git_oid oid;
348-
char oid_hex[GIT_OID_HEXSZ+1];
348+
char oid_hex[GIT_OID_SHA1_HEXSIZE+1];
349349
const char *message;
350350
unsigned int parents, p;
351351
int error;
352352
time_t time;
353353

354354
printf("\n*Commit Parsing*\n");
355355

356-
git_oid_fromstr(&oid, "8496071c1b46c854b31185ea97743be6a8774479");
356+
git_oid_fromstr(&oid, "8496071c1b46c854b31185ea97743be6a8774479", GIT_OID_SHA1);
357357

358358
error = git_commit_lookup(&commit, repo, &oid);
359359
check_error(error, "looking up commit");
@@ -422,7 +422,7 @@ static void tag_parsing(git_repository *repo)
422422
* We create an oid for the tag object if we know the SHA and look it up
423423
* the same way that we would a commit (or any other object).
424424
*/
425-
git_oid_fromstr(&oid, "b25fa35b38051e4ae45d4222e795f9df2e43f1d1");
425+
git_oid_fromstr(&oid, "b25fa35b38051e4ae45d4222e795f9df2e43f1d1", GIT_OID_SHA1);
426426

427427
error = git_tag_lookup(&tag, repo, &oid);
428428
check_error(error, "looking up tag");
@@ -470,7 +470,7 @@ static void tree_parsing(git_repository *repo)
470470
/**
471471
* Create the oid and lookup the tree object just like the other objects.
472472
*/
473-
git_oid_fromstr(&oid, "f60079018b664e4e79329a7ef9559c8d9e0378d1");
473+
git_oid_fromstr(&oid, "f60079018b664e4e79329a7ef9559c8d9e0378d1", GIT_OID_SHA1);
474474
git_tree_lookup(&tree, repo, &oid);
475475

476476
/**
@@ -524,7 +524,7 @@ static void blob_parsing(git_repository *repo)
524524

525525
printf("\n*Blob Parsing*\n");
526526

527-
git_oid_fromstr(&oid, "1385f264afb75a56a5bec74243be9b367ba4ca08");
527+
git_oid_fromstr(&oid, "1385f264afb75a56a5bec74243be9b367ba4ca08", GIT_OID_SHA1);
528528
git_blob_lookup(&blob, repo, &oid);
529529

530530
/**
@@ -566,7 +566,7 @@ static void revwalking(git_repository *repo)
566566

567567
printf("\n*Revwalking*\n");
568568

569-
git_oid_fromstr(&oid, "5b5b025afb0b4c913b4c338a42934a3863bf3644");
569+
git_oid_fromstr(&oid, "5b5b025afb0b4c913b4c338a42934a3863bf3644", GIT_OID_SHA1);
570570

571571
/**
572572
* To use the revwalker, create a new walker, tell it how you want to sort
@@ -679,7 +679,7 @@ static void reference_listing(git_repository *repo)
679679

680680
for (i = 0; i < ref_list.count; ++i) {
681681
git_reference *ref;
682-
char oid_hex[GIT_OID_HEXSZ+1] = GIT_OID_HEX_ZERO;
682+
char oid_hex[GIT_OID_SHA1_HEXSIZE+1] = GIT_OID_SHA1_HEXZERO;
683683
const char *refname;
684684

685685
refname = ref_list.strings[i];

examples/log.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -329,7 +329,7 @@ static void print_time(const git_time *intime, const char *prefix)
329329
/** Helper to print a commit object. */
330330
static void print_commit(git_commit *commit, struct log_options *opts)
331331
{
332-
char buf[GIT_OID_HEXSZ + 1];
332+
char buf[GIT_OID_SHA1_HEXSIZE + 1];
333333
int i, count;
334334
const git_signature *sig;
335335
const char *scan, *eol;

0 commit comments

Comments
 (0)