Commit a5392eae3d40dc7789de581406e35a1ce7487e1e

Edward Thomson 2019-07-21T12:13:07

blob: allow blob filtering to ignore system gitattributes Introduce `GIT_BLOB_FILTER_NO_SYSTEM_ATTRIBUTES`, which tells `git_blob_filter` to ignore the system-wide attributes file, usually `/etc/gitattributes`. This simply passes the appropriate flag to the attribute loading code.

diff --git a/include/git2/blob.h b/include/git2/blob.h
index 3710f41..923bcf6 100644
--- a/include/git2/blob.h
+++ b/include/git2/blob.h
@@ -102,6 +102,12 @@ GIT_EXTERN(git_off_t) git_blob_rawsize(const git_blob *blob);
 typedef enum {
 	/** When set, filters will not be applied to binary files. */
 	GIT_BLOB_FILTER_CHECK_FOR_BINARY = (1 << 0),
+
+	/**
+	 * When set, filters will not load configuration from the
+	 * system-wide `gitattributes` in `/etc` (or system equivalent).
+	 */
+	GIT_BLOB_FILTER_NO_SYSTEM_ATTRIBUTES = (1 << 1),
 } git_blob_filter_flag_t;
 
 /**
diff --git a/src/blob.c b/src/blob.c
index 1af3131..7db05f0 100644
--- a/src/blob.c
+++ b/src/blob.c
@@ -425,6 +425,9 @@ int git_blob_filter(
 	    git_blob_is_binary(blob))
 		return 0;
 
+	if ((opts.flags & GIT_BLOB_FILTER_NO_SYSTEM_ATTRIBUTES) != 0)
+		flags |= GIT_FILTER_NO_SYSTEM_ATTRIBUTES;
+
 	if (!(error = git_filter_list_load(
 			&fl, git_blob_owner(blob), blob, path,
 			GIT_FILTER_TO_WORKTREE, flags))) {