Merge "Use try-with-resource to close resources in BlobBasedConfig"
This commit is contained in:
commit
f96e15b1e6
|
@ -104,11 +104,8 @@ public BlobBasedConfig(Config base, Repository db, AnyObjectId objectId)
|
||||||
private static byte[] read(Repository db, AnyObjectId blobId)
|
private static byte[] read(Repository db, AnyObjectId blobId)
|
||||||
throws MissingObjectException, IncorrectObjectTypeException,
|
throws MissingObjectException, IncorrectObjectTypeException,
|
||||||
IOException {
|
IOException {
|
||||||
ObjectReader or = db.newObjectReader();
|
try (ObjectReader or = db.newObjectReader()) {
|
||||||
try {
|
|
||||||
return read(or, blobId);
|
return read(or, blobId);
|
||||||
} finally {
|
|
||||||
or.release();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -146,15 +143,12 @@ public BlobBasedConfig(Config base, Repository db, AnyObjectId treeish,
|
||||||
private static byte[] read(Repository db, AnyObjectId treeish, String path)
|
private static byte[] read(Repository db, AnyObjectId treeish, String path)
|
||||||
throws MissingObjectException, IncorrectObjectTypeException,
|
throws MissingObjectException, IncorrectObjectTypeException,
|
||||||
IOException {
|
IOException {
|
||||||
ObjectReader or = db.newObjectReader();
|
try (ObjectReader or = db.newObjectReader()) {
|
||||||
try {
|
|
||||||
TreeWalk tree = TreeWalk.forPath(or, path, asTree(or, treeish));
|
TreeWalk tree = TreeWalk.forPath(or, path, asTree(or, treeish));
|
||||||
if (tree == null)
|
if (tree == null)
|
||||||
throw new FileNotFoundException(MessageFormat.format(JGitText
|
throw new FileNotFoundException(MessageFormat.format(JGitText
|
||||||
.get().entryNotFoundByPath, path));
|
.get().entryNotFoundByPath, path));
|
||||||
return read(or, tree.getObjectId(0));
|
return read(or, tree.getObjectId(0));
|
||||||
} finally {
|
|
||||||
or.release();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -168,6 +162,8 @@ private static AnyObjectId asTree(ObjectReader or, AnyObjectId treeish)
|
||||||
&& ((RevCommit) treeish).getTree() != null)
|
&& ((RevCommit) treeish).getTree() != null)
|
||||||
return ((RevCommit) treeish).getTree();
|
return ((RevCommit) treeish).getTree();
|
||||||
|
|
||||||
return new RevWalk(or).parseTree(treeish).getId();
|
try (RevWalk rw = new RevWalk(or)) {
|
||||||
|
return rw.parseTree(treeish).getId();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue