Merge branch 'mk/merge-in-sparse-checkout'
[gitweb.git] / repository.c
index 62f52f47fcaed32c4f14a9f76eb1e66e13d4046a..5dd148671811b383a64b8f3adab87804cea9db08 100644 (file)
@@ -1,6 +1,8 @@
 #include "cache.h"
 #include "repository.h"
+#include "object-store.h"
 #include "config.h"
+#include "object.h"
 #include "submodule-config.h"
 
 /* The main repository */
@@ -12,6 +14,9 @@ void initialize_the_repository(void)
        the_repository = &the_repo;
 
        the_repo.index = &the_index;
+       the_repo.objects = raw_object_store_new();
+       the_repo.parsed_objects = parsed_object_pool_new();
+
        repo_set_hash_algo(&the_repo, GIT_HASH_SHA1);
 }
 
@@ -58,10 +63,10 @@ void repo_set_gitdir(struct repository *repo,
        free(old_gitdir);
 
        repo_set_commondir(repo, o->commondir);
-       expand_base_dir(&repo->objectdir, o->object_dir,
+       expand_base_dir(&repo->objects->objectdir, o->object_dir,
                        repo->commondir, "objects");
-       free(repo->alternate_db);
-       repo->alternate_db = xstrdup_or_null(o->alternate_db);
+       free(repo->objects->alternate_db);
+       repo->objects->alternate_db = xstrdup_or_null(o->alternate_db);
        expand_base_dir(&repo->graft_file, o->graft_file,
                        repo->commondir, "info/grafts");
        expand_base_dir(&repo->index_file, o->index_file,
@@ -133,13 +138,16 @@ 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.
  */
-static int repo_init(struct repository *repo,
-                    const char *gitdir,
-                    const char *worktree)
+int repo_init(struct repository *repo,
+             const char *gitdir,
+             const char *worktree)
 {
        struct repository_format format;
        memset(repo, 0, sizeof(*repo));
 
+       repo->objects = raw_object_store_new();
+       repo->parsed_objects = parsed_object_pool_new();
+
        if (repo_init_gitdir(repo, gitdir))
                goto error;
 
@@ -172,7 +180,7 @@ int repo_submodule_init(struct repository *submodule,
        struct strbuf worktree = STRBUF_INIT;
        int ret = 0;
 
-       sub = submodule_from_cache(superproject, &null_oid, path);
+       sub = submodule_from_path(superproject, &null_oid, path);
        if (!sub) {
                ret = -1;
                goto out;
@@ -214,13 +222,17 @@ void repo_clear(struct repository *repo)
 {
        FREE_AND_NULL(repo->gitdir);
        FREE_AND_NULL(repo->commondir);
-       FREE_AND_NULL(repo->objectdir);
-       FREE_AND_NULL(repo->alternate_db);
        FREE_AND_NULL(repo->graft_file);
        FREE_AND_NULL(repo->index_file);
        FREE_AND_NULL(repo->worktree);
        FREE_AND_NULL(repo->submodule_prefix);
 
+       raw_object_store_clear(repo->objects);
+       FREE_AND_NULL(repo->objects);
+
+       parsed_object_pool_clear(repo->parsed_objects);
+       FREE_AND_NULL(repo->parsed_objects);
+
        if (repo->config) {
                git_configset_clear(repo->config);
                FREE_AND_NULL(repo->config);
@@ -233,7 +245,8 @@ void repo_clear(struct repository *repo)
 
        if (repo->index) {
                discard_index(repo->index);
-               FREE_AND_NULL(repo->index);
+               if (repo->index != &the_index)
+                       FREE_AND_NULL(repo->index);
        }
 }