Open Repository and RevWalk in try-with-resource
Change-Id: I551159e81afe9615be207fadf4f961762b1f6ad2
This commit is contained in:
parent
4b8516b3a0
commit
1eb09cb980
@ -310,17 +310,13 @@ public class ChangeKindCacheImpl implements ChangeKindCache {
|
||||
ChangeData.Factory changeDataFactory,
|
||||
ProjectCache projectCache,
|
||||
GitRepositoryManager repoManager) {
|
||||
Repository repo = null;
|
||||
// TODO - dborowitz: add NEW_CHANGE type for default.
|
||||
ChangeKind kind = ChangeKind.REWORK;
|
||||
// Trivial case: if we're on the first patch, we don't need to open
|
||||
// the repository.
|
||||
if (patch.getId().get() > 1) {
|
||||
try {
|
||||
try (Repository repo = repoManager.openRepository(change.getProject())) {
|
||||
ProjectState projectState = projectCache.checkedGet(change.getProject());
|
||||
|
||||
repo = repoManager.openRepository(change.getProject());
|
||||
|
||||
ChangeData cd = changeDataFactory.create(db, change);
|
||||
Collection<PatchSet> patchSetCollection = cd.patchSets();
|
||||
PatchSet priorPs = patch;
|
||||
@ -347,10 +343,6 @@ public class ChangeKindCacheImpl implements ChangeKindCache {
|
||||
// Do nothing; assume we have a complex change
|
||||
log.warn("Unable to get change kind for patchSet " + patch.getPatchSetId() +
|
||||
"of change " + change.getChangeId(), e);
|
||||
} finally {
|
||||
if (repo != null) {
|
||||
repo.close();
|
||||
}
|
||||
}
|
||||
}
|
||||
return kind;
|
||||
|
@ -221,14 +221,10 @@ public class SubmoduleOp {
|
||||
private void updateGitlinks(ReviewDb db, Branch.NameKey subscriber,
|
||||
Collection<SubmoduleSubscription> updates) throws SubmoduleException {
|
||||
PersonIdent author = null;
|
||||
|
||||
Repository pdb = null;
|
||||
|
||||
StringBuilder msgbuf = new StringBuilder("Updated git submodules\n\n");
|
||||
try {
|
||||
boolean sameAuthorForAll = true;
|
||||
boolean sameAuthorForAll = true;
|
||||
|
||||
pdb = repoManager.openRepository(subscriber.getParentKey());
|
||||
try (Repository pdb = repoManager.openRepository(subscriber.getParentKey())) {
|
||||
if (pdb.getRef(subscriber.get()) == null) {
|
||||
throw new SubmoduleException(
|
||||
"The branch was probably deleted from the subscriber repository");
|
||||
@ -347,10 +343,6 @@ public class SubmoduleOp {
|
||||
} catch (IOException e) {
|
||||
throw new SubmoduleException("Cannot update gitlinks for "
|
||||
+ subscriber.get(), e);
|
||||
} finally {
|
||||
if (pdb != null) {
|
||||
pdb.close();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -96,27 +96,19 @@ public class AllProjectsCreator {
|
||||
}
|
||||
|
||||
public void create() throws IOException, ConfigInvalidException {
|
||||
Repository git = null;
|
||||
try {
|
||||
git = mgr.openRepository(allProjectsName);
|
||||
try (Repository git = mgr.openRepository(allProjectsName)) {
|
||||
initAllProjects(git);
|
||||
} catch (RepositoryNotFoundException notFound) {
|
||||
// A repository may be missing if this project existed only to store
|
||||
// inheritable permissions. For example 'All-Projects'.
|
||||
try {
|
||||
git = mgr.createRepository(allProjectsName);
|
||||
try (Repository git = mgr.createRepository(allProjectsName)) {
|
||||
initAllProjects(git);
|
||||
|
||||
RefUpdate u = git.updateRef(Constants.HEAD);
|
||||
u.link(RefNames.REFS_CONFIG);
|
||||
} catch (RepositoryNotFoundException err) {
|
||||
String name = allProjectsName.get();
|
||||
throw new IOException("Cannot create repository " + name, err);
|
||||
}
|
||||
} finally {
|
||||
if (git != null) {
|
||||
git.close();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -61,22 +61,15 @@ public class AllUsersCreator {
|
||||
}
|
||||
|
||||
public void create() throws IOException, ConfigInvalidException {
|
||||
Repository git = null;
|
||||
try {
|
||||
git = mgr.openRepository(allUsersName);
|
||||
try (Repository git = mgr.openRepository(allUsersName)) {
|
||||
initAllUsers(git);
|
||||
} catch (RepositoryNotFoundException notFound) {
|
||||
try {
|
||||
git = mgr.createRepository(allUsersName);
|
||||
try (Repository git = mgr.createRepository(allUsersName)) {
|
||||
initAllUsers(git);
|
||||
} catch (RepositoryNotFoundException err) {
|
||||
String name = allUsersName.get();
|
||||
throw new IOException("Cannot create repository " + name, err);
|
||||
}
|
||||
} finally {
|
||||
if (git != null) {
|
||||
git.close();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -1 +1 @@
|
||||
Subproject commit 264b7a00361f8a880cbad389523bf329f1989480
|
||||
Subproject commit cc91e0c2987a4606e19b10e320b14f6a0c911c06
|
@ -1 +1 @@
|
||||
Subproject commit b19086265e7cb3c23b9fbf7193fbbd16eadc3bf0
|
||||
Subproject commit 26f38c4514687c388472be19c9789eaa84b1d564
|
Loading…
Reference in New Issue
Block a user