summaryrefslogtreecommitdiff
path: root/include
diff options
context:
space:
mode:
authorEdward Thomson <ethomson@edwardthomson.com>2019-08-27 11:29:24 -0400
committerGitHub <noreply@github.com>2019-08-27 11:29:24 -0400
commit6de48085b6d6c28ea90c57286d77f88f200da841 (patch)
tree1c4c98a1da034f0c0675f79de4d4d352d250ce85 /include
parentaaa48d06d9c0ac08e09422f601f722fb7533186a (diff)
parentcdbbb364828428fd7d44cca2df01ae14ee0a3d16 (diff)
downloadlibgit2-6de48085b6d6c28ea90c57286d77f88f200da841.tar.gz
Merge pull request #5189 from libgit2/ethomson/attrs_from_head
Optionally read `.gitattributes` from HEAD
Diffstat (limited to 'include')
-rw-r--r--include/git2/attr.h11
-rw-r--r--include/git2/blob.h40
-rw-r--r--include/git2/deprecated.h7
-rw-r--r--include/git2/filter.h8
4 files changed, 60 insertions, 6 deletions
diff --git a/include/git2/attr.h b/include/git2/attr.h
index cab9758a0..72e43806c 100644
--- a/include/git2/attr.h
+++ b/include/git2/attr.h
@@ -119,13 +119,20 @@ GIT_EXTERN(git_attr_value_t) git_attr_value(const char *attr);
#define GIT_ATTR_CHECK_INDEX_ONLY 2
/**
- * Check attribute flags: Using the system attributes file.
+ * Check attribute flags: controlling extended attribute behavior.
*
* Normally, attribute checks include looking in the /etc (or system
* equivalent) directory for a `gitattributes` file. Passing this
* flag will cause attribute checks to ignore that file.
+ * equivalent) directory for a `gitattributes` file. Passing the
+ * `GIT_ATTR_CHECK_NO_SYSTEM` flag will cause attribute checks to
+ * ignore that file.
+ *
+ * Passing the `GIT_ATTR_CHECK_INCLUDE_HEAD` flag will use attributes
+ * from a `.gitattributes` file in the repository at the HEAD revision.
*/
-#define GIT_ATTR_CHECK_NO_SYSTEM (1 << 2)
+#define GIT_ATTR_CHECK_NO_SYSTEM (1 << 2)
+#define GIT_ATTR_CHECK_INCLUDE_HEAD (1 << 3)
/**
* Look up the value of one git attribute for path.
diff --git a/include/git2/blob.h b/include/git2/blob.h
index 072522d5c..1dfd6b72a 100644
--- a/include/git2/blob.h
+++ b/include/git2/blob.h
@@ -97,6 +97,39 @@ GIT_EXTERN(const void *) git_blob_rawcontent(const git_blob *blob);
GIT_EXTERN(git_off_t) git_blob_rawsize(const git_blob *blob);
/**
+ * Flags to control the functionality of `git_blob_filter`.
+ */
+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),
+
+ /**
+ * 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;
+
+/**
+ * The options used when applying filter options to a file.
+ */
+typedef struct {
+ int version;
+
+ /** Flags to control the filtering process */
+ git_blob_filter_flag_t flags;
+} git_blob_filter_options;
+
+#define GIT_BLOB_FILTER_OPTIONS_VERSION 1
+#define GIT_BLOB_FILTER_OPTIONS_INIT {GIT_BLOB_FILTER_OPTIONS_VERSION, GIT_BLOB_FILTER_CHECK_FOR_BINARY}
+
+/**
* Get a buffer with the filtered content of a blob.
*
* This applies filters as if the blob was being checked out to the
@@ -115,15 +148,14 @@ GIT_EXTERN(git_off_t) git_blob_rawsize(const git_blob *blob);
* @param out The git_buf to be filled in
* @param blob Pointer to the blob
* @param as_path Path used for file attribute lookups, etc.
- * @param check_for_binary_data Should this test if blob content contains
- * NUL bytes / looks like binary data before applying filters?
+ * @param opts Options to use for filtering the blob
* @return 0 on success or an error code
*/
-GIT_EXTERN(int) git_blob_filtered_content(
+GIT_EXTERN(int) git_blob_filter(
git_buf *out,
git_blob *blob,
const char *as_path,
- int check_for_binary_data);
+ git_blob_filter_options *opts);
/**
* Read a file from the working folder of a repository
diff --git a/include/git2/deprecated.h b/include/git2/deprecated.h
index df53cf01d..ac1ad1a63 100644
--- a/include/git2/deprecated.h
+++ b/include/git2/deprecated.h
@@ -90,6 +90,13 @@ GIT_EXTERN(int) git_blob_create_fromstream_commit(
GIT_EXTERN(int) git_blob_create_frombuffer(
git_oid *id, git_repository *repo, const void *buffer, size_t len);
+/** Deprecated in favor of @see git_blob_filter */
+GIT_EXTERN(int) git_blob_filtered_content(
+ git_buf *out,
+ git_blob *blob,
+ const char *as_path,
+ int check_for_binary_data);
+
/**@}*/
/** @name Deprecated Buffer Functions
diff --git a/include/git2/filter.h b/include/git2/filter.h
index 436a0f3c8..886059051 100644
--- a/include/git2/filter.h
+++ b/include/git2/filter.h
@@ -40,7 +40,15 @@ typedef enum {
*/
typedef enum {
GIT_FILTER_DEFAULT = 0u,
+
+ /** Don't error for `safecrlf` violations, allow them to continue. */
GIT_FILTER_ALLOW_UNSAFE = (1u << 0),
+
+ /** Don't load `/etc/gitattributes` (or the system equivalent) */
+ GIT_FILTER_NO_SYSTEM_ATTRIBUTES = (1u << 1),
+
+ /** Load attributes from `.gitattributes` in the root of HEAD */
+ GIT_FILTER_ATTRIBUTES_FROM_HEAD = (1u << 2),
} git_filter_flag_t;
/**