Fix isMergedIntoVisibleRef check to handle prefix in RefMap
RefMap does not accept mixed prefixes, as this could cause a key collision. Adding R_HEADS and R_TAGS to the same RefMap will always fail. Instead pull the refs into a List<Ref> and work from that. Change-Id: I57a463cc462b97e3ed6ac76bc8d8129c88819b03
This commit is contained in:
		| @@ -16,6 +16,7 @@ package com.google.gerrit.server.project; | ||||
|  | ||||
| import com.google.common.collect.ImmutableList; | ||||
| import com.google.common.collect.Lists; | ||||
| import com.google.common.collect.Maps; | ||||
| import com.google.gerrit.common.Nullable; | ||||
| import com.google.gerrit.common.PageLinks; | ||||
| import com.google.gerrit.common.data.AccessSection; | ||||
| @@ -525,7 +526,8 @@ public class ProjectControl { | ||||
|     try { | ||||
|       Repository repo = openRepository(); | ||||
|       try { | ||||
|         return isMergedIntoVisibleRef(repo, db, rw, commit, repo.getAllRefs()); | ||||
|         return isMergedIntoVisibleRef(repo, db, rw, commit, | ||||
|             repo.getAllRefs().values()); | ||||
|       } finally { | ||||
|         repo.close(); | ||||
|       } | ||||
| @@ -539,10 +541,14 @@ public class ProjectControl { | ||||
|   } | ||||
|  | ||||
|   boolean isMergedIntoVisibleRef(Repository repo, ReviewDb db, RevWalk rw, | ||||
|       RevCommit commit, Map<String, Ref> unfilteredRefs) throws IOException { | ||||
|       RevCommit commit, Collection<Ref> unfilteredRefs) throws IOException { | ||||
|     VisibleRefFilter filter = | ||||
|         new VisibleRefFilter(tagCache, changeCache, repo, this, db, true); | ||||
|     Map<String, Ref> refs = filter.filter(unfilteredRefs, true); | ||||
|     Map<String, Ref> m = Maps.newHashMapWithExpectedSize(unfilteredRefs.size()); | ||||
|     for (Ref r : unfilteredRefs) { | ||||
|       m.put(r.getName(), r); | ||||
|     } | ||||
|     Map<String, Ref> refs = filter.filter(m, true); | ||||
|     return !refs.isEmpty() | ||||
|         && IncludedInResolver.includedInOne(repo, rw, commit, refs.values()); | ||||
|   } | ||||
|   | ||||
| @@ -324,9 +324,9 @@ public class RefControl { | ||||
|     try { | ||||
|       Repository repo = projectControl.openRepository(); | ||||
|       try { | ||||
|         Map<String, Ref> refs = | ||||
|             repo.getRefDatabase().getRefs(Constants.R_HEADS); | ||||
|         refs.putAll(repo.getRefDatabase().getRefs(Constants.R_TAGS)); | ||||
|         List<Ref> refs = new ArrayList<>( | ||||
|             repo.getRefDatabase().getRefs(Constants.R_HEADS).values()); | ||||
|         refs.addAll(repo.getRefDatabase().getRefs(Constants.R_TAGS).values()); | ||||
|         return projectControl.isMergedIntoVisibleRef( | ||||
|             repo, db, rw, commit, refs); | ||||
|       } finally { | ||||
|   | ||||
		Reference in New Issue
	
	Block a user
	 Shawn Pearce
					Shawn Pearce