On Fri, Feb 23, 2018 at 04:47:28PM -0800, Stefan Beller wrote:
> /* 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
> + NULL, NULL,
> + RAW_OBJECT_STORE_INIT,
> + NULL, NULL, NULL,
> + NULL, NULL, NULL,
> + &the_index,
> + &hash_algos[GIT_HASH_SHA1],
> + 0, 0
> };
> struct repository *the_repository = &the_repo;
I wonder if we should do something like this. It makes the_repo
initialization easier to read and it helps unify the init code with
submodule.
No don't reroll. If you think it's a good idea, you can do something
like this in the next series instead.
-- 8< --
diff --git a/check-racy.c b/check-racy.c
index 24b6542352..47cbb4eb6d 100644
--- a/check-racy.c
+++ b/check-racy.c
@@ -1,10 +1,12 @@
#include "cache.h"
+#include "repository.h"
int main(int ac, char **av)
{
int i;
int dirty, clean, racy;
+ init_the_repository();
dirty = clean = racy = 0;
read_cache();
for (i = 0; i < active_nr; i++) {
diff --git a/common-main.c b/common-main.c
index 6a689007e7..a13ab981aa 100644
--- a/common-main.c
+++ b/common-main.c
@@ -1,6 +1,7 @@
#include "cache.h"
#include "exec_cmd.h"
#include "attr.h"
+#include "repository.h"
/*
* Many parts of Git have subprograms communicate via pipe, expect the
@@ -32,6 +33,8 @@ int main(int argc, const char **argv)
*/
sanitize_stdfds();
+ init_the_repository();
+
git_setup_gettext();
attr_start();
diff --git a/object-store.h b/object-store.h
index cf35760ceb..c3253ebc59 100644
--- a/object-store.h
+++ b/object-store.h
@@ -8,8 +8,8 @@ struct raw_object_store {
*/
char *objectdir;
};
-#define RAW_OBJECT_STORE_INIT { NULL }
+void raw_object_store_init(struct raw_object_store *o);
void raw_object_store_clear(struct raw_object_store *o);
#endif /* OBJECT_STORE_H */
diff --git a/object.c b/object.c
index 11d904c033..8a4d01dd5f 100644
--- a/object.c
+++ b/object.c
@@ -446,6 +446,11 @@ void clear_commit_marks_all(unsigned int flags)
}
}
+void raw_object_store_init(struct raw_object_store *o)
+{
+ memset(o, 0, sizeof(*o));
+}
+
void raw_object_store_clear(struct raw_object_store *o)
{
free(o->objectdir);
diff --git a/repository.c b/repository.c
index 2255ff657e..0ebcca8539 100644
--- a/repository.c
+++ b/repository.c
@@ -5,16 +5,22 @@
#include "submodule-config.h"
/* The main repository */
-static struct repository the_repo = {
- NULL, NULL,
- RAW_OBJECT_STORE_INIT,
- 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;
+
+static void repo_pre_init(struct repository *repo)
+{
+ memset(repo, 0, sizeof(*repo));
+ raw_object_store_init(&repo->objects);
+}
+
+void init_the_repository(void)
+{
+ the_repository = &the_repo;
+ repo_pre_init(the_repository);
+ the_repository->index = &the_index;
+ repo_set_hash_algo(the_repository, GIT_HASH_SHA1);
+}
static char *git_path_from_env(const char *envvar, const char *git_dir,
const char *path, int fromenv)
@@ -138,7 +144,8 @@ static int read_and_verify_repository_format(struct
repository_format *format,
int repo_init(struct repository *repo, const char *gitdir, const char
*worktree)
{
struct repository_format format;
- memset(repo, 0, sizeof(*repo));
+
+ repo_pre_init(repo);
repo->ignore_env = 1;
diff --git a/repository.h b/repository.h
index 1f8bc7a7cf..da6a8f9af9 100644
--- a/repository.h
+++ b/repository.h
@@ -93,6 +93,7 @@ extern void repo_set_gitdir(struct repository *repo, const
char *path);
extern void repo_set_worktree(struct repository *repo, const char *path);
extern void repo_set_hash_algo(struct repository *repo, int algo);
extern int repo_init(struct repository *repo, const char *gitdir, const char
*worktree);
+extern void init_the_repository(void);
extern int repo_submodule_init(struct repository *submodule,
struct repository *superproject,
const char *path);
-- 8< --