Nevar pievienot vairāk kā 25 tēmas Tēmai ir jāsākas ar burtu vai ciparu, tā var saturēt domu zīmes ('-') un var būt līdz 35 simboliem gara.

CommitPage.java 5.9KB

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