- struct commit *commit;
- if (!(commit = lookup_commit_reference(sha1)))
- return error("not a commit: %s", sha1_to_hex(sha1));
- return record_rev_cache(commit->object.sha1, NULL);
+ struct object *obj = parse_object(sha1);
+
+ if (!obj)
+ return error("ref %s has bad sha %s", path, sha1_to_hex(sha1));
+ while (obj && obj->type == tag_type)
+ obj = parse_object(((struct tag *)obj)->tagged->sha1);
+ if (!obj || obj->type != commit_type)
+ /* tag pointing at a non-commit */
+ return 0;
+ return record_rev_cache(obj->sha1, NULL);