sha1_file: convert read_object_with_reference to object_id

Convert read_object_with_reference to take pointers to struct object_id.
Update the internals of the function accordingly.

Signed-off-by: brian m. carlson <sandals@crustytoothpaste.net>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
This commit is contained in:
brian m. carlson
2018-03-12 02:27:52 +00:00
committed by Junio C Hamano
parent 916bc35b29
commit 02f0547eaa
7 changed files with 28 additions and 28 deletions

View File

@ -159,7 +159,7 @@ 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(oid.hash, exp_type, &size, NULL); buf = read_object_with_reference(&oid, exp_type, &size, NULL);
break; break;
default: default:

View File

@ -452,7 +452,7 @@ static int grep_submodule(struct grep_opt *opt, struct repository *superproject,
object = parse_object_or_die(oid, oid_to_hex(oid)); object = parse_object_or_die(oid, oid_to_hex(oid));
grep_read_lock(); grep_read_lock();
data = read_object_with_reference(object->oid.hash, tree_type, data = read_object_with_reference(&object->oid, tree_type,
&size, NULL); &size, NULL);
grep_read_unlock(); grep_read_unlock();
@ -614,7 +614,7 @@ static int grep_object(struct grep_opt *opt, const struct pathspec *pathspec,
int hit, len; int hit, len;
grep_read_lock(); grep_read_lock();
data = read_object_with_reference(obj->oid.hash, tree_type, data = read_object_with_reference(&obj->oid, tree_type,
&size, NULL); &size, NULL);
grep_read_unlock(); grep_read_unlock();

View File

@ -1351,7 +1351,7 @@ static void add_preferred_base(struct object_id *oid)
if (window <= num_preferred_base++) if (window <= num_preferred_base++)
return; return;
data = read_object_with_reference(oid->hash, tree_type, &size, tree_oid.hash); data = read_object_with_reference(oid, tree_type, &size, &tree_oid);
if (!data) if (!data)
return; return;

View File

@ -1431,10 +1431,10 @@ extern int df_name_compare(const char *name1, int len1, int mode1, const char *n
extern int name_compare(const char *name1, size_t len1, const char *name2, size_t len2); extern int name_compare(const char *name1, size_t len1, const char *name2, size_t len2);
extern int cache_name_stage_compare(const char *name1, int len1, int stage1, const char *name2, int len2, int stage2); extern int cache_name_stage_compare(const char *name1, int len1, int stage1, const char *name2, int len2, int stage2);
extern void *read_object_with_reference(const unsigned char *sha1, extern void *read_object_with_reference(const struct object_id *oid,
const char *required_type, const char *required_type,
unsigned long *size, unsigned long *size,
unsigned char *sha1_ret); struct object_id *oid_ret);
extern struct object *peel_to_type(const char *name, int namelen, extern struct object *peel_to_type(const char *name, int namelen,
struct object *o, enum object_type); struct object *o, enum object_type);

View File

@ -2583,8 +2583,9 @@ static void note_change_n(const char *p, struct branch *b, unsigned char *old_fa
oidcpy(&commit_oid, &commit_oe->idx.oid); oidcpy(&commit_oid, &commit_oe->idx.oid);
} else if (!get_oid(p, &commit_oid)) { } else if (!get_oid(p, &commit_oid)) {
unsigned long size; unsigned long size;
char *buf = read_object_with_reference(commit_oid.hash, char *buf = read_object_with_reference(&commit_oid,
commit_type, &size, commit_oid.hash); commit_type, &size,
&commit_oid);
if (!buf || size < 46) if (!buf || size < 46)
die("Not a valid commit: %s", p); die("Not a valid commit: %s", p);
free(buf); free(buf);
@ -2653,9 +2654,8 @@ static void parse_from_existing(struct branch *b)
unsigned long size; unsigned long size;
char *buf; char *buf;
buf = read_object_with_reference(b->oid.hash, buf = read_object_with_reference(&b->oid, commit_type, &size,
commit_type, &size, &b->oid);
b->oid.hash);
parse_from_commit(b, buf, size); parse_from_commit(b, buf, size);
free(buf); free(buf);
} }
@ -2732,8 +2732,9 @@ static struct hash_list *parse_merge(unsigned int *count)
oidcpy(&n->oid, &oe->idx.oid); oidcpy(&n->oid, &oe->idx.oid);
} else if (!get_oid(from, &n->oid)) { } else if (!get_oid(from, &n->oid)) {
unsigned long size; unsigned long size;
char *buf = read_object_with_reference(n->oid.hash, char *buf = read_object_with_reference(&n->oid,
commit_type, &size, n->oid.hash); commit_type,
&size, &n->oid);
if (!buf || size < 46) if (!buf || size < 46)
die("Not a valid commit: %s", from); die("Not a valid commit: %s", from);
free(buf); free(buf);

View File

@ -1399,29 +1399,29 @@ void *read_sha1_file_extended(const unsigned char *sha1,
return NULL; return NULL;
} }
void *read_object_with_reference(const unsigned char *sha1, void *read_object_with_reference(const struct object_id *oid,
const char *required_type_name, const char *required_type_name,
unsigned long *size, unsigned long *size,
unsigned char *actual_sha1_return) struct object_id *actual_oid_return)
{ {
enum object_type type, required_type; enum object_type type, required_type;
void *buffer; void *buffer;
unsigned long isize; unsigned long isize;
unsigned char actual_sha1[20]; struct object_id actual_oid;
required_type = type_from_string(required_type_name); required_type = type_from_string(required_type_name);
hashcpy(actual_sha1, sha1); oidcpy(&actual_oid, oid);
while (1) { while (1) {
int ref_length = -1; int ref_length = -1;
const char *ref_type = NULL; const char *ref_type = NULL;
buffer = read_sha1_file(actual_sha1, &type, &isize); buffer = read_sha1_file(actual_oid.hash, &type, &isize);
if (!buffer) if (!buffer)
return NULL; return NULL;
if (type == required_type) { if (type == required_type) {
*size = isize; *size = isize;
if (actual_sha1_return) if (actual_oid_return)
hashcpy(actual_sha1_return, actual_sha1); oidcpy(actual_oid_return, &actual_oid);
return buffer; return buffer;
} }
/* Handle references */ /* Handle references */
@ -1435,15 +1435,15 @@ void *read_object_with_reference(const unsigned char *sha1,
} }
ref_length = strlen(ref_type); ref_length = strlen(ref_type);
if (ref_length + 40 > isize || if (ref_length + GIT_SHA1_HEXSZ > isize ||
memcmp(buffer, ref_type, ref_length) || memcmp(buffer, ref_type, ref_length) ||
get_sha1_hex((char *) buffer + ref_length, actual_sha1)) { get_oid_hex((char *) buffer + ref_length, &actual_oid)) {
free(buffer); free(buffer);
return NULL; return NULL;
} }
free(buffer); free(buffer);
/* Now we have the ID of the referred-to object in /* Now we have the ID of the referred-to object in
* actual_sha1. Check again. */ * actual_oid. Check again. */
} }
} }

View File

@ -84,8 +84,7 @@ void *fill_tree_descriptor(struct tree_desc *desc, const struct object_id *oid)
void *buf = NULL; void *buf = NULL;
if (oid) { if (oid) {
buf = read_object_with_reference(oid->hash, tree_type, &size, buf = read_object_with_reference(oid, tree_type, &size, NULL);
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));
} }
@ -534,7 +533,7 @@ int get_tree_entry(const struct object_id *tree_oid, const char *name, struct ob
unsigned long size; unsigned long size;
struct object_id root; struct object_id root;
tree = read_object_with_reference(tree_oid->hash, tree_type, &size, root.hash); tree = read_object_with_reference(tree_oid, tree_type, &size, &root);
if (!tree) if (!tree)
return -1; return -1;
@ -601,9 +600,9 @@ enum follow_symlinks_result get_tree_entry_follow_symlinks(unsigned char *tree_s
void *tree; void *tree;
struct object_id root; struct object_id root;
unsigned long size; unsigned long size;
tree = read_object_with_reference(current_tree_oid.hash, tree = read_object_with_reference(&current_tree_oid,
tree_type, &size, tree_type, &size,
root.hash); &root);
if (!tree) if (!tree)
goto done; goto done;