Re: [PATCH 1/3] ls-tree.c: support `--oid-only` option for "git-ls-tree"
- From
Ævar Arnfjörð Bjarmason <avarab@gmail.com>
- Date
- Nov 15, 2021, 15:12 UTC
- Message-ID
- <211115.86r1bhsb8x.gmgdl@evledraar.gmail.com>
- In-Reply-To
- <20211115115153.48307-2-dyroneteng@gmail.com>
lorn Mon, Nov 15 2021, Teng Long wrote:
Show 27 quoted lines
> This commit supply an option names `--oid-only` to let `git ls-tree`
> only print out the OID of the object. `--oid-only` and `--name-only`
> are mutually exclusive in use.
>
> Signed-off-by: Teng Long <dyroneteng@gmail.com>
> ---
> builtin/ls-tree.c | 11 +++++++++++
> 1 file changed, 11 insertions(+)
>
> diff --git a/builtin/ls-tree.c b/builtin/ls-tree.c
> index 3a442631c7..1f82229649 100644
> --- a/builtin/ls-tree.c
> +++ b/builtin/ls-tree.c
> @@ -20,6 +20,7 @@ static int line_termination = '\n';
> #define LS_SHOW_TREES 4
> #define LS_NAME_ONLY 8
> #define LS_SHOW_SIZE 16
> +#define LS_OID_ONLY 32
> static int abbrev;
> static int ls_options;
> static struct pathspec pathspec;
> @@ -90,6 +91,14 @@ static int show_tree(const struct object_id *oid, struct strbuf *base,
> else if (ls_options & LS_TREE_ONLY)
> return 0;
>
> + if ((ls_options & LS_NAME_ONLY) && (ls_options & LS_OID_ONLY))
> + die(_("cannot specify --oid-only and --name-only at the same time"));If you make these an OPT_CMDMODE you get this behavior for free. See e.g. my https://lore.kernel.org/git/patch-v2-06.10-d945fc94774-20211112T221506Z-avarab@gmail.com/