diff options
author | James Moger <james.moger@gitblit.com> | 2011-10-28 08:08:00 -0400 |
---|---|---|
committer | James Moger <james.moger@gitblit.com> | 2011-10-28 08:08:00 -0400 |
commit | c75304637f5535e634e57d4ed933c0fdb594d890 (patch) | |
tree | 347171533279f8c75bb3be8914ab665186800969 /src/com | |
parent | 565ee056cd74a119b6b7c108239a6470976d02b7 (diff) | |
download | gitblit-c75304637f5535e634e57d4ed933c0fdb594d890.tar.gz gitblit-c75304637f5535e634e57d4ed933c0fdb594d890.zip |
Added a list branches rpc
Diffstat (limited to 'src/com')
-rw-r--r-- | src/com/gitblit/Constants.java | 2 | ||||
-rw-r--r-- | src/com/gitblit/GitBlitException.java | 4 | ||||
-rw-r--r-- | src/com/gitblit/RpcFilter.java | 2 | ||||
-rw-r--r-- | src/com/gitblit/RpcServlet.java | 27 | ||||
-rw-r--r-- | src/com/gitblit/utils/RpcUtils.java | 21 |
5 files changed, 54 insertions, 2 deletions
diff --git a/src/com/gitblit/Constants.java b/src/com/gitblit/Constants.java index 450c11fb..25143051 100644 --- a/src/com/gitblit/Constants.java +++ b/src/com/gitblit/Constants.java @@ -201,7 +201,7 @@ public class Constants { * a client.
*/
public static enum RpcRequest {
- LIST_REPOSITORIES, CREATE_REPOSITORY, EDIT_REPOSITORY, DELETE_REPOSITORY,
+ LIST_REPOSITORIES, LIST_BRANCHES, CREATE_REPOSITORY, EDIT_REPOSITORY, DELETE_REPOSITORY,
LIST_USERS, CREATE_USER, EDIT_USER, DELETE_USER, LIST_REPOSITORY_MEMBERS,
SET_REPOSITORY_MEMBERS, LIST_FEDERATION_REGISTRATIONS, LIST_FEDERATION_RESULTS,
LIST_FEDERATION_PROPOSALS, LIST_FEDERATION_SETS, LIST_SETTINGS, EDIT_SETTINGS,
diff --git a/src/com/gitblit/GitBlitException.java b/src/com/gitblit/GitBlitException.java index 360f9f0a..7ab0f99d 100644 --- a/src/com/gitblit/GitBlitException.java +++ b/src/com/gitblit/GitBlitException.java @@ -31,6 +31,10 @@ public class GitBlitException extends IOException { super(message);
}
+ public GitBlitException(Throwable cause) {
+ super(cause);
+ }
+
/**
* Exception to indicate that the client should prompt for credentials
* because the requested action requires authentication.
diff --git a/src/com/gitblit/RpcFilter.java b/src/com/gitblit/RpcFilter.java index 551ca3c6..e768a514 100644 --- a/src/com/gitblit/RpcFilter.java +++ b/src/com/gitblit/RpcFilter.java @@ -64,7 +64,7 @@ public class RpcFilter extends AuthenticationFilter { return;
}
- boolean adminRequest = requestType.exceeds(RpcRequest.LIST_REPOSITORIES);
+ boolean adminRequest = requestType.exceeds(RpcRequest.LIST_BRANCHES);
// conditionally reject all rpc requests
if (!GitBlit.getBoolean(Keys.web.enableRpcServlet, true)) {
diff --git a/src/com/gitblit/RpcServlet.java b/src/com/gitblit/RpcServlet.java index 53628a09..b068a39b 100644 --- a/src/com/gitblit/RpcServlet.java +++ b/src/com/gitblit/RpcServlet.java @@ -27,11 +27,15 @@ import javax.servlet.ServletException; import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
+import org.eclipse.jgit.lib.Repository;
+
import com.gitblit.Constants.RpcRequest;
+import com.gitblit.models.RefModel;
import com.gitblit.models.RepositoryModel;
import com.gitblit.models.ServerSettings;
import com.gitblit.models.UserModel;
import com.gitblit.utils.HttpUtils;
+import com.gitblit.utils.JGitUtils;
import com.gitblit.utils.RpcUtils;
/**
@@ -86,6 +90,29 @@ public class RpcServlet extends JsonServlet { repositories.put(url, model);
}
result = repositories;
+ } else if (RpcRequest.LIST_BRANCHES.equals(reqType)) {
+ // list all branches in all repositories accessible to user
+ Map<String, List<String>> allBranches = new HashMap<String, List<String>>();
+ List<RepositoryModel> models = GitBlit.self().getRepositoryModels(user);
+ for (RepositoryModel model : models) {
+ if (!model.hasCommits) {
+ // skip empty repository
+ continue;
+ }
+ // get branches
+ Repository repository = GitBlit.self().getRepository(model.name);
+ List<RefModel> refs = JGitUtils.getLocalBranches(repository, false, -1);
+ refs.addAll(JGitUtils.getRemoteBranches(repository, false, -1));
+ if (refs.size() > 0) {
+ List<String> branches = new ArrayList<String>();
+ for (RefModel ref : refs) {
+ branches.add(ref.getName());
+ }
+ allBranches.put(model.name, branches);
+ }
+ repository.close();
+ }
+ result = allBranches;
} else if (RpcRequest.LIST_USERS.equals(reqType)) {
// list users
List<String> names = GitBlit.self().getAllUsernames();
diff --git a/src/com/gitblit/utils/RpcUtils.java b/src/com/gitblit/utils/RpcUtils.java index e5841518..faa910ba 100644 --- a/src/com/gitblit/utils/RpcUtils.java +++ b/src/com/gitblit/utils/RpcUtils.java @@ -62,6 +62,9 @@ public class RpcUtils { private static final Type SETS_TYPE = new TypeToken<Collection<FederationSet>>() {
}.getType();
+ private static final Type BRANCHES_TYPE = new TypeToken<Map<String, Collection<String>>>() {
+ }.getType();
+
/**
*
* @param remoteURL
@@ -386,6 +389,24 @@ public class RpcUtils { }
/**
+ * Retrieves a map of all branches in the Gitblit server keyed by
+ * repository.
+ *
+ * @param serverUrl
+ * @param account
+ * @param password
+ * @return
+ * @throws IOException
+ */
+ public static Map<String, Collection<String>> getAllBranches(String serverUrl,
+ String account, char[] password) throws IOException {
+ String url = asLink(serverUrl, RpcRequest.LIST_BRANCHES);
+ Map<String, Collection<String>> allReferences = JsonUtils.retrieveJson(url,
+ BRANCHES_TYPE, account, password);
+ return allReferences;
+ }
+
+ /**
* Do the specified administrative action on the Gitblit server.
*
* @param request
|