Merge branch 'jt/clone-server-option'
[git/raj.git] / repository.h
blob4fb6a5885f794dea9ff7a1ecf37f27bc34e4d218
1 #ifndef REPOSITORY_H
2 #define REPOSITORY_H
4 #include "path.h"
6 struct config_set;
7 struct git_hash_algo;
8 struct index_state;
9 struct lock_file;
10 struct pathspec;
11 struct raw_object_store;
12 struct submodule_cache;
14 struct repository {
15 /* Environment */
17 * Path to the git directory.
18 * Cannot be NULL after initialization.
20 char *gitdir;
23 * Path to the common git directory.
24 * Cannot be NULL after initialization.
26 char *commondir;
29 * Holds any information related to accessing the raw object content.
31 struct raw_object_store *objects;
34 * All objects in this repository that have been parsed. This structure
35 * owns all objects it references, so users of "struct object *"
36 * generally do not need to free them; instead, when a repository is no
37 * longer used, call parsed_object_pool_clear() on this structure, which
38 * is called by the repositories repo_clear on its desconstruction.
40 struct parsed_object_pool *parsed_objects;
42 /* The store in which the refs are held. */
43 struct ref_store *refs;
46 * Contains path to often used file names.
48 struct path_cache cached_paths;
51 * Path to the repository's graft file.
52 * Cannot be NULL after initialization.
54 char *graft_file;
57 * Path to the current worktree's index file.
58 * Cannot be NULL after initialization.
60 char *index_file;
63 * Path to the working directory.
64 * A NULL value indicates that there is no working directory.
66 char *worktree;
69 * Path from the root of the top-level superproject down to this
70 * repository. This is only non-NULL if the repository is initialized
71 * as a submodule of another repository.
73 char *submodule_prefix;
75 /* Subsystems */
77 * Repository's config which contains key-value pairs from the usual
78 * set of config files (i.e. repo specific .git/config, user wide
79 * ~/.gitconfig, XDG config file and the global /etc/gitconfig)
81 struct config_set *config;
83 /* Repository's submodule config as defined by '.gitmodules' */
84 struct submodule_cache *submodule_cache;
87 * Repository's in-memory index.
88 * 'repo_read_index()' can be used to populate 'index'.
90 struct index_state *index;
92 /* Repository's current hash algorithm, as serialized on disk. */
93 const struct git_hash_algo *hash_algo;
95 /* A unique-id for tracing purposes. */
96 int trace2_repo_id;
98 /* Configurations */
100 /* Indicate if a repository has a different 'commondir' from 'gitdir' */
101 unsigned different_commondir:1;
104 extern struct repository *the_repository;
107 * Define a custom repository layout. Any field can be NULL, which
108 * will default back to the path according to the default layout.
110 struct set_gitdir_args {
111 const char *commondir;
112 const char *object_dir;
113 const char *graft_file;
114 const char *index_file;
115 const char *alternate_db;
118 void repo_set_gitdir(struct repository *repo, const char *root,
119 const struct set_gitdir_args *extra_args);
120 void repo_set_worktree(struct repository *repo, const char *path);
121 void repo_set_hash_algo(struct repository *repo, int algo);
122 void initialize_the_repository(void);
123 int repo_init(struct repository *r, const char *gitdir, const char *worktree);
126 * Initialize the repository 'subrepo' as the submodule given by the
127 * struct submodule 'sub' in parent repository 'superproject'.
128 * Return 0 upon success and a non-zero value upon failure, which may happen
129 * if the submodule is not found, or 'sub' is NULL.
131 struct submodule;
132 int repo_submodule_init(struct repository *subrepo,
133 struct repository *superproject,
134 const struct submodule *sub);
135 void repo_clear(struct repository *repo);
138 * Populates the repository's index from its index_file, an index struct will
139 * be allocated if needed.
141 * Return the number of index entries in the populated index or a value less
142 * than zero if an error occured. If the repository's index has already been
143 * populated then the number of entries will simply be returned.
145 int repo_read_index(struct repository *repo);
146 int repo_hold_locked_index(struct repository *repo,
147 struct lock_file *lf,
148 int flags);
150 int repo_read_index_preload(struct repository *,
151 const struct pathspec *pathspec,
152 unsigned refresh_flags);
153 int repo_read_index_unmerged(struct repository *);
155 * Opportunistically update the index but do not complain if we can't.
156 * The lockfile is always committed or rolled back.
158 void repo_update_index_if_able(struct repository *, struct lock_file *);
161 #endif /* REPOSITORY_H */