Skip to content

Commit bb211b4

Browse files
tboegigitster
authored andcommitted
convert.c: remove input_crlf_action()
Integrate the code of input_crlf_action() into convert_attrs(), so that ca.crlf_action is always valid after calling convert_attrs(). Keep a copy of crlf_action in attr_action, this is needed for get_convert_attr_ascii(). Remove eol_attr from struct conv_attrs, as it is now used temporally. Signed-off-by: Torsten Bögershausen <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 92cce13 commit bb211b4

File tree

1 file changed

+14
-23
lines changed

1 file changed

+14
-23
lines changed

convert.c

Lines changed: 14 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -746,21 +746,10 @@ static int git_path_check_ident(struct git_attr_check *check)
746746
return !!ATTR_TRUE(value);
747747
}
748748

749-
static enum crlf_action input_crlf_action(enum crlf_action text_attr, enum eol eol_attr)
750-
{
751-
if (text_attr == CRLF_BINARY)
752-
return CRLF_BINARY;
753-
if (eol_attr == EOL_LF)
754-
return CRLF_INPUT;
755-
if (eol_attr == EOL_CRLF)
756-
return CRLF_CRLF;
757-
return text_attr;
758-
}
759-
760749
struct conv_attrs {
761750
struct convert_driver *drv;
762-
enum crlf_action crlf_action;
763-
enum eol eol_attr;
751+
enum crlf_action attr_action; /* What attr says */
752+
enum crlf_action crlf_action; /* When no attr is set, use core.autocrlf */
764753
int ident;
765754
};
766755

@@ -782,16 +771,23 @@ static void convert_attrs(struct conv_attrs *ca, const char *path)
782771
}
783772

784773
if (!git_check_attr(path, NUM_CONV_ATTRS, ccheck)) {
785-
ca->crlf_action = git_path_check_crlf( ccheck + 4);
774+
enum eol eol_attr;
775+
ca->crlf_action = git_path_check_crlf(ccheck + 4);
786776
if (ca->crlf_action == CRLF_GUESS)
787777
ca->crlf_action = git_path_check_crlf(ccheck + 0);
778+
ca->attr_action = ca->crlf_action;
788779
ca->ident = git_path_check_ident(ccheck + 1);
789780
ca->drv = git_path_check_convert(ccheck + 2);
790-
ca->eol_attr = git_path_check_eol(ccheck + 3);
781+
if (ca->crlf_action == CRLF_BINARY)
782+
return;
783+
eol_attr = git_path_check_eol(ccheck + 3);
784+
if (eol_attr == EOL_LF)
785+
ca->crlf_action = CRLF_INPUT;
786+
else if (eol_attr == EOL_CRLF)
787+
ca->crlf_action = CRLF_CRLF;
791788
} else {
792789
ca->drv = NULL;
793790
ca->crlf_action = CRLF_GUESS;
794-
ca->eol_attr = EOL_UNSET;
795791
ca->ident = 0;
796792
}
797793
}
@@ -818,11 +814,9 @@ int would_convert_to_git_filter_fd(const char *path)
818814
const char *get_convert_attr_ascii(const char *path)
819815
{
820816
struct conv_attrs ca;
821-
enum crlf_action crlf_action;
822817

823818
convert_attrs(&ca, path);
824-
crlf_action = input_crlf_action(ca.crlf_action, ca.eol_attr);
825-
switch (crlf_action) {
819+
switch (ca.attr_action) {
826820
case CRLF_GUESS:
827821
return "";
828822
case CRLF_BINARY:
@@ -861,7 +855,6 @@ int convert_to_git(const char *path, const char *src, size_t len,
861855
src = dst->buf;
862856
len = dst->len;
863857
}
864-
ca.crlf_action = input_crlf_action(ca.crlf_action, ca.eol_attr);
865858
ret |= crlf_to_git(path, src, len, dst, ca.crlf_action, checksafe);
866859
if (ret && dst) {
867860
src = dst->buf;
@@ -882,7 +875,6 @@ void convert_to_git_filter_fd(const char *path, int fd, struct strbuf *dst,
882875
if (!apply_filter(path, NULL, 0, fd, dst, ca.drv->clean))
883876
die("%s: clean filter '%s' failed", path, ca.drv->name);
884877

885-
ca.crlf_action = input_crlf_action(ca.crlf_action, ca.eol_attr);
886878
crlf_to_git(path, dst->buf, dst->len, dst, ca.crlf_action, checksafe);
887879
ident_to_git(path, dst->buf, dst->len, dst, ca.ident);
888880
}
@@ -912,7 +904,6 @@ static int convert_to_working_tree_internal(const char *path, const char *src,
912904
* is a smudge filter. The filter might expect CRLFs.
913905
*/
914906
if (filter || !normalizing) {
915-
ca.crlf_action = input_crlf_action(ca.crlf_action, ca.eol_attr);
916907
ret |= crlf_to_worktree(path, src, len, dst, ca.crlf_action);
917908
if (ret) {
918909
src = dst->buf;
@@ -1381,7 +1372,7 @@ struct stream_filter *get_stream_filter(const char *path, const unsigned char *s
13811372
if (ca.ident)
13821373
filter = ident_filter(sha1);
13831374

1384-
crlf_action = input_crlf_action(ca.crlf_action, ca.eol_attr);
1375+
crlf_action = ca.crlf_action;
13851376

13861377
if ((crlf_action == CRLF_BINARY) || (crlf_action == CRLF_INPUT) ||
13871378
(crlf_action == CRLF_GUESS && auto_crlf == AUTO_CRLF_FALSE))

0 commit comments

Comments
 (0)