193
return core_eol;
194
}
195
196
-static void check_safe_crlf(const char *path, enum crlf_action crlf_action,
196
+static void check_global_conv_flags_eol(const char *path, enum crlf_action crlf_action,
197
struct text_stat *old_stats, struct text_stat *new_stats,
198
- enum safe_crlf checksafe)
198
+ int conv_flags)
199
{
200
if (old_stats->crlf && !new_stats->crlf ) {
201
/*
202
* CRLFs would not be restored by checkout
203
*/
204
- if (checksafe == SAFE_CRLF_WARN)
204
+ if (conv_flags & CONV_EOL_RNDTRP_DIE)
205
+ die(_("CRLF would be replaced by LF in %s."), path);
206
+ else if (conv_flags & CONV_EOL_RNDTRP_WARN)
207
warning(_("CRLF will be replaced by LF in %s.\n"
208
"The file will have its original line"
209
" endings in your working directory."), path);
208
- else /* i.e. SAFE_CRLF_FAIL */
209
- die(_("CRLF would be replaced by LF in %s."), path);
210
} else if (old_stats->lonelf && !new_stats->lonelf ) {
211
/*
212
* CRLFs would be added by checkout
213
*/
214
- if (checksafe == SAFE_CRLF_WARN)
214
+ if (conv_flags & CONV_EOL_RNDTRP_DIE)
215
+ die(_("LF would be replaced by CRLF in %s"), path);
216
+ else if (conv_flags & CONV_EOL_RNDTRP_WARN)
217
warning(_("LF will be replaced by CRLF in %s.\n"
218
"The file will have its original line"
219
" endings in your working directory."), path);
218
- else /* i.e. SAFE_CRLF_FAIL */
219
- die(_("LF would be replaced by CRLF in %s"), path);
220
}
221
}
222
268
static int crlf_to_git(const struct index_state *istate,
269
const char *path, const char *src, size_t len,
270
struct strbuf *buf,
271
- enum crlf_action crlf_action, enum safe_crlf checksafe)
271
+ enum crlf_action crlf_action, int conv_flags)
272
{
273
struct text_stat stats;
274
char *dst;
298
* unless we want to renormalize in a merge or
299
* cherry-pick.
300
*/
301
- if ((checksafe != SAFE_CRLF_RENORMALIZE) &&
301
+ if ((!(conv_flags & CONV_EOL_RENORMALIZE)) &&
302
has_crlf_in_index(istate, path))
303
convert_crlf_into_lf = 0;
304
}
305
- if ((checksafe == SAFE_CRLF_WARN ||
306
- (checksafe == SAFE_CRLF_FAIL)) && len) {
305
+ if (((conv_flags & CONV_EOL_RNDTRP_WARN) ||
306
+ ((conv_flags & CONV_EOL_RNDTRP_DIE) && len))) {
307
struct text_stat new_stats;
308
memcpy(&new_stats, &stats, sizeof(new_stats));
309
/* simulate "git add" */
316
new_stats.crlf += new_stats.lonelf;
317
new_stats.lonelf = 0;
318
}
319
- check_safe_crlf(path, crlf_action, &stats, &new_stats, checksafe);
319
+ check_global_conv_flags_eol(path, crlf_action, &stats, &new_stats, conv_flags);
320
}
321
if (!convert_crlf_into_lf)
322
return 0;
1129
1130
int convert_to_git(const struct index_state *istate,
1131
const char *path, const char *src, size_t len,
1132
- struct strbuf *dst, enum safe_crlf checksafe)
1132
+ struct strbuf *dst, int conv_flags)
1133
{
1134
int ret = 0;
1135
struct conv_attrs ca;
1144
src = dst->buf;
1145
len = dst->len;
1146
}
1147
- if (checksafe != SAFE_CRLF_KEEP_CRLF) {
1148
- ret |= crlf_to_git(istate, path, src, len, dst, ca.crlf_action, checksafe);
1147
+ if (!(conv_flags & CONV_EOL_KEEP_CRLF)) {
1148
+ ret |= crlf_to_git(istate, path, src, len, dst, ca.crlf_action, conv_flags);
1149
if (ret && dst) {
1150
src = dst->buf;
1151
len = dst->len;
1156
1157
void convert_to_git_filter_fd(const struct index_state *istate,
1158
const char *path, int fd, struct strbuf *dst,
1159
- enum safe_crlf checksafe)
1159
+ int conv_flags)
1160
{
1161
struct conv_attrs ca;
1162
convert_attrs(&ca, path);
1167
if (!apply_filter(path, NULL, 0, fd, dst, ca.drv, CAP_CLEAN, NULL))
1168
die("%s: clean filter '%s' failed", path, ca.drv->name);
1169
1170
- crlf_to_git(istate, path, dst->buf, dst->len, dst, ca.crlf_action, checksafe);
1170
+ crlf_to_git(istate, path, dst->buf, dst->len, dst, ca.crlf_action, conv_flags);
1171
ident_to_git(path, dst->buf, dst->len, dst, ca.ident);
1172
}
1173
1226
src = dst->buf;
1227
len = dst->len;
1228
}
1229
- return ret | convert_to_git(istate, path, src, len, dst, SAFE_CRLF_RENORMALIZE);
1229
+ return ret | convert_to_git(istate, path, src, len, dst, CONV_EOL_RENORMALIZE);
1230
}
1231
1232
/*****************************************************************