aboutsummaryrefslogtreecommitdiff
path: root/repository.h
diff options
context:
space:
mode:
authorBrandon Williams <bmwill@google.com>2017-06-22 11:43:32 -0700
committerJunio C Hamano <gitster@pobox.com>2017-06-23 18:24:34 -0700
commit359efeffc1f16443be18a80b91ba7cd356eb34f1 (patch)
treef8cecc22fbe18c585c51f637f6113daf8d742f42 /repository.h
parentbf08c8cfc1cff6aa4377efad8bdc166106b3a4d5 (diff)
downloadgit-359efeffc1f16443be18a80b91ba7cd356eb34f1.tar.gz
git-359efeffc1f16443be18a80b91ba7cd356eb34f1.tar.xz
repository: introduce the repository object
Introduce the repository object 'struct repository' which can be used to hold all state pertaining to a git repository. Some of the benefits of object-ifying a repository are: 1. Make the code base more readable and easier to reason about. 2. Allow for working on multiple repositories, specifically submodules, within the same process. Currently the process for working on a submodule involves setting up an argv_array of options for a particular command and then launching a child process to execute the command in the context of the submodule. This is clunky and can require lots of little hacks in order to ensure correctness. Ideally it would be nice to simply pass a repository and an options struct to a command. 3. Eliminating reliance on global state will make it easier to enable the use of threading to improve performance. Signed-off-by: Brandon Williams <bmwill@google.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Diffstat (limited to 'repository.h')
-rw-r--r--repository.h64
1 files changed, 64 insertions, 0 deletions
diff --git a/repository.h b/repository.h
new file mode 100644
index 000000000..0a1db9633
--- /dev/null
+++ b/repository.h
@@ -0,0 +1,64 @@
+#ifndef REPOSITORY_H
+#define REPOSITORY_H
+
+struct repository {
+ /* Environment */
+ /*
+ * Path to the git directory.
+ * Cannot be NULL after initialization.
+ */
+ char *gitdir;
+
+ /*
+ * Path to the common git directory.
+ * Cannot be NULL after initialization.
+ */
+ char *commondir;
+
+ /*
+ * Path to the repository's object store.
+ * Cannot be NULL after initialization.
+ */
+ char *objectdir;
+
+ /*
+ * Path to the repository's graft file.
+ * Cannot be NULL after initialization.
+ */
+ char *graft_file;
+
+ /*
+ * Path to the current worktree's index file.
+ * Cannot be NULL after initialization.
+ */
+ char *index_file;
+
+ /*
+ * Path to the working directory.
+ * A NULL value indicates that there is no working directory.
+ */
+ char *worktree;
+
+ /* Configurations */
+ /*
+ * Bit used during initialization to indicate if repository state (like
+ * the location of the 'objectdir') should be read from the
+ * environment. By default this bit will be set at the begining of
+ * 'repo_init()' so that all repositories will ignore the environment.
+ * The exception to this is 'the_repository', which doesn't go through
+ * the normal 'repo_init()' process.
+ */
+ unsigned ignore_env:1;
+
+ /* Indicate if a repository has a different 'commondir' from 'gitdir' */
+ unsigned different_commondir:1;
+};
+
+extern struct repository *the_repository;
+
+extern void repo_set_gitdir(struct repository *repo, const char *path);
+extern void repo_set_worktree(struct repository *repo, const char *path);
+extern int repo_init(struct repository *repo, const char *gitdir, const char *worktree);
+extern void repo_clear(struct repository *repo);
+
+#endif /* REPOSITORY_H */