summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorShawn Pearce <sop@google.com>2011-06-07 09:50:09 -0700
committerAndroid Code Review <code-review@android.com>2011-06-07 09:50:09 -0700
commit045b76c6d63c091bdd43235cb035a61501421529 (patch)
treea93f944c0f2a3eb6745ff0e63135f5122e0367c2
parent99071dd23240d121967f84759651f61f698442e0 (diff)
parent3739569aad5153cc33ae59f3a1ad98b848fe5fad (diff)
Merge "Implement multiple branches in ls-project"
-rw-r--r--Documentation/cmd-ls-projects.txt10
-rw-r--r--gerrit-sshd/src/main/java/com/google/gerrit/sshd/commands/ListProjects.java48
2 files changed, 45 insertions, 13 deletions
diff --git a/Documentation/cmd-ls-projects.txt b/Documentation/cmd-ls-projects.txt
index 1e7b4cc7ce..2134df8319 100644
--- a/Documentation/cmd-ls-projects.txt
+++ b/Documentation/cmd-ls-projects.txt
@@ -8,7 +8,7 @@ gerrit ls-projects - List projects visible to caller
SYNOPSIS
--------
[verse]
-'ssh' -p <port> <host> 'gerrit ls-projects' [\--show-branch <BRANCH>]
+'ssh' -p <port> <host> 'gerrit ls-projects' [\--show-branch <BRANCH1> ...]
DESCRIPTION
-----------
@@ -30,7 +30,13 @@ OPTIONS
-------
\--show-branch::
\-b::
- Name of the branch for which the command will display the sha of each project.
+ Branch for which the command will display the sha of each project.
+ The command may have multiple \--show-branch parameters, in this case
+ sha will be shown for each of the branches.
+ If the user does not have READ access to some branch or the branch does not
+ exist then stub (forty '\-' symbols) is shown.
+ If the user does not have access to any branch in the project then the
+ whole project is not shown.
\--tree::
\-t::
diff --git a/gerrit-sshd/src/main/java/com/google/gerrit/sshd/commands/ListProjects.java b/gerrit-sshd/src/main/java/com/google/gerrit/sshd/commands/ListProjects.java
index b70b743844..d38794913d 100644
--- a/gerrit-sshd/src/main/java/com/google/gerrit/sshd/commands/ListProjects.java
+++ b/gerrit-sshd/src/main/java/com/google/gerrit/sshd/commands/ListProjects.java
@@ -49,8 +49,9 @@ final class ListProjects extends BaseCommand {
@Inject
private GitRepositoryManager repoManager;
- @Option(name = "--show-branch", aliases = {"-b"}, usage = "displays the sha of each project in the specified branch")
- private String showBranch;
+ @Option(name = "--show-branch", aliases = {"-b"}, multiValued = true,
+ usage = "displays the sha of each project in the specified branch")
+ private List<String> showBranch;
@Option(name = "--tree", aliases = {"-t"}, usage = "displays project inheritance in a tree-like format\n" +
"this option does not work together with the show-branch option")
@@ -102,16 +103,37 @@ final class ListProjects extends BaseCommand {
}
if (showBranch != null) {
- final Ref ref = getBranchRef(projectName);
- if (ref == null || ref.getObjectId() == null
- || !pctl.controlForRef(ref.getLeaf().getName()).isVisible()) {
- // No branch, or the user can't see this branch, so skip it.
- //
+ final List<Ref> refs = getBranchRefs(projectName);
+ if (refs == null) {
continue;
}
- stdout.print(ref.getObjectId().name());
- stdout.print(' ');
+ boolean hasVisibleRefs = false;
+ for (int i = 0; i < refs.size(); i++) {
+ Ref ref = refs.get(i);
+ if (ref == null
+ || ref.getObjectId() == null
+ || !pctl.controlForRef(ref.getLeaf().getName()).isVisible()) {
+ // No branch, or the user can't see this branch, so remove it.
+ refs.set(i, null);
+ } else {
+ hasVisibleRefs = true;
+ }
+ }
+
+ if (!hasVisibleRefs) {
+ continue;
+ }
+
+ for (Ref ref : refs) {
+ if (ref == null) {
+ // Print stub (forty '-' symbols)
+ stdout.print("----------------------------------------");
+ } else {
+ stdout.print(ref.getObjectId().name());
+ }
+ stdout.print(' ');
+ }
}
stdout.print(projectName.get() + "\n");
@@ -151,11 +173,15 @@ final class ListProjects extends BaseCommand {
}
}
- private Ref getBranchRef(Project.NameKey projectName) {
+ private List<Ref> getBranchRefs(Project.NameKey projectName) {
try {
final Repository r = repoManager.openRepository(projectName);
try {
- return r.getRef(showBranch);
+ final List<Ref> result = new ArrayList<Ref>(showBranch.size());
+ for (String branch : showBranch) {
+ result.add(r.getRef(branch));
+ }
+ return result;
} finally {
r.close();
}