| 1 | #ifndef ENVIRONMENT_H |
| 2 | #define ENVIRONMENT_H |
| 3 | |
| 4 | #include "repo-settings.h" |
| 5 | #include "branch.h" |
| 6 | |
| 7 | /* Double-check local_repo_env below if you add to this list. */ |
| 8 | #define GIT_DIR_ENVIRONMENT "GIT_DIR" |
| 9 | #define GIT_COMMON_DIR_ENVIRONMENT "GIT_COMMON_DIR" |
| 10 | #define GIT_NAMESPACE_ENVIRONMENT "GIT_NAMESPACE" |
| 11 | #define GIT_WORK_TREE_ENVIRONMENT "GIT_WORK_TREE" |
| 12 | #define GIT_PREFIX_ENVIRONMENT "GIT_PREFIX" |
| 13 | #define DEFAULT_GIT_DIR_ENVIRONMENT ".git" |
| 14 | #define DB_ENVIRONMENT "GIT_OBJECT_DIRECTORY" |
| 15 | #define INDEX_ENVIRONMENT "GIT_INDEX_FILE" |
| 16 | #define GRAFT_ENVIRONMENT "GIT_GRAFT_FILE" |
| 17 | #define GIT_SHALLOW_FILE_ENVIRONMENT "GIT_SHALLOW_FILE" |
| 18 | #define TEMPLATE_DIR_ENVIRONMENT "GIT_TEMPLATE_DIR" |
| 19 | #define CONFIG_ENVIRONMENT "GIT_CONFIG" |
| 20 | #define CONFIG_DATA_ENVIRONMENT "GIT_CONFIG_PARAMETERS" |
| 21 | #define CONFIG_COUNT_ENVIRONMENT "GIT_CONFIG_COUNT" |
| 22 | #define EXEC_PATH_ENVIRONMENT "GIT_EXEC_PATH" |
| 23 | #define CEILING_DIRECTORIES_ENVIRONMENT "GIT_CEILING_DIRECTORIES" |
| 24 | #define NO_REPLACE_OBJECTS_ENVIRONMENT "GIT_NO_REPLACE_OBJECTS" |
| 25 | #define GIT_REPLACE_REF_BASE_ENVIRONMENT "GIT_REPLACE_REF_BASE" |
| 26 | #define NO_LAZY_FETCH_ENVIRONMENT "GIT_NO_LAZY_FETCH" |
| 27 | #define GITATTRIBUTES_FILE ".gitattributes" |
| 28 | #define INFOATTRIBUTES_FILE "info/attributes" |
| 29 | #define ATTRIBUTE_MACRO_PREFIX "[attr]" |
| 30 | #define GITMODULES_FILE ".gitmodules" |
| 31 | #define GITMODULES_INDEX ":.gitmodules" |
| 32 | #define GITMODULES_HEAD "HEAD:.gitmodules" |
| 33 | #define GIT_NOTES_REF_ENVIRONMENT "GIT_NOTES_REF" |
| 34 | #define GIT_NOTES_DEFAULT_REF "refs/notes/commits" |
| 35 | #define GIT_NOTES_DISPLAY_REF_ENVIRONMENT "GIT_NOTES_DISPLAY_REF" |
| 36 | #define GIT_NOTES_REWRITE_REF_ENVIRONMENT "GIT_NOTES_REWRITE_REF" |
| 37 | #define GIT_NOTES_REWRITE_MODE_ENVIRONMENT "GIT_NOTES_REWRITE_MODE" |
| 38 | #define GIT_LITERAL_PATHSPECS_ENVIRONMENT "GIT_LITERAL_PATHSPECS" |
| 39 | #define GIT_GLOB_PATHSPECS_ENVIRONMENT "GIT_GLOB_PATHSPECS" |
| 40 | #define GIT_NOGLOB_PATHSPECS_ENVIRONMENT "GIT_NOGLOB_PATHSPECS" |
| 41 | #define GIT_ICASE_PATHSPECS_ENVIRONMENT "GIT_ICASE_PATHSPECS" |
| 42 | #define GIT_QUARANTINE_ENVIRONMENT "GIT_QUARANTINE_PATH" |
| 43 | #define GIT_OPTIONAL_LOCKS_ENVIRONMENT "GIT_OPTIONAL_LOCKS" |
| 44 | #define GIT_TEXT_DOMAIN_DIR_ENVIRONMENT "GIT_TEXTDOMAINDIR" |
| 45 | #define GIT_ATTR_SOURCE_ENVIRONMENT "GIT_ATTR_SOURCE" |
| 46 | #define GIT_REFERENCE_BACKEND_ENVIRONMENT "GIT_REFERENCE_BACKEND" |
| 47 | |
| 48 | /* |
| 49 | * Environment variable used to propagate the --no-advice global option to the |
| 50 | * advice_enabled() helper, even when run in a subprocess. |
| 51 | * This is an internal variable that should not be set by the user. |
| 52 | */ |
| 53 | #define GIT_ADVICE_ENVIRONMENT "GIT_ADVICE" |
| 54 | |
| 55 | /* |
| 56 | * Environment variable used in handshaking the wire protocol. |
| 57 | * Contains a colon ':' separated list of keys with optional values |
| 58 | * 'key[=value]'. Presence of unknown keys and values must be |
| 59 | * ignored. |
| 60 | */ |
| 61 | #define GIT_PROTOCOL_ENVIRONMENT "GIT_PROTOCOL" |
| 62 | /* HTTP header used to handshake the wire protocol */ |
| 63 | #define GIT_PROTOCOL_HEADER "Git-Protocol" |
| 64 | |
| 65 | /* |
| 66 | * This environment variable is expected to contain a boolean indicating |
| 67 | * whether we should or should not treat: |
| 68 | * |
| 69 | * GIT_DIR=foo.git git ... |
| 70 | * |
| 71 | * as if GIT_WORK_TREE=. was given. It's not expected that users will make use |
| 72 | * of this, but we use it internally to communicate to sub-processes that we |
| 73 | * are in a bare repo. If not set, defaults to true. |
| 74 | */ |
| 75 | #define GIT_IMPLICIT_WORK_TREE_ENVIRONMENT "GIT_IMPLICIT_WORK_TREE" |
| 76 | |
| 77 | #define ALTERNATE_DB_ENVIRONMENT "GIT_ALTERNATE_OBJECT_DIRECTORIES" |
| 78 | |
| 79 | /* |
| 80 | * Repository-local GIT_* environment variables; these will be cleared |
| 81 | * when git spawns a sub-process that runs inside another repository. |
| 82 | * The array is NULL-terminated, which makes it easy to pass in the "env" |
| 83 | * parameter of a run-command invocation, or to do a simple walk. |
| 84 | */ |
| 85 | extern const char * const local_repo_env[]; |
| 86 | |
| 87 | struct strvec; |
| 88 | |
| 89 | struct repository; |
| 90 | |
| 91 | /* |
| 92 | * NEEDSWORK: It would be better if these definitions could be moved to |
| 93 | * other more specific files, but care is needed to avoid circular |
| 94 | * inclusion issues. |
| 95 | */ |
| 96 | enum push_default_type { |
| 97 | PUSH_DEFAULT_NOTHING = 0, |
| 98 | PUSH_DEFAULT_MATCHING, |
| 99 | PUSH_DEFAULT_SIMPLE, |
| 100 | PUSH_DEFAULT_UPSTREAM, |
| 101 | PUSH_DEFAULT_CURRENT, |
| 102 | PUSH_DEFAULT_UNSPECIFIED |
| 103 | }; |
| 104 | |
| 105 | enum rebase_setup_type { |
| 106 | AUTOREBASE_NEVER = 0, |
| 107 | AUTOREBASE_LOCAL, |
| 108 | AUTOREBASE_REMOTE, |
| 109 | AUTOREBASE_ALWAYS |
| 110 | }; |
| 111 | |
| 112 | enum object_creation_mode { |
| 113 | OBJECT_CREATION_USES_HARDLINKS = 0, |
| 114 | OBJECT_CREATION_USES_RENAMES = 1 |
| 115 | }; |
| 116 | |
| 117 | struct repo_config_values { |
| 118 | /* section "core" config values */ |
| 119 | char *attributes_file; |
| 120 | char *excludes_file; |
| 121 | char *editor_program; |
| 122 | char *pager_program; |
| 123 | char *askpass_program; |
| 124 | char *apply_default_whitespace; |
| 125 | char *apply_default_ignorewhitespace; |
| 126 | enum push_default_type push_default; |
| 127 | enum rebase_setup_type autorebase; |
| 128 | enum object_creation_mode object_creation_mode; |
| 129 | int apply_sparse_checkout; |
| 130 | int trust_ctime; |
| 131 | int check_stat; |
| 132 | int zlib_compression_level; |
| 133 | int pack_compression_level; |
| 134 | int precomposed_unicode; |
| 135 | int core_sparse_checkout_cone; |
| 136 | int warn_on_object_refname_ambiguity; |
| 137 | int protect_hfs; |
| 138 | int protect_ntfs; |
| 139 | int ignore_case; |
| 140 | int trust_executable_bit; |
| 141 | int has_symlinks; |
| 142 | |
| 143 | /* section "sparse" config values */ |
| 144 | int sparse_expect_files_outside_of_patterns; |
| 145 | |
| 146 | /* section "branch" config values */ |
| 147 | enum branch_track branch_track; |
| 148 | }; |
| 149 | |
| 150 | struct repo_config_values *repo_config_values(struct repository *repo); |
| 151 | |
| 152 | /* |
| 153 | * Wrapper of getenv() that returns a strdup value. This value is kept |
| 154 | * in argv to be freed later. |
| 155 | */ |
| 156 | const char *getenv_safe(struct strvec *argv, const char *name); |
| 157 | |
| 158 | /* |
| 159 | * Should we print an ellipsis after an abbreviated SHA-1 value |
| 160 | * when doing diff-raw output or indicating a detached HEAD? |
| 161 | */ |
| 162 | int print_sha1_ellipsis(void); |
| 163 | |
| 164 | /* |
| 165 | * Returns the boolean value of $GIT_OPTIONAL_LOCKS (or the default value). |
| 166 | */ |
| 167 | int use_optional_locks(void); |
| 168 | |
| 169 | const char *get_git_namespace(void); |
| 170 | const char *strip_namespace(const char *namespaced_ref); |
| 171 | |
| 172 | int git_default_config(const char *, const char *, |
| 173 | const struct config_context *, void *); |
| 174 | int git_default_core_config(const char *var, const char *value, |
| 175 | const struct config_context *ctx, void *cb); |
| 176 | |
| 177 | /* |
| 178 | * Getters for the `protect_hfs` and `protect_ntfs` fields of `struct repo_config_values`. |
| 179 | * They check `repo->initialized` to prevent calling `repo_config_values()` |
| 180 | * before the repository setup is fully complete or in non-git environments. |
| 181 | */ |
| 182 | int repo_protect_hfs(struct repository *repo); |
| 183 | int repo_protect_ntfs(struct repository *repo); |
| 184 | |
| 185 | /* |
| 186 | * Getter for the `ignore_case` field of `struct repo_config_values`. |
| 187 | * It checks `repo->initialized` to prevent calling repo_config_values()` |
| 188 | * before the repository setup is fully complete or in non-git environments. |
| 189 | */ |
| 190 | int repo_ignore_case(struct repository *repo); |
| 191 | |
| 192 | int repo_trust_executable_bit(struct repository *repo); |
| 193 | |
| 194 | int repo_has_symlinks(struct repository *repo); |
| 195 | |
| 196 | const char *repo_excludes_file(struct repository *repo); |
| 197 | |
| 198 | void repo_config_values_init(struct repo_config_values *cfg); |
| 199 | |
| 200 | int is_bare_repository(struct repository *repo); |
| 201 | |
| 202 | /* |
| 203 | * Frees memory allocated for dynamically loaded configuration values |
| 204 | * inside `repo_config_values`. |
| 205 | * |
| 206 | * As dynamically allocated variables are migrated into this struct, |
| 207 | * their FREE_AND_NULL() calls should be appended here. |
| 208 | */ |
| 209 | void repo_config_values_clear(struct repo_config_values *cfg); |
| 210 | |
| 211 | /* |
| 212 | * TODO: All the below state either explicitly or implicitly relies on |
| 213 | * `the_repository`. We should eventually get rid of these and make the |
| 214 | * dependency on a repository explicit: |
| 215 | * |
| 216 | * - `have_git_dir()` should not have to exist at all. Instead, we should |
| 217 | * decide on whether or not we have a `struct repository`. |
| 218 | * |
| 219 | * - All the global config variables should become tied to a repository. Like |
| 220 | * this, we'd correctly honor repository-local configuration and be able to |
| 221 | * distinguish configuration values from different repositories. |
| 222 | * |
| 223 | * Please do not add new global config variables here. |
| 224 | */ |
| 225 | # ifdef USE_THE_REPOSITORY_VARIABLE |
| 226 | |
| 227 | /* |
| 228 | * Returns true iff we have a configured git repository (either via |
| 229 | * setup_git_directory, or in the environment via $GIT_DIR). |
| 230 | */ |
| 231 | int have_git_dir(void); |
| 232 | |
| 233 | /* Environment bits from configuration mechanism */ |
| 234 | extern int minimum_abbrev, default_abbrev; |
| 235 | extern int assume_unchanged; |
| 236 | extern unsigned long pack_size_limit_cfg; |
| 237 | |
| 238 | extern int grafts_keep_true_parents; |
| 239 | |
| 240 | const char *get_log_output_encoding(void); |
| 241 | const char *get_commit_output_encoding(void); |
| 242 | |
| 243 | extern char *git_commit_encoding; |
| 244 | extern char *git_log_output_encoding; |
| 245 | |
| 246 | /* |
| 247 | * The character that begins a commented line in user-editable file |
| 248 | * that is subject to stripspace. |
| 249 | */ |
| 250 | extern const char *comment_line_str; |
| 251 | extern char *comment_line_str_to_free; |
| 252 | #ifndef WITH_BREAKING_CHANGES |
| 253 | extern int auto_comment_line_char; |
| 254 | extern bool warn_on_auto_comment_char; |
| 255 | #endif /* !WITH_BREAKING_CHANGES */ |
| 256 | |
| 257 | # endif /* USE_THE_REPOSITORY_VARIABLE */ |
| 258 | #endif /* ENVIRONMENT_H */ |