diff mbox series

[v2,03/10] object.c: make type_from_string() return "enum object_type"

Message ID patch-03.10-f0ec7d1dbb-20210420T125416Z-avarab@gmail.com (mailing list archive)
State New
Headers show
Series {tag,object}*.c: refactorings + prep for a larger change | expand

Commit Message

Ævar Arnfjörð Bjarmason April 20, 2021, 1 p.m. UTC
Change the type_from_string*() functions to return an "enum
object_type", but don't refactor their callers to check for "==
OBJ_BAD" instead of "< 0".

Refactoring the check of the return value to check == OBJ_BAD would
now be equivalent to "ret < 0", but the consensus on an earlier
version of this patch was to not do that, and to instead use -1
consistently as a return value. It just so happens that OBJ_BAD == -1,
but let's not put a hard reliance on that.

Signed-off-by: Ævar Arnfjörð Bjarmason <avarab@gmail.com>
---
 object.c | 8 ++++----
 object.h | 4 ++--
 2 files changed, 6 insertions(+), 6 deletions(-)
diff mbox series

Patch

diff --git a/object.c b/object.c
index 7028243c9a..8f3ddfc8f4 100644
--- a/object.c
+++ b/object.c
@@ -35,9 +35,9 @@  const char *type_name(unsigned int type)
 	return object_type_strings[type];
 }
 
-int type_from_string_gently(const char *str, size_t len)
+enum object_type type_from_string_gently(const char *str, size_t len)
 {
-	int i;
+	enum object_type i;
 
 	if (len == ~(size_t)0)
 		BUG("type-from-string-gently no longer allows unspecified length");
@@ -49,10 +49,10 @@  int type_from_string_gently(const char *str, size_t len)
 	return -1;
 }
 
-int type_from_string(const char *str)
+enum object_type type_from_string(const char *str)
 {
 	size_t len = strlen(str);
-	int ret = type_from_string_gently(str, len);
+	enum object_type 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 470b3c1b86..a4eca10d72 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, size_t len);
-int type_from_string(const char *str);
+enum object_type type_from_string_gently(const char *str, size_t len);
+enum object_type type_from_string(const char *str);
 
 /*
  * Return the current number of buckets in the object hashmap.