Skip to content

Commit cd35085

Browse files
committed
object_type: GIT_OBJECT_BAD is now GIT_OBJECT_INVALID
We use the term "invalid" to refer to bad or malformed data, eg `GIT_REF_INVALID` and `GIT_EINVALIDSPEC`. Since we're changing the names of the `git_object_t`s in this release, update it to be `GIT_OBJECT_INVALID` instead of `BAD`.
1 parent 9004689 commit cd35085

File tree

10 files changed

+25
-25
lines changed

10 files changed

+25
-25
lines changed

include/git2/types.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ typedef int64_t git_time_t;
6969
/** Basic type (loose or packed) of any Git object. */
7070
typedef enum {
7171
GIT_OBJECT_ANY = -2, /**< Object can be any of the following */
72-
GIT_OBJECT_BAD = -1, /**< Object is invalid. */
72+
GIT_OBJECT_INVALID = -1, /**< Object is invalid. */
7373
GIT_OBJECT_COMMIT = 1, /**< A commit object. */
7474
GIT_OBJECT_TREE = 2, /**< A tree (directory listing) object. */
7575
GIT_OBJECT_BLOB = 3, /**< A file revision object. */
@@ -451,7 +451,7 @@ typedef struct git_mailmap git_mailmap;
451451
/**@{*/
452452

453453
GIT_DEPRECATED(static const int) GIT_OBJ_ANY = GIT_OBJECT_ANY;
454-
GIT_DEPRECATED(static const int) GIT_OBJ_BAD = GIT_OBJECT_BAD;
454+
GIT_DEPRECATED(static const int) GIT_OBJ_BAD = GIT_OBJECT_INVALID;
455455
GIT_DEPRECATED(static const int) GIT_OBJ__EXT1 = 0;
456456
GIT_DEPRECATED(static const int) GIT_OBJ_COMMIT = GIT_OBJECT_COMMIT;
457457
GIT_DEPRECATED(static const int) GIT_OBJ_TREE = GIT_OBJECT_TREE;

src/object.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -288,7 +288,7 @@ const char *git_object_type2string(git_object_t type)
288288
git_object_t git_object_string2type(const char *str)
289289
{
290290
if (!str)
291-
return GIT_OBJECT_BAD;
291+
return GIT_OBJECT_INVALID;
292292

293293
return git_object_stringn2type(str, strlen(str));
294294
}
@@ -298,14 +298,14 @@ git_object_t git_object_stringn2type(const char *str, size_t len)
298298
size_t i;
299299

300300
if (!str || !len || !*str)
301-
return GIT_OBJECT_BAD;
301+
return GIT_OBJECT_INVALID;
302302

303303
for (i = 0; i < ARRAY_SIZE(git_objects_table); i++)
304304
if (*git_objects_table[i].str &&
305305
!git__prefixncmp(str, len, git_objects_table[i].str))
306306
return (git_object_t)i;
307307

308-
return GIT_OBJECT_BAD;
308+
return GIT_OBJECT_INVALID;
309309
}
310310

311311
int git_object_typeisloose(git_object_t type)

src/object.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ GIT_INLINE(git_object_t) git_object__type_from_filemode(git_filemode_t mode)
6262
case GIT_FILEMODE_LINK:
6363
return GIT_OBJECT_BLOB;
6464
default:
65-
return GIT_OBJECT_BAD;
65+
return GIT_OBJECT_INVALID;
6666
}
6767
}
6868

src/odb.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ static git_object_t odb_hardcoded_type(const git_oid *id)
6363
if (!git_oid_cmp(id, &empty_tree))
6464
return GIT_OBJECT_TREE;
6565

66-
return GIT_OBJECT_BAD;
66+
return GIT_OBJECT_INVALID;
6767
}
6868

6969
static int odb_read_hardcoded(bool *found, git_rawobj *raw, const git_oid *id)
@@ -72,7 +72,7 @@ static int odb_read_hardcoded(bool *found, git_rawobj *raw, const git_oid *id)
7272

7373
*found = false;
7474

75-
if ((type = odb_hardcoded_type(id)) == GIT_OBJECT_BAD)
75+
if ((type = odb_hardcoded_type(id)) == GIT_OBJECT_INVALID)
7676
return 0;
7777

7878
raw->type = type;
@@ -945,7 +945,7 @@ static int odb_read_header_1(
945945
bool passthrough = false;
946946
int error;
947947

948-
if (!only_refreshed && (ht = odb_hardcoded_type(id)) != GIT_OBJECT_BAD) {
948+
if (!only_refreshed && (ht = odb_hardcoded_type(id)) != GIT_OBJECT_INVALID) {
949949
*type_p = ht;
950950
*len_p = 0;
951951
return 0;

src/odb_loose.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -351,7 +351,7 @@ static int read_loose(git_rawobj *out, git_buf *loc)
351351

352352
out->data = NULL;
353353
out->len = 0;
354-
out->type = GIT_OBJECT_BAD;
354+
out->type = GIT_OBJECT_INVALID;
355355

356356
if ((error = git_futils_readbuffer(&obj, loc->ptr)) < 0)
357357
goto done;
@@ -583,7 +583,7 @@ static int loose_backend__read_header(size_t *len_p, git_object_t *type_p, git_o
583583
assert(backend && oid);
584584

585585
raw.len = 0;
586-
raw.type = GIT_OBJECT_BAD;
586+
raw.type = GIT_OBJECT_INVALID;
587587

588588
if (locate_object(&object_path, (loose_backend *)backend, oid) < 0) {
589589
error = git_odb__error_notfound("no matching loose object",
@@ -989,7 +989,7 @@ static int loose_backend__readstream(
989989
backend = (loose_backend *)_backend;
990990
*stream_out = NULL;
991991
*len_out = 0;
992-
*type_out = GIT_OBJECT_BAD;
992+
*type_out = GIT_OBJECT_INVALID;
993993

994994
if (locate_object(&object_path, backend, oid) < 0) {
995995
error = git_odb__error_notfound("no matching loose object",

src/pack.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -644,7 +644,7 @@ int git_packfile_unpack(
644644

645645
obj->data = NULL;
646646
obj->len = 0;
647-
obj->type = GIT_OBJECT_BAD;
647+
obj->type = GIT_OBJECT_INVALID;
648648

649649
/* let's point to the right stack */
650650
stack = chain.ptr ? chain.ptr : small_stack;
@@ -726,7 +726,7 @@ int git_packfile_unpack(
726726
base = *obj;
727727
obj->data = NULL;
728728
obj->len = 0;
729-
obj->type = GIT_OBJECT_BAD;
729+
obj->type = GIT_OBJECT_INVALID;
730730

731731
error = git_delta_apply(&obj->data, &obj->len, base.data, base.len, delta.data, delta.len);
732732
obj->type = base_type;

src/revparse.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -369,7 +369,7 @@ static git_object_t parse_obj_type(const char *str)
369369
if (!strcmp(str, "tag"))
370370
return GIT_OBJECT_TAG;
371371

372-
return GIT_OBJECT_BAD;
372+
return GIT_OBJECT_INVALID;
373373
}
374374

375375
static int dereference_to_non_tag(git_object **out, git_object *obj)
@@ -515,7 +515,7 @@ static int handle_caret_curly_syntax(git_object **out, git_object *obj, const ch
515515

516516
expected_type = parse_obj_type(curly_braces_content);
517517

518-
if (expected_type == GIT_OBJECT_BAD)
518+
if (expected_type == GIT_OBJECT_INVALID)
519519
return GIT_EINVALIDSPEC;
520520

521521
return git_object_peel(out, obj, expected_type);

src/tag.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ static int tag_parse(git_tag *tag, const char *buffer, const char *buffer_end)
8484
return tag_error("type field not found");
8585
buffer += 5;
8686

87-
tag->type = GIT_OBJECT_BAD;
87+
tag->type = GIT_OBJECT_INVALID;
8888

8989
for (i = 1; i < ARRAY_SIZE(tag_types); ++i) {
9090
size_t type_length = strlen(tag_types[i]);
@@ -99,7 +99,7 @@ static int tag_parse(git_tag *tag, const char *buffer, const char *buffer_end)
9999
}
100100
}
101101

102-
if (tag->type == GIT_OBJECT_BAD)
102+
if (tag->type == GIT_OBJECT_INVALID)
103103
return tag_error("invalid object type");
104104

105105
if (buffer + 4 >= buffer_end)

tests/object/raw/data.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -319,5 +319,5 @@ static git_rawobj some_obj = {
319319
static git_rawobj junk_obj = {
320320
NULL,
321321
0,
322-
GIT_OBJECT_BAD
322+
GIT_OBJECT_INVALID
323323
};

tests/object/raw/type2string.c

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66

77
void test_object_raw_type2string__convert_type_to_string(void)
88
{
9-
cl_assert_equal_s(git_object_type2string(GIT_OBJECT_BAD), "");
9+
cl_assert_equal_s(git_object_type2string(GIT_OBJECT_INVALID), "");
1010
cl_assert_equal_s(git_object_type2string(0), ""); /* EXT1 */
1111
cl_assert_equal_s(git_object_type2string(GIT_OBJECT_COMMIT), "commit");
1212
cl_assert_equal_s(git_object_type2string(GIT_OBJECT_TREE), "tree");
@@ -23,22 +23,22 @@ void test_object_raw_type2string__convert_type_to_string(void)
2323

2424
void test_object_raw_type2string__convert_string_to_type(void)
2525
{
26-
cl_assert(git_object_string2type(NULL) == GIT_OBJECT_BAD);
27-
cl_assert(git_object_string2type("") == GIT_OBJECT_BAD);
26+
cl_assert(git_object_string2type(NULL) == GIT_OBJECT_INVALID);
27+
cl_assert(git_object_string2type("") == GIT_OBJECT_INVALID);
2828
cl_assert(git_object_string2type("commit") == GIT_OBJECT_COMMIT);
2929
cl_assert(git_object_string2type("tree") == GIT_OBJECT_TREE);
3030
cl_assert(git_object_string2type("blob") == GIT_OBJECT_BLOB);
3131
cl_assert(git_object_string2type("tag") == GIT_OBJECT_TAG);
3232
cl_assert(git_object_string2type("OFS_DELTA") == GIT_OBJECT_OFS_DELTA);
3333
cl_assert(git_object_string2type("REF_DELTA") == GIT_OBJECT_REF_DELTA);
3434

35-
cl_assert(git_object_string2type("CoMmIt") == GIT_OBJECT_BAD);
36-
cl_assert(git_object_string2type("hohoho") == GIT_OBJECT_BAD);
35+
cl_assert(git_object_string2type("CoMmIt") == GIT_OBJECT_INVALID);
36+
cl_assert(git_object_string2type("hohoho") == GIT_OBJECT_INVALID);
3737
}
3838

3939
void test_object_raw_type2string__check_type_is_loose(void)
4040
{
41-
cl_assert(git_object_typeisloose(GIT_OBJECT_BAD) == 0);
41+
cl_assert(git_object_typeisloose(GIT_OBJECT_INVALID) == 0);
4242
cl_assert(git_object_typeisloose(0) == 0); /* EXT1 */
4343
cl_assert(git_object_typeisloose(GIT_OBJECT_COMMIT) == 1);
4444
cl_assert(git_object_typeisloose(GIT_OBJECT_TREE) == 1);

0 commit comments

Comments
 (0)