summaryrefslogtreecommitdiff
path: root/help.c
diff options
context:
space:
mode:
authorJeff King <peff@peff.net>2014-06-18 19:48:29 (GMT)
committerJunio C Hamano <gitster@pobox.com>2014-06-20 17:44:45 (GMT)
commit95b567c7c3cf6b85d74b79424cdfbd40a7dee7c9 (patch)
treee150b9f71b846bb3245577b55b9ba536bf5a6bfd /help.c
parentae021d87911da4328157273df24779892cb51277 (diff)
downloadgit-95b567c7c3cf6b85d74b79424cdfbd40a7dee7c9.zip
git-95b567c7c3cf6b85d74b79424cdfbd40a7dee7c9.tar.gz
git-95b567c7c3cf6b85d74b79424cdfbd40a7dee7c9.tar.bz2
use skip_prefix to avoid repeating strings
It's a common idiom to match a prefix and then skip past it with strlen, like: if (starts_with(foo, "bar")) foo += strlen("bar"); This avoids magic numbers, but means we have to repeat the string (and there is no compiler check that we didn't make a typo in one of the strings). We can use skip_prefix to handle this case without repeating ourselves. Signed-off-by: Jeff King <peff@peff.net> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Diffstat (limited to 'help.c')
-rw-r--r--help.c7
1 files changed, 4 insertions, 3 deletions
diff --git a/help.c b/help.c
index b0f1a69..79e8007 100644
--- a/help.c
+++ b/help.c
@@ -414,11 +414,12 @@ static int append_similar_ref(const char *refname, const unsigned char *sha1,
{
struct similar_ref_cb *cb = (struct similar_ref_cb *)(cb_data);
char *branch = strrchr(refname, '/') + 1;
+ const char *remote;
+
/* A remote branch of the same name is deemed similar */
- if (starts_with(refname, "refs/remotes/") &&
+ if (skip_prefix(refname, "refs/remotes/", &remote) &&
!strcmp(branch, cb->base_ref))
- string_list_append(cb->similar_refs,
- refname + strlen("refs/remotes/"));
+ string_list_append(cb->similar_refs, remote);
return 0;
}