sha1_file: convert read_sha1_file to struct object_id
Convert read_sha1_file to take a pointer to struct object_id and rename it read_object_file. Do the same for read_sha1_file_extended. Convert one use in grep.c to use the new function without any other code change, since the pointer being passed is a void pointer that is already initialized with a pointer to struct object_id. Update the declaration and definitions of the modified functions, and apply the following semantic patch to convert the remaining callers: @@ expression E1, E2, E3; @@ - read_sha1_file(E1.hash, E2, E3) + read_object_file(&E1, E2, E3) @@ expression E1, E2, E3; @@ - read_sha1_file(E1->hash, E2, E3) + read_object_file(E1, E2, E3) @@ expression E1, E2, E3, E4; @@ - read_sha1_file_extended(E1.hash, E2, E3, E4) + read_object_file_extended(&E1, E2, E3, E4) @@ expression E1, E2, E3, E4; @@ - read_sha1_file_extended(E1->hash, E2, E3, E4) + read_object_file_extended(E1, E2, E3, E4) Signed-off-by: brian m. carlson <sandals@crustytoothpaste.net> Signed-off-by: Junio C Hamano <gitster@pobox.com>
This commit is contained in:

committed by
Junio C Hamano

parent
02f0547eaa
commit
b4f5aca40e
@ -32,7 +32,7 @@ static int filter_object(const char *path, unsigned mode,
|
||||
{
|
||||
enum object_type type;
|
||||
|
||||
*buf = read_sha1_file(oid->hash, &type, size);
|
||||
*buf = read_object_file(oid, &type, size);
|
||||
if (!*buf)
|
||||
return error(_("cannot read object %s '%s'"),
|
||||
oid_to_hex(oid), path);
|
||||
@ -130,7 +130,7 @@ static int cat_one_file(int opt, const char *exp_type, const char *obj_name,
|
||||
|
||||
if (type == OBJ_BLOB)
|
||||
return stream_blob_to_fd(1, &oid, NULL, 0);
|
||||
buf = read_sha1_file(oid.hash, &type, &size);
|
||||
buf = read_object_file(&oid, &type, &size);
|
||||
if (!buf)
|
||||
die("Cannot read object %s", obj_name);
|
||||
|
||||
@ -141,7 +141,8 @@ static int cat_one_file(int opt, const char *exp_type, const char *obj_name,
|
||||
if (type_from_string(exp_type) == OBJ_BLOB) {
|
||||
struct object_id blob_oid;
|
||||
if (oid_object_info(&oid, NULL) == OBJ_TAG) {
|
||||
char *buffer = read_sha1_file(oid.hash, &type, &size);
|
||||
char *buffer = read_object_file(&oid, &type,
|
||||
&size);
|
||||
const char *target;
|
||||
if (!skip_prefix(buffer, "object ", &target) ||
|
||||
get_oid_hex(target, &blob_oid))
|
||||
@ -304,8 +305,9 @@ static void print_object_or_die(struct batch_options *opt, struct expand_data *d
|
||||
enum object_type type;
|
||||
if (!textconv_object(data->rest, 0100644, oid,
|
||||
1, &contents, &size))
|
||||
contents = read_sha1_file(oid->hash, &type,
|
||||
&size);
|
||||
contents = read_object_file(oid,
|
||||
&type,
|
||||
&size);
|
||||
if (!contents)
|
||||
die("could not convert '%s' %s",
|
||||
oid_to_hex(oid), data->rest);
|
||||
@ -321,7 +323,7 @@ static void print_object_or_die(struct batch_options *opt, struct expand_data *d
|
||||
unsigned long size;
|
||||
void *contents;
|
||||
|
||||
contents = read_sha1_file(oid->hash, &type, &size);
|
||||
contents = read_object_file(oid, &type, &size);
|
||||
if (!contents)
|
||||
die("object %s disappeared", oid_to_hex(oid));
|
||||
if (type != data->type)
|
||||
|
@ -306,7 +306,7 @@ static char *get_symlink(const struct object_id *oid, const char *path)
|
||||
} else {
|
||||
enum object_type type;
|
||||
unsigned long size;
|
||||
data = read_sha1_file(oid->hash, &type, &size);
|
||||
data = read_object_file(oid, &type, &size);
|
||||
if (!data)
|
||||
die(_("could not read object %s for symlink %s"),
|
||||
oid_to_hex(oid), path);
|
||||
|
@ -237,7 +237,7 @@ static void export_blob(const struct object_id *oid)
|
||||
object = (struct object *)lookup_blob(oid);
|
||||
eaten = 0;
|
||||
} else {
|
||||
buf = read_sha1_file(oid->hash, &type, &size);
|
||||
buf = read_object_file(oid, &type, &size);
|
||||
if (!buf)
|
||||
die ("Could not read blob %s", oid_to_hex(oid));
|
||||
if (check_object_signature(oid, buf, size, type_name(type)) < 0)
|
||||
@ -682,7 +682,7 @@ static void handle_tag(const char *name, struct tag *tag)
|
||||
return;
|
||||
}
|
||||
|
||||
buf = read_sha1_file(tag->object.oid.hash, &type, &size);
|
||||
buf = read_object_file(&tag->object.oid, &type, &size);
|
||||
if (!buf)
|
||||
die ("Could not read tag %s", oid_to_hex(&tag->object.oid));
|
||||
message = memmem(buf, size, "\n\n", 2);
|
||||
|
@ -488,7 +488,7 @@ static void fmt_merge_msg_sigs(struct strbuf *out)
|
||||
struct object_id *oid = origins.items[i].util;
|
||||
enum object_type type;
|
||||
unsigned long size, len;
|
||||
char *buf = read_sha1_file(oid->hash, &type, &size);
|
||||
char *buf = read_object_file(oid, &type, &size);
|
||||
struct strbuf sig = STRBUF_INIT;
|
||||
|
||||
if (!buf || type != OBJ_TAG)
|
||||
|
@ -306,7 +306,7 @@ static void *lock_and_read_oid_file(const struct object_id *oid, enum object_typ
|
||||
void *data;
|
||||
|
||||
grep_read_lock();
|
||||
data = read_sha1_file(oid->hash, type, size);
|
||||
data = read_object_file(oid, type, size);
|
||||
grep_read_unlock();
|
||||
return data;
|
||||
}
|
||||
|
@ -815,7 +815,7 @@ static void sha1_object(const void *data, struct object_entry *obj_entry,
|
||||
die(_("cannot read existing object info %s"), oid_to_hex(oid));
|
||||
if (has_type != type || has_size != size)
|
||||
die(_("SHA1 COLLISION FOUND WITH %s !"), oid_to_hex(oid));
|
||||
has_data = read_sha1_file(oid->hash, &has_type, &has_size);
|
||||
has_data = read_object_file(oid, &has_type, &has_size);
|
||||
read_unlock();
|
||||
if (!data)
|
||||
data = new_data = get_data_from_pack(obj_entry);
|
||||
@ -1373,7 +1373,8 @@ static void fix_unresolved_deltas(struct hashfile *f)
|
||||
|
||||
if (objects[d->obj_no].real_type != OBJ_REF_DELTA)
|
||||
continue;
|
||||
base_obj->data = read_sha1_file(d->oid.hash, &type, &base_obj->size);
|
||||
base_obj->data = read_object_file(&d->oid, &type,
|
||||
&base_obj->size);
|
||||
if (!base_obj->data)
|
||||
continue;
|
||||
|
||||
|
@ -518,7 +518,7 @@ static int show_tag_object(const struct object_id *oid, struct rev_info *rev)
|
||||
{
|
||||
unsigned long size;
|
||||
enum object_type type;
|
||||
char *buf = read_sha1_file(oid->hash, &type, &size);
|
||||
char *buf = read_object_file(oid, &type, &size);
|
||||
int offset = 0;
|
||||
|
||||
if (!buf)
|
||||
|
@ -60,7 +60,7 @@ static void *result(struct merge_list *entry, unsigned long *size)
|
||||
const char *path = entry->path;
|
||||
|
||||
if (!entry->stage)
|
||||
return read_sha1_file(entry->blob->object.oid.hash, &type, size);
|
||||
return read_object_file(&entry->blob->object.oid, &type, size);
|
||||
base = NULL;
|
||||
if (entry->stage == 1) {
|
||||
base = entry->blob;
|
||||
@ -82,7 +82,8 @@ static void *origin(struct merge_list *entry, unsigned long *size)
|
||||
enum object_type type;
|
||||
while (entry) {
|
||||
if (entry->stage == 2)
|
||||
return read_sha1_file(entry->blob->object.oid.hash, &type, size);
|
||||
return read_object_file(&entry->blob->object.oid,
|
||||
&type, size);
|
||||
entry = entry->link;
|
||||
}
|
||||
return NULL;
|
||||
|
@ -23,7 +23,7 @@ static int verify_object(const struct object_id *oid, const char *expected_type)
|
||||
int ret = -1;
|
||||
enum object_type type;
|
||||
unsigned long size;
|
||||
void *buffer = read_sha1_file(oid->hash, &type, &size);
|
||||
void *buffer = read_object_file(oid, &type, &size);
|
||||
const unsigned char *repl = lookup_replace_object(oid->hash);
|
||||
|
||||
if (buffer) {
|
||||
|
@ -122,7 +122,7 @@ static void copy_obj_to_fd(int fd, const struct object_id *oid)
|
||||
{
|
||||
unsigned long size;
|
||||
enum object_type type;
|
||||
char *buf = read_sha1_file(oid->hash, &type, &size);
|
||||
char *buf = read_object_file(oid, &type, &size);
|
||||
if (buf) {
|
||||
if (size)
|
||||
write_or_die(fd, buf, size);
|
||||
@ -253,7 +253,7 @@ static int parse_reuse_arg(const struct option *opt, const char *arg, int unset)
|
||||
|
||||
if (get_oid(arg, &object))
|
||||
die(_("failed to resolve '%s' as a valid ref."), arg);
|
||||
if (!(buf = read_sha1_file(object.hash, &type, &len))) {
|
||||
if (!(buf = read_object_file(&object, &type, &len))) {
|
||||
free(buf);
|
||||
die(_("failed to read object '%s'."), arg);
|
||||
}
|
||||
@ -608,7 +608,7 @@ static int append_edit(int argc, const char **argv, const char *prefix)
|
||||
/* Append buf to previous note contents */
|
||||
unsigned long size;
|
||||
enum object_type type;
|
||||
char *prev_buf = read_sha1_file(note->hash, &type, &size);
|
||||
char *prev_buf = read_object_file(note, &type, &size);
|
||||
|
||||
strbuf_grow(&d.buf, size + 1);
|
||||
if (d.buf.len && prev_buf && size)
|
||||
|
@ -122,11 +122,10 @@ static void *get_delta(struct object_entry *entry)
|
||||
void *buf, *base_buf, *delta_buf;
|
||||
enum object_type type;
|
||||
|
||||
buf = read_sha1_file(entry->idx.oid.hash, &type, &size);
|
||||
buf = read_object_file(&entry->idx.oid, &type, &size);
|
||||
if (!buf)
|
||||
die("unable to read %s", oid_to_hex(&entry->idx.oid));
|
||||
base_buf = read_sha1_file(entry->delta->idx.oid.hash, &type,
|
||||
&base_size);
|
||||
base_buf = read_object_file(&entry->delta->idx.oid, &type, &base_size);
|
||||
if (!base_buf)
|
||||
die("unable to read %s",
|
||||
oid_to_hex(&entry->delta->idx.oid));
|
||||
@ -270,8 +269,7 @@ static unsigned long write_no_reuse_object(struct hashfile *f, struct object_ent
|
||||
(st = open_istream(&entry->idx.oid, &type, &size, NULL)) != NULL)
|
||||
buf = NULL;
|
||||
else {
|
||||
buf = read_sha1_file(entry->idx.oid.hash, &type,
|
||||
&size);
|
||||
buf = read_object_file(&entry->idx.oid, &type, &size);
|
||||
if (!buf)
|
||||
die(_("unable to read %s"),
|
||||
oid_to_hex(&entry->idx.oid));
|
||||
@ -1190,7 +1188,7 @@ static struct pbase_tree_cache *pbase_tree_get(const struct object_id *oid)
|
||||
/* Did not find one. Either we got a bogus request or
|
||||
* we need to read and perhaps cache.
|
||||
*/
|
||||
data = read_sha1_file(oid->hash, &type, &size);
|
||||
data = read_object_file(oid, &type, &size);
|
||||
if (!data)
|
||||
return NULL;
|
||||
if (type != OBJ_TREE) {
|
||||
@ -1870,8 +1868,7 @@ static int try_delta(struct unpacked *trg, struct unpacked *src,
|
||||
/* Load data if not already done */
|
||||
if (!trg->data) {
|
||||
read_lock();
|
||||
trg->data = read_sha1_file(trg_entry->idx.oid.hash, &type,
|
||||
&sz);
|
||||
trg->data = read_object_file(&trg_entry->idx.oid, &type, &sz);
|
||||
read_unlock();
|
||||
if (!trg->data)
|
||||
die("object %s cannot be read",
|
||||
@ -1884,8 +1881,7 @@ static int try_delta(struct unpacked *trg, struct unpacked *src,
|
||||
}
|
||||
if (!src->data) {
|
||||
read_lock();
|
||||
src->data = read_sha1_file(src_entry->idx.oid.hash, &type,
|
||||
&sz);
|
||||
src->data = read_object_file(&src_entry->idx.oid, &type, &sz);
|
||||
read_unlock();
|
||||
if (!src->data) {
|
||||
if (src_entry->preferred_base) {
|
||||
|
@ -74,7 +74,7 @@ static int tree_is_complete(const struct object_id *oid)
|
||||
if (!tree->buffer) {
|
||||
enum object_type type;
|
||||
unsigned long size;
|
||||
void *data = read_sha1_file(oid->hash, &type, &size);
|
||||
void *data = read_object_file(oid, &type, &size);
|
||||
if (!data) {
|
||||
tree->object.flags |= INCOMPLETE;
|
||||
return 0;
|
||||
|
@ -168,7 +168,7 @@ static void write_tag_body(int fd, const struct object_id *oid)
|
||||
enum object_type type;
|
||||
char *buf, *sp;
|
||||
|
||||
buf = read_sha1_file(oid->hash, &type, &size);
|
||||
buf = read_object_file(oid, &type, &size);
|
||||
if (!buf)
|
||||
return;
|
||||
/* skip header */
|
||||
@ -304,7 +304,7 @@ static void create_reflog_msg(const struct object_id *oid, struct strbuf *sb)
|
||||
strbuf_addstr(sb, "object of unknown type");
|
||||
break;
|
||||
case OBJ_COMMIT:
|
||||
if ((buf = read_sha1_file(oid->hash, &type, &size)) != NULL) {
|
||||
if ((buf = read_object_file(oid, &type, &size)) != NULL) {
|
||||
subject_len = find_commit_subject(buf, &subject_start);
|
||||
strbuf_insert(sb, sb->len, subject_start, subject_len);
|
||||
} else {
|
||||
|
@ -9,7 +9,7 @@ static char *create_temp_file(struct object_id *oid)
|
||||
unsigned long size;
|
||||
int fd;
|
||||
|
||||
buf = read_sha1_file(oid->hash, &type, &size);
|
||||
buf = read_object_file(oid, &type, &size);
|
||||
if (!buf || type != OBJ_BLOB)
|
||||
die("unable to read blob object %s", oid_to_hex(oid));
|
||||
|
||||
|
@ -422,7 +422,7 @@ static void unpack_delta_entry(enum object_type type, unsigned long delta_size,
|
||||
if (resolve_against_held(nr, &base_oid, delta_data, delta_size))
|
||||
return;
|
||||
|
||||
base = read_sha1_file(base_oid.hash, &type, &base_size);
|
||||
base = read_object_file(&base_oid, &type, &base_size);
|
||||
if (!base) {
|
||||
error("failed to read delta-pack base object %s",
|
||||
oid_to_hex(&base_oid));
|
||||
|
@ -44,7 +44,7 @@ static int verify_commit(const char *name, unsigned flags)
|
||||
if (get_oid(name, &oid))
|
||||
return error("commit '%s' not found.", name);
|
||||
|
||||
buf = read_sha1_file(oid.hash, &type, &size);
|
||||
buf = read_object_file(&oid, &type, &size);
|
||||
if (!buf)
|
||||
return error("%s: unable to read file.", name);
|
||||
if (type != OBJ_COMMIT)
|
||||
|
Reference in New Issue
Block a user