Skip to content

Commit 7f944e2

Browse files
pcloudsgitster
authored andcommitted
convert.c: remove an implicit dependency on the_index
Make the convert API take an index_state instead of assuming the_index in convert.c. All external call sites are converted blindly to keep the patch simple and retain current behavior. Individual call sites may receive further updates to use the right index instead of the_index. Signed-off-by: Nguyễn Thái Ngọc Duy <pclouds@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
1 parent 7a400a2 commit 7f944e2

File tree

10 files changed

+45
-33
lines changed

10 files changed

+45
-33
lines changed

apply.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4335,7 +4335,7 @@ static int try_create_file(const char *path, unsigned int mode, const char *buf,
43354335
if (fd < 0)
43364336
return 1;
43374337

4338-
if (convert_to_working_tree(path, buf, size, &nbuf)) {
4338+
if (convert_to_working_tree(&the_index, path, buf, size, &nbuf)) {
43394339
size = nbuf.len;
43404340
buf = nbuf.buf;
43414341
}

archive.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ void *object_file_to_archive(const struct archiver_args *args,
7979
size_t size = 0;
8080

8181
strbuf_attach(&buf, buffer, *sizep, *sizep + 1);
82-
convert_to_working_tree(path, buf.buf, buf.len, &buf);
82+
convert_to_working_tree(&the_index, path, buf.buf, buf.len, &buf);
8383
if (commit)
8484
format_subst(commit, buf.buf, buf.len, &buf);
8585
buffer = strbuf_detach(&buf, &size);

builtin/cat-file.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ static int filter_object(const char *path, unsigned mode,
3939
oid_to_hex(oid), path);
4040
if ((type == OBJ_BLOB) && S_ISREG(mode)) {
4141
struct strbuf strbuf = STRBUF_INIT;
42-
if (convert_to_working_tree(path, *buf, *size, &strbuf)) {
42+
if (convert_to_working_tree(&the_index, path, *buf, *size, &strbuf)) {
4343
free(*buf);
4444
*size = strbuf.len;
4545
*buf = strbuf_detach(&strbuf, NULL);

builtin/ls-files.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ static void write_eolinfo(const struct index_state *istate,
6363
struct stat st;
6464
const char *i_txt = "";
6565
const char *w_txt = "";
66-
const char *a_txt = get_convert_attr_ascii(path);
66+
const char *a_txt = get_convert_attr_ascii(&the_index, path);
6767
if (ce && S_ISREG(ce->ce_mode))
6868
i_txt = get_cached_convert_stats_ascii(istate,
6969
ce->name);

convert.c

Lines changed: 24 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1291,7 +1291,8 @@ struct conv_attrs {
12911291
const char *working_tree_encoding; /* Supported encoding or default encoding if NULL */
12921292
};
12931293

1294-
static void convert_attrs(struct conv_attrs *ca, const char *path)
1294+
static void convert_attrs(const struct index_state *istate,
1295+
struct conv_attrs *ca, const char *path)
12951296
{
12961297
static struct attr_check *check;
12971298

@@ -1303,7 +1304,7 @@ static void convert_attrs(struct conv_attrs *ca, const char *path)
13031304
git_config(read_convert_config, NULL);
13041305
}
13051306

1306-
if (!git_check_attr(&the_index, path, check)) {
1307+
if (!git_check_attr(istate, path, check)) {
13071308
struct attr_check_item *ccheck = check->items;
13081309
ca->crlf_action = git_path_check_crlf(ccheck + 4);
13091310
if (ca->crlf_action == CRLF_UNDEFINED)
@@ -1340,11 +1341,11 @@ static void convert_attrs(struct conv_attrs *ca, const char *path)
13401341
ca->crlf_action = CRLF_AUTO_INPUT;
13411342
}
13421343

1343-
int would_convert_to_git_filter_fd(const char *path)
1344+
int would_convert_to_git_filter_fd(const struct index_state *istate, const char *path)
13441345
{
13451346
struct conv_attrs ca;
13461347

1347-
convert_attrs(&ca, path);
1348+
convert_attrs(istate, &ca, path);
13481349
if (!ca.drv)
13491350
return 0;
13501351

@@ -1359,11 +1360,11 @@ int would_convert_to_git_filter_fd(const char *path)
13591360
return apply_filter(path, NULL, 0, -1, NULL, ca.drv, CAP_CLEAN, NULL);
13601361
}
13611362

1362-
const char *get_convert_attr_ascii(const char *path)
1363+
const char *get_convert_attr_ascii(const struct index_state *istate, const char *path)
13631364
{
13641365
struct conv_attrs ca;
13651366

1366-
convert_attrs(&ca, path);
1367+
convert_attrs(istate, &ca, path);
13671368
switch (ca.attr_action) {
13681369
case CRLF_UNDEFINED:
13691370
return "";
@@ -1392,7 +1393,7 @@ int convert_to_git(const struct index_state *istate,
13921393
int ret = 0;
13931394
struct conv_attrs ca;
13941395

1395-
convert_attrs(&ca, path);
1396+
convert_attrs(istate, &ca, path);
13961397

13971398
ret |= apply_filter(path, src, len, -1, dst, ca.drv, CAP_CLEAN, NULL);
13981399
if (!ret && ca.drv && ca.drv->required)
@@ -1424,7 +1425,7 @@ void convert_to_git_filter_fd(const struct index_state *istate,
14241425
int conv_flags)
14251426
{
14261427
struct conv_attrs ca;
1427-
convert_attrs(&ca, path);
1428+
convert_attrs(istate, &ca, path);
14281429

14291430
assert(ca.drv);
14301431
assert(ca.drv->clean || ca.drv->process);
@@ -1437,14 +1438,15 @@ void convert_to_git_filter_fd(const struct index_state *istate,
14371438
ident_to_git(path, dst->buf, dst->len, dst, ca.ident);
14381439
}
14391440

1440-
static int convert_to_working_tree_internal(const char *path, const char *src,
1441+
static int convert_to_working_tree_internal(const struct index_state *istate,
1442+
const char *path, const char *src,
14411443
size_t len, struct strbuf *dst,
14421444
int normalizing, struct delayed_checkout *dco)
14431445
{
14441446
int ret = 0, ret_filter = 0;
14451447
struct conv_attrs ca;
14461448

1447-
convert_attrs(&ca, path);
1449+
convert_attrs(istate, &ca, path);
14481450

14491451
ret |= ident_to_worktree(path, src, len, dst, ca.ident);
14501452
if (ret) {
@@ -1478,22 +1480,25 @@ static int convert_to_working_tree_internal(const char *path, const char *src,
14781480
return ret | ret_filter;
14791481
}
14801482

1481-
int async_convert_to_working_tree(const char *path, const char *src,
1483+
int async_convert_to_working_tree(const struct index_state *istate,
1484+
const char *path, const char *src,
14821485
size_t len, struct strbuf *dst,
14831486
void *dco)
14841487
{
1485-
return convert_to_working_tree_internal(path, src, len, dst, 0, dco);
1488+
return convert_to_working_tree_internal(istate, path, src, len, dst, 0, dco);
14861489
}
14871490

1488-
int convert_to_working_tree(const char *path, const char *src, size_t len, struct strbuf *dst)
1491+
int convert_to_working_tree(const struct index_state *istate,
1492+
const char *path, const char *src,
1493+
size_t len, struct strbuf *dst)
14891494
{
1490-
return convert_to_working_tree_internal(path, src, len, dst, 0, NULL);
1495+
return convert_to_working_tree_internal(istate, path, src, len, dst, 0, NULL);
14911496
}
14921497

14931498
int renormalize_buffer(const struct index_state *istate, const char *path,
14941499
const char *src, size_t len, struct strbuf *dst)
14951500
{
1496-
int ret = convert_to_working_tree_internal(path, src, len, dst, 1, NULL);
1501+
int ret = convert_to_working_tree_internal(istate, path, src, len, dst, 1, NULL);
14971502
if (ret) {
14981503
src = dst->buf;
14991504
len = dst->len;
@@ -1927,12 +1932,14 @@ static struct stream_filter *ident_filter(const struct object_id *oid)
19271932
* Note that you would be crazy to set CRLF, smuge/clean or ident to a
19281933
* large binary blob you would want us not to slurp into the memory!
19291934
*/
1930-
struct stream_filter *get_stream_filter(const char *path, const struct object_id *oid)
1935+
struct stream_filter *get_stream_filter(const struct index_state *istate,
1936+
const char *path,
1937+
const struct object_id *oid)
19311938
{
19321939
struct conv_attrs ca;
19331940
struct stream_filter *filter = NULL;
19341941

1935-
convert_attrs(&ca, path);
1942+
convert_attrs(istate, &ca, path);
19361943
if (ca.drv && (ca.drv->process || ca.drv->smudge || ca.drv->clean))
19371944
return NULL;
19381945

convert.h

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -60,15 +60,18 @@ extern char *check_roundtrip_encoding;
6060
const char *get_cached_convert_stats_ascii(const struct index_state *istate,
6161
const char *path);
6262
const char *get_wt_convert_stats_ascii(const char *path);
63-
const char *get_convert_attr_ascii(const char *path);
63+
const char *get_convert_attr_ascii(const struct index_state *istate,
64+
const char *path);
6465

6566
/* returns 1 if *dst was used */
6667
int convert_to_git(const struct index_state *istate,
6768
const char *path, const char *src, size_t len,
6869
struct strbuf *dst, int conv_flags);
69-
int convert_to_working_tree(const char *path, const char *src,
70+
int convert_to_working_tree(const struct index_state *istate,
71+
const char *path, const char *src,
7072
size_t len, struct strbuf *dst);
71-
int async_convert_to_working_tree(const char *path, const char *src,
73+
int async_convert_to_working_tree(const struct index_state *istate,
74+
const char *path, const char *src,
7275
size_t len, struct strbuf *dst,
7376
void *dco);
7477
int async_query_available_blobs(const char *cmd,
@@ -86,7 +89,8 @@ void convert_to_git_filter_fd(const struct index_state *istate,
8689
const char *path, int fd,
8790
struct strbuf *dst,
8891
int conv_flags);
89-
int would_convert_to_git_filter_fd(const char *path);
92+
int would_convert_to_git_filter_fd(const struct index_state *istate,
93+
const char *path);
9094

9195
/*****************************************************************
9296
*
@@ -96,7 +100,8 @@ int would_convert_to_git_filter_fd(const char *path);
96100

97101
struct stream_filter; /* opaque */
98102

99-
struct stream_filter *get_stream_filter(const char *path,
103+
struct stream_filter *get_stream_filter(const struct index_state *istate,
104+
const char *path,
100105
const struct object_id *);
101106
void free_stream_filter(struct stream_filter *);
102107
int is_null_stream_filter(struct stream_filter *);

diff.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3893,7 +3893,7 @@ static void prep_temp_blob(const char *path, struct diff_tempfile *temp,
38933893
temp->tempfile = mks_tempfile_ts(tempfile.buf, strlen(base) + 1);
38943894
if (!temp->tempfile)
38953895
die_errno("unable to create temp-file");
3896-
if (convert_to_working_tree(path,
3896+
if (convert_to_working_tree(&the_index, path,
38973897
(const char *)blob, (size_t)size, &buf)) {
38983898
blob = buf.buf;
38993899
size = buf.len;

entry.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -266,7 +266,7 @@ static int write_entry(struct cache_entry *ce,
266266
const struct submodule *sub;
267267

268268
if (ce_mode_s_ifmt == S_IFREG) {
269-
struct stream_filter *filter = get_stream_filter(ce->name,
269+
struct stream_filter *filter = get_stream_filter(&the_index, ce->name,
270270
&ce->oid);
271271
if (filter &&
272272
!streaming_write_entry(ce, path, filter,
@@ -314,14 +314,14 @@ static int write_entry(struct cache_entry *ce,
314314
* Convert from git internal format to working tree format
315315
*/
316316
if (dco && dco->state != CE_NO_DELAY) {
317-
ret = async_convert_to_working_tree(ce->name, new_blob,
317+
ret = async_convert_to_working_tree(&the_index, ce->name, new_blob,
318318
size, &buf, dco);
319319
if (ret && string_list_has_string(&dco->paths, ce->name)) {
320320
free(new_blob);
321321
goto delayed;
322322
}
323323
} else
324-
ret = convert_to_working_tree(ce->name, new_blob, size, &buf);
324+
ret = convert_to_working_tree(&the_index, ce->name, new_blob, size, &buf);
325325

326326
if (ret) {
327327
free(new_blob);

merge-recursive.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -966,7 +966,7 @@ static int update_file_flags(struct merge_options *o,
966966
}
967967
if (S_ISREG(mode)) {
968968
struct strbuf strbuf = STRBUF_INIT;
969-
if (convert_to_working_tree(path, buf, size, &strbuf)) {
969+
if (convert_to_working_tree(&the_index, path, buf, size, &strbuf)) {
970970
free(buf);
971971
size = strbuf.len;
972972
buf = strbuf_detach(&strbuf, NULL);

sha1-file.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1860,7 +1860,7 @@ static int index_stream_convert_blob(struct object_id *oid, int fd,
18601860
struct strbuf sbuf = STRBUF_INIT;
18611861

18621862
assert(path);
1863-
assert(would_convert_to_git_filter_fd(path));
1863+
assert(would_convert_to_git_filter_fd(&the_index, path));
18641864

18651865
convert_to_git_filter_fd(&the_index, path, fd, &sbuf,
18661866
get_conv_flags(flags));
@@ -1950,7 +1950,7 @@ int index_fd(struct object_id *oid, int fd, struct stat *st,
19501950
* Call xsize_t() only when needed to avoid potentially unnecessary
19511951
* die() for large files.
19521952
*/
1953-
if (type == OBJ_BLOB && path && would_convert_to_git_filter_fd(path))
1953+
if (type == OBJ_BLOB && path && would_convert_to_git_filter_fd(&the_index, path))
19541954
ret = index_stream_convert_blob(oid, fd, path, flags);
19551955
else if (!S_ISREG(st->st_mode))
19561956
ret = index_pipe(oid, fd, type, path, flags);

0 commit comments

Comments
 (0)