Re: [PATCH v3] ls-files: introduce "--format" option
- From
ZheNing Hu <adlternative@gmail.com>
- Date
- Jun 26, 2022, 13:01 UTC
- Message-ID
- <CAOLTT8R1fQoH7cEWcE42+fjxu_iGBxDJy5Cgff6Bj9YH2f0--g@mail.gmail.com>
- In-Reply-To
- <080f65b3-91f5-7b68-4235-4bfb956c8321@gmail.com>
Phillip Wood <phillip.wood123@gmail.com> 于2022年6月23日周四 22:06写道:
Show 33 quoted lines
> > Hi ZheNing > > [...] > > +It is possible to print in a custom format by using the `--format` > > +option, which is able to interpolate different fields using > > +a `%(fieldname)` notation. For example, if you only care about the > > +"objectname" and "path" fields, you can execute with a specific > > +"--format" like > > + > > + git ls-files --format='%(objectname) %(path)' > > + > > +FIELD NAMES > > +----------- > > +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 in the index. > > +objectname:: > > + The name of the file which is in the index. > > +stage:: > > + The stage of the file which is in the index. > > +eol:: > > + The <eolinfo> and <eolattr> of files both in the > > + index and the work-tree. > > Looking at the test for this option I think it needs more work, why > should --format arbitrarily append a tab to the end of the output? - the > user should be able to specify a separator if they want one as part of > the format string. Also I'm not sure why there is so much whitespace in > the output. >
Because I used old output format in write_eolinfo(), now I think it's wrong, I will separate it to three parts: %(eolinfo:index), %(eolinfo:worktree), %(eolattr).
Show 7 quoted lines
> If %(flags) is going to be useful then I think we need to think about > how they are printed and document that. At the moment they are printed > as a hexadecimal number which is fine for debugging but probably not > going to be useful for something like --format. I think printing > documented symbolic names with some kind of separator (a comma maybe) > between them is probably more useful >
Agree.
Show 9 quoted lines
> > [...] > > +test_expect_success 'git ls-files --format eol' ' > > + printf "i/lf w/lf attr/ \t\n" >expect && > > + printf "i/lf w/lf attr/ \t\n" >>expect && > > + git ls-files --format="%(eol)" --eol >actual && > > I'm not sure why this is passing --eol as well as --format='%(eol)' - > shouldn't that combination of flags be an error? >
Thank you for reminding, will be corrected.
> Best Wishes > > Phillip
ZheNing Hu