repository.h 5.6 KB

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