]> source.dussan.org Git - jgit.git/commitdiff
RepoCommand#readFile: Don't call Git#getRepository() in try-with-resource 66/89666/2
authorDavid Pursehouse <david.pursehouse@gmail.com>
Fri, 27 Jan 2017 05:44:14 +0000 (14:44 +0900)
committerMatthias Sohn <matthias.sohn@sap.com>
Sat, 28 Jan 2017 16:46:28 +0000 (17:46 +0100)
Using try-with-resource means that close() will automatically be
called on the Repository object. However, according to the javadoc
of Git#close():

  If the repository was opened by a static factory method in this class,
  then this method calls Repository#close() on the underlying repository
  instance.

This means that Repository#close() is called twice, by Git.close()
and in the outer try-with-resource, leading to a corrupt use count.

Change-Id: I37ba517eb2cc67d1cd36813598772c70208d0bc9
Signed-off-by: David Pursehouse <david.pursehouse@gmail.com>
org.eclipse.jgit/src/org/eclipse/jgit/gitrepo/RepoCommand.java

index 86dbabca0b9c9b61f850b9fe2d8a63e1ffe9e0bd..d18cd97489053c494f4d9c10b6be4be448ef3c8b 100644 (file)
@@ -181,9 +181,8 @@ public class RepoCommand extends GitCommand<RevCommit> {
                                throws GitAPIException, IOException {
                        File dir = FileUtils.createTempDir("jgit_", ".git", null); //$NON-NLS-1$ //$NON-NLS-2$
                        try (Git git = Git.cloneRepository().setBare(true).setDirectory(dir)
-                                       .setURI(uri).call();
-                                       Repository repo = git.getRepository()) {
-                               return readFileFromRepo(repo, ref, path);
+                                       .setURI(uri).call()) {
+                               return readFileFromRepo(git.getRepository(), ref, path);
                        } finally {
                                FileUtils.delete(dir, FileUtils.RECURSIVE);
                        }