All of lore.kernel.org
 help / color / mirror / Atom feed
From: "Ævar Arnfjörð Bjarmason" <avarab@gmail.com>
To: ZheNing Hu via GitGitGadget <gitgitgadget@gmail.com>
Cc: git@vger.kernel.org, Junio C Hamano <gitster@pobox.com>,
	Christian Couder <christian.couder@gmail.com>,
	ZheNing Hu <adlternative@gmail.com>
Subject: Re: [PATCH 2/2] ls-files: introduce "--object-only" option
Date: Wed, 15 Jun 2022 22:15:45 +0200	[thread overview]
Message-ID: <220615.865yl1y8qh.gmgdl@evledraar.gmail.com> (raw)
In-Reply-To: <81ae1280e8eb471c7a11dceb0aa7a8915948b2ce.1655300752.git.gitgitgadget@gmail.com>


On Wed, Jun 15 2022, ZheNing Hu via GitGitGadget wrote:

> From: ZheNing Hu <adlternative@gmail.com>
>
> --object-only is an alias for --format=%(objectname),
> which output objectname of index entries, taking
> inspiration from the option with the same name in
> the `git ls-tree` command.
>
> --object-only cannot be used with --format, and -s, -o,
> -k, --resolve-undo, --deduplicate, --debug.
>
> Signed-off-by: ZheNing Hu <adlternative@gmail.com>
> ---
>  Documentation/git-ls-files.txt |  8 +++++++-
>  builtin/ls-files.c             | 36 +++++++++++++++++++++++++++++++++-
>  t/t3013-ls-files-format.sh     | 34 ++++++++++++++++++++++++++++++++
>  3 files changed, 76 insertions(+), 2 deletions(-)
>
> diff --git a/Documentation/git-ls-files.txt b/Documentation/git-ls-files.txt
> index b22860ec8c0..c3f46bb821b 100644
> --- a/Documentation/git-ls-files.txt
> +++ b/Documentation/git-ls-files.txt
> @@ -13,7 +13,7 @@ SYNOPSIS
>  		[-c|--cached] [-d|--deleted] [-o|--others] [-i|--|ignored]
>  		[-s|--stage] [-u|--unmerged] [-k|--|killed] [-m|--modified]
>  		[--directory [--no-empty-directory]] [--eol]
> -		[--deduplicate]
> +		[--deduplicate] [--object-only]
>  		[-x <pattern>|--exclude=<pattern>]
>  		[-X <file>|--exclude-from=<file>]
>  		[--exclude-per-directory=<file>]
> @@ -199,6 +199,12 @@ followed by the  ("attr/<eolattr>").
>  	interpolates to `\0` (NUL), `%09` to `\t` (TAB) and %0a to `\n` (LF).
>  	--format cannot be combined with `-s`, `-o`, `-k`, `--resolve-undo`,
>  	`--debug`.
> +
> +--object-only::
> +	List only names of the objects, one per line. This is equivalent
> +	to specifying `--format='%(objectname)'`. Cannot be combined with
> +	`--format=<format>`.
> +
>  \--::
>  	Do not interpret any more arguments as options.
>  
> diff --git a/builtin/ls-files.c b/builtin/ls-files.c
> index 9dd6c55eeb9..4ac8f34baac 100644
> --- a/builtin/ls-files.c
> +++ b/builtin/ls-files.c
> @@ -60,6 +60,27 @@ static const char *tag_modified = "";
>  static const char *tag_skip_worktree = "";
>  static const char *tag_resolve_undo = "";
>  
> +static enum ls_files_cmdmode {
> +	MODE_DEFAULT = 0,
> +	MODE_OBJECT_ONLY,
> +} ls_files_cmdmode;
> +
> +struct ls_files_cmdmodee_to_fmt {
> +	enum ls_files_cmdmode mode;
> +	const char *const fmt;
> +};
> +
> +static struct ls_files_cmdmodee_to_fmt ls_files_cmdmode_format[] = {
> +	{
> +		.mode = MODE_DEFAULT,
> +		.fmt = NULL,
> +	},
> +	{
> +		.mode = MODE_OBJECT_ONLY,
> +		.fmt = "%(objectname)",
> +	},
> +};
[...snip...]

This code all looks OK from skimming it, and is substantially copied
from builtin/ls-tree.c (which is good).

But I wonder as in that case whether having such an alias is worth it at
all, especially since in the case of ls-files (unlike ls-tree) we don't
start out with various --just-the-X-field type options, this is the
first one.

So I *really* like that you took my suggestion of "why not a --format"
from a previous round, but given the above for ls-files in particular is
it really worth it to have this extra code just to type:

    --object-only

Instead of:

    --format="%(objectname)"

So, maybe, and I'm not set against it, but I think it's worth
re-evaluating in this case.

In particular because the part of ls-tree's code is missing here where
we "format optimize", i.e. we take a form like:

    --format="%(objectname)"

And dispatch it to the more optimized special function, instead of the
generic strbuf_expand(), whereas in this case it's the other way around,
the option is just an alias for --format.

  reply	other threads:[~2022-06-15 20:25 UTC|newest]

Thread overview: 61+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-06-15 13:45 [PATCH 0/2] ls-files: introduce "--format" and "--object-only" options ZheNing Hu via GitGitGadget
2022-06-15 13:45 ` [PATCH 1/2] ls-files: introduce "--format" option ZheNing Hu via GitGitGadget
2022-06-15 20:07   ` Ævar Arnfjörð Bjarmason
2022-06-18 10:50     ` ZheNing Hu
2022-06-15 13:45 ` [PATCH 2/2] ls-files: introduce "--object-only" option ZheNing Hu via GitGitGadget
2022-06-15 20:15   ` Ævar Arnfjörð Bjarmason [this message]
2022-06-18 10:59     ` ZheNing Hu
2022-06-19  9:13 ` [PATCH v2] ls-files: introduce "--format" option ZheNing Hu via GitGitGadget
2022-06-19 13:50   ` Phillip Wood
2022-06-20 13:32     ` ZheNing Hu
2022-06-21  2:05   ` [PATCH v3] " ZheNing Hu via GitGitGadget
2022-06-23 14:06     ` Phillip Wood
2022-06-23 15:57       ` Junio C Hamano
2022-06-24 10:16         ` Phillip Wood
2022-06-26 13:05           ` ZheNing Hu
2022-06-24 13:20         ` Ævar Arnfjörð Bjarmason
2022-06-24 15:28           ` Junio C Hamano
2022-06-26 13:01       ` ZheNing Hu
2022-06-24 13:25     ` Ævar Arnfjörð Bjarmason
2022-06-24 15:33       ` Junio C Hamano
2022-06-26 13:35         ` ZheNing Hu
2022-06-27  8:22           ` Junio C Hamano
2022-06-27 11:06             ` ZheNing Hu
2022-06-27 15:41               ` Junio C Hamano
2022-07-01 13:30                 ` ZheNing Hu
2022-06-26 13:34       ` ZheNing Hu
2022-06-26 15:29     ` [PATCH v4] " ZheNing Hu via GitGitGadget
2022-06-27  8:32       ` Junio C Hamano
2022-06-27 11:18         ` ZheNing Hu
2022-06-27 18:34       ` Ævar Arnfjörð Bjarmason
2022-07-01 12:42         ` ZheNing Hu
2022-06-28 15:19       ` Phillip Wood
2022-07-01 12:47         ` ZheNing Hu
2022-07-05  6:32       ` [PATCH v5] " ZheNing Hu via GitGitGadget
2022-07-05  8:39         ` Ævar Arnfjörð Bjarmason
2022-07-11 15:14           ` ZheNing Hu
2022-07-05 19:28         ` Torsten Bögershausen
2022-07-11 15:27           ` ZheNing Hu
2022-07-11 16:53         ` [PATCH v6] " ZheNing Hu via GitGitGadget
2022-07-11 22:11           ` Junio C Hamano
2022-07-12 13:53             ` ZheNing Hu
2022-07-12 14:34               ` Junio C Hamano
2022-07-13  6:07           ` [PATCH v7] " ZheNing Hu via GitGitGadget
2022-07-18  8:09             ` Ævar Arnfjörð Bjarmason
2022-07-19 16:19               ` ZheNing Hu
2022-07-19 16:47                 ` Junio C Hamano
2022-07-19 17:21                   ` ZheNing Hu
2022-07-20 16:36             ` [PATCH v8] " ZheNing Hu via GitGitGadget
2022-07-20 17:37               ` Junio C Hamano
2022-07-21 15:54                 ` Ævar Arnfjörð Bjarmason
2022-07-21 17:22                   ` Eric Sunshine
2022-07-21 17:23                   ` Junio C Hamano
2022-07-22  6:44                 ` ZheNing Hu
2022-07-23 18:40                   ` Junio C Hamano
2022-07-23 18:46                     ` Junio C Hamano
2022-07-24 11:08                     ` ZheNing Hu
2022-07-25  1:03                       ` Junio C Hamano
2022-07-25 11:00                         ` ZheNing Hu
2022-07-23  6:44               ` [PATCH v9] " ZheNing Hu via GitGitGadget
2022-09-08  2:01                 ` Jiang Xin
2022-09-11 11:01                   ` ZheNing Hu

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=220615.865yl1y8qh.gmgdl@evledraar.gmail.com \
    --to=avarab@gmail.com \
    --cc=adlternative@gmail.com \
    --cc=christian.couder@gmail.com \
    --cc=git@vger.kernel.org \
    --cc=gitgitgadget@gmail.com \
    --cc=gitster@pobox.com \
    /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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.