mirror of
https://github.com/git/git.git
synced 2024-11-23 18:05:29 +08:00
convert: convert crlf_to_git to take an index
Signed-off-by: Brandon Williams <bmwill@google.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
This commit is contained in:
parent
a7609c54b3
commit
49a6d31fc8
14
convert.c
14
convert.c
@ -218,13 +218,13 @@ static void check_safe_crlf(const char *path, enum crlf_action crlf_action,
|
||||
}
|
||||
}
|
||||
|
||||
static int has_cr_in_index(const char *path)
|
||||
static int has_cr_in_index(const struct index_state *istate, const char *path)
|
||||
{
|
||||
unsigned long sz;
|
||||
void *data;
|
||||
int has_cr;
|
||||
|
||||
data = read_blob_data_from_cache(path, &sz);
|
||||
data = read_blob_data_from_index(istate, path, &sz);
|
||||
if (!data)
|
||||
return 0;
|
||||
has_cr = memchr(data, '\r', sz) != NULL;
|
||||
@ -254,7 +254,8 @@ static int will_convert_lf_to_crlf(size_t len, struct text_stat *stats,
|
||||
|
||||
}
|
||||
|
||||
static int crlf_to_git(const char *path, const char *src, size_t len,
|
||||
static int crlf_to_git(const struct index_state *istate,
|
||||
const char *path, const char *src, size_t len,
|
||||
struct strbuf *buf,
|
||||
enum crlf_action crlf_action, enum safe_crlf checksafe)
|
||||
{
|
||||
@ -286,7 +287,8 @@ static int crlf_to_git(const char *path, const char *src, size_t len,
|
||||
* unless we want to renormalize in a merge or
|
||||
* cherry-pick.
|
||||
*/
|
||||
if ((checksafe != SAFE_CRLF_RENORMALIZE) && has_cr_in_index(path))
|
||||
if ((checksafe != SAFE_CRLF_RENORMALIZE) &&
|
||||
has_cr_in_index(istate, path))
|
||||
convert_crlf_into_lf = 0;
|
||||
}
|
||||
if ((checksafe == SAFE_CRLF_WARN ||
|
||||
@ -1098,7 +1100,7 @@ int convert_to_git(const char *path, const char *src, size_t len,
|
||||
src = dst->buf;
|
||||
len = dst->len;
|
||||
}
|
||||
ret |= crlf_to_git(path, src, len, dst, ca.crlf_action, checksafe);
|
||||
ret |= crlf_to_git(&the_index, path, src, len, dst, ca.crlf_action, checksafe);
|
||||
if (ret && dst) {
|
||||
src = dst->buf;
|
||||
len = dst->len;
|
||||
@ -1118,7 +1120,7 @@ void convert_to_git_filter_fd(const char *path, int fd, struct strbuf *dst,
|
||||
if (!apply_filter(path, NULL, 0, fd, dst, ca.drv, CAP_CLEAN))
|
||||
die("%s: clean filter '%s' failed", path, ca.drv->name);
|
||||
|
||||
crlf_to_git(path, dst->buf, dst->len, dst, ca.crlf_action, checksafe);
|
||||
crlf_to_git(&the_index, path, dst->buf, dst->len, dst, ca.crlf_action, checksafe);
|
||||
ident_to_git(path, dst->buf, dst->len, dst, ca.ident);
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user