Skip to content

Commit ff509c5

Browse files
stefanbellergitster
authored andcommitted
t/helper/test-repository: celebrate independence from the_repository
dade47c (commit-graph: add repo arg to graph readers, 2018-07-11) brought more independence from the_repository to the commit graph, however it was not completely independent of the_repository, as the previous patches show. To ensure we're not accessing the_repository by accident, we'd ideally assign NULL to the_repository to trigger a segfault on access. We currently have a temporary hack in cache.h, which relies on the_hash_algo (which is a short form of the_repository->hash_algo) to be set, so we cannot do that. The next best thing is to set all fields of the_repository to 0, so any accidental access is more likely to be found. Signed-off-by: Stefan Beller <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent b6b24fc commit ff509c5

File tree

2 files changed

+12
-0
lines changed

2 files changed

+12
-0
lines changed

cache.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1033,6 +1033,8 @@ static inline int hashcmp(const unsigned char *sha1, const unsigned char *sha2)
10331033
*
10341034
* This will need to be extended or ripped out when we learn about
10351035
* hashes of different sizes.
1036+
*
1037+
* When ripping this out, see TODO in test-repository.c.
10361038
*/
10371039
if (the_hash_algo->rawsz != 20)
10381040
BUG("hash size not yet supported by hashcmp");

t/helper/test-repository.c

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,11 @@ static void test_parse_commit_in_graph(const char *gitdir, const char *worktree,
1717

1818
setup_git_env(gitdir);
1919

20+
memset(the_repository, 0, sizeof(*the_repository));
21+
22+
/* TODO: Needed for temporary hack in hashcmp, see 183a638b7da. */
23+
repo_set_hash_algo(the_repository, GIT_HASH_SHA1);
24+
2025
if (repo_init(&r, gitdir, worktree))
2126
die("Couldn't init repo");
2227

@@ -43,6 +48,11 @@ static void test_get_commit_tree_in_graph(const char *gitdir,
4348

4449
setup_git_env(gitdir);
4550

51+
memset(the_repository, 0, sizeof(*the_repository));
52+
53+
/* TODO: Needed for temporary hack in hashcmp, see 183a638b7da. */
54+
repo_set_hash_algo(the_repository, GIT_HASH_SHA1);
55+
4656
if (repo_init(&r, gitdir, worktree))
4757
die("Couldn't init repo");
4858

0 commit comments

Comments
 (0)