Re: [PATCH 1/5] ref-filter: support different email formats
- From
Đoàn Trần Công Danh <congdanhqx@gmail.com>
- Date
- Jul 28, 2020, 13:58 UTC
- Message-ID
- <20200728135803.GD24134@danh.dev>
- In-Reply-To
- <aeb116c5aaaa23dfefbc7a6f4ac743a6f5a3ade8.1595882588.git.gitgitgadget@gmail.com>
[this is a resent, my previous mail couldn't reach the archive]
On 2020-07-27 20:43:04+0000, Hariom Verma via GitGitGadget <gitgitgadget@gmail.com> wrote:
Show 48 quoted lines
> From: Hariom Verma <hariom18599@gmail.com>
>
> Currently, ref-filter only supports printing email with arrow brackets.
>
> Let's add support for two more email options.
> - trim : print email without arrow brackets.
> - localpart : prints the part before the @ sign
>
> Mentored-by: Christian Couder <chriscool@tuxfamily.org>
> Mentored-by: Heba Waly <heba.waly@gmail.com>
> Signed-off-by: Hariom Verma <hariom18599@gmail.com>
> ---
> ref-filter.c | 36 ++++++++++++++++++++++++++++++++----
> t/t6300-for-each-ref.sh | 16 ++++++++++++++++
> 2 files changed, 48 insertions(+), 4 deletions(-)
>
> diff --git a/ref-filter.c b/ref-filter.c
> index 8447cb09be..8563088eb1 100644
> --- a/ref-filter.c
> +++ b/ref-filter.c
> @@ -102,6 +102,10 @@ static struct ref_to_worktree_map {
> struct worktree **worktrees;
> } ref_to_worktree_map;
>
> +static struct email_option{
> + enum { EO_INVALID, EO_RAW, EO_TRIM, EO_LOCALPART } option;
> +} email_option;
> +
> /*
> * An atom is a valid field atom listed below, possibly prefixed with
> * a "*" to denote deref_tag().
> @@ -1040,10 +1044,26 @@ static const char *copy_email(const char *buf)
> const char *eoemail;
> if (!email)
> return xstrdup("");
> - eoemail = strchr(email, '>');
> + switch (email_option.option) {
> + case EO_RAW:
> + eoemail = strchr(email, '>') + 1;
> + break;
> + case EO_TRIM:
> + email++;
> + eoemail = strchr(email, '>');
> + break;
> + case EO_LOCALPART:
> + email++;
> + eoemail = strchr(email, '@');
> + break;This is not correct. RFC-822 allows @ in local part, albeit, that localpart must be quoted:
addr-spec = local-part "@" domain
local-part = dot-atom / quoted-string / obs-local-part
quoted-string = [CFWS]
DQUOTE *([FWS] qcontent) [FWS] DQUOTE
[CFWS]
qcontent = qtext / quoted-pair
qtext = NO-WS-CTL / ; Non white space
qtext = NO-WS-CTL / ; Non white space controls
%d33 / ; The rest of the US-ASCII
%d35-91 / ; characters not including "\"
%d93-126 ; or the quote character
quoted-pair = ("\" text) / obs-qpIOW, those below email addresses are valid email address, and the local part is `quoted@local'
"quoted@local"@example.com
quoted\@local@example.comAnyway, it seems like current Git strips first `"' from `"quoted@local"@example.com'
-- Danh