Get rid of the "gently" argument to type_from_string_gently() to make it consistent with most other *_gently() functions. This refactoring of adding a third parameter was done in fe8e3b71805 (Refactor type_from_string() to allow continuing after detecting an error, 2014-09-10) in preparation for its use in fsck.c. Since then no callers of this function have passed a "len < 0" as was expected might happen, so we can simplify its invocation by knowing that it's never called like that. Signed-off-by: Ævar Arnfjörð Bjarmason <avarab@xxxxxxxxx> --- fsck.c | 2 +- object-file.c | 2 +- object.c | 18 ++++++++++-------- object.h | 4 ++-- 4 files changed, 14 insertions(+), 12 deletions(-) diff --git a/fsck.c b/fsck.c index e3030f3b358..6cc4f9ea892 100644 --- a/fsck.c +++ b/fsck.c @@ -957,7 +957,7 @@ int fsck_tag_standalone(const struct object_id *oid, const char *buffer, ret = report(options, oid, OBJ_TAG, FSCK_MSG_MISSING_TYPE, "invalid format - unexpected end after 'type' line"); goto done; } - *tagged_type = type_from_string_gently(buffer, eol - buffer, 1); + *tagged_type = type_from_string_gently(buffer, eol - buffer); if (*tagged_type < 0) ret = report(options, oid, OBJ_TAG, FSCK_MSG_BAD_TYPE, "invalid 'type' value"); if (ret) diff --git a/object-file.c b/object-file.c index 5bcfde84718..42bc579828d 100644 --- a/object-file.c +++ b/object-file.c @@ -1314,7 +1314,7 @@ static int parse_loose_header_extended(const char *hdr, struct object_info *oi, type_len++; } - type = type_from_string_gently(type_buf, type_len, 1); + type = type_from_string_gently(type_buf, type_len); if (oi->type_name) strbuf_add(oi->type_name, type_buf, type_len); /* diff --git a/object.c b/object.c index 98017bed8ef..c7586e46727 100644 --- a/object.c +++ b/object.c @@ -35,22 +35,24 @@ const char *type_name(unsigned int type) return object_type_strings[type]; } -int type_from_string_gently(const char *str, ssize_t len, int gentle) +int type_from_string_gently(const char *str, ssize_t len) { int i; - if (len < 0) - len = strlen(str); - for (i = 1; i < ARRAY_SIZE(object_type_strings); i++) if (!strncmp(str, object_type_strings[i], len) && object_type_strings[i][len] == '\0') return i; + return -1; +} - if (gentle) - return -1; - - die(_("invalid object type \"%s\""), str); +int type_from_string(const char *str) +{ + size_t len = strlen(str); + int ret = type_from_string_gently(str, len); + if (ret < 0) + die(_("invalid object type \"%s\""), str); + return ret; } /* diff --git a/object.h b/object.h index 59daadce214..ffdc1298300 100644 --- a/object.h +++ b/object.h @@ -93,8 +93,8 @@ struct object { }; const char *type_name(unsigned int type); -int type_from_string_gently(const char *str, ssize_t, int gentle); -#define type_from_string(str) type_from_string_gently(str, -1, 0) +int type_from_string_gently(const char *str, ssize_t len); +int type_from_string(const char *str); /* * Return the current number of buckets in the object hashmap. -- 2.31.0.rc1.210.g0f8085a843c