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

Bug: issue 2583
Change-Id: Icaf213f890c10f7f4207e1c3e48c1c8d841bd6d1
Signed-off-by: Edwin Kempin <edwin.kempin@sap.com>
This commit is contained in:
Edwin Kempin
2014-04-10 10:41:45 +02:00
parent c8133d1c62
commit a1eae0d64a
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<String>(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 {