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.5KB

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