searchType = type;\r
}\r
}\r
+\r
+ Constants.FeedContentObjectType objectType = Constants.FeedContentObjectType.COMMIT;\r
+ if (!StringUtils.isEmpty(request.getParameter("ot"))) {\r
+ Constants.FeedContentObjectType type = Constants.FeedContentObjectType.forName(request.getParameter("ot"));\r
+ if (type != null) {\r
+ objectType = type;\r
+ }\r
+ }\r
+\r
int length = settings.getInteger(Keys.web.syndicationEntries, 25);\r
if (StringUtils.isEmpty(objectId)) {\r
objectId = org.eclipse.jgit.lib.Constants.HEAD;\r
\r
\r
boolean mountParameters = settings.getBoolean(Keys.web.mountParameters, true);\r
- String urlPattern;\r
- if (mountParameters) {\r
- // mounted parameters\r
- urlPattern = "{0}/commit/{1}/{2}";\r
- } else {\r
- // parameterized parameters\r
- urlPattern = "{0}/commit/?r={1}&h={2}";\r
- }\r
+\r
String gitblitUrl = settings.getString(Keys.web.canonicalUrl, null);\r
if (StringUtils.isEmpty(gitblitUrl)) {\r
gitblitUrl = HttpUtils.getGitblitURL(request);\r
feedDescription = model.description;\r
}\r
\r
- List<RevCommit> commits;\r
- if (StringUtils.isEmpty(searchString)) {\r
- // standard log/history lookup\r
- commits = JGitUtils.getRevLog(repository, objectId, offset, length);\r
+ if (objectType == Constants.FeedContentObjectType.TAG) {\r
+\r
+ String urlPattern;\r
+ if (mountParameters) {\r
+ // mounted parameters\r
+ urlPattern = "{0}/tag/{1}/{2}";\r
+ } else {\r
+ // parameterized parameters\r
+ urlPattern = "{0}/tag/?r={1}&h={2}";\r
+ }\r
+\r
+ List<RefModel> tags = JGitUtils.getTags(repository, false, length, offset);\r
+\r
+ for (RefModel tag : tags) {\r
+ FeedEntryModel entry = new FeedEntryModel();\r
+ entry.title = tag.getName();\r
+ entry.author = tag.getAuthorIdent().getName();\r
+ entry.link = MessageFormat.format(urlPattern, gitblitUrl,\r
+ StringUtils.encodeURL(model.name.replace('/', fsc)), tag.getObjectId().getName());\r
+ entry.published = tag.getDate();\r
+ entry.contentType = "text/html";\r
+ entry.content = tag.getFullMessage();\r
+ entry.repository = model.name;\r
+ entry.branch = objectId;\r
+\r
+ entry.tags = new ArrayList<String>();\r
+\r
+ // add tag id and referenced commit id\r
+ entry.tags.add("tag:" + tag.getObjectId().getName());\r
+ entry.tags.add("commit:" + tag.getReferencedObjectId().getName());\r
+\r
+ entries.add(entry);\r
+ }\r
} else {\r
- // repository search\r
- commits = JGitUtils.searchRevlogs(repository, objectId, searchString, searchType,\r
- offset, length);\r
- }\r
- Map<ObjectId, List<RefModel>> allRefs = JGitUtils.getAllRefs(repository, model.showRemoteBranches);\r
- BugtraqProcessor processor = new BugtraqProcessor(settings);\r
-\r
- // convert RevCommit to SyndicatedEntryModel\r
- for (RevCommit commit : commits) {\r
- FeedEntryModel entry = new FeedEntryModel();\r
- entry.title = commit.getShortMessage();\r
- entry.author = commit.getAuthorIdent().getName();\r
- entry.link = MessageFormat.format(urlPattern, gitblitUrl,\r
- StringUtils.encodeURL(model.name.replace('/', fsc)), commit.getName());\r
- entry.published = commit.getCommitterIdent().getWhen();\r
- entry.contentType = "text/html";\r
- String message = processor.processCommitMessage(repository, model, commit.getFullMessage());\r
- entry.content = message;\r
- entry.repository = model.name;\r
- entry.branch = objectId;\r
- entry.tags = new ArrayList<String>();\r
-\r
- // add commit id and parent commit ids\r
- entry.tags.add("commit:" + commit.getName());\r
- for (RevCommit parent : commit.getParents()) {\r
- entry.tags.add("parent:" + parent.getName());\r
+\r
+ String urlPattern;\r
+ if (mountParameters) {\r
+ // mounted parameters\r
+ urlPattern = "{0}/commit/{1}/{2}";\r
+ } else {\r
+ // parameterized parameters\r
+ urlPattern = "{0}/commit/?r={1}&h={2}";\r
}\r
\r
- // add refs to tabs list\r
- List<RefModel> refs = allRefs.get(commit.getId());\r
- if (refs != null && refs.size() > 0) {\r
- for (RefModel ref : refs) {\r
- entry.tags.add("ref:" + ref.getName());\r
+ List<RevCommit> commits;\r
+ if (StringUtils.isEmpty(searchString)) {\r
+ // standard log/history lookup\r
+ commits = JGitUtils.getRevLog(repository, objectId, offset, length);\r
+ } else {\r
+ // repository search\r
+ commits = JGitUtils.searchRevlogs(repository, objectId, searchString, searchType,\r
+ offset, length);\r
+ }\r
+ Map<ObjectId, List<RefModel>> allRefs = JGitUtils.getAllRefs(repository, model.showRemoteBranches);\r
+ BugtraqProcessor processor = new BugtraqProcessor(settings);\r
+\r
+ // convert RevCommit to SyndicatedEntryModel\r
+ for (RevCommit commit : commits) {\r
+ FeedEntryModel entry = new FeedEntryModel();\r
+ entry.title = commit.getShortMessage();\r
+ entry.author = commit.getAuthorIdent().getName();\r
+ entry.link = MessageFormat.format(urlPattern, gitblitUrl,\r
+ StringUtils.encodeURL(model.name.replace('/', fsc)), commit.getName());\r
+ entry.published = commit.getCommitterIdent().getWhen();\r
+ entry.contentType = "text/html";\r
+ String message = processor.processCommitMessage(repository, model, commit.getFullMessage());\r
+ entry.content = message;\r
+ entry.repository = model.name;\r
+ entry.branch = objectId;\r
+ entry.tags = new ArrayList<String>();\r
+\r
+ // add commit id and parent commit ids\r
+ entry.tags.add("commit:" + commit.getName());\r
+ for (RevCommit parent : commit.getParents()) {\r
+ entry.tags.add("parent:" + parent.getName());\r
+ }\r
+\r
+ // add refs to tabs list\r
+ List<RefModel> refs = allRefs.get(commit.getId());\r
+ if (refs != null && refs.size() > 0) {\r
+ for (RefModel ref : refs) {\r
+ entry.tags.add("ref:" + ref.getName());\r
+ }\r
}\r
+ entries.add(entry);\r
}\r
- entries.add(entry);\r
}\r
}\r
\r
return getRefs(repository, Constants.R_TAGS, fullName, maxCount);\r
}\r
\r
+ /**\r
+ * Returns the list of tags in the repository. If repository does not exist\r
+ * or is empty, an empty list is returned.\r
+ *\r
+ * @param repository\r
+ * @param fullName\r
+ * if true, /refs/tags/yadayadayada is returned. If false,\r
+ * yadayadayada is returned.\r
+ * @param maxCount\r
+ * if < 0, all tags are returned\r
+ * @param offset\r
+ * if maxCount provided sets the starting point of the records to return\r
+ * @return list of tags\r
+ */\r
+ public static List<RefModel> getTags(Repository repository, boolean fullName, int maxCount, int offset) {\r
+ return getRefs(repository, Constants.R_TAGS, fullName, maxCount, offset);\r
+ }\r
+\r
/**\r
* Returns the list of local branches in the repository. If repository does\r
* not exist or is empty, an empty list is returned.\r
*/\r
private static List<RefModel> getRefs(Repository repository, String refs, boolean fullName,\r
int maxCount) {\r
+ return getRefs(repository, refs, fullName, maxCount, 0);\r
+ }\r
+\r
+ /**\r
+ * Returns a list of references in the repository matching "refs". If the\r
+ * repository is null or empty, an empty list is returned.\r
+ *\r
+ * @param repository\r
+ * @param refs\r
+ * if unspecified, all refs are returned\r
+ * @param fullName\r
+ * if true, /refs/something/yadayadayada is returned. If false,\r
+ * yadayadayada is returned.\r
+ * @param maxCount\r
+ * if < 0, all references are returned\r
+ * @param offset\r
+ * if maxCount provided sets the starting point of the records to return\r
+ * @return list of references\r
+ */\r
+ private static List<RefModel> getRefs(Repository repository, String refs, boolean fullName,\r
+ int maxCount, int offset) {\r
List<RefModel> list = new ArrayList<RefModel>();\r
if (maxCount == 0) {\r
return list;\r
Collections.sort(list);\r
Collections.reverse(list);\r
if (maxCount > 0 && list.size() > maxCount) {\r
- list = new ArrayList<RefModel>(list.subList(0, maxCount));\r
+ if (offset < 0) {\r
+ offset = 0;\r
+ }\r
+ int endIndex = offset + maxCount;\r
+ if (endIndex > list.size()) {\r
+ endIndex = list.size();\r
+ }\r
+ list = new ArrayList<RefModel>(list.subList(offset, endIndex));\r
}\r
} catch (IOException e) {\r
error(e, repository, "{0} failed to retrieve {1}", refs);\r