summaryrefslogtreecommitdiff
path: root/notes.c
diff options
context:
space:
mode:
authorJunio C Hamano <gitster@pobox.com>2020-01-30 19:35:46 (GMT)
committerJunio C Hamano <gitster@pobox.com>2020-01-31 21:03:45 (GMT)
commit145136a95a8755528aa012a4ce0ed50d1ec39e24 (patch)
treecdb54dc3d1730adf84bff93e743f55414ea8ea0e /notes.c
parentd0654dc308b0ba76dd8ed7bbb33c8d8f7aacd783 (diff)
downloadgit-145136a95a8755528aa012a4ce0ed50d1ec39e24.zip
git-145136a95a8755528aa012a4ce0ed50d1ec39e24.tar.gz
git-145136a95a8755528aa012a4ce0ed50d1ec39e24.tar.bz2
C: use skip_prefix() to avoid hardcoded string length
We often skip an optional prefix in a string with a hardcoded constant, e.g. if (starts_with(string, "prefix")) string += 6; which is less error prone when written skip_prefix(string, "prefix", &string); Note that this changes a few error messages from "git reflog expire --expire=nonsense.timestamp", which used to complain by saying '--expire=nonsense.timestamp' is not a valid timestamp but with this change, we say 'nonsense.timestamp' is not a valid timestamp which is more technically correct (the string with --expire= as a prefix obviously cannot be a valid timestamp, but the error is about the part of the input without that prefix). Helped-by: Jeff King <peff@peff.net> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Diffstat (limited to 'notes.c')
-rw-r--r--notes.c6
1 files changed, 2 insertions, 4 deletions
diff --git a/notes.c b/notes.c
index 0c79964..a0349fa 100644
--- a/notes.c
+++ b/notes.c
@@ -1279,10 +1279,8 @@ static void format_note(struct notes_tree *t, const struct object_id *object_oid
if (!ref || !strcmp(ref, GIT_NOTES_DEFAULT_REF)) {
strbuf_addstr(sb, "\nNotes:\n");
} else {
- if (starts_with(ref, "refs/"))
- ref += 5;
- if (starts_with(ref, "notes/"))
- ref += 6;
+ skip_prefix(ref, "refs/", &ref);
+ skip_prefix(ref, "notes/", &ref);
strbuf_addf(sb, "\nNotes (%s):\n", ref);
}
}