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.

HistoryPanel.java 6.8KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186
  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.panels;
  17. import java.util.Date;
  18. import java.util.List;
  19. import java.util.Map;
  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.panel.Fragment;
  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.ObjectId;
  28. import org.eclipse.jgit.lib.Repository;
  29. import org.eclipse.jgit.revwalk.RevCommit;
  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.utils.StringUtils;
  35. import com.gitblit.wicket.LinkPanel;
  36. import com.gitblit.wicket.WicketUtils;
  37. import com.gitblit.wicket.models.PathModel;
  38. import com.gitblit.wicket.models.PathModel.PathChangeModel;
  39. import com.gitblit.wicket.pages.BlobDiffPage;
  40. import com.gitblit.wicket.pages.BlobPage;
  41. import com.gitblit.wicket.pages.CommitDiffPage;
  42. import com.gitblit.wicket.pages.CommitPage;
  43. import com.gitblit.wicket.pages.HistoryPage;
  44. import com.gitblit.wicket.pages.SearchPage;
  45. import com.gitblit.wicket.pages.TreePage;
  46. public class HistoryPanel extends BasePanel {
  47. private static final long serialVersionUID = 1L;
  48. private boolean hasMore;
  49. public HistoryPanel(String wicketId, final String repositoryName, final String objectId,
  50. final String path, Repository r, int limit, int pageOffset) {
  51. super(wicketId);
  52. boolean pageResults = limit <= 0;
  53. int itemsPerPage = GitBlit.getInteger(Keys.web.itemsPerPage, 50);
  54. if (itemsPerPage <= 1) {
  55. itemsPerPage = 50;
  56. }
  57. RevCommit commit = JGitUtils.getCommit(r, objectId);
  58. List<PathChangeModel> paths = JGitUtils.getFilesInCommit(r, commit);
  59. PathModel matchingPath = null;
  60. for (PathModel p : paths) {
  61. if (p.path.equals(path)) {
  62. matchingPath = p;
  63. break;
  64. }
  65. }
  66. final boolean isTree = matchingPath == null ? true : matchingPath.isTree();
  67. final Map<ObjectId, List<String>> allRefs = JGitUtils.getAllRefs(r);
  68. List<RevCommit> commits;
  69. if (pageResults) {
  70. // Paging result set
  71. commits = JGitUtils.getRevLog(r, objectId, path, pageOffset * itemsPerPage,
  72. itemsPerPage);
  73. } else {
  74. // Fixed size result set
  75. commits = JGitUtils.getRevLog(r, objectId, path, 0, limit);
  76. }
  77. // inaccurate way to determine if there are more commits.
  78. // works unless commits.size() represents the exact end.
  79. hasMore = commits.size() >= itemsPerPage;
  80. add(new CommitHeaderPanel("commitHeader", repositoryName, commit));
  81. // breadcrumbs
  82. add(new PathBreadcrumbsPanel("breadcrumbs", repositoryName, path, objectId));
  83. ListDataProvider<RevCommit> dp = new ListDataProvider<RevCommit>(commits);
  84. DataView<RevCommit> logView = new DataView<RevCommit>("commit", dp) {
  85. private static final long serialVersionUID = 1L;
  86. int counter;
  87. public void populateItem(final Item<RevCommit> item) {
  88. final RevCommit entry = item.getModelObject();
  89. final Date date = JGitUtils.getCommitDate(entry);
  90. item.add(WicketUtils.createDateLabel("commitDate", date, getTimeZone()));
  91. // author search link
  92. String author = entry.getAuthorIdent().getName();
  93. LinkPanel authorLink = new LinkPanel("commitAuthor", "list", author,
  94. SearchPage.class, WicketUtils.newSearchParameter(repositoryName, objectId,
  95. author, SearchType.AUTHOR));
  96. setPersonSearchTooltip(authorLink, author, SearchType.AUTHOR);
  97. item.add(authorLink);
  98. // merge icon
  99. if (entry.getParentCount() > 1) {
  100. item.add(WicketUtils.newImage("commitIcon", "commit_merge_16x16.png"));
  101. } else {
  102. item.add(WicketUtils.newBlankImage("commitIcon"));
  103. }
  104. String shortMessage = entry.getShortMessage();
  105. String trimmedMessage = StringUtils.trimShortLog(shortMessage);
  106. LinkPanel shortlog = new LinkPanel("commitShortMessage", "list subject",
  107. trimmedMessage, CommitPage.class, WicketUtils.newObjectParameter(
  108. repositoryName, entry.getName()));
  109. if (!shortMessage.equals(trimmedMessage)) {
  110. WicketUtils.setHtmlTooltip(shortlog, shortMessage);
  111. }
  112. item.add(shortlog);
  113. item.add(new RefsPanel("commitRefs", repositoryName, entry, allRefs));
  114. if (isTree) {
  115. Fragment links = new Fragment("historyLinks", "treeLinks", this);
  116. links.add(new BookmarkablePageLink<Void>("tree", TreePage.class, WicketUtils
  117. .newObjectParameter(repositoryName, entry.getName())));
  118. links.add(new BookmarkablePageLink<Void>("commitdiff", CommitDiffPage.class,
  119. WicketUtils.newObjectParameter(repositoryName, entry.getName())));
  120. item.add(links);
  121. } else {
  122. Fragment links = new Fragment("historyLinks", "blobLinks", this);
  123. links.add(new BookmarkablePageLink<Void>("view", BlobPage.class, WicketUtils
  124. .newPathParameter(repositoryName, entry.getName(), path)));
  125. links.add(new BookmarkablePageLink<Void>("commitdiff", CommitDiffPage.class,
  126. WicketUtils.newObjectParameter(repositoryName, entry.getName())));
  127. links.add(new BookmarkablePageLink<Void>("difftocurrent", BlobDiffPage.class,
  128. WicketUtils.newBlobDiffParameter(repositoryName, entry.getName(),
  129. objectId, path)).setEnabled(counter > 0));
  130. item.add(links);
  131. }
  132. WicketUtils.setAlternatingBackground(item, counter);
  133. counter++;
  134. }
  135. };
  136. add(logView);
  137. // determine to show pager, more, or neither
  138. if (limit <= 0) {
  139. // no display limit
  140. add(new Label("moreHistory", "").setVisible(false));
  141. } else {
  142. if (pageResults) {
  143. // paging
  144. add(new Label("moreHistory", "").setVisible(false));
  145. } else {
  146. // more
  147. if (commits.size() == limit) {
  148. // show more
  149. add(new LinkPanel("moreHistory", "link", new StringResourceModel(
  150. "gb.moreHistory", this, null), HistoryPage.class,
  151. WicketUtils.newPathParameter(repositoryName, objectId, path)));
  152. } else {
  153. // no more
  154. add(new Label("moreHistory", "").setVisible(false));
  155. }
  156. }
  157. }
  158. }
  159. public boolean hasMore() {
  160. return hasMore;
  161. }
  162. }