Skip to content

Commit 6aea6ba

Browse files
avargitster
authored andcommitted
object-file API: pass an enum to read_object_with_reference()
Change the read_object_with_reference() function to take an "enum object_type". It was not prepared to handle an arbitrary "const char *type", as it was itself calling type_from_string(). Let's change the only caller that passes in user data to use type_from_string(), and convert the rest to use e.g. "OBJ_TREE" instead of "tree_type". The "cat-file" caller is not on the codepath that handles"--allow-unknown", so the type_from_string() there is safe. Its use of type_from_string() doesn't functionally differ from that of the pre-image. Signed-off-by: Ævar Arnfjörð Bjarmason <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 2bbb28a commit 6aea6ba

File tree

7 files changed

+19
-17
lines changed

7 files changed

+19
-17
lines changed

builtin/cat-file.c

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -154,7 +154,10 @@ static int cat_one_file(int opt, const char *exp_type, const char *obj_name,
154154
break;
155155

156156
case 0:
157-
if (type_from_string(exp_type) == OBJ_BLOB) {
157+
{
158+
enum object_type exp_type_id = type_from_string(exp_type);
159+
160+
if (exp_type_id == OBJ_BLOB) {
158161
struct object_id blob_oid;
159162
if (oid_object_info(the_repository, &oid, NULL) == OBJ_TAG) {
160163
char *buffer = read_object_file(&oid, &type,
@@ -176,10 +179,10 @@ static int cat_one_file(int opt, const char *exp_type, const char *obj_name,
176179
* fall-back to the usual case.
177180
*/
178181
}
179-
buf = read_object_with_reference(the_repository,
180-
&oid, exp_type, &size, NULL);
182+
buf = read_object_with_reference(the_repository, &oid,
183+
exp_type_id, &size, NULL);
181184
break;
182-
185+
}
183186
default:
184187
die("git cat-file: unknown option: %s", exp_type);
185188
}

builtin/fast-import.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2483,7 +2483,7 @@ static void note_change_n(const char *p, struct branch *b, unsigned char *old_fa
24832483
unsigned long size;
24842484
char *buf = read_object_with_reference(the_repository,
24852485
&commit_oid,
2486-
commit_type, &size,
2486+
OBJ_COMMIT, &size,
24872487
&commit_oid);
24882488
if (!buf || size < the_hash_algo->hexsz + 6)
24892489
die("Not a valid commit: %s", p);
@@ -2555,7 +2555,7 @@ static void parse_from_existing(struct branch *b)
25552555
char *buf;
25562556

25572557
buf = read_object_with_reference(the_repository,
2558-
&b->oid, commit_type, &size,
2558+
&b->oid, OBJ_COMMIT, &size,
25592559
&b->oid);
25602560
parse_from_commit(b, buf, size);
25612561
free(buf);
@@ -2651,7 +2651,7 @@ static struct hash_list *parse_merge(unsigned int *count)
26512651
unsigned long size;
26522652
char *buf = read_object_with_reference(the_repository,
26532653
&n->oid,
2654-
commit_type,
2654+
OBJ_COMMIT,
26552655
&size, &n->oid);
26562656
if (!buf || size < the_hash_algo->hexsz + 6)
26572657
die("Not a valid commit: %s", from);

builtin/grep.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -482,7 +482,7 @@ static int grep_submodule(struct grep_opt *opt,
482482
object_type = oid_object_info(subrepo, oid, NULL);
483483
obj_read_unlock();
484484
data = read_object_with_reference(subrepo,
485-
oid, tree_type,
485+
oid, OBJ_TREE,
486486
&size, NULL);
487487
if (!data)
488488
die(_("unable to read tree (%s)"), oid_to_hex(oid));
@@ -651,7 +651,7 @@ static int grep_object(struct grep_opt *opt, const struct pathspec *pathspec,
651651
int hit, len;
652652

653653
data = read_object_with_reference(opt->repo,
654-
&obj->oid, tree_type,
654+
&obj->oid, OBJ_TREE,
655655
&size, NULL);
656656
if (!data)
657657
die(_("unable to read tree (%s)"), oid_to_hex(&obj->oid));

builtin/pack-objects.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1802,7 +1802,7 @@ static void add_preferred_base(struct object_id *oid)
18021802
return;
18031803

18041804
data = read_object_with_reference(the_repository, oid,
1805-
tree_type, &size, &tree_oid);
1805+
OBJ_TREE, &size, &tree_oid);
18061806
if (!data)
18071807
return;
18081808

cache.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1561,7 +1561,7 @@ int cache_name_stage_compare(const char *name1, int len1, int stage1, const char
15611561

15621562
void *read_object_with_reference(struct repository *r,
15631563
const struct object_id *oid,
1564-
const char *required_type,
1564+
enum object_type required_type,
15651565
unsigned long *size,
15661566
struct object_id *oid_ret);
15671567

object-file.c

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1737,16 +1737,15 @@ void *read_object_file_extended(struct repository *r,
17371737

17381738
void *read_object_with_reference(struct repository *r,
17391739
const struct object_id *oid,
1740-
const char *required_type_name,
1740+
enum object_type required_type,
17411741
unsigned long *size,
17421742
struct object_id *actual_oid_return)
17431743
{
1744-
enum object_type type, required_type;
1744+
enum object_type type;
17451745
void *buffer;
17461746
unsigned long isize;
17471747
struct object_id actual_oid;
17481748

1749-
required_type = type_from_string(required_type_name);
17501749
oidcpy(&actual_oid, oid);
17511750
while (1) {
17521751
int ref_length = -1;

tree-walk.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@ void *fill_tree_descriptor(struct repository *r,
8989
void *buf = NULL;
9090

9191
if (oid) {
92-
buf = read_object_with_reference(r, oid, tree_type, &size, NULL);
92+
buf = read_object_with_reference(r, oid, OBJ_TREE, &size, NULL);
9393
if (!buf)
9494
die("unable to read tree %s", oid_to_hex(oid));
9595
}
@@ -605,7 +605,7 @@ int get_tree_entry(struct repository *r,
605605
unsigned long size;
606606
struct object_id root;
607607

608-
tree = read_object_with_reference(r, tree_oid, tree_type, &size, &root);
608+
tree = read_object_with_reference(r, tree_oid, OBJ_TREE, &size, &root);
609609
if (!tree)
610610
return -1;
611611

@@ -677,7 +677,7 @@ enum get_oid_result get_tree_entry_follow_symlinks(struct repository *r,
677677
unsigned long size;
678678
tree = read_object_with_reference(r,
679679
&current_tree_oid,
680-
tree_type, &size,
680+
OBJ_TREE, &size,
681681
&root);
682682
if (!tree)
683683
goto done;

0 commit comments

Comments
 (0)