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 3.3KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  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.basic.Label;
  19. import org.apache.wicket.markup.html.link.BookmarkablePageLink;
  20. import org.eclipse.jgit.lib.Repository;
  21. import org.eclipse.jgit.revwalk.RevCommit;
  22. import com.gitblit.utils.DiffUtils;
  23. import com.gitblit.utils.DiffUtils.DiffOutputType;
  24. import com.gitblit.utils.JGitUtils;
  25. import com.gitblit.utils.StringUtils;
  26. import com.gitblit.wicket.CacheControl;
  27. import com.gitblit.wicket.CacheControl.LastModified;
  28. import com.gitblit.wicket.WicketUtils;
  29. import com.gitblit.wicket.panels.CommitHeaderPanel;
  30. import com.gitblit.wicket.panels.PathBreadcrumbsPanel;
  31. @CacheControl(LastModified.BOOT)
  32. public class BlobDiffPage extends RepositoryPage {
  33. public BlobDiffPage(PageParameters params) {
  34. super(params);
  35. final String blobPath = WicketUtils.getPath(params);
  36. final String baseObjectId = WicketUtils.getBaseObjectId(params);
  37. Repository r = getRepository();
  38. RevCommit commit = getCommit();
  39. String diff;
  40. if (StringUtils.isEmpty(baseObjectId)) {
  41. // use first parent
  42. diff = DiffUtils.getDiff(r, commit, blobPath, DiffOutputType.HTML).content;
  43. add(new BookmarkablePageLink<Void>("patchLink", PatchPage.class,
  44. WicketUtils.newPathParameter(repositoryName, objectId, blobPath)));
  45. } else {
  46. // base commit specified
  47. RevCommit baseCommit = JGitUtils.getCommit(r, baseObjectId);
  48. diff = DiffUtils.getDiff(r, baseCommit, commit, blobPath, DiffOutputType.HTML).content;
  49. add(new BookmarkablePageLink<Void>("patchLink", PatchPage.class,
  50. WicketUtils.newBlobDiffParameter(repositoryName, baseObjectId, objectId,
  51. blobPath)));
  52. }
  53. add(new BookmarkablePageLink<Void>("commitLink", CommitPage.class,
  54. WicketUtils.newObjectParameter(repositoryName, objectId)));
  55. add(new BookmarkablePageLink<Void>("commitDiffLink", CommitDiffPage.class,
  56. WicketUtils.newObjectParameter(repositoryName, objectId)));
  57. // diff page links
  58. add(new BookmarkablePageLink<Void>("blameLink", BlamePage.class,
  59. WicketUtils.newPathParameter(repositoryName, objectId, blobPath)));
  60. add(new BookmarkablePageLink<Void>("historyLink", HistoryPage.class,
  61. WicketUtils.newPathParameter(repositoryName, objectId, blobPath)));
  62. add(new CommitHeaderPanel("commitHeader", repositoryName, commit));
  63. add(new PathBreadcrumbsPanel("breadcrumbs", repositoryName, blobPath, objectId));
  64. add(new Label("diffText", diff).setEscapeModelStrings(false));
  65. }
  66. @Override
  67. protected String getPageName() {
  68. return getString("gb.diff");
  69. }
  70. @Override
  71. protected Class<? extends BasePage> getRepoNavPageClass() {
  72. return TreePage.class;
  73. }
  74. }