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 <sandals@crustytoothpaste.net> Signed-off-by: Junio C Hamano <gitster@pobox.com>
1 parent a9dbc17 commit c251c83

38 files changed

+107
-108
lines changed

builtin/diff-tree.c

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

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

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

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

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

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

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

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

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

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

0 commit comments

Comments
 (0)