Re: [PATCH] ref-filter: add new atom "signature" atom
- From
Christian Couder <christian.couder@gmail.com>
- Date
- Jan 2, 2023, 08:37 UTC
- Message-ID
- <CAP8UFD3i7C2c79V2ORxh-Q-rNuwKVqkMRX0VoXy3iugw=u5K+A@mail.gmail.com>
- In-Reply-To
- <CA+PPyiGPRztaLsty5LqT-7GfjPusyt=7hi22z1aPdm-G8pZpuQ@mail.gmail.com>
On Mon, Jan 2, 2023 at 6:01 AM NSENGIYUMVA WILBERFORCE <nsengiyumvawilberforce@gmail.com> wrote:
Show 26 quoted lines
> > Handing the !arg case first will make the if/else if/... cascade
> > easier to follow, no? Also the body of the function may want to
> > become a separate function that returns one of these S_FOO constants.
> >
> > static enum signatore_option signature_atom_parser(...)
> > {
> > enum signature_option opt = parse_signature_option(arg);
> > if (opt < 0)
> > return strbuf_addf_ret(err, opt, _("unknown ..."), arg);
> > return opt;
> > }
> >
> > where parse_signature_option() would look like
> >
> > static enum signature_option parse_signature_option(const char *arg)
> > {
> > if (!arg)
> > return S_BARE;
> > else if (!strcmp(arg, "signer"))
> > return S_SIGNER;
> > ...
> > else
> > return -1;
> > }
> >
> > or something like that?[...]
Show 13 quoted lines
> > > + if (strcmp(name, "signature") && > > > + strcmp(name, "signature:signer") && > > > + strcmp(name, "signature:grade") && > > > + strcmp(name, "signature:key") && > > > + strcmp(name, "signature:fingerprint") && > > > + strcmp(name, "signature:primarykeyfingerprint") && > > > + strcmp(name, "signature:trustlevel")) > > > + continue; > > > > And with the helper above, we can avoid the repetition here that can > > go out of sync with the parser function. > > I am not sure I have understood this, which helper?
I think Junio is talking about the following function:
static enum signature_option parse_signature_option(const char *arg)
he suggested above.
With this function the above code could be just something like:
if (parse_signature_option(name) < 0)
continue;