git@vger.kernel.org mailing list mirror (one of many)
 help / color / mirror / code / Atom feed
From: Junio C Hamano <gitster@pobox.com>
To: Eric Sunshine <sunshine@sunshineco.com>
Cc: Phillip Wood <phillip.wood@dunelm.org.uk>,
	Git List <git@vger.kernel.org>,
	Johannes Schindelin <Johannes.Schindelin@gmx.de>
Subject: Re: [PATCH v4 2/5] am: improve author-script error reporting
Date: Mon, 05 Nov 2018 10:53:27 +0900	[thread overview]
Message-ID: <xmqqy3a8jnmw.fsf@gitster-ct.c.googlers.com> (raw)
In-Reply-To: <CAPig+cRBwkKGtzY6CwZiKb1mef0a-9F+O24d0R8ZfsRb5ssUbA@mail.gmail.com> (Eric Sunshine's message of "Sun, 4 Nov 2018 00:12:13 -0400")

Eric Sunshine <sunshine@sunshineco.com> writes:

> Junio labeled the "-2" trick "cute", and while it is optimal in that
> it only traverses the key/value list once, it also increases cognitive
> load since the reader has to spend a good deal more brain cycles
> understanding what is going on than would be the case with simpler
> (and less noisily repetitive) code.

... and update three copies of very similar looking code that have
to stay similar.  If this were parsing unbounded and customizable
set of variables, I think the approach you suggest to use a helper
that iterates over the whole array for each key makes sense, but for
now I think what was queued would be OK.

> An alternative would be to make the code trivially easy to understand,
> though a bit more costly, but that expense should be negligible since
> this file should always be tiny, containing very few key/value pairs,
> and it's not timing critical code anyhow. For instance:
>
> static char *find(struct string_list *kv, const char *key)
> {
>     const char *val = NULL;
>     int i;
>     for (i = 0; i < kv.nr; i++) {
>         if (!strcmp(kv.items[i].string, key)) {
>             if (val) {
>                 error(_("duplicate %s"), key);
>                 return NULL;
>             }
>             val = kv.items[i].util;
>         }
>     }
>     if (!val)
>         error(_("missing %s"), key);
>     return val;
> }
>
> static int read_author_script(struct am_state *state)
> {
>     ...
>     char *name, *email, *date;
>     ...
>     name = find(&kv, "GIT_AUTHOR_NAME");
>     email = find(&kv, "GIT_AUTHOR_EMAIL");
>     date = find(&kv, "GIT_AUTHOR_DATE");
>     if (name && email && date) {
>         state->author_name = name;
>         state->author_email = email;
>         state->author_date = date;
>         retval = 0;
>     }
>     string_list_clear&kv, !!retval);
>     ...

  reply	other threads:[~2018-11-05  1:53 UTC|newest]

Thread overview: 41+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-09-12 10:10 [PATCH 0/3] am/rebase: share read_author_script() Phillip Wood
2018-09-12 10:10 ` [PATCH 1/3] am: rename read_author_script() Phillip Wood
2018-09-12 10:10 ` [PATCH 2/3] add read_author_script() to libgit Phillip Wood
2018-09-13 23:49   ` Eric Sunshine
2018-10-10 10:14     ` Phillip Wood
2018-10-10 10:22       ` Eric Sunshine
2018-09-12 10:10 ` [PATCH 3/3] sequencer: use read_author_script() Phillip Wood
2018-09-12 12:14   ` Eric Sunshine
2018-09-14  0:31   ` Eric Sunshine
2018-10-10 10:35     ` Phillip Wood
2018-10-18 10:00 ` [PATCH v2 0/5] am/rebase: share read_author_script() Phillip Wood
2018-10-18 10:00   ` [PATCH v2 1/5] am: don't die in read_author_script() Phillip Wood
2018-10-25  8:44     ` Junio C Hamano
2018-10-18 10:00   ` [PATCH v2 2/5] am: improve author-script error reporting Phillip Wood
2018-10-25  8:55     ` Junio C Hamano
2018-10-18 10:00   ` [PATCH v2 3/5] am: rename read_author_script() Phillip Wood
2018-10-18 10:00   ` [PATCH v2 4/5] add read_author_script() to libgit Phillip Wood
2018-10-18 10:00   ` [PATCH v2 5/5] sequencer: use read_author_script() Phillip Wood
2018-10-25  8:59   ` [PATCH v2 0/5] am/rebase: share read_author_script() Junio C Hamano
2018-10-26  9:00     ` Phillip Wood
2018-10-26 13:32       ` Junio C Hamano
2018-10-30 10:39 ` [PATCH v3 " Phillip Wood
2018-10-30 10:39   ` [PATCH v3 1/5] am: don't die in read_author_script() Phillip Wood
2018-10-30 10:39   ` [PATCH v3 2/5] am: improve author-script error reporting Phillip Wood
2018-10-30 10:39   ` [PATCH v3 3/5] am: rename read_author_script() Phillip Wood
2018-10-30 10:39   ` [PATCH v3 4/5] add read_author_script() to libgit Phillip Wood
2018-10-30 10:39   ` [PATCH v3 5/5] sequencer: use read_author_script() Phillip Wood
2018-10-31  2:50   ` [PATCH v3 0/5] am/rebase: share read_author_script() Junio C Hamano
2018-10-31 10:14     ` Phillip Wood
2018-10-31 10:15 ` [PATCH v4 " Phillip Wood
2018-10-31 10:15   ` [PATCH v4 1/5] am: don't die in read_author_script() Phillip Wood
2018-10-31 10:15   ` [PATCH v4 2/5] am: improve author-script error reporting Phillip Wood
2018-11-04  4:12     ` Eric Sunshine
2018-11-05  1:53       ` Junio C Hamano [this message]
2018-10-31 10:15   ` [PATCH v4 3/5] am: rename read_author_script() Phillip Wood
2018-10-31 10:15   ` [PATCH v4 4/5] add read_author_script() to libgit Phillip Wood
2018-10-31 10:15   ` [PATCH v4 5/5] sequencer: use read_author_script() Phillip Wood
2018-11-01  3:01   ` [PATCH v4 0/5] am/rebase: share read_author_script() Junio C Hamano
2018-11-01  3:12     ` [PATCH v4fixed 2/5] am: improve author-script error reporting Junio C Hamano
2018-11-01  3:12       ` [PATCH v4fixed 4/5] add read_author_script() to libgit Junio C Hamano
2018-11-01 16:27     ` [PATCH v4 0/5] am/rebase: share read_author_script() Phillip Wood

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=xmqqy3a8jnmw.fsf@gitster-ct.c.googlers.com \
    --to=gitster@pobox.com \
    --cc=Johannes.Schindelin@gmx.de \
    --cc=git@vger.kernel.org \
    --cc=phillip.wood@dunelm.org.uk \
    --cc=sunshine@sunshineco.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).