cc285ad3278bf8ac40dfb780afa523e2ee280029
   1#ifndef REPOSITORY_H
   2#define REPOSITORY_H
   3
   4#include "path.h"
   5
   6struct config_set;
   7struct git_hash_algo;
   8struct index_state;
   9struct lock_file;
  10struct pathspec;
  11struct raw_object_store;
  12struct submodule_cache;
  13
  14struct repo_settings {
  15        int initialized;
  16
  17        int core_commit_graph;
  18        int gc_write_commit_graph;
  19
  20        int index_version;
  21
  22        int pack_use_sparse;
  23};
  24
  25struct repository {
  26        /* Environment */
  27        /*
  28         * Path to the git directory.
  29         * Cannot be NULL after initialization.
  30         */
  31        char *gitdir;
  32
  33        /*
  34         * Path to the common git directory.
  35         * Cannot be NULL after initialization.
  36         */
  37        char *commondir;
  38
  39        /*
  40         * Holds any information related to accessing the raw object content.
  41         */
  42        struct raw_object_store *objects;
  43
  44        /*
  45         * All objects in this repository that have been parsed. This structure
  46         * owns all objects it references, so users of "struct object *"
  47         * generally do not need to free them; instead, when a repository is no
  48         * longer used, call parsed_object_pool_clear() on this structure, which
  49         * is called by the repositories repo_clear on its desconstruction.
  50         */
  51        struct parsed_object_pool *parsed_objects;
  52
  53        /* The store in which the refs are held. */
  54        struct ref_store *refs;
  55
  56        /*
  57         * Contains path to often used file names.
  58         */
  59        struct path_cache cached_paths;
  60
  61        /*
  62         * Path to the repository's graft file.
  63         * Cannot be NULL after initialization.
  64         */
  65        char *graft_file;
  66
  67        /*
  68         * Path to the current worktree's index file.
  69         * Cannot be NULL after initialization.
  70         */
  71        char *index_file;
  72
  73        /*
  74         * Path to the working directory.
  75         * A NULL value indicates that there is no working directory.
  76         */
  77        char *worktree;
  78
  79        /*
  80         * Path from the root of the top-level superproject down to this
  81         * repository.  This is only non-NULL if the repository is initialized
  82         * as a submodule of another repository.
  83         */
  84        char *submodule_prefix;
  85
  86        struct repo_settings settings;
  87
  88        /* Subsystems */
  89        /*
  90         * Repository's config which contains key-value pairs from the usual
  91         * set of config files (i.e. repo specific .git/config, user wide
  92         * ~/.gitconfig, XDG config file and the global /etc/gitconfig)
  93         */
  94        struct config_set *config;
  95
  96        /* Repository's submodule config as defined by '.gitmodules' */
  97        struct submodule_cache *submodule_cache;
  98
  99        /*
 100         * Repository's in-memory index.
 101         * 'repo_read_index()' can be used to populate 'index'.
 102         */
 103        struct index_state *index;
 104
 105        /* Repository's current hash algorithm, as serialized on disk. */
 106        const struct git_hash_algo *hash_algo;
 107
 108        /* A unique-id for tracing purposes. */
 109        int trace2_repo_id;
 110
 111        /* Configurations */
 112
 113        /* Indicate if a repository has a different 'commondir' from 'gitdir' */
 114        unsigned different_commondir:1;
 115};
 116
 117extern struct repository *the_repository;
 118
 119/*
 120 * Define a custom repository layout. Any field can be NULL, which
 121 * will default back to the path according to the default layout.
 122 */
 123struct set_gitdir_args {
 124        const char *commondir;
 125        const char *object_dir;
 126        const char *graft_file;
 127        const char *index_file;
 128        const char *alternate_db;
 129};
 130
 131void repo_set_gitdir(struct repository *repo, const char *root,
 132                     const struct set_gitdir_args *extra_args);
 133void repo_set_worktree(struct repository *repo, const char *path);
 134void repo_set_hash_algo(struct repository *repo, int algo);
 135void initialize_the_repository(void);
 136int repo_init(struct repository *r, const char *gitdir, const char *worktree);
 137
 138/*
 139 * Initialize the repository 'subrepo' as the submodule given by the
 140 * struct submodule 'sub' in parent repository 'superproject'.
 141 * Return 0 upon success and a non-zero value upon failure, which may happen
 142 * if the submodule is not found, or 'sub' is NULL.
 143 */
 144struct submodule;
 145int repo_submodule_init(struct repository *subrepo,
 146                        struct repository *superproject,
 147                        const struct submodule *sub);
 148void repo_clear(struct repository *repo);
 149
 150/*
 151 * Populates the repository's index from its index_file, an index struct will
 152 * be allocated if needed.
 153 *
 154 * Return the number of index entries in the populated index or a value less
 155 * than zero if an error occured.  If the repository's index has already been
 156 * populated then the number of entries will simply be returned.
 157 */
 158int repo_read_index(struct repository *repo);
 159int repo_hold_locked_index(struct repository *repo,
 160                           struct lock_file *lf,
 161                           int flags);
 162
 163int repo_read_index_preload(struct repository *,
 164                            const struct pathspec *pathspec,
 165                            unsigned refresh_flags);
 166int repo_read_index_unmerged(struct repository *);
 167/*
 168 * Opportunistically update the index but do not complain if we can't.
 169 * The lockfile is always committed or rolled back.
 170 */
 171void repo_update_index_if_able(struct repository *, struct lock_file *);
 172
 173void prepare_repo_settings(struct repository *r);
 174
 175#endif /* REPOSITORY_H */