Skip to content

Commit 6afaf80

Browse files
pcloudsgitster
authored andcommitted
diff.c: remove the_index dependency in textconv() functions
Signed-off-by: Nguyễn Thái Ngọc Duy <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent a470bee commit 6afaf80

File tree

8 files changed

+45
-30
lines changed

8 files changed

+45
-30
lines changed

blame.c

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -234,7 +234,7 @@ static struct commit *fake_working_tree_commit(struct repository *r,
234234
switch (st.st_mode & S_IFMT) {
235235
case S_IFREG:
236236
if (opt->flags.allow_textconv &&
237-
textconv_object(read_from, mode, &null_oid, 0, &buf_ptr, &buf_len))
237+
textconv_object(r, read_from, mode, &null_oid, 0, &buf_ptr, &buf_len))
238238
strbuf_attach(&buf, buf_ptr, buf_len, buf_len + 1);
239239
else if (strbuf_read_file(&buf, read_from, st.st_size) != st.st_size)
240240
die_errno("cannot open or read '%s'", read_from);
@@ -318,7 +318,8 @@ static void fill_origin_blob(struct diff_options *opt,
318318

319319
(*num_read_blob)++;
320320
if (opt->flags.allow_textconv &&
321-
textconv_object(o->path, o->mode, &o->blob_oid, 1, &file->ptr, &file_size))
321+
textconv_object(opt->repo, o->path, o->mode,
322+
&o->blob_oid, 1, &file->ptr, &file_size))
322323
;
323324
else
324325
file->ptr = read_object_file(&o->blob_oid, &type,
@@ -1857,7 +1858,7 @@ void setup_scoreboard(struct blame_scoreboard *sb,
18571858
die(_("no such path %s in %s"), path, final_commit_name);
18581859

18591860
if (sb->revs->diffopt.flags.allow_textconv &&
1860-
textconv_object(path, o->mode, &o->blob_oid, 1, (char **) &sb->final_buf,
1861+
textconv_object(sb->repo, path, o->mode, &o->blob_oid, 1, (char **) &sb->final_buf,
18611862
&sb->final_buf_size))
18621863
;
18631864
else

builtin/cat-file.c

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,8 @@ static int cat_one_file(int opt, const char *exp_type, const char *obj_name,
113113
die("git cat-file --textconv %s: <object> must be <sha1:path>",
114114
obj_name);
115115

116-
if (textconv_object(path, obj_context.mode, &oid, 1, &buf, &size))
116+
if (textconv_object(the_repository, path, obj_context.mode,
117+
&oid, 1, &buf, &size))
117118
break;
118119
/* else fallthrough */
119120

@@ -305,7 +306,8 @@ static void print_object_or_die(struct batch_options *opt, struct expand_data *d
305306
oid_to_hex(oid), data->rest);
306307
} else if (opt->cmdmode == 'c') {
307308
enum object_type type;
308-
if (!textconv_object(data->rest, 0100644, oid,
309+
if (!textconv_object(the_repository,
310+
data->rest, 0100644, oid,
309311
1, &contents, &size))
310312
contents = read_object_file(oid,
311313
&type,

builtin/log.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -507,7 +507,8 @@ static int show_blob_object(const struct object_id *oid, struct rev_info *rev, c
507507
&oidc, &obj_context))
508508
die(_("Not a valid object name %s"), obj_name);
509509
if (!obj_context.path ||
510-
!textconv_object(obj_context.path, obj_context.mode, &oidc, 1, &buf, &size)) {
510+
!textconv_object(the_repository, obj_context.path,
511+
obj_context.mode, &oidc, 1, &buf, &size)) {
511512
free(obj_context.path);
512513
return stream_blob_to_fd(1, oid, NULL, 0);
513514
}

combine-diff.c

Lines changed: 16 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -285,7 +285,8 @@ static struct lline *coalesce_lines(struct lline *base, int *lenbase,
285285
return base;
286286
}
287287

288-
static char *grab_blob(const struct object_id *oid, unsigned int mode,
288+
static char *grab_blob(struct repository *r,
289+
const struct object_id *oid, unsigned int mode,
289290
unsigned long *size, struct userdiff_driver *textconv,
290291
const char *path)
291292
{
@@ -304,7 +305,7 @@ static char *grab_blob(const struct object_id *oid, unsigned int mode,
304305
} else if (textconv) {
305306
struct diff_filespec *df = alloc_filespec(path);
306307
fill_filespec(df, oid, 1, mode);
307-
*size = fill_textconv(textconv, df, &blob);
308+
*size = fill_textconv(r, textconv, df, &blob);
308309
free_filespec(df);
309310
} else {
310311
blob = read_object_file(oid, &type, size);
@@ -389,7 +390,8 @@ static void consume_line(void *state_, char *line, unsigned long len)
389390
}
390391
}
391392

392-
static void combine_diff(const struct object_id *parent, unsigned int mode,
393+
static void combine_diff(struct repository *r,
394+
const struct object_id *parent, unsigned int mode,
393395
mmfile_t *result_file,
394396
struct sline *sline, unsigned int cnt, int n,
395397
int num_parent, int result_deleted,
@@ -407,7 +409,7 @@ static void combine_diff(const struct object_id *parent, unsigned int mode,
407409
if (result_deleted)
408410
return; /* result deleted */
409411

410-
parent_file.ptr = grab_blob(parent, mode, &sz, textconv, path);
412+
parent_file.ptr = grab_blob(r, parent, mode, &sz, textconv, path);
411413
parent_file.size = sz;
412414
memset(&xpp, 0, sizeof(xpp));
413415
xpp.flags = flags;
@@ -993,7 +995,7 @@ static void show_patch_diff(struct combine_diff_path *elem, int num_parent,
993995

994996
/* Read the result of merge first */
995997
if (!working_tree_file)
996-
result = grab_blob(&elem->oid, elem->mode, &result_size,
998+
result = grab_blob(opt->repo, &elem->oid, elem->mode, &result_size,
997999
textconv, elem->path);
9981000
else {
9991001
/* 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,
10161018
} else if (S_ISDIR(st.st_mode)) {
10171019
struct object_id oid;
10181020
if (resolve_gitlink_ref(elem->path, "HEAD", &oid) < 0)
1019-
result = grab_blob(&elem->oid, elem->mode,
1020-
&result_size, NULL, NULL);
1021+
result = grab_blob(opt->repo, &elem->oid,
1022+
elem->mode, &result_size,
1023+
NULL, NULL);
10211024
else
1022-
result = grab_blob(&oid, elem->mode,
1025+
result = grab_blob(opt->repo, &oid, elem->mode,
10231026
&result_size, NULL, NULL);
10241027
} else if (textconv) {
10251028
struct diff_filespec *df = alloc_filespec(elem->path);
10261029
fill_filespec(df, &null_oid, 0, st.st_mode);
1027-
result_size = fill_textconv(textconv, df, &result);
1030+
result_size = fill_textconv(opt->repo, textconv, df, &result);
10281031
free_filespec(df);
10291032
} else if (0 <= (fd = open(elem->path, O_RDONLY))) {
10301033
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,
10901093
for (i = 0; !is_binary && i < num_parent; i++) {
10911094
char *buf;
10921095
unsigned long size;
1093-
buf = grab_blob(&elem->parent[i].oid,
1096+
buf = grab_blob(opt->repo,
1097+
&elem->parent[i].oid,
10941098
elem->parent[i].mode,
10951099
&size, NULL, NULL);
10961100
if (buffer_is_binary(buf, size))
@@ -1146,7 +1150,8 @@ static void show_patch_diff(struct combine_diff_path *elem, int num_parent,
11461150
}
11471151
}
11481152
if (i <= j)
1149-
combine_diff(&elem->parent[i].oid,
1153+
combine_diff(opt->repo,
1154+
&elem->parent[i].oid,
11501155
elem->parent[i].mode,
11511156
&result_file, sline,
11521157
cnt, i, num_parent, result_deleted,

diff.c

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1700,8 +1700,8 @@ static void emit_rewrite_diff(const char *name_a,
17001700
quote_two_c_style(&a_name, a_prefix, name_a, 0);
17011701
quote_two_c_style(&b_name, b_prefix, name_b, 0);
17021702

1703-
size_one = fill_textconv(textconv_one, one, &data_one);
1704-
size_two = fill_textconv(textconv_two, two, &data_two);
1703+
size_one = fill_textconv(o->repo, textconv_one, one, &data_one);
1704+
size_two = fill_textconv(o->repo, textconv_two, two, &data_two);
17051705

17061706
memset(&ecbdata, 0, sizeof(ecbdata));
17071707
ecbdata.color_diff = want_color(o->use_color);
@@ -3462,8 +3462,8 @@ static void builtin_diff(const char *name_a,
34623462
strbuf_reset(&header);
34633463
}
34643464

3465-
mf1.size = fill_textconv(textconv_one, one, &mf1.ptr);
3466-
mf2.size = fill_textconv(textconv_two, two, &mf2.ptr);
3465+
mf1.size = fill_textconv(o->repo, textconv_one, one, &mf1.ptr);
3466+
mf2.size = fill_textconv(o->repo, textconv_two, two, &mf2.ptr);
34673467

34683468
pe = diff_funcname_pattern(one);
34693469
if (!pe)
@@ -6337,11 +6337,11 @@ static char *run_textconv(struct repository *r,
63376337
return strbuf_detach(&buf, outsize);
63386338
}
63396339

6340-
size_t fill_textconv(struct userdiff_driver *driver,
6340+
size_t fill_textconv(struct repository *r,
6341+
struct userdiff_driver *driver,
63416342
struct diff_filespec *df,
63426343
char **outbuf)
63436344
{
6344-
struct repository *r = the_repository;
63456345
size_t size;
63466346

63476347
if (!driver) {
@@ -6386,7 +6386,8 @@ size_t fill_textconv(struct userdiff_driver *driver,
63866386
return size;
63876387
}
63886388

6389-
int textconv_object(const char *path,
6389+
int textconv_object(struct repository *r,
6390+
const char *path,
63906391
unsigned mode,
63916392
const struct object_id *oid,
63926393
int oid_valid,
@@ -6404,7 +6405,7 @@ int textconv_object(const char *path,
64046405
return 0;
64056406
}
64066407

6407-
*buf_size = fill_textconv(textconv, df, buf);
6408+
*buf_size = fill_textconv(r, textconv, df, buf);
64086409
free_filespec(df);
64096410
return 1;
64106411
}

diff.h

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -442,7 +442,8 @@ int index_differs_from(const char *def, const struct diff_flags *flags,
442442
* struct. If it is non-NULL, then "outbuf" points to a newly allocated buffer
443443
* that should be freed by the caller.
444444
*/
445-
size_t fill_textconv(struct userdiff_driver *driver,
445+
size_t fill_textconv(struct repository *r,
446+
struct userdiff_driver *driver,
446447
struct diff_filespec *df,
447448
char **outbuf);
448449

@@ -458,7 +459,11 @@ struct userdiff_driver *get_textconv(struct diff_filespec *one);
458459
* if the textconv driver exists.
459460
* Return 1 if the conversion succeeds, 0 otherwise.
460461
*/
461-
int textconv_object(const char *path, unsigned mode, const struct object_id *oid, int oid_valid, char **buf, unsigned long *buf_size);
462+
int textconv_object(struct repository *repo,
463+
const char *path,
464+
unsigned mode,
465+
const struct object_id *oid, int oid_valid,
466+
char **buf, unsigned long *buf_size);
462467

463468
int parse_rename_score(const char **cp_p);
464469

diffcore-pickaxe.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -153,8 +153,8 @@ static int pickaxe_match(struct diff_filepair *p, struct diff_options *o,
153153
if (textconv_one == textconv_two && diff_unmodified_pair(p))
154154
return 0;
155155

156-
mf1.size = fill_textconv(textconv_one, p->one, &mf1.ptr);
157-
mf2.size = fill_textconv(textconv_two, p->two, &mf2.ptr);
156+
mf1.size = fill_textconv(o->repo, textconv_one, p->one, &mf1.ptr);
157+
mf2.size = fill_textconv(o->repo, textconv_two, p->two, &mf2.ptr);
158158

159159
ret = fn(DIFF_FILE_VALID(p->one) ? &mf1 : NULL,
160160
DIFF_FILE_VALID(p->two) ? &mf2 : NULL,

grep.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1741,7 +1741,7 @@ static int fill_textconv_grep(struct userdiff_driver *driver,
17411741
* structure.
17421742
*/
17431743
grep_read_lock();
1744-
size = fill_textconv(driver, df, &buf);
1744+
size = fill_textconv(the_repository, driver, df, &buf);
17451745
grep_read_unlock();
17461746
free_filespec(df);
17471747

0 commit comments

Comments
 (0)