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