]> source.dussan.org Git - gitblit.git/commitdiff
Fixed repository reference leak in fork mechanism
authorJames Moger <james.moger@gitblit.com>
Thu, 4 Oct 2012 22:27:06 +0000 (18:27 -0400)
committerJames Moger <james.moger@gitblit.com>
Thu, 4 Oct 2012 22:27:06 +0000 (18:27 -0400)
src/com/gitblit/GitBlit.java
src/com/gitblit/utils/JGitUtils.java

index b14adc97df2c651d89c73b0aa7e8473c164cfb97..5a4135657dae81374bb1b3cbc6754291318d34e6 100644 (file)
@@ -57,18 +57,13 @@ import javax.servlet.ServletContextListener;
 import javax.servlet.http.Cookie;\r
 \r
 import org.apache.wicket.protocol.http.WebResponse;\r
-import org.eclipse.jgit.errors.RepositoryNotFoundException;\r
 import org.eclipse.jgit.lib.Repository;\r
+import org.eclipse.jgit.lib.RepositoryCache;\r
 import org.eclipse.jgit.lib.RepositoryCache.FileKey;\r
 import org.eclipse.jgit.lib.StoredConfig;\r
 import org.eclipse.jgit.storage.file.FileBasedConfig;\r
 import org.eclipse.jgit.storage.file.WindowCache;\r
 import org.eclipse.jgit.storage.file.WindowCacheConfig;\r
-import org.eclipse.jgit.transport.ServiceMayNotContinueException;\r
-import org.eclipse.jgit.transport.resolver.FileResolver;\r
-import org.eclipse.jgit.transport.resolver.RepositoryResolver;\r
-import org.eclipse.jgit.transport.resolver.ServiceNotAuthorizedException;\r
-import org.eclipse.jgit.transport.resolver.ServiceNotEnabledException;\r
 import org.eclipse.jgit.util.FS;\r
 import org.eclipse.jgit.util.FileUtils;\r
 import org.slf4j.Logger;\r
@@ -142,8 +137,6 @@ public class GitBlit implements ServletContextListener {
        \r
        private final AtomicReference<String> repositoryListSettingsChecksum = new AtomicReference<String>("");\r
 \r
-       private RepositoryResolver<Void> repositoryResolver;\r
-\r
        private ServletContext servletContext;\r
 \r
        private File repositoriesFolder;\r
@@ -895,33 +888,19 @@ public class GitBlit implements ServletContextListener {
         * @return repository or null\r
         */\r
        public Repository getRepository(String repositoryName, boolean logError) {\r
+               File dir = FileKey.resolve(new File(repositoriesFolder, repositoryName), FS.DETECTED);\r
+               if (dir == null)\r
+                       return null;\r
+\r
                Repository r = null;\r
                try {\r
-                       r = repositoryResolver.open(null, repositoryName);\r
-               } catch (RepositoryNotFoundException e) {\r
-                       r = null;\r
+                       FileKey key = FileKey.exact(dir, FS.DETECTED);\r
+                       r = RepositoryCache.open(key, true);\r
+               } catch (IOException e) {\r
                        if (logError) {\r
                                logger.error("GitBlit.getRepository(String) failed to find "\r
                                                + new File(repositoriesFolder, repositoryName).getAbsolutePath());\r
                        }\r
-               } catch (ServiceNotAuthorizedException e) {\r
-                       r = null;\r
-                       if (logError) {\r
-                               logger.error("GitBlit.getRepository(String) failed to find "\r
-                                               + new File(repositoriesFolder, repositoryName).getAbsolutePath(), e);\r
-                       }\r
-               } catch (ServiceNotEnabledException e) {\r
-                       r = null;\r
-                       if (logError) {\r
-                               logger.error("GitBlit.getRepository(String) failed to find "\r
-                                               + new File(repositoriesFolder, repositoryName).getAbsolutePath(), e);\r
-                       }\r
-               } catch (ServiceMayNotContinueException e) {\r
-                       r = null;\r
-                       if (logError) {\r
-                               logger.error("GitBlit.getRepository(String) failed to find "\r
-                                               + new File(repositoriesFolder, repositoryName).getAbsolutePath(), e);\r
-                       }\r
                }\r
                return r;\r
        }\r
@@ -1470,6 +1449,8 @@ public class GitBlit implements ServletContextListener {
         */\r
        private void closeRepository(String repositoryName) {\r
                Repository repository = getRepository(repositoryName);\r
+               RepositoryCache.close(repository);\r
+\r
                // assume 2 uses in case reflection fails\r
                int uses = 2;\r
                try {\r
@@ -1641,17 +1622,7 @@ public class GitBlit implements ServletContextListener {
 \r
                        // load repository\r
                        logger.info("edit repository " + repository.name);\r
-                       try {\r
-                               r = repositoryResolver.open(null, repository.name);\r
-                       } catch (RepositoryNotFoundException e) {\r
-                               logger.error("Repository not found", e);\r
-                       } catch (ServiceNotAuthorizedException e) {\r
-                               logger.error("Service not authorized", e);\r
-                       } catch (ServiceNotEnabledException e) {\r
-                               logger.error("Service not enabled", e);\r
-                       } catch (ServiceMayNotContinueException e) {\r
-                               logger.error("Service may not continue", e);\r
-                       }\r
+                       r = getRepository(repository.name);\r
                }\r
 \r
                // update settings\r
@@ -2499,7 +2470,6 @@ public class GitBlit implements ServletContextListener {
                this.settings = settings;\r
                repositoriesFolder = getRepositoriesFolder();\r
                logger.info("Git repositories folder " + repositoriesFolder.getAbsolutePath());\r
-               repositoryResolver = new FileResolver<Void>(repositoriesFolder, true);\r
 \r
                // calculate repository list settings checksum for future config changes\r
                repositoryListSettingsChecksum.set(getRepositoryListSettingsChecksum());\r
index 050b591f483e77b8e4a7737c1e106a7d0e5983b4..231b935ceec8335973bca3c201d9c9bd84f90222 100644 (file)
@@ -210,11 +210,10 @@ public class JGitUtils {
                        if (credentialsProvider != null) {\r
                                clone.setCredentialsProvider(credentialsProvider);\r
                        }\r
-                       clone.call();\r
+                       Repository repository = clone.call().getRepository();\r
+                       \r
                        // Now we have to fetch because CloneCommand doesn't fetch\r
                        // refs/notes nor does it allow manual RefSpec.\r
-                       File gitDir = FileKey.resolve(new File(repositoriesFolder, name), FS.DETECTED);\r
-                       FileRepository repository = new FileRepository(gitDir);\r
                        result.createdRepository = true;\r
                        result.fetchResult = fetchRepository(credentialsProvider, repository);\r
                        repository.close();\r