WorkingTreeIterator#idSubmodule: Refactor to open Repository in try-with-resource

Change-Id: I991f0096c833da721b98c1e0423a8dadc67cd64f
Signed-off-by: David Pursehouse <david.pursehouse@gmail.com>
This commit is contained in:
David Pursehouse 2018-03-14 10:19:06 +09:00
parent 67df4986ce
commit aa563091d5
1 changed files with 13 additions and 21 deletions

View File

@ -340,30 +340,22 @@ protected byte[] idSubmodule(Entry e) {
* @return non-null submodule id
*/
protected byte[] idSubmodule(File directory, Entry e) {
final Repository submoduleRepo;
try {
submoduleRepo = SubmoduleWalk.getSubmoduleRepository(directory,
e.getName(),
repository != null ? repository.getFS() : FS.DETECTED);
try (Repository submoduleRepo = SubmoduleWalk.getSubmoduleRepository(
directory, e.getName(),
repository != null ? repository.getFS() : FS.DETECTED)) {
if (submoduleRepo == null) {
return zeroid;
}
ObjectId head = submoduleRepo.resolve(Constants.HEAD);
if (head == null) {
return zeroid;
}
byte[] id = new byte[Constants.OBJECT_ID_LENGTH];
head.copyRawTo(id, 0);
return id;
} catch (IOException exception) {
return zeroid;
}
if (submoduleRepo == null)
return zeroid;
final ObjectId head;
try {
head = submoduleRepo.resolve(Constants.HEAD);
} catch (IOException exception) {
return zeroid;
} finally {
submoduleRepo.close();
}
if (head == null)
return zeroid;
final byte[] id = new byte[Constants.OBJECT_ID_LENGTH];
head.copyRawTo(id, 0);
return id;
}
private static final byte[] digits = { '0', '1', '2', '3', '4', '5', '6',