summaryrefslogtreecommitdiff
path: root/repository.c
diff options
context:
space:
mode:
authorNguyễn Thái Ngọc Duy <pclouds@gmail.com>2018-03-03 11:35:54 (GMT)
committerJunio C Hamano <gitster@pobox.com>2018-03-05 19:14:03 (GMT)
commitb2f0eceecf266e60fa95970e0973a8f23f911fb1 (patch)
treeca03c9b0c360f210b0005112c2b01278c7b9c0a7 /repository.c
parentb2e45c695d09f6a31ce09347ae0a5d2cdfe9dd4e (diff)
downloadgit-b2f0eceecf266e60fa95970e0973a8f23f911fb1.zip
git-b2f0eceecf266e60fa95970e0973a8f23f911fb1.tar.gz
git-b2f0eceecf266e60fa95970e0973a8f23f911fb1.tar.bz2
repository: initialize the_repository in main()
This simplifies initialization of struct repository and anything inside. Easier to read. Easier to add/remove fields. Everything will go through main() common-main.c so this should cover all programs, including t/helper. Signed-off-by: Nguyễn Thái Ngọc Duy <pclouds@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Diffstat (limited to 'repository.c')
-rw-r--r--repository.c18
1 files changed, 13 insertions, 5 deletions
diff --git a/repository.c b/repository.c
index 4ffbe9b..0eddf28 100644
--- a/repository.c
+++ b/repository.c
@@ -4,10 +4,16 @@
#include "submodule-config.h"
/* The main repository */
-static struct repository the_repo = {
- NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, &the_index, &hash_algos[GIT_HASH_SHA1], 0, 0
-};
-struct repository *the_repository = &the_repo;
+static struct repository the_repo;
+struct repository *the_repository;
+
+void initialize_the_repository(void)
+{
+ the_repository = &the_repo;
+
+ the_repo.index = &the_index;
+ repo_set_hash_algo(&the_repo, GIT_HASH_SHA1);
+}
static char *git_path_from_env(const char *envvar, const char *git_dir,
const char *path, int fromenv)
@@ -128,7 +134,9 @@ static int read_and_verify_repository_format(struct repository_format *format,
* Initialize 'repo' based on the provided 'gitdir'.
* Return 0 upon success and a non-zero value upon failure.
*/
-int repo_init(struct repository *repo, const char *gitdir, const char *worktree)
+static int repo_init(struct repository *repo,
+ const char *gitdir,
+ const char *worktree)
{
struct repository_format format;
memset(repo, 0, sizeof(*repo));