Subject: Re: [PATCH v4] ls-files: introduce "--format" option

From: Ævar Arnfjörð Bjarmason <[email-masked]>
Date: Mon, 27 Jun 2022 20:34:30 +0200

On Sun, Jun 26 2022, ZheNing Hu via GitGitGadget wrote:

> From: ZheNing Hu <[email-masked]>
>
> 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.
>
> --format cannot used with -s, -o, -k, --resolve-undo,
> --deduplicate and --eol.
>
> Signed-off-by: ZheNing Hu <[email-masked]>
> ---
> [...]
> +test_expect_success 'git ls-files --format with --debug' '
> +	git ls-files --debug >expect &&
> +	git ls-files --format="%(path)" --debug >actual &&
> +	test_cmp expect actual
> +'
> +
> +test_done

I'm not sure what to make of this.

In some ways I think this makes more sense than what I suggested in
https://lore.kernel.org/git/[email-masked]/;
but I had to think for a second about what's going on here.

In my version I suggested having this work with --debug, but not in this
way, in my version you'd always emit the debug output, and the format
output.

But here e.g.:

    git ls-files -t --debug

Will emit "H tag.c" or whatever, but if you add --format the -t option
is silently discarded.

So the test is relying on "%(path)" being the default format.

I think extending this to e.g. test what happens with "-t" would be a
good thing, but also in general does combining --format with -t make
sense, and are there other such options where the combination might not
make sense?

So I'm not 100% sure, but I think I'd prefer my version, but I see how
it would get hairy to support, e.g.:

    git ls-files -s --debug --format=...

Should work, but you'd have to special-case the logic for erroring if -s
is combined with --format.

Anyway, I think it would be fine to leave this in whatever state is
easy, the --debug option "just for debugging".

But re
https://lore.kernel.org/git/[email-masked]/
I think it might be interesting to get --format to a state where we can
remove --debug entirely.

I.e. in c2a29405105 (t1091/t3705: remove 'test-tool read-cache --table',
2021-12-22) we could replace some similar test-only code with "git
ls-files". I for one wouldn't mind --debug going away entirely, and have
the t3705-add-sparse-checkout.sh tests use --format instead.

Or we could keep --debug, but just have it powerful enough to do what
print_debug() is doing now, possibly without "truly internal" stuff like
"ce_flags".