- for (p = prefix; *p; p++) {
- char *pathname = git_path("%s/%.*s", *p, len, str);
-
- if (!read_ref(pathname, sha1)) {
- /* Must be unique; i.e. when heads/foo and
- * tags/foo are both present, reject "foo".
- */
- if (1 < found++)
- return -1;
- }
-
- /* We want to allow .git/description file and
- * "description" branch to exist at the same time.
- * "git-rev-parse description" should silently skip
- * .git/description file as a candidate for
- * get_sha1(). However, having garbage file anywhere
- * under refs/ is not OK, and we would not have caught
- * ambiguous heads and tags with the above test.
- */
- else if (**p && !access(pathname, F_OK)) {
- /* Garbage exists under .git/refs */
- return error("garbage ref found '%s'", pathname);
+ for (p = fmt; *p; p++) {
+ this_result = already_found ? sha1_from_ref : sha1;
+ pathname = git_path(*p, len, str);
+ if (!read_ref(pathname, this_result)) {
+ if (warn_ambiguous_refs) {
+ if (already_found)
+ fprintf(stderr, warning, len, str);
+ already_found++;
+ }
+ else
+ return 0;