Coverage Report

Created: 2024-09-08 06:23

/src/git/convert.h
Line
Count
Source (jump to first uncovered line)
1
/*
2
 * Copyright (c) 2011, Google Inc.
3
 */
4
#ifndef CONVERT_H
5
#define CONVERT_H
6
7
#include "hash.h"
8
#include "string-list.h"
9
10
struct index_state;
11
struct strbuf;
12
13
0
#define CONV_EOL_RNDTRP_DIE   (1<<0) /* Die if CRLF to LF to CRLF is different */
14
0
#define CONV_EOL_RNDTRP_WARN  (1<<1) /* Warn if CRLF to LF to CRLF is different */
15
0
#define CONV_EOL_RENORMALIZE  (1<<2) /* Convert CRLF to LF */
16
0
#define CONV_EOL_KEEP_CRLF    (1<<3) /* Keep CRLF line endings as is */
17
0
#define CONV_WRITE_OBJECT     (1<<4) /* Content is written to the index */
18
19
extern int global_conv_flags_eol;
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
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
  /*
57
   * List of delayed blobs identified by their path. The `util` member
58
   * holds a counter pointer which must be incremented when/if the
59
   * associated blob gets checked out.
60
   */
61
  struct string_list paths;
62
};
63
64
struct checkout_metadata {
65
  const char *refname;
66
  struct object_id treeish;
67
  struct object_id blob;
68
};
69
70
enum convert_crlf_action {
71
  CRLF_UNDEFINED,
72
  CRLF_BINARY,
73
  CRLF_TEXT,
74
  CRLF_TEXT_INPUT,
75
  CRLF_TEXT_CRLF,
76
  CRLF_AUTO,
77
  CRLF_AUTO_INPUT,
78
  CRLF_AUTO_CRLF
79
};
80
81
struct convert_driver;
82
83
struct conv_attrs {
84
  struct convert_driver *drv;
85
  enum convert_crlf_action attr_action; /* What attr says */
86
  enum convert_crlf_action crlf_action; /* When no attr is set, use core.autocrlf */
87
  int ident;
88
  const char *working_tree_encoding; /* Supported encoding or default encoding if NULL */
89
};
90
91
void convert_attrs(struct index_state *istate,
92
       struct conv_attrs *ca, const char *path);
93
94
extern enum eol core_eol;
95
extern char *check_roundtrip_encoding;
96
const char *get_cached_convert_stats_ascii(struct index_state *istate,
97
             const char *path);
98
const char *get_wt_convert_stats_ascii(const char *path);
99
const char *get_convert_attr_ascii(struct index_state *istate,
100
           const char *path);
101
102
/* returns 1 if *dst was used */
103
int convert_to_git(struct index_state *istate,
104
       const char *path, const char *src, size_t len,
105
       struct strbuf *dst, int conv_flags);
106
int convert_to_working_tree_ca(const struct conv_attrs *ca,
107
             const char *path, const char *src,
108
             size_t len, struct strbuf *dst,
109
             const struct checkout_metadata *meta);
110
int async_convert_to_working_tree_ca(const struct conv_attrs *ca,
111
             const char *path, const char *src,
112
             size_t len, struct strbuf *dst,
113
             const struct checkout_metadata *meta,
114
             void *dco);
115
static inline int convert_to_working_tree(struct index_state *istate,
116
            const char *path, const char *src,
117
            size_t len, struct strbuf *dst,
118
            const struct checkout_metadata *meta)
119
0
{
120
0
  struct conv_attrs ca;
121
0
  convert_attrs(istate, &ca, path);
122
0
  return convert_to_working_tree_ca(&ca, path, src, len, dst, meta);
123
0
}
Unexecuted instantiation: am.c:convert_to_working_tree
Unexecuted instantiation: cat-file.c:convert_to_working_tree
Unexecuted instantiation: checkout--worker.c:convert_to_working_tree
Unexecuted instantiation: checkout-index.c:convert_to_working_tree
Unexecuted instantiation: checkout.c:convert_to_working_tree
Unexecuted instantiation: clone.c:convert_to_working_tree
Unexecuted instantiation: commit.c:convert_to_working_tree
Unexecuted instantiation: difftool.c:convert_to_working_tree
Unexecuted instantiation: ls-files.c:convert_to_working_tree
Unexecuted instantiation: merge.c:convert_to_working_tree
Unexecuted instantiation: mv.c:convert_to_working_tree
Unexecuted instantiation: read-tree.c:convert_to_working_tree
Unexecuted instantiation: rebase.c:convert_to_working_tree
Unexecuted instantiation: reset.c:convert_to_working_tree
Unexecuted instantiation: sparse-checkout.c:convert_to_working_tree
Unexecuted instantiation: stash.c:convert_to_working_tree
Unexecuted instantiation: apply.c:convert_to_working_tree
Unexecuted instantiation: archive.c:convert_to_working_tree
Unexecuted instantiation: blame.c:convert_to_working_tree
Unexecuted instantiation: combine-diff.c:convert_to_working_tree
Unexecuted instantiation: config.c:convert_to_working_tree
Unexecuted instantiation: convert.c:convert_to_working_tree
Unexecuted instantiation: diff-lib.c:convert_to_working_tree
Unexecuted instantiation: diff.c:convert_to_working_tree
Unexecuted instantiation: dir.c:convert_to_working_tree
Unexecuted instantiation: entry.c:convert_to_working_tree
Unexecuted instantiation: environment.c:convert_to_working_tree
Unexecuted instantiation: merge-ll.c:convert_to_working_tree
Unexecuted instantiation: merge-ort.c:convert_to_working_tree
Unexecuted instantiation: merge-recursive.c:convert_to_working_tree
Unexecuted instantiation: object-file.c:convert_to_working_tree
Unexecuted instantiation: parallel-checkout.c:convert_to_working_tree
Unexecuted instantiation: sequencer.c:convert_to_working_tree
Unexecuted instantiation: streaming.c:convert_to_working_tree
Unexecuted instantiation: unpack-trees.c:convert_to_working_tree
124
static inline int async_convert_to_working_tree(struct index_state *istate,
125
            const char *path, const char *src,
126
            size_t len, struct strbuf *dst,
127
            const struct checkout_metadata *meta,
128
            void *dco)
129
0
{
130
0
  struct conv_attrs ca;
131
0
  convert_attrs(istate, &ca, path);
132
0
  return async_convert_to_working_tree_ca(&ca, path, src, len, dst, meta, dco);
133
0
}
Unexecuted instantiation: am.c:async_convert_to_working_tree
Unexecuted instantiation: cat-file.c:async_convert_to_working_tree
Unexecuted instantiation: checkout--worker.c:async_convert_to_working_tree
Unexecuted instantiation: checkout-index.c:async_convert_to_working_tree
Unexecuted instantiation: checkout.c:async_convert_to_working_tree
Unexecuted instantiation: clone.c:async_convert_to_working_tree
Unexecuted instantiation: commit.c:async_convert_to_working_tree
Unexecuted instantiation: difftool.c:async_convert_to_working_tree
Unexecuted instantiation: ls-files.c:async_convert_to_working_tree
Unexecuted instantiation: merge.c:async_convert_to_working_tree
Unexecuted instantiation: mv.c:async_convert_to_working_tree
Unexecuted instantiation: read-tree.c:async_convert_to_working_tree
Unexecuted instantiation: rebase.c:async_convert_to_working_tree
Unexecuted instantiation: reset.c:async_convert_to_working_tree
Unexecuted instantiation: sparse-checkout.c:async_convert_to_working_tree
Unexecuted instantiation: stash.c:async_convert_to_working_tree
Unexecuted instantiation: apply.c:async_convert_to_working_tree
Unexecuted instantiation: archive.c:async_convert_to_working_tree
Unexecuted instantiation: blame.c:async_convert_to_working_tree
Unexecuted instantiation: combine-diff.c:async_convert_to_working_tree
Unexecuted instantiation: config.c:async_convert_to_working_tree
Unexecuted instantiation: convert.c:async_convert_to_working_tree
Unexecuted instantiation: diff-lib.c:async_convert_to_working_tree
Unexecuted instantiation: diff.c:async_convert_to_working_tree
Unexecuted instantiation: dir.c:async_convert_to_working_tree
Unexecuted instantiation: entry.c:async_convert_to_working_tree
Unexecuted instantiation: environment.c:async_convert_to_working_tree
Unexecuted instantiation: merge-ll.c:async_convert_to_working_tree
Unexecuted instantiation: merge-ort.c:async_convert_to_working_tree
Unexecuted instantiation: merge-recursive.c:async_convert_to_working_tree
Unexecuted instantiation: object-file.c:async_convert_to_working_tree
Unexecuted instantiation: parallel-checkout.c:async_convert_to_working_tree
Unexecuted instantiation: sequencer.c:async_convert_to_working_tree
Unexecuted instantiation: streaming.c:async_convert_to_working_tree
Unexecuted instantiation: unpack-trees.c:async_convert_to_working_tree
134
int async_query_available_blobs(const char *cmd,
135
        struct string_list *available_paths);
136
int renormalize_buffer(struct index_state *istate,
137
           const char *path, const char *src, size_t len,
138
           struct strbuf *dst);
139
static inline int would_convert_to_git(struct index_state *istate,
140
               const char *path)
141
0
{
142
0
  return convert_to_git(istate, path, NULL, 0, NULL, 0);
143
0
}
Unexecuted instantiation: am.c:would_convert_to_git
Unexecuted instantiation: cat-file.c:would_convert_to_git
Unexecuted instantiation: checkout--worker.c:would_convert_to_git
Unexecuted instantiation: checkout-index.c:would_convert_to_git
Unexecuted instantiation: checkout.c:would_convert_to_git
Unexecuted instantiation: clone.c:would_convert_to_git
Unexecuted instantiation: commit.c:would_convert_to_git
Unexecuted instantiation: difftool.c:would_convert_to_git
Unexecuted instantiation: ls-files.c:would_convert_to_git
Unexecuted instantiation: merge.c:would_convert_to_git
Unexecuted instantiation: mv.c:would_convert_to_git
Unexecuted instantiation: read-tree.c:would_convert_to_git
Unexecuted instantiation: rebase.c:would_convert_to_git
Unexecuted instantiation: reset.c:would_convert_to_git
Unexecuted instantiation: sparse-checkout.c:would_convert_to_git
Unexecuted instantiation: stash.c:would_convert_to_git
Unexecuted instantiation: apply.c:would_convert_to_git
Unexecuted instantiation: archive.c:would_convert_to_git
Unexecuted instantiation: blame.c:would_convert_to_git
Unexecuted instantiation: combine-diff.c:would_convert_to_git
Unexecuted instantiation: config.c:would_convert_to_git
Unexecuted instantiation: convert.c:would_convert_to_git
Unexecuted instantiation: diff-lib.c:would_convert_to_git
Unexecuted instantiation: diff.c:would_convert_to_git
Unexecuted instantiation: dir.c:would_convert_to_git
Unexecuted instantiation: entry.c:would_convert_to_git
Unexecuted instantiation: environment.c:would_convert_to_git
Unexecuted instantiation: merge-ll.c:would_convert_to_git
Unexecuted instantiation: merge-ort.c:would_convert_to_git
Unexecuted instantiation: merge-recursive.c:would_convert_to_git
Unexecuted instantiation: object-file.c:would_convert_to_git
Unexecuted instantiation: parallel-checkout.c:would_convert_to_git
Unexecuted instantiation: sequencer.c:would_convert_to_git
Unexecuted instantiation: streaming.c:would_convert_to_git
Unexecuted instantiation: unpack-trees.c:would_convert_to_git
144
/* Precondition: would_convert_to_git_filter_fd(path) == true */
145
void convert_to_git_filter_fd(struct index_state *istate,
146
            const char *path, int fd,
147
            struct strbuf *dst,
148
            int conv_flags);
149
int would_convert_to_git_filter_fd(struct index_state *istate,
150
           const char *path);
151
152
/*
153
 * Initialize the checkout metadata with the given values.  Any argument may be
154
 * NULL if it is not applicable.  The treeish should be a commit if that is
155
 * available, and a tree otherwise.
156
 *
157
 * The refname is not copied and must be valid for the lifetime of the struct.
158
 * THe object IDs are copied.
159
 */
160
void init_checkout_metadata(struct checkout_metadata *meta, const char *refname,
161
          const struct object_id *treeish,
162
          const struct object_id *blob);
163
164
/* Copy the metadata from src to dst, updating the blob. */
165
void clone_checkout_metadata(struct checkout_metadata *dst,
166
           const struct checkout_metadata *src,
167
           const struct object_id *blob);
168
169
/*
170
 * Reset the internal list of attributes used by convert_to_git and
171
 * convert_to_working_tree.
172
 */
173
void reset_parsed_attributes(void);
174
175
/*****************************************************************
176
 *
177
 * Streaming conversion support
178
 *
179
 *****************************************************************/
180
181
struct stream_filter; /* opaque */
182
183
struct stream_filter *get_stream_filter(struct index_state *istate,
184
          const char *path,
185
          const struct object_id *);
186
struct stream_filter *get_stream_filter_ca(const struct conv_attrs *ca,
187
             const struct object_id *oid);
188
void free_stream_filter(struct stream_filter *);
189
int is_null_stream_filter(struct stream_filter *);
190
191
/*
192
 * Use as much input up to *isize_p and fill output up to *osize_p;
193
 * update isize_p and osize_p to indicate how much buffer space was
194
 * consumed and filled. Return 0 on success, non-zero on error.
195
 *
196
 * Some filters may need to buffer the input and look-ahead inside it
197
 * to decide what to output, and they may consume more than zero bytes
198
 * of input and still not produce any output. After feeding all the
199
 * input, pass NULL as input and keep calling this function, to let
200
 * such filters know there is no more input coming and it is time for
201
 * them to produce the remaining output based on the buffered input.
202
 */
203
int stream_filter(struct stream_filter *,
204
      const char *input, size_t *isize_p,
205
      char *output, size_t *osize_p);
206
207
enum conv_attrs_classification {
208
  /*
209
   * The blob must be loaded into a buffer before it can be
210
   * smudged. All smudging is done in-proc.
211
   */
212
  CA_CLASS_INCORE,
213
214
  /*
215
   * The blob must be loaded into a buffer, but uses a
216
   * single-file driver filter, such as rot13.
217
   */
218
  CA_CLASS_INCORE_FILTER,
219
220
  /*
221
   * The blob must be loaded into a buffer, but uses a
222
   * long-running driver process, such as LFS. This might or
223
   * might not use delayed operations. (The important thing is
224
   * that there is a single subordinate long-running process
225
   * handling all associated blobs and in case of delayed
226
   * operations, may hold per-blob state.)
227
   */
228
  CA_CLASS_INCORE_PROCESS,
229
230
  /*
231
   * The blob can be streamed and smudged without needing to
232
   * completely read it into a buffer.
233
   */
234
  CA_CLASS_STREAMABLE,
235
};
236
237
enum conv_attrs_classification classify_conv_attrs(
238
  const struct conv_attrs *ca);
239
240
#endif /* CONVERT_H */