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>
Nguyễn Thái Ngọc Duy committed
Mar 3, 2018 at 18:35 UTC
b2f0eceecf266e60fa95970e0973a8f23f911fb1
3 files changed
+16
-6
common-main.c
+2
@@ -34,6 +34,8 @@ int main(int argc, const char **argv)
34
35
git_setup_gettext();
36
37
+ initialize_the_repository();
38
+
39
attr_start();
40
41
git_extract_argv0_path(argv[0]);
repository.c
+13
-5
@@ -4,10 +4,16 @@
4
#include "submodule-config.h"
5
6
/* The main repository */
7
-static struct repository the_repo = {
8
- NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, &the_index, &hash_algos[GIT_HASH_SHA1], 0, 0
9
-};
10
-struct repository *the_repository = &the_repo;
7
+static struct repository the_repo;
8
+struct repository *the_repository;
9
+
10
+void initialize_the_repository(void)
11
+{
12
+ the_repository = &the_repo;
13
+
14
+ the_repo.index = &the_index;
15
+ repo_set_hash_algo(&the_repo, GIT_HASH_SHA1);
16
+}
17
18
static char *git_path_from_env(const char *envvar, const char *git_dir,
19
const char *path, int fromenv)
@@ -128,7 +134,9 @@ static int read_and_verify_repository_format(struct repository_format *format,
134
* Initialize 'repo' based on the provided 'gitdir'.
135
* Return 0 upon success and a non-zero value upon failure.
136
*/
131
-int repo_init(struct repository *repo, const char *gitdir, const char *worktree)
137
+static int repo_init(struct repository *repo,
138
+ const char *gitdir,
139
+ const char *worktree)
140
{
141
struct repository_format format;
142
memset(repo, 0, sizeof(*repo));
repository.h
+1
-1
@@ -91,7 +91,7 @@ extern struct repository *the_repository;
91
extern void repo_set_gitdir(struct repository *repo, const char *path);
92
extern void repo_set_worktree(struct repository *repo, const char *path);
93
extern void repo_set_hash_algo(struct repository *repo, int algo);
94
-extern int repo_init(struct repository *repo, const char *gitdir, const char *worktree);
94
+extern void initialize_the_repository(void);
95
extern int repo_submodule_init(struct repository *submodule,
96
struct repository *superproject,
97
const char *path);