diff options
author | Jeff King <peff@peff.net> | 2017-02-15 16:40:52 -0500 |
---|---|---|
committer | Junio C Hamano <gitster@pobox.com> | 2017-02-15 13:50:31 -0800 |
commit | d3cc5f4c44eeacca556f9ae0972837a84e72f288 (patch) | |
tree | 9c3fee20aa69e546af697fcc4b2063ba6ba9d421 /builtin/show-branch.c | |
parent | show-branch: store resolved head in heap buffer (diff) | |
download | tgif-d3cc5f4c44eeacca556f9ae0972837a84e72f288.tar.xz |
show-branch: use skip_prefix to drop magic numbers
We make several starts_with() calls, only to advance
pointers. This is exactly what skip_prefix() is for, which
lets us avoid manually-counted magic numbers.
Helped-by: Pranit Bauva <pranit.bauva@gmail.com>
Signed-off-by: Jeff King <peff@peff.net>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
Diffstat (limited to 'builtin/show-branch.c')
-rw-r--r-- | builtin/show-branch.c | 19 |
1 files changed, 8 insertions, 11 deletions
diff --git a/builtin/show-branch.c b/builtin/show-branch.c index 705e492ce6..c438853330 100644 --- a/builtin/show-branch.c +++ b/builtin/show-branch.c @@ -275,8 +275,7 @@ static void show_one_commit(struct commit *commit, int no_name) pp_commit_easy(CMIT_FMT_ONELINE, commit, &pretty); pretty_str = pretty.buf; } - if (starts_with(pretty_str, "[PATCH] ")) - pretty_str += 8; + skip_prefix(pretty_str, "[PATCH] ", &pretty_str); if (!no_name) { if (name && name->head_name) { @@ -470,17 +469,14 @@ static void snarf_refs(int head, int remotes) } } -static int rev_is_head(char *head, char *name, +static int rev_is_head(const char *head, const char *name, unsigned char *head_sha1, unsigned char *sha1) { if (!head || (head_sha1 && sha1 && hashcmp(head_sha1, sha1))) return 0; - if (starts_with(head, "refs/heads/")) - head += 11; - if (starts_with(name, "refs/heads/")) - name += 11; - else if (starts_with(name, "heads/")) - name += 6; + skip_prefix(head, "refs/heads/", &head); + if (!skip_prefix(name, "refs/heads/", &name)) + skip_prefix(name, "heads/", &name); return !strcmp(head, name); } @@ -799,8 +795,9 @@ int cmd_show_branch(int ac, const char **av, const char *prefix) has_head++; } if (!has_head) { - int offset = starts_with(head, "refs/heads/") ? 11 : 0; - append_one_rev(head + offset); + const char *name = head; + skip_prefix(name, "refs/heads/", &name); + append_one_rev(name); } } |