git-p4: add options --commit and --disable-rebase
[gitweb.git] / repository.c
index bb53b54b6d44392078774ae0ab20342c4d8cdf8e..beff3caa9e24a902e560372cdab3c337769c7c89 100644 (file)
@@ -1,5 +1,6 @@
 #include "cache.h"
 #include "repository.h"
+#include "object-store.h"
 #include "config.h"
 #include "submodule-config.h"
 
@@ -12,34 +13,10 @@ void initialize_the_repository(void)
        the_repository = &the_repo;
 
        the_repo.index = &the_index;
+       the_repo.objects = raw_object_store_new();
        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)
-{
-       if (fromenv) {
-               const char *value = getenv(envvar);
-               if (value)
-                       return xstrdup(value);
-       }
-
-       return xstrfmt("%s/%s", git_dir, path);
-}
-
-static int find_common_dir(struct strbuf *sb, const char *gitdir, int fromenv)
-{
-       if (fromenv) {
-               const char *value = getenv(GIT_COMMON_DIR_ENVIRONMENT);
-               if (value) {
-                       strbuf_addstr(sb, value);
-                       return 1;
-               }
-       }
-
-       return get_common_dir_noenv(sb, gitdir);
-}
-
 static void expand_base_dir(char **out, const char *in,
                            const char *base_dir, const char *def_in)
 {
@@ -83,8 +60,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->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,
@@ -156,14 +135,14 @@ 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->ignore_env = 1;
+       repo->objects = raw_object_store_new();
 
        if (repo_init_gitdir(repo, gitdir))
                goto error;
@@ -197,7 +176,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;
@@ -239,12 +218,14 @@ 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->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);
+
        if (repo->config) {
                git_configset_clear(repo->config);
                FREE_AND_NULL(repo->config);