]> git.ipfire.org Git - thirdparty/git.git/blame - convert.h
Git 2.45-rc0
[thirdparty/git.git] / convert.h
CommitLineData
d1bf0e08
JH
1/*
2 * Copyright (c) 2011, Google Inc.
3 */
4#ifndef CONVERT_H
5#define CONVERT_H
6
d1cbe1e6 7#include "hash-ll.h"
2841e8f8
LS
8#include "string-list.h"
9
a7609c54 10struct index_state;
ef3ca954 11struct strbuf;
a7609c54 12
8462ff43
TB
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 */
107642fe 17#define CONV_WRITE_OBJECT (1<<4) /* Content is written to the index */
d1bf0e08 18
8462ff43 19extern int global_conv_flags_eol;
d1bf0e08
JH
20
21enum auto_crlf {
22 AUTO_CRLF_FALSE = 0,
23 AUTO_CRLF_TRUE = 1,
24 AUTO_CRLF_INPUT = -1
25};
26
27extern enum auto_crlf auto_crlf;
28
29enum 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
38};
39
2841e8f8
LS
40enum ce_delay_state {
41 CE_NO_DELAY = 0,
42 CE_CAN_DELAY = 1,
43 CE_RETRY = 2
44};
45
46struct delayed_checkout {
47 /*
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.
52 */
53 enum ce_delay_state state;
54 /* List of filter drivers that signaled delayed blobs. */
55 struct string_list filters;
611c7785
MT
56 /*
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.
60 */
2841e8f8
LS
61 struct string_list paths;
62};
63
ab90ecae 64struct checkout_metadata {
65 const char *refname;
66 struct object_id treeish;
67 struct object_id blob;
68};
69
38e95844
JH
70enum 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
79};
80
81struct convert_driver;
82
83struct 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 */
89};
90
8e978529 91void convert_attrs(struct index_state *istate,
38e95844
JH
92 struct conv_attrs *ca, const char *path);
93
d1bf0e08 94extern enum eol core_eol;
be6bc048 95extern const char *check_roundtrip_encoding;
847a9e5d 96const char *get_cached_convert_stats_ascii(struct index_state *istate,
546f70f3
NTND
97 const char *path);
98const char *get_wt_convert_stats_ascii(const char *path);
847a9e5d 99const char *get_convert_attr_ascii(struct index_state *istate,
7f944e26 100 const char *path);
d1bf0e08
JH
101
102/* returns 1 if *dst was used */
847a9e5d 103int convert_to_git(struct index_state *istate,
546f70f3
NTND
104 const char *path, const char *src, size_t len,
105 struct strbuf *dst, int conv_flags);
55b4ad0e
JH
106int 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);
110int 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);
8e978529 115static inline int convert_to_working_tree(struct index_state *istate,
55b4ad0e
JH
116 const char *path, const char *src,
117 size_t len, struct strbuf *dst,
118 const struct checkout_metadata *meta)
119{
120 struct conv_attrs ca;
121 convert_attrs(istate, &ca, path);
122 return convert_to_working_tree_ca(&ca, path, src, len, dst, meta);
123}
8e978529 124static inline int async_convert_to_working_tree(struct index_state *istate,
55b4ad0e
JH
125 const char *path, const char *src,
126 size_t len, struct strbuf *dst,
127 const struct checkout_metadata *meta,
128 void *dco)
129{
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);
133}
546f70f3
NTND
134int async_query_available_blobs(const char *cmd,
135 struct string_list *available_paths);
847a9e5d 136int renormalize_buffer(struct index_state *istate,
546f70f3
NTND
137 const char *path, const char *src, size_t len,
138 struct strbuf *dst);
847a9e5d 139static inline int would_convert_to_git(struct index_state *istate,
82b474e0 140 const char *path)
92ac3197 141{
82b474e0 142 return convert_to_git(istate, path, NULL, 0, NULL, 0);
92ac3197 143}
9035d75a 144/* Precondition: would_convert_to_git_filter_fd(path) == true */
847a9e5d 145void convert_to_git_filter_fd(struct index_state *istate,
546f70f3
NTND
146 const char *path, int fd,
147 struct strbuf *dst,
148 int conv_flags);
847a9e5d 149int would_convert_to_git_filter_fd(struct index_state *istate,
7f944e26 150 const char *path);
b6691092 151
c397aac0 152/*
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.
156 *
157 * The refname is not copied and must be valid for the lifetime of the struct.
158 * THe object IDs are copied.
159 */
160void init_checkout_metadata(struct checkout_metadata *meta, const char *refname,
161 const struct object_id *treeish,
162 const struct object_id *blob);
163
164/* Copy the metadata from src to dst, updating the blob. */
165void clone_checkout_metadata(struct checkout_metadata *dst,
166 const struct checkout_metadata *src,
167 const struct object_id *blob);
168
2c65d90f 169/*
170 * Reset the internal list of attributes used by convert_to_git and
171 * convert_to_working_tree.
172 */
173void reset_parsed_attributes(void);
174
b6691092
JH
175/*****************************************************************
176 *
749f763d 177 * Streaming conversion support
b6691092
JH
178 *
179 *****************************************************************/
180
181struct stream_filter; /* opaque */
182
847a9e5d 183struct stream_filter *get_stream_filter(struct index_state *istate,
7f944e26 184 const char *path,
546f70f3 185 const struct object_id *);
3e9e82c0
JH
186struct stream_filter *get_stream_filter_ca(const struct conv_attrs *ca,
187 const struct object_id *oid);
546f70f3
NTND
188void free_stream_filter(struct stream_filter *);
189int is_null_stream_filter(struct stream_filter *);
b6691092
JH
190
191/*
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.
4ae66704
JH
195 *
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.
b6691092 202 */
546f70f3
NTND
203int stream_filter(struct stream_filter *,
204 const char *input, size_t *isize_p,
205 char *output, size_t *osize_p);
b6691092 206
f59d15bb
JH
207enum conv_attrs_classification {
208 /*
209 * The blob must be loaded into a buffer before it can be
210 * smudged. All smudging is done in-proc.
211 */
212 CA_CLASS_INCORE,
213
214 /*
215 * The blob must be loaded into a buffer, but uses a
216 * single-file driver filter, such as rot13.
217 */
218 CA_CLASS_INCORE_FILTER,
219
220 /*
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.)
227 */
228 CA_CLASS_INCORE_PROCESS,
229
230 /*
231 * The blob can be streamed and smudged without needing to
232 * completely read it into a buffer.
233 */
234 CA_CLASS_STREAMABLE,
235};
236
237enum conv_attrs_classification classify_conv_attrs(
238 const struct conv_attrs *ca);
239
d1bf0e08 240#endif /* CONVERT_H */