mirror of
https://github.com/git/git
synced 2024-10-02 14:45:21 +00:00
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 <avarab@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
This commit is contained in:
parent
2bbb28a3ee
commit
6aea6baeb3
|
@ -154,7 +154,10 @@ static int cat_one_file(int opt, const char *exp_type, const char *obj_name,
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case 0:
|
case 0:
|
||||||
if (type_from_string(exp_type) == OBJ_BLOB) {
|
{
|
||||||
|
enum object_type exp_type_id = type_from_string(exp_type);
|
||||||
|
|
||||||
|
if (exp_type_id == OBJ_BLOB) {
|
||||||
struct object_id blob_oid;
|
struct object_id blob_oid;
|
||||||
if (oid_object_info(the_repository, &oid, NULL) == OBJ_TAG) {
|
if (oid_object_info(the_repository, &oid, NULL) == OBJ_TAG) {
|
||||||
char *buffer = read_object_file(&oid, &type,
|
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,
|
||||||
* fall-back to the usual case.
|
* fall-back to the usual case.
|
||||||
*/
|
*/
|
||||||
}
|
}
|
||||||
buf = read_object_with_reference(the_repository,
|
buf = read_object_with_reference(the_repository, &oid,
|
||||||
&oid, exp_type, &size, NULL);
|
exp_type_id, &size, NULL);
|
||||||
break;
|
break;
|
||||||
|
}
|
||||||
default:
|
default:
|
||||||
die("git cat-file: unknown option: %s", exp_type);
|
die("git cat-file: unknown option: %s", exp_type);
|
||||||
}
|
}
|
||||||
|
|
|
@ -2483,7 +2483,7 @@ static void note_change_n(const char *p, struct branch *b, unsigned char *old_fa
|
||||||
unsigned long size;
|
unsigned long size;
|
||||||
char *buf = read_object_with_reference(the_repository,
|
char *buf = read_object_with_reference(the_repository,
|
||||||
&commit_oid,
|
&commit_oid,
|
||||||
commit_type, &size,
|
OBJ_COMMIT, &size,
|
||||||
&commit_oid);
|
&commit_oid);
|
||||||
if (!buf || size < the_hash_algo->hexsz + 6)
|
if (!buf || size < the_hash_algo->hexsz + 6)
|
||||||
die("Not a valid commit: %s", p);
|
die("Not a valid commit: %s", p);
|
||||||
|
@ -2555,7 +2555,7 @@ static void parse_from_existing(struct branch *b)
|
||||||
char *buf;
|
char *buf;
|
||||||
|
|
||||||
buf = read_object_with_reference(the_repository,
|
buf = read_object_with_reference(the_repository,
|
||||||
&b->oid, commit_type, &size,
|
&b->oid, OBJ_COMMIT, &size,
|
||||||
&b->oid);
|
&b->oid);
|
||||||
parse_from_commit(b, buf, size);
|
parse_from_commit(b, buf, size);
|
||||||
free(buf);
|
free(buf);
|
||||||
|
@ -2651,7 +2651,7 @@ static struct hash_list *parse_merge(unsigned int *count)
|
||||||
unsigned long size;
|
unsigned long size;
|
||||||
char *buf = read_object_with_reference(the_repository,
|
char *buf = read_object_with_reference(the_repository,
|
||||||
&n->oid,
|
&n->oid,
|
||||||
commit_type,
|
OBJ_COMMIT,
|
||||||
&size, &n->oid);
|
&size, &n->oid);
|
||||||
if (!buf || size < the_hash_algo->hexsz + 6)
|
if (!buf || size < the_hash_algo->hexsz + 6)
|
||||||
die("Not a valid commit: %s", from);
|
die("Not a valid commit: %s", from);
|
||||||
|
|
|
@ -482,7 +482,7 @@ static int grep_submodule(struct grep_opt *opt,
|
||||||
object_type = oid_object_info(subrepo, oid, NULL);
|
object_type = oid_object_info(subrepo, oid, NULL);
|
||||||
obj_read_unlock();
|
obj_read_unlock();
|
||||||
data = read_object_with_reference(subrepo,
|
data = read_object_with_reference(subrepo,
|
||||||
oid, tree_type,
|
oid, OBJ_TREE,
|
||||||
&size, NULL);
|
&size, NULL);
|
||||||
if (!data)
|
if (!data)
|
||||||
die(_("unable to read tree (%s)"), oid_to_hex(oid));
|
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,
|
||||||
int hit, len;
|
int hit, len;
|
||||||
|
|
||||||
data = read_object_with_reference(opt->repo,
|
data = read_object_with_reference(opt->repo,
|
||||||
&obj->oid, tree_type,
|
&obj->oid, OBJ_TREE,
|
||||||
&size, NULL);
|
&size, NULL);
|
||||||
if (!data)
|
if (!data)
|
||||||
die(_("unable to read tree (%s)"), oid_to_hex(&obj->oid));
|
die(_("unable to read tree (%s)"), oid_to_hex(&obj->oid));
|
||||||
|
|
|
@ -1802,7 +1802,7 @@ static void add_preferred_base(struct object_id *oid)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
data = read_object_with_reference(the_repository, oid,
|
data = read_object_with_reference(the_repository, oid,
|
||||||
tree_type, &size, &tree_oid);
|
OBJ_TREE, &size, &tree_oid);
|
||||||
if (!data)
|
if (!data)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
|
|
2
cache.h
2
cache.h
|
@ -1561,7 +1561,7 @@ int cache_name_stage_compare(const char *name1, int len1, int stage1, const char
|
||||||
|
|
||||||
void *read_object_with_reference(struct repository *r,
|
void *read_object_with_reference(struct repository *r,
|
||||||
const struct object_id *oid,
|
const struct object_id *oid,
|
||||||
const char *required_type,
|
enum object_type required_type,
|
||||||
unsigned long *size,
|
unsigned long *size,
|
||||||
struct object_id *oid_ret);
|
struct object_id *oid_ret);
|
||||||
|
|
||||||
|
|
|
@ -1737,16 +1737,15 @@ void *read_object_file_extended(struct repository *r,
|
||||||
|
|
||||||
void *read_object_with_reference(struct repository *r,
|
void *read_object_with_reference(struct repository *r,
|
||||||
const struct object_id *oid,
|
const struct object_id *oid,
|
||||||
const char *required_type_name,
|
enum object_type required_type,
|
||||||
unsigned long *size,
|
unsigned long *size,
|
||||||
struct object_id *actual_oid_return)
|
struct object_id *actual_oid_return)
|
||||||
{
|
{
|
||||||
enum object_type type, required_type;
|
enum object_type type;
|
||||||
void *buffer;
|
void *buffer;
|
||||||
unsigned long isize;
|
unsigned long isize;
|
||||||
struct object_id actual_oid;
|
struct object_id actual_oid;
|
||||||
|
|
||||||
required_type = type_from_string(required_type_name);
|
|
||||||
oidcpy(&actual_oid, oid);
|
oidcpy(&actual_oid, oid);
|
||||||
while (1) {
|
while (1) {
|
||||||
int ref_length = -1;
|
int ref_length = -1;
|
||||||
|
|
|
@ -89,7 +89,7 @@ void *fill_tree_descriptor(struct repository *r,
|
||||||
void *buf = NULL;
|
void *buf = NULL;
|
||||||
|
|
||||||
if (oid) {
|
if (oid) {
|
||||||
buf = read_object_with_reference(r, oid, tree_type, &size, NULL);
|
buf = read_object_with_reference(r, oid, OBJ_TREE, &size, NULL);
|
||||||
if (!buf)
|
if (!buf)
|
||||||
die("unable to read tree %s", oid_to_hex(oid));
|
die("unable to read tree %s", oid_to_hex(oid));
|
||||||
}
|
}
|
||||||
|
@ -605,7 +605,7 @@ int get_tree_entry(struct repository *r,
|
||||||
unsigned long size;
|
unsigned long size;
|
||||||
struct object_id root;
|
struct object_id root;
|
||||||
|
|
||||||
tree = read_object_with_reference(r, tree_oid, tree_type, &size, &root);
|
tree = read_object_with_reference(r, tree_oid, OBJ_TREE, &size, &root);
|
||||||
if (!tree)
|
if (!tree)
|
||||||
return -1;
|
return -1;
|
||||||
|
|
||||||
|
@ -677,7 +677,7 @@ enum get_oid_result get_tree_entry_follow_symlinks(struct repository *r,
|
||||||
unsigned long size;
|
unsigned long size;
|
||||||
tree = read_object_with_reference(r,
|
tree = read_object_with_reference(r,
|
||||||
¤t_tree_oid,
|
¤t_tree_oid,
|
||||||
tree_type, &size,
|
OBJ_TREE, &size,
|
||||||
&root);
|
&root);
|
||||||
if (!tree)
|
if (!tree)
|
||||||
goto done;
|
goto done;
|
||||||
|
|
Loading…
Reference in a new issue