Re: [PATCH v5] ls-files: introduce "--format" option
Torsten Bögershausen <tboegi@web.de> 于2022年7月6日周三 03:28写道:
Show 39 quoted lines
>
> On Tue, Jul 05, 2022 at 06:32:40AM +0000, ZheNing Hu via GitGitGadget wrote:
> > From: ZheNing Hu <adlternative@gmail.com>
> >
> > Add a new option --format that output index enties
> > informations with custom format, taking inspiration
> > from the option with the same name in the `git ls-tree`
> > command.
> []
> > +FIELD NAMES
>
> Nice
>
> > +-----------
> > +Various values from structured fields can be used to interpolate
> > +into the resulting output. For each outputting line, the following
> > +names can be used:
> > +
> > +objectmode::
> > + The mode of the file which is recorded in the index.
> > +objectname::
> > + The name of the file which is recorded in the index.
> > +stage::
> > + The stage of the file which is recorded in the index.
> > +eolinfo:index::
> > +eolinfo:worktree::
> > + The <eolinfo> (see the description of the `--eol` option) of
> > + the contents in the index or in the worktree for the path.
> > +eolattr::
> > + The <eolattr> (see the description of the `--eol` option)
> > + that applies to the path.
>
> This may be a matter of taste, looking at the eol-stuff:
> Should the ':' be dropped and we have 3 fieldnames like this:
>
> eolindex
> eolworktree
> eolattr
>
Let's see the document of --eol in git-ls-files.txt:
--eol::
Show <eolinfo> and <eolattr> of files.
<eolinfo> is the file content identification used by Git when
the "text" attribute is "auto" (or not set and core.autocrlf is not false).
<eolinfo> is either "-text", "none", "lf", "crlf", "mixed" or "".There mentioned eolinfo and eolattr many times, so let's keep it.
Show 33 quoted lines
> > +test_expect_success 'git ls-files --format eolinfo:index' '
> > + cat >expect <<-\EOF &&
> > + lf
> > + lf
> > + EOF
> > + git ls-files --format="%(eolinfo:index)" >actual &&
> > + test_cmp expect actual
> > +'
> > +
> > +test_expect_success 'git ls-files --format eolinfo:worktree' '
> > + cat >expect <<-\EOF &&
> > + lf
> > + lf
> > + EOF
> > + git ls-files --format="%(eolinfo:worktree)" >actual &&
> > + test_cmp expect actual
> > +'
> > +
> > +test_expect_success 'git ls-files --format eolattr' '
> > + printf "\n\n" >expect &&
> > + git ls-files --format="%(eolattr)" >actual &&
> > + test_cmp expect actual
> > +'
> > +
>
> What exactly should this testcases test ?
> Does it make sense to set up a combination of index, worktree, attr,
> which are happening in real live ?
>
> There are some tests in t0025, t0027 and t0028 that do more
> realistic tests of different combinations.
>
>
Origin test is not good, But now I decide use Avar's patch version:
-test_expect_success 'git ls-files --format eolattr' '
- printf "\n\n" >expect &&
- git ls-files --format="%(eolattr)" >actual &&
+HT=' '
+WS=' '
+test_expect_success 'git ls-files --format v.s. --eol' '
+ git ls-files --eol >expect 2>err &&
+ test_must_be_empty err &&
+ git ls-files
--format="i/%(eolinfo:index)${WS}w/%(eolinfo:worktree)${WS}attr/${WS}${WS}${WS}${WS}
${HT}%(path)" >actual 2>err &&
+ test_must_be_empty err &&
test_cmp expect actualit can compare the output of git ls-files --format with git ls-files --eol.
Thanks for review!
ZheNing Hu