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.

BlobDiffPage.java 4.1KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109
  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 java.util.List;
  18. import org.apache.wicket.PageParameters;
  19. import org.apache.wicket.markup.html.basic.Label;
  20. import org.apache.wicket.markup.html.link.BookmarkablePageLink;
  21. import org.eclipse.jgit.lib.Repository;
  22. import org.eclipse.jgit.revwalk.RevCommit;
  23. import com.gitblit.Keys;
  24. import com.gitblit.utils.DiffUtils;
  25. import com.gitblit.utils.DiffUtils.DiffOutputType;
  26. import com.gitblit.utils.JGitUtils;
  27. import com.gitblit.utils.StringUtils;
  28. import com.gitblit.wicket.CacheControl;
  29. import com.gitblit.wicket.CacheControl.LastModified;
  30. import com.gitblit.wicket.WicketUtils;
  31. import com.gitblit.wicket.panels.CommitHeaderPanel;
  32. import com.gitblit.wicket.panels.PathBreadcrumbsPanel;
  33. @CacheControl(LastModified.BOOT)
  34. public class BlobDiffPage extends RepositoryPage {
  35. public BlobDiffPage(PageParameters params) {
  36. super(params);
  37. final String blobPath = WicketUtils.getPath(params);
  38. final String baseObjectId = WicketUtils.getBaseObjectId(params);
  39. Repository r = getRepository();
  40. RevCommit commit = getCommit();
  41. final List<String> imageExtensions = app().settings().getStrings(Keys.web.imageExtensions);
  42. String diff;
  43. if (StringUtils.isEmpty(baseObjectId)) {
  44. // use first parent
  45. RevCommit parent = commit.getParentCount() == 0 ? null : commit.getParent(0);
  46. ImageDiffHandler handler = new ImageDiffHandler(this, repositoryName,
  47. parent.getName(), commit.getName(), imageExtensions);
  48. diff = DiffUtils.getDiff(r, commit, blobPath, DiffOutputType.HTML, handler).content;
  49. if (handler.getImgDiffCount() > 0) {
  50. addBottomScript("scripts/imgdiff.js"); // Tiny support script for image diffs
  51. }
  52. add(new BookmarkablePageLink<Void>("patchLink", PatchPage.class,
  53. WicketUtils.newPathParameter(repositoryName, objectId, blobPath)));
  54. } else {
  55. // base commit specified
  56. RevCommit baseCommit = JGitUtils.getCommit(r, baseObjectId);
  57. ImageDiffHandler handler = new ImageDiffHandler(this, repositoryName,
  58. baseCommit.getName(), commit.getName(), imageExtensions);
  59. diff = DiffUtils.getDiff(r, baseCommit, commit, blobPath, DiffOutputType.HTML, handler).content;
  60. if (handler.getImgDiffCount() > 0) {
  61. addBottomScript("scripts/imgdiff.js"); // Tiny support script for image diffs
  62. }
  63. add(new BookmarkablePageLink<Void>("patchLink", PatchPage.class,
  64. WicketUtils.newBlobDiffParameter(repositoryName, baseObjectId, objectId,
  65. blobPath)));
  66. }
  67. add(new BookmarkablePageLink<Void>("commitLink", CommitPage.class,
  68. WicketUtils.newObjectParameter(repositoryName, objectId)));
  69. add(new BookmarkablePageLink<Void>("commitDiffLink", CommitDiffPage.class,
  70. WicketUtils.newObjectParameter(repositoryName, objectId)));
  71. // diff page links
  72. add(new BookmarkablePageLink<Void>("blameLink", BlamePage.class,
  73. WicketUtils.newPathParameter(repositoryName, objectId, blobPath)));
  74. add(new BookmarkablePageLink<Void>("historyLink", HistoryPage.class,
  75. WicketUtils.newPathParameter(repositoryName, objectId, blobPath)));
  76. add(new CommitHeaderPanel("commitHeader", repositoryName, commit));
  77. add(new PathBreadcrumbsPanel("breadcrumbs", repositoryName, blobPath, objectId));
  78. add(new Label("diffText", diff).setEscapeModelStrings(false));
  79. }
  80. @Override
  81. protected String getPageName() {
  82. return getString("gb.diff");
  83. }
  84. @Override
  85. protected boolean isCommitPage() {
  86. return true;
  87. }
  88. @Override
  89. protected Class<? extends BasePage> getRepoNavPageClass() {
  90. return TreePage.class;
  91. }
  92. }