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>
Nguyễn Thái Ngọc Duy committed
Sep 21, 2018 at 17:57 UTC
6afaf807859bd671a3f8e9101952e648a1a5e1a9
8 files changed
+45
-30
blame.c
+4
-3
@@ -234,7 +234,7 @@ static struct commit *fake_working_tree_commit(struct repository *r,
234
switch (st.st_mode & S_IFMT) {
235
case S_IFREG:
236
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))
238
strbuf_attach(&buf, buf_ptr, buf_len, buf_len + 1);
239
else if (strbuf_read_file(&buf, read_from, st.st_size) != st.st_size)
240
die_errno("cannot open or read '%s'", read_from);
@@ -318,7 +318,8 @@ static void fill_origin_blob(struct diff_options *opt,
318
319
(*num_read_blob)++;
320
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))
323
;
324
else
325
file->ptr = read_object_file(&o->blob_oid, &type,
@@ -1857,7 +1858,7 @@ void setup_scoreboard(struct blame_scoreboard *sb,
1858
die(_("no such path %s in %s"), path, final_commit_name);
1859
1860
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,
1862
&sb->final_buf_size))
1863
;
1864
else
builtin/cat-file.c
+4
-2
@@ -113,7 +113,8 @@ static int cat_one_file(int opt, const char *exp_type, const char *obj_name,
113
die("git cat-file --textconv %s: <object> must be <sha1:path>",
114
obj_name);
115
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))
118
break;
119
/* else fallthrough */
120
@@ -305,7 +306,8 @@ static void print_object_or_die(struct batch_options *opt, struct expand_data *d
306
oid_to_hex(oid), data->rest);
307
} else if (opt->cmdmode == 'c') {
308
enum object_type type;
308
- if (!textconv_object(data->rest, 0100644, oid,
309
+ if (!textconv_object(the_repository,
310
+ data->rest, 0100644, oid,
311
1, &contents, &size))
312
contents = read_object_file(oid,
313
&type,
builtin/log.c
+2
-1
@@ -507,7 +507,8 @@ static int show_blob_object(const struct object_id *oid, struct rev_info *rev, c
507
&oidc, &obj_context))
508
die(_("Not a valid object name %s"), obj_name);
509
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)) {
512
free(obj_context.path);
513
return stream_blob_to_fd(1, oid, NULL, 0);
514
}
combine-diff.c
+16
-11
@@ -285,7 +285,8 @@ static struct lline *coalesce_lines(struct lline *base, int *lenbase,
285
return base;
286
}
287
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,
290
unsigned long *size, struct userdiff_driver *textconv,
291
const char *path)
292
{
@@ -304,7 +305,7 @@ static char *grab_blob(const struct object_id *oid, unsigned int mode,
305
} else if (textconv) {
306
struct diff_filespec *df = alloc_filespec(path);
307
fill_filespec(df, oid, 1, mode);
307
- *size = fill_textconv(textconv, df, &blob);
308
+ *size = fill_textconv(r, textconv, df, &blob);
309
free_filespec(df);
310
} else {
311
blob = read_object_file(oid, &type, size);
@@ -389,7 +390,8 @@ static void consume_line(void *state_, char *line, unsigned long len)
390
}
391
}
392
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,
395
mmfile_t *result_file,
396
struct sline *sline, unsigned int cnt, int n,
397
int num_parent, int result_deleted,
@@ -407,7 +409,7 @@ static void combine_diff(const struct object_id *parent, unsigned int mode,
409
if (result_deleted)
410
return; /* result deleted */
411
410
- parent_file.ptr = grab_blob(parent, mode, &sz, textconv, path);
412
+ parent_file.ptr = grab_blob(r, parent, mode, &sz, textconv, path);
413
parent_file.size = sz;
414
memset(&xpp, 0, sizeof(xpp));
415
xpp.flags = flags;
@@ -993,7 +995,7 @@ static void show_patch_diff(struct combine_diff_path *elem, int num_parent,
995
996
/* Read the result of merge first */
997
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,
999
textconv, elem->path);
1000
else {
1001
/* 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,
1018
} else if (S_ISDIR(st.st_mode)) {
1019
struct object_id oid;
1020
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);
1024
else
1022
- result = grab_blob(&oid, elem->mode,
1025
+ result = grab_blob(opt->repo, &oid, elem->mode,
1026
&result_size, NULL, NULL);
1027
} else if (textconv) {
1028
struct diff_filespec *df = alloc_filespec(elem->path);
1029
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);
1031
free_filespec(df);
1032
} else if (0 <= (fd = open(elem->path, O_RDONLY))) {
1033
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,
1093
for (i = 0; !is_binary && i < num_parent; i++) {
1094
char *buf;
1095
unsigned long size;
1093
- buf = grab_blob(&elem->parent[i].oid,
1096
+ buf = grab_blob(opt->repo,
1097
+ &elem->parent[i].oid,
1098
elem->parent[i].mode,
1099
&size, NULL, NULL);
1100
if (buffer_is_binary(buf, size))
@@ -1146,7 +1150,8 @@ static void show_patch_diff(struct combine_diff_path *elem, int num_parent,
1150
}
1151
}
1152
if (i <= j)
1149
- combine_diff(&elem->parent[i].oid,
1153
+ combine_diff(opt->repo,
1154
+ &elem->parent[i].oid,
1155
elem->parent[i].mode,
1156
&result_file, sline,
1157
cnt, i, num_parent, result_deleted,
diff.c
+9
-8
@@ -1700,8 +1700,8 @@ static void emit_rewrite_diff(const char *name_a,
1700
quote_two_c_style(&a_name, a_prefix, name_a, 0);
1701
quote_two_c_style(&b_name, b_prefix, name_b, 0);
1702
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);
1705
1706
memset(&ecbdata, 0, sizeof(ecbdata));
1707
ecbdata.color_diff = want_color(o->use_color);
@@ -3462,8 +3462,8 @@ static void builtin_diff(const char *name_a,
3462
strbuf_reset(&header);
3463
}
3464
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);
3467
3468
pe = diff_funcname_pattern(one);
3469
if (!pe)
@@ -6337,11 +6337,11 @@ static char *run_textconv(struct repository *r,
6337
return strbuf_detach(&buf, outsize);
6338
}
6339
6340
-size_t fill_textconv(struct userdiff_driver *driver,
6340
+size_t fill_textconv(struct repository *r,
6341
+ struct userdiff_driver *driver,
6342
struct diff_filespec *df,
6343
char **outbuf)
6344
{
6344
- struct repository *r = the_repository;
6345
size_t size;
6346
6347
if (!driver) {
@@ -6386,7 +6386,8 @@ size_t fill_textconv(struct userdiff_driver *driver,
6386
return size;
6387
}
6388
6389
-int textconv_object(const char *path,
6389
+int textconv_object(struct repository *r,
6390
+ const char *path,
6391
unsigned mode,
6392
const struct object_id *oid,
6393
int oid_valid,
@@ -6404,7 +6405,7 @@ int textconv_object(const char *path,
6405
return 0;
6406
}
6407
6407
- *buf_size = fill_textconv(textconv, df, buf);
6408
+ *buf_size = fill_textconv(r, textconv, df, buf);
6409
free_filespec(df);
6410
return 1;
6411
}
diff.h
+7
-2
@@ -442,7 +442,8 @@ int index_differs_from(const char *def, const struct diff_flags *flags,
442
* struct. If it is non-NULL, then "outbuf" points to a newly allocated buffer
443
* that should be freed by the caller.
444
*/
445
-size_t fill_textconv(struct userdiff_driver *driver,
445
+size_t fill_textconv(struct repository *r,
446
+ struct userdiff_driver *driver,
447
struct diff_filespec *df,
448
char **outbuf);
449
@@ -458,7 +459,11 @@ struct userdiff_driver *get_textconv(struct diff_filespec *one);
459
* if the textconv driver exists.
460
* Return 1 if the conversion succeeds, 0 otherwise.
461
*/
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);
467
468
int parse_rename_score(const char **cp_p);
469
diffcore-pickaxe.c
+2
-2
@@ -153,8 +153,8 @@ static int pickaxe_match(struct diff_filepair *p, struct diff_options *o,
153
if (textconv_one == textconv_two && diff_unmodified_pair(p))
154
return 0;
155
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);
158
159
ret = fn(DIFF_FILE_VALID(p->one) ? &mf1 : NULL,
160
DIFF_FILE_VALID(p->two) ? &mf2 : NULL,
grep.c
+1
-1
@@ -1741,7 +1741,7 @@ static int fill_textconv_grep(struct userdiff_driver *driver,
1741
* structure.
1742
*/
1743
grep_read_lock();
1744
- size = fill_textconv(driver, df, &buf);
1744
+ size = fill_textconv(the_repository, driver, df, &buf);
1745
grep_read_unlock();
1746
free_filespec(df);
1747