convert: convert convert_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:
Brandon Williams 2017-06-12 15:13:55 -07:00 committed by Junio C Hamano
parent d6c41c20e6
commit 82b474e025
8 changed files with 18 additions and 15 deletions

View File

@ -2267,7 +2267,7 @@ static int read_old_data(struct stat *st, const char *path, struct strbuf *buf)
case S_IFREG: case S_IFREG:
if (strbuf_read_file(buf, path, st->st_size) != st->st_size) if (strbuf_read_file(buf, path, st->st_size) != st->st_size)
return error(_("unable to open or read %s"), path); return error(_("unable to open or read %s"), path);
convert_to_git(path, buf->buf, buf->len, buf, 0); convert_to_git(&the_index, path, buf->buf, buf->len, buf, 0);
return 0; return 0;
default: default:
return -1; return -1;

View File

@ -229,7 +229,7 @@ static struct commit *fake_working_tree_commit(struct diff_options *opt,
if (strbuf_read(&buf, 0, 0) < 0) if (strbuf_read(&buf, 0, 0) < 0)
die_errno("failed to read from stdin"); die_errno("failed to read from stdin");
} }
convert_to_git(path, buf.buf, buf.len, &buf, 0); convert_to_git(&the_index, path, buf.buf, buf.len, &buf, 0);
origin->file.ptr = buf.buf; origin->file.ptr = buf.buf;
origin->file.size = buf.len; origin->file.size = buf.len;
pretend_sha1_file(buf.buf, buf.len, OBJ_BLOB, origin->blob_oid.hash); pretend_sha1_file(buf.buf, buf.len, OBJ_BLOB, origin->blob_oid.hash);

View File

@ -1053,7 +1053,7 @@ static void show_patch_diff(struct combine_diff_path *elem, int num_parent,
if (is_file) { if (is_file) {
struct strbuf buf = STRBUF_INIT; struct strbuf buf = STRBUF_INIT;
if (convert_to_git(elem->path, result, len, &buf, safe_crlf)) { if (convert_to_git(&the_index, elem->path, result, len, &buf, safe_crlf)) {
free(result); free(result);
result = strbuf_detach(&buf, &len); result = strbuf_detach(&buf, &len);
result_size = len; result_size = len;

View File

@ -1084,7 +1084,8 @@ const char *get_convert_attr_ascii(const char *path)
return ""; return "";
} }
int convert_to_git(const char *path, const char *src, size_t len, int convert_to_git(const struct index_state *istate,
const char *path, const char *src, size_t len,
struct strbuf *dst, enum safe_crlf checksafe) struct strbuf *dst, enum safe_crlf checksafe)
{ {
int ret = 0; int ret = 0;
@ -1100,7 +1101,7 @@ int convert_to_git(const char *path, const char *src, size_t len,
src = dst->buf; src = dst->buf;
len = dst->len; len = dst->len;
} }
ret |= crlf_to_git(&the_index, path, src, len, dst, ca.crlf_action, checksafe); ret |= crlf_to_git(istate, path, src, len, dst, ca.crlf_action, checksafe);
if (ret && dst) { if (ret && dst) {
src = dst->buf; src = dst->buf;
len = dst->len; len = dst->len;
@ -1171,7 +1172,7 @@ int renormalize_buffer(const char *path, const char *src, size_t len, struct str
src = dst->buf; src = dst->buf;
len = dst->len; len = dst->len;
} }
return ret | convert_to_git(path, src, len, dst, SAFE_CRLF_RENORMALIZE); return ret | convert_to_git(&the_index, path, src, len, dst, SAFE_CRLF_RENORMALIZE);
} }
/***************************************************************** /*****************************************************************

View File

@ -41,15 +41,17 @@ extern const char *get_wt_convert_stats_ascii(const char *path);
extern const char *get_convert_attr_ascii(const char *path); extern const char *get_convert_attr_ascii(const char *path);
/* returns 1 if *dst was used */ /* returns 1 if *dst was used */
extern int convert_to_git(const char *path, const char *src, size_t len, extern int convert_to_git(const struct index_state *istate,
const char *path, const char *src, size_t len,
struct strbuf *dst, enum safe_crlf checksafe); struct strbuf *dst, enum safe_crlf checksafe);
extern int convert_to_working_tree(const char *path, const char *src, extern int convert_to_working_tree(const char *path, const char *src,
size_t len, struct strbuf *dst); size_t len, struct strbuf *dst);
extern int renormalize_buffer(const char *path, const char *src, size_t len, extern int renormalize_buffer(const char *path, const char *src, size_t len,
struct strbuf *dst); struct strbuf *dst);
static inline int would_convert_to_git(const char *path) static inline int would_convert_to_git(const struct index_state *istate,
const char *path)
{ {
return convert_to_git(path, NULL, 0, NULL, 0); return convert_to_git(istate, path, NULL, 0, NULL, 0);
} }
/* Precondition: would_convert_to_git_filter_fd(path) == true */ /* Precondition: would_convert_to_git_filter_fd(path) == true */
extern void convert_to_git_filter_fd(const struct index_state *istate, extern void convert_to_git_filter_fd(const struct index_state *istate,

6
diff.c
View File

@ -2755,7 +2755,7 @@ static int reuse_worktree_file(const char *name, const unsigned char *sha1, int
* Similarly, if we'd have to convert the file contents anyway, that * Similarly, if we'd have to convert the file contents anyway, that
* makes the optimization not worthwhile. * makes the optimization not worthwhile.
*/ */
if (!want_file && would_convert_to_git(name)) if (!want_file && would_convert_to_git(&the_index, name))
return 0; return 0;
len = strlen(name); len = strlen(name);
@ -2877,7 +2877,7 @@ int diff_populate_filespec(struct diff_filespec *s, unsigned int flags)
* point if the path requires us to run the content * point if the path requires us to run the content
* conversion. * conversion.
*/ */
if (size_only && !would_convert_to_git(s->path)) if (size_only && !would_convert_to_git(&the_index, s->path))
return 0; return 0;
/* /*
@ -2904,7 +2904,7 @@ int diff_populate_filespec(struct diff_filespec *s, unsigned int flags)
/* /*
* Convert from working tree format to canonical git format * Convert from working tree format to canonical git format
*/ */
if (convert_to_git(s->path, s->data, s->size, &buf, crlf_warn)) { if (convert_to_git(&the_index, s->path, s->data, s->size, &buf, crlf_warn)) {
size_t size = 0; size_t size = 0;
munmap(s->data, s->size); munmap(s->data, s->size);
s->should_munmap = 0; s->should_munmap = 0;

2
dir.c
View File

@ -795,7 +795,7 @@ static int add_excludes(const char *fname, const char *base, int baselen,
(pos = index_name_pos(istate, fname, strlen(fname))) >= 0 && (pos = index_name_pos(istate, fname, strlen(fname))) >= 0 &&
!ce_stage(istate->cache[pos]) && !ce_stage(istate->cache[pos]) &&
ce_uptodate(istate->cache[pos]) && ce_uptodate(istate->cache[pos]) &&
!would_convert_to_git(fname)) !would_convert_to_git(istate, fname))
hashcpy(sha1_stat->sha1, hashcpy(sha1_stat->sha1,
istate->cache[pos]->oid.hash); istate->cache[pos]->oid.hash);
else else

View File

@ -3546,7 +3546,7 @@ static int index_mem(unsigned char *sha1, void *buf, size_t size,
*/ */
if ((type == OBJ_BLOB) && path) { if ((type == OBJ_BLOB) && path) {
struct strbuf nbuf = STRBUF_INIT; struct strbuf nbuf = STRBUF_INIT;
if (convert_to_git(path, buf, size, &nbuf, if (convert_to_git(&the_index, path, buf, size, &nbuf,
write_object ? safe_crlf : SAFE_CRLF_FALSE)) { write_object ? safe_crlf : SAFE_CRLF_FALSE)) {
buf = strbuf_detach(&nbuf, &size); buf = strbuf_detach(&nbuf, &size);
re_allocated = 1; re_allocated = 1;
@ -3668,7 +3668,7 @@ int index_fd(unsigned char *sha1, int fd, struct stat *st,
else if (!S_ISREG(st->st_mode)) else if (!S_ISREG(st->st_mode))
ret = index_pipe(sha1, fd, type, path, flags); ret = index_pipe(sha1, fd, type, path, flags);
else if (st->st_size <= big_file_threshold || type != OBJ_BLOB || else if (st->st_size <= big_file_threshold || type != OBJ_BLOB ||
(path && would_convert_to_git(path))) (path && would_convert_to_git(&the_index, path)))
ret = index_core(sha1, fd, xsize_t(st->st_size), type, path, ret = index_core(sha1, fd, xsize_t(st->st_size), type, path,
flags); flags);
else else