Skip to content

Commit 5ee5048

Browse files
committed
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.
1 parent 5c5c19a commit 5ee5048

File tree

8 files changed

+89
-77
lines changed

8 files changed

+89
-77
lines changed

src/attr.c

Lines changed: 29 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -256,7 +256,7 @@ int git_attr_foreach(
256256
static int preload_attr_file(
257257
git_repository *repo,
258258
git_attr_session *attr_session,
259-
git_attr_file_source source,
259+
git_attr_file_source_t source_type,
260260
const char *base,
261261
const char *file,
262262
bool allow_macros)
@@ -266,8 +266,10 @@ static int preload_attr_file(
266266

267267
if (!file)
268268
return 0;
269-
if (!(error = git_attr_cache__get(&preload, repo, attr_session, source, base, file,
270-
git_attr_file__parse_buffer, allow_macros)))
269+
if (!(error = git_attr_cache__get(&preload, repo, attr_session,
270+
source_type, base, file,
271+
git_attr_file__parse_buffer,
272+
allow_macros)))
271273
git_attr_file__free(preload);
272274

273275
return error;
@@ -333,36 +335,36 @@ static int attr_setup(
333335
*/
334336

335337
if ((error = system_attr_file(&path, attr_session)) < 0 ||
336-
(error = preload_attr_file(repo, attr_session, GIT_ATTR_FILE__FROM_FILE,
338+
(error = preload_attr_file(repo, attr_session, GIT_ATTR_FILE_SOURCE_FILE,
337339
NULL, path.ptr, true)) < 0) {
338340
if (error != GIT_ENOTFOUND)
339341
goto out;
340342
}
341343

342-
if ((error = preload_attr_file(repo, attr_session, GIT_ATTR_FILE__FROM_FILE,
344+
if ((error = preload_attr_file(repo, attr_session, GIT_ATTR_FILE_SOURCE_FILE,
343345
NULL, git_repository_attr_cache(repo)->cfg_attr_file, true)) < 0)
344346
goto out;
345347

346348
git_buf_clear(&path); /* git_repository_item_path expects an empty buffer, because it uses git_buf_set */
347349
if ((error = git_repository_item_path(&path, repo, GIT_REPOSITORY_ITEM_INFO)) < 0 ||
348-
(error = preload_attr_file(repo, attr_session, GIT_ATTR_FILE__FROM_FILE,
350+
(error = preload_attr_file(repo, attr_session, GIT_ATTR_FILE_SOURCE_FILE,
349351
path.ptr, GIT_ATTR_FILE_INREPO, true)) < 0) {
350352
if (error != GIT_ENOTFOUND)
351353
goto out;
352354
}
353355

354356
if ((workdir = git_repository_workdir(repo)) != NULL &&
355-
(error = preload_attr_file(repo, attr_session, GIT_ATTR_FILE__FROM_FILE,
357+
(error = preload_attr_file(repo, attr_session, GIT_ATTR_FILE_SOURCE_FILE,
356358
workdir, GIT_ATTR_FILE, true)) < 0)
357359
goto out;
358360

359361
if ((error = git_repository_index__weakptr(&idx, repo)) < 0 ||
360-
(error = preload_attr_file(repo, attr_session, GIT_ATTR_FILE__FROM_INDEX,
362+
(error = preload_attr_file(repo, attr_session, GIT_ATTR_FILE_SOURCE_INDEX,
361363
NULL, GIT_ATTR_FILE, true)) < 0)
362364
goto out;
363365

364366
if ((flags & GIT_ATTR_CHECK_INCLUDE_HEAD) != 0 &&
365-
(error = preload_attr_file(repo, attr_session, GIT_ATTR_FILE__FROM_HEAD,
367+
(error = preload_attr_file(repo, attr_session, GIT_ATTR_FILE_SOURCE_HEAD,
366368
NULL, GIT_ATTR_FILE, true)) < 0)
367369
goto out;
368370

@@ -422,31 +424,34 @@ typedef struct {
422424
} attr_walk_up_info;
423425

424426
static int attr_decide_sources(
425-
uint32_t flags, bool has_wd, bool has_index, git_attr_file_source *srcs)
427+
uint32_t flags,
428+
bool has_wd,
429+
bool has_index,
430+
git_attr_file_source_t *srcs)
426431
{
427432
int count = 0;
428433

429434
switch (flags & 0x03) {
430435
case GIT_ATTR_CHECK_FILE_THEN_INDEX:
431436
if (has_wd)
432-
srcs[count++] = GIT_ATTR_FILE__FROM_FILE;
437+
srcs[count++] = GIT_ATTR_FILE_SOURCE_FILE;
433438
if (has_index)
434-
srcs[count++] = GIT_ATTR_FILE__FROM_INDEX;
439+
srcs[count++] = GIT_ATTR_FILE_SOURCE_INDEX;
435440
break;
436441
case GIT_ATTR_CHECK_INDEX_THEN_FILE:
437442
if (has_index)
438-
srcs[count++] = GIT_ATTR_FILE__FROM_INDEX;
443+
srcs[count++] = GIT_ATTR_FILE_SOURCE_INDEX;
439444
if (has_wd)
440-
srcs[count++] = GIT_ATTR_FILE__FROM_FILE;
445+
srcs[count++] = GIT_ATTR_FILE_SOURCE_FILE;
441446
break;
442447
case GIT_ATTR_CHECK_INDEX_ONLY:
443448
if (has_index)
444-
srcs[count++] = GIT_ATTR_FILE__FROM_INDEX;
449+
srcs[count++] = GIT_ATTR_FILE_SOURCE_INDEX;
445450
break;
446451
}
447452

448453
if ((flags & GIT_ATTR_CHECK_INCLUDE_HEAD) != 0)
449-
srcs[count++] = GIT_ATTR_FILE__FROM_HEAD;
454+
srcs[count++] = GIT_ATTR_FILE_SOURCE_HEAD;
450455

451456
return count;
452457
}
@@ -455,7 +460,7 @@ static int push_attr_file(
455460
git_repository *repo,
456461
git_attr_session *attr_session,
457462
git_vector *list,
458-
git_attr_file_source source,
463+
git_attr_file_source_t source_type,
459464
const char *base,
460465
const char *filename,
461466
bool allow_macros)
@@ -464,7 +469,9 @@ static int push_attr_file(
464469
git_attr_file *file = NULL;
465470

466471
error = git_attr_cache__get(&file, repo, attr_session,
467-
source, base, filename, git_attr_file__parse_buffer, allow_macros);
472+
source_type, base, filename,
473+
git_attr_file__parse_buffer,
474+
allow_macros);
468475

469476
if (error < 0)
470477
return error;
@@ -480,7 +487,7 @@ static int push_attr_file(
480487
static int push_one_attr(void *ref, const char *path)
481488
{
482489
attr_walk_up_info *info = (attr_walk_up_info *)ref;
483-
git_attr_file_source src[GIT_ATTR_FILE_NUM_SOURCES];
490+
git_attr_file_source_t src[GIT_ATTR_FILE_NUM_SOURCES];
484491
int error = 0, n_src, i;
485492
bool allow_macros;
486493

@@ -542,7 +549,7 @@ static int collect_attr_files(
542549
*/
543550

544551
if ((error = git_repository_item_path(&attrfile, repo, GIT_REPOSITORY_ITEM_INFO)) < 0 ||
545-
(error = push_attr_file(repo, attr_session, files, GIT_ATTR_FILE__FROM_FILE,
552+
(error = push_attr_file(repo, attr_session, files, GIT_ATTR_FILE_SOURCE_FILE,
546553
attrfile.ptr, GIT_ATTR_FILE_INREPO, true)) < 0) {
547554
if (error != GIT_ENOTFOUND)
548555
goto cleanup;
@@ -565,7 +572,7 @@ static int collect_attr_files(
565572
goto cleanup;
566573

567574
if (git_repository_attr_cache(repo)->cfg_attr_file != NULL) {
568-
error = push_attr_file(repo, attr_session, files, GIT_ATTR_FILE__FROM_FILE,
575+
error = push_attr_file(repo, attr_session, files, GIT_ATTR_FILE_SOURCE_FILE,
569576
NULL, git_repository_attr_cache(repo)->cfg_attr_file, true);
570577
if (error < 0)
571578
goto cleanup;
@@ -575,7 +582,7 @@ static int collect_attr_files(
575582
error = system_attr_file(&dir, attr_session);
576583

577584
if (!error)
578-
error = push_attr_file(repo, attr_session, files, GIT_ATTR_FILE__FROM_FILE,
585+
error = push_attr_file(repo, attr_session, files, GIT_ATTR_FILE_SOURCE_FILE,
579586
NULL, dir.ptr, true);
580587
else if (error == GIT_ENOTFOUND)
581588
error = 0;

src/attr_file.c

Lines changed: 21 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ static void attr_file_free(git_attr_file *file)
3333
int git_attr_file__new(
3434
git_attr_file **out,
3535
git_attr_file_entry *entry,
36-
git_attr_file_source source)
36+
git_attr_file_source_t source_type)
3737
{
3838
git_attr_file *attrs = git__calloc(1, sizeof(git_attr_file));
3939
GIT_ERROR_CHECK_ALLOC(attrs);
@@ -47,8 +47,8 @@ int git_attr_file__new(
4747
goto on_error;
4848

4949
GIT_REFCOUNT_INC(attrs);
50-
attrs->entry = entry;
51-
attrs->source = source;
50+
attrs->entry = entry;
51+
attrs->source_type = source_type;
5252
*out = attrs;
5353
return 0;
5454

@@ -108,7 +108,7 @@ int git_attr_file__load(
108108
git_repository *repo,
109109
git_attr_session *attr_session,
110110
git_attr_file_entry *entry,
111-
git_attr_file_source source,
111+
git_attr_file_source_t source_type,
112112
git_attr_file_parser parser,
113113
bool allow_macros)
114114
{
@@ -128,11 +128,11 @@ int git_attr_file__load(
128128

129129
*out = NULL;
130130

131-
switch (source) {
132-
case GIT_ATTR_FILE__IN_MEMORY:
131+
switch (source_type) {
132+
case GIT_ATTR_FILE_SOURCE_MEMORY:
133133
/* in-memory attribute file doesn't need data */
134134
break;
135-
case GIT_ATTR_FILE__FROM_INDEX: {
135+
case GIT_ATTR_FILE_SOURCE_INDEX: {
136136
if ((error = attr_file_oid_from_index(&id, repo, entry->path)) < 0 ||
137137
(error = git_blob_lookup(&blob, repo, &id)) < 0)
138138
return error;
@@ -145,7 +145,7 @@ int git_attr_file__load(
145145
git_buf_put(&content, git_blob_rawcontent(blob), (size_t)blobsize);
146146
break;
147147
}
148-
case GIT_ATTR_FILE__FROM_FILE: {
148+
case GIT_ATTR_FILE_SOURCE_FILE: {
149149
int fd = -1;
150150

151151
/* For open or read errors, pretend that we got ENOTFOUND. */
@@ -162,7 +162,7 @@ int git_attr_file__load(
162162

163163
break;
164164
}
165-
case GIT_ATTR_FILE__FROM_HEAD: {
165+
case GIT_ATTR_FILE_SOURCE_HEAD: {
166166
if ((error = git_repository_head_tree(&tree, repo)) < 0 ||
167167
(error = git_tree_entry_bypath(&tree_entry, tree, entry->path)) < 0 ||
168168
(error = git_blob_lookup(&blob, repo, git_tree_entry_id(tree_entry))) < 0)
@@ -182,11 +182,11 @@ int git_attr_file__load(
182182
break;
183183
}
184184
default:
185-
git_error_set(GIT_ERROR_INVALID, "unknown file source %d", source);
185+
git_error_set(GIT_ERROR_INVALID, "unknown file source %d", source_type);
186186
return -1;
187187
}
188188

189-
if ((error = git_attr_file__new(&file, entry, source)) < 0)
189+
if ((error = git_attr_file__new(&file, entry, source_type)) < 0)
190190
goto cleanup;
191191

192192
/* advance over a UTF8 BOM */
@@ -210,11 +210,11 @@ int git_attr_file__load(
210210
/* write cache breakers */
211211
if (nonexistent)
212212
file->nonexistent = 1;
213-
else if (source == GIT_ATTR_FILE__FROM_INDEX)
213+
else if (source_type == GIT_ATTR_FILE_SOURCE_INDEX)
214214
git_oid_cpy(&file->cache_data.oid, git_blob_id(blob));
215-
else if (source == GIT_ATTR_FILE__FROM_HEAD)
215+
else if (source_type == GIT_ATTR_FILE_SOURCE_HEAD)
216216
git_oid_cpy(&file->cache_data.oid, git_tree_id(tree));
217-
else if (source == GIT_ATTR_FILE__FROM_FILE)
217+
else if (source_type == GIT_ATTR_FILE_SOURCE_FILE)
218218
git_futils_filestamp_set_from_stat(&file->cache_data.stamp, &st);
219219
/* else always cacheable */
220220

@@ -245,15 +245,15 @@ int git_attr_file__out_of_date(
245245
else if (file->nonexistent)
246246
return 1;
247247

248-
switch (file->source) {
249-
case GIT_ATTR_FILE__IN_MEMORY:
248+
switch (file->source_type) {
249+
case GIT_ATTR_FILE_SOURCE_MEMORY:
250250
return 0;
251251

252-
case GIT_ATTR_FILE__FROM_FILE:
252+
case GIT_ATTR_FILE_SOURCE_FILE:
253253
return git_futils_filestamp_check(
254254
&file->cache_data.stamp, file->entry->fullpath);
255255

256-
case GIT_ATTR_FILE__FROM_INDEX: {
256+
case GIT_ATTR_FILE_SOURCE_INDEX: {
257257
int error;
258258
git_oid id;
259259

@@ -264,7 +264,7 @@ int git_attr_file__out_of_date(
264264
return (git_oid__cmp(&file->cache_data.oid, &id) != 0);
265265
}
266266

267-
case GIT_ATTR_FILE__FROM_HEAD: {
267+
case GIT_ATTR_FILE_SOURCE_HEAD: {
268268
git_tree *tree;
269269
int error;
270270

@@ -278,7 +278,7 @@ int git_attr_file__out_of_date(
278278
}
279279

280280
default:
281-
git_error_set(GIT_ERROR_INVALID, "invalid file type %d", file->source);
281+
git_error_set(GIT_ERROR_INVALID, "invalid file type %d", file->source_type);
282282
return -1;
283283
}
284284
}
@@ -400,7 +400,7 @@ int git_attr_file__load_standalone(git_attr_file **out, const char *path)
400400
* don't have to free it - freeing file+pool will free cache entry, too.
401401
*/
402402

403-
if ((error = git_attr_file__new(&file, NULL, GIT_ATTR_FILE__FROM_FILE)) < 0 ||
403+
if ((error = git_attr_file__new(&file, NULL, GIT_ATTR_FILE_SOURCE_FILE)) < 0 ||
404404
(error = git_attr_file__parse_buffer(NULL, file, content.ptr, true)) < 0 ||
405405
(error = git_attr_cache__alloc_file_entry(&file->entry, NULL, NULL, path, &file->pool)) < 0)
406406
goto out;

src/attr_file.h

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -37,13 +37,13 @@
3737
(GIT_ATTR_FNMATCH_ALLOWSPACE | GIT_ATTR_FNMATCH_ALLOWNEG | GIT_ATTR_FNMATCH_ALLOWMACRO)
3838

3939
typedef enum {
40-
GIT_ATTR_FILE__IN_MEMORY = 0,
41-
GIT_ATTR_FILE__FROM_FILE = 1,
42-
GIT_ATTR_FILE__FROM_INDEX = 2,
43-
GIT_ATTR_FILE__FROM_HEAD = 3,
40+
GIT_ATTR_FILE_SOURCE_MEMORY = 0,
41+
GIT_ATTR_FILE_SOURCE_FILE = 1,
42+
GIT_ATTR_FILE_SOURCE_INDEX = 2,
43+
GIT_ATTR_FILE_SOURCE_HEAD = 3,
4444

45-
GIT_ATTR_FILE_NUM_SOURCES = 4
46-
} git_attr_file_source;
45+
GIT_ATTR_FILE_NUM_SOURCES = 4
46+
} git_attr_file_source_t;
4747

4848
extern const char *git_attr__true;
4949
extern const char *git_attr__false;
@@ -81,7 +81,7 @@ typedef struct {
8181
git_refcount rc;
8282
git_mutex lock;
8383
git_attr_file_entry *entry;
84-
git_attr_file_source source;
84+
git_attr_file_source_t source_type;
8585
git_vector rules; /* vector of <rule*> or <fnmatch*> */
8686
git_pool pool;
8787
unsigned int nonexistent:1;
@@ -142,7 +142,7 @@ typedef int (*git_attr_file_parser)(
142142
int git_attr_file__new(
143143
git_attr_file **out,
144144
git_attr_file_entry *entry,
145-
git_attr_file_source source);
145+
git_attr_file_source_t source_type);
146146

147147
void git_attr_file__free(git_attr_file *file);
148148

@@ -151,7 +151,7 @@ int git_attr_file__load(
151151
git_repository *repo,
152152
git_attr_session *attr_session,
153153
git_attr_file_entry *ce,
154-
git_attr_file_source source,
154+
git_attr_file_source_t source_type,
155155
git_attr_file_parser parser,
156156
bool allow_macros);
157157

0 commit comments

Comments
 (0)