Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.kernel.org/pub/scm/git/git.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJunio C Hamano <gitster@pobox.com>2020-01-30 22:35:46 +0300
committerJunio C Hamano <gitster@pobox.com>2020-02-01 00:03:45 +0300
commit145136a95a8755528aa012a4ce0ed50d1ec39e24 (patch)
treecdb54dc3d1730adf84bff93e743f55414ea8ea0e /parse-options.c
parentd0654dc308b0ba76dd8ed7bbb33c8d8f7aacd783 (diff)
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 'parse-options.c')
-rw-r--r--parse-options.c3
1 files changed, 1 insertions, 2 deletions
diff --git a/parse-options.c b/parse-options.c
index 60fae3ad21..e8c04109ba 100644
--- a/parse-options.c
+++ b/parse-options.c
@@ -357,8 +357,7 @@ is_abbreviated:
}
/* negated? */
if (!starts_with(arg, "no-")) {
- if (starts_with(long_name, "no-")) {
- long_name += 3;
+ if (skip_prefix(long_name, "no-", &long_name)) {
opt_flags |= OPT_UNSET;
goto again;
}