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>
This commit is contained in:
brian m. carlson
2017-05-06 22:10:38 +00:00
committed by Junio C Hamano
parent a9dbc17910
commit c251c83df2
38 changed files with 107 additions and 108 deletions

View File

@@ -67,7 +67,7 @@ static int diff_tree_stdin(char *line)
line[len-1] = 0; line[len-1] = 0;
if (parse_oid_hex(line, &oid, &p)) if (parse_oid_hex(line, &oid, &p))
return -1; return -1;
obj = parse_object(oid.hash); obj = parse_object(&oid);
if (!obj) if (!obj)
return -1; return -1;
if (obj->type == OBJ_COMMIT) if (obj->type == OBJ_COMMIT)

View File

@@ -395,7 +395,7 @@ int cmd_diff(int argc, const char **argv, const char *prefix)
const char *name = entry->name; const char *name = entry->name;
int flags = (obj->flags & UNINTERESTING); int flags = (obj->flags & UNINTERESTING);
if (!obj->parsed) if (!obj->parsed)
obj = parse_object(obj->oid.hash); obj = parse_object(&obj->oid);
obj = deref_tag(obj, NULL, 0); obj = deref_tag(obj, NULL, 0);
if (!obj) if (!obj)
die(_("invalid object '%s' given."), name); die(_("invalid object '%s' given."), name);

View File

@@ -240,7 +240,7 @@ static void export_blob(const struct object_id *oid)
die ("Could not read blob %s", oid_to_hex(oid)); die ("Could not read blob %s", oid_to_hex(oid));
if (check_sha1_signature(oid->hash, buf, size, typename(type)) < 0) if (check_sha1_signature(oid->hash, buf, size, typename(type)) < 0)
die("sha1 mismatch in blob %s", oid_to_hex(oid)); die("sha1 mismatch in blob %s", oid_to_hex(oid));
object = parse_object_buffer(oid->hash, type, size, buf, &eaten); object = parse_object_buffer(oid, type, size, buf, &eaten);
} }
if (!object) if (!object)
@@ -777,7 +777,7 @@ static struct commit *get_commit(struct rev_cmdline_entry *e, char *full_name)
/* handle nested tags */ /* handle nested tags */
while (tag && tag->object.type == OBJ_TAG) { while (tag && tag->object.type == OBJ_TAG) {
parse_object(tag->object.oid.hash); parse_object(&tag->object.oid);
string_list_append(&extra_refs, full_name)->util = tag; string_list_append(&extra_refs, full_name)->util = tag;
tag = (struct tag *)tag->tagged; tag = (struct tag *)tag->tagged;
} }

View File

@@ -341,7 +341,7 @@ static void shortlog(const char *name,
const struct object_id *oid = &origin_data->oid; const struct object_id *oid = &origin_data->oid;
int limit = opts->shortlog_len; int limit = opts->shortlog_len;
branch = deref_tag(parse_object(oid->hash), oid_to_hex(oid), GIT_SHA1_HEXSZ); branch = deref_tag(parse_object(oid), oid_to_hex(oid), GIT_SHA1_HEXSZ);
if (!branch || branch->type != OBJ_COMMIT) if (!branch || branch->type != OBJ_COMMIT)
return; return;
@@ -559,7 +559,7 @@ static void find_merge_parents(struct merge_parents *result,
* "name" here and we do not want to contaminate its * "name" here and we do not want to contaminate its
* util field yet. * util field yet.
*/ */
obj = parse_object(oid.hash); obj = parse_object(&oid);
parent = (struct commit *)peel_to_type(NULL, 0, obj, OBJ_COMMIT); parent = (struct commit *)peel_to_type(NULL, 0, obj, OBJ_COMMIT);
if (!parent) if (!parent)
continue; continue;

View File

@@ -385,7 +385,7 @@ static int fsck_obj_buffer(const struct object_id *oid, enum object_type type,
* verify_packfile(), data_valid variable for details. * verify_packfile(), data_valid variable for details.
*/ */
struct object *obj; struct object *obj;
obj = parse_object_buffer(oid->hash, type, size, buffer, eaten); obj = parse_object_buffer(oid, type, size, buffer, eaten);
if (!obj) { if (!obj) {
errors_found |= ERROR_OBJECT; errors_found |= ERROR_OBJECT;
return error("%s: object corrupt or missing", oid_to_hex(oid)); 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,
{ {
struct object *obj; struct object *obj;
obj = parse_object(oid->hash); obj = parse_object(oid);
if (!obj) { if (!obj) {
error("%s: invalid sha1 pointer %s", refname, oid_to_hex(oid)); error("%s: invalid sha1 pointer %s", refname, oid_to_hex(oid));
errors_found |= ERROR_REACHABLE; errors_found |= ERROR_REACHABLE;
@@ -506,7 +506,7 @@ static struct object *parse_loose_object(const struct object_id *oid,
if (!contents && type != OBJ_BLOB) if (!contents && type != OBJ_BLOB)
die("BUG: read_loose_object streamed a non-blob"); die("BUG: read_loose_object streamed a non-blob");
obj = parse_object_buffer(oid->hash, type, size, contents, &eaten); obj = parse_object_buffer(oid, type, size, contents, &eaten);
if (!eaten) if (!eaten)
free(contents); free(contents);
@@ -599,7 +599,7 @@ static int fsck_cache_tree(struct cache_tree *it)
fprintf(stderr, "Checking cache tree\n"); fprintf(stderr, "Checking cache tree\n");
if (0 <= it->entry_count) { if (0 <= it->entry_count) {
struct object *obj = parse_object(it->oid.hash); struct object *obj = parse_object(&it->oid);
if (!obj) { if (!obj) {
error("%s: invalid sha1 pointer in cache-tree", error("%s: invalid sha1 pointer in cache-tree",
oid_to_hex(&it->oid)); oid_to_hex(&it->oid));

View File

@@ -1196,7 +1196,7 @@ int cmd_grep(int argc, const char **argv, const char *prefix)
break; break;
} }
object = parse_object_or_die(oid.hash, arg); object = parse_object_or_die(&oid, arg);
if (!seen_dashdash) if (!seen_dashdash)
verify_non_filename(prefix, arg); verify_non_filename(prefix, arg);
add_object_array_with_path(object, arg, &list, oc.mode, oc.path); add_object_array_with_path(object, arg, &list, oc.mode, oc.path);

View File

@@ -845,7 +845,8 @@ static void sha1_object(const void *data, struct object_entry *obj_entry,
* we do not need to free the memory here, as the * we do not need to free the memory here, as the
* buf is deleted by the caller. * buf is deleted by the caller.
*/ */
obj = parse_object_buffer(oid->hash, type, size, buf, &eaten); obj = parse_object_buffer(oid, type, size, buf,
&eaten);
if (!obj) if (!obj)
die(_("invalid %s"), typename(type)); die(_("invalid %s"), typename(type));
if (do_fsck_object && if (do_fsck_object &&

View File

@@ -596,7 +596,7 @@ int cmd_show(int argc, const char **argv, const char *prefix)
rev.shown_one = 1; rev.shown_one = 1;
if (ret) if (ret)
break; break;
o = parse_object(t->tagged->oid.hash); o = parse_object(&t->tagged->oid);
if (!o) if (!o)
ret = error(_("Could not read object %s"), ret = error(_("Could not read object %s"),
oid_to_hex(&t->tagged->oid)); oid_to_hex(&t->tagged->oid));

View File

@@ -142,7 +142,7 @@ static int tipcmp(const void *a_, const void *b_)
static int name_ref(const char *path, const struct object_id *oid, int flags, void *cb_data) static int name_ref(const char *path, const struct object_id *oid, int flags, void *cb_data)
{ {
struct object *o = parse_object(oid->hash); struct object *o = parse_object(oid);
struct name_ref_data *data = cb_data; struct name_ref_data *data = cb_data;
int can_abbreviate_output = data->tags_only && data->name_only; int can_abbreviate_output = data->tags_only && data->name_only;
int deref = 0; int deref = 0;
@@ -200,7 +200,7 @@ static int name_ref(const char *path, const struct object_id *oid, int flags, vo
struct tag *t = (struct tag *) o; struct tag *t = (struct tag *) o;
if (!t->tagged) if (!t->tagged)
break; /* broken repository */ break; /* broken repository */
o = parse_object(t->tagged->oid.hash); o = parse_object(&t->tagged->oid);
deref = 1; deref = 1;
taggerdate = t->date; taggerdate = t->date;
} }
@@ -385,7 +385,7 @@ int cmd_name_rev(int argc, const char **argv, const char *prefix)
} }
commit = NULL; commit = NULL;
object = parse_object(oid.hash); object = parse_object(&oid);
if (object) { if (object) {
struct object *peeled = deref_tag(object, *argv, 0); struct object *peeled = deref_tag(object, *argv, 0);
if (peeled && peeled->type == OBJ_COMMIT) if (peeled && peeled->type == OBJ_COMMIT)

View File

@@ -127,7 +127,8 @@ int cmd_prune(int argc, const char **argv, const char *prefix)
const char *name = *argv++; const char *name = *argv++;
if (!get_oid(name, &oid)) { if (!get_oid(name, &oid)) {
struct object *object = parse_object_or_die(oid.hash, name); struct object *object = parse_object_or_die(&oid,
name);
add_pending_object(&revs, object, ""); add_pending_object(&revs, object, "");
} }
else else

View File

@@ -1058,8 +1058,8 @@ static const char *update(struct command *cmd, struct shallow_info *si)
struct object *old_object, *new_object; struct object *old_object, *new_object;
struct commit *old_commit, *new_commit; struct commit *old_commit, *new_commit;
old_object = parse_object(old_oid->hash); old_object = parse_object(old_oid);
new_object = parse_object(new_oid->hash); new_object = parse_object(new_oid);
if (!old_object || !new_object || if (!old_object || !new_object ||
old_object->type != OBJ_COMMIT || old_object->type != OBJ_COMMIT ||
@@ -1082,7 +1082,7 @@ static const char *update(struct command *cmd, struct shallow_info *si)
if (is_null_oid(new_oid)) { if (is_null_oid(new_oid)) {
struct strbuf err = STRBUF_INIT; struct strbuf err = STRBUF_INIT;
if (!parse_object(old_oid->hash)) { if (!parse_object(old_oid)) {
old_oid = NULL; old_oid = NULL;
if (ref_exists(name)) { if (ref_exists(name)) {
rp_warning("Allowing deletion of corrupt ref."); rp_warning("Allowing deletion of corrupt ref.");

View File

@@ -126,7 +126,7 @@ static int commit_is_complete(struct commit *commit)
struct commit_list *parent; struct commit_list *parent;
c = (struct commit *)study.objects[--study.nr].item; c = (struct commit *)study.objects[--study.nr].item;
if (!c->object.parsed && !parse_object(c->object.oid.hash)) if (!c->object.parsed && !parse_object(&c->object.oid))
c->object.flags |= INCOMPLETE; c->object.flags |= INCOMPLETE;
if (c->object.flags & INCOMPLETE) { if (c->object.flags & INCOMPLETE) {

View File

@@ -181,7 +181,7 @@ static void finish_object(struct object *obj, const char *name, void *cb_data)
if (obj->type == OBJ_BLOB && !has_object_file(&obj->oid)) if (obj->type == OBJ_BLOB && !has_object_file(&obj->oid))
die("missing blob object '%s'", oid_to_hex(&obj->oid)); die("missing blob object '%s'", oid_to_hex(&obj->oid));
if (info->revs->verify_objects && !obj->parsed && obj->type != OBJ_COMMIT) if (info->revs->verify_objects && !obj->parsed && obj->type != OBJ_COMMIT)
parse_object(obj->oid.hash); parse_object(&obj->oid);
} }
static void show_object(struct object *obj, const char *name, void *cb_data) static void show_object(struct object *obj, const char *name, void *cb_data)

View File

@@ -260,7 +260,8 @@ static void write_object(unsigned nr, enum object_type type,
int eaten; int eaten;
hash_sha1_file(buf, size, typename(type), obj_list[nr].oid.hash); hash_sha1_file(buf, size, typename(type), obj_list[nr].oid.hash);
added_object(nr, type, buf, size); added_object(nr, type, buf, size);
obj = parse_object_buffer(obj_list[nr].oid.hash, type, size, buf, &eaten); obj = parse_object_buffer(&obj_list[nr].oid, type, size, buf,
&eaten);
if (!obj) if (!obj)
die("invalid %s", typename(type)); die("invalid %s", typename(type));
add_object_buffer(obj, buf, size); add_object_buffer(obj, buf, size);

View File

@@ -142,7 +142,7 @@ int verify_bundle(struct bundle_header *header, int verbose)
init_revisions(&revs, NULL); init_revisions(&revs, NULL);
for (i = 0; i < p->nr; i++) { for (i = 0; i < p->nr; i++) {
struct ref_list_entry *e = p->list + i; struct ref_list_entry *e = p->list + i;
struct object *o = parse_object(e->oid.hash); struct object *o = parse_object(&e->oid);
if (o) { if (o) {
o->flags |= PREREQ_MARK; o->flags |= PREREQ_MARK;
add_pending_object(&revs, o, e->name); add_pending_object(&revs, o, e->name);
@@ -290,12 +290,14 @@ static int compute_and_write_prerequisites(int bundle_fd,
if (buf.len > 0 && buf.buf[0] == '-') { if (buf.len > 0 && buf.buf[0] == '-') {
write_or_die(bundle_fd, buf.buf, buf.len); write_or_die(bundle_fd, buf.buf, buf.len);
if (!get_oid_hex(buf.buf + 1, &oid)) { if (!get_oid_hex(buf.buf + 1, &oid)) {
struct object *object = parse_object_or_die(oid.hash, buf.buf); struct object *object = parse_object_or_die(&oid,
buf.buf);
object->flags |= UNINTERESTING; object->flags |= UNINTERESTING;
add_pending_object(revs, object, buf.buf); add_pending_object(revs, object, buf.buf);
} }
} else if (!get_oid_hex(buf.buf, &oid)) { } else if (!get_oid_hex(buf.buf, &oid)) {
struct object *object = parse_object_or_die(oid.hash, buf.buf); struct object *object = parse_object_or_die(&oid,
buf.buf);
object->flags |= SHOWN; object->flags |= SHOWN;
} }
} }
@@ -379,7 +381,7 @@ static int write_bundle_refs(int bundle_fd, struct rev_info *revs)
* end up triggering "empty bundle" * end up triggering "empty bundle"
* error. * error.
*/ */
obj = parse_object_or_die(oid.hash, e->name); obj = parse_object_or_die(&oid, e->name);
obj->flags |= SHOWN; obj->flags |= SHOWN;
add_pending_object(revs, obj, e->name); add_pending_object(revs, obj, e->name);
} }

View File

@@ -21,7 +21,7 @@ const char *commit_type = "commit";
struct commit *lookup_commit_reference_gently(const struct object_id *oid, struct commit *lookup_commit_reference_gently(const struct object_id *oid,
int quiet) int quiet)
{ {
struct object *obj = deref_tag(parse_object(oid->hash), NULL, 0); struct object *obj = deref_tag(parse_object(oid), NULL, 0);
if (!obj) if (!obj)
return NULL; return NULL;
@@ -1589,7 +1589,7 @@ struct commit *get_merge_parent(const char *name)
struct object_id oid; struct object_id oid;
if (get_sha1(name, oid.hash)) if (get_sha1(name, oid.hash))
return NULL; return NULL;
obj = parse_object(oid.hash); obj = parse_object(&oid);
commit = (struct commit *)peel_to_type(name, 0, obj, OBJ_COMMIT); commit = (struct commit *)peel_to_type(name, 0, obj, OBJ_COMMIT);
if (commit && !commit->util) if (commit && !commit->util)
set_merge_remote_desc(commit, name, obj); set_merge_remote_desc(commit, name, obj);

View File

@@ -78,7 +78,7 @@ static void cache_one_alternate(const char *refname,
void *vcache) void *vcache)
{ {
struct alternate_object_cache *cache = vcache; struct alternate_object_cache *cache = vcache;
struct object *obj = parse_object(oid->hash); struct object *obj = parse_object(oid);
if (!obj || (obj->flags & ALTERNATE)) if (!obj || (obj->flags & ALTERNATE))
return; return;
@@ -120,7 +120,7 @@ static void rev_list_push(struct commit *commit, int mark)
static int rev_list_insert_ref(const char *refname, const struct object_id *oid) static int rev_list_insert_ref(const char *refname, const struct object_id *oid)
{ {
struct object *o = deref_tag(parse_object(oid->hash), refname, 0); struct object *o = deref_tag(parse_object(oid), refname, 0);
if (o && o->type == OBJ_COMMIT) if (o && o->type == OBJ_COMMIT)
rev_list_push((struct commit *)o, SEEN); 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 *
static int clear_marks(const char *refname, const struct object_id *oid, static int clear_marks(const char *refname, const struct object_id *oid,
int flag, void *cb_data) int flag, void *cb_data)
{ {
struct object *o = deref_tag(parse_object(oid->hash), refname, 0); struct object *o = deref_tag(parse_object(oid), refname, 0);
if (o && o->type == OBJ_COMMIT) if (o && o->type == OBJ_COMMIT)
clear_commit_marks((struct commit *)o, clear_commit_marks((struct commit *)o,
@@ -426,7 +426,7 @@ static int find_common(struct fetch_pack_args *args,
if (!lookup_object(oid.hash)) if (!lookup_object(oid.hash))
die(_("object not found: %s"), line); die(_("object not found: %s"), line);
/* make sure that it is parsed as shallow */ /* make sure that it is parsed as shallow */
if (!parse_object(oid.hash)) if (!parse_object(&oid))
die(_("error in object: %s"), line); die(_("error in object: %s"), line);
if (unregister_shallow(&oid)) if (unregister_shallow(&oid))
die(_("no shallow found: %s"), line); die(_("no shallow found: %s"), line);
@@ -557,14 +557,14 @@ static struct commit_list *complete;
static int mark_complete(const struct object_id *oid) static int mark_complete(const struct object_id *oid)
{ {
struct object *o = parse_object(oid->hash); struct object *o = parse_object(oid);
while (o && o->type == OBJ_TAG) { while (o && o->type == OBJ_TAG) {
struct tag *t = (struct tag *) o; struct tag *t = (struct tag *) o;
if (!t->tagged) if (!t->tagged)
break; /* broken repository */ break; /* broken repository */
o->flags |= COMPLETE; o->flags |= COMPLETE;
o = parse_object(t->tagged->oid.hash); o = parse_object(&t->tagged->oid);
} }
if (o && o->type == OBJ_COMMIT) { if (o && o->type == OBJ_COMMIT) {
struct commit *commit = (struct commit *)o; struct commit *commit = (struct commit *)o;
@@ -681,7 +681,7 @@ static int everything_local(struct fetch_pack_args *args,
if (!has_object_file(&ref->old_oid)) if (!has_object_file(&ref->old_oid))
continue; continue;
o = parse_object(ref->old_oid.hash); o = parse_object(&ref->old_oid);
if (!o) if (!o)
continue; continue;

2
fsck.c
View File

@@ -461,7 +461,7 @@ int fsck_walk(struct object *obj, void *data, struct fsck_options *options)
return -1; return -1;
if (obj->type == OBJ_NONE) if (obj->type == OBJ_NONE)
parse_object(obj->oid.hash); parse_object(&obj->oid);
switch (obj->type) { switch (obj->type) {
case OBJ_BLOB: case OBJ_BLOB:

View File

@@ -431,7 +431,7 @@ static int show_text_ref(const char *name, const struct object_id *oid,
{ {
const char *name_nons = strip_namespace(name); const char *name_nons = strip_namespace(name);
struct strbuf *buf = cb_data; struct strbuf *buf = cb_data;
struct object *o = parse_object(oid->hash); struct object *o = parse_object(oid);
if (!o) if (!o)
return 0; return 0;

View File

@@ -724,7 +724,7 @@ static void one_remote_object(const struct object_id *oid)
obj = lookup_object(oid->hash); obj = lookup_object(oid->hash);
if (!obj) if (!obj)
obj = parse_object(oid->hash); obj = parse_object(oid);
/* Ignore remote objects that don't exist locally */ /* Ignore remote objects that don't exist locally */
if (!obj) if (!obj)
@@ -1462,7 +1462,7 @@ static void add_remote_info_ref(struct remote_ls_ctx *ls)
return; return;
} }
o = parse_object(ref->old_oid.hash); o = parse_object(&ref->old_oid);
if (!o) { if (!o) {
fprintf(stderr, fprintf(stderr,
"Unable to parse object %s for remote ref %s\n", "Unable to parse object %s for remote ref %s\n",

View File

@@ -105,13 +105,13 @@ static int add_ref_decoration(const char *refname, const struct object_id *oid,
warning("invalid replace ref %s", refname); warning("invalid replace ref %s", refname);
return 0; return 0;
} }
obj = parse_object(original_oid.hash); obj = parse_object(&original_oid);
if (obj) if (obj)
add_name_decoration(DECORATION_GRAFTED, "replaced", obj); add_name_decoration(DECORATION_GRAFTED, "replaced", obj);
return 0; return 0;
} }
obj = parse_object(oid->hash); obj = parse_object(oid);
if (!obj) if (!obj)
return 0; return 0;
@@ -132,7 +132,7 @@ static int add_ref_decoration(const char *refname, const struct object_id *oid,
if (!obj) if (!obj)
break; break;
if (!obj->parsed) if (!obj->parsed)
parse_object(obj->oid.hash); parse_object(&obj->oid);
add_name_decoration(DECORATION_REF_TAG, refname, obj); add_name_decoration(DECORATION_REF_TAG, refname, obj);
} }
return 0; return 0;

View File

@@ -2103,7 +2103,7 @@ static struct commit *get_ref(const struct object_id *oid, const char *name)
{ {
struct object *object; struct object *object;
object = deref_tag(parse_object(oid->hash), name, strlen(name)); object = deref_tag(parse_object(oid), name, strlen(name));
if (!object) if (!object)
return NULL; return NULL;
if (object->type == OBJ_TREE) if (object->type == OBJ_TREE)

View File

@@ -180,24 +180,21 @@ struct object *lookup_unknown_object(const unsigned char *sha1)
return obj; return obj;
} }
struct object *parse_object_buffer(const unsigned char *sha1, enum object_type type, unsigned long size, void *buffer, int *eaten_p) struct object *parse_object_buffer(const struct object_id *oid, enum object_type type, unsigned long size, void *buffer, int *eaten_p)
{ {
struct object_id oid;
struct object *obj; struct object *obj;
*eaten_p = 0; *eaten_p = 0;
hashcpy(oid.hash, sha1);
obj = NULL; obj = NULL;
if (type == OBJ_BLOB) { if (type == OBJ_BLOB) {
struct blob *blob = lookup_blob(&oid); struct blob *blob = lookup_blob(oid);
if (blob) { if (blob) {
if (parse_blob_buffer(blob, buffer, size)) if (parse_blob_buffer(blob, buffer, size))
return NULL; return NULL;
obj = &blob->object; obj = &blob->object;
} }
} else if (type == OBJ_TREE) { } else if (type == OBJ_TREE) {
struct tree *tree = lookup_tree(&oid); struct tree *tree = lookup_tree(oid);
if (tree) { if (tree) {
obj = &tree->object; obj = &tree->object;
if (!tree->buffer) if (!tree->buffer)
@@ -209,7 +206,7 @@ struct object *parse_object_buffer(const unsigned char *sha1, enum object_type t
} }
} }
} else if (type == OBJ_COMMIT) { } else if (type == OBJ_COMMIT) {
struct commit *commit = lookup_commit(&oid); struct commit *commit = lookup_commit(oid);
if (commit) { if (commit) {
if (parse_commit_buffer(commit, buffer, size)) if (parse_commit_buffer(commit, buffer, size))
return NULL; return NULL;
@@ -220,57 +217,54 @@ struct object *parse_object_buffer(const unsigned char *sha1, enum object_type t
obj = &commit->object; obj = &commit->object;
} }
} else if (type == OBJ_TAG) { } else if (type == OBJ_TAG) {
struct tag *tag = lookup_tag(&oid); struct tag *tag = lookup_tag(oid);
if (tag) { if (tag) {
if (parse_tag_buffer(tag, buffer, size)) if (parse_tag_buffer(tag, buffer, size))
return NULL; return NULL;
obj = &tag->object; obj = &tag->object;
} }
} else { } else {
warning("object %s has unknown type id %d", sha1_to_hex(sha1), type); warning("object %s has unknown type id %d", oid_to_hex(oid), type);
obj = NULL; obj = NULL;
} }
return obj; return obj;
} }
struct object *parse_object_or_die(const unsigned char *sha1, struct object *parse_object_or_die(const struct object_id *oid,
const char *name) const char *name)
{ {
struct object *o = parse_object(sha1); struct object *o = parse_object(oid);
if (o) if (o)
return o; return o;
die(_("unable to parse object: %s"), name ? name : sha1_to_hex(sha1)); die(_("unable to parse object: %s"), name ? name : oid_to_hex(oid));
} }
struct object *parse_object(const unsigned char *sha1) struct object *parse_object(const struct object_id *oid)
{ {
unsigned long size; unsigned long size;
enum object_type type; enum object_type type;
int eaten; int eaten;
const unsigned char *repl = lookup_replace_object(sha1); const unsigned char *repl = lookup_replace_object(oid->hash);
void *buffer; void *buffer;
struct object *obj; struct object *obj;
struct object_id oid;
hashcpy(oid.hash, sha1); obj = lookup_object(oid->hash);
obj = lookup_object(oid.hash);
if (obj && obj->parsed) if (obj && obj->parsed)
return obj; return obj;
if ((obj && obj->type == OBJ_BLOB) || if ((obj && obj->type == OBJ_BLOB) ||
(!obj && has_sha1_file(sha1) && (!obj && has_object_file(oid) &&
sha1_object_info(sha1, NULL) == OBJ_BLOB)) { sha1_object_info(oid->hash, NULL) == OBJ_BLOB)) {
if (check_sha1_signature(repl, NULL, 0, NULL) < 0) { if (check_sha1_signature(repl, NULL, 0, NULL) < 0) {
error("sha1 mismatch %s", sha1_to_hex(repl)); error("sha1 mismatch %s", oid_to_hex(oid));
return NULL; return NULL;
} }
parse_blob_buffer(lookup_blob(&oid), NULL, 0); parse_blob_buffer(lookup_blob(oid), NULL, 0);
return lookup_object(sha1); return lookup_object(oid->hash);
} }
buffer = read_sha1_file(sha1, &type, &size); buffer = read_sha1_file(oid->hash, &type, &size);
if (buffer) { if (buffer) {
if (check_sha1_signature(repl, buffer, size, typename(type)) < 0) { if (check_sha1_signature(repl, buffer, size, typename(type)) < 0) {
free(buffer); free(buffer);
@@ -278,7 +272,7 @@ struct object *parse_object(const unsigned char *sha1)
return NULL; return NULL;
} }
obj = parse_object_buffer(sha1, type, size, buffer, &eaten); obj = parse_object_buffer(oid, type, size, buffer, &eaten);
if (!eaten) if (!eaten)
free(buffer); free(buffer);
return obj; return obj;

View File

@@ -89,20 +89,20 @@ void *object_as_type(struct object *obj, enum object_type type, int quiet);
* *
* Returns NULL if the object is missing or corrupt. * Returns NULL if the object is missing or corrupt.
*/ */
struct object *parse_object(const unsigned char *sha1); struct object *parse_object(const struct object_id *oid);
/* /*
* Like parse_object, but will die() instead of returning NULL. If the * Like parse_object, but will die() instead of returning NULL. If the
* "name" parameter is not NULL, it is included in the error message * "name" parameter is not NULL, it is included in the error message
* (otherwise, the sha1 hex is given). * (otherwise, the hex object ID is given).
*/ */
struct object *parse_object_or_die(const unsigned char *sha1, const char *name); struct object *parse_object_or_die(const struct object_id *oid, const char *name);
/* Given the result of read_sha1_file(), returns the object after /* Given the result of read_sha1_file(), returns the object after
* parsing it. eaten_p indicates if the object has a borrowed copy * parsing it. eaten_p indicates if the object has a borrowed copy
* of buffer and the caller should not free() it. * of buffer and the caller should not free() it.
*/ */
struct object *parse_object_buffer(const unsigned char *sha1, enum object_type type, unsigned long size, void *buffer, int *eaten_p); struct object *parse_object_buffer(const struct object_id *oid, enum object_type type, unsigned long size, void *buffer, int *eaten_p);
/** Returns the object, with potentially excess memory allocated. **/ /** Returns the object, with potentially excess memory allocated. **/
struct object *lookup_unknown_object(const unsigned char *sha1); struct object *lookup_unknown_object(const unsigned char *sha1);

View File

@@ -673,7 +673,7 @@ int prepare_bitmap_walk(struct rev_info *revs)
struct object *object = pending_e[i].item; struct object *object = pending_e[i].item;
if (object->type == OBJ_NONE) if (object->type == OBJ_NONE)
parse_object_or_die(object->oid.hash, NULL); parse_object_or_die(&object->oid, NULL);
while (object->type == OBJ_TAG) { while (object->type == OBJ_TAG) {
struct tag *tag = (struct tag *) object; struct tag *tag = (struct tag *) object;
@@ -685,7 +685,7 @@ int prepare_bitmap_walk(struct rev_info *revs)
if (!tag->tagged) if (!tag->tagged)
die("bad tag"); die("bad tag");
object = parse_object_or_die(tag->tagged->oid.hash, NULL); object = parse_object_or_die(&tag->tagged->oid, NULL);
} }
if (object->flags & UNINTERESTING) if (object->flags & UNINTERESTING)

View File

@@ -1137,7 +1137,7 @@ static size_t format_commit_one(struct strbuf *sb, /* in UTF-8 */
/* these depend on the commit */ /* these depend on the commit */
if (!commit->object.parsed) if (!commit->object.parsed)
parse_object(commit->object.oid.hash); parse_object(&commit->object.oid);
switch (placeholder[0]) { switch (placeholder[0]) {
case 'H': /* commit hash */ case 'H': /* commit hash */

View File

@@ -33,7 +33,7 @@ static int add_one_ref(const char *path, const struct object_id *oid,
return 0; return 0;
} }
object = parse_object_or_die(oid->hash, path); object = parse_object_or_die(oid, path);
add_pending_object(revs, object, ""); add_pending_object(revs, object, "");
return 0; return 0;
@@ -82,7 +82,7 @@ static void add_recent_object(const struct object_id *oid,
switch (type) { switch (type) {
case OBJ_TAG: case OBJ_TAG:
case OBJ_COMMIT: case OBJ_COMMIT:
obj = parse_object_or_die(oid->hash, NULL); obj = parse_object_or_die(oid, NULL);
break; break;
case OBJ_TREE: case OBJ_TREE:
obj = (struct object *)lookup_tree(oid); obj = (struct object *)lookup_tree(oid);

View File

@@ -683,7 +683,7 @@ static void *get_obj(const struct object_id *oid, struct object **obj, unsigned
void *buf = read_sha1_file(oid->hash, &type, sz); void *buf = read_sha1_file(oid->hash, &type, sz);
if (buf) if (buf)
*obj = parse_object_buffer(oid->hash, type, *sz, buf, eaten); *obj = parse_object_buffer(oid, type, *sz, buf, eaten);
else else
*obj = NULL; *obj = NULL;
return buf; return buf;
@@ -1687,7 +1687,7 @@ static const struct object_id *match_points_at(struct oid_array *points_at,
if (oid_array_lookup(points_at, oid) >= 0) if (oid_array_lookup(points_at, oid) >= 0)
return oid; return oid;
obj = parse_object(oid->hash); obj = parse_object(oid);
if (!obj) if (!obj)
die(_("malformed object at '%s'"), refname); die(_("malformed object at '%s'"), refname);
if (obj->type == OBJ_TAG) if (obj->type == OBJ_TAG)

View File

@@ -238,13 +238,13 @@ void fake_reflog_parent(struct reflog_walk_info *info, struct commit *commit)
do { do {
reflog = &commit_reflog->reflogs->items[commit_reflog->recno]; reflog = &commit_reflog->reflogs->items[commit_reflog->recno];
commit_reflog->recno--; commit_reflog->recno--;
logobj = parse_object(reflog->ooid.hash); logobj = parse_object(&reflog->ooid);
} while (commit_reflog->recno && (logobj && logobj->type != OBJ_COMMIT)); } while (commit_reflog->recno && (logobj && logobj->type != OBJ_COMMIT));
if (!logobj && commit_reflog->recno >= 0 && is_null_oid(&reflog->ooid)) { if (!logobj && commit_reflog->recno >= 0 && is_null_oid(&reflog->ooid)) {
/* a root commit, but there are still more entries to show */ /* a root commit, but there are still more entries to show */
reflog = &commit_reflog->reflogs->items[commit_reflog->recno]; reflog = &commit_reflog->reflogs->items[commit_reflog->recno];
logobj = parse_object(reflog->noid.hash); logobj = parse_object(&reflog->noid);
} }
if (!logobj || logobj->type != OBJ_COMMIT) { if (!logobj || logobj->type != OBJ_COMMIT) {

View File

@@ -2057,7 +2057,7 @@ static int write_ref_to_lockfile(struct ref_lock *lock,
struct object *o; struct object *o;
int fd; int fd;
o = parse_object(oid->hash); o = parse_object(oid);
if (!o) { if (!o) {
strbuf_addf(err, strbuf_addf(err,
"trying to write ref '%s' with nonexistent object %s", "trying to write ref '%s' with nonexistent object %s",

View File

@@ -1954,12 +1954,12 @@ int ref_newer(const struct object_id *new_oid, const struct object_id *old_oid)
* Both new and old must be commit-ish and new is descendant of * Both new and old must be commit-ish and new is descendant of
* old. Otherwise we require --force. * old. Otherwise we require --force.
*/ */
o = deref_tag(parse_object(old_oid->hash), NULL, 0); o = deref_tag(parse_object(old_oid), NULL, 0);
if (!o || o->type != OBJ_COMMIT) if (!o || o->type != OBJ_COMMIT)
return 0; return 0;
old = (struct commit *) o; old = (struct commit *) o;
o = deref_tag(parse_object(new_oid->hash), NULL, 0); o = deref_tag(parse_object(new_oid), NULL, 0);
if (!o || o->type != OBJ_COMMIT) if (!o || o->type != OBJ_COMMIT)
return 0; return 0;
new = (struct commit *) o; new = (struct commit *) o;

View File

@@ -181,7 +181,7 @@ void add_head_to_pending(struct rev_info *revs)
struct object *obj; struct object *obj;
if (get_oid("HEAD", &oid)) if (get_oid("HEAD", &oid))
return; return;
obj = parse_object(oid.hash); obj = parse_object(&oid);
if (!obj) if (!obj)
return; return;
add_pending_object(revs, obj, "HEAD"); add_pending_object(revs, obj, "HEAD");
@@ -193,7 +193,7 @@ static struct object *get_reference(struct rev_info *revs, const char *name,
{ {
struct object *object; struct object *object;
object = parse_object(oid->hash); object = parse_object(oid);
if (!object) { if (!object) {
if (revs->ignore_missing) if (revs->ignore_missing)
return object; return object;
@@ -228,7 +228,7 @@ static struct commit *handle_commit(struct rev_info *revs,
add_pending_object(revs, object, tag->tag); add_pending_object(revs, object, tag->tag);
if (!tag->tagged) if (!tag->tagged)
die("bad tag"); die("bad tag");
object = parse_object(tag->tagged->oid.hash); object = parse_object(&tag->tagged->oid);
if (!object) { if (!object) {
if (flags & UNINTERESTING) if (flags & UNINTERESTING)
return NULL; return NULL;
@@ -1200,7 +1200,7 @@ static void handle_one_reflog_commit(struct object_id *oid, void *cb_data)
{ {
struct all_refs_cb *cb = cb_data; struct all_refs_cb *cb = cb_data;
if (!is_null_oid(oid)) { if (!is_null_oid(oid)) {
struct object *o = parse_object(oid->hash); struct object *o = parse_object(oid);
if (o) { if (o) {
o->flags |= cb->all_flags; o->flags |= cb->all_flags;
/* ??? CMDLINEFLAGS ??? */ /* ??? CMDLINEFLAGS ??? */
@@ -1479,8 +1479,8 @@ int handle_revision_arg(const char *arg_, struct rev_info *revs, int flags, unsi
verify_non_filename(revs->prefix, arg); verify_non_filename(revs->prefix, arg);
} }
a_obj = parse_object(from_oid.hash); a_obj = parse_object(&from_oid);
b_obj = parse_object(oid.hash); b_obj = parse_object(&oid);
if (!a_obj || !b_obj) { if (!a_obj || !b_obj) {
missing: missing:
if (revs->ignore_missing) if (revs->ignore_missing)

View File

@@ -53,7 +53,7 @@ static int add_info_ref(const char *path, const struct object_id *oid,
int flag, void *cb_data) int flag, void *cb_data)
{ {
FILE *fp = cb_data; FILE *fp = cb_data;
struct object *o = parse_object(oid->hash); struct object *o = parse_object(oid);
if (!o) if (!o)
return -1; return -1;

View File

@@ -241,7 +241,7 @@ static int disambiguate_committish_only(const struct object_id *oid, void *cb_da
return 0; return 0;
/* We need to do this the hard way... */ /* We need to do this the hard way... */
obj = deref_tag(parse_object(oid->hash), NULL, 0); obj = deref_tag(parse_object(oid), NULL, 0);
if (obj && obj->type == OBJ_COMMIT) if (obj && obj->type == OBJ_COMMIT)
return 1; return 1;
return 0; return 0;
@@ -265,7 +265,7 @@ static int disambiguate_treeish_only(const struct object_id *oid, void *cb_data_
return 0; return 0;
/* We need to do this the hard way... */ /* We need to do this the hard way... */
obj = deref_tag(parse_object(oid->hash), NULL, 0); obj = deref_tag(parse_object(oid), NULL, 0);
if (obj && (obj->type == OBJ_TREE || obj->type == OBJ_COMMIT)) if (obj && (obj->type == OBJ_TREE || obj->type == OBJ_COMMIT))
return 1; return 1;
return 0; return 0;
@@ -776,7 +776,7 @@ struct object *peel_to_type(const char *name, int namelen,
if (name && !namelen) if (name && !namelen)
namelen = strlen(name); namelen = strlen(name);
while (1) { while (1) {
if (!o || (!o->parsed && !parse_object(o->oid.hash))) if (!o || (!o->parsed && !parse_object(&o->oid)))
return NULL; return NULL;
if (expected_type == OBJ_ANY || o->type == expected_type) if (expected_type == OBJ_ANY || o->type == expected_type)
return o; return o;
@@ -849,12 +849,12 @@ static int peel_onion(const char *name, int len, unsigned char *sha1,
if (get_sha1_1(name, sp - name - 2, outer.hash, lookup_flags)) if (get_sha1_1(name, sp - name - 2, outer.hash, lookup_flags))
return -1; return -1;
o = parse_object(outer.hash); o = parse_object(&outer);
if (!o) if (!o)
return -1; return -1;
if (!expected_type) { if (!expected_type) {
o = deref_tag(o, name, sp - name - 2); o = deref_tag(o, name, sp - name - 2);
if (!o || (!o->parsed && !parse_object(o->oid.hash))) if (!o || (!o->parsed && !parse_object(&o->oid)))
return -1; return -1;
hashcpy(sha1, o->oid.hash); hashcpy(sha1, o->oid.hash);
return 0; return 0;
@@ -981,7 +981,7 @@ static int handle_one_ref(const char *path, const struct object_id *oid,
int flag, void *cb_data) int flag, void *cb_data)
{ {
struct commit_list **list = cb_data; struct commit_list **list = cb_data;
struct object *object = parse_object(oid->hash); struct object *object = parse_object(oid);
if (!object) if (!object)
return 0; return 0;
if (object->type == OBJ_TAG) { if (object->type == OBJ_TAG) {
@@ -1027,7 +1027,7 @@ static int get_sha1_oneline(const char *prefix, unsigned char *sha1,
int matches; int matches;
commit = pop_most_recent_commit(&list, ONELINE_SEEN); commit = pop_most_recent_commit(&list, ONELINE_SEEN);
if (!parse_object(commit->object.oid.hash)) if (!parse_object(&commit->object.oid))
continue; continue;
buf = get_commit_buffer(commit, NULL); buf = get_commit_buffer(commit, NULL);
p = strstr(buf, "\n\n"); p = strstr(buf, "\n\n");

4
tag.c
View File

@@ -66,7 +66,7 @@ struct object *deref_tag(struct object *o, const char *warn, int warnlen)
{ {
while (o && o->type == OBJ_TAG) while (o && o->type == OBJ_TAG)
if (((struct tag *)o)->tagged) if (((struct tag *)o)->tagged)
o = parse_object(((struct tag *)o)->tagged->oid.hash); o = parse_object(&((struct tag *)o)->tagged->oid);
else else
o = NULL; o = NULL;
if (!o && warn) { if (!o && warn) {
@@ -80,7 +80,7 @@ struct object *deref_tag(struct object *o, const char *warn, int warnlen)
struct object *deref_tag_noverify(struct object *o) struct object *deref_tag_noverify(struct object *o)
{ {
while (o && o->type == OBJ_TAG) { while (o && o->type == OBJ_TAG) {
o = parse_object(o->oid.hash); o = parse_object(&o->oid);
if (o && o->type == OBJ_TAG && ((struct tag *)o)->tagged) if (o && o->type == OBJ_TAG && ((struct tag *)o)->tagged)
o = ((struct tag *)o)->tagged; o = ((struct tag *)o)->tagged;
else else

4
tree.c
View File

@@ -234,7 +234,7 @@ void free_tree_buffer(struct tree *tree)
struct tree *parse_tree_indirect(const struct object_id *oid) struct tree *parse_tree_indirect(const struct object_id *oid)
{ {
struct object *obj = parse_object(oid->hash); struct object *obj = parse_object(oid);
do { do {
if (!obj) if (!obj)
return NULL; return NULL;
@@ -247,6 +247,6 @@ struct tree *parse_tree_indirect(const struct object_id *oid)
else else
return NULL; return NULL;
if (!obj->parsed) if (!obj->parsed)
parse_object(obj->oid.hash); parse_object(&obj->oid);
} while (1); } while (1);
} }

View File

@@ -296,7 +296,7 @@ static int got_oid(const char *hex, struct object_id *oid)
if (!has_object_file(oid)) if (!has_object_file(oid))
return -1; return -1;
o = parse_object(oid->hash); o = parse_object(oid);
if (!o) if (!o)
die("oops (%s)", oid_to_hex(oid)); die("oops (%s)", oid_to_hex(oid));
if (o->type == OBJ_COMMIT) { if (o->type == OBJ_COMMIT) {
@@ -334,7 +334,7 @@ static int reachable(struct commit *want)
break; break;
} }
if (!commit->object.parsed) if (!commit->object.parsed)
parse_object(commit->object.oid.hash); parse_object(&commit->object.oid);
if (commit->object.flags & REACHABLE) if (commit->object.flags & REACHABLE)
continue; continue;
commit->object.flags |= REACHABLE; commit->object.flags |= REACHABLE;
@@ -755,7 +755,7 @@ static void receive_needs(void)
struct object *object; struct object *object;
if (get_oid_hex(arg, &oid)) if (get_oid_hex(arg, &oid))
die("invalid shallow line: %s", line); die("invalid shallow line: %s", line);
object = parse_object(oid.hash); object = parse_object(&oid);
if (!object) if (!object)
continue; continue;
if (object->type != OBJ_COMMIT) if (object->type != OBJ_COMMIT)
@@ -821,7 +821,7 @@ static void receive_needs(void)
if (parse_feature_request(features, "include-tag")) if (parse_feature_request(features, "include-tag"))
use_include_tag = 1; use_include_tag = 1;
o = parse_object(oid_buf.hash); o = parse_object(&oid_buf);
if (!o) { if (!o) {
packet_write_fmt(1, packet_write_fmt(1,
"ERR upload-pack: not our ref %s", "ERR upload-pack: not our ref %s",

View File

@@ -180,7 +180,7 @@ static int loop(struct walker *walker)
} }
} }
if (!obj->type) if (!obj->type)
parse_object(obj->oid.hash); parse_object(&obj->oid);
if (process_object(walker, obj)) if (process_object(walker, obj))
return -1; return -1;
} }