diff options
author | James Moger <james.moger@gitblit.com> | 2014-06-16 17:36:12 -0400 |
---|---|---|
committer | James Moger <james.moger@gitblit.com> | 2014-06-16 17:36:12 -0400 |
commit | 6b18b0761b726fd9aef1ebcc21b760378f7d4b5c (patch) | |
tree | 4bdb208cede00e637ce4704d942aa045f5af5ed9 /src/main/java/com/gitblit/utils | |
parent | 07eb0963cae3a403f8774f65afa20c940ce7124f (diff) | |
parent | 9b575e8fac8d5e17e77cc284092abd856ddec8ac (diff) | |
download | gitblit-6b18b0761b726fd9aef1ebcc21b760378f7d4b5c.tar.gz gitblit-6b18b0761b726fd9aef1ebcc21b760378f7d4b5c.zip |
Merge release 1.6.0
Diffstat (limited to 'src/main/java/com/gitblit/utils')
-rw-r--r-- | src/main/java/com/gitblit/utils/JGitUtils.java | 48 | ||||
-rw-r--r-- | src/main/java/com/gitblit/utils/MarkdownUtils.java | 4 | ||||
-rw-r--r-- | src/main/java/com/gitblit/utils/RpcUtils.java | 16 | ||||
-rw-r--r-- | src/main/java/com/gitblit/utils/SyndicationUtils.java | 57 |
4 files changed, 121 insertions, 4 deletions
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);
diff --git a/src/main/java/com/gitblit/utils/MarkdownUtils.java b/src/main/java/com/gitblit/utils/MarkdownUtils.java index da0db79d..2ebfdb26 100644 --- a/src/main/java/com/gitblit/utils/MarkdownUtils.java +++ b/src/main/java/com/gitblit/utils/MarkdownUtils.java @@ -136,7 +136,7 @@ public class MarkdownUtils { String canonicalUrl = settings.getString(Keys.web.canonicalUrl, "https://localhost:8443");
// emphasize and link mentions
- String mentionReplacement = String.format(" **<a href=\"%1s/user/$1\">@$1</a>**", canonicalUrl);
+ String mentionReplacement = String.format(" **[@$1](%1s/user/$1)**", canonicalUrl);
text = text.replaceAll("\\s@([A-Za-z0-9-_]+)", mentionReplacement);
// link ticket refs @@ -146,7 +146,7 @@ public class MarkdownUtils { // link commit shas
int shaLen = settings.getInteger(Keys.web.shortCommitIdLength, 6);
String commitPattern = MessageFormat.format("\\s([A-Fa-f0-9]'{'{0}'}')([A-Fa-f0-9]'{'{1}'}')", shaLen, 40 - shaLen);
- String commitReplacement = String.format(" <a class='commit' href='%1$s/commit?r=%2$s&h=$1$2'>$1</a>", canonicalUrl, repositoryName);
+ String commitReplacement = String.format(" [`$1`](%1$s/commit?r=%2$s&h=$1$2)", canonicalUrl, repositoryName);
text = text.replaceAll(commitPattern, commitReplacement);
String html = transformMarkdown(text);
diff --git a/src/main/java/com/gitblit/utils/RpcUtils.java b/src/main/java/com/gitblit/utils/RpcUtils.java index 5e577fb6..82202154 100644 --- a/src/main/java/com/gitblit/utils/RpcUtils.java +++ b/src/main/java/com/gitblit/utils/RpcUtils.java @@ -203,7 +203,21 @@ public class RpcUtils { }
- /**
+ /**
+ * Create a fork of a repository.
+ *
+ * @param repository
+
+ * @return true if the action succeeded
+ * @throws IOException
+ */
+ public static boolean forkRepository(RepositoryModel repository, String serverUrl,
+ String account, char[] password) throws IOException {
+ return doAction(RpcRequest.FORK_REPOSITORY, repository.name, null, serverUrl, account, password);
+ }
+
+
+ /**
* Send a revised version of the repository model to the Gitblit server.
*
* @param repository
diff --git a/src/main/java/com/gitblit/utils/SyndicationUtils.java b/src/main/java/com/gitblit/utils/SyndicationUtils.java index 2ee1cf69..93e9321a 100644 --- a/src/main/java/com/gitblit/utils/SyndicationUtils.java +++ b/src/main/java/com/gitblit/utils/SyndicationUtils.java @@ -25,6 +25,7 @@ import java.util.ArrayList; import java.util.List;
import com.gitblit.Constants;
+import com.gitblit.Constants.FeedObjectType;
import com.gitblit.GitBlitException;
import com.gitblit.models.FeedEntryModel;
import com.sun.syndication.feed.synd.SyndCategory;
@@ -137,6 +138,59 @@ public class SyndicationUtils { */
public static List<FeedEntryModel> readFeed(String url, String repository, String branch,
int numberOfEntries, int page, String username, char[] password) throws IOException {
+ return readFeed(url, repository, branch, FeedObjectType.COMMIT, numberOfEntries,
+ page, username, password);
+ }
+
+ /**
+ * Reads tags from the specified repository.
+ *
+ * @param url
+ * the url of the Gitblit server
+ * @param repository
+ * the repository name
+ * @param branch
+ * the branch name (optional)
+ * @param numberOfEntries
+ * the number of entries to retrieve. if <= 0 the server default
+ * is used.
+ * @param page
+ * 0-indexed. used to paginate the results.
+ * @param username
+ * @param password
+ * @return a list of SyndicationModel entries
+ * @throws {@link IOException}
+ */
+ public static List<FeedEntryModel> readTags(String url, String repository,
+ int numberOfEntries, int page, String username, char[] password) throws IOException {
+ return readFeed(url, repository, null, FeedObjectType.TAG, numberOfEntries,
+ page, username, password);
+ }
+
+ /**
+ * Reads a Gitblit RSS feed.
+ *
+ * @param url
+ * the url of the Gitblit server
+ * @param repository
+ * the repository name
+ * @param branch
+ * the branch name (optional)
+ * @param objectType
+ * the object type to return (optional, COMMIT assummed)
+ * @param numberOfEntries
+ * the number of entries to retrieve. if <= 0 the server default
+ * is used.
+ * @param page
+ * 0-indexed. used to paginate the results.
+ * @param username
+ * @param password
+ * @return a list of SyndicationModel entries
+ * @throws {@link IOException}
+ */
+ private static List<FeedEntryModel> readFeed(String url, String repository, String branch,
+ FeedObjectType objectType, int numberOfEntries, int page, String username,
+ char[] password) throws IOException {
// build feed url
List<String> parameters = new ArrayList<String>();
if (numberOfEntries > 0) {
@@ -148,6 +202,9 @@ public class SyndicationUtils { if (!StringUtils.isEmpty(branch)) {
parameters.add("h=" + branch);
}
+ if (objectType != null) {
+ parameters.add("ot=" + objectType.name());
+ }
return readFeed(url, parameters, repository, branch, username, password);
}
|