From: Hariom verma <hariom18599@gmail.com>
To: Junio C Hamano <gitster@pobox.com>
Cc: Hariom Verma via GitGitGadget <gitgitgadget@gmail.com>,
git <git@vger.kernel.org>,
Christian Couder <christian.couder@gmail.com>,
Heba Waly <heba.waly@gmail.com>
Subject: Re: [PATCH 1/5] ref-filter: support different email formats
Date: Wed, 29 Jul 2020 02:01:53 +0530 [thread overview]
Message-ID: <CA+CkUQ9nqW8=GuvNapsySf=EXm8c02qKV2xMrwvRY-Kd9Yy9mA@mail.gmail.com> (raw)
In-Reply-To: <xmqqeeowfu75.fsf@gitster.c.googlers.com>
Hi,
On Tue, Jul 28, 2020 at 4:21 AM Junio C Hamano <gitster@pobox.com> wrote:
>
> "Hariom Verma via GitGitGadget" <gitgitgadget@gmail.com> writes:
>
> > From: Hariom Verma <hariom18599@gmail.com>
> >
> > Currently, ref-filter only supports printing email with arrow brackets.
>
> This is the first time I heard the term "arrow bracket". Aren't
> they more commonly called angle brackets?
Yeah. Sorry about that.
> > Let's add support for two more email options.
> > - trim : print email without arrow brackets.
>
> Why would this be useful?
It might be useful for using the ref-filter's logic in pretty.c
(especially for `--pretty` formats like `%an` and `%cn`)
> > - localpart : prints the part before the @ sign
>
> Meaning I'd get "<gitster" for me?
No, you'll get "gitster".
> Building small pieces of new feature in each patch is good, and
> adding tests to each step is also good. Why not do the same for
> docs?
Yeah, I agree with you. I should have focused on documentation too.
> > +static struct email_option{
>
> Missing SP.
I'll fix it.
> > + enum { EO_INVALID, EO_RAW, EO_TRIM, EO_LOCALPART } option;
> > +} email_option;
> > +
> > @@ -1040,10 +1044,26 @@ static const char *copy_email(const char *buf)
> > const char *eoemail;
> > if (!email)
> > return xstrdup("");
> > - eoemail = strchr(email, '>');
>
> The original code prepares to see NULL from this strchr(); that is
> why it checks eoemail for NULL and returns an empty string---the
> data is broken (i.e. not an address in angle brackets), which this
> code cannot do anything about---in the later part of the code.
I think this commit still takes care of NULL.
After the switch-case statements, code consists of:
```
if (!eoemail)
return xstrdup("");
```
Which checks eoemail for NULL. And will return empty string if address
is not in angle brackets.
Same applies for local-part too. If '@' is not present in email
address, it will still return empty string.
> > + switch (email_option.option) {
> > + case EO_RAW:
> > + eoemail = strchr(email, '>') + 1;
>
> And this breaks the carefully laid out error handling by the
> original code. Adding 1 to NULL is quite undefined.
Yeah. I'll take care of it in the next version.
> > + break;
> > + case EO_TRIM:
> > + email++;
> > + eoemail = strchr(email, '>');
> > + break;
> > + case EO_LOCALPART:
> > + email++;
> > + eoemail = strchr(email, '@');
>
> The undocumented design here is that you want to return "hariom" for
> "<hariom@gmail.com>", i.e. out of the "trimmed" e-mail, the part
> before the at-sign is returned.
>
> If the data were "<hariom>", you'd still want to return "hariom" no?
> But because you do not check for NULL, you end up returning an empty
> string.
I never heard of email address without '@' symbol. Thats why I
returned empty string.
Will fix that too.
> I think you want to cut at the first '@' or '>', whichever comes
> first.
If email data can be without '@' symbol, then I guess "yes".
> > + break;
> > + case EO_INVALID:
> > + default:
>
> Invalid and unhandled ones are silently ignored and not treated as
> an error? I would have thought that at least the "default" one
> would be a BUG(), as you covered all the possible values for the
> enum with case arms. I wouldn't be surprised if seeing EO_INVALID
> is also a BUG(), i.e. the control flow that led to the caller to
> call this function with EO_INVALID in email_option.option is likely
> to be broken. It's not like you return "" to protect yourself when
> fed a bad data from objects---a bad value in .option can only come
> here if the parser you wrote for "--format=<string>" produced a
> wrong result.
Christian <chriscool@tuxfamily.org> also suggested me the same. Will
fix this too.
BTW, on master "{author,committer,tagger}email:<xyz>" does not print any error.
> > + return xstrdup("");
> > + }
> > +
> > if (!eoemail)
> > return xstrdup("");
> > - return xmemdupz(email, eoemail + 1 - email);
> > + return xmemdupz(email, eoemail - email);
> > }
> >
> > static char *copy_subject(const char *buf, unsigned long len)
> > @@ -1113,7 +1133,7 @@ static void grab_person(const char *who, struct atom_value *val, int deref, void
> > continue;
> > if (name[wholen] != 0 &&
> > strcmp(name + wholen, "name") &&
> > - strcmp(name + wholen, "email") &&
> > + !starts_with(name + wholen, "email") &&
> > !starts_with(name + wholen, "date"))
> > continue;
> > if (!wholine)
> > @@ -1124,8 +1144,16 @@ static void grab_person(const char *who, struct atom_value *val, int deref, void
> > v->s = copy_line(wholine);
> > else if (!strcmp(name + wholen, "name"))
> > v->s = copy_name(wholine);
> > - else if (!strcmp(name + wholen, "email"))
> > + else if (starts_with(name + wholen, "email")) {
> > + email_option.option = EO_INVALID;
> > + if (!strcmp(name + wholen, "email"))
> > + email_option.option = EO_RAW;
> > + if (!strcmp(name + wholen, "email:trim"))
> > + email_option.option = EO_TRIM;
> > + if (!strcmp(name + wholen, "email:localpart"))
> > + email_option.option = EO_LOCALPART;
>
> The ref-filter formatting language already knows many "colon plus
> modifier" suffix like "refname:short" and "contents:body", but I do
> not think we have ugly repetition like the above code to parse them.
> Perhaps the addition for "email:<whatever>" can benefit from
> studying and mimicking existing practices a bit more?
>
For "email:<whatever>",
even If I parse that <whatever>. I still make comparison something like:
```
if (!modifier)
email_option.option = EO_RAW;
else if (!strcmp(modifier, "trim"))
email_option.option = EO_TRIM;
else if (!strcmp(arg, "localpart"))
email_option.option = EO_LOCALPART;
```
Thanks,
Hariom
next prev parent reply other threads:[~2020-07-28 20:32 UTC|newest]
Thread overview: 51+ messages / expand[flat|nested] mbox.gz Atom feed top
2020-07-27 20:43 [PATCH 0/5] [GSoC] Improvements to ref-filter Hariom Verma via GitGitGadget
2020-07-27 20:43 ` [PATCH 1/5] ref-filter: support different email formats Hariom Verma via GitGitGadget
2020-07-27 22:51 ` Junio C Hamano
2020-07-28 20:31 ` Hariom verma [this message]
2020-07-28 20:43 ` Junio C Hamano
2020-07-28 13:58 ` Đoàn Trần Công Danh
2020-07-28 16:45 ` Junio C Hamano
2020-07-27 20:43 ` [PATCH 2/5] ref-filter: add `short` option for 'tree' and 'parent' Hariom Verma via GitGitGadget
2020-07-27 23:21 ` Junio C Hamano
2020-07-27 20:43 ` [PATCH 3/5] pretty: refactor `format_sanitized_subject()` Hariom Verma via GitGitGadget
2020-07-27 20:43 ` [PATCH 4/5] format-support: move `format_sanitized_subject()` from pretty Hariom Verma via GitGitGadget
2020-07-27 20:43 ` [PATCH 5/5] ref-filter: add `sanitize` option for 'subject' atom Hariom Verma via GitGitGadget
2020-08-05 21:51 ` [PATCH v2 0/9] [GSoC] Improvements to ref-filter Hariom Verma via GitGitGadget
2020-08-05 21:51 ` [PATCH v2 1/9] ref-filter: support different email formats Hariom Verma via GitGitGadget
2020-08-05 21:51 ` [PATCH v2 2/9] ref-filter: refactor `grab_objectname()` Hariom Verma via GitGitGadget
2020-08-05 21:51 ` [PATCH v2 3/9] ref-filter: modify error messages in `grab_objectname()` Hariom Verma via GitGitGadget
2020-08-05 21:51 ` [PATCH v2 4/9] ref-filter: rename `objectname` related functions and fields Hariom Verma via GitGitGadget
2020-08-05 21:51 ` [PATCH v2 5/9] ref-filter: add `short` modifier to 'tree' atom Hariom Verma via GitGitGadget
2020-08-05 21:51 ` [PATCH v2 6/9] ref-filter: add `short` modifier to 'parent' atom Hariom Verma via GitGitGadget
2020-08-05 21:51 ` [PATCH v2 7/9] pretty: refactor `format_sanitized_subject()` Hariom Verma via GitGitGadget
2020-08-05 21:51 ` [PATCH v2 8/9] format-support: move `format_sanitized_subject()` from pretty Hariom Verma via GitGitGadget
2020-08-05 21:51 ` [PATCH v2 9/9] ref-filter: add `sanitize` option for 'subject' atom Hariom Verma via GitGitGadget
2020-08-05 22:04 ` [PATCH v2 0/9] [GSoC] Improvements to ref-filter Junio C Hamano
2020-08-06 13:47 ` Hariom verma
2020-08-17 18:10 ` [PATCH v3 0/9] [Resend][GSoC] " Hariom Verma via GitGitGadget
2020-08-17 18:10 ` [PATCH v3 1/9] ref-filter: support different email formats Hariom Verma via GitGitGadget
2020-08-17 18:10 ` [PATCH v3 2/9] ref-filter: refactor `grab_objectname()` Hariom Verma via GitGitGadget
2020-08-17 18:10 ` [PATCH v3 3/9] ref-filter: modify error messages in `grab_objectname()` Hariom Verma via GitGitGadget
2020-08-17 18:10 ` [PATCH v3 4/9] ref-filter: rename `objectname` related functions and fields Hariom Verma via GitGitGadget
2020-08-17 18:10 ` [PATCH v3 5/9] ref-filter: add `short` modifier to 'tree' atom Hariom Verma via GitGitGadget
2020-08-17 18:10 ` [PATCH v3 6/9] ref-filter: add `short` modifier to 'parent' atom Hariom Verma via GitGitGadget
2020-08-17 18:10 ` [PATCH v3 7/9] pretty: refactor `format_sanitized_subject()` Hariom Verma via GitGitGadget
2020-08-17 19:29 ` Junio C Hamano
2020-08-19 13:36 ` Hariom verma
2020-08-19 16:01 ` Junio C Hamano
2020-08-19 16:08 ` Junio C Hamano
2020-08-20 17:33 ` Hariom verma
2020-08-20 17:27 ` Hariom verma
2020-08-17 18:10 ` [PATCH v3 8/9] format-support: move `format_sanitized_subject()` from pretty Hariom Verma via GitGitGadget
2020-08-17 19:33 ` Junio C Hamano
2020-08-17 18:10 ` [PATCH v3 9/9] ref-filter: add `sanitize` option for 'subject' atom Hariom Verma via GitGitGadget
2020-08-17 19:37 ` [PATCH v3 0/9] [Resend][GSoC] Improvements to ref-filter Junio C Hamano
2020-08-21 21:41 ` [PATCH v4 0/8] [GSoC] " Hariom Verma via GitGitGadget
2020-08-21 21:41 ` [PATCH v4 1/8] ref-filter: support different email formats Hariom Verma via GitGitGadget
2020-08-21 21:41 ` [PATCH v4 2/8] ref-filter: refactor `grab_objectname()` Hariom Verma via GitGitGadget
2020-08-21 21:41 ` [PATCH v4 3/8] ref-filter: modify error messages in `grab_objectname()` Hariom Verma via GitGitGadget
2020-08-21 21:41 ` [PATCH v4 4/8] ref-filter: rename `objectname` related functions and fields Hariom Verma via GitGitGadget
2020-08-21 21:41 ` [PATCH v4 5/8] ref-filter: add `short` modifier to 'tree' atom Hariom Verma via GitGitGadget
2020-08-21 21:41 ` [PATCH v4 6/8] ref-filter: add `short` modifier to 'parent' atom Hariom Verma via GitGitGadget
2020-08-21 21:41 ` [PATCH v4 7/8] pretty: refactor `format_sanitized_subject()` Hariom Verma via GitGitGadget
2020-08-21 21:41 ` [PATCH v4 8/8] ref-filter: add `sanitize` option for 'subject' atom Hariom Verma via GitGitGadget
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
List information: http://vger.kernel.org/majordomo-info.html
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to='CA+CkUQ9nqW8=GuvNapsySf=EXm8c02qKV2xMrwvRY-Kd9Yy9mA@mail.gmail.com' \
--to=hariom18599@gmail.com \
--cc=christian.couder@gmail.com \
--cc=git@vger.kernel.org \
--cc=gitgitgadget@gmail.com \
--cc=gitster@pobox.com \
--cc=heba.waly@gmail.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.
Code repositories for project(s) associated with this public inbox
https://80x24.org/mirrors/git.git
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).