Re: [PATCH v3] ls-files: Add eol diagnostics
- From
Eric Sunshine <sunshine@sunshineco.com>
- Date
- Nov 23, 2015, 17:27 UTC
- Message-ID
- <CAPig+cTuG-vApbJfuNYxFwbkNq5wpJig6Lmxhi47CCYpMWx2iA@mail.gmail.com>
- In-Reply-To
- <56501EFA.7050105@web.de>
On Sat, Nov 21, 2015 at 2:36 AM, Torsten Bögershausen <tboegi@web.de> wrote:
Show 6 quoted lines
> When working in a cross-platform environment, a user wants to > check if text files are stored normalized in the repository and if > .gitattributes are set appropriately. > > Make it possible to let Git show the line endings in the index and > in the working tree and the effective text/eol attributes
s/$/./
Show 14 quoted lines
> [...]
> Signed-off-by: Torsten Bögershausen <tboegi@web.de>
> ---
> diff --git a/Documentation/git-ls-files.txt b/Documentation/git-ls-files.txt
> @@ -147,6 +148,18 @@ a space) at the start of each line:
> possible for manual inspection; the exact format may change at
> any time.
>
> +--eol::
> + Show line endings ("eolinfo") and the text/eol attributes ("texteolattr") of files.
> + "eolinfo" is the file content identification used by Git when
> + the "text" attribute is "auto", or core.autocrlf != false.
> +
> + "eolinfo" is either "" (when the the info is not avaiable"), or one of "binary",s/avaiable/available/
Show 5 quoted lines
> + "text-no-eol", "text-lf", "text-crlf" or "text-crlf-lf".
> + The "texteolattr" can be "", "-text", "text", "text=auto", "eol=lf", "eol=crlf".
> +
> + Both the content in the index ("i/") and the content in the working tree ("w/")
> + are shown for regular files, followed by the "exteolattr ("attr/").s/exteolattr/texteolattr/
Should the documentation mention that with --eol ls-files becomes a much more expensive operation since it now has to read all blobs referenced by trees? (genuine question)
Show 11 quoted lines
> diff --git a/builtin/check-attr.c b/builtin/check-attr.c
> @@ -51,6 +53,23 @@ static void output_attr(int cnt, struct git_attr_check *check,
> +static void output_eol_attr(const char *file)
> +{
> + struct stat st;
> + if (lstat(file, &st) || (!S_ISREG(st.st_mode)))
> + return;
> + if (nul_term_line) {
> + printf("%s:", file);
> + if (!lstat(file, &st) && (S_ISREG(st.st_mode)))
> + printf(": %-13s ", get_convert_attr_ascii(file));Why the trailing space in the format string?
> + printf("%c", 0);putc('\0') perhaps?> + } else {
> + quote_c_style(file, NULL, stdout, 0);
> + printf(": %-13s ", get_convert_attr_ascii(file));Ditto regarding trailing space.
> + printf("\n");Is there a reason the "\n" isn't incorporated into the preceding printf's format string?
Show 15 quoted lines
> + }
> +}
> diff --git a/t/t0027-auto-crlf.sh b/t/t0027-auto-crlf.sh
> @@ -213,7 +238,18 @@ checkout_files () {
> git -c core.eol=$eol checkout $src$f.txt
> fi
> done
> -
> + test_expect_success "ls-files --eol $lfname ${pfx}LF.txt" "
> + echo i/text-lf w/$(stats_ascii $lfname) ${src}LF.txt >e &&
> + echo i/text-crlf w/$(stats_ascii $crlfname) ${src}CRLF.txt >>e &&
> + echo i/text-crlf-lf w/$(stats_ascii $lfmixcrlf) ${src}CRLF_mix_LF.txt >>e &&
> + echo i/binary w/$(stats_ascii $lfmixcr) ${src}LF_mix_CR.txt >>e &&
> + echo i/binary w/$(stats_ascii $crlfnul) ${src}CRLF_nul.txt >>e &&
> + echo i/binary w/$(stats_ascii $crlfnul) ${src}LF_nul.txt >>e &&I wonder if a here-doc would make this a bit more readable and maintainable...
echo >e <<-EOF &&
i/text-lf w/$(stats_ascii $lfname) ${src}LF.txt
i/text-crlf w/$(stats_ascii $crlfname) ${src}CRLF.txt
i/text-crlf-lf w/$(stats_ascii $lfmixcrlf) ${src}CRLF_mix_LF.txt
i/binary w/$(stats_ascii $lfmixcr) ${src}LF_mix_CR.txt
i/binary w/$(stats_ascii $crlfnul) ${src}CRLF_nul.txt
i/binary w/$(stats_ascii $crlfnul) ${src}LF_nul.txt
EOFShow 33 quoted lines
> + sort <e >exp &&
> + git ls-files --eol $src* | sed -e 's!attr/[=a-z-]*!!g' -e 's/ */ /g' | sort >act &&
> + test_cmp exp act &&
> + rm e exp act
> + "
> @@ -231,6 +267,35 @@ checkout_files () {
> "
> }
>
> +# Test control characters
> +# NUL SOH CR EOF==^Z
> +test_expect_success 'ls-files --eol -o Text/Binary' '
> + test_when_finished "rm e exp act TeBi_*" &&
> + STRT=AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA &&
> + STR=$STRT$STRT$STRT$STRT &&
> + printf "${STR}BBB\001" >TeBi_127_S &&
> + printf "${STR}BBBB\001">TeBi_128_S &&
> + printf "${STR}BBB\032" >TeBi_127_E &&
> + printf "\032${STR}BBB" >TeBi_E_127 &&
> + printf "${STR}BBBB\000">TeBi_128_N &&
> + printf "${STR}BBB\012">TeBi_128_L &&
> + printf "${STR}BBB\015">TeBi_127_C &&
> + printf "${STR}BB\015\012" >TeBi_126_CL &&
> + printf "${STR}BB\015\012\015" >TeBi_126_CLC &&
> + echo i/ w/binary TeBi_127_S >e &&
> + echo i/ w/text-no-eol TeBi_128_S >>e &&
> + echo i/ w/text-no-eol TeBi_127_E >>e &&
> + echo i/ w/binary TeBi_E_127 >>e &&
> + echo i/ w/binary TeBi_128_N >>e &&
> + echo i/ w/text-lf TeBi_128_L >>e &&
> + echo i/ w/binary TeBi_127_C >>e &&
> + echo i/ w/text-crlf TeBi_126_CL >>e &&
> + echo i/ w/binary TeBi_126_CLC >>e &&here-doc equivalent:
echo >e <<-\EOF &&
i/ w/binary TeBi_127_S
i/ w/text-no-eol TeBi_128_S
i/ w/text-no-eol TeBi_127_E
i/ w/binary TeBi_E_127
i/ w/binary TeBi_128_N
i/ w/text-lf TeBi_128_L
i/ w/binary TeBi_127_C
i/ w/text-crlf TeBi_126_CL
i/ w/binary TeBi_126_CLC
EOFShow 13 quoted lines
> + sort <e >exp && > + git ls-files --eol -o | egrep "TeBi_" | sed -e 's!attr/[=a-z-]*!!g' -e "s/ */ /g" | sort >act && > + test_cmp exp act > +' > + > @@ -480,4 +545,19 @@ checkout_files native true "lf" LF CRLF CRLF_mix_LF LF_mix_CR > +# Should be the last test case > +test_expect_success 'ls-files --eol -d' " > + rm crlf_false_attr__CRLF.txt crlf_false_attr__CRLF_mix_LF.txt crlf_false_attr__LF.txt .gitattributes && > + echo i/text-lf w/ .gitattributes >e && > + echo i/text-crlf w/ crlf_false_attr__CRLF.txt >>e && > + echo i/text-crlf-lf w/ crlf_false_attr__CRLF_mix_LF.txt >>e && > + echo i/text-lf w/ crlf_false_attr__LF.txt >>e &&
echo >e <<-\EOF &&
i/text-lf w/ .gitattributes
i/text-crlf w/ crlf_false_attr__CRLF.txt
i/text-crlf-lf w/ crlf_false_attr__CRLF_mix_LF.txt
i/text-lf w/ crlf_false_attr__LF.txt
EOFShow 10 quoted lines
> + sort <e >exp && > + git ls-files --eol -d | sed -e 's!attr/[=a-z-]*!!g' -e 's/ */ /g' | sort >act && > + test_cmp exp act && > + rm e exp act > +" > + > + > test_done > -- > 2.6.1.443.g36d7748