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>

brian m. carlson committed Mar 12, 2018 at 02:27 UTC b4f5aca40e6f77cbabcbf4ff003c3cf30a1830c8
51 files changed +104 -103
apply.c
+2 -2
@@ -3180,7 +3180,7 @@ static int apply_binary(struct apply_state *state,
3180 unsigned long size;
3181 char *result;
3182
3183 - result = read_sha1_file(oid.hash, &type, &size);
3183 + result = read_object_file(&oid, &type, &size);
3184 if (!result)
3185 return error(_("the necessary postimage %s for "
3186 "'%s' cannot be read"),
@@ -3242,7 +3242,7 @@ static int read_blob_object(struct strbuf *buf, const struct object_id *oid, uns
3242 unsigned long sz;
3243 char *result;
3244
3245 - result = read_sha1_file(oid->hash, &type, &sz);
3245 + result = read_object_file(oid, &type, &sz);
3246 if (!result)
3247 return -1;
3248 /* XXX read_sha1_file NUL-terminates */
archive.c
+1 -1
@@ -72,7 +72,7 @@ void *object_file_to_archive(const struct archiver_args *args,
72 const struct commit *commit = args->convert ? args->commit : NULL;
73
74 path += args->baselen;
75 - buffer = read_sha1_file(oid->hash, type, sizep);
75 + buffer = read_object_file(oid, type, sizep);
76 if (buffer && S_ISREG(mode)) {
77 struct strbuf buf = STRBUF_INIT;
78 size_t size = 0;
bisect.c
+2 -1
@@ -132,7 +132,8 @@ static void show_list(const char *debug, int counted, int nr,
132 unsigned flags = commit->object.flags;
133 enum object_type type;
134 unsigned long size;
135 - char *buf = read_sha1_file(commit->object.oid.hash, &type, &size);
135 + char *buf = read_object_file(&commit->object.oid, &type,
136 + &size);
137 const char *subject_start;
138 int subject_len;
139
blame.c
+4 -4
@@ -297,8 +297,8 @@ static void fill_origin_blob(struct diff_options *opt,
297 textconv_object(o->path, o->mode, &o->blob_oid, 1, &file->ptr, &file_size))
298 ;
299 else
300 - file->ptr = read_sha1_file(o->blob_oid.hash, &type,
301 - &file_size);
300 + file->ptr = read_object_file(&o->blob_oid, &type,
301 + &file_size);
302 file->size = file_size;
303
304 if (!file->ptr)
@@ -1829,8 +1829,8 @@ void setup_scoreboard(struct blame_scoreboard *sb, const char *path, struct blam
1829 &sb->final_buf_size))
1830 ;
1831 else
1832 - sb->final_buf = read_sha1_file(o->blob_oid.hash, &type,
1833 - &sb->final_buf_size);
1832 + sb->final_buf = read_object_file(&o->blob_oid, &type,
1833 + &sb->final_buf_size);
1834
1835 if (!sb->final_buf)
1836 die(_("cannot read blob %s for path %s"),
builtin/cat-file.c
+8 -6
@@ -32,7 +32,7 @@ static int filter_object(const char *path, unsigned mode,
32 {
33 enum object_type type;
34
35 - *buf = read_sha1_file(oid->hash, &type, size);
35 + *buf = read_object_file(oid, &type, size);
36 if (!*buf)
37 return error(_("cannot read object %s '%s'"),
38 oid_to_hex(oid), path);
@@ -130,7 +130,7 @@ static int cat_one_file(int opt, const char *exp_type, const char *obj_name,
130
131 if (type == OBJ_BLOB)
132 return stream_blob_to_fd(1, &oid, NULL, 0);
133 - buf = read_sha1_file(oid.hash, &type, &size);
133 + buf = read_object_file(&oid, &type, &size);
134 if (!buf)
135 die("Cannot read object %s", obj_name);
136
@@ -141,7 +141,8 @@ static int cat_one_file(int opt, const char *exp_type, const char *obj_name,
141 if (type_from_string(exp_type) == OBJ_BLOB) {
142 struct object_id blob_oid;
143 if (oid_object_info(&oid, NULL) == OBJ_TAG) {
144 - char *buffer = read_sha1_file(oid.hash, &type, &size);
144 + char *buffer = read_object_file(&oid, &type,
145 + &size);
146 const char *target;
147 if (!skip_prefix(buffer, "object ", &target) ||
148 get_oid_hex(target, &blob_oid))
@@ -304,8 +305,9 @@ static void print_object_or_die(struct batch_options *opt, struct expand_data *d
305 enum object_type type;
306 if (!textconv_object(data->rest, 0100644, oid,
307 1, &contents, &size))
307 - contents = read_sha1_file(oid->hash, &type,
308 - &size);
308 + contents = read_object_file(oid,
309 + &type,
310 + &size);
311 if (!contents)
312 die("could not convert '%s' %s",
313 oid_to_hex(oid), data->rest);
@@ -321,7 +323,7 @@ static void print_object_or_die(struct batch_options *opt, struct expand_data *d
323 unsigned long size;
324 void *contents;
325
324 - contents = read_sha1_file(oid->hash, &type, &size);
326 + contents = read_object_file(oid, &type, &size);
327 if (!contents)
328 die("object %s disappeared", oid_to_hex(oid));
329 if (type != data->type)
builtin/difftool.c
+1 -1
@@ -306,7 +306,7 @@ static char *get_symlink(const struct object_id *oid, const char *path)
306 } else {
307 enum object_type type;
308 unsigned long size;
309 - data = read_sha1_file(oid->hash, &type, &size);
309 + data = read_object_file(oid, &type, &size);
310 if (!data)
311 die(_("could not read object %s for symlink %s"),
312 oid_to_hex(oid), path);
builtin/fast-export.c
+2 -2
@@ -237,7 +237,7 @@ static void export_blob(const struct object_id *oid)
237 object = (struct object *)lookup_blob(oid);
238 eaten = 0;
239 } else {
240 - buf = read_sha1_file(oid->hash, &type, &size);
240 + buf = read_object_file(oid, &type, &size);
241 if (!buf)
242 die ("Could not read blob %s", oid_to_hex(oid));
243 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)
682 return;
683 }
684
685 - buf = read_sha1_file(tag->object.oid.hash, &type, &size);
685 + buf = read_object_file(&tag->object.oid, &type, &size);
686 if (!buf)
687 die ("Could not read tag %s", oid_to_hex(&tag->object.oid));
688 message = memmem(buf, size, "\n\n", 2);
builtin/fmt-merge-msg.c
+1 -1
@@ -488,7 +488,7 @@ static void fmt_merge_msg_sigs(struct strbuf *out)
488 struct object_id *oid = origins.items[i].util;
489 enum object_type type;
490 unsigned long size, len;
491 - char *buf = read_sha1_file(oid->hash, &type, &size);
491 + char *buf = read_object_file(oid, &type, &size);
492 struct strbuf sig = STRBUF_INIT;
493
494 if (!buf || type != OBJ_TAG)
builtin/grep.c
+1 -1
@@ -306,7 +306,7 @@ static void *lock_and_read_oid_file(const struct object_id *oid, enum object_typ
306 void *data;
307
308 grep_read_lock();
309 - data = read_sha1_file(oid->hash, type, size);
309 + data = read_object_file(oid, type, size);
310 grep_read_unlock();
311 return data;
312 }
builtin/index-pack.c
+3 -2
@@ -815,7 +815,7 @@ static void sha1_object(const void *data, struct object_entry *obj_entry,
815 die(_("cannot read existing object info %s"), oid_to_hex(oid));
816 if (has_type != type || has_size != size)
817 die(_("SHA1 COLLISION FOUND WITH %s !"), oid_to_hex(oid));
818 - has_data = read_sha1_file(oid->hash, &has_type, &has_size);
818 + has_data = read_object_file(oid, &has_type, &has_size);
819 read_unlock();
820 if (!data)
821 data = new_data = get_data_from_pack(obj_entry);
@@ -1373,7 +1373,8 @@ static void fix_unresolved_deltas(struct hashfile *f)
1373
1374 if (objects[d->obj_no].real_type != OBJ_REF_DELTA)
1375 continue;
1376 - base_obj->data = read_sha1_file(d->oid.hash, &type, &base_obj->size);
1376 + base_obj->data = read_object_file(&d->oid, &type,
1377 + &base_obj->size);
1378 if (!base_obj->data)
1379 continue;
1380
builtin/log.c
+1 -1
@@ -518,7 +518,7 @@ static int show_tag_object(const struct object_id *oid, struct rev_info *rev)
518 {
519 unsigned long size;
520 enum object_type type;
521 - char *buf = read_sha1_file(oid->hash, &type, &size);
521 + char *buf = read_object_file(oid, &type, &size);
522 int offset = 0;
523
524 if (!buf)
builtin/merge-tree.c
+3 -2
@@ -60,7 +60,7 @@ static void *result(struct merge_list *entry, unsigned long *size)
60 const char *path = entry->path;
61
62 if (!entry->stage)
63 - return read_sha1_file(entry->blob->object.oid.hash, &type, size);
63 + return read_object_file(&entry->blob->object.oid, &type, size);
64 base = NULL;
65 if (entry->stage == 1) {
66 base = entry->blob;
@@ -82,7 +82,8 @@ static void *origin(struct merge_list *entry, unsigned long *size)
82 enum object_type type;
83 while (entry) {
84 if (entry->stage == 2)
85 - return read_sha1_file(entry->blob->object.oid.hash, &type, size);
85 + return read_object_file(&entry->blob->object.oid,
86 + &type, size);
87 entry = entry->link;
88 }
89 return NULL;
builtin/mktag.c
+1 -1
@@ -23,7 +23,7 @@ static int verify_object(const struct object_id *oid, const char *expected_type)
23 int ret = -1;
24 enum object_type type;
25 unsigned long size;
26 - void *buffer = read_sha1_file(oid->hash, &type, &size);
26 + void *buffer = read_object_file(oid, &type, &size);
27 const unsigned char *repl = lookup_replace_object(oid->hash);
28
29 if (buffer) {
builtin/notes.c
+3 -3
@@ -122,7 +122,7 @@ static void copy_obj_to_fd(int fd, const struct object_id *oid)
122 {
123 unsigned long size;
124 enum object_type type;
125 - char *buf = read_sha1_file(oid->hash, &type, &size);
125 + char *buf = read_object_file(oid, &type, &size);
126 if (buf) {
127 if (size)
128 write_or_die(fd, buf, size);
@@ -253,7 +253,7 @@ static int parse_reuse_arg(const struct option *opt, const char *arg, int unset)
253
254 if (get_oid(arg, &object))
255 die(_("failed to resolve '%s' as a valid ref."), arg);
256 - if (!(buf = read_sha1_file(object.hash, &type, &len))) {
256 + if (!(buf = read_object_file(&object, &type, &len))) {
257 free(buf);
258 die(_("failed to read object '%s'."), arg);
259 }
@@ -608,7 +608,7 @@ static int append_edit(int argc, const char **argv, const char *prefix)
608 /* Append buf to previous note contents */
609 unsigned long size;
610 enum object_type type;
611 - char *prev_buf = read_sha1_file(note->hash, &type, &size);
611 + char *prev_buf = read_object_file(note, &type, &size);
612
613 strbuf_grow(&d.buf, size + 1);
614 if (d.buf.len && prev_buf && size)
builtin/pack-objects.c
+6 -10
@@ -122,11 +122,10 @@ static void *get_delta(struct object_entry *entry)
122 void *buf, *base_buf, *delta_buf;
123 enum object_type type;
124
125 - buf = read_sha1_file(entry->idx.oid.hash, &type, &size);
125 + buf = read_object_file(&entry->idx.oid, &type, &size);
126 if (!buf)
127 die("unable to read %s", oid_to_hex(&entry->idx.oid));
128 - base_buf = read_sha1_file(entry->delta->idx.oid.hash, &type,
129 - &base_size);
128 + base_buf = read_object_file(&entry->delta->idx.oid, &type, &base_size);
129 if (!base_buf)
130 die("unable to read %s",
131 oid_to_hex(&entry->delta->idx.oid));
@@ -270,8 +269,7 @@ static unsigned long write_no_reuse_object(struct hashfile *f, struct object_ent
269 (st = open_istream(&entry->idx.oid, &type, &size, NULL)) != NULL)
270 buf = NULL;
271 else {
273 - buf = read_sha1_file(entry->idx.oid.hash, &type,
274 - &size);
272 + buf = read_object_file(&entry->idx.oid, &type, &size);
273 if (!buf)
274 die(_("unable to read %s"),
275 oid_to_hex(&entry->idx.oid));
@@ -1190,7 +1188,7 @@ static struct pbase_tree_cache *pbase_tree_get(const struct object_id *oid)
1188 /* Did not find one. Either we got a bogus request or
1189 * we need to read and perhaps cache.
1190 */
1193 - data = read_sha1_file(oid->hash, &type, &size);
1191 + data = read_object_file(oid, &type, &size);
1192 if (!data)
1193 return NULL;
1194 if (type != OBJ_TREE) {
@@ -1870,8 +1868,7 @@ static int try_delta(struct unpacked *trg, struct unpacked *src,
1868 /* Load data if not already done */
1869 if (!trg->data) {
1870 read_lock();
1873 - trg->data = read_sha1_file(trg_entry->idx.oid.hash, &type,
1874 - &sz);
1871 + trg->data = read_object_file(&trg_entry->idx.oid, &type, &sz);
1872 read_unlock();
1873 if (!trg->data)
1874 die("object %s cannot be read",
@@ -1884,8 +1881,7 @@ static int try_delta(struct unpacked *trg, struct unpacked *src,
1881 }
1882 if (!src->data) {
1883 read_lock();
1887 - src->data = read_sha1_file(src_entry->idx.oid.hash, &type,
1888 - &sz);
1884 + src->data = read_object_file(&src_entry->idx.oid, &type, &sz);
1885 read_unlock();
1886 if (!src->data) {
1887 if (src_entry->preferred_base) {
builtin/reflog.c
+1 -1
@@ -74,7 +74,7 @@ static int tree_is_complete(const struct object_id *oid)
74 if (!tree->buffer) {
75 enum object_type type;
76 unsigned long size;
77 - void *data = read_sha1_file(oid->hash, &type, &size);
77 + void *data = read_object_file(oid, &type, &size);
78 if (!data) {
79 tree->object.flags |= INCOMPLETE;
80 return 0;
builtin/tag.c
+2 -2
@@ -168,7 +168,7 @@ static void write_tag_body(int fd, const struct object_id *oid)
168 enum object_type type;
169 char *buf, *sp;
170
171 - buf = read_sha1_file(oid->hash, &type, &size);
171 + buf = read_object_file(oid, &type, &size);
172 if (!buf)
173 return;
174 /* skip header */
@@ -304,7 +304,7 @@ static void create_reflog_msg(const struct object_id *oid, struct strbuf *sb)
304 strbuf_addstr(sb, "object of unknown type");
305 break;
306 case OBJ_COMMIT:
307 - if ((buf = read_sha1_file(oid->hash, &type, &size)) != NULL) {
307 + if ((buf = read_object_file(oid, &type, &size)) != NULL) {
308 subject_len = find_commit_subject(buf, &subject_start);
309 strbuf_insert(sb, sb->len, subject_start, subject_len);
310 } else {
builtin/unpack-file.c
+1 -1
@@ -9,7 +9,7 @@ static char *create_temp_file(struct object_id *oid)
9 unsigned long size;
10 int fd;
11
12 - buf = read_sha1_file(oid->hash, &type, &size);
12 + buf = read_object_file(oid, &type, &size);
13 if (!buf || type != OBJ_BLOB)
14 die("unable to read blob object %s", oid_to_hex(oid));
15
builtin/unpack-objects.c
+1 -1
@@ -422,7 +422,7 @@ static void unpack_delta_entry(enum object_type type, unsigned long delta_size,
422 if (resolve_against_held(nr, &base_oid, delta_data, delta_size))
423 return;
424
425 - base = read_sha1_file(base_oid.hash, &type, &base_size);
425 + base = read_object_file(&base_oid, &type, &base_size);
426 if (!base) {
427 error("failed to read delta-pack base object %s",
428 oid_to_hex(&base_oid));
builtin/verify-commit.c
+1 -1
@@ -44,7 +44,7 @@ static int verify_commit(const char *name, unsigned flags)
44 if (get_oid(name, &oid))
45 return error("commit '%s' not found.", name);
46
47 - buf = read_sha1_file(oid.hash, &type, &size);
47 + buf = read_object_file(&oid, &type, &size);
48 if (!buf)
49 return error("%s: unable to read file.", name);
50 if (type != OBJ_COMMIT)
bundle.c
+1 -1
@@ -222,7 +222,7 @@ static int is_tag_in_date_range(struct object *tag, struct rev_info *revs)
222 if (revs->max_age == -1 && revs->min_age == -1)
223 goto out;
224
225 - buf = read_sha1_file(tag->oid.hash, &type, &size);
225 + buf = read_object_file(&tag->oid, &type, &size);
226 if (!buf)
227 goto out;
228 line = memmem(buf, size, "\ntagger ", 8);
cache.h
+5 -5
@@ -1185,12 +1185,12 @@ extern char *xdg_config_home(const char *filename);
1185 */
1186 extern char *xdg_cache_home(const char *filename);
1187
1188 -extern void *read_sha1_file_extended(const unsigned char *sha1,
1189 - enum object_type *type,
1190 - unsigned long *size, int lookup_replace);
1191 -static inline void *read_sha1_file(const unsigned char *sha1, enum object_type *type, unsigned long *size)
1188 +extern void *read_object_file_extended(const struct object_id *oid,
1189 + enum object_type *type,
1190 + unsigned long *size, int lookup_replace);
1191 +static inline void *read_object_file(const struct object_id *oid, enum object_type *type, unsigned long *size)
1192 {
1193 - return read_sha1_file_extended(sha1, type, size, 1);
1193 + return read_object_file_extended(oid, type, size, 1);
1194 }
1195
1196 /*
combine-diff.c
+1 -1
@@ -306,7 +306,7 @@ static char *grab_blob(const struct object_id *oid, unsigned int mode,
306 *size = fill_textconv(textconv, df, &blob);
307 free_filespec(df);
308 } else {
309 - blob = read_sha1_file(oid->hash, &type, size);
309 + blob = read_object_file(oid, &type, size);
310 if (type != OBJ_BLOB)
311 die("object '%s' is not a blob!", oid_to_hex(oid));
312 }
commit.c
+3 -3
@@ -266,7 +266,7 @@ const void *get_commit_buffer(const struct commit *commit, unsigned long *sizep)
266 if (!ret) {
267 enum object_type type;
268 unsigned long size;
269 - ret = read_sha1_file(commit->object.oid.hash, &type, &size);
269 + ret = read_object_file(&commit->object.oid, &type, &size);
270 if (!ret)
271 die("cannot read commit object %s",
272 oid_to_hex(&commit->object.oid));
@@ -383,7 +383,7 @@ int parse_commit_gently(struct commit *item, int quiet_on_missing)
383 return -1;
384 if (item->object.parsed)
385 return 0;
386 - buffer = read_sha1_file(item->object.oid.hash, &type, &size);
386 + buffer = read_object_file(&item->object.oid, &type, &size);
387 if (!buffer)
388 return quiet_on_missing ? -1 :
389 error("Could not read %s",
@@ -1206,7 +1206,7 @@ static void handle_signed_tag(struct commit *parent, struct commit_extra_header
1206 desc = merge_remote_util(parent);
1207 if (!desc || !desc->obj)
1208 return;
1209 - buf = read_sha1_file(desc->obj->oid.hash, &type, &size);
1209 + buf = read_object_file(&desc->obj->oid, &type, &size);
1210 if (!buf || type != OBJ_TAG)
1211 goto free_return;
1212 len = parse_signature(buf, size);
config.c
+1 -1
@@ -1488,7 +1488,7 @@ int git_config_from_blob_oid(config_fn_t fn,
1488 unsigned long size;
1489 int ret;
1490
1491 - buf = read_sha1_file(oid->hash, &type, &size);
1491 + buf = read_object_file(oid, &type, &size);
1492 if (!buf)
1493 return error("unable to load config blob object '%s'", name);
1494 if (type != OBJ_BLOB) {
diff.c
+1 -1
@@ -3626,7 +3626,7 @@ int diff_populate_filespec(struct diff_filespec *s, unsigned int flags)
3626 return 0;
3627 }
3628 }
3629 - s->data = read_sha1_file(s->oid.hash, &type, &s->size);
3629 + s->data = read_object_file(&s->oid, &type, &s->size);
3630 if (!s->data)
3631 die("unable to read %s", oid_to_hex(&s->oid));
3632 s->should_free = 1;
dir.c
+1 -1
@@ -243,7 +243,7 @@ static int do_read_blob(const struct object_id *oid, struct oid_stat *oid_stat,
243 *size_out = 0;
244 *data_out = NULL;
245
246 - data = read_sha1_file(oid->hash, &type, &sz);
246 + data = read_object_file(oid, &type, &sz);
247 if (!data || type != OBJ_BLOB) {
248 free(data);
249 return -1;
entry.c
+1 -1
@@ -85,7 +85,7 @@ static int create_file(const char *path, unsigned int mode)
85 static void *read_blob_entry(const struct cache_entry *ce, unsigned long *size)
86 {
87 enum object_type type;
88 - void *blob_data = read_sha1_file(ce->oid.hash, &type, size);
88 + void *blob_data = read_object_file(&ce->oid, &type, size);
89
90 if (blob_data) {
91 if (type == OBJ_BLOB)
fast-import.c
+3 -3
@@ -1412,7 +1412,7 @@ static void load_tree(struct tree_entry *root)
1412 die("Can't load tree %s", oid_to_hex(oid));
1413 } else {
1414 enum object_type type;
1415 - buf = read_sha1_file(oid->hash, &type, &size);
1415 + buf = read_object_file(oid, &type, &size);
1416 if (!buf || type != OBJ_TREE)
1417 die("Can't load tree %s", oid_to_hex(oid));
1418 }
@@ -2967,7 +2967,7 @@ static void cat_blob(struct object_entry *oe, struct object_id *oid)
2967 char *buf;
2968
2969 if (!oe || oe->pack_id == MAX_PACK_ID) {
2970 - buf = read_sha1_file(oid->hash, &type, &size);
2970 + buf = read_object_file(oid, &type, &size);
2971 } else {
2972 type = oe->type;
2973 buf = gfi_unpack_entry(oe, &size);
@@ -3072,7 +3072,7 @@ static struct object_entry *dereference(struct object_entry *oe,
3072 buf = gfi_unpack_entry(oe, &size);
3073 } else {
3074 enum object_type unused;
3075 - buf = read_sha1_file(oid->hash, &unused, &size);
3075 + buf = read_object_file(oid, &unused, &size);
3076 }
3077 if (!buf)
3078 die("Can't load object %s", oid_to_hex(oid));
fsck.c
+1 -1
@@ -811,7 +811,7 @@ static int fsck_tag_buffer(struct tag *tag, const char *data,
811 enum object_type type;
812
813 buffer = to_free =
814 - read_sha1_file(tag->object.oid.hash, &type, &size);
814 + read_object_file(&tag->object.oid, &type, &size);
815 if (!buffer)
816 return report(options, &tag->object,
817 FSCK_MSG_MISSING_TAG_OBJECT,
grep.c
+1 -1
@@ -2015,7 +2015,7 @@ static int grep_source_load_oid(struct grep_source *gs)
2015 enum object_type type;
2016
2017 grep_read_lock();
2018 - gs->buf = read_sha1_file(gs->identifier, &type, &gs->size);
2018 + gs->buf = read_object_file(gs->identifier, &type, &gs->size);
2019 grep_read_unlock();
2020
2021 if (!gs->buf)
http-push.c
+1 -1
@@ -361,7 +361,7 @@ static void start_put(struct transfer_request *request)
361 ssize_t size;
362 git_zstream stream;
363
364 - unpacked = read_sha1_file(request->obj->oid.hash, &type, &len);
364 + unpacked = read_object_file(&request->obj->oid, &type, &len);
365 hdrlen = xsnprintf(hdr, sizeof(hdr), "%s %lu", type_name(type), len) + 1;
366
367 /* Set it up */
mailmap.c
+1 -1
@@ -224,7 +224,7 @@ static int read_mailmap_blob(struct string_list *map,
224 if (get_oid(name, &oid) < 0)
225 return 0;
226
227 - buf = read_sha1_file(oid.hash, &type, &size);
227 + buf = read_object_file(&oid, &type, &size);
228 if (!buf)
229 return error("unable to read mailmap object at %s", name);
230 if (type != OBJ_BLOB)
match-trees.c
+2 -2
@@ -54,7 +54,7 @@ static void *fill_tree_desc_strict(struct tree_desc *desc,
54 enum object_type type;
55 unsigned long size;
56
57 - buffer = read_sha1_file(hash->hash, &type, &size);
57 + buffer = read_object_file(hash, &type, &size);
58 if (!buffer)
59 die("unable to read tree (%s)", oid_to_hex(hash));
60 if (type != OBJ_TREE)
@@ -180,7 +180,7 @@ static int splice_tree(const struct object_id *oid1, const char *prefix,
180 if (*subpath)
181 subpath++;
182
183 - buf = read_sha1_file(oid1->hash, &type, &sz);
183 + buf = read_object_file(oid1, &type, &sz);
184 if (!buf)
185 die("cannot read tree %s", oid_to_hex(oid1));
186 init_tree_desc(&desc, buf, sz);
merge-blobs.c
+2 -2
@@ -11,7 +11,7 @@ static int fill_mmfile_blob(mmfile_t *f, struct blob *obj)
11 unsigned long size;
12 enum object_type type;
13
14 - buf = read_sha1_file(obj->object.oid.hash, &type, &size);
14 + buf = read_object_file(&obj->object.oid, &type, &size);
15 if (!buf)
16 return -1;
17 if (type != OBJ_BLOB) {
@@ -66,7 +66,7 @@ void *merge_blobs(const char *path, struct blob *base, struct blob *our, struct
66 return NULL;
67 if (!our)
68 our = their;
69 - return read_sha1_file(our->object.oid.hash, &type, size);
69 + return read_object_file(&our->object.oid, &type, size);
70 }
71
72 if (fill_mmfile_blob(&f1, our) < 0)
merge-recursive.c
+2 -2
@@ -842,7 +842,7 @@ static int update_file_flags(struct merge_options *o,
842 goto update_index;
843 }
844
845 - buf = read_sha1_file(oid->hash, &type, &size);
845 + buf = read_object_file(oid, &type, &size);
846 if (!buf)
847 return err(o, _("cannot read object %s '%s'"), oid_to_hex(oid), path);
848 if (type != OBJ_BLOB) {
@@ -1656,7 +1656,7 @@ static int read_oid_strbuf(struct merge_options *o,
1656 void *buf;
1657 enum object_type type;
1658 unsigned long size;
1659 - buf = read_sha1_file(oid->hash, &type, &size);
1659 + buf = read_object_file(oid, &type, &size);
1660 if (!buf)
1661 return err(o, _("cannot read object %s"), oid_to_hex(oid));
1662 if (type != OBJ_BLOB) {
notes-cache.c
+1 -1
@@ -77,7 +77,7 @@ char *notes_cache_get(struct notes_cache *c, struct object_id *key_oid,
77 value_oid = get_note(&c->tree, key_oid);
78 if (!value_oid)
79 return NULL;
80 - value = read_sha1_file(value_oid->hash, &type, &size);
80 + value = read_object_file(value_oid, &type, &size);
81
82 *outsize = size;
83 return value;
notes-merge.c
+1 -1
@@ -322,7 +322,7 @@ static void write_note_to_worktree(const struct object_id *obj,
322 {
323 enum object_type type;
324 unsigned long size;
325 - void *buf = read_sha1_file(note->hash, &type, &size);
325 + void *buf = read_object_file(note, &type, &size);
326
327 if (!buf)
328 die("cannot read note %s for object %s",
notes.c
+4 -4
@@ -796,13 +796,13 @@ int combine_notes_concatenate(struct object_id *cur_oid,
796
797 /* read in both note blob objects */
798 if (!is_null_oid(new_oid))
799 - new_msg = read_sha1_file(new_oid->hash, &new_type, &new_len);
799 + new_msg = read_object_file(new_oid, &new_type, &new_len);
800 if (!new_msg || !new_len || new_type != OBJ_BLOB) {
801 free(new_msg);
802 return 0;
803 }
804 if (!is_null_oid(cur_oid))
805 - cur_msg = read_sha1_file(cur_oid->hash, &cur_type, &cur_len);
805 + cur_msg = read_object_file(cur_oid, &cur_type, &cur_len);
806 if (!cur_msg || !cur_len || cur_type != OBJ_BLOB) {
807 free(cur_msg);
808 free(new_msg);
@@ -858,7 +858,7 @@ static int string_list_add_note_lines(struct string_list *list,
858 return 0;
859
860 /* read_sha1_file NUL-terminates */
861 - data = read_sha1_file(oid->hash, &t, &len);
861 + data = read_object_file(oid, &t, &len);
862 if (t != OBJ_BLOB || !data || !len) {
863 free(data);
864 return t != OBJ_BLOB || !data;
@@ -1217,7 +1217,7 @@ static void format_note(struct notes_tree *t, const struct object_id *object_oid
1217 if (!oid)
1218 return;
1219
1220 - if (!(msg = read_sha1_file(oid->hash, &type, &msglen)) || type != OBJ_BLOB) {
1220 + if (!(msg = read_object_file(oid, &type, &msglen)) || type != OBJ_BLOB) {
1221 free(msg);
1222 return;
1223 }
object.c
+1 -1
@@ -266,7 +266,7 @@ struct object *parse_object(const struct object_id *oid)
266 return lookup_object(oid->hash);
267 }
268
269 - buffer = read_sha1_file(oid->hash, &type, &size);
269 + buffer = read_object_file(oid, &type, &size);
270 if (buffer) {
271 struct object_id reploid;
272 hashcpy(reploid.hash, repl);
read-cache.c
+2 -2
@@ -184,7 +184,7 @@ static int ce_compare_link(const struct cache_entry *ce, size_t expected_size)
184 if (strbuf_readlink(&sb, ce->name, expected_size))
185 return -1;
186
187 - buffer = read_sha1_file(ce->oid.hash, &type, &size);
187 + buffer = read_object_file(&ce->oid, &type, &size);
188 if (buffer) {
189 if (size == sb.len)
190 match = memcmp(buffer, sb.buf, size);
@@ -2683,7 +2683,7 @@ void *read_blob_data_from_index(const struct index_state *istate,
2683 }
2684 if (pos < 0)
2685 return NULL;
2686 - data = read_sha1_file(istate->cache[pos]->oid.hash, &type, &sz);
2686 + data = read_object_file(&istate->cache[pos]->oid, &type, &sz);
2687 if (!data || type != OBJ_BLOB) {
2688 free(data);
2689 return NULL;
ref-filter.c
+1 -1
@@ -728,7 +728,7 @@ int verify_ref_format(struct ref_format *format)
728 static void *get_obj(const struct object_id *oid, struct object **obj, unsigned long *sz, int *eaten)
729 {
730 enum object_type type;
731 - void *buf = read_sha1_file(oid->hash, &type, sz);
731 + void *buf = read_object_file(oid, &type, sz);
732
733 if (buf)
734 *obj = parse_object_buffer(oid, type, *sz, buf, eaten);
remote-testsvn.c
+2 -2
@@ -61,7 +61,7 @@ static char *read_ref_note(const struct object_id *oid)
61 init_notes(NULL, notes_ref, NULL, 0);
62 if (!(note_oid = get_note(NULL, oid)))
63 return NULL; /* note tree not found */
64 - if (!(msg = read_sha1_file(note_oid->hash, &type, &msglen)))
64 + if (!(msg = read_object_file(note_oid, &type, &msglen)))
65 error("Empty notes tree. %s", notes_ref);
66 else if (!msglen || type != OBJ_BLOB) {
67 error("Note contains unusable content. "
@@ -108,7 +108,7 @@ static int note2mark_cb(const struct object_id *object_oid,
108 enum object_type type;
109 struct rev_note note;
110
111 - if (!(msg = read_sha1_file(note_oid->hash, &type, &msglen)) ||
111 + if (!(msg = read_object_file(note_oid, &type, &msglen)) ||
112 !msglen || type != OBJ_BLOB) {
113 free(msg);
114 return 1;
rerere.c
+2 -2
@@ -981,8 +981,8 @@ static int handle_cache(const char *path, unsigned char *sha1, const char *outpu
981 break;
982 i = ce_stage(ce) - 1;
983 if (!mmfile[i].ptr) {
984 - mmfile[i].ptr = read_sha1_file(ce->oid.hash, &type,
985 - &size);
984 + mmfile[i].ptr = read_object_file(&ce->oid, &type,
985 + &size);
986 mmfile[i].size = size;
987 }
988 }
sha1_file.c
+10 -10
@@ -1363,17 +1363,17 @@ int pretend_object_file(void *buf, unsigned long len, enum object_type type,
1363 * deal with them should arrange to call read_object() and give error
1364 * messages themselves.
1365 */
1366 -void *read_sha1_file_extended(const unsigned char *sha1,
1367 - enum object_type *type,
1368 - unsigned long *size,
1369 - int lookup_replace)
1366 +void *read_object_file_extended(const struct object_id *oid,
1367 + enum object_type *type,
1368 + unsigned long *size,
1369 + int lookup_replace)
1370 {
1371 void *data;
1372 const struct packed_git *p;
1373 const char *path;
1374 struct stat st;
1375 - const unsigned char *repl = lookup_replace ? lookup_replace_object(sha1)
1376 - : sha1;
1375 + const unsigned char *repl = lookup_replace ? lookup_replace_object(oid->hash)
1376 + : oid->hash;
1377
1378 errno = 0;
1379 data = read_object(repl, type, size);
@@ -1381,12 +1381,12 @@ void *read_sha1_file_extended(const unsigned char *sha1,
1381 return data;
1382
1383 if (errno && errno != ENOENT)
1384 - die_errno("failed to read object %s", sha1_to_hex(sha1));
1384 + die_errno("failed to read object %s", oid_to_hex(oid));
1385
1386 /* die if we replaced an object with one that does not exist */
1387 - if (repl != sha1)
1387 + if (repl != oid->hash)
1388 die("replacement %s not found for %s",
1389 - sha1_to_hex(repl), sha1_to_hex(sha1));
1389 + sha1_to_hex(repl), oid_to_hex(oid));
1390
1391 if (!stat_sha1_file(repl, &st, &path))
1392 die("loose object %s (stored in %s) is corrupt",
@@ -1415,7 +1415,7 @@ void *read_object_with_reference(const struct object_id *oid,
1415 int ref_length = -1;
1416 const char *ref_type = NULL;
1417
1418 - buffer = read_sha1_file(actual_oid.hash, &type, &isize);
1418 + buffer = read_object_file(&actual_oid, &type, &isize);
1419 if (!buffer)
1420 return NULL;
1421 if (type == required_type) {
streaming.c
+1 -1
@@ -492,7 +492,7 @@ static struct stream_vtbl incore_vtbl = {
492
493 static open_method_decl(incore)
494 {
495 - st->u.incore.buf = read_sha1_file_extended(oid->hash, type, &st->size, 0);
495 + st->u.incore.buf = read_object_file_extended(oid, type, &st->size, 0);
496 st->u.incore.read_ptr = 0;
497 st->vtbl = &incore_vtbl;
498
submodule-config.c
+1 -1
@@ -520,7 +520,7 @@ static const struct submodule *config_from(struct submodule_cache *cache,
520 if (submodule)
521 goto out;
522
523 - config = read_sha1_file(oid.hash, &type, &config_size);
523 + config = read_object_file(&oid, &type, &config_size);
524 if (!config || type != OBJ_BLOB)
525 goto out;
526
tag.c
+2 -2
@@ -49,7 +49,7 @@ int gpg_verify_tag(const struct object_id *oid, const char *name_to_report,
49 find_unique_abbrev(oid, DEFAULT_ABBREV),
50 type_name(type));
51
52 - buf = read_sha1_file(oid->hash, &type, &size);
52 + buf = read_object_file(oid, &type, &size);
53 if (!buf)
54 return error("%s: unable to read file.",
55 name_to_report ?
@@ -182,7 +182,7 @@ int parse_tag(struct tag *item)
182
183 if (item->object.parsed)
184 return 0;
185 - data = read_sha1_file(item->object.oid.hash, &type, &size);
185 + data = read_object_file(&item->object.oid, &type, &size);
186 if (!data)
187 return error("Could not read %s",
188 oid_to_hex(&item->object.oid));
tree-walk.c
+2 -2
@@ -713,8 +713,8 @@ enum follow_symlinks_result get_tree_entry_follow_symlinks(unsigned char *tree_s
713 */
714 retval = DANGLING_SYMLINK;
715
716 - contents = read_sha1_file(current_tree_oid.hash, &type,
717 - &link_len);
716 + contents = read_object_file(&current_tree_oid, &type,
717 + &link_len);
718
719 if (!contents)
720 goto done;
tree.c
+1 -1
@@ -219,7 +219,7 @@ int parse_tree_gently(struct tree *item, int quiet_on_missing)
219
220 if (item->object.parsed)
221 return 0;
222 - buffer = read_sha1_file(item->object.oid.hash, &type, &size);
222 + buffer = read_object_file(&item->object.oid, &type, &size);
223 if (!buffer)
224 return quiet_on_missing ? -1 :
225 error("Could not read %s",
xdiff-interface.c
+1 -1
@@ -191,7 +191,7 @@ void read_mmblob(mmfile_t *ptr, const struct object_id *oid)
191 return;
192 }
193
194 - ptr->ptr = read_sha1_file(oid->hash, &type, &size);
194 + ptr->ptr = read_object_file(oid, &type, &size);
195 if (!ptr->ptr || type != OBJ_BLOB)
196 die("unable to read blob object %s", oid_to_hex(oid));
197 ptr->size = size;