Commit 5ee50488 by Edward Thomson

attr: rename internal attr file source enum

The enum `git_attr_file_source` is better suffixed with a `_t` since
it's a type-of source.  Similarly, its members should have a matching
name.
parent 5c5c19a6
......@@ -256,7 +256,7 @@ cleanup:
static int preload_attr_file(
git_repository *repo,
git_attr_session *attr_session,
git_attr_file_source source,
git_attr_file_source_t source_type,
const char *base,
const char *file,
bool allow_macros)
......@@ -266,8 +266,10 @@ static int preload_attr_file(
if (!file)
return 0;
if (!(error = git_attr_cache__get(&preload, repo, attr_session, source, base, file,
git_attr_file__parse_buffer, allow_macros)))
if (!(error = git_attr_cache__get(&preload, repo, attr_session,
source_type, base, file,
git_attr_file__parse_buffer,
allow_macros)))
git_attr_file__free(preload);
return error;
......@@ -333,36 +335,36 @@ static int attr_setup(
*/
if ((error = system_attr_file(&path, attr_session)) < 0 ||
(error = preload_attr_file(repo, attr_session, GIT_ATTR_FILE__FROM_FILE,
(error = preload_attr_file(repo, attr_session, GIT_ATTR_FILE_SOURCE_FILE,
NULL, path.ptr, true)) < 0) {
if (error != GIT_ENOTFOUND)
goto out;
}
if ((error = preload_attr_file(repo, attr_session, GIT_ATTR_FILE__FROM_FILE,
if ((error = preload_attr_file(repo, attr_session, GIT_ATTR_FILE_SOURCE_FILE,
NULL, git_repository_attr_cache(repo)->cfg_attr_file, true)) < 0)
goto out;
git_buf_clear(&path); /* git_repository_item_path expects an empty buffer, because it uses git_buf_set */
if ((error = git_repository_item_path(&path, repo, GIT_REPOSITORY_ITEM_INFO)) < 0 ||
(error = preload_attr_file(repo, attr_session, GIT_ATTR_FILE__FROM_FILE,
(error = preload_attr_file(repo, attr_session, GIT_ATTR_FILE_SOURCE_FILE,
path.ptr, GIT_ATTR_FILE_INREPO, true)) < 0) {
if (error != GIT_ENOTFOUND)
goto out;
}
if ((workdir = git_repository_workdir(repo)) != NULL &&
(error = preload_attr_file(repo, attr_session, GIT_ATTR_FILE__FROM_FILE,
(error = preload_attr_file(repo, attr_session, GIT_ATTR_FILE_SOURCE_FILE,
workdir, GIT_ATTR_FILE, true)) < 0)
goto out;
if ((error = git_repository_index__weakptr(&idx, repo)) < 0 ||
(error = preload_attr_file(repo, attr_session, GIT_ATTR_FILE__FROM_INDEX,
(error = preload_attr_file(repo, attr_session, GIT_ATTR_FILE_SOURCE_INDEX,
NULL, GIT_ATTR_FILE, true)) < 0)
goto out;
if ((flags & GIT_ATTR_CHECK_INCLUDE_HEAD) != 0 &&
(error = preload_attr_file(repo, attr_session, GIT_ATTR_FILE__FROM_HEAD,
(error = preload_attr_file(repo, attr_session, GIT_ATTR_FILE_SOURCE_HEAD,
NULL, GIT_ATTR_FILE, true)) < 0)
goto out;
......@@ -422,31 +424,34 @@ typedef struct {
} attr_walk_up_info;
static int attr_decide_sources(
uint32_t flags, bool has_wd, bool has_index, git_attr_file_source *srcs)
uint32_t flags,
bool has_wd,
bool has_index,
git_attr_file_source_t *srcs)
{
int count = 0;
switch (flags & 0x03) {
case GIT_ATTR_CHECK_FILE_THEN_INDEX:
if (has_wd)
srcs[count++] = GIT_ATTR_FILE__FROM_FILE;
srcs[count++] = GIT_ATTR_FILE_SOURCE_FILE;
if (has_index)
srcs[count++] = GIT_ATTR_FILE__FROM_INDEX;
srcs[count++] = GIT_ATTR_FILE_SOURCE_INDEX;
break;
case GIT_ATTR_CHECK_INDEX_THEN_FILE:
if (has_index)
srcs[count++] = GIT_ATTR_FILE__FROM_INDEX;
srcs[count++] = GIT_ATTR_FILE_SOURCE_INDEX;
if (has_wd)
srcs[count++] = GIT_ATTR_FILE__FROM_FILE;
srcs[count++] = GIT_ATTR_FILE_SOURCE_FILE;
break;
case GIT_ATTR_CHECK_INDEX_ONLY:
if (has_index)
srcs[count++] = GIT_ATTR_FILE__FROM_INDEX;
srcs[count++] = GIT_ATTR_FILE_SOURCE_INDEX;
break;
}
if ((flags & GIT_ATTR_CHECK_INCLUDE_HEAD) != 0)
srcs[count++] = GIT_ATTR_FILE__FROM_HEAD;
srcs[count++] = GIT_ATTR_FILE_SOURCE_HEAD;
return count;
}
......@@ -455,7 +460,7 @@ static int push_attr_file(
git_repository *repo,
git_attr_session *attr_session,
git_vector *list,
git_attr_file_source source,
git_attr_file_source_t source_type,
const char *base,
const char *filename,
bool allow_macros)
......@@ -464,7 +469,9 @@ static int push_attr_file(
git_attr_file *file = NULL;
error = git_attr_cache__get(&file, repo, attr_session,
source, base, filename, git_attr_file__parse_buffer, allow_macros);
source_type, base, filename,
git_attr_file__parse_buffer,
allow_macros);
if (error < 0)
return error;
......@@ -480,7 +487,7 @@ static int push_attr_file(
static int push_one_attr(void *ref, const char *path)
{
attr_walk_up_info *info = (attr_walk_up_info *)ref;
git_attr_file_source src[GIT_ATTR_FILE_NUM_SOURCES];
git_attr_file_source_t src[GIT_ATTR_FILE_NUM_SOURCES];
int error = 0, n_src, i;
bool allow_macros;
......@@ -542,7 +549,7 @@ static int collect_attr_files(
*/
if ((error = git_repository_item_path(&attrfile, repo, GIT_REPOSITORY_ITEM_INFO)) < 0 ||
(error = push_attr_file(repo, attr_session, files, GIT_ATTR_FILE__FROM_FILE,
(error = push_attr_file(repo, attr_session, files, GIT_ATTR_FILE_SOURCE_FILE,
attrfile.ptr, GIT_ATTR_FILE_INREPO, true)) < 0) {
if (error != GIT_ENOTFOUND)
goto cleanup;
......@@ -565,7 +572,7 @@ static int collect_attr_files(
goto cleanup;
if (git_repository_attr_cache(repo)->cfg_attr_file != NULL) {
error = push_attr_file(repo, attr_session, files, GIT_ATTR_FILE__FROM_FILE,
error = push_attr_file(repo, attr_session, files, GIT_ATTR_FILE_SOURCE_FILE,
NULL, git_repository_attr_cache(repo)->cfg_attr_file, true);
if (error < 0)
goto cleanup;
......@@ -575,7 +582,7 @@ static int collect_attr_files(
error = system_attr_file(&dir, attr_session);
if (!error)
error = push_attr_file(repo, attr_session, files, GIT_ATTR_FILE__FROM_FILE,
error = push_attr_file(repo, attr_session, files, GIT_ATTR_FILE_SOURCE_FILE,
NULL, dir.ptr, true);
else if (error == GIT_ENOTFOUND)
error = 0;
......
......@@ -33,7 +33,7 @@ static void attr_file_free(git_attr_file *file)
int git_attr_file__new(
git_attr_file **out,
git_attr_file_entry *entry,
git_attr_file_source source)
git_attr_file_source_t source_type)
{
git_attr_file *attrs = git__calloc(1, sizeof(git_attr_file));
GIT_ERROR_CHECK_ALLOC(attrs);
......@@ -47,8 +47,8 @@ int git_attr_file__new(
goto on_error;
GIT_REFCOUNT_INC(attrs);
attrs->entry = entry;
attrs->source = source;
attrs->entry = entry;
attrs->source_type = source_type;
*out = attrs;
return 0;
......@@ -108,7 +108,7 @@ int git_attr_file__load(
git_repository *repo,
git_attr_session *attr_session,
git_attr_file_entry *entry,
git_attr_file_source source,
git_attr_file_source_t source_type,
git_attr_file_parser parser,
bool allow_macros)
{
......@@ -128,11 +128,11 @@ int git_attr_file__load(
*out = NULL;
switch (source) {
case GIT_ATTR_FILE__IN_MEMORY:
switch (source_type) {
case GIT_ATTR_FILE_SOURCE_MEMORY:
/* in-memory attribute file doesn't need data */
break;
case GIT_ATTR_FILE__FROM_INDEX: {
case GIT_ATTR_FILE_SOURCE_INDEX: {
if ((error = attr_file_oid_from_index(&id, repo, entry->path)) < 0 ||
(error = git_blob_lookup(&blob, repo, &id)) < 0)
return error;
......@@ -145,7 +145,7 @@ int git_attr_file__load(
git_buf_put(&content, git_blob_rawcontent(blob), (size_t)blobsize);
break;
}
case GIT_ATTR_FILE__FROM_FILE: {
case GIT_ATTR_FILE_SOURCE_FILE: {
int fd = -1;
/* For open or read errors, pretend that we got ENOTFOUND. */
......@@ -162,7 +162,7 @@ int git_attr_file__load(
break;
}
case GIT_ATTR_FILE__FROM_HEAD: {
case GIT_ATTR_FILE_SOURCE_HEAD: {
if ((error = git_repository_head_tree(&tree, repo)) < 0 ||
(error = git_tree_entry_bypath(&tree_entry, tree, entry->path)) < 0 ||
(error = git_blob_lookup(&blob, repo, git_tree_entry_id(tree_entry))) < 0)
......@@ -182,11 +182,11 @@ int git_attr_file__load(
break;
}
default:
git_error_set(GIT_ERROR_INVALID, "unknown file source %d", source);
git_error_set(GIT_ERROR_INVALID, "unknown file source %d", source_type);
return -1;
}
if ((error = git_attr_file__new(&file, entry, source)) < 0)
if ((error = git_attr_file__new(&file, entry, source_type)) < 0)
goto cleanup;
/* advance over a UTF8 BOM */
......@@ -210,11 +210,11 @@ int git_attr_file__load(
/* write cache breakers */
if (nonexistent)
file->nonexistent = 1;
else if (source == GIT_ATTR_FILE__FROM_INDEX)
else if (source_type == GIT_ATTR_FILE_SOURCE_INDEX)
git_oid_cpy(&file->cache_data.oid, git_blob_id(blob));
else if (source == GIT_ATTR_FILE__FROM_HEAD)
else if (source_type == GIT_ATTR_FILE_SOURCE_HEAD)
git_oid_cpy(&file->cache_data.oid, git_tree_id(tree));
else if (source == GIT_ATTR_FILE__FROM_FILE)
else if (source_type == GIT_ATTR_FILE_SOURCE_FILE)
git_futils_filestamp_set_from_stat(&file->cache_data.stamp, &st);
/* else always cacheable */
......@@ -245,15 +245,15 @@ int git_attr_file__out_of_date(
else if (file->nonexistent)
return 1;
switch (file->source) {
case GIT_ATTR_FILE__IN_MEMORY:
switch (file->source_type) {
case GIT_ATTR_FILE_SOURCE_MEMORY:
return 0;
case GIT_ATTR_FILE__FROM_FILE:
case GIT_ATTR_FILE_SOURCE_FILE:
return git_futils_filestamp_check(
&file->cache_data.stamp, file->entry->fullpath);
case GIT_ATTR_FILE__FROM_INDEX: {
case GIT_ATTR_FILE_SOURCE_INDEX: {
int error;
git_oid id;
......@@ -264,7 +264,7 @@ int git_attr_file__out_of_date(
return (git_oid__cmp(&file->cache_data.oid, &id) != 0);
}
case GIT_ATTR_FILE__FROM_HEAD: {
case GIT_ATTR_FILE_SOURCE_HEAD: {
git_tree *tree;
int error;
......@@ -278,7 +278,7 @@ int git_attr_file__out_of_date(
}
default:
git_error_set(GIT_ERROR_INVALID, "invalid file type %d", file->source);
git_error_set(GIT_ERROR_INVALID, "invalid file type %d", file->source_type);
return -1;
}
}
......@@ -400,7 +400,7 @@ int git_attr_file__load_standalone(git_attr_file **out, const char *path)
* don't have to free it - freeing file+pool will free cache entry, too.
*/
if ((error = git_attr_file__new(&file, NULL, GIT_ATTR_FILE__FROM_FILE)) < 0 ||
if ((error = git_attr_file__new(&file, NULL, GIT_ATTR_FILE_SOURCE_FILE)) < 0 ||
(error = git_attr_file__parse_buffer(NULL, file, content.ptr, true)) < 0 ||
(error = git_attr_cache__alloc_file_entry(&file->entry, NULL, NULL, path, &file->pool)) < 0)
goto out;
......
......@@ -37,13 +37,13 @@
(GIT_ATTR_FNMATCH_ALLOWSPACE | GIT_ATTR_FNMATCH_ALLOWNEG | GIT_ATTR_FNMATCH_ALLOWMACRO)
typedef enum {
GIT_ATTR_FILE__IN_MEMORY = 0,
GIT_ATTR_FILE__FROM_FILE = 1,
GIT_ATTR_FILE__FROM_INDEX = 2,
GIT_ATTR_FILE__FROM_HEAD = 3,
GIT_ATTR_FILE_SOURCE_MEMORY = 0,
GIT_ATTR_FILE_SOURCE_FILE = 1,
GIT_ATTR_FILE_SOURCE_INDEX = 2,
GIT_ATTR_FILE_SOURCE_HEAD = 3,
GIT_ATTR_FILE_NUM_SOURCES = 4
} git_attr_file_source;
GIT_ATTR_FILE_NUM_SOURCES = 4
} git_attr_file_source_t;
extern const char *git_attr__true;
extern const char *git_attr__false;
......@@ -81,7 +81,7 @@ typedef struct {
git_refcount rc;
git_mutex lock;
git_attr_file_entry *entry;
git_attr_file_source source;
git_attr_file_source_t source_type;
git_vector rules; /* vector of <rule*> or <fnmatch*> */
git_pool pool;
unsigned int nonexistent:1;
......@@ -142,7 +142,7 @@ typedef int (*git_attr_file_parser)(
int git_attr_file__new(
git_attr_file **out,
git_attr_file_entry *entry,
git_attr_file_source source);
git_attr_file_source_t source_type);
void git_attr_file__free(git_attr_file *file);
......@@ -151,7 +151,7 @@ int git_attr_file__load(
git_repository *repo,
git_attr_session *attr_session,
git_attr_file_entry *ce,
git_attr_file_source source,
git_attr_file_source_t source_type,
git_attr_file_parser parser,
bool allow_macros);
......
......@@ -112,7 +112,7 @@ static int attr_cache_upsert(git_attr_cache *cache, git_attr_file *file)
* Replace the existing value if another thread has
* created it in the meantime.
*/
old = git_atomic_swap(entry->file[file->source], file);
old = git_atomic_swap(entry->file[file->source_type], file);
if (old) {
GIT_REFCOUNT_OWN(old, NULL);
......@@ -136,7 +136,7 @@ static int attr_cache_remove(git_attr_cache *cache, git_attr_file *file)
return error;
if ((entry = attr_cache_lookup_entry(cache, file->entry->path)) != NULL)
old = git_atomic_compare_and_swap(&entry->file[file->source], file, NULL);
old = git_atomic_compare_and_swap(&entry->file[file->source_type], file, NULL);
attr_cache_unlock(cache);
......@@ -158,7 +158,7 @@ static int attr_cache_lookup(
git_attr_file_entry **out_entry,
git_repository *repo,
git_attr_session *attr_session,
git_attr_file_source source,
git_attr_file_source_t source_type,
const char *base,
const char *filename)
{
......@@ -191,8 +191,8 @@ static int attr_cache_lookup(
entry = attr_cache_lookup_entry(cache, relfile);
if (!entry)
error = attr_cache_make_entry(&entry, repo, relfile);
else if (entry->file[source] != NULL) {
file = entry->file[source];
else if (entry->file[source_type] != NULL) {
file = entry->file[source_type];
GIT_REFCOUNT_INC(file);
}
......@@ -210,7 +210,7 @@ int git_attr_cache__get(
git_attr_file **out,
git_repository *repo,
git_attr_session *attr_session,
git_attr_file_source source,
git_attr_file_source_t source_type,
const char *base,
const char *filename,
git_attr_file_parser parser,
......@@ -221,13 +221,15 @@ int git_attr_cache__get(
git_attr_file_entry *entry = NULL;
git_attr_file *file = NULL, *updated = NULL;
if ((error = attr_cache_lookup(
&file, &entry, repo, attr_session, source, base, filename)) < 0)
if ((error = attr_cache_lookup(&file, &entry, repo, attr_session,
source_type, base, filename)) < 0)
return error;
/* load file if we don't have one or if existing one is out of date */
if (!file || (error = git_attr_file__out_of_date(repo, attr_session, file)) > 0)
error = git_attr_file__load(&updated, repo, attr_session, entry, source, parser, allow_macros);
error = git_attr_file__load(&updated, repo, attr_session,
entry, source_type, parser,
allow_macros);
/* if we loaded the file, insert into and/or update cache */
if (updated) {
......@@ -260,7 +262,7 @@ int git_attr_cache__get(
bool git_attr_cache__is_cached(
git_repository *repo,
git_attr_file_source source,
git_attr_file_source_t source_type,
const char *filename)
{
git_attr_cache *cache = git_repository_attr_cache(repo);
......@@ -273,7 +275,7 @@ bool git_attr_cache__is_cached(
if ((entry = git_strmap_get(files, filename)) == NULL)
return false;
return entry && (entry->file[source] != NULL);
return entry && (entry->file[source_type] != NULL);
}
......
......@@ -31,7 +31,7 @@ extern int git_attr_cache__get(
git_attr_file **file,
git_repository *repo,
git_attr_session *attr_session,
git_attr_file_source source,
git_attr_file_source_t source_type,
const char *base,
const char *filename,
git_attr_file_parser parser,
......@@ -39,7 +39,7 @@ extern int git_attr_cache__get(
extern bool git_attr_cache__is_cached(
git_repository *repo,
git_attr_file_source source,
git_attr_file_source_t source_type,
const char *path);
extern int git_attr_cache__alloc_file_entry(
......
......@@ -250,8 +250,10 @@ static int push_ignore_file(
int error = 0;
git_attr_file *file = NULL;
error = git_attr_cache__get(&file, ignores->repo, NULL, GIT_ATTR_FILE__FROM_FILE,
base, filename, parse_ignore_file, false);
error = git_attr_cache__get(&file, ignores->repo, NULL,
GIT_ATTR_FILE_SOURCE_FILE, base,
filename, parse_ignore_file, false);
if (error < 0)
return error;
......@@ -277,8 +279,9 @@ static int get_internal_ignores(git_attr_file **out, git_repository *repo)
if ((error = git_attr_cache__init(repo)) < 0)
return error;
error = git_attr_cache__get(out, repo, NULL, GIT_ATTR_FILE__IN_MEMORY, NULL,
GIT_IGNORE_INTERNAL, NULL, false);
error = git_attr_cache__get(out, repo, NULL,
GIT_ATTR_FILE_SOURCE_MEMORY, NULL,
GIT_IGNORE_INTERNAL, NULL, false);
/* if internal rules list is empty, insert default rules */
if (!error && !(*out)->rules.length)
......
......@@ -71,11 +71,11 @@ void test_attr_repo__get_one(void)
}
cl_assert(git_attr_cache__is_cached(
g_repo, GIT_ATTR_FILE__FROM_FILE, ".git/info/attributes"));
g_repo, GIT_ATTR_FILE_SOURCE_FILE, ".git/info/attributes"));
cl_assert(git_attr_cache__is_cached(
g_repo, GIT_ATTR_FILE__FROM_FILE, ".gitattributes"));
g_repo, GIT_ATTR_FILE_SOURCE_FILE, ".gitattributes"));
cl_assert(git_attr_cache__is_cached(
g_repo, GIT_ATTR_FILE__FROM_FILE, "sub/.gitattributes"));
g_repo, GIT_ATTR_FILE_SOURCE_FILE, "sub/.gitattributes"));
}
void test_attr_repo__get_one_start_deep(void)
......@@ -92,11 +92,11 @@ void test_attr_repo__get_one_start_deep(void)
}
cl_assert(git_attr_cache__is_cached(
g_repo, GIT_ATTR_FILE__FROM_FILE, ".git/info/attributes"));
g_repo, GIT_ATTR_FILE_SOURCE_FILE, ".git/info/attributes"));
cl_assert(git_attr_cache__is_cached(
g_repo, GIT_ATTR_FILE__FROM_FILE, ".gitattributes"));
g_repo, GIT_ATTR_FILE_SOURCE_FILE, ".gitattributes"));
cl_assert(git_attr_cache__is_cached(
g_repo, GIT_ATTR_FILE__FROM_FILE, "sub/.gitattributes"));
g_repo, GIT_ATTR_FILE_SOURCE_FILE, "sub/.gitattributes"));
}
void test_attr_repo__get_many(void)
......
......@@ -70,9 +70,9 @@ void test_ignore_status__0(void)
/* confirm that ignore files were cached */
cl_assert(git_attr_cache__is_cached(
g_repo, GIT_ATTR_FILE__FROM_FILE, ".git/info/exclude"));
g_repo, GIT_ATTR_FILE_SOURCE_FILE, ".git/info/exclude"));
cl_assert(git_attr_cache__is_cached(
g_repo, GIT_ATTR_FILE__FROM_FILE, ".gitignore"));
g_repo, GIT_ATTR_FILE_SOURCE_FILE, ".gitignore"));
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment