Blame src/repository.h

Packit Service 20376f
/*
Packit Service 20376f
 * Copyright (C) the libgit2 contributors. All rights reserved.
Packit Service 20376f
 *
Packit Service 20376f
 * This file is part of libgit2, distributed under the GNU GPL v2 with
Packit Service 20376f
 * a Linking Exception. For full terms see the included COPYING file.
Packit Service 20376f
 */
Packit Service 20376f
#ifndef INCLUDE_repository_h__
Packit Service 20376f
#define INCLUDE_repository_h__
Packit Service 20376f
Packit Service 20376f
#include "git2/common.h"
Packit Service 20376f
#include "git2/oid.h"
Packit Service 20376f
#include "git2/odb.h"
Packit Service 20376f
#include "git2/repository.h"
Packit Service 20376f
#include "git2/object.h"
Packit Service 20376f
#include "git2/config.h"
Packit Service 20376f
Packit Service 20376f
#include "array.h"
Packit Service 20376f
#include "cache.h"
Packit Service 20376f
#include "refs.h"
Packit Service 20376f
#include "buffer.h"
Packit Service 20376f
#include "object.h"
Packit Service 20376f
#include "attrcache.h"
Packit Service 20376f
#include "submodule.h"
Packit Service 20376f
#include "diff_driver.h"
Packit Service 20376f
Packit Service 20376f
#define DOT_GIT ".git"
Packit Service 20376f
#define GIT_DIR DOT_GIT "/"
Packit Service 20376f
#define GIT_DIR_MODE 0755
Packit Service 20376f
#define GIT_BARE_DIR_MODE 0777
Packit Service 20376f
Packit Service 20376f
/* Default DOS-compatible 8.3 "short name" for a git repository, "GIT~1" */
Packit Service 20376f
#define GIT_DIR_SHORTNAME "GIT~1"
Packit Service 20376f
Packit Service 20376f
extern bool git_repository__fsync_gitdir;
Packit Service 20376f
Packit Service 20376f
/** Cvar cache identifiers */
Packit Service 20376f
typedef enum {
Packit Service 20376f
	GIT_CVAR_AUTO_CRLF = 0, /* core.autocrlf */
Packit Service 20376f
	GIT_CVAR_EOL,           /* core.eol */
Packit Service 20376f
	GIT_CVAR_SYMLINKS,      /* core.symlinks */
Packit Service 20376f
	GIT_CVAR_IGNORECASE,    /* core.ignorecase */
Packit Service 20376f
	GIT_CVAR_FILEMODE,      /* core.filemode */
Packit Service 20376f
	GIT_CVAR_IGNORESTAT,    /* core.ignorestat */
Packit Service 20376f
	GIT_CVAR_TRUSTCTIME,    /* core.trustctime */
Packit Service 20376f
	GIT_CVAR_ABBREV,        /* core.abbrev */
Packit Service 20376f
	GIT_CVAR_PRECOMPOSE,    /* core.precomposeunicode */
Packit Service 20376f
	GIT_CVAR_SAFE_CRLF,		/* core.safecrlf */
Packit Service 20376f
	GIT_CVAR_LOGALLREFUPDATES, /* core.logallrefupdates */
Packit Service 20376f
	GIT_CVAR_PROTECTHFS,    /* core.protectHFS */
Packit Service 20376f
	GIT_CVAR_PROTECTNTFS,   /* core.protectNTFS */
Packit Service 20376f
	GIT_CVAR_FSYNCOBJECTFILES, /* core.fsyncObjectFiles */
Packit Service 20376f
	GIT_CVAR_CACHE_MAX
Packit Service 20376f
} git_cvar_cached;
Packit Service 20376f
Packit Service 20376f
/**
Packit Service 20376f
 * CVAR value enumerations
Packit Service 20376f
 *
Packit Service 20376f
 * These are the values that are actually stored in the cvar cache, instead
Packit Service 20376f
 * of their string equivalents. These values are internal and symbolic;
Packit Service 20376f
 * make sure that none of them is set to `-1`, since that is the unique
Packit Service 20376f
 * identifier for "not cached"
Packit Service 20376f
 */
Packit Service 20376f
typedef enum {
Packit Service 20376f
	/* The value hasn't been loaded from the cache yet */
Packit Service 20376f
	GIT_CVAR_NOT_CACHED = -1,
Packit Service 20376f
Packit Service 20376f
	/* core.safecrlf: false, 'fail', 'warn' */
Packit Service 20376f
	GIT_SAFE_CRLF_FALSE = 0,
Packit Service 20376f
	GIT_SAFE_CRLF_FAIL = 1,
Packit Service 20376f
	GIT_SAFE_CRLF_WARN = 2,
Packit Service 20376f
Packit Service 20376f
	/* core.autocrlf: false, true, 'input; */
Packit Service 20376f
	GIT_AUTO_CRLF_FALSE = 0,
Packit Service 20376f
	GIT_AUTO_CRLF_TRUE = 1,
Packit Service 20376f
	GIT_AUTO_CRLF_INPUT = 2,
Packit Service 20376f
	GIT_AUTO_CRLF_DEFAULT = GIT_AUTO_CRLF_FALSE,
Packit Service 20376f
Packit Service 20376f
	/* core.eol: unset, 'crlf', 'lf', 'native' */
Packit Service 20376f
	GIT_EOL_UNSET = 0,
Packit Service 20376f
	GIT_EOL_CRLF = 1,
Packit Service 20376f
	GIT_EOL_LF = 2,
Packit Service 20376f
#ifdef GIT_WIN32
Packit Service 20376f
	GIT_EOL_NATIVE = GIT_EOL_CRLF,
Packit Service 20376f
#else
Packit Service 20376f
	GIT_EOL_NATIVE = GIT_EOL_LF,
Packit Service 20376f
#endif
Packit Service 20376f
	GIT_EOL_DEFAULT = GIT_EOL_NATIVE,
Packit Service 20376f
Packit Service 20376f
	/* core.symlinks: bool */
Packit Service 20376f
	GIT_SYMLINKS_DEFAULT = GIT_CVAR_TRUE,
Packit Service 20376f
	/* core.ignorecase */
Packit Service 20376f
	GIT_IGNORECASE_DEFAULT = GIT_CVAR_FALSE,
Packit Service 20376f
	/* core.filemode */
Packit Service 20376f
	GIT_FILEMODE_DEFAULT = GIT_CVAR_TRUE,
Packit Service 20376f
	/* core.ignorestat */
Packit Service 20376f
	GIT_IGNORESTAT_DEFAULT = GIT_CVAR_FALSE,
Packit Service 20376f
	/* core.trustctime */
Packit Service 20376f
	GIT_TRUSTCTIME_DEFAULT = GIT_CVAR_TRUE,
Packit Service 20376f
	/* core.abbrev */
Packit Service 20376f
	GIT_ABBREV_DEFAULT = 7,
Packit Service 20376f
	/* core.precomposeunicode */
Packit Service 20376f
	GIT_PRECOMPOSE_DEFAULT = GIT_CVAR_FALSE,
Packit Service 20376f
	/* core.safecrlf */
Packit Service 20376f
	GIT_SAFE_CRLF_DEFAULT = GIT_CVAR_FALSE,
Packit Service 20376f
	/* core.logallrefupdates */
Packit Service 20376f
	GIT_LOGALLREFUPDATES_UNSET = 2,
Packit Service 20376f
	GIT_LOGALLREFUPDATES_DEFAULT = GIT_LOGALLREFUPDATES_UNSET,
Packit Service 20376f
	/* core.protectHFS */
Packit Service 20376f
	GIT_PROTECTHFS_DEFAULT = GIT_CVAR_FALSE,
Packit Service 20376f
	/* core.protectNTFS */
Packit Service 20376f
	GIT_PROTECTNTFS_DEFAULT = GIT_CVAR_FALSE,
Packit Service 20376f
	/* core.fsyncObjectFiles */
Packit Service 20376f
	GIT_FSYNCOBJECTFILES_DEFAULT = GIT_CVAR_FALSE,
Packit Service 20376f
} git_cvar_value;
Packit Service 20376f
Packit Service 20376f
/* internal repository init flags */
Packit Service 20376f
enum {
Packit Service 20376f
	GIT_REPOSITORY_INIT__HAS_DOTGIT = (1u << 16),
Packit Service 20376f
	GIT_REPOSITORY_INIT__NATURAL_WD = (1u << 17),
Packit Service 20376f
	GIT_REPOSITORY_INIT__IS_REINIT  = (1u << 18),
Packit Service 20376f
};
Packit Service 20376f
Packit Service 20376f
/** Internal structure for repository object */
Packit Service 20376f
struct git_repository {
Packit Service 20376f
	git_odb *_odb;
Packit Service 20376f
	git_refdb *_refdb;
Packit Service 20376f
	git_config *_config;
Packit Service 20376f
	git_index *_index;
Packit Service 20376f
Packit Service 20376f
	git_cache objects;
Packit Service 20376f
	git_attr_cache *attrcache;
Packit Service 20376f
	git_diff_driver_registry *diff_drivers;
Packit Service 20376f
Packit Service 20376f
	char *gitlink;
Packit Service 20376f
	char *gitdir;
Packit Service 20376f
	char *commondir;
Packit Service 20376f
	char *workdir;
Packit Service 20376f
	char *namespace;
Packit Service 20376f
Packit Service 20376f
	char *ident_name;
Packit Service 20376f
	char *ident_email;
Packit Service 20376f
Packit Service 20376f
	git_array_t(git_buf) reserved_names;
Packit Service 20376f
Packit Service 20376f
	unsigned is_bare:1;
Packit Service 20376f
	unsigned is_worktree:1;
Packit Service 20376f
Packit Service 20376f
	unsigned int lru_counter;
Packit Service 20376f
Packit Service 20376f
	git_atomic attr_session_key;
Packit Service 20376f
Packit Service 20376f
	git_cvar_value cvar_cache[GIT_CVAR_CACHE_MAX];
Packit Service 20376f
	git_strmap *submodule_cache;
Packit Service 20376f
};
Packit Service 20376f
Packit Service 20376f
GIT_INLINE(git_attr_cache *) git_repository_attr_cache(git_repository *repo)
Packit Service 20376f
{
Packit Service 20376f
	return repo->attrcache;
Packit Service 20376f
}
Packit Service 20376f
Packit Service 20376f
int git_repository_head_tree(git_tree **tree, git_repository *repo);
Packit Service 20376f
int git_repository_create_head(const char *git_dir, const char *ref_name);
Packit Service 20376f
Packit Service 20376f
/*
Packit Service 20376f
 * Called for each HEAD.
Packit Service 20376f
 *
Packit Service 20376f
 * Can return either 0, causing the iteration over HEADs to
Packit Service 20376f
 * continue, or a non-0 value causing the iteration to abort. The
Packit Service 20376f
 * return value is passed back to the caller of
Packit Service 20376f
 * `git_repository_foreach_head`
Packit Service 20376f
 */
Packit Service 20376f
typedef int (*git_repository_foreach_head_cb)(git_repository *repo, const char *path, void *payload);
Packit Service 20376f
Packit Service 20376f
/*
Packit Service 20376f
 * Iterate over repository and all worktree HEADs.
Packit Service 20376f
 *
Packit Service 20376f
 * This function will be called for the repository HEAD and for
Packit Service 20376f
 * all HEADS of linked worktrees. For each HEAD, the callback is
Packit Service 20376f
 * executed with the given payload. The return value equals the
Packit Service 20376f
 * return value of the last executed callback function.
Packit Service 20376f
 */
Packit Service 20376f
int git_repository_foreach_head(git_repository *repo, git_repository_foreach_head_cb cb, void *payload);
Packit Service 20376f
Packit Service 20376f
/*
Packit Service 20376f
 * Weak pointers to repository internals.
Packit Service 20376f
 *
Packit Service 20376f
 * The returned pointers do not need to be freed. Do not keep
Packit Service 20376f
 * permanent references to these (i.e. between API calls), since they may
Packit Service 20376f
 * become invalidated if the user replaces a repository internal.
Packit Service 20376f
 */
Packit Service 20376f
int git_repository_config__weakptr(git_config **out, git_repository *repo);
Packit Service 20376f
int git_repository_odb__weakptr(git_odb **out, git_repository *repo);
Packit Service 20376f
int git_repository_refdb__weakptr(git_refdb **out, git_repository *repo);
Packit Service 20376f
int git_repository_index__weakptr(git_index **out, git_repository *repo);
Packit Service 20376f
Packit Service 20376f
/*
Packit Service 20376f
 * CVAR cache
Packit Service 20376f
 *
Packit Service 20376f
 * Efficient access to the most used config variables of a repository.
Packit Service 20376f
 * The cache is cleared every time the config backend is replaced.
Packit Service 20376f
 */
Packit Service 20376f
int git_repository__cvar(int *out, git_repository *repo, git_cvar_cached cvar);
Packit Service 20376f
void git_repository__cvar_cache_clear(git_repository *repo);
Packit Service 20376f
Packit Service 20376f
GIT_INLINE(int) git_repository__ensure_not_bare(
Packit Service 20376f
	git_repository *repo,
Packit Service 20376f
	const char *operation_name)
Packit Service 20376f
{
Packit Service 20376f
	if (!git_repository_is_bare(repo))
Packit Service 20376f
		return 0;
Packit Service 20376f
Packit Service 20376f
	giterr_set(
Packit Service 20376f
		GITERR_REPOSITORY,
Packit Service 20376f
		"cannot %s. This operation is not allowed against bare repositories.",
Packit Service 20376f
		operation_name);
Packit Service 20376f
Packit Service 20376f
	return GIT_EBAREREPO;
Packit Service 20376f
}
Packit Service 20376f
Packit Service 20376f
int git_repository__set_orig_head(git_repository *repo, const git_oid *orig_head);
Packit Service 20376f
Packit Service 20376f
int git_repository__cleanup_files(git_repository *repo, const char *files[], size_t files_len);
Packit Service 20376f
Packit Service 20376f
/* The default "reserved names" for a repository */
Packit Service 20376f
extern git_buf git_repository__reserved_names_win32[];
Packit Service 20376f
extern size_t git_repository__reserved_names_win32_len;
Packit Service 20376f
Packit Service 20376f
extern git_buf git_repository__reserved_names_posix[];
Packit Service 20376f
extern size_t git_repository__reserved_names_posix_len;
Packit Service 20376f
Packit Service 20376f
/*
Packit Service 20376f
 * Gets any "reserved names" in the repository.  This will return paths
Packit Service 20376f
 * that should not be allowed in the repository (like ".git") to avoid
Packit Service 20376f
 * conflicting with the repository path, or with alternate mechanisms to
Packit Service 20376f
 * the repository path (eg, "GIT~1").  Every attempt will be made to look
Packit Service 20376f
 * up all possible reserved names - if there was a conflict for the shortname
Packit Service 20376f
 * GIT~1, for example, this function will try to look up the alternate
Packit Service 20376f
 * shortname.  If that fails, this function returns false, but out and outlen
Packit Service 20376f
 * will still be populated with good defaults.
Packit Service 20376f
 */
Packit Service 20376f
bool git_repository__reserved_names(
Packit Service 20376f
	git_buf **out, size_t *outlen, git_repository *repo, bool include_ntfs);
Packit Service 20376f
Packit Service 20376f
#endif