ListBranches: Use Repository in try-with-resources

Change-Id: I43a1c6950f4181f43c08b140857854e438aca6be
This commit is contained in:
Dave Borowitz
2015-03-17 13:38:24 -07:00
parent eb7d88c1ec
commit 97cfab5e5e

View File

@@ -88,14 +88,7 @@ public class ListBranches implements RestReadView<ProjectResource> {
BranchInfo configBranch = null; BranchInfo configBranch = null;
final Set<String> targets = Sets.newHashSet(); final Set<String> targets = Sets.newHashSet();
final Repository db; try (Repository db = repoManager.openRepository(rsrc.getNameKey())) {
try {
db = repoManager.openRepository(rsrc.getNameKey());
} catch (RepositoryNotFoundException noGitRepository) {
throw new ResourceNotFoundException();
}
try {
List<Ref> refs = List<Ref> refs =
new ArrayList<>(db.getRefDatabase().getRefs(Constants.R_HEADS) new ArrayList<>(db.getRefDatabase().getRefs(Constants.R_HEADS)
.values()); .values());
@@ -157,8 +150,8 @@ public class ListBranches implements RestReadView<ProjectResource> {
} }
} }
} }
} finally { } catch (RepositoryNotFoundException noGitRepository) {
db.close(); throw new ResourceNotFoundException();
} }
Collections.sort(branches, new Comparator<BranchInfo>() { Collections.sort(branches, new Comparator<BranchInfo>() {
@Override @Override