2017-06-22 18:43:32 +00:00
|
|
|
#ifndef REPOSITORY_H
|
|
|
|
#define REPOSITORY_H
|
|
|
|
|
2018-08-15 17:54:05 +00:00
|
|
|
#include "path.h"
|
|
|
|
|
2017-06-22 18:43:42 +00:00
|
|
|
struct config_set;
|
2018-03-23 17:20:55 +00:00
|
|
|
struct git_hash_algo;
|
2017-06-22 18:43:43 +00:00
|
|
|
struct index_state;
|
2019-01-12 02:13:24 +00:00
|
|
|
struct lock_file;
|
2019-01-12 02:13:26 +00:00
|
|
|
struct pathspec;
|
2018-03-23 17:20:55 +00:00
|
|
|
struct raw_object_store;
|
2017-06-22 18:43:44 +00:00
|
|
|
struct submodule_cache;
|
2021-06-17 17:13:23 +00:00
|
|
|
struct promisor_remote_config;
|
2017-06-22 18:43:42 +00:00
|
|
|
|
2019-08-13 18:37:46 +00:00
|
|
|
enum untracked_cache_setting {
|
|
|
|
UNTRACKED_CACHE_UNSET = -1,
|
|
|
|
UNTRACKED_CACHE_REMOVE = 0,
|
|
|
|
UNTRACKED_CACHE_KEEP = 1,
|
|
|
|
UNTRACKED_CACHE_WRITE = 2
|
|
|
|
};
|
|
|
|
|
2019-08-13 18:37:48 +00:00
|
|
|
enum fetch_negotiation_setting {
|
|
|
|
FETCH_NEGOTIATION_UNSET = -1,
|
|
|
|
FETCH_NEGOTIATION_NONE = 0,
|
|
|
|
FETCH_NEGOTIATION_DEFAULT = 1,
|
|
|
|
FETCH_NEGOTIATION_SKIPPING = 2,
|
2020-08-18 04:01:31 +00:00
|
|
|
FETCH_NEGOTIATION_NOOP = 3,
|
2019-08-13 18:37:48 +00:00
|
|
|
};
|
|
|
|
|
2019-08-13 18:37:43 +00:00
|
|
|
struct repo_settings {
|
|
|
|
int initialized;
|
|
|
|
|
|
|
|
int core_commit_graph;
|
2020-09-09 15:23:10 +00:00
|
|
|
int commit_graph_read_changed_paths;
|
2019-08-13 18:37:43 +00:00
|
|
|
int gc_write_commit_graph;
|
2019-09-03 02:22:02 +00:00
|
|
|
int fetch_write_commit_graph;
|
2019-08-13 18:37:43 +00:00
|
|
|
|
|
|
|
int index_version;
|
2019-08-13 18:37:46 +00:00
|
|
|
enum untracked_cache_setting core_untracked_cache;
|
2019-08-13 18:37:43 +00:00
|
|
|
|
|
|
|
int pack_use_sparse;
|
2019-08-13 18:37:48 +00:00
|
|
|
enum fetch_negotiation_setting fetch_negotiation_algorithm;
|
2020-09-25 12:33:34 +00:00
|
|
|
|
|
|
|
int core_multi_pack_index;
|
2021-03-30 13:10:47 +00:00
|
|
|
|
2021-03-30 13:10:59 +00:00
|
|
|
unsigned command_requires_full_index:1,
|
|
|
|
sparse_index:1;
|
2019-08-13 18:37:43 +00:00
|
|
|
};
|
|
|
|
|
2017-06-22 18:43:32 +00: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 17:20:55 +00:00
|
|
|
* Holds any information related to accessing the raw object content.
|
2017-06-22 18:43:32 +00:00
|
|
|
*/
|
2018-03-23 17:20:55 +00:00
|
|
|
struct raw_object_store *objects;
|
2018-03-03 11:35:57 +00:00
|
|
|
|
2018-05-08 19:37:24 +00: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 03:04:11 +00: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 00:21:14 +00:00
|
|
|
|
2018-05-17 22:51:51 +00:00
|
|
|
/*
|
|
|
|
* Contains path to often used file names.
|
|
|
|
*/
|
|
|
|
struct path_cache cached_paths;
|
|
|
|
|
2017-06-22 18:43:32 +00: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 18:43:47 +00: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 18:37:43 +00:00
|
|
|
struct repo_settings settings;
|
|
|
|
|
2017-06-22 18:43:42 +00: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 18:43:44 +00:00
|
|
|
/* Repository's submodule config as defined by '.gitmodules' */
|
|
|
|
struct submodule_cache *submodule_cache;
|
|
|
|
|
2017-06-22 18:43:43 +00:00
|
|
|
/*
|
|
|
|
* Repository's in-memory index.
|
|
|
|
* 'repo_read_index()' can be used to populate 'index'.
|
|
|
|
*/
|
|
|
|
struct index_state *index;
|
|
|
|
|
2017-11-12 21:28:53 +00:00
|
|
|
/* Repository's current hash algorithm, as serialized on disk. */
|
|
|
|
const struct git_hash_algo *hash_algo;
|
|
|
|
|
2019-02-22 22:25:01 +00: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 14:44:45 +00:00
|
|
|
/* True if commit-graph has been disabled within this process. */
|
|
|
|
int commit_graph_disabled;
|
|
|
|
|
2021-06-17 17:13:22 +00:00
|
|
|
/* Configurations related to promisor remotes. */
|
|
|
|
char *repository_format_partial_clone;
|
2021-06-17 17:13:23 +00:00
|
|
|
struct promisor_remote_config *promisor_remote_config;
|
2021-06-17 17:13:22 +00:00
|
|
|
|
2017-06-22 18:43:32 +00:00
|
|
|
/* Configurations */
|
|
|
|
|
|
|
|
/* Indicate if a repository has a different 'commondir' from 'gitdir' */
|
|
|
|
unsigned different_commondir:1;
|
|
|
|
};
|
|
|
|
|
|
|
|
extern struct repository *the_repository;
|
|
|
|
|
2018-03-23 15:55:23 +00: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 11:35:55 +00:00
|
|
|
struct set_gitdir_args {
|
|
|
|
const char *commondir;
|
|
|
|
const char *object_dir;
|
|
|
|
const char *graft_file;
|
|
|
|
const char *index_file;
|
2018-03-03 11:35:57 +00:00
|
|
|
const char *alternate_db;
|
2018-03-03 11:35:55 +00:00
|
|
|
};
|
|
|
|
|
2018-06-30 09:20:29 +00: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 00:27:53 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Initialize the repository 'subrepo' as the submodule given by the
|
|
|
|
* struct submodule 'sub' in parent repository 'superproject'.
|
|
|
|
* Return 0 upon success and a non-zero value upon failure, which may happen
|
|
|
|
* if the submodule is not found, or 'sub' is NULL.
|
|
|
|
*/
|
|
|
|
struct submodule;
|
|
|
|
int repo_submodule_init(struct repository *subrepo,
|
2018-06-30 09:20:29 +00:00
|
|
|
struct repository *superproject,
|
2018-11-29 00:27:53 +00:00
|
|
|
const struct submodule *sub);
|
2018-06-30 09:20:29 +00:00
|
|
|
void repo_clear(struct repository *repo);
|
2017-06-22 18:43:32 +00:00
|
|
|
|
2017-07-18 19:05:18 +00: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 17:07:23 +00:00
|
|
|
* than zero if an error occurred. If the repository's index has already been
|
2017-07-18 19:05:18 +00:00
|
|
|
* populated then the number of entries will simply be returned.
|
|
|
|
*/
|
2018-06-30 09:20:29 +00:00
|
|
|
int repo_read_index(struct repository *repo);
|
2019-01-12 02:13:24 +00:00
|
|
|
int repo_hold_locked_index(struct repository *repo,
|
|
|
|
struct lock_file *lf,
|
|
|
|
int flags);
|
2017-06-22 18:43:43 +00:00
|
|
|
|
2019-01-12 02:13:26 +00: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 02:13:27 +00: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 18:37:43 +00:00
|
|
|
void prepare_repo_settings(struct repository *r);
|
2017-06-22 18:43:43 +00:00
|
|
|
|
2020-06-05 09:10:01 +00: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 18:43:32 +00:00
|
|
|
#endif /* REPOSITORY_H */
|