Browse Source

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

Change-Id: I991f0096c833da721b98c1e0423a8dadc67cd64f
Signed-off-by: David Pursehouse <david.pursehouse@gmail.com>
stable-5.0
David Pursehouse 7 years ago
parent
commit
aa563091d5
  1. 34
      org.eclipse.jgit/src/org/eclipse/jgit/treewalk/WorkingTreeIterator.java

34
org.eclipse.jgit/src/org/eclipse/jgit/treewalk/WorkingTreeIterator.java

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

Loading…
Cancel
Save