Skip to content

Commit b32b434

Browse files
peffgitster
authored andcommitted
oid_object_info_convert(): stop using string for object type
In oid_object_info_convert(), we convert objects between their sha1 and sha256 variants. To do this, we naturally need to know the type, which we get from oid_object_info_extended() using its type_name strbuf option. But getting the value as a string (versus an object_type enum) is not helpful. Since we do not allow unknown types, the regular enum is sufficient. And the resulting code is a bit simpler, as we no longer have to manage the extra allocation nor convert the string to an enum ourselves. Note that at first glance, it might seem like we should retain the error check for "type == -1" to catch bogus types found by the underlying parser. But we don't need it, as an unknown type would have yielded an error from the call to oid_object_info_extended(), which would already have caused us to return an error. In fact, I suspect this was always impossible to trigger. Even when we were converting the string to a type enum ourselves, an invalid type would never have escaped oid_object_info_extended(), since we never passed the (now removed) OBJECT_INFO_ALLOW_UNKNOWN_TYPE option. Signed-off-by: Jeff King <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent aac2abe commit b32b434

File tree

1 file changed

+4
-11
lines changed

1 file changed

+4
-11
lines changed

object-store.c

Lines changed: 4 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -727,7 +727,7 @@ static int oid_object_info_convert(struct repository *r,
727727
{
728728
const struct git_hash_algo *input_algo = &hash_algos[input_oid->algo];
729729
int do_die = flags & OBJECT_INFO_DIE_IF_CORRUPT;
730-
struct strbuf type_name = STRBUF_INIT;
730+
enum object_type type;
731731
struct object_id oid, delta_base_oid;
732732
struct object_info new_oi, *oi;
733733
unsigned long size;
@@ -753,7 +753,7 @@ static int oid_object_info_convert(struct repository *r,
753753
if (input_oi->sizep || input_oi->contentp) {
754754
new_oi.contentp = &content;
755755
new_oi.sizep = &size;
756-
new_oi.type_name = &type_name;
756+
new_oi.typep = &type;
757757
}
758758
oi = &new_oi;
759759
}
@@ -766,12 +766,7 @@ static int oid_object_info_convert(struct repository *r,
766766

767767
if (new_oi.contentp) {
768768
struct strbuf outbuf = STRBUF_INIT;
769-
enum object_type type;
770769

771-
type = type_from_string_gently(type_name.buf, type_name.len,
772-
!do_die);
773-
if (type == -1)
774-
return -1;
775770
if (type != OBJ_BLOB) {
776771
ret = convert_object_file(the_repository, &outbuf,
777772
the_hash_algo, input_algo,
@@ -788,10 +783,8 @@ static int oid_object_info_convert(struct repository *r,
788783
*input_oi->contentp = content;
789784
else
790785
free(content);
791-
if (input_oi->type_name)
792-
*input_oi->type_name = type_name;
793-
else
794-
strbuf_release(&type_name);
786+
if (input_oi->typep)
787+
*input_oi->typep = type;
795788
}
796789
if (new_oi.delta_base_oid == &delta_base_oid) {
797790
if (repo_oid_to_algop(r, &delta_base_oid, input_algo,

0 commit comments

Comments
 (0)