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

apply.c

Lines changed: 2 additions & 2 deletions
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 */

archive.c

Lines changed: 1 addition & 1 deletion
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;

bisect.c

Lines changed: 2 additions & 1 deletion
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

blame.c

Lines changed: 4 additions & 4 deletions
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"),

builtin/cat-file.c

Lines changed: 8 additions & 6 deletions
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)

builtin/difftool.c

Lines changed: 1 addition & 1 deletion
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);

builtin/fast-export.c

Lines changed: 2 additions & 2 deletions
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);

builtin/fmt-merge-msg.c

Lines changed: 1 addition & 1 deletion
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)

builtin/grep.c

Lines changed: 1 addition & 1 deletion
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
}

builtin/index-pack.c

Lines changed: 3 additions & 2 deletions
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

0 commit comments

Comments
 (0)