blob: e29d1026a6866b63b047b6838727bcb71ea6eccb [file] [log] [blame]
Junio C Hamanod1bf0e02011-05-20 12:59:01 -07001/*
2 * Copyright (c) 2011, Google Inc.
3 */
4#ifndef CONVERT_H
5#define CONVERT_H
6
brian m. carlsonab90eca2020-03-16 18:05:02 +00007#include "hash.h"
Lars Schneider2841e8f2017-06-30 22:41:28 +02008#include "string-list.h"
9
Brandon Williamsa7609c52017-06-12 15:13:52 -070010struct index_state;
Elijah Newrenef3ca952018-08-15 10:54:05 -070011struct strbuf;
Brandon Williamsa7609c52017-06-12 15:13:52 -070012
Torsten Bögershausen8462ff42018-01-13 23:49:31 +010013#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 Schneider107642f2018-04-15 20:16:07 +020017#define CONV_WRITE_OBJECT (1<<4) /* Content is written to the index */
Junio C Hamanod1bf0e02011-05-20 12:59:01 -070018
Torsten Bögershausen8462ff42018-01-13 23:49:31 +010019extern int global_conv_flags_eol;
Junio C Hamanod1bf0e02011-05-20 12:59:01 -070020
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
Lars Schneider2841e8f2017-06-30 22:41:28 +020040enum 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;
56 /* List of delayed blobs identified by their path. */
57 struct string_list paths;
58};
59
brian m. carlsonab90eca2020-03-16 18:05:02 +000060struct checkout_metadata {
61 const char *refname;
62 struct object_id treeish;
63 struct object_id blob;
64};
65
Junio C Hamanod1bf0e02011-05-20 12:59:01 -070066extern enum eol core_eol;
Lars Schneidere92d6222018-04-15 20:16:10 +020067extern char *check_roundtrip_encoding;
Nguyễn Thái Ngọc Duy546f70f2018-06-30 11:20:24 +020068const char *get_cached_convert_stats_ascii(const struct index_state *istate,
69 const char *path);
70const char *get_wt_convert_stats_ascii(const char *path);
Nguyễn Thái Ngọc Duy7f944e22018-08-13 18:14:21 +020071const char *get_convert_attr_ascii(const struct index_state *istate,
72 const char *path);
Junio C Hamanod1bf0e02011-05-20 12:59:01 -070073
74/* returns 1 if *dst was used */
Nguyễn Thái Ngọc Duy546f70f2018-06-30 11:20:24 +020075int 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 Duy7f944e22018-08-13 18:14:21 +020078int convert_to_working_tree(const struct index_state *istate,
79 const char *path, const char *src,
brian m. carlsonab90eca2020-03-16 18:05:02 +000080 size_t len, struct strbuf *dst,
81 const struct checkout_metadata *meta);
Nguyễn Thái Ngọc Duy7f944e22018-08-13 18:14:21 +020082int async_convert_to_working_tree(const struct index_state *istate,
83 const char *path, const char *src,
Nguyễn Thái Ngọc Duy546f70f2018-06-30 11:20:24 +020084 size_t len, struct strbuf *dst,
brian m. carlsonab90eca2020-03-16 18:05:02 +000085 const struct checkout_metadata *meta,
Nguyễn Thái Ngọc Duy546f70f2018-06-30 11:20:24 +020086 void *dco);
87int async_query_available_blobs(const char *cmd,
88 struct string_list *available_paths);
89int renormalize_buffer(const struct index_state *istate,
90 const char *path, const char *src, size_t len,
91 struct strbuf *dst);
Brandon Williams82b474e2017-06-12 15:13:55 -070092static inline int would_convert_to_git(const struct index_state *istate,
93 const char *path)
Jeff King92ac3192012-02-24 17:02:37 -050094{
Brandon Williams82b474e2017-06-12 15:13:55 -070095 return convert_to_git(istate, path, NULL, 0, NULL, 0);
Jeff King92ac3192012-02-24 17:02:37 -050096}
Steffen Prohaska9035d752014-08-26 17:23:25 +020097/* Precondition: would_convert_to_git_filter_fd(path) == true */
Nguyễn Thái Ngọc Duy546f70f2018-06-30 11:20:24 +020098void 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 Duy7f944e22018-08-13 18:14:21 +0200102int would_convert_to_git_filter_fd(const struct index_state *istate,
103 const char *path);
Junio C Hamanob6691092011-05-20 14:33:31 -0700104
brian m. carlson2c65d902019-09-02 22:39:44 +0000105/*
brian m. carlsonc397aac2020-03-16 18:05:03 +0000106 * 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 */
113void 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. */
118void clone_checkout_metadata(struct checkout_metadata *dst,
119 const struct checkout_metadata *src,
120 const struct object_id *blob);
121
122/*
brian m. carlson2c65d902019-09-02 22:39:44 +0000123 * Reset the internal list of attributes used by convert_to_git and
124 * convert_to_working_tree.
125 */
126void reset_parsed_attributes(void);
127
Junio C Hamanob6691092011-05-20 14:33:31 -0700128/*****************************************************************
129 *
Ondřej Bílka749f7632013-07-22 23:02:23 +0200130 * Streaming conversion support
Junio C Hamanob6691092011-05-20 14:33:31 -0700131 *
132 *****************************************************************/
133
134struct stream_filter; /* opaque */
135
Nguyễn Thái Ngọc Duy7f944e22018-08-13 18:14:21 +0200136struct stream_filter *get_stream_filter(const struct index_state *istate,
137 const char *path,
Nguyễn Thái Ngọc Duy546f70f2018-06-30 11:20:24 +0200138 const struct object_id *);
139void free_stream_filter(struct stream_filter *);
140int is_null_stream_filter(struct stream_filter *);
Junio C Hamanob6691092011-05-20 14:33:31 -0700141
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 Hamano4ae66702011-05-21 14:05:51 -0700146 *
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 Hamanob6691092011-05-20 14:33:31 -0700153 */
Nguyễn Thái Ngọc Duy546f70f2018-06-30 11:20:24 +0200154int stream_filter(struct stream_filter *,
155 const char *input, size_t *isize_p,
156 char *output, size_t *osize_p);
Junio C Hamanob6691092011-05-20 14:33:31 -0700157
Junio C Hamanod1bf0e02011-05-20 12:59:01 -0700158#endif /* CONVERT_H */