{"thread":{"id":"36146","subject":"[PATCH v5] install_branch_config: simplify verbose messages logic","startedAt":"2014-03-12T23:47:45Z","lastAt":"2014-03-13T22:36:29Z","messageCount":2,"participants":["Paweł Wawruch","Eric Sunshine"],"isPatch":true,"patchVersion":5,"patchTotal":null},"messages":[{"id":"236650","messageId":"1394668065-14629-1-git-send-email-pawlo@aleg.pl","threadId":"36146","inReplyTo":null,"subject":"[PATCH v5] install_branch_config: simplify verbose messages logic","fromName":"Paweł Wawruch","fromEmail":"pawlo@aleg.pl","sentAt":"2014-03-12T23:47:45Z","receivedAt":"2014-03-12T23:47:45Z","isPatch":true,"sender":{"key":"pawlo@aleg.pl","avatar":"https://gravatar.com/avatar/17564135d51785c0ca06c280fdee1c08c803d68c3227d9e91b78db28b69d3945?d=mp&s=160"},"body":"Replace the chain of if statements with table of strings.\n\nSigned-off-by: Paweł Wawruch <pawlo@aleg.pl>\n---\nThanks to Eric Sunshine and Junio C Hamano.\nSimplified printing logic. The name moved to a table.\n\nv4: http://thread.gmane.org/gmane.comp.version-control.git/243914\nv3: http://thread.gmane.org/gmane.comp.version-control.git/243865\nv2: http://thread.gmane.org/gmane.comp.version-control.git/243849\nv1: http://thread.gmane.org/gmane.comp.version-control.git/243502\n\n branch.c | 42 +++++++++++++++++-------------------------\n 1 file changed, 17 insertions(+), 25 deletions(-)\n\ndiff --git a/branch.c b/branch.c\nindex 723a36b..c17817c 100644\n--- a/branch.c\n+++ b/branch.c\n@@ -53,6 +53,20 @@ void install_branch_config(int flag, const char *local, const char *origin, cons\n \tint remote_is_branch = starts_with(remote, \"refs/heads/\");\n \tstruct strbuf key = STRBUF_INIT;\n \tint rebasing = should_setup_rebase(origin);\n+\tconst char *message[][2][2] = {{{\n+\t\tN_(\"Branch %s set up to track remote branch %s from %s by rebasing.\"),\n+\t\tN_(\"Branch %s set up to track remote branch %s from %s.\"),\n+\t\t},{\n+\t\tN_(\"Branch %s set up to track local branch %s by rebasing.\"),\n+\t\tN_(\"Branch %s set up to track local branch %s.\"),\n+\t\t}},{{\n+\t\tN_(\"Branch %s set up to track remote ref %s by rebasing.\"),\n+\t\tN_(\"Branch %s set up to track remote ref %s.\"),\n+\t\t},{\n+\t\tN_(\"Branch %s set up to track local ref %s by rebasing.\"),\n+\t\tN_(\"Branch %s set up to track local ref %s.\")\n+\t}}};\n+\tconst char *name[] = {remote, shortname};\n \n \tif (remote_is_branch\n \t    && !strcmp(local, shortname)\n@@ -76,31 +90,9 @@ void install_branch_config(int flag, const char *local, const char *origin, cons\n \t}\n \tstrbuf_release(&key);\n \n-\tif (flag & BRANCH_CONFIG_VERBOSE) {\n-\t\tif (remote_is_branch && origin)\n-\t\t\tprintf_ln(rebasing ?\n-\t\t\t\t  _(\"Branch %s set up to track remote branch %s from %s by rebasing.\") :\n-\t\t\t\t  _(\"Branch %s set up to track remote branch %s from %s.\"),\n-\t\t\t\t  local, shortname, origin);\n-\t\telse if (remote_is_branch && !origin)\n-\t\t\tprintf_ln(rebasing ?\n-\t\t\t\t  _(\"Branch %s set up to track local branch %s by rebasing.\") :\n-\t\t\t\t  _(\"Branch %s set up to track local branch %s.\"),\n-\t\t\t\t  local, shortname);\n-\t\telse if (!remote_is_branch && origin)\n-\t\t\tprintf_ln(rebasing ?\n-\t\t\t\t  _(\"Branch %s set up to track remote ref %s by rebasing.\") :\n-\t\t\t\t  _(\"Branch %s set up to track remote ref %s.\"),\n-\t\t\t\t  local, remote);\n-\t\telse if (!remote_is_branch && !origin)\n-\t\t\tprintf_ln(rebasing ?\n-\t\t\t\t  _(\"Branch %s set up to track local ref %s by rebasing.\") :\n-\t\t\t\t  _(\"Branch %s set up to track local ref %s.\"),\n-\t\t\t\t  local, remote);\n-\t\telse\n-\t\t\tdie(\"BUG: impossible combination of %d and %p\",\n-\t\t\t    remote_is_branch, origin);\n-\t}\n+\tif (flag & BRANCH_CONFIG_VERBOSE)\n+\t\tprintf_ln(_(message[!remote_is_branch][!origin][!rebasing]),\n+\t\t\t\tlocal, name[!remote_is_branch], origin);\n }\n \n /*\n-- \n1.8.3.2\n"},{"id":"236695","messageId":"CAPig+cSh5qRyDnD3hAcdjswGZk+rGzU5ekDbNBTB-XNBSa806Q@mail.gmail.com","threadId":"36146","inReplyTo":"1394668065-14629-1-git-send-email-pawlo@aleg.pl","subject":"Re: [PATCH v5] install_branch_config: simplify verbose messages logic","fromName":"Eric Sunshine","fromEmail":"sunshine@sunshineco.com","sentAt":"2014-03-13T22:36:29Z","receivedAt":"2014-03-13T22:36:29Z","isPatch":true,"sender":{"key":"sunshine@sunshineco.com","avatar":"https://avatars.githubusercontent.com/u/163641?v=4"},"body":"On Wed, Mar 12, 2014 at 7:47 PM, Paweł Wawruch <pawlo@aleg.pl> wrote:\n> Replace the chain of if statements with table of strings.\n>\n> Signed-off-by: Paweł Wawruch <pawlo@aleg.pl>\n> ---\n> Thanks to Eric Sunshine and Junio C Hamano.\n> Simplified printing logic. The name moved to a table.\n>\n> v4: http://thread.gmane.org/gmane.comp.version-control.git/243914\n> v3: http://thread.gmane.org/gmane.comp.version-control.git/243865\n> v2: http://thread.gmane.org/gmane.comp.version-control.git/243849\n> v1: http://thread.gmane.org/gmane.comp.version-control.git/243502\n\nThanks. Using the vN notation makes these links self-explanatory.\n\n>  branch.c | 42 +++++++++++++++++-------------------------\n>  1 file changed, 17 insertions(+), 25 deletions(-)\n>\n> diff --git a/branch.c b/branch.c\n> index 723a36b..c17817c 100644\n> --- a/branch.c\n> +++ b/branch.c\n> @@ -53,6 +53,20 @@ void install_branch_config(int flag, const char *local, const char *origin, cons\n>         int remote_is_branch = starts_with(remote, \"refs/heads/\");\n>         struct strbuf key = STRBUF_INIT;\n>         int rebasing = should_setup_rebase(origin);\n> +       const char *message[][2][2] = {{{\n> +               N_(\"Branch %s set up to track remote branch %s from %s by rebasing.\"),\n> +               N_(\"Branch %s set up to track remote branch %s from %s.\"),\n\nSome compilers may complain about the trailing comma. Ditto for the ones below.\n\n> +               },{\n> +               N_(\"Branch %s set up to track local branch %s by rebasing.\"),\n> +               N_(\"Branch %s set up to track local branch %s.\"),\n> +               }},{{\n> +               N_(\"Branch %s set up to track remote ref %s by rebasing.\"),\n> +               N_(\"Branch %s set up to track remote ref %s.\"),\n> +               },{\n> +               N_(\"Branch %s set up to track local ref %s by rebasing.\"),\n> +               N_(\"Branch %s set up to track local ref %s.\")\n> +       }}};\n> +       const char *name[] = {remote, shortname};\n\nSee [1] and the messages following it for commentary about this change.\n\n>         if (remote_is_branch\n>             && !strcmp(local, shortname)\n> @@ -76,31 +90,9 @@ void install_branch_config(int flag, const char *local, const char *origin, cons\n>         }\n>         strbuf_release(&key);\n>\n> -       if (flag & BRANCH_CONFIG_VERBOSE) {\n> -               if (remote_is_branch && origin)\n> -                       printf_ln(rebasing ?\n> -                                 _(\"Branch %s set up to track remote branch %s from %s by rebasing.\") :\n> -                                 _(\"Branch %s set up to track remote branch %s from %s.\"),\n> -                                 local, shortname, origin);\n> -               else if (remote_is_branch && !origin)\n> -                       printf_ln(rebasing ?\n> -                                 _(\"Branch %s set up to track local branch %s by rebasing.\") :\n> -                                 _(\"Branch %s set up to track local branch %s.\"),\n> -                                 local, shortname);\n> -               else if (!remote_is_branch && origin)\n> -                       printf_ln(rebasing ?\n> -                                 _(\"Branch %s set up to track remote ref %s by rebasing.\") :\n> -                                 _(\"Branch %s set up to track remote ref %s.\"),\n> -                                 local, remote);\n> -               else if (!remote_is_branch && !origin)\n> -                       printf_ln(rebasing ?\n> -                                 _(\"Branch %s set up to track local ref %s by rebasing.\") :\n> -                                 _(\"Branch %s set up to track local ref %s.\"),\n> -                                 local, remote);\n> -               else\n> -                       die(\"BUG: impossible combination of %d and %p\",\n> -                           remote_is_branch, origin);\n> -       }\n> +       if (flag & BRANCH_CONFIG_VERBOSE)\n> +               printf_ln(_(message[!remote_is_branch][!origin][!rebasing]),\n> +                               local, name[!remote_is_branch], origin);\n\nMuch simpler than the previous versions (sans [1] commentary)\n\n[1]: http://thread.gmane.org/gmane.comp.version-control.git/243914/focus=244043\n\n>  }\n>\n>  /*\n> --\n> 1.8.3.2\n"}]}