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.

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