You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

PatchPage.java 2.4KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. /*
  2. * Copyright 2011 gitblit.com.
  3. *
  4. * Licensed under the Apache License, Version 2.0 (the "License");
  5. * you may not use this file except in compliance with the License.
  6. * You may obtain a copy of the License at
  7. *
  8. * http://www.apache.org/licenses/LICENSE-2.0
  9. *
  10. * Unless required by applicable law or agreed to in writing, software
  11. * distributed under the License is distributed on an "AS IS" BASIS,
  12. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  13. * See the License for the specific language governing permissions and
  14. * limitations under the License.
  15. */
  16. package com.gitblit.wicket.pages;
  17. import org.apache.wicket.PageParameters;
  18. import org.apache.wicket.markup.html.WebPage;
  19. import org.apache.wicket.markup.html.basic.Label;
  20. import org.eclipse.jgit.lib.Repository;
  21. import org.eclipse.jgit.revwalk.RevCommit;
  22. import com.gitblit.GitBlit;
  23. import com.gitblit.utils.JGitUtils;
  24. import com.gitblit.utils.StringUtils;
  25. import com.gitblit.wicket.GitBlitWebSession;
  26. import com.gitblit.wicket.WicketUtils;
  27. public class PatchPage extends WebPage {
  28. public PatchPage(PageParameters params) {
  29. super(params);
  30. if (!params.containsKey("r")) {
  31. GitBlitWebSession.get().cacheErrorMessage("Repository not specified!");
  32. redirectToInterceptPage(new RepositoriesPage());
  33. return;
  34. }
  35. final String repositoryName = WicketUtils.getRepositoryName(params);
  36. final String baseObjectId = WicketUtils.getBaseObjectId(params);
  37. final String objectId = WicketUtils.getObject(params);
  38. final String blobPath = WicketUtils.getPath(params);
  39. Repository r = GitBlit.self().getRepository(repositoryName);
  40. if (r == null) {
  41. GitBlitWebSession.get().cacheErrorMessage("Can not load repository " + repositoryName);
  42. redirectToInterceptPage(new RepositoriesPage());
  43. return;
  44. }
  45. RevCommit commit = JGitUtils.getCommit(r, objectId);
  46. if (commit == null) {
  47. GitBlitWebSession.get().cacheErrorMessage("Commit is null");
  48. redirectToInterceptPage(new RepositoriesPage());
  49. return;
  50. }
  51. String patch;
  52. if (StringUtils.isEmpty(baseObjectId)) {
  53. patch = JGitUtils.getCommitPatch(r, commit, blobPath);
  54. } else {
  55. RevCommit baseCommit = JGitUtils.getCommit(r, baseObjectId);
  56. patch = JGitUtils.getCommitPatch(r, baseCommit, commit, blobPath);
  57. }
  58. add(new Label("patchText", patch));
  59. r.close();
  60. }
  61. }