Skip to content

Commit

Permalink
cocci: apply the "object-store.h" part of "the_repository.pending"
Browse files Browse the repository at this point in the history
Apply the part of "the_repository.pending.cocci" pertaining to
"object-store.h".

Signed-off-by: Ævar Arnfjörð Bjarmason <avarab@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
  • Loading branch information
avar authored and gitster committed Mar 28, 2023
1 parent 0853903 commit bc726bd
Show file tree
Hide file tree
Showing 60 changed files with 184 additions and 142 deletions.
9 changes: 6 additions & 3 deletions apply.c
Original file line number Diff line number Diff line change
Expand Up @@ -3201,7 +3201,8 @@ static int apply_binary(struct apply_state *state,
unsigned long size;
char *result;

result = read_object_file(&oid, &type, &size);
result = repo_read_object_file(the_repository, &oid, &type,
&size);
if (!result)
return error(_("the necessary postimage %s for "
"'%s' cannot be read"),
Expand Down Expand Up @@ -3264,7 +3265,8 @@ static int read_blob_object(struct strbuf *buf, const struct object_id *oid, uns
unsigned long sz;
char *result;

result = read_object_file(oid, &type, &sz);
result = repo_read_object_file(the_repository, oid, &type,
&sz);
if (!result)
return -1;
/* XXX read_sha1_file NUL-terminates */
Expand Down Expand Up @@ -3492,7 +3494,8 @@ static int resolve_to(struct image *image, const struct object_id *result_id)

clear_image(image);

image->buf = read_object_file(result_id, &type, &size);
image->buf = repo_read_object_file(the_repository, result_id, &type,
&size);
if (!image->buf || type != OBJ_BLOB)
die("unable to read blob object %s", oid_to_hex(result_id));
image->len = size;
Expand Down
2 changes: 1 addition & 1 deletion archive.c
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ static void *object_file_to_archive(const struct archiver_args *args,
(args->tree ? &args->tree->object.oid : NULL), oid);

path += args->baselen;
buffer = read_object_file(oid, type, sizep);
buffer = repo_read_object_file(the_repository, oid, type, sizep);
if (buffer && S_ISREG(mode)) {
struct strbuf buf = STRBUF_INIT;
size_t size = 0;
Expand Down
5 changes: 3 additions & 2 deletions bisect.c
Original file line number Diff line number Diff line change
Expand Up @@ -148,8 +148,9 @@ static void show_list(const char *debug, int counted, int nr,
unsigned commit_flags = commit->object.flags;
enum object_type type;
unsigned long size;
char *buf = read_object_file(&commit->object.oid, &type,
&size);
char *buf = repo_read_object_file(the_repository,
&commit->object.oid, &type,
&size);
const char *subject_start;
int subject_len;

Expand Down
11 changes: 7 additions & 4 deletions blame.c
Original file line number Diff line number Diff line change
Expand Up @@ -1028,8 +1028,9 @@ static void fill_origin_blob(struct diff_options *opt,
&o->blob_oid, 1, &file->ptr, &file_size))
;
else
file->ptr = read_object_file(&o->blob_oid, &type,
&file_size);
file->ptr = repo_read_object_file(the_repository,
&o->blob_oid, &type,
&file_size);
file->size = file_size;

if (!file->ptr)
Expand Down Expand Up @@ -2838,8 +2839,10 @@ void setup_scoreboard(struct blame_scoreboard *sb,
&sb->final_buf_size))
;
else
sb->final_buf = read_object_file(&o->blob_oid, &type,
&sb->final_buf_size);
sb->final_buf = repo_read_object_file(the_repository,
&o->blob_oid,
&type,
&sb->final_buf_size);

if (!sb->final_buf)
die(_("cannot read blob %s for path %s"),
Expand Down
23 changes: 14 additions & 9 deletions builtin/cat-file.c
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ static int filter_object(const char *path, unsigned mode,
{
enum object_type type;

*buf = read_object_file(oid, &type, size);
*buf = repo_read_object_file(the_repository, oid, &type, size);
if (!*buf)
return error(_("cannot read object %s '%s'"),
oid_to_hex(oid), path);
Expand Down Expand Up @@ -152,7 +152,7 @@ static int cat_one_file(int opt, const char *exp_type, const char *obj_name,
goto cleanup;

case 'e':
return !has_object_file(&oid);
return !repo_has_object_file(the_repository, &oid);

case 'w':

Expand Down Expand Up @@ -187,7 +187,8 @@ static int cat_one_file(int opt, const char *exp_type, const char *obj_name,
ret = stream_blob(&oid);
goto cleanup;
}
buf = read_object_file(&oid, &type, &size);
buf = repo_read_object_file(the_repository, &oid, &type,
&size);
if (!buf)
die("Cannot read object %s", obj_name);

Expand All @@ -207,8 +208,10 @@ static int cat_one_file(int opt, const char *exp_type, const char *obj_name,
if (exp_type_id == OBJ_BLOB) {
struct object_id blob_oid;
if (oid_object_info(the_repository, &oid, NULL) == OBJ_TAG) {
char *buffer = read_object_file(&oid, &type,
&size);
char *buffer = repo_read_object_file(the_repository,
&oid,
&type,
&size);
const char *target;
if (!skip_prefix(buffer, "object ", &target) ||
get_oid_hex(target, &blob_oid))
Expand Down Expand Up @@ -383,9 +386,10 @@ static void print_object_or_die(struct batch_options *opt, struct expand_data *d
if (!textconv_object(the_repository,
data->rest, 0100644, oid,
1, &contents, &size))
contents = read_object_file(oid,
&type,
&size);
contents = repo_read_object_file(the_repository,
oid,
&type,
&size);
if (!contents)
die("could not convert '%s' %s",
oid_to_hex(oid), data->rest);
Expand All @@ -402,7 +406,8 @@ static void print_object_or_die(struct batch_options *opt, struct expand_data *d
unsigned long size;
void *contents;

contents = read_object_file(oid, &type, &size);
contents = repo_read_object_file(the_repository, oid, &type,
&size);

if (use_mailmap) {
size_t s = size;
Expand Down
6 changes: 3 additions & 3 deletions builtin/clone.c
Original file line number Diff line number Diff line change
Expand Up @@ -547,9 +547,9 @@ static void write_followtags(const struct ref *refs, const char *msg)
continue;
if (ends_with(ref->name, "^{}"))
continue;
if (!has_object_file_with_flags(&ref->old_oid,
OBJECT_INFO_QUICK |
OBJECT_INFO_SKIP_FETCH_OBJECT))
if (!repo_has_object_file_with_flags(the_repository, &ref->old_oid,
OBJECT_INFO_QUICK |
OBJECT_INFO_SKIP_FETCH_OBJECT))
continue;
update_ref(msg, ref->name, &ref->old_oid, NULL, 0,
UPDATE_REFS_DIE_ON_ERR);
Expand Down
3 changes: 2 additions & 1 deletion builtin/difftool.c
Original file line number Diff line number Diff line change
Expand Up @@ -295,7 +295,8 @@ static char *get_symlink(const struct object_id *oid, const char *path)
} else {
enum object_type type;
unsigned long size;
data = read_object_file(oid, &type, &size);
data = repo_read_object_file(the_repository, oid, &type,
&size);
if (!data)
die(_("could not read object %s for symlink %s"),
oid_to_hex(oid), path);
Expand Down
5 changes: 3 additions & 2 deletions builtin/fast-export.c
Original file line number Diff line number Diff line change
Expand Up @@ -296,7 +296,7 @@ static void export_blob(const struct object_id *oid)
object = (struct object *)lookup_blob(the_repository, oid);
eaten = 0;
} else {
buf = read_object_file(oid, &type, &size);
buf = repo_read_object_file(the_repository, oid, &type, &size);
if (!buf)
die("could not read blob %s", oid_to_hex(oid));
if (check_object_signature(the_repository, oid, buf, size,
Expand Down Expand Up @@ -766,7 +766,8 @@ static void handle_tag(const char *name, struct tag *tag)
return;
}

buf = read_object_file(&tag->object.oid, &type, &size);
buf = repo_read_object_file(the_repository, &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);
Expand Down
7 changes: 4 additions & 3 deletions builtin/fast-import.c
Original file line number Diff line number Diff line change
Expand Up @@ -1265,7 +1265,7 @@ static void load_tree(struct tree_entry *root)
die("Can't load tree %s", oid_to_hex(oid));
} else {
enum object_type type;
buf = read_object_file(oid, &type, &size);
buf = repo_read_object_file(the_repository, oid, &type, &size);
if (!buf || type != OBJ_TREE)
die("Can't load tree %s", oid_to_hex(oid));
}
Expand Down Expand Up @@ -2936,7 +2936,7 @@ static void cat_blob(struct object_entry *oe, struct object_id *oid)
char *buf;

if (!oe || oe->pack_id == MAX_PACK_ID) {
buf = read_object_file(oid, &type, &size);
buf = repo_read_object_file(the_repository, oid, &type, &size);
} else {
type = oe->type;
buf = gfi_unpack_entry(oe, &size);
Expand Down Expand Up @@ -3044,7 +3044,8 @@ static struct object_entry *dereference(struct object_entry *oe,
buf = gfi_unpack_entry(oe, &size);
} else {
enum object_type unused;
buf = read_object_file(oid, &unused, &size);
buf = repo_read_object_file(the_repository, oid, &unused,
&size);
}
if (!buf)
die("Can't load object %s", oid_to_hex(oid));
Expand Down
12 changes: 6 additions & 6 deletions builtin/fetch.c
Original file line number Diff line number Diff line change
Expand Up @@ -407,9 +407,9 @@ static void find_non_local_tags(const struct ref *refs,
*/
if (ends_with(ref->name, "^{}")) {
if (item &&
!has_object_file_with_flags(&ref->old_oid, quick_flags) &&
!repo_has_object_file_with_flags(the_repository, &ref->old_oid, quick_flags) &&
!oidset_contains(&fetch_oids, &ref->old_oid) &&
!has_object_file_with_flags(&item->oid, quick_flags) &&
!repo_has_object_file_with_flags(the_repository, &item->oid, quick_flags) &&
!oidset_contains(&fetch_oids, &item->oid))
clear_item(item);
item = NULL;
Expand All @@ -423,7 +423,7 @@ static void find_non_local_tags(const struct ref *refs,
* fetch.
*/
if (item &&
!has_object_file_with_flags(&item->oid, quick_flags) &&
!repo_has_object_file_with_flags(the_repository, &item->oid, quick_flags) &&
!oidset_contains(&fetch_oids, &item->oid))
clear_item(item);

Expand All @@ -444,7 +444,7 @@ static void find_non_local_tags(const struct ref *refs,
* checked to see if it needs fetching.
*/
if (item &&
!has_object_file_with_flags(&item->oid, quick_flags) &&
!repo_has_object_file_with_flags(the_repository, &item->oid, quick_flags) &&
!oidset_contains(&fetch_oids, &item->oid))
clear_item(item);

Expand Down Expand Up @@ -1320,8 +1320,8 @@ static int check_exist_and_connected(struct ref *ref_map)
* we need all direct targets to exist.
*/
for (r = rm; r; r = r->next) {
if (!has_object_file_with_flags(&r->old_oid,
OBJECT_INFO_SKIP_FETCH_OBJECT))
if (!repo_has_object_file_with_flags(the_repository, &r->old_oid,
OBJECT_INFO_SKIP_FETCH_OBJECT))
return -1;
}

Expand Down
6 changes: 4 additions & 2 deletions builtin/grep.c
Original file line number Diff line number Diff line change
Expand Up @@ -560,7 +560,8 @@ static int grep_cache(struct grep_opt *opt,
void *data;
unsigned long size;

data = read_object_file(&ce->oid, &type, &size);
data = repo_read_object_file(the_repository, &ce->oid,
&type, &size);
init_tree_desc(&tree, data, size);

hit |= grep_tree(opt, pathspec, &tree, &name, 0, 0);
Expand Down Expand Up @@ -650,7 +651,8 @@ static int grep_tree(struct grep_opt *opt, const struct pathspec *pathspec,
void *data;
unsigned long size;

data = read_object_file(&entry.oid, &type, &size);
data = repo_read_object_file(the_repository,
&entry.oid, &type, &size);
if (!data)
die(_("unable to read tree (%s)"),
oid_to_hex(&entry.oid));
Expand Down
9 changes: 6 additions & 3 deletions builtin/index-pack.c
Original file line number Diff line number Diff line change
Expand Up @@ -801,7 +801,8 @@ static void sha1_object(const void *data, struct object_entry *obj_entry,
if (startup_info->have_repository) {
read_lock();
collision_test_needed =
has_object_file_with_flags(oid, OBJECT_INFO_QUICK);
repo_has_object_file_with_flags(the_repository, oid,
OBJECT_INFO_QUICK);
read_unlock();
}

Expand All @@ -821,7 +822,8 @@ 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_object_file(oid, &has_type, &has_size);
has_data = repo_read_object_file(the_repository, oid,
&has_type, &has_size);
read_unlock();
if (!data)
data = new_data = get_data_from_pack(obj_entry);
Expand Down Expand Up @@ -1414,7 +1416,8 @@ static void fix_unresolved_deltas(struct hashfile *f)

if (objects[d->obj_no].real_type != OBJ_REF_DELTA)
continue;
data = read_object_file(&d->oid, &type, &size);
data = repo_read_object_file(the_repository, &d->oid, &type,
&size);
if (!data)
continue;

Expand Down
2 changes: 1 addition & 1 deletion builtin/log.c
Original file line number Diff line number Diff line change
Expand Up @@ -675,7 +675,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_object_file(oid, &type, &size);
char *buf = repo_read_object_file(the_repository, oid, &type, &size);
int offset = 0;

if (!buf)
Expand Down
9 changes: 6 additions & 3 deletions builtin/merge-tree.c
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,9 @@ static void *result(struct merge_list *entry, unsigned long *size)
const char *path = entry->path;

if (!entry->stage)
return read_object_file(&entry->blob->object.oid, &type, size);
return repo_read_object_file(the_repository,
&entry->blob->object.oid, &type,
size);
base = NULL;
if (entry->stage == 1) {
base = entry->blob;
Expand All @@ -92,8 +94,9 @@ static void *origin(struct merge_list *entry, unsigned long *size)
enum object_type type;
while (entry) {
if (entry->stage == 2)
return read_object_file(&entry->blob->object.oid,
&type, size);
return repo_read_object_file(the_repository,
&entry->blob->object.oid,
&type, size);
entry = entry->link;
}
return NULL;
Expand Down
3 changes: 2 additions & 1 deletion builtin/mktag.c
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,8 @@ static int verify_object_in_tag(struct object_id *tagged_oid, int *tagged_type)
void *buffer;
const struct object_id *repl;

buffer = read_object_file(tagged_oid, &type, &size);
buffer = repo_read_object_file(the_repository, tagged_oid, &type,
&size);
if (!buffer)
die(_("could not read tagged object '%s'"),
oid_to_hex(tagged_oid));
Expand Down
7 changes: 4 additions & 3 deletions builtin/notes.c
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ static void copy_obj_to_fd(int fd, const struct object_id *oid)
{
unsigned long size;
enum object_type type;
char *buf = read_object_file(oid, &type, &size);
char *buf = repo_read_object_file(the_repository, oid, &type, &size);
if (buf) {
if (size)
write_or_die(fd, buf, size);
Expand Down Expand Up @@ -259,7 +259,7 @@ static int parse_reuse_arg(const struct option *opt, const char *arg, int unset)

if (repo_get_oid(the_repository, arg, &object))
die(_("failed to resolve '%s' as a valid ref."), arg);
if (!(buf = read_object_file(&object, &type, &len)))
if (!(buf = repo_read_object_file(the_repository, &object, &type, &len)))
die(_("failed to read object '%s'."), arg);
if (type != OBJ_BLOB) {
free(buf);
Expand Down Expand Up @@ -616,7 +616,8 @@ 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_object_file(note, &type, &size);
char *prev_buf = repo_read_object_file(the_repository, note,
&type, &size);

strbuf_grow(&d.buf, size + 1);
if (d.buf.len && prev_buf && size)
Expand Down
Loading

0 comments on commit bc726bd

Please sign in to comment.