Git 2.45-rc0
[git.git] / convert.h
blobab8b4fa68d67ba3da1fc7900b616dc70a9967eba
1 /*
2 * Copyright (c) 2011, Google Inc.
3 */
4 #ifndef CONVERT_H
5 #define CONVERT_H
7 #include "hash-ll.h"
8 #include "string-list.h"
10 struct index_state;
11 struct strbuf;
13 #define CONV_EOL_RNDTRP_DIE (1<<0) /* Die if CRLF to LF to CRLF is different */
14 #define CONV_EOL_RNDTRP_WARN (1<<1) /* Warn if CRLF to LF to CRLF is different */
15 #define CONV_EOL_RENORMALIZE (1<<2) /* Convert CRLF to LF */
16 #define CONV_EOL_KEEP_CRLF (1<<3) /* Keep CRLF line endings as is */
17 #define CONV_WRITE_OBJECT (1<<4) /* Content is written to the index */
19 extern int global_conv_flags_eol;
21 enum auto_crlf {
22 AUTO_CRLF_FALSE = 0,
23 AUTO_CRLF_TRUE = 1,
24 AUTO_CRLF_INPUT = -1
27 extern enum auto_crlf auto_crlf;
29 enum eol {
30 EOL_UNSET,
31 EOL_CRLF,
32 EOL_LF,
33 #ifdef NATIVE_CRLF
34 EOL_NATIVE = EOL_CRLF
35 #else
36 EOL_NATIVE = EOL_LF
37 #endif
40 enum ce_delay_state {
41 CE_NO_DELAY = 0,
42 CE_CAN_DELAY = 1,
43 CE_RETRY = 2
46 struct delayed_checkout {
48 * State of the currently processed cache entry. If the state is
49 * CE_CAN_DELAY, then the filter can delay the current cache entry.
50 * If the state is CE_RETRY, then this signals the filter that the
51 * cache entry was requested before.
53 enum ce_delay_state state;
54 /* List of filter drivers that signaled delayed blobs. */
55 struct string_list filters;
57 * List of delayed blobs identified by their path. The `util` member
58 * holds a counter pointer which must be incremented when/if the
59 * associated blob gets checked out.
61 struct string_list paths;
64 struct checkout_metadata {
65 const char *refname;
66 struct object_id treeish;
67 struct object_id blob;
70 enum convert_crlf_action {
71 CRLF_UNDEFINED,
72 CRLF_BINARY,
73 CRLF_TEXT,
74 CRLF_TEXT_INPUT,
75 CRLF_TEXT_CRLF,
76 CRLF_AUTO,
77 CRLF_AUTO_INPUT,
78 CRLF_AUTO_CRLF
81 struct convert_driver;
83 struct conv_attrs {
84 struct convert_driver *drv;
85 enum convert_crlf_action attr_action; /* What attr says */
86 enum convert_crlf_action crlf_action; /* When no attr is set, use core.autocrlf */
87 int ident;
88 const char *working_tree_encoding; /* Supported encoding or default encoding if NULL */
91 void convert_attrs(struct index_state *istate,
92 struct conv_attrs *ca, const char *path);
94 extern enum eol core_eol;
95 extern const char *check_roundtrip_encoding;
96 const char *get_cached_convert_stats_ascii(struct index_state *istate,
97 const char *path);
98 const char *get_wt_convert_stats_ascii(const char *path);
99 const char *get_convert_attr_ascii(struct index_state *istate,
100 const char *path);
102 /* returns 1 if *dst was used */
103 int convert_to_git(struct index_state *istate,
104 const char *path, const char *src, size_t len,
105 struct strbuf *dst, int conv_flags);
106 int convert_to_working_tree_ca(const struct conv_attrs *ca,
107 const char *path, const char *src,
108 size_t len, struct strbuf *dst,
109 const struct checkout_metadata *meta);
110 int async_convert_to_working_tree_ca(const struct conv_attrs *ca,
111 const char *path, const char *src,
112 size_t len, struct strbuf *dst,
113 const struct checkout_metadata *meta,
114 void *dco);
115 static inline int convert_to_working_tree(struct index_state *istate,
116 const char *path, const char *src,
117 size_t len, struct strbuf *dst,
118 const struct checkout_metadata *meta)
120 struct conv_attrs ca;
121 convert_attrs(istate, &ca, path);
122 return convert_to_working_tree_ca(&ca, path, src, len, dst, meta);
124 static inline int async_convert_to_working_tree(struct index_state *istate,
125 const char *path, const char *src,
126 size_t len, struct strbuf *dst,
127 const struct checkout_metadata *meta,
128 void *dco)
130 struct conv_attrs ca;
131 convert_attrs(istate, &ca, path);
132 return async_convert_to_working_tree_ca(&ca, path, src, len, dst, meta, dco);
134 int async_query_available_blobs(const char *cmd,
135 struct string_list *available_paths);
136 int renormalize_buffer(struct index_state *istate,
137 const char *path, const char *src, size_t len,
138 struct strbuf *dst);
139 static inline int would_convert_to_git(struct index_state *istate,
140 const char *path)
142 return convert_to_git(istate, path, NULL, 0, NULL, 0);
144 /* Precondition: would_convert_to_git_filter_fd(path) == true */
145 void convert_to_git_filter_fd(struct index_state *istate,
146 const char *path, int fd,
147 struct strbuf *dst,
148 int conv_flags);
149 int would_convert_to_git_filter_fd(struct index_state *istate,
150 const char *path);
153 * Initialize the checkout metadata with the given values. Any argument may be
154 * NULL if it is not applicable. The treeish should be a commit if that is
155 * available, and a tree otherwise.
157 * The refname is not copied and must be valid for the lifetime of the struct.
158 * THe object IDs are copied.
160 void init_checkout_metadata(struct checkout_metadata *meta, const char *refname,
161 const struct object_id *treeish,
162 const struct object_id *blob);
164 /* Copy the metadata from src to dst, updating the blob. */
165 void clone_checkout_metadata(struct checkout_metadata *dst,
166 const struct checkout_metadata *src,
167 const struct object_id *blob);
170 * Reset the internal list of attributes used by convert_to_git and
171 * convert_to_working_tree.
173 void reset_parsed_attributes(void);
175 /*****************************************************************
177 * Streaming conversion support
179 *****************************************************************/
181 struct stream_filter; /* opaque */
183 struct stream_filter *get_stream_filter(struct index_state *istate,
184 const char *path,
185 const struct object_id *);
186 struct stream_filter *get_stream_filter_ca(const struct conv_attrs *ca,
187 const struct object_id *oid);
188 void free_stream_filter(struct stream_filter *);
189 int is_null_stream_filter(struct stream_filter *);
192 * Use as much input up to *isize_p and fill output up to *osize_p;
193 * update isize_p and osize_p to indicate how much buffer space was
194 * consumed and filled. Return 0 on success, non-zero on error.
196 * Some filters may need to buffer the input and look-ahead inside it
197 * to decide what to output, and they may consume more than zero bytes
198 * of input and still not produce any output. After feeding all the
199 * input, pass NULL as input and keep calling this function, to let
200 * such filters know there is no more input coming and it is time for
201 * them to produce the remaining output based on the buffered input.
203 int stream_filter(struct stream_filter *,
204 const char *input, size_t *isize_p,
205 char *output, size_t *osize_p);
207 enum conv_attrs_classification {
209 * The blob must be loaded into a buffer before it can be
210 * smudged. All smudging is done in-proc.
212 CA_CLASS_INCORE,
215 * The blob must be loaded into a buffer, but uses a
216 * single-file driver filter, such as rot13.
218 CA_CLASS_INCORE_FILTER,
221 * The blob must be loaded into a buffer, but uses a
222 * long-running driver process, such as LFS. This might or
223 * might not use delayed operations. (The important thing is
224 * that there is a single subordinate long-running process
225 * handling all associated blobs and in case of delayed
226 * operations, may hold per-blob state.)
228 CA_CLASS_INCORE_PROCESS,
231 * The blob can be streamed and smudged without needing to
232 * completely read it into a buffer.
234 CA_CLASS_STREAMABLE,
237 enum conv_attrs_classification classify_conv_attrs(
238 const struct conv_attrs *ca);
240 #endif /* CONVERT_H */