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>

brian m. carlson committed May 6, 2017 at 22:10 UTC c251c83df276dc0bff4d008433268ad59b7a8df2
38 files changed +107 -108
builtin/diff-tree.c
+1 -1
@@ -67,7 +67,7 @@ static int diff_tree_stdin(char *line)
67 line[len-1] = 0;
68 if (parse_oid_hex(line, &oid, &p))
69 return -1;
70 - obj = parse_object(oid.hash);
70 + obj = parse_object(&oid);
71 if (!obj)
72 return -1;
73 if (obj->type == OBJ_COMMIT)
builtin/diff.c
+1 -1
@@ -395,7 +395,7 @@ int cmd_diff(int argc, const char **argv, const char *prefix)
395 const char *name = entry->name;
396 int flags = (obj->flags & UNINTERESTING);
397 if (!obj->parsed)
398 - obj = parse_object(obj->oid.hash);
398 + obj = parse_object(&obj->oid);
399 obj = deref_tag(obj, NULL, 0);
400 if (!obj)
401 die(_("invalid object '%s' given."), name);
builtin/fast-export.c
+2 -2
@@ -240,7 +240,7 @@ static void export_blob(const struct object_id *oid)
240 die ("Could not read blob %s", oid_to_hex(oid));
241 if (check_sha1_signature(oid->hash, buf, size, typename(type)) < 0)
242 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);
244 }
245
246 if (!object)
@@ -777,7 +777,7 @@ static struct commit *get_commit(struct rev_cmdline_entry *e, char *full_name)
777
778 /* handle nested tags */
779 while (tag && tag->object.type == OBJ_TAG) {
780 - parse_object(tag->object.oid.hash);
780 + parse_object(&tag->object.oid);
781 string_list_append(&extra_refs, full_name)->util = tag;
782 tag = (struct tag *)tag->tagged;
783 }
builtin/fmt-merge-msg.c
+2 -2
@@ -341,7 +341,7 @@ static void shortlog(const char *name,
341 const struct object_id *oid = &origin_data->oid;
342 int limit = opts->shortlog_len;
343
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);
345 if (!branch || branch->type != OBJ_COMMIT)
346 return;
347
@@ -559,7 +559,7 @@ static void find_merge_parents(struct merge_parents *result,
559 * "name" here and we do not want to contaminate its
560 * util field yet.
561 */
562 - obj = parse_object(oid.hash);
562 + obj = parse_object(&oid);
563 parent = (struct commit *)peel_to_type(NULL, 0, obj, OBJ_COMMIT);
564 if (!parent)
565 continue;
builtin/fsck.c
+4 -4
@@ -385,7 +385,7 @@ static int fsck_obj_buffer(const struct object_id *oid, enum object_type type,
385 * verify_packfile(), data_valid variable for details.
386 */
387 struct object *obj;
388 - obj = parse_object_buffer(oid->hash, type, size, buffer, eaten);
388 + obj = parse_object_buffer(oid, type, size, buffer, eaten);
389 if (!obj) {
390 errors_found |= ERROR_OBJECT;
391 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,
444 {
445 struct object *obj;
446
447 - obj = parse_object(oid->hash);
447 + obj = parse_object(oid);
448 if (!obj) {
449 error("%s: invalid sha1 pointer %s", refname, oid_to_hex(oid));
450 errors_found |= ERROR_REACHABLE;
@@ -506,7 +506,7 @@ static struct object *parse_loose_object(const struct object_id *oid,
506 if (!contents && type != OBJ_BLOB)
507 die("BUG: read_loose_object streamed a non-blob");
508
509 - obj = parse_object_buffer(oid->hash, type, size, contents, &eaten);
509 + obj = parse_object_buffer(oid, type, size, contents, &eaten);
510
511 if (!eaten)
512 free(contents);
@@ -599,7 +599,7 @@ static int fsck_cache_tree(struct cache_tree *it)
599 fprintf(stderr, "Checking cache tree\n");
600
601 if (0 <= it->entry_count) {
602 - struct object *obj = parse_object(it->oid.hash);
602 + struct object *obj = parse_object(&it->oid);
603 if (!obj) {
604 error("%s: invalid sha1 pointer in cache-tree",
605 oid_to_hex(&it->oid));
builtin/grep.c
+1 -1
@@ -1196,7 +1196,7 @@ int cmd_grep(int argc, const char **argv, const char *prefix)
1196 break;
1197 }
1198
1199 - object = parse_object_or_die(oid.hash, arg);
1199 + object = parse_object_or_die(&oid, arg);
1200 if (!seen_dashdash)
1201 verify_non_filename(prefix, arg);
1202 add_object_array_with_path(object, arg, &list, oc.mode, oc.path);
builtin/index-pack.c
+2 -1
@@ -845,7 +845,8 @@ static void sha1_object(const void *data, struct object_entry *obj_entry,
845 * we do not need to free the memory here, as the
846 * buf is deleted by the caller.
847 */
848 - obj = parse_object_buffer(oid->hash, type, size, buf, &eaten);
848 + obj = parse_object_buffer(oid, type, size, buf,
849 + &eaten);
850 if (!obj)
851 die(_("invalid %s"), typename(type));
852 if (do_fsck_object &&
builtin/log.c
+1 -1
@@ -596,7 +596,7 @@ int cmd_show(int argc, const char **argv, const char *prefix)
596 rev.shown_one = 1;
597 if (ret)
598 break;
599 - o = parse_object(t->tagged->oid.hash);
599 + o = parse_object(&t->tagged->oid);
600 if (!o)
601 ret = error(_("Could not read object %s"),
602 oid_to_hex(&t->tagged->oid));
builtin/name-rev.c
+3 -3
@@ -142,7 +142,7 @@ static int tipcmp(const void *a_, const void *b_)
142
143 static int name_ref(const char *path, const struct object_id *oid, int flags, void *cb_data)
144 {
145 - struct object *o = parse_object(oid->hash);
145 + struct object *o = parse_object(oid);
146 struct name_ref_data *data = cb_data;
147 int can_abbreviate_output = data->tags_only && data->name_only;
148 int deref = 0;
@@ -200,7 +200,7 @@ static int name_ref(const char *path, const struct object_id *oid, int flags, vo
200 struct tag *t = (struct tag *) o;
201 if (!t->tagged)
202 break; /* broken repository */
203 - o = parse_object(t->tagged->oid.hash);
203 + o = parse_object(&t->tagged->oid);
204 deref = 1;
205 taggerdate = t->date;
206 }
@@ -385,7 +385,7 @@ int cmd_name_rev(int argc, const char **argv, const char *prefix)
385 }
386
387 commit = NULL;
388 - object = parse_object(oid.hash);
388 + object = parse_object(&oid);
389 if (object) {
390 struct object *peeled = deref_tag(object, *argv, 0);
391 if (peeled && peeled->type == OBJ_COMMIT)
builtin/prune.c
+2 -1
@@ -127,7 +127,8 @@ int cmd_prune(int argc, const char **argv, const char *prefix)
127 const char *name = *argv++;
128
129 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);
132 add_pending_object(&revs, object, "");
133 }
134 else
builtin/receive-pack.c
+3 -3
@@ -1058,8 +1058,8 @@ static const char *update(struct command *cmd, struct shallow_info *si)
1058 struct object *old_object, *new_object;
1059 struct commit *old_commit, *new_commit;
1060
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);
1063
1064 if (!old_object || !new_object ||
1065 old_object->type != OBJ_COMMIT ||
@@ -1082,7 +1082,7 @@ static const char *update(struct command *cmd, struct shallow_info *si)
1082
1083 if (is_null_oid(new_oid)) {
1084 struct strbuf err = STRBUF_INIT;
1085 - if (!parse_object(old_oid->hash)) {
1085 + if (!parse_object(old_oid)) {
1086 old_oid = NULL;
1087 if (ref_exists(name)) {
1088 rp_warning("Allowing deletion of corrupt ref.");
builtin/reflog.c
+1 -1
@@ -126,7 +126,7 @@ static int commit_is_complete(struct commit *commit)
126 struct commit_list *parent;
127
128 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))
130 c->object.flags |= INCOMPLETE;
131
132 if (c->object.flags & INCOMPLETE) {
builtin/rev-list.c
+1 -1
@@ -181,7 +181,7 @@ static void finish_object(struct object *obj, const char *name, void *cb_data)
181 if (obj->type == OBJ_BLOB && !has_object_file(&obj->oid))
182 die("missing blob object '%s'", oid_to_hex(&obj->oid));
183 if (info->revs->verify_objects && !obj->parsed && obj->type != OBJ_COMMIT)
184 - parse_object(obj->oid.hash);
184 + parse_object(&obj->oid);
185 }
186
187 static void show_object(struct object *obj, const char *name, void *cb_data)
builtin/unpack-objects.c
+2 -1
@@ -260,7 +260,8 @@ static void write_object(unsigned nr, enum object_type type,
260 int eaten;
261 hash_sha1_file(buf, size, typename(type), obj_list[nr].oid.hash);
262 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);
265 if (!obj)
266 die("invalid %s", typename(type));
267 add_object_buffer(obj, buf, size);
bundle.c
+6 -4
@@ -142,7 +142,7 @@ int verify_bundle(struct bundle_header *header, int verbose)
142 init_revisions(&revs, NULL);
143 for (i = 0; i < p->nr; i++) {
144 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);
146 if (o) {
147 o->flags |= PREREQ_MARK;
148 add_pending_object(&revs, o, e->name);
@@ -290,12 +290,14 @@ static int compute_and_write_prerequisites(int bundle_fd,
290 if (buf.len > 0 && buf.buf[0] == '-') {
291 write_or_die(bundle_fd, buf.buf, buf.len);
292 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);
295 object->flags |= UNINTERESTING;
296 add_pending_object(revs, object, buf.buf);
297 }
298 } 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);
301 object->flags |= SHOWN;
302 }
303 }
@@ -379,7 +381,7 @@ static int write_bundle_refs(int bundle_fd, struct rev_info *revs)
381 * end up triggering "empty bundle"
382 * error.
383 */
382 - obj = parse_object_or_die(oid.hash, e->name);
384 + obj = parse_object_or_die(&oid, e->name);
385 obj->flags |= SHOWN;
386 add_pending_object(revs, obj, e->name);
387 }
commit.c
+2 -2
@@ -21,7 +21,7 @@ const char *commit_type = "commit";
21 struct commit *lookup_commit_reference_gently(const struct object_id *oid,
22 int quiet)
23 {
24 - struct object *obj = deref_tag(parse_object(oid->hash), NULL, 0);
24 + struct object *obj = deref_tag(parse_object(oid), NULL, 0);
25
26 if (!obj)
27 return NULL;
@@ -1589,7 +1589,7 @@ struct commit *get_merge_parent(const char *name)
1589 struct object_id oid;
1590 if (get_sha1(name, oid.hash))
1591 return NULL;
1592 - obj = parse_object(oid.hash);
1592 + obj = parse_object(&oid);
1593 commit = (struct commit *)peel_to_type(name, 0, obj, OBJ_COMMIT);
1594 if (commit && !commit->util)
1595 set_merge_remote_desc(commit, name, obj);
fetch-pack.c
+7 -7
@@ -78,7 +78,7 @@ static void cache_one_alternate(const char *refname,
78 void *vcache)
79 {
80 struct alternate_object_cache *cache = vcache;
81 - struct object *obj = parse_object(oid->hash);
81 + struct object *obj = parse_object(oid);
82
83 if (!obj || (obj->flags & ALTERNATE))
84 return;
@@ -120,7 +120,7 @@ static void rev_list_push(struct commit *commit, int mark)
120
121 static int rev_list_insert_ref(const char *refname, const struct object_id *oid)
122 {
123 - struct object *o = deref_tag(parse_object(oid->hash), refname, 0);
123 + struct object *o = deref_tag(parse_object(oid), refname, 0);
124
125 if (o && o->type == OBJ_COMMIT)
126 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 *
137 static int clear_marks(const char *refname, const struct object_id *oid,
138 int flag, void *cb_data)
139 {
140 - struct object *o = deref_tag(parse_object(oid->hash), refname, 0);
140 + struct object *o = deref_tag(parse_object(oid), refname, 0);
141
142 if (o && o->type == OBJ_COMMIT)
143 clear_commit_marks((struct commit *)o,
@@ -426,7 +426,7 @@ static int find_common(struct fetch_pack_args *args,
426 if (!lookup_object(oid.hash))
427 die(_("object not found: %s"), line);
428 /* make sure that it is parsed as shallow */
429 - if (!parse_object(oid.hash))
429 + if (!parse_object(&oid))
430 die(_("error in object: %s"), line);
431 if (unregister_shallow(&oid))
432 die(_("no shallow found: %s"), line);
@@ -557,14 +557,14 @@ static struct commit_list *complete;
557
558 static int mark_complete(const struct object_id *oid)
559 {
560 - struct object *o = parse_object(oid->hash);
560 + struct object *o = parse_object(oid);
561
562 while (o && o->type == OBJ_TAG) {
563 struct tag *t = (struct tag *) o;
564 if (!t->tagged)
565 break; /* broken repository */
566 o->flags |= COMPLETE;
567 - o = parse_object(t->tagged->oid.hash);
567 + o = parse_object(&t->tagged->oid);
568 }
569 if (o && o->type == OBJ_COMMIT) {
570 struct commit *commit = (struct commit *)o;
@@ -681,7 +681,7 @@ static int everything_local(struct fetch_pack_args *args,
681 if (!has_object_file(&ref->old_oid))
682 continue;
683
684 - o = parse_object(ref->old_oid.hash);
684 + o = parse_object(&ref->old_oid);
685 if (!o)
686 continue;
687
fsck.c
+1 -1
@@ -461,7 +461,7 @@ int fsck_walk(struct object *obj, void *data, struct fsck_options *options)
461 return -1;
462
463 if (obj->type == OBJ_NONE)
464 - parse_object(obj->oid.hash);
464 + parse_object(&obj->oid);
465
466 switch (obj->type) {
467 case OBJ_BLOB:
http-backend.c
+1 -1
@@ -431,7 +431,7 @@ static int show_text_ref(const char *name, const struct object_id *oid,
431 {
432 const char *name_nons = strip_namespace(name);
433 struct strbuf *buf = cb_data;
434 - struct object *o = parse_object(oid->hash);
434 + struct object *o = parse_object(oid);
435 if (!o)
436 return 0;
437
http-push.c
+2 -2
@@ -724,7 +724,7 @@ static void one_remote_object(const struct object_id *oid)
724
725 obj = lookup_object(oid->hash);
726 if (!obj)
727 - obj = parse_object(oid->hash);
727 + obj = parse_object(oid);
728
729 /* Ignore remote objects that don't exist locally */
730 if (!obj)
@@ -1462,7 +1462,7 @@ static void add_remote_info_ref(struct remote_ls_ctx *ls)
1462 return;
1463 }
1464
1465 - o = parse_object(ref->old_oid.hash);
1465 + o = parse_object(&ref->old_oid);
1466 if (!o) {
1467 fprintf(stderr,
1468 "Unable to parse object %s for remote ref %s\n",
log-tree.c
+3 -3
@@ -105,13 +105,13 @@ static int add_ref_decoration(const char *refname, const struct object_id *oid,
105 warning("invalid replace ref %s", refname);
106 return 0;
107 }
108 - obj = parse_object(original_oid.hash);
108 + obj = parse_object(&original_oid);
109 if (obj)
110 add_name_decoration(DECORATION_GRAFTED, "replaced", obj);
111 return 0;
112 }
113
114 - obj = parse_object(oid->hash);
114 + obj = parse_object(oid);
115 if (!obj)
116 return 0;
117
@@ -132,7 +132,7 @@ static int add_ref_decoration(const char *refname, const struct object_id *oid,
132 if (!obj)
133 break;
134 if (!obj->parsed)
135 - parse_object(obj->oid.hash);
135 + parse_object(&obj->oid);
136 add_name_decoration(DECORATION_REF_TAG, refname, obj);
137 }
138 return 0;
merge-recursive.c
+1 -1
@@ -2103,7 +2103,7 @@ static struct commit *get_ref(const struct object_id *oid, const char *name)
2103 {
2104 struct object *object;
2105
2106 - object = deref_tag(parse_object(oid->hash), name, strlen(name));
2106 + object = deref_tag(parse_object(oid), name, strlen(name));
2107 if (!object)
2108 return NULL;
2109 if (object->type == OBJ_TREE)
object.c
+19 -25
@@ -180,24 +180,21 @@ struct object *lookup_unknown_object(const unsigned char *sha1)
180 return obj;
181 }
182
183 -struct object *parse_object_buffer(const unsigned char *sha1, enum object_type type, unsigned long size, void *buffer, int *eaten_p)
183 +struct object *parse_object_buffer(const struct object_id *oid, enum object_type type, unsigned long size, void *buffer, int *eaten_p)
184 {
185 - struct object_id oid;
185 struct object *obj;
186 *eaten_p = 0;
187
189 - hashcpy(oid.hash, sha1);
190 -
188 obj = NULL;
189 if (type == OBJ_BLOB) {
193 - struct blob *blob = lookup_blob(&oid);
190 + struct blob *blob = lookup_blob(oid);
191 if (blob) {
192 if (parse_blob_buffer(blob, buffer, size))
193 return NULL;
194 obj = &blob->object;
195 }
196 } else if (type == OBJ_TREE) {
200 - struct tree *tree = lookup_tree(&oid);
197 + struct tree *tree = lookup_tree(oid);
198 if (tree) {
199 obj = &tree->object;
200 if (!tree->buffer)
@@ -209,7 +206,7 @@ struct object *parse_object_buffer(const unsigned char *sha1, enum object_type t
206 }
207 }
208 } else if (type == OBJ_COMMIT) {
212 - struct commit *commit = lookup_commit(&oid);
209 + struct commit *commit = lookup_commit(oid);
210 if (commit) {
211 if (parse_commit_buffer(commit, buffer, size))
212 return NULL;
@@ -220,57 +217,54 @@ struct object *parse_object_buffer(const unsigned char *sha1, enum object_type t
217 obj = &commit->object;
218 }
219 } else if (type == OBJ_TAG) {
223 - struct tag *tag = lookup_tag(&oid);
220 + struct tag *tag = lookup_tag(oid);
221 if (tag) {
222 if (parse_tag_buffer(tag, buffer, size))
223 return NULL;
224 obj = &tag->object;
225 }
226 } else {
230 - warning("object %s has unknown type id %d", sha1_to_hex(sha1), type);
227 + warning("object %s has unknown type id %d", oid_to_hex(oid), type);
228 obj = NULL;
229 }
230 return obj;
231 }
232
236 -struct object *parse_object_or_die(const unsigned char *sha1,
233 +struct object *parse_object_or_die(const struct object_id *oid,
234 const char *name)
235 {
239 - struct object *o = parse_object(sha1);
236 + struct object *o = parse_object(oid);
237 if (o)
238 return o;
239
243 - die(_("unable to parse object: %s"), name ? name : sha1_to_hex(sha1));
240 + die(_("unable to parse object: %s"), name ? name : oid_to_hex(oid));
241 }
242
246 -struct object *parse_object(const unsigned char *sha1)
243 +struct object *parse_object(const struct object_id *oid)
244 {
245 unsigned long size;
246 enum object_type type;
247 int eaten;
251 - const unsigned char *repl = lookup_replace_object(sha1);
248 + const unsigned char *repl = lookup_replace_object(oid->hash);
249 void *buffer;
250 struct object *obj;
254 - struct object_id oid;
255 -
256 - hashcpy(oid.hash, sha1);
251
258 - obj = lookup_object(oid.hash);
252 + obj = lookup_object(oid->hash);
253 if (obj && obj->parsed)
254 return obj;
255
256 if ((obj && obj->type == OBJ_BLOB) ||
263 - (!obj && has_sha1_file(sha1) &&
264 - sha1_object_info(sha1, NULL) == OBJ_BLOB)) {
257 + (!obj && has_object_file(oid) &&
258 + sha1_object_info(oid->hash, NULL) == OBJ_BLOB)) {
259 if (check_sha1_signature(repl, NULL, 0, NULL) < 0) {
266 - error("sha1 mismatch %s", sha1_to_hex(repl));
260 + error("sha1 mismatch %s", oid_to_hex(oid));
261 return NULL;
262 }
269 - parse_blob_buffer(lookup_blob(&oid), NULL, 0);
270 - return lookup_object(sha1);
263 + parse_blob_buffer(lookup_blob(oid), NULL, 0);
264 + return lookup_object(oid->hash);
265 }
266
273 - buffer = read_sha1_file(sha1, &type, &size);
267 + buffer = read_sha1_file(oid->hash, &type, &size);
268 if (buffer) {
269 if (check_sha1_signature(repl, buffer, size, typename(type)) < 0) {
270 free(buffer);
@@ -278,7 +272,7 @@ struct object *parse_object(const unsigned char *sha1)
272 return NULL;
273 }
274
281 - obj = parse_object_buffer(sha1, type, size, buffer, &eaten);
275 + obj = parse_object_buffer(oid, type, size, buffer, &eaten);
276 if (!eaten)
277 free(buffer);
278 return obj;
object.h
+4 -4
@@ -89,20 +89,20 @@ void *object_as_type(struct object *obj, enum object_type type, int quiet);
89 *
90 * Returns NULL if the object is missing or corrupt.
91 */
92 -struct object *parse_object(const unsigned char *sha1);
92 +struct object *parse_object(const struct object_id *oid);
93
94 /*
95 * Like parse_object, but will die() instead of returning NULL. If the
96 * "name" parameter is not NULL, it is included in the error message
97 - * (otherwise, the sha1 hex is given).
97 + * (otherwise, the hex object ID is given).
98 */
99 -struct object *parse_object_or_die(const unsigned char *sha1, const char *name);
99 +struct object *parse_object_or_die(const struct object_id *oid, const char *name);
100
101 /* Given the result of read_sha1_file(), returns the object after
102 * parsing it. eaten_p indicates if the object has a borrowed copy
103 * of buffer and the caller should not free() it.
104 */
105 -struct object *parse_object_buffer(const unsigned char *sha1, enum object_type type, unsigned long size, void *buffer, int *eaten_p);
105 +struct object *parse_object_buffer(const struct object_id *oid, enum object_type type, unsigned long size, void *buffer, int *eaten_p);
106
107 /** Returns the object, with potentially excess memory allocated. **/
108 struct object *lookup_unknown_object(const unsigned char *sha1);
pack-bitmap.c
+2 -2
@@ -673,7 +673,7 @@ int prepare_bitmap_walk(struct rev_info *revs)
673 struct object *object = pending_e[i].item;
674
675 if (object->type == OBJ_NONE)
676 - parse_object_or_die(object->oid.hash, NULL);
676 + parse_object_or_die(&object->oid, NULL);
677
678 while (object->type == OBJ_TAG) {
679 struct tag *tag = (struct tag *) object;
@@ -685,7 +685,7 @@ int prepare_bitmap_walk(struct rev_info *revs)
685
686 if (!tag->tagged)
687 die("bad tag");
688 - object = parse_object_or_die(tag->tagged->oid.hash, NULL);
688 + object = parse_object_or_die(&tag->tagged->oid, NULL);
689 }
690
691 if (object->flags & UNINTERESTING)
pretty.c
+1 -1
@@ -1137,7 +1137,7 @@ static size_t format_commit_one(struct strbuf *sb, /* in UTF-8 */
1137
1138 /* these depend on the commit */
1139 if (!commit->object.parsed)
1140 - parse_object(commit->object.oid.hash);
1140 + parse_object(&commit->object.oid);
1141
1142 switch (placeholder[0]) {
1143 case 'H': /* commit hash */
reachable.c
+2 -2
@@ -33,7 +33,7 @@ static int add_one_ref(const char *path, const struct object_id *oid,
33 return 0;
34 }
35
36 - object = parse_object_or_die(oid->hash, path);
36 + object = parse_object_or_die(oid, path);
37 add_pending_object(revs, object, "");
38
39 return 0;
@@ -82,7 +82,7 @@ static void add_recent_object(const struct object_id *oid,
82 switch (type) {
83 case OBJ_TAG:
84 case OBJ_COMMIT:
85 - obj = parse_object_or_die(oid->hash, NULL);
85 + obj = parse_object_or_die(oid, NULL);
86 break;
87 case OBJ_TREE:
88 obj = (struct object *)lookup_tree(oid);
ref-filter.c
+2 -2
@@ -683,7 +683,7 @@ static void *get_obj(const struct object_id *oid, struct object **obj, unsigned
683 void *buf = read_sha1_file(oid->hash, &type, sz);
684
685 if (buf)
686 - *obj = parse_object_buffer(oid->hash, type, *sz, buf, eaten);
686 + *obj = parse_object_buffer(oid, type, *sz, buf, eaten);
687 else
688 *obj = NULL;
689 return buf;
@@ -1687,7 +1687,7 @@ static const struct object_id *match_points_at(struct oid_array *points_at,
1687
1688 if (oid_array_lookup(points_at, oid) >= 0)
1689 return oid;
1690 - obj = parse_object(oid->hash);
1690 + obj = parse_object(oid);
1691 if (!obj)
1692 die(_("malformed object at '%s'"), refname);
1693 if (obj->type == OBJ_TAG)
reflog-walk.c
+2 -2
@@ -238,13 +238,13 @@ void fake_reflog_parent(struct reflog_walk_info *info, struct commit *commit)
238 do {
239 reflog = &commit_reflog->reflogs->items[commit_reflog->recno];
240 commit_reflog->recno--;
241 - logobj = parse_object(reflog->ooid.hash);
241 + logobj = parse_object(&reflog->ooid);
242 } while (commit_reflog->recno && (logobj && logobj->type != OBJ_COMMIT));
243
244 if (!logobj && commit_reflog->recno >= 0 && is_null_oid(&reflog->ooid)) {
245 /* a root commit, but there are still more entries to show */
246 reflog = &commit_reflog->reflogs->items[commit_reflog->recno];
247 - logobj = parse_object(reflog->noid.hash);
247 + logobj = parse_object(&reflog->noid);
248 }
249
250 if (!logobj || logobj->type != OBJ_COMMIT) {
refs/files-backend.c
+1 -1
@@ -2057,7 +2057,7 @@ static int write_ref_to_lockfile(struct ref_lock *lock,
2057 struct object *o;
2058 int fd;
2059
2060 - o = parse_object(oid->hash);
2060 + o = parse_object(oid);
2061 if (!o) {
2062 strbuf_addf(err,
2063 "trying to write ref '%s' with nonexistent object %s",
remote.c
+2 -2
@@ -1954,12 +1954,12 @@ int ref_newer(const struct object_id *new_oid, const struct object_id *old_oid)
1954 * Both new and old must be commit-ish and new is descendant of
1955 * old. Otherwise we require --force.
1956 */
1957 - o = deref_tag(parse_object(old_oid->hash), NULL, 0);
1957 + o = deref_tag(parse_object(old_oid), NULL, 0);
1958 if (!o || o->type != OBJ_COMMIT)
1959 return 0;
1960 old = (struct commit *) o;
1961
1962 - o = deref_tag(parse_object(new_oid->hash), NULL, 0);
1962 + o = deref_tag(parse_object(new_oid), NULL, 0);
1963 if (!o || o->type != OBJ_COMMIT)
1964 return 0;
1965 new = (struct commit *) o;
revision.c
+6 -6
@@ -181,7 +181,7 @@ void add_head_to_pending(struct rev_info *revs)
181 struct object *obj;
182 if (get_oid("HEAD", &oid))
183 return;
184 - obj = parse_object(oid.hash);
184 + obj = parse_object(&oid);
185 if (!obj)
186 return;
187 add_pending_object(revs, obj, "HEAD");
@@ -193,7 +193,7 @@ static struct object *get_reference(struct rev_info *revs, const char *name,
193 {
194 struct object *object;
195
196 - object = parse_object(oid->hash);
196 + object = parse_object(oid);
197 if (!object) {
198 if (revs->ignore_missing)
199 return object;
@@ -228,7 +228,7 @@ static struct commit *handle_commit(struct rev_info *revs,
228 add_pending_object(revs, object, tag->tag);
229 if (!tag->tagged)
230 die("bad tag");
231 - object = parse_object(tag->tagged->oid.hash);
231 + object = parse_object(&tag->tagged->oid);
232 if (!object) {
233 if (flags & UNINTERESTING)
234 return NULL;
@@ -1200,7 +1200,7 @@ static void handle_one_reflog_commit(struct object_id *oid, void *cb_data)
1200 {
1201 struct all_refs_cb *cb = cb_data;
1202 if (!is_null_oid(oid)) {
1203 - struct object *o = parse_object(oid->hash);
1203 + struct object *o = parse_object(oid);
1204 if (o) {
1205 o->flags |= cb->all_flags;
1206 /* ??? CMDLINEFLAGS ??? */
@@ -1479,8 +1479,8 @@ int handle_revision_arg(const char *arg_, struct rev_info *revs, int flags, unsi
1479 verify_non_filename(revs->prefix, arg);
1480 }
1481
1482 - a_obj = parse_object(from_oid.hash);
1483 - b_obj = parse_object(oid.hash);
1482 + a_obj = parse_object(&from_oid);
1483 + b_obj = parse_object(&oid);
1484 if (!a_obj || !b_obj) {
1485 missing:
1486 if (revs->ignore_missing)
server-info.c
+1 -1
@@ -53,7 +53,7 @@ static int add_info_ref(const char *path, const struct object_id *oid,
53 int flag, void *cb_data)
54 {
55 FILE *fp = cb_data;
56 - struct object *o = parse_object(oid->hash);
56 + struct object *o = parse_object(oid);
57 if (!o)
58 return -1;
59
sha1_name.c
+7 -7
@@ -241,7 +241,7 @@ static int disambiguate_committish_only(const struct object_id *oid, void *cb_da
241 return 0;
242
243 /* We need to do this the hard way... */
244 - obj = deref_tag(parse_object(oid->hash), NULL, 0);
244 + obj = deref_tag(parse_object(oid), NULL, 0);
245 if (obj && obj->type == OBJ_COMMIT)
246 return 1;
247 return 0;
@@ -265,7 +265,7 @@ static int disambiguate_treeish_only(const struct object_id *oid, void *cb_data_
265 return 0;
266
267 /* We need to do this the hard way... */
268 - obj = deref_tag(parse_object(oid->hash), NULL, 0);
268 + obj = deref_tag(parse_object(oid), NULL, 0);
269 if (obj && (obj->type == OBJ_TREE || obj->type == OBJ_COMMIT))
270 return 1;
271 return 0;
@@ -776,7 +776,7 @@ struct object *peel_to_type(const char *name, int namelen,
776 if (name && !namelen)
777 namelen = strlen(name);
778 while (1) {
779 - if (!o || (!o->parsed && !parse_object(o->oid.hash)))
779 + if (!o || (!o->parsed && !parse_object(&o->oid)))
780 return NULL;
781 if (expected_type == OBJ_ANY || o->type == expected_type)
782 return o;
@@ -849,12 +849,12 @@ static int peel_onion(const char *name, int len, unsigned char *sha1,
849 if (get_sha1_1(name, sp - name - 2, outer.hash, lookup_flags))
850 return -1;
851
852 - o = parse_object(outer.hash);
852 + o = parse_object(&outer);
853 if (!o)
854 return -1;
855 if (!expected_type) {
856 o = deref_tag(o, name, sp - name - 2);
857 - if (!o || (!o->parsed && !parse_object(o->oid.hash)))
857 + if (!o || (!o->parsed && !parse_object(&o->oid)))
858 return -1;
859 hashcpy(sha1, o->oid.hash);
860 return 0;
@@ -981,7 +981,7 @@ static int handle_one_ref(const char *path, const struct object_id *oid,
981 int flag, void *cb_data)
982 {
983 struct commit_list **list = cb_data;
984 - struct object *object = parse_object(oid->hash);
984 + struct object *object = parse_object(oid);
985 if (!object)
986 return 0;
987 if (object->type == OBJ_TAG) {
@@ -1027,7 +1027,7 @@ static int get_sha1_oneline(const char *prefix, unsigned char *sha1,
1027 int matches;
1028
1029 commit = pop_most_recent_commit(&list, ONELINE_SEEN);
1030 - if (!parse_object(commit->object.oid.hash))
1030 + if (!parse_object(&commit->object.oid))
1031 continue;
1032 buf = get_commit_buffer(commit, NULL);
1033 p = strstr(buf, "\n\n");
tag.c
+2 -2
@@ -66,7 +66,7 @@ struct object *deref_tag(struct object *o, const char *warn, int warnlen)
66 {
67 while (o && o->type == OBJ_TAG)
68 if (((struct tag *)o)->tagged)
69 - o = parse_object(((struct tag *)o)->tagged->oid.hash);
69 + o = parse_object(&((struct tag *)o)->tagged->oid);
70 else
71 o = NULL;
72 if (!o && warn) {
@@ -80,7 +80,7 @@ struct object *deref_tag(struct object *o, const char *warn, int warnlen)
80 struct object *deref_tag_noverify(struct object *o)
81 {
82 while (o && o->type == OBJ_TAG) {
83 - o = parse_object(o->oid.hash);
83 + o = parse_object(&o->oid);
84 if (o && o->type == OBJ_TAG && ((struct tag *)o)->tagged)
85 o = ((struct tag *)o)->tagged;
86 else
tree.c
+2 -2
@@ -234,7 +234,7 @@ void free_tree_buffer(struct tree *tree)
234
235 struct tree *parse_tree_indirect(const struct object_id *oid)
236 {
237 - struct object *obj = parse_object(oid->hash);
237 + struct object *obj = parse_object(oid);
238 do {
239 if (!obj)
240 return NULL;
@@ -247,6 +247,6 @@ struct tree *parse_tree_indirect(const struct object_id *oid)
247 else
248 return NULL;
249 if (!obj->parsed)
250 - parse_object(obj->oid.hash);
250 + parse_object(&obj->oid);
251 } while (1);
252 }
upload-pack.c
+4 -4
@@ -296,7 +296,7 @@ static int got_oid(const char *hex, struct object_id *oid)
296 if (!has_object_file(oid))
297 return -1;
298
299 - o = parse_object(oid->hash);
299 + o = parse_object(oid);
300 if (!o)
301 die("oops (%s)", oid_to_hex(oid));
302 if (o->type == OBJ_COMMIT) {
@@ -334,7 +334,7 @@ static int reachable(struct commit *want)
334 break;
335 }
336 if (!commit->object.parsed)
337 - parse_object(commit->object.oid.hash);
337 + parse_object(&commit->object.oid);
338 if (commit->object.flags & REACHABLE)
339 continue;
340 commit->object.flags |= REACHABLE;
@@ -755,7 +755,7 @@ static void receive_needs(void)
755 struct object *object;
756 if (get_oid_hex(arg, &oid))
757 die("invalid shallow line: %s", line);
758 - object = parse_object(oid.hash);
758 + object = parse_object(&oid);
759 if (!object)
760 continue;
761 if (object->type != OBJ_COMMIT)
@@ -821,7 +821,7 @@ static void receive_needs(void)
821 if (parse_feature_request(features, "include-tag"))
822 use_include_tag = 1;
823
824 - o = parse_object(oid_buf.hash);
824 + o = parse_object(&oid_buf);
825 if (!o) {
826 packet_write_fmt(1,
827 "ERR upload-pack: not our ref %s",
walker.c
+1 -1
@@ -180,7 +180,7 @@ static int loop(struct walker *walker)
180 }
181 }
182 if (!obj->type)
183 - parse_object(obj->oid.hash);
183 + parse_object(&obj->oid);
184 if (process_object(walker, obj))
185 return -1;
186 }