t/helper/test-repository: celebrate independence from the_repository
authorStefan Beller <sbeller@google.com>
Sat, 15 Dec 2018 00:09:42 +0000 (16:09 -0800)
committerJunio C Hamano <gitster@pobox.com>
Fri, 28 Dec 2018 18:06:33 +0000 (10:06 -0800)
dade47c06c (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 <sbeller@google.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
cache.h
t/helper/test-repository.c
diff --git a/cache.h b/cache.h
index 59c8a930466d034ea2ce84b362e464803e19a100..8864d7ec1518dc6e280d068d315025fa30344c83 100644 (file)
--- a/cache.h
+++ b/cache.h
@@ -1033,6 +1033,8 @@ static inline int hashcmp(const unsigned char *sha1, const unsigned char *sha2)
         *
         * This will need to be extended or ripped out when we learn about
         * hashes of different sizes.
+        *
+        * When ripping this out, see TODO in test-repository.c.
         */
        if (the_hash_algo->rawsz != 20)
                BUG("hash size not yet supported by hashcmp");
index 6a84a53efbf6919c83d3f1fd73786acd92ee7abf..f7f861844560e0578eda989e39c4bd0572dcd5d6 100644 (file)
@@ -17,6 +17,11 @@ static void test_parse_commit_in_graph(const char *gitdir, const char *worktree,
 
        setup_git_env(gitdir);
 
+       memset(the_repository, 0, sizeof(*the_repository));
+
+       /* TODO: Needed for temporary hack in hashcmp, see 183a638b7da. */
+       repo_set_hash_algo(the_repository, GIT_HASH_SHA1);
+
        if (repo_init(&r, gitdir, worktree))
                die("Couldn't init repo");
 
@@ -43,6 +48,11 @@ static void test_get_commit_tree_in_graph(const char *gitdir,
 
        setup_git_env(gitdir);
 
+       memset(the_repository, 0, sizeof(*the_repository));
+
+       /* TODO: Needed for temporary hack in hashcmp, see 183a638b7da. */
+       repo_set_hash_algo(the_repository, GIT_HASH_SHA1);
+
        if (repo_init(&r, gitdir, worktree))
                die("Couldn't init repo");