]>
git.proxmox.com Git - libgit2.git/blob - src/filter.h
2 * Copyright (C) 2009-2012 the libgit2 contributors
4 * This file is part of libgit2, distributed under the GNU GPL v2 with
5 * a Linking Exception. For full terms see the included COPYING file.
7 #ifndef INCLUDE_filter_h__
8 #define INCLUDE_filter_h__
14 #include "git2/repository.h"
16 typedef struct git_filter
{
17 int (*apply
)(struct git_filter
*self
, git_buf
*dest
, const git_buf
*source
);
18 void (*do_free
)(struct git_filter
*self
);
22 GIT_FILTER_TO_WORKTREE
,
40 * For any given path in the working directory, fill the `filters`
41 * array with the relevant filters that need to be applied.
43 * Mode is either `GIT_FILTER_TO_WORKTREE` if you need to load the
44 * filters that will be used when checking out a file to the working
45 * directory, or `GIT_FILTER_TO_ODB` for the filters used when writing
48 * @param filters Vector where to store all the loaded filters
49 * @param repo Repository object that contains `path`
50 * @param path Relative path of the file to be filtered
51 * @param mode Filtering direction (WT->ODB or ODB->WT)
52 * @return the number of filters loaded for the file (0 if the file
53 * doesn't need filtering), or a negative error code
55 extern int git_filters_load(git_vector
*filters
, git_repository
*repo
, const char *path
, int mode
);
58 * Apply one or more filters to a file.
60 * The file must have been loaded as a `git_buf` object. Both the `source`
61 * and `dest` buffers are owned by the caller and must be freed once
62 * they are no longer needed.
64 * NOTE: Because of the double-buffering schema, the `source` buffer that contains
65 * the original file may be tampered once the filtering is complete. Regardless,
66 * the `dest` buffer will always contain the final result of the filtering
68 * @param dest Buffer to store the result of the filtering
69 * @param source Buffer containing the document to filter
70 * @param filters A non-empty vector of filters as supplied by `git_filters_load`
71 * @return 0 on success, an error code otherwise
73 extern int git_filters_apply(git_buf
*dest
, git_buf
*source
, git_vector
*filters
);
76 * Free the `filters` array generated by `git_filters_load`.
78 * Note that this frees both the array and its contents. The array will
79 * be clean/reusable after this call.
81 * @param filters A filters array as supplied by `git_filters_load`
83 extern void git_filters_free(git_vector
*filters
);
89 /* Strip CRLF, from Worktree to ODB */
90 extern int git_filter_add__crlf_to_odb(git_vector
*filters
, git_repository
*repo
, const char *path
);
92 /* Add CRLF, from ODB to worktree */
93 extern int git_filter_add__crlf_to_workdir(git_vector
*filters
, git_repository
*repo
, const char *path
);