Junio C Hamano | d1bf0e0 | 2011-05-20 12:59:01 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (c) 2011, Google Inc. |
| 3 | */ |
| 4 | #ifndef CONVERT_H |
| 5 | #define CONVERT_H |
| 6 | |
brian m. carlson | ab90eca | 2020-03-16 18:05:02 +0000 | [diff] [blame] | 7 | #include "hash.h" |
Lars Schneider | 2841e8f | 2017-06-30 22:41:28 +0200 | [diff] [blame] | 8 | #include "string-list.h" |
| 9 | |
Brandon Williams | a7609c5 | 2017-06-12 15:13:52 -0700 | [diff] [blame] | 10 | struct index_state; |
Elijah Newren | ef3ca95 | 2018-08-15 10:54:05 -0700 | [diff] [blame] | 11 | struct strbuf; |
Brandon Williams | a7609c5 | 2017-06-12 15:13:52 -0700 | [diff] [blame] | 12 | |
Torsten Bögershausen | 8462ff4 | 2018-01-13 23:49:31 +0100 | [diff] [blame] | 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 */ |
Lars Schneider | 107642f | 2018-04-15 20:16:07 +0200 | [diff] [blame] | 17 | #define CONV_WRITE_OBJECT (1<<4) /* Content is written to the index */ |
Junio C Hamano | d1bf0e0 | 2011-05-20 12:59:01 -0700 | [diff] [blame] | 18 | |
Torsten Bögershausen | 8462ff4 | 2018-01-13 23:49:31 +0100 | [diff] [blame] | 19 | extern int global_conv_flags_eol; |
Junio C Hamano | d1bf0e0 | 2011-05-20 12:59:01 -0700 | [diff] [blame] | 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 | |
Lars Schneider | 2841e8f | 2017-06-30 22:41:28 +0200 | [diff] [blame] | 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 | |
brian m. carlson | ab90eca | 2020-03-16 18:05:02 +0000 | [diff] [blame] | 60 | struct checkout_metadata { |
| 61 | const char *refname; |
| 62 | struct object_id treeish; |
| 63 | struct object_id blob; |
| 64 | }; |
| 65 | |
Junio C Hamano | d1bf0e0 | 2011-05-20 12:59:01 -0700 | [diff] [blame] | 66 | extern enum eol core_eol; |
Lars Schneider | e92d622 | 2018-04-15 20:16:10 +0200 | [diff] [blame] | 67 | extern char *check_roundtrip_encoding; |
Nguyễn Thái Ngọc Duy | 546f70f | 2018-06-30 11:20:24 +0200 | [diff] [blame] | 68 | const char *get_cached_convert_stats_ascii(const struct index_state *istate, |
| 69 | const char *path); |
| 70 | const char *get_wt_convert_stats_ascii(const char *path); |
Nguyễn Thái Ngọc Duy | 7f944e2 | 2018-08-13 18:14:21 +0200 | [diff] [blame] | 71 | const char *get_convert_attr_ascii(const struct index_state *istate, |
| 72 | const char *path); |
Junio C Hamano | d1bf0e0 | 2011-05-20 12:59:01 -0700 | [diff] [blame] | 73 | |
| 74 | /* returns 1 if *dst was used */ |
Nguyễn Thái Ngọc Duy | 546f70f | 2018-06-30 11:20:24 +0200 | [diff] [blame] | 75 | int convert_to_git(const struct index_state *istate, |
| 76 | const char *path, const char *src, size_t len, |
| 77 | struct strbuf *dst, int conv_flags); |
Nguyễn Thái Ngọc Duy | 7f944e2 | 2018-08-13 18:14:21 +0200 | [diff] [blame] | 78 | int convert_to_working_tree(const struct index_state *istate, |
| 79 | const char *path, const char *src, |
brian m. carlson | ab90eca | 2020-03-16 18:05:02 +0000 | [diff] [blame] | 80 | size_t len, struct strbuf *dst, |
| 81 | const struct checkout_metadata *meta); |
Nguyễn Thái Ngọc Duy | 7f944e2 | 2018-08-13 18:14:21 +0200 | [diff] [blame] | 82 | int async_convert_to_working_tree(const struct index_state *istate, |
| 83 | const char *path, const char *src, |
Nguyễn Thái Ngọc Duy | 546f70f | 2018-06-30 11:20:24 +0200 | [diff] [blame] | 84 | size_t len, struct strbuf *dst, |
brian m. carlson | ab90eca | 2020-03-16 18:05:02 +0000 | [diff] [blame] | 85 | const struct checkout_metadata *meta, |
Nguyễn Thái Ngọc Duy | 546f70f | 2018-06-30 11:20:24 +0200 | [diff] [blame] | 86 | void *dco); |
| 87 | int async_query_available_blobs(const char *cmd, |
| 88 | struct string_list *available_paths); |
| 89 | int renormalize_buffer(const struct index_state *istate, |
| 90 | const char *path, const char *src, size_t len, |
| 91 | struct strbuf *dst); |
Brandon Williams | 82b474e | 2017-06-12 15:13:55 -0700 | [diff] [blame] | 92 | static inline int would_convert_to_git(const struct index_state *istate, |
| 93 | const char *path) |
Jeff King | 92ac319 | 2012-02-24 17:02:37 -0500 | [diff] [blame] | 94 | { |
Brandon Williams | 82b474e | 2017-06-12 15:13:55 -0700 | [diff] [blame] | 95 | return convert_to_git(istate, path, NULL, 0, NULL, 0); |
Jeff King | 92ac319 | 2012-02-24 17:02:37 -0500 | [diff] [blame] | 96 | } |
Steffen Prohaska | 9035d75 | 2014-08-26 17:23:25 +0200 | [diff] [blame] | 97 | /* Precondition: would_convert_to_git_filter_fd(path) == true */ |
Nguyễn Thái Ngọc Duy | 546f70f | 2018-06-30 11:20:24 +0200 | [diff] [blame] | 98 | void convert_to_git_filter_fd(const struct index_state *istate, |
| 99 | const char *path, int fd, |
| 100 | struct strbuf *dst, |
| 101 | int conv_flags); |
Nguyễn Thái Ngọc Duy | 7f944e2 | 2018-08-13 18:14:21 +0200 | [diff] [blame] | 102 | int would_convert_to_git_filter_fd(const struct index_state *istate, |
| 103 | const char *path); |
Junio C Hamano | b669109 | 2011-05-20 14:33:31 -0700 | [diff] [blame] | 104 | |
brian m. carlson | 2c65d90 | 2019-09-02 22:39:44 +0000 | [diff] [blame] | 105 | /* |
brian m. carlson | c397aac | 2020-03-16 18:05:03 +0000 | [diff] [blame] | 106 | * Initialize the checkout metadata with the given values. Any argument may be |
| 107 | * NULL if it is not applicable. The treeish should be a commit if that is |
| 108 | * available, and a tree otherwise. |
| 109 | * |
| 110 | * The refname is not copied and must be valid for the lifetime of the struct. |
| 111 | * THe object IDs are copied. |
| 112 | */ |
| 113 | void init_checkout_metadata(struct checkout_metadata *meta, const char *refname, |
| 114 | const struct object_id *treeish, |
| 115 | const struct object_id *blob); |
| 116 | |
| 117 | /* Copy the metadata from src to dst, updating the blob. */ |
| 118 | void clone_checkout_metadata(struct checkout_metadata *dst, |
| 119 | const struct checkout_metadata *src, |
| 120 | const struct object_id *blob); |
| 121 | |
| 122 | /* |
brian m. carlson | 2c65d90 | 2019-09-02 22:39:44 +0000 | [diff] [blame] | 123 | * Reset the internal list of attributes used by convert_to_git and |
| 124 | * convert_to_working_tree. |
| 125 | */ |
| 126 | void reset_parsed_attributes(void); |
| 127 | |
Junio C Hamano | b669109 | 2011-05-20 14:33:31 -0700 | [diff] [blame] | 128 | /***************************************************************** |
| 129 | * |
Ondřej Bílka | 749f763 | 2013-07-22 23:02:23 +0200 | [diff] [blame] | 130 | * Streaming conversion support |
Junio C Hamano | b669109 | 2011-05-20 14:33:31 -0700 | [diff] [blame] | 131 | * |
| 132 | *****************************************************************/ |
| 133 | |
| 134 | struct stream_filter; /* opaque */ |
| 135 | |
Nguyễn Thái Ngọc Duy | 7f944e2 | 2018-08-13 18:14:21 +0200 | [diff] [blame] | 136 | struct stream_filter *get_stream_filter(const struct index_state *istate, |
| 137 | const char *path, |
Nguyễn Thái Ngọc Duy | 546f70f | 2018-06-30 11:20:24 +0200 | [diff] [blame] | 138 | const struct object_id *); |
| 139 | void free_stream_filter(struct stream_filter *); |
| 140 | int is_null_stream_filter(struct stream_filter *); |
Junio C Hamano | b669109 | 2011-05-20 14:33:31 -0700 | [diff] [blame] | 141 | |
| 142 | /* |
| 143 | * Use as much input up to *isize_p and fill output up to *osize_p; |
| 144 | * update isize_p and osize_p to indicate how much buffer space was |
| 145 | * consumed and filled. Return 0 on success, non-zero on error. |
Junio C Hamano | 4ae6670 | 2011-05-21 14:05:51 -0700 | [diff] [blame] | 146 | * |
| 147 | * Some filters may need to buffer the input and look-ahead inside it |
| 148 | * to decide what to output, and they may consume more than zero bytes |
| 149 | * of input and still not produce any output. After feeding all the |
| 150 | * input, pass NULL as input and keep calling this function, to let |
| 151 | * such filters know there is no more input coming and it is time for |
| 152 | * them to produce the remaining output based on the buffered input. |
Junio C Hamano | b669109 | 2011-05-20 14:33:31 -0700 | [diff] [blame] | 153 | */ |
Nguyễn Thái Ngọc Duy | 546f70f | 2018-06-30 11:20:24 +0200 | [diff] [blame] | 154 | int stream_filter(struct stream_filter *, |
| 155 | const char *input, size_t *isize_p, |
| 156 | char *output, size_t *osize_p); |
Junio C Hamano | b669109 | 2011-05-20 14:33:31 -0700 | [diff] [blame] | 157 | |
Junio C Hamano | d1bf0e0 | 2011-05-20 12:59:01 -0700 | [diff] [blame] | 158 | #endif /* CONVERT_H */ |