git.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Eric Sunshine <sunshine@sunshineco.com>
To: "Torsten Bögershausen" <tboegi@web.de>
Cc: Git List <git@vger.kernel.org>
Subject: Re: [PATCH v3] ls-files: Add eol diagnostics
Date: Mon, 23 Nov 2015 12:27:53 -0500	[thread overview]
Message-ID: <CAPig+cTuG-vApbJfuNYxFwbkNq5wpJig6Lmxhi47CCYpMWx2iA@mail.gmail.com> (raw)
In-Reply-To: <56501EFA.7050105@web.de>

On Sat, Nov 21, 2015 at 2:36 AM, Torsten Bögershausen <tboegi@web.de> wrote:
> 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/$/./

> [...]
> 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/

> +       "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)

> 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?

> +       }
> +}
> 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
    EOF

> +               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
    EOF

> +       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
    EOF

> +       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

      parent reply	other threads:[~2015-11-23 17:27 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-11-21  7:36 [PATCH v3] ls-files: Add eol diagnostics Torsten Bögershausen
2015-11-22  8:20 ` Sebastian Schuberth
2015-11-23 17:05   ` Torsten Bögershausen
2015-11-23 19:45     ` Sebastian Schuberth
2015-11-23 20:00       ` Eric Sunshine
2015-11-24 16:45     ` Ramsay Jones
2015-11-23 17:27 ` Eric Sunshine [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=CAPig+cTuG-vApbJfuNYxFwbkNq5wpJig6Lmxhi47CCYpMWx2iA@mail.gmail.com \
    --to=sunshine@sunshineco.com \
    --cc=git@vger.kernel.org \
    --cc=tboegi@web.de \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).