Merge "Implement multiple branches in ls-project"
This commit is contained in:
commit
045b76c6d6
|
@ -8,7 +8,7 @@ gerrit ls-projects - List projects visible to caller
|
||||||
SYNOPSIS
|
SYNOPSIS
|
||||||
--------
|
--------
|
||||||
[verse]
|
[verse]
|
||||||
'ssh' -p <port> <host> 'gerrit ls-projects' [\--show-branch <BRANCH>]
|
'ssh' -p <port> <host> 'gerrit ls-projects' [\--show-branch <BRANCH1> ...]
|
||||||
|
|
||||||
DESCRIPTION
|
DESCRIPTION
|
||||||
-----------
|
-----------
|
||||||
|
@ -30,7 +30,13 @@ OPTIONS
|
||||||
-------
|
-------
|
||||||
\--show-branch::
|
\--show-branch::
|
||||||
\-b::
|
\-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::
|
\--tree::
|
||||||
\-t::
|
\-t::
|
||||||
|
|
|
@ -49,8 +49,9 @@ final class ListProjects extends BaseCommand {
|
||||||
@Inject
|
@Inject
|
||||||
private GitRepositoryManager repoManager;
|
private GitRepositoryManager repoManager;
|
||||||
|
|
||||||
@Option(name = "--show-branch", aliases = {"-b"}, usage = "displays the sha of each project in the specified branch")
|
@Option(name = "--show-branch", aliases = {"-b"}, multiValued = true,
|
||||||
private String showBranch;
|
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" +
|
@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")
|
"this option does not work together with the show-branch option")
|
||||||
|
@ -102,17 +103,38 @@ final class ListProjects extends BaseCommand {
|
||||||
}
|
}
|
||||||
|
|
||||||
if (showBranch != null) {
|
if (showBranch != null) {
|
||||||
final Ref ref = getBranchRef(projectName);
|
final List<Ref> refs = getBranchRefs(projectName);
|
||||||
if (ref == null || ref.getObjectId() == null
|
if (refs == null) {
|
||||||
|| !pctl.controlForRef(ref.getLeaf().getName()).isVisible()) {
|
|
||||||
// No branch, or the user can't see this branch, so skip it.
|
|
||||||
//
|
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
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(ref.getObjectId().name());
|
||||||
|
}
|
||||||
stdout.print(' ');
|
stdout.print(' ');
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
stdout.print(projectName.get() + "\n");
|
stdout.print(projectName.get() + "\n");
|
||||||
} else {
|
} else {
|
||||||
|
@ -151,11 +173,15 @@ final class ListProjects extends BaseCommand {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private Ref getBranchRef(Project.NameKey projectName) {
|
private List<Ref> getBranchRefs(Project.NameKey projectName) {
|
||||||
try {
|
try {
|
||||||
final Repository r = repoManager.openRepository(projectName);
|
final Repository r = repoManager.openRepository(projectName);
|
||||||
try {
|
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 {
|
} finally {
|
||||||
r.close();
|
r.close();
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue