Skip to content

Commit b4f5aca

Browse files
bk2204gitster
authored andcommitted
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 <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 02f0547 commit b4f5aca

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

51 files changed

+104
-103
lines changed

Diff for: apply.c

+2-2
Original file line numberDiff line numberDiff line change
@@ -3180,7 +3180,7 @@ static int apply_binary(struct apply_state *state,
31803180
unsigned long size;
31813181
char *result;
31823182

3183-
result = read_sha1_file(oid.hash, &type, &size);
3183+
result = read_object_file(&oid, &type, &size);
31843184
if (!result)
31853185
return error(_("the necessary postimage %s for "
31863186
"'%s' cannot be read"),
@@ -3242,7 +3242,7 @@ static int read_blob_object(struct strbuf *buf, const struct object_id *oid, uns
32423242
unsigned long sz;
32433243
char *result;
32443244

3245-
result = read_sha1_file(oid->hash, &type, &sz);
3245+
result = read_object_file(oid, &type, &sz);
32463246
if (!result)
32473247
return -1;
32483248
/* XXX read_sha1_file NUL-terminates */

Diff for: archive.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ void *object_file_to_archive(const struct archiver_args *args,
7272
const struct commit *commit = args->convert ? args->commit : NULL;
7373

7474
path += args->baselen;
75-
buffer = read_sha1_file(oid->hash, type, sizep);
75+
buffer = read_object_file(oid, type, sizep);
7676
if (buffer && S_ISREG(mode)) {
7777
struct strbuf buf = STRBUF_INIT;
7878
size_t size = 0;

Diff for: bisect.c

+2-1
Original file line numberDiff line numberDiff line change
@@ -132,7 +132,8 @@ static void show_list(const char *debug, int counted, int nr,
132132
unsigned flags = commit->object.flags;
133133
enum object_type type;
134134
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);
136137
const char *subject_start;
137138
int subject_len;
138139

Diff for: blame.c

+4-4
Original file line numberDiff line numberDiff line change
@@ -297,8 +297,8 @@ static void fill_origin_blob(struct diff_options *opt,
297297
textconv_object(o->path, o->mode, &o->blob_oid, 1, &file->ptr, &file_size))
298298
;
299299
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);
302302
file->size = file_size;
303303

304304
if (!file->ptr)
@@ -1829,8 +1829,8 @@ void setup_scoreboard(struct blame_scoreboard *sb, const char *path, struct blam
18291829
&sb->final_buf_size))
18301830
;
18311831
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);
18341834

18351835
if (!sb->final_buf)
18361836
die(_("cannot read blob %s for path %s"),

Diff for: builtin/cat-file.c

+8-6
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ static int filter_object(const char *path, unsigned mode,
3232
{
3333
enum object_type type;
3434

35-
*buf = read_sha1_file(oid->hash, &type, size);
35+
*buf = read_object_file(oid, &type, size);
3636
if (!*buf)
3737
return error(_("cannot read object %s '%s'"),
3838
oid_to_hex(oid), path);
@@ -130,7 +130,7 @@ static int cat_one_file(int opt, const char *exp_type, const char *obj_name,
130130

131131
if (type == OBJ_BLOB)
132132
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);
134134
if (!buf)
135135
die("Cannot read object %s", obj_name);
136136

@@ -141,7 +141,8 @@ static int cat_one_file(int opt, const char *exp_type, const char *obj_name,
141141
if (type_from_string(exp_type) == OBJ_BLOB) {
142142
struct object_id blob_oid;
143143
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);
145146
const char *target;
146147
if (!skip_prefix(buffer, "object ", &target) ||
147148
get_oid_hex(target, &blob_oid))
@@ -304,8 +305,9 @@ static void print_object_or_die(struct batch_options *opt, struct expand_data *d
304305
enum object_type type;
305306
if (!textconv_object(data->rest, 0100644, oid,
306307
1, &contents, &size))
307-
contents = read_sha1_file(oid->hash, &type,
308-
&size);
308+
contents = read_object_file(oid,
309+
&type,
310+
&size);
309311
if (!contents)
310312
die("could not convert '%s' %s",
311313
oid_to_hex(oid), data->rest);
@@ -321,7 +323,7 @@ static void print_object_or_die(struct batch_options *opt, struct expand_data *d
321323
unsigned long size;
322324
void *contents;
323325

324-
contents = read_sha1_file(oid->hash, &type, &size);
326+
contents = read_object_file(oid, &type, &size);
325327
if (!contents)
326328
die("object %s disappeared", oid_to_hex(oid));
327329
if (type != data->type)

Diff for: builtin/difftool.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -306,7 +306,7 @@ static char *get_symlink(const struct object_id *oid, const char *path)
306306
} else {
307307
enum object_type type;
308308
unsigned long size;
309-
data = read_sha1_file(oid->hash, &type, &size);
309+
data = read_object_file(oid, &type, &size);
310310
if (!data)
311311
die(_("could not read object %s for symlink %s"),
312312
oid_to_hex(oid), path);

Diff for: builtin/fast-export.c

+2-2
Original file line numberDiff line numberDiff line change
@@ -237,7 +237,7 @@ static void export_blob(const struct object_id *oid)
237237
object = (struct object *)lookup_blob(oid);
238238
eaten = 0;
239239
} else {
240-
buf = read_sha1_file(oid->hash, &type, &size);
240+
buf = read_object_file(oid, &type, &size);
241241
if (!buf)
242242
die ("Could not read blob %s", oid_to_hex(oid));
243243
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)
682682
return;
683683
}
684684

685-
buf = read_sha1_file(tag->object.oid.hash, &type, &size);
685+
buf = read_object_file(&tag->object.oid, &type, &size);
686686
if (!buf)
687687
die ("Could not read tag %s", oid_to_hex(&tag->object.oid));
688688
message = memmem(buf, size, "\n\n", 2);

Diff for: builtin/fmt-merge-msg.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -488,7 +488,7 @@ static void fmt_merge_msg_sigs(struct strbuf *out)
488488
struct object_id *oid = origins.items[i].util;
489489
enum object_type type;
490490
unsigned long size, len;
491-
char *buf = read_sha1_file(oid->hash, &type, &size);
491+
char *buf = read_object_file(oid, &type, &size);
492492
struct strbuf sig = STRBUF_INIT;
493493

494494
if (!buf || type != OBJ_TAG)

Diff for: builtin/grep.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -306,7 +306,7 @@ static void *lock_and_read_oid_file(const struct object_id *oid, enum object_typ
306306
void *data;
307307

308308
grep_read_lock();
309-
data = read_sha1_file(oid->hash, type, size);
309+
data = read_object_file(oid, type, size);
310310
grep_read_unlock();
311311
return data;
312312
}

Diff for: builtin/index-pack.c

+3-2
Original file line numberDiff line numberDiff line change
@@ -815,7 +815,7 @@ static void sha1_object(const void *data, struct object_entry *obj_entry,
815815
die(_("cannot read existing object info %s"), oid_to_hex(oid));
816816
if (has_type != type || has_size != size)
817817
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);
819819
read_unlock();
820820
if (!data)
821821
data = new_data = get_data_from_pack(obj_entry);
@@ -1373,7 +1373,8 @@ static void fix_unresolved_deltas(struct hashfile *f)
13731373

13741374
if (objects[d->obj_no].real_type != OBJ_REF_DELTA)
13751375
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);
13771378
if (!base_obj->data)
13781379
continue;
13791380

Diff for: builtin/log.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -518,7 +518,7 @@ static int show_tag_object(const struct object_id *oid, struct rev_info *rev)
518518
{
519519
unsigned long size;
520520
enum object_type type;
521-
char *buf = read_sha1_file(oid->hash, &type, &size);
521+
char *buf = read_object_file(oid, &type, &size);
522522
int offset = 0;
523523

524524
if (!buf)

Diff for: builtin/merge-tree.c

+3-2
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ static void *result(struct merge_list *entry, unsigned long *size)
6060
const char *path = entry->path;
6161

6262
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);
6464
base = NULL;
6565
if (entry->stage == 1) {
6666
base = entry->blob;
@@ -82,7 +82,8 @@ static void *origin(struct merge_list *entry, unsigned long *size)
8282
enum object_type type;
8383
while (entry) {
8484
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);
8687
entry = entry->link;
8788
}
8889
return NULL;

Diff for: builtin/mktag.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ static int verify_object(const struct object_id *oid, const char *expected_type)
2323
int ret = -1;
2424
enum object_type type;
2525
unsigned long size;
26-
void *buffer = read_sha1_file(oid->hash, &type, &size);
26+
void *buffer = read_object_file(oid, &type, &size);
2727
const unsigned char *repl = lookup_replace_object(oid->hash);
2828

2929
if (buffer) {

Diff for: builtin/notes.c

+3-3
Original file line numberDiff line numberDiff line change
@@ -122,7 +122,7 @@ static void copy_obj_to_fd(int fd, const struct object_id *oid)
122122
{
123123
unsigned long size;
124124
enum object_type type;
125-
char *buf = read_sha1_file(oid->hash, &type, &size);
125+
char *buf = read_object_file(oid, &type, &size);
126126
if (buf) {
127127
if (size)
128128
write_or_die(fd, buf, size);
@@ -253,7 +253,7 @@ static int parse_reuse_arg(const struct option *opt, const char *arg, int unset)
253253

254254
if (get_oid(arg, &object))
255255
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))) {
257257
free(buf);
258258
die(_("failed to read object '%s'."), arg);
259259
}
@@ -608,7 +608,7 @@ static int append_edit(int argc, const char **argv, const char *prefix)
608608
/* Append buf to previous note contents */
609609
unsigned long size;
610610
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);
612612

613613
strbuf_grow(&d.buf, size + 1);
614614
if (d.buf.len && prev_buf && size)

Diff for: builtin/pack-objects.c

+6-10
Original file line numberDiff line numberDiff line change
@@ -122,11 +122,10 @@ static void *get_delta(struct object_entry *entry)
122122
void *buf, *base_buf, *delta_buf;
123123
enum object_type type;
124124

125-
buf = read_sha1_file(entry->idx.oid.hash, &type, &size);
125+
buf = read_object_file(&entry->idx.oid, &type, &size);
126126
if (!buf)
127127
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);
130129
if (!base_buf)
131130
die("unable to read %s",
132131
oid_to_hex(&entry->delta->idx.oid));
@@ -270,8 +269,7 @@ static unsigned long write_no_reuse_object(struct hashfile *f, struct object_ent
270269
(st = open_istream(&entry->idx.oid, &type, &size, NULL)) != NULL)
271270
buf = NULL;
272271
else {
273-
buf = read_sha1_file(entry->idx.oid.hash, &type,
274-
&size);
272+
buf = read_object_file(&entry->idx.oid, &type, &size);
275273
if (!buf)
276274
die(_("unable to read %s"),
277275
oid_to_hex(&entry->idx.oid));
@@ -1190,7 +1188,7 @@ static struct pbase_tree_cache *pbase_tree_get(const struct object_id *oid)
11901188
/* Did not find one. Either we got a bogus request or
11911189
* we need to read and perhaps cache.
11921190
*/
1193-
data = read_sha1_file(oid->hash, &type, &size);
1191+
data = read_object_file(oid, &type, &size);
11941192
if (!data)
11951193
return NULL;
11961194
if (type != OBJ_TREE) {
@@ -1870,8 +1868,7 @@ static int try_delta(struct unpacked *trg, struct unpacked *src,
18701868
/* Load data if not already done */
18711869
if (!trg->data) {
18721870
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);
18751872
read_unlock();
18761873
if (!trg->data)
18771874
die("object %s cannot be read",
@@ -1884,8 +1881,7 @@ static int try_delta(struct unpacked *trg, struct unpacked *src,
18841881
}
18851882
if (!src->data) {
18861883
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);
18891885
read_unlock();
18901886
if (!src->data) {
18911887
if (src_entry->preferred_base) {

Diff for: builtin/reflog.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ static int tree_is_complete(const struct object_id *oid)
7474
if (!tree->buffer) {
7575
enum object_type type;
7676
unsigned long size;
77-
void *data = read_sha1_file(oid->hash, &type, &size);
77+
void *data = read_object_file(oid, &type, &size);
7878
if (!data) {
7979
tree->object.flags |= INCOMPLETE;
8080
return 0;

Diff for: builtin/tag.c

+2-2
Original file line numberDiff line numberDiff line change
@@ -168,7 +168,7 @@ static void write_tag_body(int fd, const struct object_id *oid)
168168
enum object_type type;
169169
char *buf, *sp;
170170

171-
buf = read_sha1_file(oid->hash, &type, &size);
171+
buf = read_object_file(oid, &type, &size);
172172
if (!buf)
173173
return;
174174
/* skip header */
@@ -304,7 +304,7 @@ static void create_reflog_msg(const struct object_id *oid, struct strbuf *sb)
304304
strbuf_addstr(sb, "object of unknown type");
305305
break;
306306
case OBJ_COMMIT:
307-
if ((buf = read_sha1_file(oid->hash, &type, &size)) != NULL) {
307+
if ((buf = read_object_file(oid, &type, &size)) != NULL) {
308308
subject_len = find_commit_subject(buf, &subject_start);
309309
strbuf_insert(sb, sb->len, subject_start, subject_len);
310310
} else {

Diff for: builtin/unpack-file.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ static char *create_temp_file(struct object_id *oid)
99
unsigned long size;
1010
int fd;
1111

12-
buf = read_sha1_file(oid->hash, &type, &size);
12+
buf = read_object_file(oid, &type, &size);
1313
if (!buf || type != OBJ_BLOB)
1414
die("unable to read blob object %s", oid_to_hex(oid));
1515

Diff for: builtin/unpack-objects.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -422,7 +422,7 @@ static void unpack_delta_entry(enum object_type type, unsigned long delta_size,
422422
if (resolve_against_held(nr, &base_oid, delta_data, delta_size))
423423
return;
424424

425-
base = read_sha1_file(base_oid.hash, &type, &base_size);
425+
base = read_object_file(&base_oid, &type, &base_size);
426426
if (!base) {
427427
error("failed to read delta-pack base object %s",
428428
oid_to_hex(&base_oid));

Diff for: builtin/verify-commit.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ static int verify_commit(const char *name, unsigned flags)
4444
if (get_oid(name, &oid))
4545
return error("commit '%s' not found.", name);
4646

47-
buf = read_sha1_file(oid.hash, &type, &size);
47+
buf = read_object_file(&oid, &type, &size);
4848
if (!buf)
4949
return error("%s: unable to read file.", name);
5050
if (type != OBJ_COMMIT)

Diff for: bundle.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -222,7 +222,7 @@ static int is_tag_in_date_range(struct object *tag, struct rev_info *revs)
222222
if (revs->max_age == -1 && revs->min_age == -1)
223223
goto out;
224224

225-
buf = read_sha1_file(tag->oid.hash, &type, &size);
225+
buf = read_object_file(&tag->oid, &type, &size);
226226
if (!buf)
227227
goto out;
228228
line = memmem(buf, size, "\ntagger ", 8);

Diff for: cache.h

+5-5
Original file line numberDiff line numberDiff line change
@@ -1185,12 +1185,12 @@ extern char *xdg_config_home(const char *filename);
11851185
*/
11861186
extern char *xdg_cache_home(const char *filename);
11871187

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)
11921192
{
1193-
return read_sha1_file_extended(sha1, type, size, 1);
1193+
return read_object_file_extended(oid, type, size, 1);
11941194
}
11951195

11961196
/*

Diff for: combine-diff.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -306,7 +306,7 @@ static char *grab_blob(const struct object_id *oid, unsigned int mode,
306306
*size = fill_textconv(textconv, df, &blob);
307307
free_filespec(df);
308308
} else {
309-
blob = read_sha1_file(oid->hash, &type, size);
309+
blob = read_object_file(oid, &type, size);
310310
if (type != OBJ_BLOB)
311311
die("object '%s' is not a blob!", oid_to_hex(oid));
312312
}

0 commit comments

Comments
 (0)