Skip to content

Commit 22eb12a

Browse files
committed
filter: add GIT_FILTER_NO_SYSTEM_ATTRIBUTES option
Allow system-wide attributes (the ones specified in `/etc/gitattributes`) to be ignored if the flag `GIT_FILTER_NO_SYSTEM_ATTRIBUTES` is specified.
1 parent e7fc860 commit 22eb12a

File tree

2 files changed

+11
-3
lines changed

2 files changed

+11
-3
lines changed

include/git2/filter.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,9 @@ typedef enum {
4343

4444
/** Don't error for `safecrlf` violations, allow them to continue. */
4545
GIT_FILTER_ALLOW_UNSAFE = (1u << 0),
46+
47+
/** Don't load `/etc/gitattributes` (or the system equivalent) */
48+
GIT_FILTER_NO_SYSTEM_ATTRIBUTES = (1u << 1),
4649
} git_filter_flag_t;
4750

4851
/**

src/filter.c

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -428,13 +428,18 @@ static int filter_list_check_attributes(
428428
git_filter_def *fdef,
429429
const git_filter_source *src)
430430
{
431-
int error;
432-
size_t i;
433431
const char **strs = git__calloc(fdef->nattrs, sizeof(const char *));
432+
uint32_t flags = 0;
433+
size_t i;
434+
int error;
435+
434436
GIT_ERROR_CHECK_ALLOC(strs);
435437

438+
if ((src->flags & GIT_FILTER_NO_SYSTEM_ATTRIBUTES) != 0)
439+
flags |= GIT_ATTR_CHECK_NO_SYSTEM;
440+
436441
error = git_attr_get_many_with_session(
437-
strs, repo, attr_session, 0, src->path, fdef->nattrs, fdef->attrs);
442+
strs, repo, attr_session, flags, src->path, fdef->nattrs, fdef->attrs);
438443

439444
/* if no values were found but no matches are needed, it's okay! */
440445
if (error == GIT_ENOTFOUND && !fdef->nmatches) {

0 commit comments

Comments
 (0)