OSDN Git Service

convert: add SAFE_CRLF_KEEP_CRLF
[git-core/git.git] / convert.h
1 /*
2  * Copyright (c) 2011, Google Inc.
3  */
4 #ifndef CONVERT_H
5 #define CONVERT_H
6
7 struct index_state;
8
9 enum safe_crlf {
10         SAFE_CRLF_FALSE = 0,
11         SAFE_CRLF_FAIL = 1,
12         SAFE_CRLF_WARN = 2,
13         SAFE_CRLF_RENORMALIZE = 3,
14         SAFE_CRLF_KEEP_CRLF = 4
15 };
16
17 extern enum safe_crlf safe_crlf;
18
19 enum auto_crlf {
20         AUTO_CRLF_FALSE = 0,
21         AUTO_CRLF_TRUE = 1,
22         AUTO_CRLF_INPUT = -1
23 };
24
25 extern enum auto_crlf auto_crlf;
26
27 enum eol {
28         EOL_UNSET,
29         EOL_CRLF,
30         EOL_LF,
31 #ifdef NATIVE_CRLF
32         EOL_NATIVE = EOL_CRLF
33 #else
34         EOL_NATIVE = EOL_LF
35 #endif
36 };
37
38 extern enum eol core_eol;
39 extern const char *get_cached_convert_stats_ascii(const struct index_state *istate,
40                                                   const char *path);
41 extern const char *get_wt_convert_stats_ascii(const char *path);
42 extern const char *get_convert_attr_ascii(const char *path);
43
44 /* returns 1 if *dst was used */
45 extern int convert_to_git(const struct index_state *istate,
46                           const char *path, const char *src, size_t len,
47                           struct strbuf *dst, enum safe_crlf checksafe);
48 extern int convert_to_working_tree(const char *path, const char *src,
49                                    size_t len, struct strbuf *dst);
50 extern int renormalize_buffer(const struct index_state *istate,
51                               const char *path, const char *src, size_t len,
52                               struct strbuf *dst);
53 static inline int would_convert_to_git(const struct index_state *istate,
54                                        const char *path)
55 {
56         return convert_to_git(istate, path, NULL, 0, NULL, 0);
57 }
58 /* Precondition: would_convert_to_git_filter_fd(path) == true */
59 extern void convert_to_git_filter_fd(const struct index_state *istate,
60                                      const char *path, int fd,
61                                      struct strbuf *dst,
62                                      enum safe_crlf checksafe);
63 extern int would_convert_to_git_filter_fd(const char *path);
64
65 /*****************************************************************
66  *
67  * Streaming conversion support
68  *
69  *****************************************************************/
70
71 struct stream_filter; /* opaque */
72
73 extern struct stream_filter *get_stream_filter(const char *path, const unsigned char *);
74 extern void free_stream_filter(struct stream_filter *);
75 extern int is_null_stream_filter(struct stream_filter *);
76
77 /*
78  * Use as much input up to *isize_p and fill output up to *osize_p;
79  * update isize_p and osize_p to indicate how much buffer space was
80  * consumed and filled. Return 0 on success, non-zero on error.
81  *
82  * Some filters may need to buffer the input and look-ahead inside it
83  * to decide what to output, and they may consume more than zero bytes
84  * of input and still not produce any output. After feeding all the
85  * input, pass NULL as input and keep calling this function, to let
86  * such filters know there is no more input coming and it is time for
87  * them to produce the remaining output based on the buffered input.
88  */
89 extern int stream_filter(struct stream_filter *,
90                          const char *input, size_t *isize_p,
91                          char *output, size_t *osize_p);
92
93 #endif /* CONVERT_H */