repository.h 4.57 KB
Newer Older
Vicent Marti committed
1
/*
Edward Thomson committed
2
 * Copyright (C) the libgit2 contributors. All rights reserved.
Vicent Marti committed
3 4 5 6
 *
 * This file is part of libgit2, distributed under the GNU GPL v2 with
 * a Linking Exception. For full terms see the included COPYING file.
 */
7 8 9
#ifndef INCLUDE_repository_h__
#define INCLUDE_repository_h__

10 11 12 13
#include "git2/common.h"
#include "git2/oid.h"
#include "git2/odb.h"
#include "git2/repository.h"
14
#include "git2/object.h"
15
#include "git2/config.h"
16

Vicent Marti committed
17
#include "cache.h"
18
#include "refs.h"
19
#include "buffer.h"
20
#include "object.h"
21
#include "attrcache.h"
22
#include "strmap.h"
23
#include "diff_driver.h"
24

25 26
#define DOT_GIT ".git"
#define GIT_DIR DOT_GIT "/"
27 28
#define GIT_DIR_MODE 0755
#define GIT_BARE_DIR_MODE 0777
29

30 31 32
/** Cvar cache identifiers */
typedef enum {
	GIT_CVAR_AUTO_CRLF = 0, /* core.autocrlf */
33 34 35 36 37 38 39
	GIT_CVAR_EOL,           /* core.eol */
	GIT_CVAR_SYMLINKS,      /* core.symlinks */
	GIT_CVAR_IGNORECASE,    /* core.ignorecase */
	GIT_CVAR_FILEMODE,      /* core.filemode */
	GIT_CVAR_IGNORESTAT,    /* core.ignorestat */
	GIT_CVAR_TRUSTCTIME,    /* core.trustctime */
	GIT_CVAR_ABBREV,        /* core.abbrev */
40
	GIT_CVAR_PRECOMPOSE,    /* core.precomposeunicode */
41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75
	GIT_CVAR_CACHE_MAX
} git_cvar_cached;

/**
 * CVAR value enumerations
 *
 * These are the values that are actually stored in the cvar cache, instead
 * of their string equivalents. These values are internal and symbolic;
 * make sure that none of them is set to `-1`, since that is the unique
 * identifier for "not cached"
 */
typedef enum {
	/* The value hasn't been loaded from the cache yet */
	GIT_CVAR_NOT_CACHED = -1,

	/* core.safecrlf: false, 'fail', 'warn' */
	GIT_SAFE_CRLF_FALSE = 0,
	GIT_SAFE_CRLF_FAIL = 1,
	GIT_SAFE_CRLF_WARN = 2,

	/* core.autocrlf: false, true, 'input; */
	GIT_AUTO_CRLF_FALSE = 0,
	GIT_AUTO_CRLF_TRUE = 1,
	GIT_AUTO_CRLF_INPUT = 2,
	GIT_AUTO_CRLF_DEFAULT = GIT_AUTO_CRLF_FALSE,

	/* core.eol: unset, 'crlf', 'lf', 'native' */
	GIT_EOL_UNSET = 0,
	GIT_EOL_CRLF = 1,
	GIT_EOL_LF = 2,
#ifdef GIT_WIN32
	GIT_EOL_NATIVE = GIT_EOL_CRLF,
#else
	GIT_EOL_NATIVE = GIT_EOL_LF,
#endif
76 77 78 79 80 81 82 83 84 85 86 87 88 89
	GIT_EOL_DEFAULT = GIT_EOL_NATIVE,

	/* core.symlinks: bool */
	GIT_SYMLINKS_DEFAULT = GIT_CVAR_TRUE,
	/* core.ignorecase */
	GIT_IGNORECASE_DEFAULT = GIT_CVAR_FALSE,
	/* core.filemode */
	GIT_FILEMODE_DEFAULT = GIT_CVAR_TRUE,
	/* core.ignorestat */
	GIT_IGNORESTAT_DEFAULT = GIT_CVAR_FALSE,
	/* core.trustctime */
	GIT_TRUSTCTIME_DEFAULT = GIT_CVAR_TRUE,
	/* core.abbrev */
	GIT_ABBREV_DEFAULT = 7,
90 91
	/* core.precomposeunicode */
	GIT_PRECOMPOSE_DEFAULT = GIT_CVAR_FALSE,
92

93 94
} git_cvar_value;

95 96 97 98 99 100 101 102
/* internal repository init flags */
enum {
	GIT_REPOSITORY_INIT__HAS_DOTGIT = (1u << 16),
	GIT_REPOSITORY_INIT__NATURAL_WD = (1u << 17),
	GIT_REPOSITORY_INIT__IS_REINIT  = (1u << 18),
};

/** Internal structure for repository object */
103
struct git_repository {
104
	git_odb *_odb;
105
	git_refdb *_refdb;
106 107
	git_config *_config;
	git_index *_index;
108

Vicent Marti committed
109
	git_cache objects;
110
	git_attr_cache attrcache;
111
	git_strmap *submodules;
112
	git_diff_driver_registry *diff_drivers;
113 114

	char *path_repository;
115
	char *workdir;
Vicent Marti committed
116
	char *namespace;
117

118 119
	unsigned is_bare:1;
	unsigned int lru_counter;
120

121
	git_cvar_value cvar_cache[GIT_CVAR_CACHE_MAX];
122 123
};

124 125 126 127 128
GIT_INLINE(git_attr_cache *) git_repository_attr_cache(git_repository *repo)
{
	return &repo->attrcache;
}

129 130
int git_repository_head_tree(git_tree **tree, git_repository *repo);

131 132 133 134 135 136 137
/*
 * Weak pointers to repository internals.
 *
 * The returned pointers do not need to be freed. Do not keep
 * permanent references to these (i.e. between API calls), since they may
 * become invalidated if the user replaces a repository internal.
 */
138 139
int git_repository_config__weakptr(git_config **out, git_repository *repo);
int git_repository_odb__weakptr(git_odb **out, git_repository *repo);
140
int git_repository_refdb__weakptr(git_refdb **out, git_repository *repo);
141 142
int git_repository_index__weakptr(git_index **out, git_repository *repo);

143
/*
144
 * CVAR cache
145 146 147 148 149 150 151
 *
 * Efficient access to the most used config variables of a repository.
 * The cache is cleared everytime the config backend is replaced.
 */
int git_repository__cvar(int *out, git_repository *repo, git_cvar_cached cvar);
void git_repository__cvar_cache_clear(git_repository *repo);

152 153 154 155 156
/*
 * Submodule cache
 */
extern void git_submodule_config_free(git_repository *repo);

157 158 159 160 161 162 163 164 165 166 167 168 169 170 171
GIT_INLINE(int) git_repository__ensure_not_bare(
	git_repository *repo,
	const char *operation_name)
{
	if (!git_repository_is_bare(repo))
		return 0;

	giterr_set(
		GITERR_REPOSITORY,
		"Cannot %s. This operation is not allowed against bare repositories.",
		operation_name);

	return GIT_EBAREREPO;
}

172 173
int git_repository__cleanup_files(git_repository *repo, const char *files[], size_t files_len);

174
#endif