Re: [PATCH v4] install_branch_config: simplify verbose messages logic
- From
Eric Sunshine <sunshine@sunshineco.com>
- Date
- Mar 13, 2014, 22:45 UTC
- Message-ID
- <CAPig+cS9n64boSSgoK-z=V9QFkvr=1Z2Db5KRrsyZNDthDE27A@mail.gmail.com>
- In-Reply-To
- <CAPig+cQU5__EPA2C3QvCPAT4od3Ux8kCgq-2H8nCddGdNqaG0A@mail.gmail.com>
On Thu, Mar 13, 2014 at 4:35 PM, Eric Sunshine <sunshine@sunshineco.com> wrote:
Show 14 quoted lines
> A more table-driven approach might look something
> like this:
>
> struct M { const char *s; const char **a1; const char **a2; }
> message[][2][2] = {{{
> { "Branch %s set ... %s ... %s", &shortname, &origin },
> ...
> }},{{
> { "Branch %s set ... %s", &remote, NULL },
> ...
> }}};
>
> const struct M *m = message[!remote_is_branch][!origin][!rebasing];
> printf_ln(m->s, local, *m->a1, *m->a2);Of course, using NULL in the table like that would crash when dereferenced: *m->a2. It was just an quick example typed on-the-fly. Real code would want to be more careful.