Merge "Reject inline comments on files that do not exist in the patch set"

This commit is contained in:
Shawn Pearce
2014-04-28 18:19:22 +00:00
committed by Gerrit Code Review
3 changed files with 42 additions and 16 deletions

View File

@@ -62,6 +62,7 @@ import java.io.IOException;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
@@ -172,7 +173,7 @@ public class ChangeData {
private Collection<PatchSet> patches;
private ListMultimap<PatchSet.Id, PatchSetApproval> allApprovals;
private List<PatchSetApproval> currentApprovals;
private List<String> currentFiles;
private Map<Integer, List<String>> files = new HashMap<>();
private Collection<PatchLineComment> comments;
private CurrentUser visibleTo;
private ChangeControl changeControl;
@@ -258,27 +259,35 @@ public class ChangeData {
returnedBySource = s;
}
public void setCurrentFilePaths(List<String> filePaths) {
currentFiles = ImmutableList.copyOf(filePaths);
public void setCurrentFilePaths(List<String> filePaths) throws OrmException {
PatchSet ps = currentPatchSet();
if (ps != null) {
files.put(ps.getPatchSetId(), ImmutableList.copyOf(filePaths));
}
}
public List<String> currentFilePaths() throws OrmException {
if (currentFiles == null) {
PatchSet ps = currentPatchSet();
if (ps == null) {
return null;
}
return filePaths(currentPatchSet);
}
public List<String> filePaths(PatchSet ps) throws OrmException {
if (!files.containsKey(ps.getPatchSetId())) {
Change c = change();
if (c == null) {
return null;
}
PatchSet ps = currentPatchSet();
if (ps == null) {
return null;
}
PatchList p;
try {
p = patchListCache.get(c, ps);
} catch (PatchListNotAvailableException e) {
currentFiles = Collections.emptyList();
return currentFiles;
List<String> emptyFileList = Collections.emptyList();
files.put(ps.getPatchSetId(), emptyFileList);
return emptyFileList;
}
List<String> r = new ArrayList<>(p.getPatches().size());
@@ -302,9 +311,9 @@ public class ChangeData {
}
}
Collections.sort(r);
currentFiles = Collections.unmodifiableList(r);
files.put(ps.getPatchSetId(), Collections.unmodifiableList(r));
}
return currentFiles;
return files.get(ps.getPatchSetId());
}
public ChangedLines changedLines() throws OrmException {