]> git.ipfire.org Git - thirdparty/git.git/blame - convert.h
Merge branch 'ma/doc-fixes'
[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
ab90ecae 7#include "hash.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;
56 /* List of delayed blobs identified by their path. */
57 struct string_list paths;
58};
59
ab90ecae 60struct checkout_metadata {
61 const char *refname;
62 struct object_id treeish;
63 struct object_id blob;
64};
65
d1bf0e08 66extern enum eol core_eol;
e92d6225 67extern char *check_roundtrip_encoding;
546f70f3
NTND
68const 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);
7f944e26
NTND
71const char *get_convert_attr_ascii(const struct index_state *istate,
72 const char *path);
d1bf0e08
JH
73
74/* returns 1 if *dst was used */
546f70f3
NTND
75int 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);
7f944e26
NTND
78int convert_to_working_tree(const struct index_state *istate,
79 const char *path, const char *src,
ab90ecae 80 size_t len, struct strbuf *dst,
81 const struct checkout_metadata *meta);
7f944e26
NTND
82int async_convert_to_working_tree(const struct index_state *istate,
83 const char *path, const char *src,
546f70f3 84 size_t len, struct strbuf *dst,
ab90ecae 85 const struct checkout_metadata *meta,
546f70f3
NTND
86 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);
82b474e0
BW
92static inline int would_convert_to_git(const struct index_state *istate,
93 const char *path)
92ac3197 94{
82b474e0 95 return convert_to_git(istate, path, NULL, 0, NULL, 0);
92ac3197 96}
9035d75a 97/* Precondition: would_convert_to_git_filter_fd(path) == true */
546f70f3
NTND
98void convert_to_git_filter_fd(const struct index_state *istate,
99 const char *path, int fd,
100 struct strbuf *dst,
101 int conv_flags);
7f944e26
NTND
102int would_convert_to_git_filter_fd(const struct index_state *istate,
103 const char *path);
b6691092 104
c397aac0 105/*
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 */
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
2c65d90f 122/*
123 * Reset the internal list of attributes used by convert_to_git and
124 * convert_to_working_tree.
125 */
126void reset_parsed_attributes(void);
127
b6691092
JH
128/*****************************************************************
129 *
749f763d 130 * Streaming conversion support
b6691092
JH
131 *
132 *****************************************************************/
133
134struct stream_filter; /* opaque */
135
7f944e26
NTND
136struct stream_filter *get_stream_filter(const struct index_state *istate,
137 const char *path,
546f70f3
NTND
138 const struct object_id *);
139void free_stream_filter(struct stream_filter *);
140int is_null_stream_filter(struct stream_filter *);
b6691092
JH
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.
4ae66704
JH
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.
b6691092 153 */
546f70f3
NTND
154int stream_filter(struct stream_filter *,
155 const char *input, size_t *isize_p,
156 char *output, size_t *osize_p);
b6691092 157
d1bf0e08 158#endif /* CONVERT_H */