Skip to content

Commit acd00ea

Browse files
pcloudsgitster
authored andcommitted
userdiff.c: remove implicit dependency on the_index
[jc: squashed in missing forward decl in userdiff.h found by Ramsay] Helped-by: Ramsay Jones <[email protected]> Signed-off-by: Nguyễn Thái Ngọc Duy <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 35843b1 commit acd00ea

11 files changed

+61
-41
lines changed

Diff for: archive-zip.c

+9-5
Original file line numberDiff line numberDiff line change
@@ -264,9 +264,10 @@ static int has_only_ascii(const char *s)
264264
}
265265
}
266266

267-
static int entry_is_binary(const char *path, const void *buffer, size_t size)
267+
static int entry_is_binary(struct index_state *istate, const char *path,
268+
const void *buffer, size_t size)
268269
{
269-
struct userdiff_driver *driver = userdiff_find_by_path(path);
270+
struct userdiff_driver *driver = userdiff_find_by_path(istate, path);
270271
if (!driver)
271272
driver = userdiff_find_by_name("default");
272273
if (driver->binary != -1)
@@ -352,7 +353,8 @@ static int write_zip_entry(struct archiver_args *args,
352353
return error(_("cannot read %s"),
353354
oid_to_hex(oid));
354355
crc = crc32(crc, buffer, size);
355-
is_binary = entry_is_binary(path_without_prefix,
356+
is_binary = entry_is_binary(args->repo->index,
357+
path_without_prefix,
356358
buffer, size);
357359
out = buffer;
358360
}
@@ -428,7 +430,8 @@ static int write_zip_entry(struct archiver_args *args,
428430
break;
429431
crc = crc32(crc, buf, readlen);
430432
if (is_binary == -1)
431-
is_binary = entry_is_binary(path_without_prefix,
433+
is_binary = entry_is_binary(args->repo->index,
434+
path_without_prefix,
432435
buf, readlen);
433436
write_or_die(1, buf, readlen);
434437
}
@@ -460,7 +463,8 @@ static int write_zip_entry(struct archiver_args *args,
460463
break;
461464
crc = crc32(crc, buf, readlen);
462465
if (is_binary == -1)
463-
is_binary = entry_is_binary(path_without_prefix,
466+
is_binary = entry_is_binary(args->repo->index,
467+
path_without_prefix,
464468
buf, readlen);
465469

466470
zstream.next_in = buf;

Diff for: builtin/grep.c

+2-1
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,8 @@ static void add_work(struct grep_opt *opt, const struct grep_source *gs)
103103

104104
todo[todo_end].source = *gs;
105105
if (opt->binary != GREP_BINARY_TEXT)
106-
grep_source_load_driver(&todo[todo_end].source);
106+
grep_source_load_driver(&todo[todo_end].source,
107+
opt->repo->index);
107108
todo[todo_end].done = 0;
108109
strbuf_reset(&todo[todo_end].out);
109110
todo_end = (todo_end + 1) % ARRAY_SIZE(todo);

Diff for: combine-diff.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -987,7 +987,7 @@ static void show_patch_diff(struct combine_diff_path *elem, int num_parent,
987987
const char *line_prefix = diff_line_prefix(opt);
988988

989989
context = opt->context;
990-
userdiff = userdiff_find_by_path(elem->path);
990+
userdiff = userdiff_find_by_path(opt->repo->index, elem->path);
991991
if (!userdiff)
992992
userdiff = userdiff_find_by_name("default");
993993
if (opt->flags.allow_textconv)

Diff for: diff.c

+23-17
Original file line numberDiff line numberDiff line change
@@ -2093,23 +2093,25 @@ static void diff_words_flush(struct emit_callback *ecbdata)
20932093
}
20942094
}
20952095

2096-
static void diff_filespec_load_driver(struct diff_filespec *one)
2096+
static void diff_filespec_load_driver(struct diff_filespec *one,
2097+
struct index_state *istate)
20972098
{
20982099
/* Use already-loaded driver */
20992100
if (one->driver)
21002101
return;
21012102

21022103
if (S_ISREG(one->mode))
2103-
one->driver = userdiff_find_by_path(one->path);
2104+
one->driver = userdiff_find_by_path(istate, one->path);
21042105

21052106
/* Fallback to default settings */
21062107
if (!one->driver)
21072108
one->driver = userdiff_find_by_name("default");
21082109
}
21092110

2110-
static const char *userdiff_word_regex(struct diff_filespec *one)
2111+
static const char *userdiff_word_regex(struct diff_filespec *one,
2112+
struct index_state *istate)
21112113
{
2112-
diff_filespec_load_driver(one);
2114+
diff_filespec_load_driver(one, istate);
21132115
return one->driver->word_regex;
21142116
}
21152117

@@ -2132,9 +2134,9 @@ static void init_diff_words_data(struct emit_callback *ecbdata,
21322134
xcalloc(1, sizeof(struct emitted_diff_symbols));
21332135

21342136
if (!o->word_regex)
2135-
o->word_regex = userdiff_word_regex(one);
2137+
o->word_regex = userdiff_word_regex(one, o->repo->index);
21362138
if (!o->word_regex)
2137-
o->word_regex = userdiff_word_regex(two);
2139+
o->word_regex = userdiff_word_regex(two, o->repo->index);
21382140
if (!o->word_regex)
21392141
o->word_regex = diff_word_regex_cfg;
21402142
if (o->word_regex) {
@@ -3257,7 +3259,7 @@ int diff_filespec_is_binary(struct repository *r,
32573259
struct diff_filespec *one)
32583260
{
32593261
if (one->is_binary == -1) {
3260-
diff_filespec_load_driver(one);
3262+
diff_filespec_load_driver(one, r->index);
32613263
if (one->driver->binary != -1)
32623264
one->is_binary = one->driver->binary;
32633265
else {
@@ -3273,9 +3275,10 @@ int diff_filespec_is_binary(struct repository *r,
32733275
return one->is_binary;
32743276
}
32753277

3276-
static const struct userdiff_funcname *diff_funcname_pattern(struct diff_filespec *one)
3278+
static const struct userdiff_funcname *
3279+
diff_funcname_pattern(struct diff_options *o, struct diff_filespec *one)
32773280
{
3278-
diff_filespec_load_driver(one);
3281+
diff_filespec_load_driver(one, o->repo->index);
32793282
return one->driver->funcname.pattern ? &one->driver->funcname : NULL;
32803283
}
32813284

@@ -3287,12 +3290,13 @@ void diff_set_mnemonic_prefix(struct diff_options *options, const char *a, const
32873290
options->b_prefix = b;
32883291
}
32893292

3290-
struct userdiff_driver *get_textconv(struct diff_filespec *one)
3293+
struct userdiff_driver *get_textconv(struct index_state *istate,
3294+
struct diff_filespec *one)
32913295
{
32923296
if (!DIFF_FILE_VALID(one))
32933297
return NULL;
32943298

3295-
diff_filespec_load_driver(one);
3299+
diff_filespec_load_driver(one, istate);
32963300
return userdiff_get_textconv(one->driver);
32973301
}
32983302

@@ -3342,8 +3346,8 @@ static void builtin_diff(const char *name_a,
33423346
}
33433347

33443348
if (o->flags.allow_textconv) {
3345-
textconv_one = get_textconv(one);
3346-
textconv_two = get_textconv(two);
3349+
textconv_one = get_textconv(o->repo->index, one);
3350+
textconv_two = get_textconv(o->repo->index, two);
33473351
}
33483352

33493353
/* Never use a non-valid filename anywhere if at all possible */
@@ -3465,9 +3469,9 @@ static void builtin_diff(const char *name_a,
34653469
mf1.size = fill_textconv(o->repo, textconv_one, one, &mf1.ptr);
34663470
mf2.size = fill_textconv(o->repo, textconv_two, two, &mf2.ptr);
34673471

3468-
pe = diff_funcname_pattern(one);
3472+
pe = diff_funcname_pattern(o, one);
34693473
if (!pe)
3470-
pe = diff_funcname_pattern(two);
3474+
pe = diff_funcname_pattern(o, two);
34713475

34723476
memset(&xpp, 0, sizeof(xpp));
34733477
memset(&xecfg, 0, sizeof(xecfg));
@@ -4223,7 +4227,9 @@ static void run_diff_cmd(const char *pgm,
42234227

42244228

42254229
if (o->flags.allow_external) {
4226-
struct userdiff_driver *drv = userdiff_find_by_path(attr_path);
4230+
struct userdiff_driver *drv;
4231+
4232+
drv = userdiff_find_by_path(o->repo->index, attr_path);
42274233
if (drv && drv->external)
42284234
pgm = drv->external;
42294235
}
@@ -6399,7 +6405,7 @@ int textconv_object(struct repository *r,
63996405

64006406
df = alloc_filespec(path);
64016407
fill_filespec(df, oid, oid_valid, mode);
6402-
textconv = get_textconv(df);
6408+
textconv = get_textconv(r->index, df);
64036409
if (!textconv) {
64046410
free_filespec(df);
64056411
return 0;

Diff for: diff.h

+2-1
Original file line numberDiff line numberDiff line change
@@ -455,7 +455,8 @@ size_t fill_textconv(struct repository *r,
455455
* and only if it has textconv enabled (otherwise return NULL). The result
456456
* can be passed to fill_textconv().
457457
*/
458-
struct userdiff_driver *get_textconv(struct diff_filespec *one);
458+
struct userdiff_driver *get_textconv(struct index_state *istate,
459+
struct diff_filespec *one);
459460

460461
/*
461462
* Prepare diff_filespec and convert it using diff textconv API

Diff for: diffcore-pickaxe.c

+2-2
Original file line numberDiff line numberDiff line change
@@ -139,8 +139,8 @@ static int pickaxe_match(struct diff_filepair *p, struct diff_options *o,
139139
return 0;
140140

141141
if (o->flags.allow_textconv) {
142-
textconv_one = get_textconv(p->one);
143-
textconv_two = get_textconv(p->two);
142+
textconv_one = get_textconv(o->repo->index, p->one);
143+
textconv_two = get_textconv(o->repo->index, p->two);
144144
}
145145

146146
/*

Diff for: grep.c

+12-9
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,8 @@
1111
#include "help.h"
1212

1313
static int grep_source_load(struct grep_source *gs);
14-
static int grep_source_is_binary(struct grep_source *gs);
14+
static int grep_source_is_binary(struct grep_source *gs,
15+
struct index_state *istate);
1516

1617
static struct grep_opt grep_defaults;
1718

@@ -1547,7 +1548,7 @@ static int match_funcname(struct grep_opt *opt, struct grep_source *gs, char *bo
15471548
{
15481549
xdemitconf_t *xecfg = opt->priv;
15491550
if (xecfg && !xecfg->find_func) {
1550-
grep_source_load_driver(gs);
1551+
grep_source_load_driver(gs, opt->repo->index);
15511552
if (gs->driver->funcname.pattern) {
15521553
const struct userdiff_funcname *pe = &gs->driver->funcname;
15531554
xdiff_set_find_func(xecfg, pe->pattern, pe->cflags);
@@ -1804,7 +1805,7 @@ static int grep_source_1(struct grep_opt *opt, struct grep_source *gs, int colle
18041805
opt->last_shown = 0;
18051806

18061807
if (opt->allow_textconv) {
1807-
grep_source_load_driver(gs);
1808+
grep_source_load_driver(gs, opt->repo->index);
18081809
/*
18091810
* We might set up the shared textconv cache data here, which
18101811
* is not thread-safe.
@@ -1821,11 +1822,11 @@ static int grep_source_1(struct grep_opt *opt, struct grep_source *gs, int colle
18211822
if (!textconv) {
18221823
switch (opt->binary) {
18231824
case GREP_BINARY_DEFAULT:
1824-
if (grep_source_is_binary(gs))
1825+
if (grep_source_is_binary(gs, opt->repo->index))
18251826
binary_match_only = 1;
18261827
break;
18271828
case GREP_BINARY_NOMATCH:
1828-
if (grep_source_is_binary(gs))
1829+
if (grep_source_is_binary(gs, opt->repo->index))
18291830
return 0; /* Assume unmatch */
18301831
break;
18311832
case GREP_BINARY_TEXT:
@@ -2171,22 +2172,24 @@ static int grep_source_load(struct grep_source *gs)
21712172
BUG("invalid grep_source type to load");
21722173
}
21732174

2174-
void grep_source_load_driver(struct grep_source *gs)
2175+
void grep_source_load_driver(struct grep_source *gs,
2176+
struct index_state *istate)
21752177
{
21762178
if (gs->driver)
21772179
return;
21782180

21792181
grep_attr_lock();
21802182
if (gs->path)
2181-
gs->driver = userdiff_find_by_path(gs->path);
2183+
gs->driver = userdiff_find_by_path(istate, gs->path);
21822184
if (!gs->driver)
21832185
gs->driver = userdiff_find_by_name("default");
21842186
grep_attr_unlock();
21852187
}
21862188

2187-
static int grep_source_is_binary(struct grep_source *gs)
2189+
static int grep_source_is_binary(struct grep_source *gs,
2190+
struct index_state *istate)
21882191
{
2189-
grep_source_load_driver(gs);
2192+
grep_source_load_driver(gs, istate);
21902193
if (gs->driver->binary != -1)
21912194
return gs->driver->binary;
21922195

Diff for: grep.h

+2-1
Original file line numberDiff line numberDiff line change
@@ -220,7 +220,8 @@ void grep_source_init(struct grep_source *gs, enum grep_source_type type,
220220
const void *identifier);
221221
void grep_source_clear_data(struct grep_source *gs);
222222
void grep_source_clear(struct grep_source *gs);
223-
void grep_source_load_driver(struct grep_source *gs);
223+
void grep_source_load_driver(struct grep_source *gs,
224+
struct index_state *istate);
224225

225226

226227
int grep_source(struct grep_opt *opt, struct grep_source *gs);

Diff for: line-range.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -198,7 +198,7 @@ static const char *parse_range_funcname(const char *arg, nth_line_fn_t nth_line_
198198
anchor--; /* input is in human terms */
199199
start = nth_line_cb(cb_data, anchor);
200200

201-
drv = userdiff_find_by_path(path);
201+
drv = userdiff_find_by_path(&the_index, path);
202202
if (drv && drv->funcname.pattern) {
203203
const struct userdiff_funcname *pe = &drv->funcname;
204204
xecfg = xcalloc(1, sizeof(*xecfg));

Diff for: userdiff.c

+3-2
Original file line numberDiff line numberDiff line change
@@ -270,15 +270,16 @@ struct userdiff_driver *userdiff_find_by_name(const char *name) {
270270
return userdiff_find_by_namelen(name, len);
271271
}
272272

273-
struct userdiff_driver *userdiff_find_by_path(const char *path)
273+
struct userdiff_driver *userdiff_find_by_path(struct index_state *istate,
274+
const char *path)
274275
{
275276
static struct attr_check *check;
276277

277278
if (!check)
278279
check = attr_check_initl("diff", NULL);
279280
if (!path)
280281
return NULL;
281-
if (git_check_attr(&the_index, path, check))
282+
if (git_check_attr(istate, path, check))
282283
return NULL;
283284

284285
if (ATTR_TRUE(check->items[0].value))

Diff for: userdiff.h

+4-1
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@
33

44
#include "notes-cache.h"
55

6+
struct index_state;
7+
68
struct userdiff_funcname {
79
const char *pattern;
810
int cflags;
@@ -21,7 +23,8 @@ struct userdiff_driver {
2123

2224
int userdiff_config(const char *k, const char *v);
2325
struct userdiff_driver *userdiff_find_by_name(const char *name);
24-
struct userdiff_driver *userdiff_find_by_path(const char *path);
26+
struct userdiff_driver *userdiff_find_by_path(struct index_state *istate,
27+
const char *path);
2528

2629
/*
2730
* Initialize any textconv-related fields in the driver and return it, or NULL

0 commit comments

Comments
 (0)