ListBranches: Don't ignore IOExceptions reading refs
Factor out this logic into an addRef method to save a line or two. Change-Id: Iaeacfca063ccfb9643da1e2614ab5e2b7ffdc31f
This commit is contained in:
@@ -92,22 +92,8 @@ public class ListBranches implements RestReadView<ProjectResource> {
|
|||||||
db.getRefDatabase().getRefs(Constants.R_HEADS).values();
|
db.getRefDatabase().getRefs(Constants.R_HEADS).values();
|
||||||
List<Ref> refs = new ArrayList<>(heads.size() + 2);
|
List<Ref> refs = new ArrayList<>(heads.size() + 2);
|
||||||
refs.addAll(heads);
|
refs.addAll(heads);
|
||||||
try {
|
addRef(db, refs, Constants.HEAD);
|
||||||
Ref head = db.getRef(Constants.HEAD);
|
addRef(db, refs, RefNames.REFS_CONFIG);
|
||||||
if (head != null) {
|
|
||||||
refs.add(head);
|
|
||||||
}
|
|
||||||
} catch (IOException e) {
|
|
||||||
// Ignore the failure reading HEAD.
|
|
||||||
}
|
|
||||||
try {
|
|
||||||
Ref config = db.getRef(RefNames.REFS_CONFIG);
|
|
||||||
if (config != null) {
|
|
||||||
refs.add(config);
|
|
||||||
}
|
|
||||||
} catch (IOException e) {
|
|
||||||
// Ignore the failure reading refs/meta/config.
|
|
||||||
}
|
|
||||||
|
|
||||||
Set<String> targets = Sets.newHashSetWithExpectedSize(1);
|
Set<String> targets = Sets.newHashSetWithExpectedSize(1);
|
||||||
for (Ref ref : refs) {
|
for (Ref ref : refs) {
|
||||||
@@ -188,6 +174,14 @@ public class ListBranches implements RestReadView<ProjectResource> {
|
|||||||
return filteredBranches;
|
return filteredBranches;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private static void addRef(Repository db, List<Ref> refs, String name)
|
||||||
|
throws IOException {
|
||||||
|
Ref ref = db.getRef(name);
|
||||||
|
if (ref != null) {
|
||||||
|
refs.add(ref);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
private List<BranchInfo> filterBranches(List<BranchInfo> branches)
|
private List<BranchInfo> filterBranches(List<BranchInfo> branches)
|
||||||
throws BadRequestException {
|
throws BadRequestException {
|
||||||
if (matchSubstring != null) {
|
if (matchSubstring != null) {
|
||||||
|
|||||||
Reference in New Issue
Block a user