2017-06-22 20:43:32 +02:00
|
|
|
#ifndef REPOSITORY_H
|
|
|
|
#define REPOSITORY_H
|
|
|
|
|
2018-08-15 19:54:05 +02:00
|
|
|
#include "path.h"
|
|
|
|
|
2017-06-22 20:43:42 +02:00
|
|
|
struct config_set;
|
2018-03-23 18:20:55 +01:00
|
|
|
struct git_hash_algo;
|
2017-06-22 20:43:43 +02:00
|
|
|
struct index_state;
|
2019-01-12 03:13:24 +01:00
|
|
|
struct lock_file;
|
2019-01-12 03:13:26 +01:00
|
|
|
struct pathspec;
|
2018-03-23 18:20:55 +01:00
|
|
|
struct raw_object_store;
|
2017-06-22 20:43:44 +02:00
|
|
|
struct submodule_cache;
|
2021-06-17 19:13:23 +02:00
|
|
|
struct promisor_remote_config;
|
2021-11-18 01:53:22 +01:00
|
|
|
struct remote_state;
|
2017-06-22 20:43:42 +02:00
|
|
|
|
2019-08-13 20:37:46 +02:00
|
|
|
enum untracked_cache_setting {
|
repo-settings.c: simplify the setup
Simplify the setup code in repo-settings.c in various ways, making the
code shorter, easier to read, and requiring fewer hacks to do the same
thing as it did before:
Since 7211b9e7534 (repo-settings: consolidate some config settings,
2019-08-13) we have memset() the whole "settings" structure to -1 in
prepare_repo_settings(), and subsequently relied on the -1 value.
Most of the fields did not need to be initialized to -1, and because
we were doing that we had the enum labels "UNTRACKED_CACHE_UNSET" and
"FETCH_NEGOTIATION_UNSET" purely to reflect the resulting state
created this memset() in prepare_repo_settings(). No other code used
or relied on them, more on that below.
For the rest most of the subsequent "are we -1, then read xyz" can
simply be removed by re-arranging what we read first. E.g. when
setting the "index.version" setting we should have first read
"feature.experimental", so that it (and "feature.manyfiles") can
provide a default for our "index.version".
Instead the code setting it, added when "feature.manyFiles"[1] was
created, was using the UPDATE_DEFAULT_BOOL() macro added in an earlier
commit[2]. That macro is now gone, since it was only needed for this
pattern of reading things in the wrong order.
This also fixes an (admittedly obscure) logic error where we'd
conflate an explicit "-1" value in the config with our own earlier
memset() -1.
We can also remove the UPDATE_DEFAULT_BOOL() wrapper added in
[3]. Using it is redundant to simply using the return value from
repo_config_get_bool(), which is non-zero if the provided key exists
in the config.
Details on edge cases relating to the memset() to -1, continued from
"more on that below" above:
* UNTRACKED_CACHE_KEEP:
In [4] the "unset" and "keep" handling for core.untrackedCache was
consolidated. But it while we understand the "keep" value, we don't
handle it differently than the case of any other unknown value.
So let's retain UNTRACKED_CACHE_KEEP and remove the
UNTRACKED_CACHE_UNSET setting (which was always implicitly
UNTRACKED_CACHE_KEEP before). We don't need to inform any code
after prepare_repo_settings() that the setting was "unset", as far
as anyone else is concerned it's core.untrackedCache=keep. if
"core.untrackedcache" isn't present in the config.
* FETCH_NEGOTIATION_UNSET & FETCH_NEGOTIATION_NONE:
Since these two two enum fields added in [5] don't rely on the
memzero() setting them to "-1" anymore we don't have to provide
them with explicit values.
1. c6cc4c5afd2 (repo-settings: create feature.manyFiles setting,
2019-08-13)
2. 31b1de6a09b (commit-graph: turn on commit-graph by default,
2019-08-13)
3. 31b1de6a09b (commit-graph: turn on commit-graph by default,
2019-08-13)
4. ad0fb659993 (repo-settings: parse core.untrackedCache,
2019-08-13)
5. aaf633c2ad1 (repo-settings: create feature.experimental setting,
2019-08-13)
Signed-off-by: Ævar Arnfjörð Bjarmason <avarab@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2021-09-21 15:13:02 +02:00
|
|
|
UNTRACKED_CACHE_KEEP,
|
|
|
|
UNTRACKED_CACHE_REMOVE,
|
|
|
|
UNTRACKED_CACHE_WRITE,
|
2019-08-13 20:37:46 +02:00
|
|
|
};
|
|
|
|
|
2019-08-13 20:37:48 +02:00
|
|
|
enum fetch_negotiation_setting {
|
repo-settings.c: simplify the setup
Simplify the setup code in repo-settings.c in various ways, making the
code shorter, easier to read, and requiring fewer hacks to do the same
thing as it did before:
Since 7211b9e7534 (repo-settings: consolidate some config settings,
2019-08-13) we have memset() the whole "settings" structure to -1 in
prepare_repo_settings(), and subsequently relied on the -1 value.
Most of the fields did not need to be initialized to -1, and because
we were doing that we had the enum labels "UNTRACKED_CACHE_UNSET" and
"FETCH_NEGOTIATION_UNSET" purely to reflect the resulting state
created this memset() in prepare_repo_settings(). No other code used
or relied on them, more on that below.
For the rest most of the subsequent "are we -1, then read xyz" can
simply be removed by re-arranging what we read first. E.g. when
setting the "index.version" setting we should have first read
"feature.experimental", so that it (and "feature.manyfiles") can
provide a default for our "index.version".
Instead the code setting it, added when "feature.manyFiles"[1] was
created, was using the UPDATE_DEFAULT_BOOL() macro added in an earlier
commit[2]. That macro is now gone, since it was only needed for this
pattern of reading things in the wrong order.
This also fixes an (admittedly obscure) logic error where we'd
conflate an explicit "-1" value in the config with our own earlier
memset() -1.
We can also remove the UPDATE_DEFAULT_BOOL() wrapper added in
[3]. Using it is redundant to simply using the return value from
repo_config_get_bool(), which is non-zero if the provided key exists
in the config.
Details on edge cases relating to the memset() to -1, continued from
"more on that below" above:
* UNTRACKED_CACHE_KEEP:
In [4] the "unset" and "keep" handling for core.untrackedCache was
consolidated. But it while we understand the "keep" value, we don't
handle it differently than the case of any other unknown value.
So let's retain UNTRACKED_CACHE_KEEP and remove the
UNTRACKED_CACHE_UNSET setting (which was always implicitly
UNTRACKED_CACHE_KEEP before). We don't need to inform any code
after prepare_repo_settings() that the setting was "unset", as far
as anyone else is concerned it's core.untrackedCache=keep. if
"core.untrackedcache" isn't present in the config.
* FETCH_NEGOTIATION_UNSET & FETCH_NEGOTIATION_NONE:
Since these two two enum fields added in [5] don't rely on the
memzero() setting them to "-1" anymore we don't have to provide
them with explicit values.
1. c6cc4c5afd2 (repo-settings: create feature.manyFiles setting,
2019-08-13)
2. 31b1de6a09b (commit-graph: turn on commit-graph by default,
2019-08-13)
3. 31b1de6a09b (commit-graph: turn on commit-graph by default,
2019-08-13)
4. ad0fb659993 (repo-settings: parse core.untrackedCache,
2019-08-13)
5. aaf633c2ad1 (repo-settings: create feature.experimental setting,
2019-08-13)
Signed-off-by: Ævar Arnfjörð Bjarmason <avarab@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2021-09-21 15:13:02 +02:00
|
|
|
FETCH_NEGOTIATION_DEFAULT,
|
|
|
|
FETCH_NEGOTIATION_SKIPPING,
|
|
|
|
FETCH_NEGOTIATION_NOOP,
|
2019-08-13 20:37:48 +02:00
|
|
|
};
|
|
|
|
|
2019-08-13 20:37:43 +02:00
|
|
|
struct repo_settings {
|
|
|
|
int initialized;
|
|
|
|
|
|
|
|
int core_commit_graph;
|
2020-09-09 17:23:10 +02:00
|
|
|
int commit_graph_read_changed_paths;
|
2019-08-13 20:37:43 +02:00
|
|
|
int gc_write_commit_graph;
|
2019-09-03 04:22:02 +02:00
|
|
|
int fetch_write_commit_graph;
|
repository.h: don't use a mix of int and bitfields
Change the bitfield added in 58300f47432 (sparse-index: add
index.sparse config option, 2021-03-30) and 3964fc2aae7 (sparse-index:
add guard to ensure full index, 2021-03-30) to just use an "int"
boolean instead.
It might be smart to optimize the space here in the future, but by
consistently using an "int" we can take its address and pass it to
repo_cfg_bool(), and therefore don't need to handle "sparse_index" as
a special-case when reading the "index.sparse" setting.
There's no corresponding config for "command_requires_full_index", but
let's change it too for consistency and to prevent future bugs
creeping in due to one of these being "unsigned".
Using "int" consistently also prevents subtle bugs or undesired
control flow creeping in here. Before the preceding commit the
initialization of "command_requires_full_index" in
prepare_repo_settings() did nothing, i.e. this:
r->settings.command_requires_full_index = 1
Was redundant to the earlier memset() to -1. Likewise for
"sparse_index" added in 58300f47432 (sparse-index: add index.sparse
config option, 2021-03-30) the code and comment added there was
misleading, we weren't initializing it to off, but re-initializing it
from "1" to "0", and then finally checking the config, and perhaps
setting it to "1" again. I.e. we could have applied this patch before
the preceding commit:
+ assert(r->settings.command_requires_full_index == 1);
r->settings.command_requires_full_index = 1;
/*
* Initialize this as off.
*/
+ assert(r->settings.sparse_index == 1);
r->settings.sparse_index = 0;
if (!repo_config_get_bool(r, "index.sparse", &value) && value)
r->settings.sparse_index = 1;
Signed-off-by: Ævar Arnfjörð Bjarmason <avarab@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2021-09-21 15:13:03 +02:00
|
|
|
int command_requires_full_index;
|
|
|
|
int sparse_index;
|
2019-08-13 20:37:43 +02:00
|
|
|
|
|
|
|
int index_version;
|
2019-08-13 20:37:46 +02:00
|
|
|
enum untracked_cache_setting core_untracked_cache;
|
2019-08-13 20:37:43 +02:00
|
|
|
|
|
|
|
int pack_use_sparse;
|
2019-08-13 20:37:48 +02:00
|
|
|
enum fetch_negotiation_setting fetch_negotiation_algorithm;
|
2020-09-25 14:33:34 +02:00
|
|
|
|
|
|
|
int core_multi_pack_index;
|
2019-08-13 20:37:43 +02:00
|
|
|
};
|
|
|
|
|
2017-06-22 20:43:32 +02:00
|
|
|
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;
|
|
|
|
|
|
|
|
/*
|
2018-03-23 18:20:55 +01:00
|
|
|
* Holds any information related to accessing the raw object content.
|
2017-06-22 20:43:32 +02:00
|
|
|
*/
|
2018-03-23 18:20:55 +01:00
|
|
|
struct raw_object_store *objects;
|
2018-03-03 12:35:57 +01:00
|
|
|
|
2018-05-08 21:37:24 +02:00
|
|
|
/*
|
|
|
|
* All objects in this repository that have been parsed. This structure
|
|
|
|
* owns all objects it references, so users of "struct object *"
|
|
|
|
* generally do not need to free them; instead, when a repository is no
|
|
|
|
* longer used, call parsed_object_pool_clear() on this structure, which
|
|
|
|
* is called by the repositories repo_clear on its desconstruction.
|
|
|
|
*/
|
|
|
|
struct parsed_object_pool *parsed_objects;
|
|
|
|
|
repository: mark the "refs" pointer as private
The "refs" pointer in a struct repository starts life as NULL, but then
is lazily initialized when it is accessed via get_main_ref_store().
However, it's easy for calling code to forget this and access it
directly, leading to code which works _some_ of the time, but fails if
it is called before anybody else accesses the refs.
This was the cause of the bug fixed by 5ff4b920eb (sha1-name: do not
assume that the ref store is initialized, 2020-04-09). In order to
prevent similar bugs, let's more clearly mark the "refs" field as
private.
In addition to helping future code, the name change will help us audit
any existing direct uses. Besides get_main_ref_store() itself, it turns
out there is only one. But we know it's OK as it is on the line directly
after the fix from 5ff4b920eb, which will have initialized the pointer.
However it's still a good idea for it to model the proper use of the
accessing function, so we'll convert it.
Signed-off-by: Jeff King <peff@peff.net>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2020-04-10 05:04:11 +02:00
|
|
|
/*
|
|
|
|
* The store in which the refs are held. This should generally only be
|
|
|
|
* accessed via get_main_ref_store(), as that will lazily initialize
|
|
|
|
* the ref object.
|
|
|
|
*/
|
|
|
|
struct ref_store *refs_private;
|
2018-04-12 02:21:14 +02:00
|
|
|
|
2018-05-18 00:51:51 +02:00
|
|
|
/*
|
|
|
|
* Contains path to often used file names.
|
|
|
|
*/
|
|
|
|
struct path_cache cached_paths;
|
|
|
|
|
2017-06-22 20:43:32 +02:00
|
|
|
/*
|
|
|
|
* 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;
|
|
|
|
|
2017-06-22 20:43:47 +02:00
|
|
|
/*
|
|
|
|
* Path from the root of the top-level superproject down to this
|
|
|
|
* repository. This is only non-NULL if the repository is initialized
|
|
|
|
* as a submodule of another repository.
|
|
|
|
*/
|
|
|
|
char *submodule_prefix;
|
|
|
|
|
2019-08-13 20:37:43 +02:00
|
|
|
struct repo_settings settings;
|
|
|
|
|
2017-06-22 20:43:42 +02:00
|
|
|
/* Subsystems */
|
|
|
|
/*
|
|
|
|
* Repository's config which contains key-value pairs from the usual
|
|
|
|
* set of config files (i.e. repo specific .git/config, user wide
|
|
|
|
* ~/.gitconfig, XDG config file and the global /etc/gitconfig)
|
|
|
|
*/
|
|
|
|
struct config_set *config;
|
|
|
|
|
2017-06-22 20:43:44 +02:00
|
|
|
/* Repository's submodule config as defined by '.gitmodules' */
|
|
|
|
struct submodule_cache *submodule_cache;
|
|
|
|
|
2017-06-22 20:43:43 +02:00
|
|
|
/*
|
|
|
|
* Repository's in-memory index.
|
|
|
|
* 'repo_read_index()' can be used to populate 'index'.
|
|
|
|
*/
|
|
|
|
struct index_state *index;
|
|
|
|
|
2021-11-18 01:53:22 +01:00
|
|
|
/* Repository's remotes and associated structures. */
|
|
|
|
struct remote_state *remote_state;
|
|
|
|
|
2017-11-12 22:28:53 +01:00
|
|
|
/* Repository's current hash algorithm, as serialized on disk. */
|
|
|
|
const struct git_hash_algo *hash_algo;
|
|
|
|
|
2019-02-22 23:25:01 +01:00
|
|
|
/* A unique-id for tracing purposes. */
|
|
|
|
int trace2_repo_id;
|
|
|
|
|
upload-pack: disable commit graph more gently for shallow traversal
When the client has asked for certain shallow options like
"deepen-since", we do a custom rev-list walk that pretends to be
shallow. Before doing so, we have to disable the commit-graph, since it
is not compatible with the shallow view of the repository. That's
handled by 829a321569 (commit-graph: close_commit_graph before shallow
walk, 2018-08-20). That commit literally closes and frees our
repo->objects->commit_graph struct.
That creates an interesting problem for commits that have _already_ been
parsed using the commit graph. Their commit->object.parsed flag is set,
their commit->graph_pos is set, but their commit->maybe_tree may still
be NULL. When somebody later calls repo_get_commit_tree(), we see that
we haven't loaded the tree oid yet and try to get it from the commit
graph. But since it has been freed, we segfault!
So the root of the issue is a data dependency between the commit's
lazy-load of the tree oid and the fact that the commit graph can go
away mid-process. How can we resolve it?
There are a couple of general approaches:
1. The obvious answer is to avoid loading the tree from the graph when
we see that it's NULL. But then what do we return for the tree oid?
If we return NULL, our caller in do_traverse() will rightly
complain that we have no tree. We'd have to fallback to loading the
actual commit object and re-parsing it. That requires teaching
parse_commit_buffer() to understand re-parsing (i.e., not starting
from a clean slate and not leaking any allocated bits like parent
list pointers).
2. When we close the commit graph, walk through the set of in-memory
objects and clear any graph_pos pointers. But this means we also
have to "unparse" any such commits so that we know they still need
to open the commit object to fill in their trees. So it's no less
complicated than (1), and is more expensive (since we clear objects
we might not later need).
3. Stop freeing the commit-graph struct. Continue to let it be used
for lazy-loads of tree oids, but let upload-pack specify that it
shouldn't be used for further commit parsing.
4. Push the whole shallow rev-list out to its own sub-process, with
the commit-graph disabled from the start, giving it a clean memory
space to work from.
I've chosen (3) here. Options (1) and (2) would work, but are
non-trivial to implement. Option (4) is more expensive, and I'm not sure
how complicated it is (shelling out for the actual rev-list part is
easy, but we do then parse the resulting commits internally, and I'm not
clear which parts need to be handling shallow-ness).
The new test in t5500 triggers this segfault, but see the comments there
for how horribly intimate it has to be with how both upload-pack and
commit graphs work.
Signed-off-by: Jeff King <peff@peff.net>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2019-09-12 16:44:45 +02:00
|
|
|
/* True if commit-graph has been disabled within this process. */
|
|
|
|
int commit_graph_disabled;
|
|
|
|
|
2021-06-17 19:13:22 +02:00
|
|
|
/* Configurations related to promisor remotes. */
|
|
|
|
char *repository_format_partial_clone;
|
2021-06-17 19:13:23 +02:00
|
|
|
struct promisor_remote_config *promisor_remote_config;
|
2021-06-17 19:13:22 +02:00
|
|
|
|
2017-06-22 20:43:32 +02:00
|
|
|
/* Configurations */
|
|
|
|
|
|
|
|
/* Indicate if a repository has a different 'commondir' from 'gitdir' */
|
|
|
|
unsigned different_commondir:1;
|
|
|
|
};
|
|
|
|
|
|
|
|
extern struct repository *the_repository;
|
|
|
|
|
2018-03-23 16:55:23 +01:00
|
|
|
/*
|
|
|
|
* Define a custom repository layout. Any field can be NULL, which
|
|
|
|
* will default back to the path according to the default layout.
|
|
|
|
*/
|
2018-03-03 12:35:55 +01:00
|
|
|
struct set_gitdir_args {
|
|
|
|
const char *commondir;
|
|
|
|
const char *object_dir;
|
|
|
|
const char *graft_file;
|
|
|
|
const char *index_file;
|
2018-03-03 12:35:57 +01:00
|
|
|
const char *alternate_db;
|
2021-12-06 23:05:05 +01:00
|
|
|
int disable_ref_updates;
|
2018-03-03 12:35:55 +01:00
|
|
|
};
|
|
|
|
|
2018-06-30 11:20:29 +02:00
|
|
|
void repo_set_gitdir(struct repository *repo, const char *root,
|
|
|
|
const struct set_gitdir_args *extra_args);
|
|
|
|
void repo_set_worktree(struct repository *repo, const char *path);
|
|
|
|
void repo_set_hash_algo(struct repository *repo, int algo);
|
|
|
|
void initialize_the_repository(void);
|
|
|
|
int repo_init(struct repository *r, const char *gitdir, const char *worktree);
|
2018-11-29 01:27:53 +01:00
|
|
|
|
|
|
|
/*
|
2021-09-09 20:47:28 +02:00
|
|
|
* Initialize the repository 'subrepo' as the submodule at the given path. If
|
|
|
|
* the submodule's gitdir cannot be found at <path>/.git, this function calls
|
|
|
|
* submodule_from_path() to try to find it. treeish_name is only used if
|
|
|
|
* submodule_from_path() needs to be called; see its documentation for more
|
|
|
|
* information.
|
|
|
|
* Return 0 upon success and a non-zero value upon failure.
|
2018-11-29 01:27:53 +01:00
|
|
|
*/
|
2021-09-09 20:47:28 +02:00
|
|
|
struct object_id;
|
2018-11-29 01:27:53 +01:00
|
|
|
int repo_submodule_init(struct repository *subrepo,
|
2018-06-30 11:20:29 +02:00
|
|
|
struct repository *superproject,
|
2021-09-09 20:47:28 +02:00
|
|
|
const char *path,
|
|
|
|
const struct object_id *treeish_name);
|
2018-06-30 11:20:29 +02:00
|
|
|
void repo_clear(struct repository *repo);
|
2017-06-22 20:43:32 +02:00
|
|
|
|
2017-07-18 21:05:18 +02:00
|
|
|
/*
|
|
|
|
* Populates the repository's index from its index_file, an index struct will
|
|
|
|
* be allocated if needed.
|
|
|
|
*
|
|
|
|
* Return the number of index entries in the populated index or a value less
|
2019-11-05 18:07:23 +01:00
|
|
|
* than zero if an error occurred. If the repository's index has already been
|
2017-07-18 21:05:18 +02:00
|
|
|
* populated then the number of entries will simply be returned.
|
|
|
|
*/
|
2018-06-30 11:20:29 +02:00
|
|
|
int repo_read_index(struct repository *repo);
|
2019-01-12 03:13:24 +01:00
|
|
|
int repo_hold_locked_index(struct repository *repo,
|
|
|
|
struct lock_file *lf,
|
|
|
|
int flags);
|
2017-06-22 20:43:43 +02:00
|
|
|
|
2019-01-12 03:13:26 +01:00
|
|
|
int repo_read_index_preload(struct repository *,
|
|
|
|
const struct pathspec *pathspec,
|
|
|
|
unsigned refresh_flags);
|
|
|
|
int repo_read_index_unmerged(struct repository *);
|
2019-01-12 03:13:27 +01:00
|
|
|
/*
|
|
|
|
* Opportunistically update the index but do not complain if we can't.
|
|
|
|
* The lockfile is always committed or rolled back.
|
|
|
|
*/
|
|
|
|
void repo_update_index_if_able(struct repository *, struct lock_file *);
|
|
|
|
|
2019-08-13 20:37:43 +02:00
|
|
|
void prepare_repo_settings(struct repository *r);
|
2017-06-22 20:43:43 +02:00
|
|
|
|
2020-06-05 11:10:01 +02:00
|
|
|
/*
|
|
|
|
* Return 1 if upgrade repository format to target_version succeeded,
|
|
|
|
* 0 if no upgrade is necessary, and -1 when upgrade is not possible.
|
|
|
|
*/
|
|
|
|
int upgrade_repository_format(int target_version);
|
|
|
|
|
2017-06-22 20:43:32 +02:00
|
|
|
#endif /* REPOSITORY_H */
|