Re: [PATCH 05/16] index-info.c: identify empty input lines in read_index_info
- From
Victoria Dye <vdye@github.com>
- Date
- Jun 18, 2024, 17:33 UTC
- Message-ID
- <96f0ca92-b30f-4a7a-bf67-1967d8399177@github.com>
- In-Reply-To
- <xmqq34pjt7m2.fsf@gitster.g>
Junio C Hamano wrote:
Show 21 quoted lines
> "Victoria Dye via GitGitGadget" <gitgitgadget@gmail.com> writes: > >> From: Victoria Dye <vdye@github.com> >> >> Update 'read_index_info()' to return INDEX_INFO_EMPTY_LINE (value 1), rather >> than the default error code (value -1) when the function encounters an empty >> line in stdin. This grants the caller the flexibility to handle such >> scenarios differently than a typical error. In the case of 'update-index', >> we'll still exit with a "malformed input line" error. However, when >> 'read_index_info()' is used to process the input to 'mktree' in a later >> patch, the empty line return value will signal a new tree in --batch mode. > > Interesting. We could even introduce "# commented input" but that > is a different story ;-). > > I also wonder if we can flip it around and teach read_index_info() > to (1) silently accept and do a callback when it recognises the > input line is one of the supported formats, and (2) send any > unrecognised line, not just an empty one, with "unrecognised" status > code. That way, the caller can handle more than single kind of > "special input line" more easily, perhaps?
This is an interesting idea. The simplest way to do this would probably to have 'bad_line' stop printing the "malformed input line" error and instead return INDEX_INFO_UNRECOGNIZED_LINE, and pass in a strbuf so that the "malformed" line is available to the caller.
That seems simple enough, so I'll include it in V2; I can always revert back to INDEX_INFO_EMPTY_LINE if the generalized approach doesn't work out for some reason.
> > Thanks.