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();
|
||||
List<Ref> refs = new ArrayList<>(heads.size() + 2);
|
||||
refs.addAll(heads);
|
||||
try {
|
||||
Ref head = db.getRef(Constants.HEAD);
|
||||
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.
|
||||
}
|
||||
addRef(db, refs, Constants.HEAD);
|
||||
addRef(db, refs, RefNames.REFS_CONFIG);
|
||||
|
||||
Set<String> targets = Sets.newHashSetWithExpectedSize(1);
|
||||
for (Ref ref : refs) {
|
||||
@@ -188,6 +174,14 @@ public class ListBranches implements RestReadView<ProjectResource> {
|
||||
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)
|
||||
throws BadRequestException {
|
||||
if (matchSubstring != null) {
|
||||
|
Reference in New Issue
Block a user