diff options
author | Junio C Hamano <gitster@pobox.com> | 2020-01-30 11:35:46 -0800 |
---|---|---|
committer | Junio C Hamano <gitster@pobox.com> | 2020-01-31 13:03:45 -0800 |
commit | 145136a95a8755528aa012a4ce0ed50d1ec39e24 (patch) | |
tree | cdb54dc3d1730adf84bff93e743f55414ea8ea0e /builtin/fast-export.c | |
parent | Git 2.25 (diff) | |
download | tgif-145136a95a8755528aa012a4ce0ed50d1ec39e24.tar.xz |
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 'builtin/fast-export.c')
-rw-r--r-- | builtin/fast-export.c | 3 |
1 files changed, 1 insertions, 2 deletions
diff --git a/builtin/fast-export.c b/builtin/fast-export.c index dbec4df92b..164406fdd4 100644 --- a/builtin/fast-export.c +++ b/builtin/fast-export.c @@ -870,8 +870,7 @@ static void handle_tag(const char *name, struct tag *tag) printf("reset %s\nfrom %s\n\n", name, oid_to_hex(&null_oid)); } - if (starts_with(name, "refs/tags/")) - name += 10; + skip_prefix(name, "refs/tags/", &name); printf("tag %s\n", name); if (mark_tags) { mark_next_object(&tag->object); |