diff.c: remove the_index dependency in textconv() functions

Signed-off-by: Nguyễn Thái Ngọc Duy <pclouds@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
This commit is contained in:
Nguyễn Thái Ngọc Duy
2018-09-21 17:57:22 +02:00
committed by Junio C Hamano
parent a470beea39
commit 6afaf80785
8 changed files with 45 additions and 30 deletions

View File

@ -285,7 +285,8 @@ static struct lline *coalesce_lines(struct lline *base, int *lenbase,
return base;
}
static char *grab_blob(const struct object_id *oid, unsigned int mode,
static char *grab_blob(struct repository *r,
const struct object_id *oid, unsigned int mode,
unsigned long *size, struct userdiff_driver *textconv,
const char *path)
{
@ -304,7 +305,7 @@ static char *grab_blob(const struct object_id *oid, unsigned int mode,
} else if (textconv) {
struct diff_filespec *df = alloc_filespec(path);
fill_filespec(df, oid, 1, mode);
*size = fill_textconv(textconv, df, &blob);
*size = fill_textconv(r, textconv, df, &blob);
free_filespec(df);
} else {
blob = read_object_file(oid, &type, size);
@ -389,7 +390,8 @@ static void consume_line(void *state_, char *line, unsigned long len)
}
}
static void combine_diff(const struct object_id *parent, unsigned int mode,
static void combine_diff(struct repository *r,
const struct object_id *parent, unsigned int mode,
mmfile_t *result_file,
struct sline *sline, unsigned int cnt, int n,
int num_parent, int result_deleted,
@ -407,7 +409,7 @@ static void combine_diff(const struct object_id *parent, unsigned int mode,
if (result_deleted)
return; /* result deleted */
parent_file.ptr = grab_blob(parent, mode, &sz, textconv, path);
parent_file.ptr = grab_blob(r, parent, mode, &sz, textconv, path);
parent_file.size = sz;
memset(&xpp, 0, sizeof(xpp));
xpp.flags = flags;
@ -993,7 +995,7 @@ static void show_patch_diff(struct combine_diff_path *elem, int num_parent,
/* Read the result of merge first */
if (!working_tree_file)
result = grab_blob(&elem->oid, elem->mode, &result_size,
result = grab_blob(opt->repo, &elem->oid, elem->mode, &result_size,
textconv, elem->path);
else {
/* Used by diff-tree to read from the working tree */
@ -1016,15 +1018,16 @@ static void show_patch_diff(struct combine_diff_path *elem, int num_parent,
} else if (S_ISDIR(st.st_mode)) {
struct object_id oid;
if (resolve_gitlink_ref(elem->path, "HEAD", &oid) < 0)
result = grab_blob(&elem->oid, elem->mode,
&result_size, NULL, NULL);
result = grab_blob(opt->repo, &elem->oid,
elem->mode, &result_size,
NULL, NULL);
else
result = grab_blob(&oid, elem->mode,
result = grab_blob(opt->repo, &oid, elem->mode,
&result_size, NULL, NULL);
} else if (textconv) {
struct diff_filespec *df = alloc_filespec(elem->path);
fill_filespec(df, &null_oid, 0, st.st_mode);
result_size = fill_textconv(textconv, df, &result);
result_size = fill_textconv(opt->repo, textconv, df, &result);
free_filespec(df);
} else if (0 <= (fd = open(elem->path, O_RDONLY))) {
size_t len = xsize_t(st.st_size);
@ -1090,7 +1093,8 @@ static void show_patch_diff(struct combine_diff_path *elem, int num_parent,
for (i = 0; !is_binary && i < num_parent; i++) {
char *buf;
unsigned long size;
buf = grab_blob(&elem->parent[i].oid,
buf = grab_blob(opt->repo,
&elem->parent[i].oid,
elem->parent[i].mode,
&size, NULL, NULL);
if (buffer_is_binary(buf, size))
@ -1146,7 +1150,8 @@ static void show_patch_diff(struct combine_diff_path *elem, int num_parent,
}
}
if (i <= j)
combine_diff(&elem->parent[i].oid,
combine_diff(opt->repo,
&elem->parent[i].oid,
elem->parent[i].mode,
&result_file, sline,
cnt, i, num_parent, result_deleted,