branch: use skip_prefix() in install_branch_config()

The install_branch_config() function reimplemented the skip_prefix() function inline. Reported-by: Michael Haggerty <mhagger@alum.mit.edu> Signed-off-by: Brian Gesiak <modocache@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Brian Gesiak committed Feb 28, 2014 at 15:43 UTC 303d1d0bd660b56d25ac6016c085bb3856b08203
1 file changed +9 -9
branch.c
+9 -9
@@ -1,3 +1,4 @@
1 +#include "git-compat-util.h"
2 #include "cache.h"
3 #include "branch.h"
4 #include "refs.h"
@@ -49,12 +50,11 @@ static int should_setup_rebase(const char *origin)
50
51 void install_branch_config(int flag, const char *local, const char *origin, const char *remote)
52 {
52 - const char *shortname = remote + 11;
53 - int remote_is_branch = starts_with(remote, "refs/heads/");
53 + const char *shortname = skip_prefix(remote, "refs/heads/");
54 struct strbuf key = STRBUF_INIT;
55 int rebasing = should_setup_rebase(origin);
56
57 - if (remote_is_branch
57 + if (shortname
58 && !strcmp(local, shortname)
59 && !origin) {
60 warning(_("Not setting branch %s as its own upstream."),
@@ -77,29 +77,29 @@ void install_branch_config(int flag, const char *local, const char *origin, cons
77 strbuf_release(&key);
78
79 if (flag & BRANCH_CONFIG_VERBOSE) {
80 - if (remote_is_branch && origin)
80 + if (shortname && origin)
81 printf_ln(rebasing ?
82 _("Branch %s set up to track remote branch %s from %s by rebasing.") :
83 _("Branch %s set up to track remote branch %s from %s."),
84 local, shortname, origin);
85 - else if (remote_is_branch && !origin)
85 + else if (shortname && !origin)
86 printf_ln(rebasing ?
87 _("Branch %s set up to track local branch %s by rebasing.") :
88 _("Branch %s set up to track local branch %s."),
89 local, shortname);
90 - else if (!remote_is_branch && origin)
90 + else if (!shortname && origin)
91 printf_ln(rebasing ?
92 _("Branch %s set up to track remote ref %s by rebasing.") :
93 _("Branch %s set up to track remote ref %s."),
94 local, remote);
95 - else if (!remote_is_branch && !origin)
95 + else if (!shortname && !origin)
96 printf_ln(rebasing ?
97 _("Branch %s set up to track local ref %s by rebasing.") :
98 _("Branch %s set up to track local ref %s."),
99 local, remote);
100 else
101 - die("BUG: impossible combination of %d and %p",
102 - remote_is_branch, origin);
101 + die("BUG: impossible combination of %p and %p",
102 + shortname, origin);
103 }
104 }
105