Skip to content

Commit f6581e2

Browse files
bk2204gitster
authored andcommitted
repository: require Rust support for interoperability
We'll be implementing some of our interoperability code, like the loose object map, in Rust. While the code currently compiles with the old loose object map format, which is written entirely in C, we'll soon replace that with the Rust-based implementation. Require the use of Rust for compatibility mode and die if it is not supported. Because the repo argument is not used when Rust is missing, cast it to void to silence the compiler warning, which we do not care about. Add a prerequisite in our tests, RUST, that checks if Rust functionality is available and use it in the tests that handle interoperability. This is technically a regression in functionality compared to our existing state, but pack index v3 is not yet implemented and thus the functionality is mostly quite broken, which is why we've recently marked this functionality as experimental. We don't believe anyone is getting useful use out of the interoperability code in its current state, so no actual users should be negatively impacted by this change. Signed-off-by: brian m. carlson <sandals@crustytoothpaste.net> Signed-off-by: Junio C Hamano <gitster@pobox.com>
1 parent 57da342 commit f6581e2

File tree

7 files changed

+77
-32
lines changed

7 files changed

+77
-32
lines changed

repository.c

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
#include "repository.h"
44
#include "odb.h"
55
#include "config.h"
6+
#include "gettext.h"
67
#include "object.h"
78
#include "lockfile.h"
89
#include "path.h"
@@ -192,11 +193,17 @@ void repo_set_hash_algo(struct repository *repo, int hash_algo)
192193

193194
void repo_set_compat_hash_algo(struct repository *repo, int algo)
194195
{
196+
#ifdef WITH_RUST
195197
if (hash_algo_by_ptr(repo->hash_algo) == algo)
196198
BUG("hash_algo and compat_hash_algo match");
197199
repo->compat_hash_algo = algo ? &hash_algos[algo] : NULL;
198200
if (repo->compat_hash_algo)
199201
repo_read_loose_object_map(repo);
202+
#else
203+
(void)repo;
204+
if (algo)
205+
die(_("compatibility hash algorithm support requires Rust"));
206+
#endif
200207
}
201208

202209
void repo_set_ref_storage_format(struct repository *repo,

t/t1006-cat-file.sh

Lines changed: 55 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -241,10 +241,16 @@ hello_content="Hello World"
241241
hello_size=$(strlen "$hello_content")
242242
hello_oid=$(echo_without_newline "$hello_content" | git hash-object --stdin)
243243

244-
test_expect_success "setup" '
244+
test_expect_success "setup part 1" '
245245
git config core.repositoryformatversion 1 &&
246-
git config extensions.objectformat $test_hash_algo &&
247-
git config extensions.compatobjectformat $test_compat_hash_algo &&
246+
git config extensions.objectformat $test_hash_algo
247+
'
248+
249+
test_expect_success RUST 'compat setup' '
250+
git config extensions.compatobjectformat $test_compat_hash_algo
251+
'
252+
253+
test_expect_success 'setup part 2' '
248254
echo_without_newline "$hello_content" > hello &&
249255
git update-index --add hello &&
250256
echo_without_newline "$hello_content" > "path with spaces" &&
@@ -273,9 +279,13 @@ run_blob_tests () {
273279
'
274280
}
275281

276-
hello_compat_oid=$(git rev-parse --output-object-format=$test_compat_hash_algo $hello_oid)
277282
run_blob_tests $hello_oid
278-
run_blob_tests $hello_compat_oid
283+
284+
if test_have_prereq RUST
285+
then
286+
hello_compat_oid=$(git rev-parse --output-object-format=$test_compat_hash_algo $hello_oid)
287+
run_blob_tests $hello_compat_oid
288+
fi
279289

280290
test_expect_success '--batch-check without %(rest) considers whole line' '
281291
echo "$hello_oid blob $hello_size" >expect &&
@@ -286,62 +296,76 @@ test_expect_success '--batch-check without %(rest) considers whole line' '
286296
'
287297

288298
tree_oid=$(git write-tree)
289-
tree_compat_oid=$(git rev-parse --output-object-format=$test_compat_hash_algo $tree_oid)
290299
tree_size=$((2 * $(test_oid rawsz) + 13 + 24))
291-
tree_compat_size=$((2 * $(test_oid --hash=compat rawsz) + 13 + 24))
292300
tree_pretty_content="100644 blob $hello_oid hello${LF}100755 blob $hello_oid path with spaces${LF}"
293-
tree_compat_pretty_content="100644 blob $hello_compat_oid hello${LF}100755 blob $hello_compat_oid path with spaces${LF}"
294301

295302
run_tests 'tree' $tree_oid "" $tree_size "" "$tree_pretty_content"
296-
run_tests 'tree' $tree_compat_oid "" $tree_compat_size "" "$tree_compat_pretty_content"
297303
run_tests 'blob' "$tree_oid:hello" "100644" $hello_size "" "$hello_content" $hello_oid
298-
run_tests 'blob' "$tree_compat_oid:hello" "100644" $hello_size "" "$hello_content" $hello_compat_oid
299304
run_tests 'blob' "$tree_oid:path with spaces" "100755" $hello_size "" "$hello_content" $hello_oid
300-
run_tests 'blob' "$tree_compat_oid:path with spaces" "100755" $hello_size "" "$hello_content" $hello_compat_oid
305+
306+
if test_have_prereq RUST
307+
then
308+
tree_compat_oid=$(git rev-parse --output-object-format=$test_compat_hash_algo $tree_oid)
309+
tree_compat_size=$((2 * $(test_oid --hash=compat rawsz) + 13 + 24))
310+
tree_compat_pretty_content="100644 blob $hello_compat_oid hello${LF}100755 blob $hello_compat_oid path with spaces${LF}"
311+
312+
run_tests 'tree' $tree_compat_oid "" $tree_compat_size "" "$tree_compat_pretty_content"
313+
run_tests 'blob' "$tree_compat_oid:hello" "100644" $hello_size "" "$hello_content" $hello_compat_oid
314+
run_tests 'blob' "$tree_compat_oid:path with spaces" "100755" $hello_size "" "$hello_content" $hello_compat_oid
315+
fi
301316

302317
commit_message="Initial commit"
303318
commit_oid=$(echo_without_newline "$commit_message" | git commit-tree $tree_oid)
304-
commit_compat_oid=$(git rev-parse --output-object-format=$test_compat_hash_algo $commit_oid)
305319
commit_size=$(($(test_oid hexsz) + 137))
306-
commit_compat_size=$(($(test_oid --hash=compat hexsz) + 137))
307320
commit_content="tree $tree_oid
308321
author $GIT_AUTHOR_NAME <$GIT_AUTHOR_EMAIL> $GIT_AUTHOR_DATE
309322
committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
310323
311324
$commit_message"
312325

313-
commit_compat_content="tree $tree_compat_oid
326+
run_tests 'commit' $commit_oid "" $commit_size "$commit_content" "$commit_content"
327+
328+
if test_have_prereq RUST
329+
then
330+
commit_compat_oid=$(git rev-parse --output-object-format=$test_compat_hash_algo $commit_oid)
331+
commit_compat_size=$(($(test_oid --hash=compat hexsz) + 137))
332+
commit_compat_content="tree $tree_compat_oid
314333
author $GIT_AUTHOR_NAME <$GIT_AUTHOR_EMAIL> $GIT_AUTHOR_DATE
315334
committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
316335
317336
$commit_message"
318337

319-
run_tests 'commit' $commit_oid "" $commit_size "$commit_content" "$commit_content"
320-
run_tests 'commit' $commit_compat_oid "" $commit_compat_size "$commit_compat_content" "$commit_compat_content"
338+
run_tests 'commit' $commit_compat_oid "" $commit_compat_size "$commit_compat_content" "$commit_compat_content"
339+
fi
321340

322341
tag_header_without_oid="type blob
323342
tag hellotag
324343
tagger $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL>"
325344
tag_header_without_timestamp="object $hello_oid
326345
$tag_header_without_oid"
327-
tag_compat_header_without_timestamp="object $hello_compat_oid
328-
$tag_header_without_oid"
329346
tag_description="This is a tag"
330347
tag_content="$tag_header_without_timestamp 0 +0000
331348
332-
$tag_description"
333-
tag_compat_content="$tag_compat_header_without_timestamp 0 +0000
334-
335349
$tag_description"
336350

337351
tag_oid=$(echo_without_newline "$tag_content" | git hash-object -t tag --stdin -w)
338352
tag_size=$(strlen "$tag_content")
339353

340-
tag_compat_oid=$(git rev-parse --output-object-format=$test_compat_hash_algo $tag_oid)
341-
tag_compat_size=$(strlen "$tag_compat_content")
342-
343354
run_tests 'tag' $tag_oid "" $tag_size "$tag_content" "$tag_content"
344-
run_tests 'tag' $tag_compat_oid "" $tag_compat_size "$tag_compat_content" "$tag_compat_content"
355+
356+
if test_have_prereq RUST
357+
then
358+
tag_compat_header_without_timestamp="object $hello_compat_oid
359+
$tag_header_without_oid"
360+
tag_compat_content="$tag_compat_header_without_timestamp 0 +0000
361+
362+
$tag_description"
363+
364+
tag_compat_oid=$(git rev-parse --output-object-format=$test_compat_hash_algo $tag_oid)
365+
tag_compat_size=$(strlen "$tag_compat_content")
366+
367+
run_tests 'tag' $tag_compat_oid "" $tag_compat_size "$tag_compat_content" "$tag_compat_content"
368+
fi
345369

346370
test_expect_success "Reach a blob from a tag pointing to it" '
347371
echo_without_newline "$hello_content" >expect &&
@@ -590,7 +614,8 @@ flush"
590614
}
591615

592616
batch_tests $hello_oid $tree_oid $tree_size $commit_oid $commit_size "$commit_content" $tag_oid $tag_size "$tag_content"
593-
batch_tests $hello_compat_oid $tree_compat_oid $tree_compat_size $commit_compat_oid $commit_compat_size "$commit_compat_content" $tag_compat_oid $tag_compat_size "$tag_compat_content"
617+
618+
test_have_prereq RUST && batch_tests $hello_compat_oid $tree_compat_oid $tree_compat_size $commit_compat_oid $commit_compat_size "$commit_compat_content" $tag_compat_oid $tag_compat_size "$tag_compat_content"
594619

595620

596621
test_expect_success FUNNYNAMES 'setup with newline in input' '
@@ -1226,7 +1251,10 @@ test_expect_success 'batch-check with a submodule' '
12261251
test_unconfig extensions.compatobjectformat &&
12271252
printf "160000 commit $(test_oid deadbeef)\tsub\n" >tree-with-sub &&
12281253
tree=$(git mktree <tree-with-sub) &&
1229-
test_config extensions.compatobjectformat $test_compat_hash_algo &&
1254+
if test_have_prereq RUST
1255+
then
1256+
test_config extensions.compatobjectformat $test_compat_hash_algo
1257+
fi &&
12301258
12311259
git cat-file --batch-check >actual <<-EOF &&
12321260
$tree:sub

t/t1016-compatObjectFormat.sh

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,12 @@ test_description='Test how well compatObjectFormat works'
88
. ./test-lib.sh
99
. "$TEST_DIRECTORY"/lib-gpg.sh
1010

11+
if ! test_have_prereq RUST
12+
then
13+
skip_all='interoperability requires a Git built with Rust'
14+
test_done
15+
fi
16+
1117
# All of the follow variables must be defined in the environment:
1218
# GIT_AUTHOR_NAME
1319
# GIT_AUTHOR_EMAIL

t/t1500-rev-parse.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -208,7 +208,7 @@ test_expect_success 'rev-parse --show-object-format in repo' '
208208
'
209209

210210

211-
test_expect_success 'rev-parse --show-object-format in repo with compat mode' '
211+
test_expect_success RUST 'rev-parse --show-object-format in repo with compat mode' '
212212
mkdir repo &&
213213
(
214214
sane_unset GIT_DEFAULT_HASH &&

t/t9305-fast-import-signatures.sh

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ test_expect_success GPGSSH 'strip SSH signature with --signed-commits=strip' '
7070
test_must_be_empty log
7171
'
7272

73-
test_expect_success GPG 'setup a commit with dual OpenPGP signatures on its SHA-1 and SHA-256 formats' '
73+
test_expect_success RUST,GPG 'setup a commit with dual OpenPGP signatures on its SHA-1 and SHA-256 formats' '
7474
# Create a signed SHA-256 commit
7575
git init --object-format=sha256 explicit-sha256 &&
7676
git -C explicit-sha256 config extensions.compatObjectFormat sha1 &&
@@ -91,7 +91,7 @@ test_expect_success GPG 'setup a commit with dual OpenPGP signatures on its SHA-
9191
test_grep -E "^gpgsig-sha256 " out
9292
'
9393

94-
test_expect_success GPG 'strip both OpenPGP signatures with --signed-commits=warn-strip' '
94+
test_expect_success RUST,GPG 'strip both OpenPGP signatures with --signed-commits=warn-strip' '
9595
git -C explicit-sha256 fast-export --signed-commits=verbatim dual-signed >output &&
9696
test_grep -E "^gpgsig sha1 openpgp" output &&
9797
test_grep -E "^gpgsig sha256 openpgp" output &&

t/t9350-fast-export.sh

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -972,7 +972,7 @@ test_expect_success 'fast-export handles --end-of-options' '
972972
test_cmp expect actual
973973
'
974974

975-
test_expect_success GPG 'setup a commit with dual signatures on its SHA-1 and SHA-256 formats' '
975+
test_expect_success GPG,RUST 'setup a commit with dual signatures on its SHA-1 and SHA-256 formats' '
976976
# Create a signed SHA-256 commit
977977
git init --object-format=sha256 explicit-sha256 &&
978978
git -C explicit-sha256 config extensions.compatObjectFormat sha1 &&
@@ -993,7 +993,7 @@ test_expect_success GPG 'setup a commit with dual signatures on its SHA-1 and SH
993993
test_grep -E "^gpgsig-sha256 " out
994994
'
995995

996-
test_expect_success GPG 'export and import of doubly signed commit' '
996+
test_expect_success GPG,RUST 'export and import of doubly signed commit' '
997997
git -C explicit-sha256 fast-export --signed-commits=verbatim dual-signed >output &&
998998
test_grep -E "^gpgsig sha1 openpgp" output &&
999999
test_grep -E "^gpgsig sha256 openpgp" output &&

t/test-lib.sh

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1890,6 +1890,10 @@ test_lazy_prereq LONG_IS_64BIT '
18901890
test 8 -le "$(build_option sizeof-long)"
18911891
'
18921892

1893+
test_lazy_prereq RUST '
1894+
test "$(build_option rust)" = enabled
1895+
'
1896+
18931897
test_lazy_prereq TIME_IS_64BIT 'test-tool date is64bit'
18941898
test_lazy_prereq TIME_T_IS_64BIT 'test-tool date time_t-is64bit'
18951899

0 commit comments

Comments
 (0)