private boolean applyPatch( HttpServletRequest request, HttpServletResponse response, Repository db, String contentType) throws ServletException { try { String patch = readPatch(request.getInputStream(), contentType); Git git = new Git(db); ApplyCommand applyCommand = git.apply(); applyCommand.setPatch(IOUtilities.toInputStream(patch)); // TODO: ignore all errors for now, see bug 366008 try { ApplyResult applyResult = applyCommand.call(); JSONObject resp = new JSONObject(); JSONArray modifiedFieles = new JSONArray(); for (File file : applyResult.getUpdatedFiles()) { modifiedFieles.put(stripGlobalPaths(db, file.getAbsolutePath())); } resp.put("modifiedFieles", modifiedFieles); return statusHandler.handleRequest( request, response, new ServerStatus(Status.OK_STATUS, HttpServletResponse.SC_OK, resp)); // OrionServlet.writeJSONResponse(request, response, toJSON(applyResult)); } catch (PatchFormatException e) { return statusHandler.handleRequest( request, response, new ServerStatus( IStatus.ERROR, HttpServletResponse.SC_BAD_REQUEST, stripGlobalPaths(db, e.getMessage()), null)); } catch (PatchApplyException e) { return statusHandler.handleRequest( request, response, new ServerStatus( IStatus.ERROR, HttpServletResponse.SC_BAD_REQUEST, stripGlobalPaths(db, e.getMessage()), null)); } } catch (Exception e) { return statusHandler.handleRequest( request, response, new ServerStatus( IStatus.ERROR, HttpServletResponse.SC_INTERNAL_SERVER_ERROR, "An error occured when reading the patch.", e)); } }