deref_tag: handle return value NULL

Signed-off-by: Martin Koegler <mkoegler@auto.tuwien.ac.at>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
This commit is contained in:
Martin Koegler 2008-02-18 08:31:54 +01:00 committed by Junio C Hamano
parent 9886ea417b
commit affeef12fb
5 changed files with 12 additions and 3 deletions

View File

@ -86,6 +86,9 @@ match:
sha1_to_hex(sha1)); sha1_to_hex(sha1));
if (obj->type == OBJ_TAG) { if (obj->type == OBJ_TAG) {
obj = deref_tag(obj, refname, 0); obj = deref_tag(obj, refname, 0);
if (!obj)
die("git-show-ref: bad tag at ref %s (%s)", refname,
sha1_to_hex(sha1));
hex = find_unique_abbrev(obj->sha1, abbrev); hex = find_unique_abbrev(obj->sha1, abbrev);
printf("%s %s^{}\n", hex, refname); printf("%s %s^{}\n", hex, refname);
} }

View File

@ -1673,6 +1673,8 @@ static struct commit *get_ref(const char *ref)
if (get_sha1(ref, sha1)) if (get_sha1(ref, sha1))
die("Could not resolve ref '%s'", ref); die("Could not resolve ref '%s'", ref);
object = deref_tag(parse_object(sha1), ref, strlen(ref)); object = deref_tag(parse_object(sha1), ref, strlen(ref));
if (!object)
return NULL;
if (object->type == OBJ_TREE) if (object->type == OBJ_TREE)
return make_virtual_commit((struct tree*)object, return make_virtual_commit((struct tree*)object,
better_branch_name(ref)); better_branch_name(ref));

View File

@ -578,8 +578,11 @@ static int handle_one_ref(const char *path,
struct object *object = parse_object(sha1); struct object *object = parse_object(sha1);
if (!object) if (!object)
return 0; return 0;
if (object->type == OBJ_TAG) if (object->type == OBJ_TAG) {
object = deref_tag(object, path, strlen(path)); object = deref_tag(object, path, strlen(path));
if (!object)
return 0;
}
if (object->type != OBJ_COMMIT) if (object->type != OBJ_COMMIT)
return 0; return 0;
insert_by_date((struct commit *)object, list); insert_by_date((struct commit *)object, list);

View File

@ -56,7 +56,7 @@ struct commit_list *get_shallow_commits(struct object_array *heads, int depth,
if (i < heads->nr) { if (i < heads->nr) {
commit = (struct commit *) commit = (struct commit *)
deref_tag(heads->objects[i++].item, NULL, 0); deref_tag(heads->objects[i++].item, NULL, 0);
if (commit->object.type != OBJ_COMMIT) { if (!commit || commit->object.type != OBJ_COMMIT) {
commit = NULL; commit = NULL;
continue; continue;
} }

View File

@ -575,6 +575,7 @@ static int send_ref(const char *refname, const unsigned char *sha1, int flag, vo
} }
if (o->type == OBJ_TAG) { if (o->type == OBJ_TAG) {
o = deref_tag(o, refname, 0); o = deref_tag(o, refname, 0);
if (o)
packet_write(1, "%s %s^{}\n", sha1_to_hex(o->sha1), refname); packet_write(1, "%s %s^{}\n", sha1_to_hex(o->sha1), refname);
} }
return 0; return 0;