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 <tboegi@web.de> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Torsten Bögershausen committed
Feb 5, 2016 at 17:13 UTC
bb211b4de83b7cbc93049bc0d73883083a6a8b0b
1 file changed
+14
-23
convert.c
+14
-23
@@ -746,21 +746,10 @@ static int git_path_check_ident(struct git_attr_check *check)
746
return !!ATTR_TRUE(value);
747
}
748
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
-
749
struct conv_attrs {
750
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 */
753
int ident;
754
};
755
@@ -782,16 +771,23 @@ static void convert_attrs(struct conv_attrs *ca, const char *path)
771
}
772
773
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);
776
if (ca->crlf_action == CRLF_GUESS)
777
ca->crlf_action = git_path_check_crlf(ccheck + 0);
778
+ ca->attr_action = ca->crlf_action;
779
ca->ident = git_path_check_ident(ccheck + 1);
780
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;
788
} else {
789
ca->drv = NULL;
790
ca->crlf_action = CRLF_GUESS;
794
- ca->eol_attr = EOL_UNSET;
791
ca->ident = 0;
792
}
793
}
@@ -818,11 +814,9 @@ int would_convert_to_git_filter_fd(const char *path)
814
const char *get_convert_attr_ascii(const char *path)
815
{
816
struct conv_attrs ca;
821
- enum crlf_action crlf_action;
817
818
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) {
820
case CRLF_GUESS:
821
return "";
822
case CRLF_BINARY:
@@ -861,7 +855,6 @@ int convert_to_git(const char *path, const char *src, size_t len,
855
src = dst->buf;
856
len = dst->len;
857
}
864
- ca.crlf_action = input_crlf_action(ca.crlf_action, ca.eol_attr);
858
ret |= crlf_to_git(path, src, len, dst, ca.crlf_action, checksafe);
859
if (ret && dst) {
860
src = dst->buf;
@@ -882,7 +875,6 @@ void convert_to_git_filter_fd(const char *path, int fd, struct strbuf *dst,
875
if (!apply_filter(path, NULL, 0, fd, dst, ca.drv->clean))
876
die("%s: clean filter '%s' failed", path, ca.drv->name);
877
885
- ca.crlf_action = input_crlf_action(ca.crlf_action, ca.eol_attr);
878
crlf_to_git(path, dst->buf, dst->len, dst, ca.crlf_action, checksafe);
879
ident_to_git(path, dst->buf, dst->len, dst, ca.ident);
880
}
@@ -912,7 +904,6 @@ static int convert_to_working_tree_internal(const char *path, const char *src,
904
* is a smudge filter. The filter might expect CRLFs.
905
*/
906
if (filter || !normalizing) {
915
- ca.crlf_action = input_crlf_action(ca.crlf_action, ca.eol_attr);
907
ret |= crlf_to_worktree(path, src, len, dst, ca.crlf_action);
908
if (ret) {
909
src = dst->buf;
@@ -1381,7 +1372,7 @@ struct stream_filter *get_stream_filter(const char *path, const unsigned char *s
1372
if (ca.ident)
1373
filter = ident_filter(sha1);
1374
1384
- crlf_action = input_crlf_action(ca.crlf_action, ca.eol_attr);
1375
+ crlf_action = ca.crlf_action;
1376
1377
if ((crlf_action == CRLF_BINARY) || (crlf_action == CRLF_INPUT) ||
1378
(crlf_action == CRLF_GUESS && auto_crlf == AUTO_CRLF_FALSE))