summaryrefslogtreecommitdiff
path: root/repository.c
diff options
context:
space:
mode:
Diffstat (limited to 'repository.c')
-rw-r--r--repository.c51
1 files changed, 33 insertions, 18 deletions
diff --git a/repository.c b/repository.c
index 5dd1486718..65e6f8b8fd 100644
--- a/repository.c
+++ b/repository.c
@@ -1,13 +1,20 @@
+/*
+ * not really _using_ the compat macros, just make sure the_index
+ * declaration matches the definition in this file.
+ */
+#define USE_THE_INDEX_COMPATIBILITY_MACROS
#include "cache.h"
#include "repository.h"
#include "object-store.h"
#include "config.h"
#include "object.h"
+#include "lockfile.h"
#include "submodule-config.h"
/* The main repository */
static struct repository the_repo;
struct repository *the_repository;
+struct index_state the_index;
void initialize_the_repository(void)
{
@@ -63,8 +70,14 @@ void repo_set_gitdir(struct repository *repo,
free(old_gitdir);
repo_set_commondir(repo, o->commondir);
- expand_base_dir(&repo->objects->objectdir, o->object_dir,
+
+ if (!repo->objects->odb) {
+ repo->objects->odb = xcalloc(1, sizeof(*repo->objects->odb));
+ repo->objects->odb_tail = &repo->objects->odb->next;
+ }
+ expand_base_dir(&repo->objects->odb->path, 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,
@@ -166,30 +179,23 @@ error:
return -1;
}
-/*
- * Initialize 'submodule' as the submodule given by 'path' in parent repository
- * 'superproject'.
- * Return 0 upon success and a non-zero value upon failure.
- */
-int repo_submodule_init(struct repository *submodule,
+int repo_submodule_init(struct repository *subrepo,
struct repository *superproject,
- const char *path)
+ const struct submodule *sub)
{
- const struct submodule *sub;
struct strbuf gitdir = STRBUF_INIT;
struct strbuf worktree = STRBUF_INIT;
int ret = 0;
- sub = submodule_from_path(superproject, &null_oid, path);
if (!sub) {
ret = -1;
goto out;
}
- strbuf_repo_worktree_path(&gitdir, superproject, "%s/.git", path);
- strbuf_repo_worktree_path(&worktree, superproject, "%s", path);
+ strbuf_repo_worktree_path(&gitdir, superproject, "%s/.git", sub->path);
+ strbuf_repo_worktree_path(&worktree, superproject, "%s", sub->path);
- if (repo_init(submodule, gitdir.buf, worktree.buf)) {
+ if (repo_init(subrepo, gitdir.buf, worktree.buf)) {
/*
* If initilization fails then it may be due to the submodule
* not being populated in the superproject's worktree. Instead
@@ -201,16 +207,16 @@ int repo_submodule_init(struct repository *submodule,
strbuf_repo_git_path(&gitdir, superproject,
"modules/%s", sub->name);
- if (repo_init(submodule, gitdir.buf, NULL)) {
+ if (repo_init(subrepo, gitdir.buf, NULL)) {
ret = -1;
goto out;
}
}
- submodule->submodule_prefix = xstrfmt("%s%s/",
- superproject->submodule_prefix ?
- superproject->submodule_prefix :
- "", path);
+ subrepo->submodule_prefix = xstrfmt("%s%s/",
+ superproject->submodule_prefix ?
+ superproject->submodule_prefix :
+ "", sub->path);
out:
strbuf_release(&gitdir);
@@ -257,3 +263,12 @@ int repo_read_index(struct repository *repo)
return read_index_from(repo->index, repo->index_file, repo->gitdir);
}
+
+int repo_hold_locked_index(struct repository *repo,
+ struct lock_file *lf,
+ int flags)
+{
+ if (!repo->index_file)
+ BUG("the repo hasn't been setup");
+ return hold_lock_file_for_update(lf, repo->index_file, flags);
+}