James Moger
2015-11-22 ed552ba47c02779c270ffd62841d6d1048dade70
commit | author | age
f13c4c 1 /*
JM 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  */
698678 16 package com.gitblit.wicket.panels;
JM 17
18 import java.util.Date;
19 import java.util.List;
20 import java.util.Map;
21
f084f4 22 import org.apache.wicket.MarkupContainer;
JM 23 import org.apache.wicket.behavior.SimpleAttributeModifier;
24 import org.apache.wicket.markup.html.WebMarkupContainer;
698678 25 import org.apache.wicket.markup.html.basic.Label;
JM 26 import org.apache.wicket.markup.html.link.BookmarkablePageLink;
27 import org.apache.wicket.markup.repeater.Item;
28 import org.apache.wicket.markup.repeater.data.DataView;
29 import org.apache.wicket.markup.repeater.data.ListDataProvider;
30 import org.apache.wicket.model.StringResourceModel;
31 import org.eclipse.jgit.lib.ObjectId;
32 import org.eclipse.jgit.lib.Repository;
33 import org.eclipse.jgit.revwalk.RevCommit;
34
33d8d8 35 import com.gitblit.Constants;
155bf7 36 import com.gitblit.Keys;
4ab184 37 import com.gitblit.models.RefModel;
7bf6e1 38 import com.gitblit.servlet.BranchGraphServlet;
698678 39 import com.gitblit.utils.JGitUtils;
87cc1e 40 import com.gitblit.utils.StringUtils;
f084f4 41 import com.gitblit.wicket.ExternalImage;
698678 42 import com.gitblit.wicket.WicketUtils;
608ece 43 import com.gitblit.wicket.pages.CommitDiffPage;
155bf7 44 import com.gitblit.wicket.pages.CommitPage;
4e1930 45 import com.gitblit.wicket.pages.GitSearchPage;
fd9d28 46 import com.gitblit.wicket.pages.LogPage;
698678 47 import com.gitblit.wicket.pages.TreePage;
JM 48
bc10f9 49 public class LogPanel extends BasePanel {
698678 50
JM 51     private static final long serialVersionUID = 1L;
52
2a7306 53     private boolean hasMore;
JM 54
55     public LogPanel(String wicketId, final String repositoryName, final String objectId,
1e1b85 56             Repository r, int limit, int pageOffset, boolean showRemoteRefs) {
698678 57         super(wicketId);
50984c 58         boolean pageResults = limit <= 0;
99d0d4 59         int itemsPerPage = app().settings().getInteger(Keys.web.itemsPerPage, 50);
66c29a 60         if (itemsPerPage <= 1) {
JM 61             itemsPerPage = 50;
62         }
bc10f9 63
1e1b85 64         final Map<ObjectId, List<RefModel>> allRefs = JGitUtils.getAllRefs(r, showRemoteRefs);
ef5c58 65         List<RevCommit> commits;
JM 66         if (pageResults) {
67             // Paging result set
50984c 68             commits = JGitUtils.getRevLog(r, objectId, pageOffset * itemsPerPage, itemsPerPage);
ef5c58 69         } else {
JM 70             // Fixed size result set
71             commits = JGitUtils.getRevLog(r, objectId, 0, limit);
72         }
f602a2 73
JM 74         // inaccurate way to determine if there are more commits.
2a7306 75         // works unless commits.size() represents the exact end.
f602a2 76         hasMore = commits.size() >= itemsPerPage;
699e71 77
f084f4 78         final String baseUrl = WicketUtils.getGitblitURL(getRequest());
99d0d4 79         final boolean showGraph = app().settings().getBoolean(Keys.web.showBranchGraph, true);
699e71 80
f084f4 81         MarkupContainer graph = new WebMarkupContainer("graph");
JM 82         add(graph);
83         if (!showGraph || commits.isEmpty()) {
84             // not showing or nothing to show
85             graph.setVisible(false);
86         } else {
87             // set the rowspan on the graph row and +1 for the graph row itself
88             graph.add(new SimpleAttributeModifier("rowspan", "" + (commits.size() + 1)));
89             graph.add(new ExternalImage("image", BranchGraphServlet.asLink(baseUrl, repositoryName, commits.get(0).name(), commits.size())));
90         }
698678 91
JM 92         // header
ef5c58 93         if (pageResults) {
698678 94             // shortlog page
a45caa 95             add(new Label("header", objectId));
698678 96         } else {
JM 97             // summary page
98             // show shortlog page link
9c4725 99             add(new LinkPanel("header", "title", objectId, LogPage.class,
JM 100                     WicketUtils.newRepositoryParameter(repositoryName)));
698678 101         }
JM 102
99d0d4 103         final int hashLen = app().settings().getInteger(Keys.web.shortCommitIdLength, 6);
698678 104         ListDataProvider<RevCommit> dp = new ListDataProvider<RevCommit>(commits);
JM 105         DataView<RevCommit> logView = new DataView<RevCommit>("commit", dp) {
106             private static final long serialVersionUID = 1L;
2a7306 107             int counter;
698678 108
699e71 109             @Override
698678 110             public void populateItem(final Item<RevCommit> item) {
JM 111                 final RevCommit entry = item.getModelObject();
a59232 112                 final Date date = JGitUtils.getAuthorDate(entry);
590249 113                 final boolean isMerge = entry.getParentCount() > 1;
698678 114
9adf62 115                 item.add(WicketUtils.createDateLabel("commitDate", date, getTimeZone(), getTimeUtils()));
698678 116
98ce17 117                 // author search link
698678 118                 String author = entry.getAuthorIdent().getName();
2a7306 119                 LinkPanel authorLink = new LinkPanel("commitAuthor", "list", author,
4e1930 120                         GitSearchPage.class, WicketUtils.newSearchParameter(repositoryName,
4fb2c0 121                                 null, author, Constants.SearchType.AUTHOR));
33d8d8 122                 setPersonSearchTooltip(authorLink, author, Constants.SearchType.AUTHOR);
98ce17 123                 item.add(authorLink);
699e71 124
a645ba 125                 // merge icon
590249 126                 if (isMerge) {
1e8390 127                     item.add(WicketUtils.newImage("commitIcon", "commit_merge_16x16.png"));
a645ba 128                 } else {
1e8390 129                     item.add(WicketUtils.newBlankImage("commitIcon"));
a645ba 130                 }
2a7306 131
a645ba 132                 // short message
698678 133                 String shortMessage = entry.getShortMessage();
a45caa 134                 String trimmedMessage = shortMessage;
JM 135                 if (allRefs.containsKey(entry.getId())) {
136                     trimmedMessage = StringUtils.trimString(shortMessage, Constants.LEN_SHORTLOG_REFS);
137                 } else {
138                     trimmedMessage = StringUtils.trimString(shortMessage, Constants.LEN_SHORTLOG);
139                 }
590249 140                 LinkPanel shortlog = new LinkPanel("commitShortMessage", "list subject" + (isMerge ? " merge" : ""),
2a7306 141                         trimmedMessage, CommitPage.class, WicketUtils.newObjectParameter(
JM 142                                 repositoryName, entry.getName()));
698678 143                 if (!shortMessage.equals(trimmedMessage)) {
1e8390 144                     WicketUtils.setHtmlTooltip(shortlog, shortMessage);
698678 145                 }
JM 146                 item.add(shortlog);
147
7d35e2 148                 item.add(new RefsPanel("commitRefs", repositoryName, entry, allRefs));
698678 149
75705a 150                 // commit hash link
JM 151                 LinkPanel commitHash = new LinkPanel("hashLink", null, entry.getName().substring(0, hashLen),
152                         CommitPage.class, WicketUtils.newObjectParameter(
153                                 repositoryName, entry.getName()));
87d72e 154                 WicketUtils.setCssClass(commitHash, "shortsha1");
75705a 155                 WicketUtils.setHtmlTooltip(commitHash, entry.getName());
JM 156                 item.add(commitHash);
699e71 157
2a7306 158                 item.add(new BookmarkablePageLink<Void>("diff", CommitDiffPage.class, WicketUtils
008322 159                         .newObjectParameter(repositoryName, entry.getName())).setEnabled(entry
JM 160                         .getParentCount() > 0));
2a7306 161                 item.add(new BookmarkablePageLink<Void>("tree", TreePage.class, WicketUtils
JM 162                         .newObjectParameter(repositoryName, entry.getName())));
698678 163
b932aa 164                 String clazz = counter % 2 == 0 ? "light commit" : "dark commit";
JM 165                 WicketUtils.setCssClass(item, clazz);
166
698678 167                 counter++;
JM 168             }
169         };
50984c 170         add(logView);
698678 171
JM 172         // determine to show pager, more, or neither
ef5c58 173         if (limit <= 0) {
698678 174             // no display limit
JM 175             add(new Label("moreLogs", "").setVisible(false));
50984c 176         } else {
ef5c58 177             if (pageResults) {
698678 178                 // paging
JM 179                 add(new Label("moreLogs", "").setVisible(false));
180             } else {
181                 // more
ef5c58 182                 if (commits.size() == limit) {
698678 183                     // show more
2a7306 184                     add(new LinkPanel("moreLogs", "link", new StringResourceModel("gb.moreLogs",
JM 185                             this, null), LogPage.class,
186                             WicketUtils.newRepositoryParameter(repositoryName)));
698678 187                 } else {
JM 188                     // no more
189                     add(new Label("moreLogs", "").setVisible(false));
190                 }
191             }
192         }
193     }
2a7306 194
f602a2 195     public boolean hasMore() {
JM 196         return hasMore;
197     }
698678 198 }