]>
Commit | Line | Data |
---|---|---|
d1bf0e08 JH |
1 | /* |
2 | * Copyright (c) 2011, Google Inc. | |
3 | */ | |
4 | #ifndef CONVERT_H | |
5 | #define CONVERT_H | |
6 | ||
ab90ecae | 7 | #include "hash.h" |
2841e8f8 LS |
8 | #include "string-list.h" |
9 | ||
a7609c54 | 10 | struct index_state; |
ef3ca954 | 11 | struct 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 | 19 | extern int global_conv_flags_eol; |
d1bf0e08 JH |
20 | |
21 | enum auto_crlf { | |
22 | AUTO_CRLF_FALSE = 0, | |
23 | AUTO_CRLF_TRUE = 1, | |
24 | AUTO_CRLF_INPUT = -1 | |
25 | }; | |
26 | ||
27 | extern enum auto_crlf auto_crlf; | |
28 | ||
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 | |
38 | }; | |
39 | ||
2841e8f8 LS |
40 | enum ce_delay_state { |
41 | CE_NO_DELAY = 0, | |
42 | CE_CAN_DELAY = 1, | |
43 | CE_RETRY = 2 | |
44 | }; | |
45 | ||
46 | struct 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; | |
56 | /* List of delayed blobs identified by their path. */ | |
57 | struct string_list paths; | |
58 | }; | |
59 | ||
ab90ecae | 60 | struct checkout_metadata { |
61 | const char *refname; | |
62 | struct object_id treeish; | |
63 | struct object_id blob; | |
64 | }; | |
65 | ||
38e95844 JH |
66 | enum convert_crlf_action { |
67 | CRLF_UNDEFINED, | |
68 | CRLF_BINARY, | |
69 | CRLF_TEXT, | |
70 | CRLF_TEXT_INPUT, | |
71 | CRLF_TEXT_CRLF, | |
72 | CRLF_AUTO, | |
73 | CRLF_AUTO_INPUT, | |
74 | CRLF_AUTO_CRLF | |
75 | }; | |
76 | ||
77 | struct convert_driver; | |
78 | ||
79 | struct conv_attrs { | |
80 | struct convert_driver *drv; | |
81 | enum convert_crlf_action attr_action; /* What attr says */ | |
82 | enum convert_crlf_action crlf_action; /* When no attr is set, use core.autocrlf */ | |
83 | int ident; | |
84 | const char *working_tree_encoding; /* Supported encoding or default encoding if NULL */ | |
85 | }; | |
86 | ||
87 | void convert_attrs(const struct index_state *istate, | |
88 | struct conv_attrs *ca, const char *path); | |
89 | ||
d1bf0e08 | 90 | extern enum eol core_eol; |
e92d6225 | 91 | extern char *check_roundtrip_encoding; |
546f70f3 NTND |
92 | const char *get_cached_convert_stats_ascii(const struct index_state *istate, |
93 | const char *path); | |
94 | const char *get_wt_convert_stats_ascii(const char *path); | |
7f944e26 NTND |
95 | const char *get_convert_attr_ascii(const struct index_state *istate, |
96 | const char *path); | |
d1bf0e08 JH |
97 | |
98 | /* returns 1 if *dst was used */ | |
546f70f3 NTND |
99 | int convert_to_git(const struct index_state *istate, |
100 | const char *path, const char *src, size_t len, | |
101 | struct strbuf *dst, int conv_flags); | |
7f944e26 NTND |
102 | int convert_to_working_tree(const struct index_state *istate, |
103 | const char *path, const char *src, | |
ab90ecae | 104 | size_t len, struct strbuf *dst, |
105 | const struct checkout_metadata *meta); | |
7f944e26 NTND |
106 | int async_convert_to_working_tree(const struct index_state *istate, |
107 | const char *path, const char *src, | |
546f70f3 | 108 | size_t len, struct strbuf *dst, |
ab90ecae | 109 | const struct checkout_metadata *meta, |
546f70f3 NTND |
110 | void *dco); |
111 | int async_query_available_blobs(const char *cmd, | |
112 | struct string_list *available_paths); | |
113 | int renormalize_buffer(const struct index_state *istate, | |
114 | const char *path, const char *src, size_t len, | |
115 | struct strbuf *dst); | |
82b474e0 BW |
116 | static inline int would_convert_to_git(const struct index_state *istate, |
117 | const char *path) | |
92ac3197 | 118 | { |
82b474e0 | 119 | return convert_to_git(istate, path, NULL, 0, NULL, 0); |
92ac3197 | 120 | } |
9035d75a | 121 | /* Precondition: would_convert_to_git_filter_fd(path) == true */ |
546f70f3 NTND |
122 | void convert_to_git_filter_fd(const struct index_state *istate, |
123 | const char *path, int fd, | |
124 | struct strbuf *dst, | |
125 | int conv_flags); | |
7f944e26 NTND |
126 | int would_convert_to_git_filter_fd(const struct index_state *istate, |
127 | const char *path); | |
b6691092 | 128 | |
c397aac0 | 129 | /* |
130 | * Initialize the checkout metadata with the given values. Any argument may be | |
131 | * NULL if it is not applicable. The treeish should be a commit if that is | |
132 | * available, and a tree otherwise. | |
133 | * | |
134 | * The refname is not copied and must be valid for the lifetime of the struct. | |
135 | * THe object IDs are copied. | |
136 | */ | |
137 | void init_checkout_metadata(struct checkout_metadata *meta, const char *refname, | |
138 | const struct object_id *treeish, | |
139 | const struct object_id *blob); | |
140 | ||
141 | /* Copy the metadata from src to dst, updating the blob. */ | |
142 | void clone_checkout_metadata(struct checkout_metadata *dst, | |
143 | const struct checkout_metadata *src, | |
144 | const struct object_id *blob); | |
145 | ||
2c65d90f | 146 | /* |
147 | * Reset the internal list of attributes used by convert_to_git and | |
148 | * convert_to_working_tree. | |
149 | */ | |
150 | void reset_parsed_attributes(void); | |
151 | ||
b6691092 JH |
152 | /***************************************************************** |
153 | * | |
749f763d | 154 | * Streaming conversion support |
b6691092 JH |
155 | * |
156 | *****************************************************************/ | |
157 | ||
158 | struct stream_filter; /* opaque */ | |
159 | ||
7f944e26 NTND |
160 | struct stream_filter *get_stream_filter(const struct index_state *istate, |
161 | const char *path, | |
546f70f3 NTND |
162 | const struct object_id *); |
163 | void free_stream_filter(struct stream_filter *); | |
164 | int is_null_stream_filter(struct stream_filter *); | |
b6691092 JH |
165 | |
166 | /* | |
167 | * Use as much input up to *isize_p and fill output up to *osize_p; | |
168 | * update isize_p and osize_p to indicate how much buffer space was | |
169 | * consumed and filled. Return 0 on success, non-zero on error. | |
4ae66704 JH |
170 | * |
171 | * Some filters may need to buffer the input and look-ahead inside it | |
172 | * to decide what to output, and they may consume more than zero bytes | |
173 | * of input and still not produce any output. After feeding all the | |
174 | * input, pass NULL as input and keep calling this function, to let | |
175 | * such filters know there is no more input coming and it is time for | |
176 | * them to produce the remaining output based on the buffered input. | |
b6691092 | 177 | */ |
546f70f3 NTND |
178 | int stream_filter(struct stream_filter *, |
179 | const char *input, size_t *isize_p, | |
180 | char *output, size_t *osize_p); | |
b6691092 | 181 | |
d1bf0e08 | 182 | #endif /* CONVERT_H */ |