{"thread":{"id":"35987","subject":"[PATCH v2 2/2] branch: use skip_prefix","startedAt":"2014-02-28T06:43:33Z","lastAt":"2014-02-28T06:43:33Z","messageCount":1,"participants":["Brian Gesiak"],"isPatch":true,"patchVersion":2,"patchTotal":2},"messages":[{"id":"235544","messageId":"1393569813-68583-1-git-send-email-modocache@gmail.com","threadId":"35987","inReplyTo":null,"subject":"[PATCH v2 2/2] branch: use skip_prefix","fromName":"Brian Gesiak","fromEmail":"modocache@gmail.com","sentAt":"2014-02-28T06:43:33Z","receivedAt":"2014-02-28T06:43:33Z","isPatch":true,"sender":{"key":"modocache@gmail.com","avatar":"https://avatars.githubusercontent.com/u/552921?v=4"},"body":"The install_branch_config function reimplemented the skip_prefix\nfunction inline. Use skip_prefix function instead for brevity.\n\nReported-by: Michael Haggerty <mhagger@alum.mit.edu>\nSigned-off-by: Brian Gesiak <modocache@gmail.com>\n---\n branch.c | 18 +++++++++---------\n 1 file changed, 9 insertions(+), 9 deletions(-)\n\ndiff --git a/branch.c b/branch.c\nindex 723a36b..e163f3c 100644\n--- a/branch.c\n+++ b/branch.c\n@@ -1,3 +1,4 @@\n+#include \"git-compat-util.h\"\n #include \"cache.h\"\n #include \"branch.h\"\n #include \"refs.h\"\n@@ -49,12 +50,11 @@ 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 \tstruct strbuf key = STRBUF_INIT;\n \tint rebasing = should_setup_rebase(origin);\n \n-\tif (remote_is_branch\n+\tif (shortname\n \t    && !strcmp(local, shortname)\n \t    && !origin) {\n \t\twarning(_(\"Not setting branch %s as its own upstream.\"),\n@@ -77,29 +77,29 @@ void install_branch_config(int flag, const char *local, const char *origin, cons\n \tstrbuf_release(&key);\n \n \tif (flag & BRANCH_CONFIG_VERBOSE) {\n-\t\tif (remote_is_branch && origin)\n+\t\tif (shortname && 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\telse if (shortname && !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\telse if (!shortname && 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\telse if (!shortname && !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\t\tdie(\"BUG: impossible combination of %p and %p\",\n+\t\t\t    shortname, origin);\n \t}\n }\n \n-- \n1.8.3.4 (Apple Git-47)\n"}]}