control = changeControlFactory.validateFor(changeId);
change = control.getChange();
projectKey = change.getProject();
patchSet = db.patchSets().get(patchSetId);
if (patchSet == null) {
throw new NoSuchChangeException(changeId);
}
aId = psa != null ? toObjectId(db, psa) : null;
bId = toObjectId(db, psb);
final Repository git;
try {
git = repoManager.openRepository(projectKey);
} catch (RepositoryNotFoundException e) {
log.error("Repository " + projectKey + " not found", e);
throw new NoSuchChangeException(changeId, e);
} catch (IOException e) {
log.error("Cannot open repository " + projectKey, e);
throw new NoSuchChangeException(changeId, e);
}
try {
final PatchList list = listFor(keyFor(diffPrefs.getIgnoreWhitespace()));
final PatchScriptBuilder b = newBuilder(list, git);
final PatchListEntry content = list.get(patchKey.getFileName());
loadCommentsAndHistory(content.getChangeType(), //
content.getOldName(), //
content.getNewName());
return b.toPatchScript(content, comments, history);
} catch (PatchListNotAvailableException e) {
throw new NoSuchChangeException(changeId, e);
} catch (IOException e) {
log.error("File content unavailable", e);
throw new NoSuchChangeException(changeId, e);
} catch (org.eclipse.jgit.errors.LargeObjectException err) {
throw new LargeObjectException("File content is too large", err);
} finally {
git.close();
}