summaryrefslogtreecommitdiff
path: root/include/git2/blob.h
diff options
context:
space:
mode:
authorEdward Thomson <ethomson@edwardthomson.com>2019-07-21 10:56:42 +0100
committerEdward Thomson <ethomson@edwardthomson.com>2019-08-11 20:47:59 +0100
commita32ab076bda0a283806f6690a853729fb43fa3f0 (patch)
tree61b56354a3532ffcaacd3b4ef364941dd224e1ba /include/git2/blob.h
parentc0290e27cc61b8110f1d5565ac4c1eb276217015 (diff)
downloadlibgit2-a32ab076bda0a283806f6690a853729fb43fa3f0.tar.gz
blob: introduce git_blob_filter
Provide a function to filter blobs that allows for more functionality than the existing `git_blob_filtered_content` function.
Diffstat (limited to 'include/git2/blob.h')
-rw-r--r--include/git2/blob.h39
1 files changed, 39 insertions, 0 deletions
diff --git a/include/git2/blob.h b/include/git2/blob.h
index 072522d5c..be721edd0 100644
--- a/include/git2/blob.h
+++ b/include/git2/blob.h
@@ -97,6 +97,27 @@ 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),
+} 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,6 +136,24 @@ 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 opts Options to use for filtering the blob
+ * @return 0 on success or an error code
+ */
+GIT_EXTERN(int) git_blob_filter(
+ git_buf *out,
+ git_blob *blob,
+ const char *as_path,
+ git_blob_filter_options *opts);
+
+/**
+ * Get a buffer with the filtered content of a blob. This is
+ * equivalent to calling `git_blob_filter`, with the only possible
+ * option being the binary check.
+ *
+ * @see git_blob_filter
+ * @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?
* @return 0 on success or an error code