summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGerard Smyth <gerard.smyth@gmail.com>2014-04-01 12:29:01 +0100
committerJames Moger <james.moger@gitblit.com>2014-05-08 13:09:30 -0400
commitf76fee63ed9cb3a30d3c0c092d860b1cb93a481b (patch)
tree10177da656f10daae98dc0ba627c702bbf050438
parentd99277724206102f25e7c5c569d2e7fdc891e4a0 (diff)
downloadgitblit-f76fee63ed9cb3a30d3c0c092d860b1cb93a481b.tar.gz
gitblit-f76fee63ed9cb3a30d3c0c092d860b1cb93a481b.zip
Updated the SyndicationServlet to provide an additional option to return details of the tags in the repository instead of the commits.
This uses a new 'ot' request parameter to indicate the object type of the content to return, which can be ither TAG or COMMIT. If this is not provided, then COMMIT is assumed to maintain backwards compatability. If tags are returned, then the paging parameters, 'l' and 'pg' are still supported, but searching options are currently ignored.
-rw-r--r--src/main/java/com/gitblit/Constants.java21
-rw-r--r--src/main/java/com/gitblit/servlet/SyndicationServlet.java135
-rw-r--r--src/main/java/com/gitblit/utils/JGitUtils.java48
3 files changed, 159 insertions, 45 deletions
diff --git a/src/main/java/com/gitblit/Constants.java b/src/main/java/com/gitblit/Constants.java
index c8ce83c1..2007c0a8 100644
--- a/src/main/java/com/gitblit/Constants.java
+++ b/src/main/java/com/gitblit/Constants.java
@@ -403,6 +403,27 @@ public class Constants {
}
/**
+ * Enumeration of the feed content object types.
+ */
+ public static enum FeedContentObjectType {
+ COMMIT, TAG;
+
+ public static FeedContentObjectType forName(String name) {
+ for (FeedContentObjectType type : values()) {
+ if (type.name().equalsIgnoreCase(name)) {
+ return type;
+ }
+ }
+ return COMMIT;
+ }
+
+ @Override
+ public String toString() {
+ return name().toLowerCase();
+ }
+ }
+
+ /**
* The types of objects that can be indexed and queried.
*/
public static enum SearchObjectType {
diff --git a/src/main/java/com/gitblit/servlet/SyndicationServlet.java b/src/main/java/com/gitblit/servlet/SyndicationServlet.java
index 24def995..9650ee3a 100644
--- a/src/main/java/com/gitblit/servlet/SyndicationServlet.java
+++ b/src/main/java/com/gitblit/servlet/SyndicationServlet.java
@@ -163,6 +163,15 @@ public class SyndicationServlet extends DaggerServlet {
searchType = type;
}
}
+
+ Constants.FeedContentObjectType objectType = Constants.FeedContentObjectType.COMMIT;
+ if (!StringUtils.isEmpty(request.getParameter("ot"))) {
+ Constants.FeedContentObjectType type = Constants.FeedContentObjectType.forName(request.getParameter("ot"));
+ if (type != null) {
+ objectType = type;
+ }
+ }
+
int length = settings.getInteger(Keys.web.syndicationEntries, 25);
if (StringUtils.isEmpty(objectId)) {
objectId = org.eclipse.jgit.lib.Constants.HEAD;
@@ -214,14 +223,7 @@ public class SyndicationServlet extends DaggerServlet {
boolean mountParameters = settings.getBoolean(Keys.web.mountParameters, true);
- String urlPattern;
- if (mountParameters) {
- // mounted parameters
- urlPattern = "{0}/commit/{1}/{2}";
- } else {
- // parameterized parameters
- urlPattern = "{0}/commit/?r={1}&h={2}";
- }
+
String gitblitUrl = settings.getString(Keys.web.canonicalUrl, null);
if (StringUtils.isEmpty(gitblitUrl)) {
gitblitUrl = HttpUtils.getGitblitURL(request);
@@ -247,47 +249,92 @@ public class SyndicationServlet extends DaggerServlet {
feedDescription = model.description;
}
- List<RevCommit> commits;
- if (StringUtils.isEmpty(searchString)) {
- // standard log/history lookup
- commits = JGitUtils.getRevLog(repository, objectId, offset, length);
+ if (objectType == Constants.FeedContentObjectType.TAG) {
+
+ String urlPattern;
+ if (mountParameters) {
+ // mounted parameters
+ urlPattern = "{0}/tag/{1}/{2}";
+ } else {
+ // parameterized parameters
+ urlPattern = "{0}/tag/?r={1}&h={2}";
+ }
+
+ List<RefModel> tags = JGitUtils.getTags(repository, false, length, offset);
+
+ for (RefModel tag : tags) {
+ FeedEntryModel entry = new FeedEntryModel();
+ entry.title = tag.getName();
+ entry.author = tag.getAuthorIdent().getName();
+ entry.link = MessageFormat.format(urlPattern, gitblitUrl,
+ StringUtils.encodeURL(model.name.replace('/', fsc)), tag.getObjectId().getName());
+ entry.published = tag.getDate();
+ entry.contentType = "text/html";
+ entry.content = tag.getFullMessage();
+ entry.repository = model.name;
+ entry.branch = objectId;
+
+ entry.tags = new ArrayList<String>();
+
+ // add tag id and referenced commit id
+ entry.tags.add("tag:" + tag.getObjectId().getName());
+ entry.tags.add("commit:" + tag.getReferencedObjectId().getName());
+
+ entries.add(entry);
+ }
} else {
- // repository search
- commits = JGitUtils.searchRevlogs(repository, objectId, searchString, searchType,
- offset, length);
- }
- Map<ObjectId, List<RefModel>> allRefs = JGitUtils.getAllRefs(repository, model.showRemoteBranches);
- BugtraqProcessor processor = new BugtraqProcessor(settings);
-
- // convert RevCommit to SyndicatedEntryModel
- for (RevCommit commit : commits) {
- FeedEntryModel entry = new FeedEntryModel();
- entry.title = commit.getShortMessage();
- entry.author = commit.getAuthorIdent().getName();
- entry.link = MessageFormat.format(urlPattern, gitblitUrl,
- StringUtils.encodeURL(model.name.replace('/', fsc)), commit.getName());
- entry.published = commit.getCommitterIdent().getWhen();
- entry.contentType = "text/html";
- String message = processor.processCommitMessage(repository, model, commit.getFullMessage());
- entry.content = message;
- entry.repository = model.name;
- entry.branch = objectId;
- entry.tags = new ArrayList<String>();
-
- // add commit id and parent commit ids
- entry.tags.add("commit:" + commit.getName());
- for (RevCommit parent : commit.getParents()) {
- entry.tags.add("parent:" + parent.getName());
+
+ String urlPattern;
+ if (mountParameters) {
+ // mounted parameters
+ urlPattern = "{0}/commit/{1}/{2}";
+ } else {
+ // parameterized parameters
+ urlPattern = "{0}/commit/?r={1}&h={2}";
}
- // add refs to tabs list
- List<RefModel> refs = allRefs.get(commit.getId());
- if (refs != null && refs.size() > 0) {
- for (RefModel ref : refs) {
- entry.tags.add("ref:" + ref.getName());
+ List<RevCommit> commits;
+ if (StringUtils.isEmpty(searchString)) {
+ // standard log/history lookup
+ commits = JGitUtils.getRevLog(repository, objectId, offset, length);
+ } else {
+ // repository search
+ commits = JGitUtils.searchRevlogs(repository, objectId, searchString, searchType,
+ offset, length);
+ }
+ Map<ObjectId, List<RefModel>> allRefs = JGitUtils.getAllRefs(repository, model.showRemoteBranches);
+ BugtraqProcessor processor = new BugtraqProcessor(settings);
+
+ // convert RevCommit to SyndicatedEntryModel
+ for (RevCommit commit : commits) {
+ FeedEntryModel entry = new FeedEntryModel();
+ entry.title = commit.getShortMessage();
+ entry.author = commit.getAuthorIdent().getName();
+ entry.link = MessageFormat.format(urlPattern, gitblitUrl,
+ StringUtils.encodeURL(model.name.replace('/', fsc)), commit.getName());
+ entry.published = commit.getCommitterIdent().getWhen();
+ entry.contentType = "text/html";
+ String message = processor.processCommitMessage(repository, model, commit.getFullMessage());
+ entry.content = message;
+ entry.repository = model.name;
+ entry.branch = objectId;
+ entry.tags = new ArrayList<String>();
+
+ // add commit id and parent commit ids
+ entry.tags.add("commit:" + commit.getName());
+ for (RevCommit parent : commit.getParents()) {
+ entry.tags.add("parent:" + parent.getName());
+ }
+
+ // add refs to tabs list
+ List<RefModel> refs = allRefs.get(commit.getId());
+ if (refs != null && refs.size() > 0) {
+ for (RefModel ref : refs) {
+ entry.tags.add("ref:" + ref.getName());
+ }
}
+ entries.add(entry);
}
- entries.add(entry);
}
}
diff --git a/src/main/java/com/gitblit/utils/JGitUtils.java b/src/main/java/com/gitblit/utils/JGitUtils.java
index 190872a7..da51ea98 100644
--- a/src/main/java/com/gitblit/utils/JGitUtils.java
+++ b/src/main/java/com/gitblit/utils/JGitUtils.java
@@ -1668,6 +1668,24 @@ public class JGitUtils {
}
/**
+ * Returns the list of tags in the repository. If repository does not exist
+ * or is empty, an empty list is returned.
+ *
+ * @param repository
+ * @param fullName
+ * if true, /refs/tags/yadayadayada is returned. If false,
+ * yadayadayada is returned.
+ * @param maxCount
+ * if < 0, all tags are returned
+ * @param offset
+ * if maxCount provided sets the starting point of the records to return
+ * @return list of tags
+ */
+ public static List<RefModel> getTags(Repository repository, boolean fullName, int maxCount, int offset) {
+ return getRefs(repository, Constants.R_TAGS, fullName, maxCount, offset);
+ }
+
+ /**
* Returns the list of local branches in the repository. If repository does
* not exist or is empty, an empty list is returned.
*
@@ -1748,6 +1766,27 @@ public class JGitUtils {
*/
private static List<RefModel> getRefs(Repository repository, String refs, boolean fullName,
int maxCount) {
+ return getRefs(repository, refs, fullName, maxCount, 0);
+ }
+
+ /**
+ * Returns a list of references in the repository matching "refs". If the
+ * repository is null or empty, an empty list is returned.
+ *
+ * @param repository
+ * @param refs
+ * if unspecified, all refs are returned
+ * @param fullName
+ * if true, /refs/something/yadayadayada is returned. If false,
+ * yadayadayada is returned.
+ * @param maxCount
+ * if < 0, all references are returned
+ * @param offset
+ * if maxCount provided sets the starting point of the records to return
+ * @return list of references
+ */
+ private static List<RefModel> getRefs(Repository repository, String refs, boolean fullName,
+ int maxCount, int offset) {
List<RefModel> list = new ArrayList<RefModel>();
if (maxCount == 0) {
return list;
@@ -1771,7 +1810,14 @@ public class JGitUtils {
Collections.sort(list);
Collections.reverse(list);
if (maxCount > 0 && list.size() > maxCount) {
- list = new ArrayList<RefModel>(list.subList(0, maxCount));
+ if (offset < 0) {
+ offset = 0;
+ }
+ int endIndex = offset + maxCount;
+ if (endIndex > list.size()) {
+ endIndex = list.size();
+ }
+ list = new ArrayList<RefModel>(list.subList(offset, endIndex));
}
} catch (IOException e) {
error(e, repository, "{0} failed to retrieve {1}", refs);