{"thread":{"id":"36029","subject":"[PATCH v4] branch.c: change install_branch_config() to use skip_prefix()","startedAt":"2014-03-03T06:36:21Z","lastAt":"2014-03-03T08:57:18Z","messageCount":3,"participants":["Guanglin Xu","Eric Sunshine"],"isPatch":true,"patchVersion":4,"patchTotal":null},"messages":[{"id":"235828","messageId":"1393828581-65523-1-git-send-email-mzguanglin@gmail.com","threadId":"36029","inReplyTo":null,"subject":"[PATCH v4] branch.c: change install_branch_config() to use skip_prefix()","fromName":"Guanglin Xu","fromEmail":"mzguanglin@gmail.com","sentAt":"2014-03-03T06:36:21Z","receivedAt":"2014-03-03T06:36:21Z","isPatch":true,"sender":{"key":"mzguanglin@gmail.com","avatar":"https://gravatar.com/avatar/fb3a07ac20762e91fec45813fa7b91f5497c3ed748441e9d14e888900d5653c0?d=mp&s=160"},"body":"to avoid a magic code of 11.\n\nHelped-by: Sun He <sunheeh...@gmail.com>\nHelped-by: Eric Sunshine <sunsh...@sunshineco.com>\nHelped-by: Jacopo Notarstefano <jaco...@gmail.com>\n\nSigned-off-by: Guanglin Xu <mzguanglin@gmail.com>\n---\n\nThis is an implementation of the idea#2 of GSoC 2014 microproject.\n\n branch.c | 8 ++++++--\n 1 file changed, 6 insertions(+), 2 deletions(-)\n\ndiff --git a/branch.c b/branch.c\nindex 723a36b..4eec0ac 100644\n--- a/branch.c\n+++ b/branch.c\n@@ -49,8 +49,12 @@ static int should_setup_rebase(const char *origin)\n \n void install_branch_config(int flag, const char *local, const char *origin, const char *remote)\n {\n-\tconst char *shortname = remote + 11;\n-\tint remote_is_branch = starts_with(remote, \"refs/heads/\");\n+\tconst char *shortname = skip_prefix(remote ,\"refs/heads/\");\n+\tint remote_is_branch;\n+\tif (NULL == shortname)\n+\t\tremote_is_branch = 0;\n+\telse\n+\t\tremote_is_branch = 1;\n \tstruct strbuf key = STRBUF_INIT;\n \tint rebasing = should_setup_rebase(origin);\n \n-- \n1.9.0\n"},{"id":"235846","messageId":"CAPig+cQ7Zg-jPewuaYJ7K8aZBfJQPPt64Pzn9g1GdbikTQORzQ@mail.gmail.com","threadId":"36029","inReplyTo":"1393828581-65523-1-git-send-email-mzguanglin@gmail.com","subject":"Re: [PATCH v4] branch.c: change install_branch_config() to use skip_prefix()","fromName":"Eric Sunshine","fromEmail":"sunshine@sunshineco.com","sentAt":"2014-03-03T08:12:34Z","receivedAt":"2014-03-03T08:12:34Z","isPatch":true,"sender":{"key":"sunshine@sunshineco.com","avatar":"https://avatars.githubusercontent.com/u/163641?v=4"},"body":"On Mon, Mar 3, 2014 at 1:36 AM, Guanglin Xu <mzguanglin@gmail.com> wrote:\n> to avoid a magic code of 11.\n>\n> Helped-by: Sun He <sunheeh...@gmail.com>\n> Helped-by: Eric Sunshine <sunsh...@sunshineco.com>\n> Helped-by: Jacopo Notarstefano <jaco...@gmail.com>\n>\n> Signed-off-by: Guanglin Xu <mzguanglin@gmail.com>\n> ---\n>\n> This is an implementation of the idea#2 of GSoC 2014 microproject.\n>\n>  branch.c | 8 ++++++--\n>  1 file changed, 6 insertions(+), 2 deletions(-)\n>\n> diff --git a/branch.c b/branch.c\n> index 723a36b..4eec0ac 100644\n> --- a/branch.c\n> +++ b/branch.c\n> @@ -49,8 +49,12 @@ static int should_setup_rebase(const char *origin)\n>\n>  void install_branch_config(int flag, const char *local, const char *origin, const char *remote)\n>  {\n> -       const char *shortname = remote + 11;\n> -       int remote_is_branch = starts_with(remote, \"refs/heads/\");\n> +       const char *shortname = skip_prefix(remote ,\"refs/heads/\");\n> +       int remote_is_branch;\n> +       if (NULL == shortname)\n> +               remote_is_branch = 0;\n> +       else\n> +               remote_is_branch = 1;\n\nA bit verbose. Perhaps just:\n\n    int remote_is_branch = !!shortname;\n\nwhich you will find to be idiomatic in this project.\n\n>         struct strbuf key = STRBUF_INIT;\n>         int rebasing = should_setup_rebase(origin);\n>\n> --\n> 1.9.0\n"},{"id":"235850","messageId":"CAATe9ugnq6bm8W05RP=uq+nPEZqsyRYFosRvyJwOSot+ynPOKw@mail.gmail.com","threadId":"36029","inReplyTo":"CAPig+cQ7Zg-jPewuaYJ7K8aZBfJQPPt64Pzn9g1GdbikTQORzQ@mail.gmail.com","subject":"Re: [PATCH v4] branch.c: change install_branch_config() to use skip_prefix()","fromName":"Guanglin Xu","fromEmail":"mzguanglin@gmail.com","sentAt":"2014-03-03T08:57:18Z","receivedAt":"2014-03-03T08:57:18Z","isPatch":true,"sender":{"key":"mzguanglin@gmail.com","avatar":"https://gravatar.com/avatar/fb3a07ac20762e91fec45813fa7b91f5497c3ed748441e9d14e888900d5653c0?d=mp&s=160"},"body":"Hi Eric,\n\nYes, you're right. \"!!\" is comfortably concise and also idiomatic in\nGit sources.\n\nThanks,\n\nGuanglin\n\n2014-03-03 16:12 GMT+08:00 Eric Sunshine <sunshine@sunshineco.com>:\n> On Mon, Mar 3, 2014 at 1:36 AM, Guanglin Xu <mzguanglin@gmail.com> wrote:\n>> to avoid a magic code of 11.\n>>\n>> Helped-by: Sun He <sunheeh...@gmail.com>\n>> Helped-by: Eric Sunshine <sunsh...@sunshineco.com>\n>> Helped-by: Jacopo Notarstefano <jaco...@gmail.com>\n>>\n>> Signed-off-by: Guanglin Xu <mzguanglin@gmail.com>\n>> ---\n>>\n>> This is an implementation of the idea#2 of GSoC 2014 microproject.\n>>\n>>  branch.c | 8 ++++++--\n>>  1 file changed, 6 insertions(+), 2 deletions(-)\n>>\n>> diff --git a/branch.c b/branch.c\n>> index 723a36b..4eec0ac 100644\n>> --- a/branch.c\n>> +++ b/branch.c\n>> @@ -49,8 +49,12 @@ static int should_setup_rebase(const char *origin)\n>>\n>>  void install_branch_config(int flag, const char *local, const char *origin, const char *remote)\n>>  {\n>> -       const char *shortname = remote + 11;\n>> -       int remote_is_branch = starts_with(remote, \"refs/heads/\");\n>> +       const char *shortname = skip_prefix(remote ,\"refs/heads/\");\n>> +       int remote_is_branch;\n>> +       if (NULL == shortname)\n>> +               remote_is_branch = 0;\n>> +       else\n>> +               remote_is_branch = 1;\n>\n> A bit verbose. Perhaps just:\n>\n>     int remote_is_branch = !!shortname;\n>\n> which you will find to be idiomatic in this project.\n>\n>>         struct strbuf key = STRBUF_INIT;\n>>         int rebasing = should_setup_rebase(origin);\n>>\n>> --\n>> 1.9.0\n"}]}