summaryrefslogtreecommitdiff
path: root/src/checkout.c
diff options
context:
space:
mode:
authorRussell Belfer <rb@github.com>2013-09-10 16:33:32 -0700
committerRussell Belfer <rb@github.com>2013-09-17 09:31:44 -0700
commit2a7d224f99a053d93079644947d04e7cc085930f (patch)
tree5a9082e68e98cd85e0bde8d8e399d386158ad390 /src/checkout.c
parent974774c7b00c08585b05ff87174872be005a1f29 (diff)
downloadlibgit2-2a7d224f99a053d93079644947d04e7cc085930f.tar.gz
Extend public filter api with filter lists
This moves the git_filter_list into the public API so that users can create, apply, and dispose of filter lists. This allows more granular application of filters to user data outside of libgit2 internals. This also converts all the internal usage of filters to the public APIs along with a few small tweaks to make it easier to use the public git_buffer stuff alongside the internal git_buf.
Diffstat (limited to 'src/checkout.c')
-rw-r--r--src/checkout.c38
1 files changed, 13 insertions, 25 deletions
diff --git a/src/checkout.c b/src/checkout.c
index 5ce4a19c5..1def58b0a 100644
--- a/src/checkout.c
+++ b/src/checkout.c
@@ -678,19 +678,20 @@ fail:
static int buffer_to_file(
struct stat *st,
- git_buf *buffer,
+ git_buffer *buffer,
const char *path,
mode_t dir_mode,
int file_open_flags,
mode_t file_mode)
{
int error;
+ git_buf buf = GIT_BUF_FROM_BUFFER(buffer);
if ((error = git_futils_mkpath2file(path, dir_mode)) < 0)
return error;
if ((error = git_futils_writebuffer(
- buffer, path, file_open_flags, file_mode)) < 0)
+ &buf, path, file_open_flags, file_mode)) < 0)
return error;
if (st != NULL && (error = p_stat(path, st)) < 0)
@@ -712,39 +713,26 @@ static int blob_content_to_file(
{
int error = 0;
mode_t file_mode = opts->file_mode ? opts->file_mode : entry_filemode;
- git_buf unfiltered = GIT_BUF_INIT, filtered = GIT_BUF_INIT;
+ git_buffer out = GIT_BUFFER_INIT;
git_filter_list *fl = NULL;
- /* 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);
-
- if (!opts->disable_filters && !git_buf_text_is_binary(&filtered)) {
+ if (!opts->disable_filters && !git_blob_is_binary(blob))
error = git_filter_list_load(
&fl, git_blob_owner(blob), path, GIT_FILTER_TO_WORKTREE);
- }
- if (fl != NULL) {
- /* reset 'filtered' so it can be a filter target */
- git_buf_init(&filtered, 0);
+ if (!error)
+ error = git_filter_list_apply_to_blob(&out, fl, blob);
- if (!(error = git_blob__getbuf(&unfiltered, blob))) {
- error = git_filter_list_apply(&filtered, &unfiltered, fl);
-
- git_buf_free(&unfiltered);
- }
+ git_filter_list_free(fl);
- git_filter_list_free(fl);
- }
+ if (!error) {
+ error = buffer_to_file(
+ st, &out, path, opts->dir_mode, opts->file_open_flags, file_mode);
- if (!error &&
- !(error = buffer_to_file(
- st, &filtered, path, opts->dir_mode,
- opts->file_open_flags, file_mode)))
st->st_mode = entry_filemode;
- if (filtered.asize != 0)
- git_buf_free(&filtered);
+ git_buffer_free(&out);
+ }
return error;
}