Commit fba3bf79780406cad976086cbba8b9684073ba9d

Edward Thomson 2019-07-21T14:15:12

blob: optionally read attributes from repository When `GIT_BLOB_FILTER_ATTTRIBUTES_FROM_HEAD` is passed to `git_blob_filter`, read attributes from `gitattributes` files that are checked in to the repository at the HEAD revision. This passes the flag `GIT_FILTER_ATTRIBUTES_FROM_HEAD` to the filter functions.

diff --git a/include/git2/blob.h b/include/git2/blob.h
index 923bcf6..1dfd6b7 100644
--- a/include/git2/blob.h
+++ b/include/git2/blob.h
@@ -108,6 +108,12 @@ typedef enum {
 	 * system-wide `gitattributes` in `/etc` (or system equivalent).
 	 */
 	GIT_BLOB_FILTER_NO_SYSTEM_ATTRIBUTES = (1 << 1),
+
+	/**
+	 * When set, filters will be loaded from a `.gitattributes` file
+	 * in the HEAD commit.
+	 */
+	GIT_BLOB_FILTER_ATTTRIBUTES_FROM_HEAD = (1 << 2),
 } git_blob_filter_flag_t;
 
 /**
diff --git a/src/blob.c b/src/blob.c
index 7db05f0..487e608 100644
--- a/src/blob.c
+++ b/src/blob.c
@@ -428,6 +428,9 @@ int git_blob_filter(
 	if ((opts.flags & GIT_BLOB_FILTER_NO_SYSTEM_ATTRIBUTES) != 0)
 		flags |= GIT_FILTER_NO_SYSTEM_ATTRIBUTES;
 
+	if ((opts.flags & GIT_BLOB_FILTER_ATTTRIBUTES_FROM_HEAD) != 0)
+		flags |= GIT_FILTER_ATTRIBUTES_FROM_HEAD;
+
 	if (!(error = git_filter_list_load(
 			&fl, git_blob_owner(blob), blob, path,
 			GIT_FILTER_TO_WORKTREE, flags))) {