Skip to content

Commit c251c83

Browse files
bk2204gitster
authored andcommitted
object: convert parse_object* to take struct object_id
Make parse_object, parse_object_or_die, and parse_object_buffer take a pointer to struct object_id. Remove the temporary variables inserted earlier, since they are no longer necessary. Transform all of the callers using the following semantic patch: @@ expression E1; @@ - parse_object(E1.hash) + parse_object(&E1) @@ expression E1; @@ - parse_object(E1->hash) + parse_object(E1) @@ expression E1, E2; @@ - parse_object_or_die(E1.hash, E2) + parse_object_or_die(&E1, E2) @@ expression E1, E2; @@ - parse_object_or_die(E1->hash, E2) + parse_object_or_die(E1, E2) @@ expression E1, E2, E3, E4, E5; @@ - parse_object_buffer(E1.hash, E2, E3, E4, E5) + parse_object_buffer(&E1, E2, E3, E4, E5) @@ expression E1, E2, E3, E4, E5; @@ - parse_object_buffer(E1->hash, E2, E3, E4, E5) + parse_object_buffer(E1, E2, E3, E4, E5) Signed-off-by: brian m. carlson <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent a9dbc17 commit c251c83

38 files changed

+107
-108
lines changed

builtin/diff-tree.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ static int diff_tree_stdin(char *line)
6767
line[len-1] = 0;
6868
if (parse_oid_hex(line, &oid, &p))
6969
return -1;
70-
obj = parse_object(oid.hash);
70+
obj = parse_object(&oid);
7171
if (!obj)
7272
return -1;
7373
if (obj->type == OBJ_COMMIT)

builtin/diff.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -395,7 +395,7 @@ int cmd_diff(int argc, const char **argv, const char *prefix)
395395
const char *name = entry->name;
396396
int flags = (obj->flags & UNINTERESTING);
397397
if (!obj->parsed)
398-
obj = parse_object(obj->oid.hash);
398+
obj = parse_object(&obj->oid);
399399
obj = deref_tag(obj, NULL, 0);
400400
if (!obj)
401401
die(_("invalid object '%s' given."), name);

builtin/fast-export.c

+2-2
Original file line numberDiff line numberDiff line change
@@ -240,7 +240,7 @@ static void export_blob(const struct object_id *oid)
240240
die ("Could not read blob %s", oid_to_hex(oid));
241241
if (check_sha1_signature(oid->hash, buf, size, typename(type)) < 0)
242242
die("sha1 mismatch in blob %s", oid_to_hex(oid));
243-
object = parse_object_buffer(oid->hash, type, size, buf, &eaten);
243+
object = parse_object_buffer(oid, type, size, buf, &eaten);
244244
}
245245

246246
if (!object)
@@ -777,7 +777,7 @@ static struct commit *get_commit(struct rev_cmdline_entry *e, char *full_name)
777777

778778
/* handle nested tags */
779779
while (tag && tag->object.type == OBJ_TAG) {
780-
parse_object(tag->object.oid.hash);
780+
parse_object(&tag->object.oid);
781781
string_list_append(&extra_refs, full_name)->util = tag;
782782
tag = (struct tag *)tag->tagged;
783783
}

builtin/fmt-merge-msg.c

+2-2
Original file line numberDiff line numberDiff line change
@@ -341,7 +341,7 @@ static void shortlog(const char *name,
341341
const struct object_id *oid = &origin_data->oid;
342342
int limit = opts->shortlog_len;
343343

344-
branch = deref_tag(parse_object(oid->hash), oid_to_hex(oid), GIT_SHA1_HEXSZ);
344+
branch = deref_tag(parse_object(oid), oid_to_hex(oid), GIT_SHA1_HEXSZ);
345345
if (!branch || branch->type != OBJ_COMMIT)
346346
return;
347347

@@ -559,7 +559,7 @@ static void find_merge_parents(struct merge_parents *result,
559559
* "name" here and we do not want to contaminate its
560560
* util field yet.
561561
*/
562-
obj = parse_object(oid.hash);
562+
obj = parse_object(&oid);
563563
parent = (struct commit *)peel_to_type(NULL, 0, obj, OBJ_COMMIT);
564564
if (!parent)
565565
continue;

builtin/fsck.c

+4-4
Original file line numberDiff line numberDiff line change
@@ -385,7 +385,7 @@ static int fsck_obj_buffer(const struct object_id *oid, enum object_type type,
385385
* verify_packfile(), data_valid variable for details.
386386
*/
387387
struct object *obj;
388-
obj = parse_object_buffer(oid->hash, type, size, buffer, eaten);
388+
obj = parse_object_buffer(oid, type, size, buffer, eaten);
389389
if (!obj) {
390390
errors_found |= ERROR_OBJECT;
391391
return error("%s: object corrupt or missing", oid_to_hex(oid));
@@ -444,7 +444,7 @@ static int fsck_handle_ref(const char *refname, const struct object_id *oid,
444444
{
445445
struct object *obj;
446446

447-
obj = parse_object(oid->hash);
447+
obj = parse_object(oid);
448448
if (!obj) {
449449
error("%s: invalid sha1 pointer %s", refname, oid_to_hex(oid));
450450
errors_found |= ERROR_REACHABLE;
@@ -506,7 +506,7 @@ static struct object *parse_loose_object(const struct object_id *oid,
506506
if (!contents && type != OBJ_BLOB)
507507
die("BUG: read_loose_object streamed a non-blob");
508508

509-
obj = parse_object_buffer(oid->hash, type, size, contents, &eaten);
509+
obj = parse_object_buffer(oid, type, size, contents, &eaten);
510510

511511
if (!eaten)
512512
free(contents);
@@ -599,7 +599,7 @@ static int fsck_cache_tree(struct cache_tree *it)
599599
fprintf(stderr, "Checking cache tree\n");
600600

601601
if (0 <= it->entry_count) {
602-
struct object *obj = parse_object(it->oid.hash);
602+
struct object *obj = parse_object(&it->oid);
603603
if (!obj) {
604604
error("%s: invalid sha1 pointer in cache-tree",
605605
oid_to_hex(&it->oid));

builtin/grep.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -1196,7 +1196,7 @@ int cmd_grep(int argc, const char **argv, const char *prefix)
11961196
break;
11971197
}
11981198

1199-
object = parse_object_or_die(oid.hash, arg);
1199+
object = parse_object_or_die(&oid, arg);
12001200
if (!seen_dashdash)
12011201
verify_non_filename(prefix, arg);
12021202
add_object_array_with_path(object, arg, &list, oc.mode, oc.path);

builtin/index-pack.c

+2-1
Original file line numberDiff line numberDiff line change
@@ -845,7 +845,8 @@ static void sha1_object(const void *data, struct object_entry *obj_entry,
845845
* we do not need to free the memory here, as the
846846
* buf is deleted by the caller.
847847
*/
848-
obj = parse_object_buffer(oid->hash, type, size, buf, &eaten);
848+
obj = parse_object_buffer(oid, type, size, buf,
849+
&eaten);
849850
if (!obj)
850851
die(_("invalid %s"), typename(type));
851852
if (do_fsck_object &&

builtin/log.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -596,7 +596,7 @@ int cmd_show(int argc, const char **argv, const char *prefix)
596596
rev.shown_one = 1;
597597
if (ret)
598598
break;
599-
o = parse_object(t->tagged->oid.hash);
599+
o = parse_object(&t->tagged->oid);
600600
if (!o)
601601
ret = error(_("Could not read object %s"),
602602
oid_to_hex(&t->tagged->oid));

builtin/name-rev.c

+3-3
Original file line numberDiff line numberDiff line change
@@ -142,7 +142,7 @@ static int tipcmp(const void *a_, const void *b_)
142142

143143
static int name_ref(const char *path, const struct object_id *oid, int flags, void *cb_data)
144144
{
145-
struct object *o = parse_object(oid->hash);
145+
struct object *o = parse_object(oid);
146146
struct name_ref_data *data = cb_data;
147147
int can_abbreviate_output = data->tags_only && data->name_only;
148148
int deref = 0;
@@ -200,7 +200,7 @@ static int name_ref(const char *path, const struct object_id *oid, int flags, vo
200200
struct tag *t = (struct tag *) o;
201201
if (!t->tagged)
202202
break; /* broken repository */
203-
o = parse_object(t->tagged->oid.hash);
203+
o = parse_object(&t->tagged->oid);
204204
deref = 1;
205205
taggerdate = t->date;
206206
}
@@ -385,7 +385,7 @@ int cmd_name_rev(int argc, const char **argv, const char *prefix)
385385
}
386386

387387
commit = NULL;
388-
object = parse_object(oid.hash);
388+
object = parse_object(&oid);
389389
if (object) {
390390
struct object *peeled = deref_tag(object, *argv, 0);
391391
if (peeled && peeled->type == OBJ_COMMIT)

builtin/prune.c

+2-1
Original file line numberDiff line numberDiff line change
@@ -127,7 +127,8 @@ int cmd_prune(int argc, const char **argv, const char *prefix)
127127
const char *name = *argv++;
128128

129129
if (!get_oid(name, &oid)) {
130-
struct object *object = parse_object_or_die(oid.hash, name);
130+
struct object *object = parse_object_or_die(&oid,
131+
name);
131132
add_pending_object(&revs, object, "");
132133
}
133134
else

builtin/receive-pack.c

+3-3
Original file line numberDiff line numberDiff line change
@@ -1058,8 +1058,8 @@ static const char *update(struct command *cmd, struct shallow_info *si)
10581058
struct object *old_object, *new_object;
10591059
struct commit *old_commit, *new_commit;
10601060

1061-
old_object = parse_object(old_oid->hash);
1062-
new_object = parse_object(new_oid->hash);
1061+
old_object = parse_object(old_oid);
1062+
new_object = parse_object(new_oid);
10631063

10641064
if (!old_object || !new_object ||
10651065
old_object->type != OBJ_COMMIT ||
@@ -1082,7 +1082,7 @@ static const char *update(struct command *cmd, struct shallow_info *si)
10821082

10831083
if (is_null_oid(new_oid)) {
10841084
struct strbuf err = STRBUF_INIT;
1085-
if (!parse_object(old_oid->hash)) {
1085+
if (!parse_object(old_oid)) {
10861086
old_oid = NULL;
10871087
if (ref_exists(name)) {
10881088
rp_warning("Allowing deletion of corrupt ref.");

builtin/reflog.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -126,7 +126,7 @@ static int commit_is_complete(struct commit *commit)
126126
struct commit_list *parent;
127127

128128
c = (struct commit *)study.objects[--study.nr].item;
129-
if (!c->object.parsed && !parse_object(c->object.oid.hash))
129+
if (!c->object.parsed && !parse_object(&c->object.oid))
130130
c->object.flags |= INCOMPLETE;
131131

132132
if (c->object.flags & INCOMPLETE) {

builtin/rev-list.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -181,7 +181,7 @@ static void finish_object(struct object *obj, const char *name, void *cb_data)
181181
if (obj->type == OBJ_BLOB && !has_object_file(&obj->oid))
182182
die("missing blob object '%s'", oid_to_hex(&obj->oid));
183183
if (info->revs->verify_objects && !obj->parsed && obj->type != OBJ_COMMIT)
184-
parse_object(obj->oid.hash);
184+
parse_object(&obj->oid);
185185
}
186186

187187
static void show_object(struct object *obj, const char *name, void *cb_data)

builtin/unpack-objects.c

+2-1
Original file line numberDiff line numberDiff line change
@@ -260,7 +260,8 @@ static void write_object(unsigned nr, enum object_type type,
260260
int eaten;
261261
hash_sha1_file(buf, size, typename(type), obj_list[nr].oid.hash);
262262
added_object(nr, type, buf, size);
263-
obj = parse_object_buffer(obj_list[nr].oid.hash, type, size, buf, &eaten);
263+
obj = parse_object_buffer(&obj_list[nr].oid, type, size, buf,
264+
&eaten);
264265
if (!obj)
265266
die("invalid %s", typename(type));
266267
add_object_buffer(obj, buf, size);

bundle.c

+6-4
Original file line numberDiff line numberDiff line change
@@ -142,7 +142,7 @@ int verify_bundle(struct bundle_header *header, int verbose)
142142
init_revisions(&revs, NULL);
143143
for (i = 0; i < p->nr; i++) {
144144
struct ref_list_entry *e = p->list + i;
145-
struct object *o = parse_object(e->oid.hash);
145+
struct object *o = parse_object(&e->oid);
146146
if (o) {
147147
o->flags |= PREREQ_MARK;
148148
add_pending_object(&revs, o, e->name);
@@ -290,12 +290,14 @@ static int compute_and_write_prerequisites(int bundle_fd,
290290
if (buf.len > 0 && buf.buf[0] == '-') {
291291
write_or_die(bundle_fd, buf.buf, buf.len);
292292
if (!get_oid_hex(buf.buf + 1, &oid)) {
293-
struct object *object = parse_object_or_die(oid.hash, buf.buf);
293+
struct object *object = parse_object_or_die(&oid,
294+
buf.buf);
294295
object->flags |= UNINTERESTING;
295296
add_pending_object(revs, object, buf.buf);
296297
}
297298
} else if (!get_oid_hex(buf.buf, &oid)) {
298-
struct object *object = parse_object_or_die(oid.hash, buf.buf);
299+
struct object *object = parse_object_or_die(&oid,
300+
buf.buf);
299301
object->flags |= SHOWN;
300302
}
301303
}
@@ -379,7 +381,7 @@ static int write_bundle_refs(int bundle_fd, struct rev_info *revs)
379381
* end up triggering "empty bundle"
380382
* error.
381383
*/
382-
obj = parse_object_or_die(oid.hash, e->name);
384+
obj = parse_object_or_die(&oid, e->name);
383385
obj->flags |= SHOWN;
384386
add_pending_object(revs, obj, e->name);
385387
}

commit.c

+2-2
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ const char *commit_type = "commit";
2121
struct commit *lookup_commit_reference_gently(const struct object_id *oid,
2222
int quiet)
2323
{
24-
struct object *obj = deref_tag(parse_object(oid->hash), NULL, 0);
24+
struct object *obj = deref_tag(parse_object(oid), NULL, 0);
2525

2626
if (!obj)
2727
return NULL;
@@ -1589,7 +1589,7 @@ struct commit *get_merge_parent(const char *name)
15891589
struct object_id oid;
15901590
if (get_sha1(name, oid.hash))
15911591
return NULL;
1592-
obj = parse_object(oid.hash);
1592+
obj = parse_object(&oid);
15931593
commit = (struct commit *)peel_to_type(name, 0, obj, OBJ_COMMIT);
15941594
if (commit && !commit->util)
15951595
set_merge_remote_desc(commit, name, obj);

fetch-pack.c

+7-7
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ static void cache_one_alternate(const char *refname,
7878
void *vcache)
7979
{
8080
struct alternate_object_cache *cache = vcache;
81-
struct object *obj = parse_object(oid->hash);
81+
struct object *obj = parse_object(oid);
8282

8383
if (!obj || (obj->flags & ALTERNATE))
8484
return;
@@ -120,7 +120,7 @@ static void rev_list_push(struct commit *commit, int mark)
120120

121121
static int rev_list_insert_ref(const char *refname, const struct object_id *oid)
122122
{
123-
struct object *o = deref_tag(parse_object(oid->hash), refname, 0);
123+
struct object *o = deref_tag(parse_object(oid), refname, 0);
124124

125125
if (o && o->type == OBJ_COMMIT)
126126
rev_list_push((struct commit *)o, SEEN);
@@ -137,7 +137,7 @@ static int rev_list_insert_ref_oid(const char *refname, const struct object_id *
137137
static int clear_marks(const char *refname, const struct object_id *oid,
138138
int flag, void *cb_data)
139139
{
140-
struct object *o = deref_tag(parse_object(oid->hash), refname, 0);
140+
struct object *o = deref_tag(parse_object(oid), refname, 0);
141141

142142
if (o && o->type == OBJ_COMMIT)
143143
clear_commit_marks((struct commit *)o,
@@ -426,7 +426,7 @@ static int find_common(struct fetch_pack_args *args,
426426
if (!lookup_object(oid.hash))
427427
die(_("object not found: %s"), line);
428428
/* make sure that it is parsed as shallow */
429-
if (!parse_object(oid.hash))
429+
if (!parse_object(&oid))
430430
die(_("error in object: %s"), line);
431431
if (unregister_shallow(&oid))
432432
die(_("no shallow found: %s"), line);
@@ -557,14 +557,14 @@ static struct commit_list *complete;
557557

558558
static int mark_complete(const struct object_id *oid)
559559
{
560-
struct object *o = parse_object(oid->hash);
560+
struct object *o = parse_object(oid);
561561

562562
while (o && o->type == OBJ_TAG) {
563563
struct tag *t = (struct tag *) o;
564564
if (!t->tagged)
565565
break; /* broken repository */
566566
o->flags |= COMPLETE;
567-
o = parse_object(t->tagged->oid.hash);
567+
o = parse_object(&t->tagged->oid);
568568
}
569569
if (o && o->type == OBJ_COMMIT) {
570570
struct commit *commit = (struct commit *)o;
@@ -681,7 +681,7 @@ static int everything_local(struct fetch_pack_args *args,
681681
if (!has_object_file(&ref->old_oid))
682682
continue;
683683

684-
o = parse_object(ref->old_oid.hash);
684+
o = parse_object(&ref->old_oid);
685685
if (!o)
686686
continue;
687687

fsck.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -461,7 +461,7 @@ int fsck_walk(struct object *obj, void *data, struct fsck_options *options)
461461
return -1;
462462

463463
if (obj->type == OBJ_NONE)
464-
parse_object(obj->oid.hash);
464+
parse_object(&obj->oid);
465465

466466
switch (obj->type) {
467467
case OBJ_BLOB:

http-backend.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -431,7 +431,7 @@ static int show_text_ref(const char *name, const struct object_id *oid,
431431
{
432432
const char *name_nons = strip_namespace(name);
433433
struct strbuf *buf = cb_data;
434-
struct object *o = parse_object(oid->hash);
434+
struct object *o = parse_object(oid);
435435
if (!o)
436436
return 0;
437437

http-push.c

+2-2
Original file line numberDiff line numberDiff line change
@@ -724,7 +724,7 @@ static void one_remote_object(const struct object_id *oid)
724724

725725
obj = lookup_object(oid->hash);
726726
if (!obj)
727-
obj = parse_object(oid->hash);
727+
obj = parse_object(oid);
728728

729729
/* Ignore remote objects that don't exist locally */
730730
if (!obj)
@@ -1462,7 +1462,7 @@ static void add_remote_info_ref(struct remote_ls_ctx *ls)
14621462
return;
14631463
}
14641464

1465-
o = parse_object(ref->old_oid.hash);
1465+
o = parse_object(&ref->old_oid);
14661466
if (!o) {
14671467
fprintf(stderr,
14681468
"Unable to parse object %s for remote ref %s\n",

log-tree.c

+3-3
Original file line numberDiff line numberDiff line change
@@ -105,13 +105,13 @@ static int add_ref_decoration(const char *refname, const struct object_id *oid,
105105
warning("invalid replace ref %s", refname);
106106
return 0;
107107
}
108-
obj = parse_object(original_oid.hash);
108+
obj = parse_object(&original_oid);
109109
if (obj)
110110
add_name_decoration(DECORATION_GRAFTED, "replaced", obj);
111111
return 0;
112112
}
113113

114-
obj = parse_object(oid->hash);
114+
obj = parse_object(oid);
115115
if (!obj)
116116
return 0;
117117

@@ -132,7 +132,7 @@ static int add_ref_decoration(const char *refname, const struct object_id *oid,
132132
if (!obj)
133133
break;
134134
if (!obj->parsed)
135-
parse_object(obj->oid.hash);
135+
parse_object(&obj->oid);
136136
add_name_decoration(DECORATION_REF_TAG, refname, obj);
137137
}
138138
return 0;

merge-recursive.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -2103,7 +2103,7 @@ static struct commit *get_ref(const struct object_id *oid, const char *name)
21032103
{
21042104
struct object *object;
21052105

2106-
object = deref_tag(parse_object(oid->hash), name, strlen(name));
2106+
object = deref_tag(parse_object(oid), name, strlen(name));
21072107
if (!object)
21082108
return NULL;
21092109
if (object->type == OBJ_TREE)

0 commit comments

Comments
 (0)