Re: [PATCH 08/15] [GSOC] ref-filter: add cat_file_mode in struct ref_format
- From
Ævar Arnfjörð Bjarmason <avarab@gmail.com>
- Date
- Jul 2, 2021, 13:32 UTC
- Message-ID
- <87czs0alhg.fsf@evledraar.gmail.com>
- In-Reply-To
- <9568baf5dddcc0637c15f698aea24d230c4d01b2.1625155693.git.gitgitgadget@gmail.com>
On Thu, Jul 01 2021, ZheNing Hu via GitGitGadget wrote:
Show 34 quoted lines
> From: ZheNing Hu <adlternative@gmail.com>
>
> Add `cat_file_mode` member in struct `ref_format`, when
> `cat-file --batch` use ref-filter logic later, it can help
> us reject atoms in verify_ref_format() which cat-file cannot
> use, e.g. `%(refname)`, `%(push)`, `%(upstream)`...
>
> Mentored-by: Christian Couder <christian.couder@gmail.com>
> Mentored-by: Hariom Verma <hariom18599@gmail.com>
> Signed-off-by: ZheNing Hu <adlternative@gmail.com>
> ---
> ref-filter.c | 11 +++++++++--
> ref-filter.h | 1 +
> 2 files changed, 10 insertions(+), 2 deletions(-)
>
> diff --git a/ref-filter.c b/ref-filter.c
> index 731e596eaa6..45122959eef 100644
> --- a/ref-filter.c
> +++ b/ref-filter.c
> @@ -1021,8 +1021,15 @@ int verify_ref_format(struct ref_format *format)
> if (at < 0)
> die("%s", err.buf);
>
> - if (used_atom[at].atom_type == ATOM_REST)
> - die("this command reject atom %%(%.*s)", (int)(ep - sp - 2), sp + 2);
> + if ((!format->cat_file_mode && used_atom[at].atom_type == ATOM_REST) ||
> + (format->cat_file_mode && (used_atom[at].atom_type == ATOM_FLAG ||
> + used_atom[at].atom_type == ATOM_HEAD ||
> + used_atom[at].atom_type == ATOM_PUSH ||
> + used_atom[at].atom_type == ATOM_REFNAME ||
> + used_atom[at].atom_type == ATOM_SYMREF ||
> + used_atom[at].atom_type == ATOM_UPSTREAM ||
> + used_atom[at].atom_type == ATOM_WORKTREEPATH)))
> + die(_("this command reject atom %%(%.*s)"), (int)(ep - sp - 2), sp + 2);Maybe it was brought up already, but those ATOM_* are mostly continuous where they're declared, Maybe worth making it so having a comment like:
/* These need to be in order, used in verify_ref_format */
And then just doing:
used_atom[at].atom_type >= FIRST_OF_THOSE &&
used_atom[at].atom_type >= LAST_OF_THOSEMaybe it's too magical and peeking under the hood of an enum...