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.

CommitDiffPage.java 4.3KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107
  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.ArrayList;
  18. import java.util.List;
  19. import org.apache.wicket.PageParameters;
  20. import org.apache.wicket.markup.html.basic.Label;
  21. import org.apache.wicket.markup.html.link.BookmarkablePageLink;
  22. import org.apache.wicket.markup.repeater.Item;
  23. import org.apache.wicket.markup.repeater.data.DataView;
  24. import org.apache.wicket.markup.repeater.data.ListDataProvider;
  25. import org.eclipse.jgit.lib.Repository;
  26. import org.eclipse.jgit.revwalk.RevCommit;
  27. import com.gitblit.GitBlit;
  28. import com.gitblit.Keys;
  29. import com.gitblit.utils.JGitUtils;
  30. import com.gitblit.utils.JGitUtils.DiffOutputType;
  31. import com.gitblit.wicket.LinkPanel;
  32. import com.gitblit.wicket.RepositoryPage;
  33. import com.gitblit.wicket.WicketUtils;
  34. import com.gitblit.wicket.models.PathModel.PathChangeModel;
  35. import com.gitblit.wicket.panels.CommitHeaderPanel;
  36. import com.gitblit.wicket.panels.CommitLegendPanel;
  37. public class CommitDiffPage extends RepositoryPage {
  38. public CommitDiffPage(PageParameters params) {
  39. super(params);
  40. Repository r = getRepository();
  41. RevCommit commit = getCommit();
  42. DiffOutputType diffType = DiffOutputType.forName(GitBlit.self().settings().getString(Keys.web.diffStyle, DiffOutputType.GITBLIT.name()));
  43. String diff = JGitUtils.getCommitDiff(r, commit, diffType);
  44. List<String> parents = new ArrayList<String>();
  45. if (commit.getParentCount() > 0) {
  46. for (RevCommit parent : commit.getParents()) {
  47. parents.add(parent.name());
  48. }
  49. }
  50. // commit page links
  51. if (parents.size() == 0) {
  52. add(new Label("parentLink", "none"));
  53. } else {
  54. add(new LinkPanel("parentLink", null, parents.get(0).substring(0, 8), CommitDiffPage.class, newCommitParameter(parents.get(0))));
  55. }
  56. add(new BookmarkablePageLink<Void>("patchLink", PatchPage.class, WicketUtils.newObjectParameter(repositoryName, objectId)));
  57. add(new BookmarkablePageLink<Void>("commitLink", CommitPage.class, WicketUtils.newObjectParameter(repositoryName, objectId)));
  58. add(new CommitHeaderPanel("commitHeader", repositoryName, commit));
  59. // changed paths list
  60. List<PathChangeModel> paths = JGitUtils.getFilesInCommit(r, commit);
  61. add(new CommitLegendPanel("commitLegend", paths));
  62. ListDataProvider<PathChangeModel> pathsDp = new ListDataProvider<PathChangeModel>(paths);
  63. DataView<PathChangeModel> pathsView = new DataView<PathChangeModel>("changedPath", pathsDp) {
  64. private static final long serialVersionUID = 1L;
  65. int counter = 0;
  66. public void populateItem(final Item<PathChangeModel> item) {
  67. final PathChangeModel entry = item.getModelObject();
  68. Label changeType = new Label("changeType", "");
  69. WicketUtils.setChangeTypeCssClass(changeType, entry.changeType);
  70. setChangeTypeTooltip(changeType, entry.changeType);
  71. item.add(changeType);
  72. if (entry.isTree()) {
  73. item.add(new LinkPanel("pathName", null, entry.path, TreePage.class, newPathParameter(entry.path)));
  74. } else {
  75. item.add(new LinkPanel("pathName", "list", entry.path, BlobPage.class, newPathParameter(entry.path)));
  76. }
  77. item.add(new BookmarkablePageLink<Void>("patch", PatchPage.class, newPathParameter(entry.path)));
  78. item.add(new BookmarkablePageLink<Void>("view", BlobPage.class, newPathParameter(entry.path)));
  79. item.add(new BookmarkablePageLink<Void>("blame", BlobPage.class).setEnabled(false));
  80. item.add(new BookmarkablePageLink<Void>("history", HistoryPage.class, newPathParameter(entry.path)));
  81. WicketUtils.setAlternatingBackground(item, counter);
  82. counter++;
  83. }
  84. };
  85. add(pathsView);
  86. add(new Label("diffText", diff).setEscapeModelStrings(false));
  87. }
  88. @Override
  89. protected String getPageName() {
  90. return getString("gb.commitdiff");
  91. }
  92. }