Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/mono/libgit2.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRussell Belfer <rb@github.com>2013-08-27 10:17:07 +0400
committerRussell Belfer <rb@github.com>2013-09-17 20:30:06 +0400
commit0cf77103b218ad3622aff34f3296db1bdd5f0df9 (patch)
treef60998088c2617f3a289942d7928112f0fe683e9 /src/blob.c
parent4581f9d8ab72e9b97817e1eaa7154bcec1c7f0b1 (diff)
Start of filter API + git_blob_filtered_content
This begins the process of exposing git_filter objects to the public API. This includes: * new public type and API for `git_buffer` through which an allocated buffer can be passed to the user * new API `git_blob_filtered_content` * make the git_filter type and GIT_FILTER_TO_... constants public
Diffstat (limited to 'src/blob.c')
-rw-r--r--src/blob.c51
1 files changed, 51 insertions, 0 deletions
diff --git a/src/blob.c b/src/blob.c
index 6a289f43b..6a866538c 100644
--- a/src/blob.c
+++ b/src/blob.c
@@ -338,3 +338,54 @@ int git_blob_is_binary(git_blob *blob)
return git_buf_text_is_binary(&content);
}
+
+int git_blob_filtered_content(
+ git_buffer *out,
+ git_blob *blob,
+ const char *as_path,
+ int check_for_binary_data)
+{
+ int error = 0, num_filters = 0;
+ git_buf filtered = GIT_BUF_INIT, unfiltered = GIT_BUF_INIT;
+ git_vector filters = GIT_VECTOR_INIT;
+
+ assert(blob && as_path && out);
+
+ /* Create a fake git_buf from the blob raw data... */
+ filtered.ptr = (void *)git_blob_rawcontent(blob);
+ filtered.size = (size_t)git_blob_rawsize(blob);
+ filtered.asize = 0;
+
+ if (check_for_binary_data && git_buf_text_is_binary(&filtered))
+ return 0;
+
+ num_filters = git_filters_load(
+ &filters, git_blob_owner(blob), as_path, GIT_FILTER_TO_WORKTREE);
+ if (num_filters < 0)
+ return num_filters;
+
+ if (num_filters > 0) {
+ if (out->ptr && out->available) {
+ filtered.ptr = out->ptr;
+ filtered.size = out->size;
+ filtered.asize = out->available;
+ } else {
+ git_buf_init(&filtered, filtered.size + 1);
+ }
+
+ if (!(error = git_blob__getbuf(&unfiltered, blob)))
+ error = git_filters_apply(&filtered, &unfiltered, &filters);
+
+ git_filters_free(&filters);
+ git_buf_free(&unfiltered);
+ }
+
+ if (!error) {
+ out->ptr = filtered.ptr;
+ out->size = filtered.size;
+ out->available = filtered.asize;
+ }
+
+ return error;
+}
+