]>
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__
13 #include "git2/repository.h"
15 typedef struct git_filter
{
16 int (*apply
)(struct git_filter
*self
, git_buf
*dest
, const git_buf
*source
);
17 void (*do_free
)(struct git_filter
*self
);
21 GIT_FILTER_TO_WORKTREE
,
35 /* NUL, CR, LF and CRLF counts */
36 unsigned int nul
, cr
, lf
, crlf
;
38 /* These are just approximations! */
39 unsigned int printable
, nonprintable
;
47 * For any given path in the working directory, fill the `filters`
48 * array with the relevant filters that need to be applied.
50 * Mode is either `GIT_FILTER_TO_WORKTREE` if you need to load the
51 * filters that will be used when checking out a file to the working
52 * directory, or `GIT_FILTER_TO_ODB` for the filters used when writing
55 * @param filters Vector where to store all the loaded filters
56 * @param repo Repository object that contains `path`
57 * @param path Relative path of the file to be filtered
58 * @param mode Filtering direction (WT->ODB or ODB->WT)
59 * @return the number of filters loaded for the file (0 if the file
60 * doesn't need filtering), or a negative error code
62 extern int git_filters_load(git_vector
*filters
, git_repository
*repo
, const char *path
, int mode
);
65 * Apply one or more filters to a file.
67 * The file must have been loaded as a `git_buf` object. Both the `source`
68 * and `dest` buffers are owned by the caller and must be freed once
69 * they are no longer needed.
71 * NOTE: Because of the double-buffering schema, the `source` buffer that contains
72 * the original file may be tampered once the filtering is complete. Regardless,
73 * the `dest` buffer will always contain the final result of the filtering
75 * @param dest Buffer to store the result of the filtering
76 * @param source Buffer containing the document to filter
77 * @param filters A non-empty vector of filters as supplied by `git_filters_load`
78 * @return 0 on success, an error code otherwise
80 extern int git_filters_apply(git_buf
*dest
, git_buf
*source
, git_vector
*filters
);
83 * Free the `filters` array generated by `git_filters_load`.
85 * Note that this frees both the array and its contents. The array will
86 * be clean/reusable after this call.
88 * @param filters A filters array as supplied by `git_filters_load`
90 extern void git_filters_free(git_vector
*filters
);
96 /* Strip CRLF, from Worktree to ODB */
97 extern int git_filter_add__crlf_to_odb(git_vector
*filters
, git_repository
*repo
, const char *path
);
99 /* Add CRLF, from ODB to worktree */
100 extern int git_filter_add__crlf_to_workdir(git_vector
*filters
, git_repository
*repo
, const char *path
);
108 * Gather stats for a piece of text
110 * Fill the `stats` structure with information on the number of
111 * unreadable characters, carriage returns, etc, so it can be
112 * used in heuristics.
114 extern void git_text_gather_stats(git_text_stats
*stats
, const git_buf
*text
);
117 * Process `git_text_stats` data generated by `git_text_stat` to see
118 * if it qualifies as a binary file
120 extern int git_text_is_binary(git_text_stats
*stats
);