blob: 71f7384f79a3e107e24e3a775644f89574dd6e85 [file] [log] [blame]
Dave Borowitz9de65952012-08-13 16:09:45 -07001// Copyright 2012 Google Inc. All Rights Reserved.
2//
3// Licensed under the Apache License, Version 2.0 (the "License");
4// you may not use this file except in compliance with the License.
5// You may obtain a copy of the License at
6//
7// http://www.apache.org/licenses/LICENSE-2.0
8//
9// Unless required by applicable law or agreed to in writing, software
10// distributed under the License is distributed on an "AS IS" BASIS,
11// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12// See the License for the specific language governing permissions and
13// limitations under the License.
14
15package com.google.gitiles;
16
Dave Borowitz9de65952012-08-13 16:09:45 -070017import static com.google.common.base.Preconditions.checkNotNull;
Dave Borowitz9de65952012-08-13 16:09:45 -070018
Dave Borowitz80334b22013-01-11 14:19:11 -080019import com.google.common.base.Strings;
20import com.google.common.collect.Iterables;
21import com.google.common.collect.ListMultimap;
22import com.google.common.collect.Lists;
Dave Borowitzef055812013-11-01 12:05:55 -070023import com.google.common.collect.Maps;
Paweł Hajdan, Jrf7cd3372015-10-15 12:30:46 +020024import com.google.common.collect.Sets;
Dave Borowitzef055812013-11-01 12:05:55 -070025import com.google.common.primitives.Longs;
Paweł Hajdan, Jrf7cd3372015-10-15 12:30:46 +020026import com.google.gitiles.CommitData.Field;
Dave Borowitz2b2f34b2014-04-29 16:47:20 -070027import com.google.gitiles.DateFormatter.Format;
Masaya Suzuki5cecb862019-03-25 17:35:44 -070028import com.google.gitiles.GitilesRequestFailureException.FailureReason;
Dave Borowitzd6ebc2d2013-11-01 11:44:06 -070029import com.google.gson.reflect.TypeToken;
Dave Borowitz3b744b12016-08-19 16:11:10 -040030import java.io.IOException;
31import java.io.OutputStream;
32import java.io.Writer;
33import java.util.ArrayList;
34import java.util.Collection;
35import java.util.List;
36import java.util.Map;
David Pursehouse7a7f5472016-10-14 09:59:20 +090037import java.util.Optional;
Dave Borowitz3b744b12016-08-19 16:11:10 -040038import java.util.Set;
Matthias Sohnc156c962023-09-30 22:15:23 +020039import javax.annotation.Nullable;
Dave Borowitz3b744b12016-08-19 16:11:10 -040040import javax.servlet.http.HttpServletRequest;
41import javax.servlet.http.HttpServletResponse;
Dave Borowitz344c4dd2015-10-26 11:02:13 -040042import org.eclipse.jgit.diff.DiffConfig;
Dave Borowitz9de65952012-08-13 16:09:45 -070043import org.eclipse.jgit.errors.IncorrectObjectTypeException;
44import org.eclipse.jgit.errors.MissingObjectException;
Dave Borowitz9de65952012-08-13 16:09:45 -070045import org.eclipse.jgit.http.server.ServletUtils;
46import org.eclipse.jgit.lib.AbbreviatedObjectId;
Dave Borowitz80334b22013-01-11 14:19:11 -080047import org.eclipse.jgit.lib.Constants;
Dave Borowitz9de65952012-08-13 16:09:45 -070048import org.eclipse.jgit.lib.ObjectId;
49import org.eclipse.jgit.lib.ObjectReader;
50import org.eclipse.jgit.lib.Ref;
51import org.eclipse.jgit.lib.Repository;
Dave Borowitz344c4dd2015-10-26 11:02:13 -040052import org.eclipse.jgit.revwalk.FollowFilter;
Dave Borowitzd6ebc2d2013-11-01 11:44:06 -070053import org.eclipse.jgit.revwalk.RevCommit;
Dave Borowitz9de65952012-08-13 16:09:45 -070054import org.eclipse.jgit.revwalk.RevObject;
Shawn Pearce31037672016-08-18 21:44:43 -070055import org.eclipse.jgit.revwalk.RevSort;
Dave Borowitz9de65952012-08-13 16:09:45 -070056import org.eclipse.jgit.revwalk.RevTag;
57import org.eclipse.jgit.revwalk.RevWalk;
Shawn Pearce20b42292015-03-17 21:53:55 -070058import org.eclipse.jgit.revwalk.filter.AndRevFilter;
59import org.eclipse.jgit.revwalk.filter.RevFilter;
Xing Huang06b65fd2025-03-10 12:50:09 -050060import org.eclipse.jgit.treewalk.filter.ChangedPathTreeFilter;
Shawn Pearce20b42292015-03-17 21:53:55 -070061import org.eclipse.jgit.util.StringUtils;
Dave Borowitz9de65952012-08-13 16:09:45 -070062
Dave Borowitz9de65952012-08-13 16:09:45 -070063/** Serves an HTML page with a shortlog for commits and paths. */
64public class LogServlet extends BaseServlet {
Chad Horohoead23f142012-11-12 09:45:39 -080065 private static final long serialVersionUID = 1L;
Dave Borowitz9de65952012-08-13 16:09:45 -070066
Dave Borowitzef055812013-11-01 12:05:55 -070067 static final String LIMIT_PARAM = "n";
Dave Borowitzb772cce2012-12-28 13:57:22 -080068 static final String START_PARAM = "s";
Dave Borowitz344c4dd2015-10-26 11:02:13 -040069
70 private static final String FOLLOW_PARAM = "follow";
Paweł Hajdan, Jrf7cd3372015-10-15 12:30:46 +020071 private static final String NAME_STATUS_PARAM = "name-status";
Dave Borowitz344c4dd2015-10-26 11:02:13 -040072 private static final String PRETTY_PARAM = "pretty";
Alex Spradlin284a35a2019-07-09 16:02:55 -070073 private static final String TOPO_ORDER_PARAM = "topo-order";
74 private static final String REVERSE_PARAM = "reverse";
75 private static final String FIRST_PARENT_PARAM = "first-parent";
Dave Borowitz344c4dd2015-10-26 11:02:13 -040076
Dave Borowitzef055812013-11-01 12:05:55 -070077 private static final int DEFAULT_LIMIT = 100;
78 private static final int MAX_LIMIT = 10000;
Dave Borowitz9de65952012-08-13 16:09:45 -070079
80 private final Linkifier linkifier;
Dave Borowitz9de65952012-08-13 16:09:45 -070081
Dave Borowitz2b2f34b2014-04-29 16:47:20 -070082 public LogServlet(GitilesAccess.Factory accessFactory, Renderer renderer, Linkifier linkifier) {
Dave Borowitz8d6d6872014-03-16 15:18:14 -070083 super(renderer, accessFactory);
Dave Borowitz9de65952012-08-13 16:09:45 -070084 this.linkifier = checkNotNull(linkifier, "linkifier");
Dave Borowitz9de65952012-08-13 16:09:45 -070085 }
86
87 @Override
Dave Borowitz80334b22013-01-11 14:19:11 -080088 protected void doGetHtml(HttpServletRequest req, HttpServletResponse res) throws IOException {
Dave Borowitz9de65952012-08-13 16:09:45 -070089 Repository repo = ServletUtils.getRepository(req);
Dave Borowitz80334b22013-01-11 14:19:11 -080090 GitilesView view = getView(req, repo);
Dave Borowitz80334b22013-01-11 14:19:11 -080091
Dave Borowitz344c4dd2015-10-26 11:02:13 -040092 Paginator paginator = null;
Dave Borowitz9de65952012-08-13 16:09:45 -070093 try {
Dave Borowitz2b2f34b2014-04-29 16:47:20 -070094 GitilesAccess access = getAccess(req);
Shawn Pearce31037672016-08-18 21:44:43 -070095 paginator = newPaginator(repo, view, access);
Dave Borowitz344c4dd2015-10-26 11:02:13 -040096 if (paginator == null) {
Masaya Suzuki5cecb862019-03-25 17:35:44 -070097 throw new GitilesRequestFailureException(FailureReason.OBJECT_NOT_FOUND);
Dave Borowitz344c4dd2015-10-26 11:02:13 -040098 }
Dave Borowitz2b2f34b2014-04-29 16:47:20 -070099 DateFormatter df = new DateFormatter(access, Format.DEFAULT);
Michael Moss558f8642014-04-15 09:29:21 -0700100
101 // Allow the user to select a logView variant with the "pretty" param.
102 String pretty = Iterables.getFirst(view.getParameters().get(PRETTY_PARAM), "default");
Dave Borowitzf6dcf7a2014-07-30 10:26:58 -0700103 Map<String, Object> data = Maps.newHashMapWithExpectedSize(2);
Dave Borowitz9de65952012-08-13 16:09:45 -0700104
105 if (!view.getRevision().nameIsId()) {
106 List<Map<String, Object>> tags = Lists.newArrayListWithExpectedSize(1);
Dave Borowitz27fada42013-11-01 11:09:49 -0700107 for (RevObject o : RevisionServlet.listObjects(paginator.getWalk(), view.getRevision())) {
Dave Borowitz9de65952012-08-13 16:09:45 -0700108 if (o instanceof RevTag) {
Jonathan Nieder9e3b1b72019-03-07 14:38:28 -0800109 tags.add(new TagSoyData(linkifier, req).toSoyData(paginator.getWalk(), (RevTag) o, df));
Dave Borowitz9de65952012-08-13 16:09:45 -0700110 }
111 }
112 if (!tags.isEmpty()) {
113 data.put("tags", tags);
114 }
115 }
116
Dave Borowitz9de65952012-08-13 16:09:45 -0700117 String title = "Log - ";
David Pursehousec53de2b2019-06-01 15:27:25 +0900118 if (!Revision.isNull(view.getOldRevision())) {
Dave Borowitz9de65952012-08-13 16:09:45 -0700119 title += view.getRevisionRange();
120 } else {
121 title += view.getRevision().getName();
122 }
123
124 data.put("title", title);
Dave Borowitz9de65952012-08-13 16:09:45 -0700125
Sven Selbergd99004c2022-01-31 10:24:08 +0100126 try (OutputStream out =
127 startRenderStreamingHtml(
128 req, res, "com.google.gitiles.templates.LogDetail.logDetail", data)) {
Shawn Pearce4c2eb852014-08-26 15:35:33 -0700129 Writer w = newWriter(out, res);
Dave Borowitz571b7a02018-02-09 15:18:10 -0500130 new LogSoyData(req, access, pretty)
131 .renderStreaming(paginator, null, renderer, w, df, LogSoyData.FooterBehavior.NEXT);
Shawn Pearce4c2eb852014-08-26 15:35:33 -0700132 w.flush();
Dave Borowitzf6dcf7a2014-07-30 10:26:58 -0700133 }
Dave Borowitz9de65952012-08-13 16:09:45 -0700134 } finally {
Dave Borowitz344c4dd2015-10-26 11:02:13 -0400135 if (paginator != null) {
136 paginator.getWalk().close();
137 }
Dave Borowitz9de65952012-08-13 16:09:45 -0700138 }
139 }
140
Dave Borowitzd6ebc2d2013-11-01 11:44:06 -0700141 @Override
142 protected void doGetJson(HttpServletRequest req, HttpServletResponse res) throws IOException {
143 Repository repo = ServletUtils.getRepository(req);
144 GitilesView view = getView(req, repo);
Dave Borowitzd6ebc2d2013-11-01 11:44:06 -0700145
Paweł Hajdan, Jrf7cd3372015-10-15 12:30:46 +0200146 Set<Field> fs = Sets.newEnumSet(CommitJsonData.DEFAULT_FIELDS, Field.class);
147 String nameStatus = Iterables.getFirst(view.getParameters().get(NAME_STATUS_PARAM), null);
148 if ("1".equals(nameStatus) || "".equals(nameStatus)) {
149 fs.add(Field.DIFF_TREE);
150 }
151
Dave Borowitz344c4dd2015-10-26 11:02:13 -0400152 Paginator paginator = null;
Dave Borowitzd6ebc2d2013-11-01 11:44:06 -0700153 try {
Shawn Pearce31037672016-08-18 21:44:43 -0700154 GitilesAccess access = getAccess(req);
155 paginator = newPaginator(repo, view, access);
Dave Borowitz344c4dd2015-10-26 11:02:13 -0400156 if (paginator == null) {
Masaya Suzuki5cecb862019-03-25 17:35:44 -0700157 throw new GitilesRequestFailureException(FailureReason.OBJECT_NOT_FOUND);
Dave Borowitz344c4dd2015-10-26 11:02:13 -0400158 }
Shawn Pearce31037672016-08-18 21:44:43 -0700159 DateFormatter df = new DateFormatter(access, Format.DEFAULT);
Dave Borowitz77cf5f22015-10-26 11:05:07 -0400160 CommitJsonData.Log result = new CommitJsonData.Log();
Dave Borowitzd6ebc2d2013-11-01 11:44:06 -0700161 List<CommitJsonData.Commit> entries = Lists.newArrayListWithCapacity(paginator.getLimit());
162 for (RevCommit c : paginator) {
Xing Huang06b65fd2025-03-10 12:50:09 -0500163 RevWalk walk = paginator.getWalk();
164 if (!walk.isRetainBody()) {
165 walk.parseBody(c);
166 }
Jonathan Niederb49306a2019-03-07 14:10:57 -0800167 entries.add(new CommitJsonData().toJsonData(req, paginator.getWalk(), c, fs, df));
Dave Borowitzd6ebc2d2013-11-01 11:44:06 -0700168 }
Dave Borowitz77cf5f22015-10-26 11:05:07 -0400169 result.log = entries;
Dave Borowitzd6ebc2d2013-11-01 11:44:06 -0700170 if (paginator.getPreviousStart() != null) {
Dave Borowitz77cf5f22015-10-26 11:05:07 -0400171 result.previous = paginator.getPreviousStart().name();
Dave Borowitzd6ebc2d2013-11-01 11:44:06 -0700172 }
173 if (paginator.getNextStart() != null) {
Dave Borowitz77cf5f22015-10-26 11:05:07 -0400174 result.next = paginator.getNextStart().name();
Dave Borowitzd6ebc2d2013-11-01 11:44:06 -0700175 }
Dave Borowitz77cf5f22015-10-26 11:05:07 -0400176 renderJson(req, res, result, new TypeToken<CommitJsonData.Log>() {}.getType());
Dave Borowitzd6ebc2d2013-11-01 11:44:06 -0700177 } finally {
Dave Borowitz344c4dd2015-10-26 11:02:13 -0400178 if (paginator != null) {
179 paginator.getWalk().close();
180 }
Dave Borowitzd6ebc2d2013-11-01 11:44:06 -0700181 }
182 }
183
Matthias Sohnc156c962023-09-30 22:15:23 +0200184 private static @Nullable GitilesView getView(HttpServletRequest req, Repository repo)
185 throws IOException {
Dave Borowitz80334b22013-01-11 14:19:11 -0800186 GitilesView view = ViewFilter.getView(req);
David Pursehousec53de2b2019-06-01 15:27:25 +0900187 if (!Revision.isNull(view.getRevision())) {
Dave Borowitz80334b22013-01-11 14:19:11 -0800188 return view;
189 }
Dave Borowitz14cad732016-05-26 17:34:19 -0400190 Ref headRef = repo.exactRef(Constants.HEAD);
Dave Borowitz80334b22013-01-11 14:19:11 -0800191 if (headRef == null) {
192 return null;
193 }
Shawn Pearceb5ad0a02015-05-24 20:33:17 -0700194 try (RevWalk walk = new RevWalk(repo)) {
Dave Borowitz80334b22013-01-11 14:19:11 -0800195 return GitilesView.log()
Han-Wen Nienhuysc0200f62016-05-02 17:34:51 +0200196 .copyFrom(view)
197 .setRevision(Revision.peel(Constants.HEAD, walk.parseAny(headRef.getObjectId()), walk))
198 .build();
Dave Borowitz80334b22013-01-11 14:19:11 -0800199 }
200 }
201
David Pursehouse17c09fe2016-08-26 15:41:01 +0900202 private static class InvalidStartValueException extends IllegalArgumentException {
203 private static final long serialVersionUID = 1L;
204
205 InvalidStartValueException() {
206 super();
207 }
208 }
209
Han-Wen Nienhuysc0200f62016-05-02 17:34:51 +0200210 private static Optional<ObjectId> getStart(
David Pursehouse17c09fe2016-08-26 15:41:01 +0900211 ListMultimap<String, String> params, ObjectReader reader)
David Pursehouseccaa85d2017-05-30 10:47:27 +0900212 throws IOException, InvalidStartValueException {
Dave Borowitz9de65952012-08-13 16:09:45 -0700213 List<String> values = params.get(START_PARAM);
214 switch (values.size()) {
215 case 0:
David Pursehouse7a7f5472016-10-14 09:59:20 +0900216 return Optional.empty();
Dave Borowitz9de65952012-08-13 16:09:45 -0700217 case 1:
Dave Borowitz95ef58a2016-05-26 17:30:10 -0400218 String id = values.get(0);
219 if (!AbbreviatedObjectId.isId(id)) {
David Pursehouse17c09fe2016-08-26 15:41:01 +0900220 throw new InvalidStartValueException();
Dave Borowitz95ef58a2016-05-26 17:30:10 -0400221 }
222 Collection<ObjectId> ids = reader.resolve(AbbreviatedObjectId.fromString(id));
Dave Borowitz9de65952012-08-13 16:09:45 -0700223 if (ids.size() != 1) {
David Pursehouse17c09fe2016-08-26 15:41:01 +0900224 throw new InvalidStartValueException();
Dave Borowitz9de65952012-08-13 16:09:45 -0700225 }
226 return Optional.of(Iterables.getOnlyElement(ids));
227 default:
David Pursehouse17c09fe2016-08-26 15:41:01 +0900228 throw new InvalidStartValueException();
Dave Borowitz9de65952012-08-13 16:09:45 -0700229 }
230 }
231
Matthias Sohnc156c962023-09-30 22:15:23 +0200232 private static @Nullable RevWalk newWalk(Repository repo, GitilesView view, GitilesAccess access)
David Pursehousec3e772a2016-06-15 21:49:35 +0900233 throws MissingObjectException, IOException {
Dave Borowitz9de65952012-08-13 16:09:45 -0700234 RevWalk walk = new RevWalk(repo);
Alex Spradlin284a35a2019-07-09 16:02:55 -0700235 if (isTrue(view, FIRST_PARENT_PARAM)) {
236 walk.setFirstParent(true);
237 }
238 if (isTrue(view, TOPO_ORDER_PARAM)) {
Alex Spradlind9225862020-03-18 13:14:47 -0700239 walk.sort(RevSort.TOPO_KEEP_BRANCH_TOGETHER, true);
Alex Spradlin284a35a2019-07-09 16:02:55 -0700240 }
241 if (isTrue(view, REVERSE_PARAM)) {
242 walk.sort(RevSort.REVERSE, true);
243 }
David Pursehousec3e772a2016-06-15 21:49:35 +0900244 try {
245 walk.markStart(walk.parseCommit(view.getRevision().getId()));
David Pursehousec53de2b2019-06-01 15:27:25 +0900246 if (!Revision.isNull(view.getOldRevision())) {
David Pursehousec3e772a2016-06-15 21:49:35 +0900247 walk.markUninteresting(walk.parseCommit(view.getOldRevision().getId()));
248 }
249 } catch (IncorrectObjectTypeException iote) {
250 return null;
Dave Borowitz9de65952012-08-13 16:09:45 -0700251 }
Dave Borowitz344c4dd2015-10-26 11:02:13 -0400252 setTreeFilter(walk, view, access);
Shawn Pearce31037672016-08-18 21:44:43 -0700253 setRevFilter(walk, view);
Xing Huang06b65fd2025-03-10 12:50:09 -0500254 walk.setRetainBody(false);
Shawn Pearce31037672016-08-18 21:44:43 -0700255 return walk;
256 }
257
258 private static void setRevFilter(RevWalk walk, GitilesView view) {
Shawn Pearce20b42292015-03-17 21:53:55 -0700259 List<RevFilter> filters = new ArrayList<>(3);
Shawn Pearce31037672016-08-18 21:44:43 -0700260 if (isTrue(view, "no-merges")) {
Shawn Pearce20b42292015-03-17 21:53:55 -0700261 filters.add(RevFilter.NO_MERGES);
262 }
Shawn Pearce31037672016-08-18 21:44:43 -0700263
Benjamin Kalmanbcc19fa2014-08-21 17:24:41 -0700264 String author = Iterables.getFirst(view.getParameters().get("author"), null);
265 if (author != null) {
Shawn Pearce20b42292015-03-17 21:53:55 -0700266 filters.add(IdentRevFilter.author(author));
Dave Borowitz8646ff52014-09-05 16:18:56 -0700267 }
Shawn Pearce31037672016-08-18 21:44:43 -0700268
Dave Borowitz8646ff52014-09-05 16:18:56 -0700269 String committer = Iterables.getFirst(view.getParameters().get("committer"), null);
270 if (committer != null) {
Shawn Pearce20b42292015-03-17 21:53:55 -0700271 filters.add(IdentRevFilter.committer(committer));
272 }
Shawn Pearce31037672016-08-18 21:44:43 -0700273
Shawn Pearce20b42292015-03-17 21:53:55 -0700274 if (filters.size() > 1) {
275 walk.setRevFilter(AndRevFilter.create(filters));
276 } else if (filters.size() == 1) {
277 walk.setRevFilter(filters.get(0));
Benjamin Kalmanbcc19fa2014-08-21 17:24:41 -0700278 }
Dave Borowitz9de65952012-08-13 16:09:45 -0700279 }
Dave Borowitz27fada42013-11-01 11:09:49 -0700280
Dave Borowitz344c4dd2015-10-26 11:02:13 -0400281 private static void setTreeFilter(RevWalk walk, GitilesView view, GitilesAccess access)
282 throws IOException {
283 if (Strings.isNullOrEmpty(view.getPathPart())) {
284 return;
285 }
286 walk.setRewriteParents(false);
287 String path = view.getPathPart();
Dave Borowitz45dde172016-03-22 10:10:58 -0400288
289 List<String> followParams = view.getParameters().get(FOLLOW_PARAM);
Han-Wen Nienhuysc0200f62016-05-02 17:34:51 +0200290 boolean follow =
291 !followParams.isEmpty()
292 ? isTrue(followParams.get(0))
293 : access.getConfig().getBoolean("log", null, "follow", true);
Dave Borowitz45dde172016-03-22 10:10:58 -0400294 if (follow) {
Dave Borowitz344c4dd2015-10-26 11:02:13 -0400295 walk.setTreeFilter(FollowFilter.create(path, access.getConfig().get(DiffConfig.KEY)));
296 } else {
Xing Huang06b65fd2025-03-10 12:50:09 -0500297 walk.setTreeFilter(ChangedPathTreeFilter.create(path));
Dave Borowitz344c4dd2015-10-26 11:02:13 -0400298 }
299 }
300
Shawn Pearce31037672016-08-18 21:44:43 -0700301 private static boolean isTrue(GitilesView view, String param) {
302 return isTrue(Iterables.getFirst(view.getParameters().get(param), null));
303 }
304
Shawn Pearce20b42292015-03-17 21:53:55 -0700305 private static boolean isTrue(String v) {
306 if (v == null) {
307 return false;
308 } else if (v.isEmpty()) {
309 return true;
310 }
311 return Boolean.TRUE.equals(StringUtils.toBooleanOrNull(v));
312 }
313
Matthias Sohnc156c962023-09-30 22:15:23 +0200314 private static @Nullable Paginator newPaginator(
315 Repository repo, GitilesView view, GitilesAccess access) throws IOException {
Dave Borowitz27fada42013-11-01 11:09:49 -0700316 if (view == null) {
317 return null;
318 }
319
David Pursehousec3e772a2016-06-15 21:49:35 +0900320 try (RevWalk walk = newWalk(repo, view, access)) {
321 if (walk == null) {
322 return null;
323 }
Dave Borowitz27fada42013-11-01 11:09:49 -0700324
David Pursehouse17c09fe2016-08-26 15:41:01 +0900325 try {
326 Optional<ObjectId> start = getStart(view.getParameters(), walk.getObjectReader());
David Pursehouse7a7f5472016-10-14 09:59:20 +0900327 return new Paginator(walk, getLimit(view), start.orElse(null));
David Pursehouse17c09fe2016-08-26 15:41:01 +0900328 } catch (InvalidStartValueException e) {
David Pursehousec3e772a2016-06-15 21:49:35 +0900329 return null;
330 }
David Pursehousec3e772a2016-06-15 21:49:35 +0900331 }
Dave Borowitzef055812013-11-01 12:05:55 -0700332 }
333
334 private static int getLimit(GitilesView view) {
335 List<String> values = view.getParameters().get(LIMIT_PARAM);
336 if (values.isEmpty()) {
337 return DEFAULT_LIMIT;
338 }
339 Long limit = Longs.tryParse(values.get(0));
340 if (limit == null) {
341 return DEFAULT_LIMIT;
342 }
343 return (int) Math.min(limit, MAX_LIMIT);
Dave Borowitz27fada42013-11-01 11:09:49 -0700344 }
Dave Borowitz9de65952012-08-13 16:09:45 -0700345}