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 10KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253
  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.Arrays;
  19. import java.util.List;
  20. import org.apache.wicket.PageParameters;
  21. import org.apache.wicket.markup.html.basic.Label;
  22. import org.apache.wicket.markup.html.link.BookmarkablePageLink;
  23. import org.apache.wicket.markup.html.link.ExternalLink;
  24. import org.apache.wicket.markup.repeater.Item;
  25. import org.apache.wicket.markup.repeater.data.DataView;
  26. import org.apache.wicket.markup.repeater.data.ListDataProvider;
  27. import org.apache.wicket.model.StringResourceModel;
  28. import org.eclipse.jgit.diff.DiffEntry.ChangeType;
  29. import org.eclipse.jgit.lib.Repository;
  30. import org.eclipse.jgit.revwalk.RevCommit;
  31. import com.gitblit.Constants;
  32. import com.gitblit.models.GitNote;
  33. import com.gitblit.models.PathModel.PathChangeModel;
  34. import com.gitblit.models.SubmoduleModel;
  35. import com.gitblit.utils.JGitUtils;
  36. import com.gitblit.wicket.CacheControl;
  37. import com.gitblit.wicket.CacheControl.LastModified;
  38. import com.gitblit.wicket.WicketUtils;
  39. import com.gitblit.wicket.panels.CommitHeaderPanel;
  40. import com.gitblit.wicket.panels.CommitLegendPanel;
  41. import com.gitblit.wicket.panels.CompressedDownloadsPanel;
  42. import com.gitblit.wicket.panels.DiffStatPanel;
  43. import com.gitblit.wicket.panels.GravatarImage;
  44. import com.gitblit.wicket.panels.LinkPanel;
  45. import com.gitblit.wicket.panels.RefsPanel;
  46. @CacheControl(LastModified.BOOT)
  47. public class CommitPage extends RepositoryPage {
  48. public CommitPage(PageParameters params) {
  49. super(params);
  50. Repository r = getRepository();
  51. RevCommit c = getCommit();
  52. List<String> parents = new ArrayList<String>();
  53. if (c.getParentCount() > 0) {
  54. for (RevCommit parent : c.getParents()) {
  55. parents.add(parent.name());
  56. }
  57. }
  58. // commit page links
  59. if (parents.size() == 0) {
  60. add(new Label("parentLink", "none"));
  61. add(new Label("commitdiffLink", getString("gb.commitdiff")));
  62. } else {
  63. add(new LinkPanel("parentLink", null, getShortObjectId(parents.get(0)),
  64. CommitPage.class, newCommitParameter(parents.get(0))));
  65. add(new LinkPanel("commitdiffLink", null, new StringResourceModel("gb.commitdiff",
  66. this, null), CommitDiffPage.class, WicketUtils.newObjectParameter(
  67. repositoryName, objectId)));
  68. }
  69. add(new BookmarkablePageLink<Void>("patchLink", PatchPage.class,
  70. WicketUtils.newObjectParameter(repositoryName, objectId)));
  71. add(new CommitHeaderPanel("commitHeader", repositoryName, c));
  72. addRefs(r, c);
  73. // author
  74. add(createPersonPanel("commitAuthor", c.getAuthorIdent(), Constants.SearchType.AUTHOR));
  75. add(WicketUtils.createTimestampLabel("commitAuthorDate", c.getAuthorIdent().getWhen(),
  76. getTimeZone(), getTimeUtils()));
  77. // committer
  78. add(createPersonPanel("commitCommitter", c.getCommitterIdent(), Constants.SearchType.COMMITTER));
  79. add(WicketUtils.createTimestampLabel("commitCommitterDate",
  80. c.getCommitterIdent().getWhen(), getTimeZone(), getTimeUtils()));
  81. add(new Label("commitId", c.getName()));
  82. add(new LinkPanel("commitTree", "list", c.getTree().getName(), TreePage.class,
  83. newCommitParameter()));
  84. add(new BookmarkablePageLink<Void>("treeLink", TreePage.class, newCommitParameter()));
  85. final String baseUrl = WicketUtils.getGitblitURL(getRequest());
  86. add(new CompressedDownloadsPanel("compressedLinks", baseUrl, repositoryName, objectId, null));
  87. // Parent Commits
  88. ListDataProvider<String> parentsDp = new ListDataProvider<String>(parents);
  89. DataView<String> parentsView = new DataView<String>("commitParents", parentsDp) {
  90. private static final long serialVersionUID = 1L;
  91. @Override
  92. public void populateItem(final Item<String> item) {
  93. String entry = item.getModelObject();
  94. item.add(new LinkPanel("commitParent", "list", entry, CommitPage.class,
  95. newCommitParameter(entry)));
  96. item.add(new BookmarkablePageLink<Void>("view", CommitPage.class,
  97. newCommitParameter(entry)));
  98. item.add(new BookmarkablePageLink<Void>("diff", CommitDiffPage.class,
  99. newCommitParameter(entry)));
  100. }
  101. };
  102. add(parentsView);
  103. addFullText("fullMessage", c.getFullMessage());
  104. // git notes
  105. List<GitNote> notes = JGitUtils.getNotesOnCommit(r, c);
  106. ListDataProvider<GitNote> notesDp = new ListDataProvider<GitNote>(notes);
  107. DataView<GitNote> notesView = new DataView<GitNote>("notes", notesDp) {
  108. private static final long serialVersionUID = 1L;
  109. @Override
  110. public void populateItem(final Item<GitNote> item) {
  111. GitNote entry = item.getModelObject();
  112. item.add(new RefsPanel("refName", repositoryName, Arrays.asList(entry.notesRef)));
  113. item.add(createPersonPanel("authorName", entry.notesRef.getAuthorIdent(),
  114. Constants.SearchType.AUTHOR));
  115. item.add(new GravatarImage("noteAuthorAvatar", entry.notesRef.getAuthorIdent()));
  116. item.add(WicketUtils.createTimestampLabel("authorDate", entry.notesRef
  117. .getAuthorIdent().getWhen(), getTimeZone(), getTimeUtils()));
  118. item.add(new Label("noteContent", messageProcessor().processPlainCommitMessage(getRepository(), repositoryName,
  119. entry.content)).setEscapeModelStrings(false));
  120. }
  121. };
  122. add(notesView.setVisible(notes.size() > 0));
  123. // changed paths list
  124. List<PathChangeModel> paths = JGitUtils.getFilesInCommit(r, c);
  125. // add commit diffstat
  126. int insertions = 0;
  127. int deletions = 0;
  128. for (PathChangeModel pcm : paths) {
  129. insertions += pcm.insertions;
  130. deletions += pcm.deletions;
  131. }
  132. add(new DiffStatPanel("diffStat", insertions, deletions));
  133. add(new CommitLegendPanel("commitLegend", paths));
  134. ListDataProvider<PathChangeModel> pathsDp = new ListDataProvider<PathChangeModel>(paths);
  135. DataView<PathChangeModel> pathsView = new DataView<PathChangeModel>("changedPath", pathsDp) {
  136. private static final long serialVersionUID = 1L;
  137. int counter;
  138. @Override
  139. public void populateItem(final Item<PathChangeModel> item) {
  140. final PathChangeModel entry = item.getModelObject();
  141. Label changeType = new Label("changeType", "");
  142. WicketUtils.setChangeTypeCssClass(changeType, entry.changeType);
  143. setChangeTypeTooltip(changeType, entry.changeType);
  144. item.add(changeType);
  145. item.add(new DiffStatPanel("diffStat", entry.insertions, entry.deletions, true));
  146. boolean hasSubmodule = false;
  147. String submodulePath = null;
  148. if (entry.isTree()) {
  149. // tree
  150. item.add(new LinkPanel("pathName", null, entry.path, TreePage.class,
  151. WicketUtils
  152. .newPathParameter(repositoryName, entry.commitId, entry.path)));
  153. } else if (entry.isSubmodule()) {
  154. // submodule
  155. String submoduleId = entry.objectId;
  156. SubmoduleModel submodule = getSubmodule(entry.path);
  157. submodulePath = submodule.gitblitPath;
  158. hasSubmodule = submodule.hasSubmodule;
  159. item.add(new LinkPanel("pathName", "list", entry.path + " @ " +
  160. getShortObjectId(submoduleId), TreePage.class,
  161. WicketUtils.newPathParameter(submodulePath, submoduleId, "")).setEnabled(hasSubmodule));
  162. } else {
  163. // blob
  164. String displayPath = entry.path;
  165. String path = entry.path;
  166. if (entry.isSymlink()) {
  167. path = JGitUtils.getStringContent(getRepository(), getCommit().getTree(), path);
  168. displayPath = entry.path + " -> " + path;
  169. }
  170. item.add(new LinkPanel("pathName", "list", displayPath, BlobPage.class,
  171. WicketUtils
  172. .newPathParameter(repositoryName, entry.commitId, path)));
  173. }
  174. // quick links
  175. if (entry.isSubmodule()) {
  176. item.add(new ExternalLink("raw", "").setEnabled(false));
  177. // submodule
  178. item.add(new BookmarkablePageLink<Void>("diff", BlobDiffPage.class, WicketUtils
  179. .newPathParameter(repositoryName, entry.commitId, entry.path))
  180. .setEnabled(!entry.changeType.equals(ChangeType.ADD)));
  181. item.add(new BookmarkablePageLink<Void>("view", CommitPage.class, WicketUtils
  182. .newObjectParameter(submodulePath, entry.objectId)).setEnabled(hasSubmodule));
  183. item.add(new ExternalLink("blame", "").setEnabled(false));
  184. item.add(new BookmarkablePageLink<Void>("history", HistoryPage.class, WicketUtils
  185. .newPathParameter(repositoryName, entry.commitId, entry.path))
  186. .setEnabled(!entry.changeType.equals(ChangeType.ADD)));
  187. } else {
  188. // tree or blob
  189. item.add(new BookmarkablePageLink<Void>("diff", BlobDiffPage.class, WicketUtils
  190. .newPathParameter(repositoryName, entry.commitId, entry.path))
  191. .setEnabled(!entry.changeType.equals(ChangeType.ADD)
  192. && !entry.changeType.equals(ChangeType.DELETE)));
  193. item.add(new BookmarkablePageLink<Void>("view", BlobPage.class, WicketUtils
  194. .newPathParameter(repositoryName, entry.commitId, entry.path))
  195. .setEnabled(!entry.changeType.equals(ChangeType.DELETE)));
  196. item.add(new BookmarkablePageLink<Void>("raw", RawPage.class, WicketUtils
  197. .newPathParameter(repositoryName, entry.commitId, entry.path))
  198. .setEnabled(!entry.changeType.equals(ChangeType.DELETE)));
  199. item.add(new BookmarkablePageLink<Void>("blame", BlamePage.class, WicketUtils
  200. .newPathParameter(repositoryName, entry.commitId, entry.path))
  201. .setEnabled(!entry.changeType.equals(ChangeType.ADD)
  202. && !entry.changeType.equals(ChangeType.DELETE)));
  203. item.add(new BookmarkablePageLink<Void>("history", HistoryPage.class, WicketUtils
  204. .newPathParameter(repositoryName, entry.commitId, entry.path))
  205. .setEnabled(!entry.changeType.equals(ChangeType.ADD)));
  206. }
  207. WicketUtils.setAlternatingBackground(item, counter);
  208. counter++;
  209. }
  210. };
  211. add(pathsView);
  212. }
  213. @Override
  214. protected String getPageName() {
  215. return getString("gb.commit");
  216. }
  217. @Override
  218. protected Class<? extends BasePage> getRepoNavPageClass() {
  219. return LogPage.class;
  220. }
  221. }