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.

CommitPage.java 5.3KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124
  1. package com.gitblit.wicket.pages;
  2. import java.util.ArrayList;
  3. import java.util.List;
  4. import org.apache.wicket.PageParameters;
  5. import org.apache.wicket.markup.html.basic.Label;
  6. import org.apache.wicket.markup.html.link.BookmarkablePageLink;
  7. import org.apache.wicket.markup.html.link.ExternalLink;
  8. import org.apache.wicket.markup.repeater.Item;
  9. import org.apache.wicket.markup.repeater.data.DataView;
  10. import org.apache.wicket.markup.repeater.data.ListDataProvider;
  11. import org.apache.wicket.model.StringResourceModel;
  12. import org.eclipse.jgit.lib.Repository;
  13. import org.eclipse.jgit.revwalk.RevCommit;
  14. import com.gitblit.DownloadZipServlet;
  15. import com.gitblit.GitBlit;
  16. import com.gitblit.Keys;
  17. import com.gitblit.utils.JGitUtils;
  18. import com.gitblit.utils.JGitUtils.SearchType;
  19. import com.gitblit.wicket.LinkPanel;
  20. import com.gitblit.wicket.RepositoryPage;
  21. import com.gitblit.wicket.WicketUtils;
  22. import com.gitblit.wicket.models.PathModel.PathChangeModel;
  23. import com.gitblit.wicket.panels.CommitHeaderPanel;
  24. import com.gitblit.wicket.panels.CommitLegendPanel;
  25. public class CommitPage extends RepositoryPage {
  26. public CommitPage(PageParameters params) {
  27. super(params);
  28. Repository r = getRepository();
  29. RevCommit c = getCommit();
  30. List<String> parents = new ArrayList<String>();
  31. if (c.getParentCount() > 0) {
  32. for (RevCommit parent : c.getParents()) {
  33. parents.add(parent.name());
  34. }
  35. }
  36. // commit page links
  37. if (parents.size() == 0) {
  38. add(new Label("parentLink", "none"));
  39. add(new Label("commitdiffLink", getString("gb.commitdiff")));
  40. } else {
  41. add(new LinkPanel("parentLink", null, parents.get(0).substring(0, 8), CommitPage.class, newCommitParameter(parents.get(0))));
  42. add(new LinkPanel("commitdiffLink", null, new StringResourceModel("gb.commitdiff", this, null), CommitDiffPage.class, WicketUtils.newObjectParameter(repositoryName, objectId)));
  43. }
  44. add(new BookmarkablePageLink<Void>("patchLink", PatchPage.class, WicketUtils.newObjectParameter(repositoryName, objectId)));
  45. add(new CommitHeaderPanel("commitHeader", repositoryName, c));
  46. addRefs(r, c);
  47. // author
  48. add(createPersonPanel("commitAuthor", c.getAuthorIdent(), SearchType.AUTHOR));
  49. add(WicketUtils.createTimestampLabel("commitAuthorDate", c.getAuthorIdent().getWhen(), getTimeZone()));
  50. // committer
  51. add(createPersonPanel("commitCommitter", c.getCommitterIdent(), SearchType.COMMITTER));
  52. add(WicketUtils.createTimestampLabel("commitCommitterDate", c.getCommitterIdent().getWhen(), getTimeZone()));
  53. add(new Label("commitId", c.getName()));
  54. add(new LinkPanel("commitTree", "list", c.getTree().getName(), TreePage.class, newCommitParameter()));
  55. add(new BookmarkablePageLink<Void>("treeLink", TreePage.class, newCommitParameter()));
  56. add(new ExternalLink("zipLink", DownloadZipServlet.asLink(getRequest().getRelativePathPrefixToContextRoot(), repositoryName, objectId, null)).setVisible(GitBlit.self().settings().getBoolean(Keys.web.allowZipDownloads, true)));
  57. // Parent Commits
  58. ListDataProvider<String> parentsDp = new ListDataProvider<String>(parents);
  59. DataView<String> parentsView = new DataView<String>("commitParents", parentsDp) {
  60. private static final long serialVersionUID = 1L;
  61. public void populateItem(final Item<String> item) {
  62. String entry = item.getModelObject();
  63. item.add(new LinkPanel("commitParent", "list", entry, CommitPage.class, newCommitParameter(entry)));
  64. item.add(new BookmarkablePageLink<Void>("view", CommitPage.class, newCommitParameter(entry)));
  65. item.add(new BookmarkablePageLink<Void>("diff", CommitDiffPage.class, newCommitParameter(entry)));
  66. }
  67. };
  68. add(parentsView);
  69. addFullText("fullMessage", c.getFullMessage(), true);
  70. // changed paths list
  71. List<PathChangeModel> paths = JGitUtils.getFilesInCommit(r, c);
  72. add(new CommitLegendPanel("commitLegend", paths));
  73. ListDataProvider<PathChangeModel> pathsDp = new ListDataProvider<PathChangeModel>(paths);
  74. DataView<PathChangeModel> pathsView = new DataView<PathChangeModel>("changedPath", pathsDp) {
  75. private static final long serialVersionUID = 1L;
  76. int counter = 0;
  77. public void populateItem(final Item<PathChangeModel> item) {
  78. final PathChangeModel entry = item.getModelObject();
  79. Label changeType = new Label("changeType", "");
  80. WicketUtils.setChangeTypeCssClass(changeType, entry.changeType);
  81. setChangeTypeTooltip(changeType, entry.changeType);
  82. item.add(changeType);
  83. if (entry.isTree()) {
  84. item.add(new LinkPanel("pathName", null, entry.path, TreePage.class, newPathParameter(entry.path)));
  85. } else {
  86. item.add(new LinkPanel("pathName", "list", entry.path, BlobPage.class, newPathParameter(entry.path)));
  87. }
  88. item.add(new BookmarkablePageLink<Void>("diff", BlobDiffPage.class, newPathParameter(entry.path)));
  89. item.add(new BookmarkablePageLink<Void>("view", BlobPage.class, newPathParameter(entry.path)));
  90. item.add(new BookmarkablePageLink<Void>("blame", BlobPage.class).setEnabled(false));
  91. item.add(new BookmarkablePageLink<Void>("history", HistoryPage.class, newPathParameter(entry.path)));
  92. WicketUtils.setAlternatingBackground(item, counter);
  93. counter++;
  94. }
  95. };
  96. add(pathsView);
  97. }
  98. @Override
  99. protected String getPageName() {
  100. return getString("gb.commit");
  101. }
  102. }