Commits

Sebastian Sdorra  committed fac2d21 Merge

merge with branch issue-500

  • Participants
  • Parent commits 82004a9, cf591a8

Comments (0)

Files changed (4)

File scm-plugins/scm-git-plugin/src/main/java/sonia/scm/repository/GitHookChangesetCollector.java

     finally
     {
       IOUtil.close(converter);
+      GitUtil.release(walk);
     }
 
     return changesets;

File scm-plugins/scm-git-plugin/src/main/java/sonia/scm/repository/GitUtil.java

 import org.eclipse.jgit.lib.Constants;
 import org.eclipse.jgit.lib.ObjectId;
 import org.eclipse.jgit.lib.Ref;
-import org.eclipse.jgit.lib.RepositoryCache;
 import org.eclipse.jgit.revwalk.RevCommit;
 import org.eclipse.jgit.revwalk.RevWalk;
+import org.eclipse.jgit.storage.file.FileRepositoryBuilder;
 import org.eclipse.jgit.transport.FetchResult;
 import org.eclipse.jgit.transport.RefSpec;
 import org.eclipse.jgit.treewalk.TreeWalk;
   public static final String REF_MASTER = "master";
 
   /** Field description */
+  private static final String DIRECTORY_DOTGIT = ".git";
+
+  /** Field description */
+  private static final String DIRECTORY_OBJETCS = "objects";
+
+  /** Field description */
+  private static final String DIRECTORY_REFS = "refs";
+
+  /** Field description */
   private static final String PREFIX_HEADS = "refs/heads/";
 
   /** Field description */
   public static org.eclipse.jgit.lib.Repository open(File directory)
     throws IOException
   {
-    return RepositoryCache.open(RepositoryCache.FileKey.lenient(directory,
-      FS.DETECTED), true);
+    FS fs = FS.DETECTED;
+    FileRepositoryBuilder builder = new FileRepositoryBuilder();
+
+    builder.setFS(fs);
+
+    if (isGitDirectory(fs, directory))
+    {
+
+      // bare repository
+      builder.setGitDir(directory).setBare();
+    }
+    else
+    {
+      builder.setWorkTree(directory);
+    }
+
+    return builder.build();
   }
 
   /**
     String localBranch)
   {
     String branch = localBranch;
-    if ( localBranch.startsWith(REF_HEAD_PREFIX) )
+
+    if (localBranch.startsWith(REF_HEAD_PREFIX))
     {
       branch = localBranch.substring(REF_HEAD_PREFIX.length());
     }
+
     return String.format(REMOTE_REF, repository.getId(), branch);
   }
 
     return name;
   }
 
+  /**
+   * Method description
+   *
+   *
+   * @param dir
+   *
+   * @return
+   */
+  public static boolean isGitDirectory(File dir)
+  {
+    return isGitDirectory(FS.DETECTED, dir);
+  }
+
+  /**
+   * Method description
+   *
+   *
+   * @param fs
+   * @param dir
+   *
+   * @return
+   */
+  public static boolean isGitDirectory(FS fs, File dir)
+  {
+    //J-
+    return fs.resolve(dir, DIRECTORY_OBJETCS).exists()
+      && fs.resolve(dir, DIRECTORY_REFS).exists() 
+      &&!fs.resolve(dir, DIRECTORY_DOTGIT).exists();
+    //J+
+  }
+
   //~--- methods --------------------------------------------------------------
 
   /**

File scm-plugins/scm-git-plugin/src/main/java/sonia/scm/repository/spi/GitLogCommand.java

     Changeset changeset = null;
     Repository gr = null;
     GitChangesetConverter converter = null;
+    RevWalk revWalk = null;
 
     try
     {
 
       if (!gr.getAllRefs().isEmpty())
       {
-        RevWalk revWalk = new RevWalk(gr);
+        revWalk = new RevWalk(gr);
         ObjectId id = GitUtil.getRevisionId(gr, revision);
         RevCommit commit = revWalk.parseCommit(id);
 
     finally
     {
       IOUtil.close(converter);
+      GitUtil.release(revWalk);
       GitUtil.close(gr);
     }
 
 
     ChangesetPagingResult changesets = null;
     GitChangesetConverter converter = null;
+    RevWalk revWalk = null;
 
     try
     {
           endId = gr.resolve(request.getEndChangeset());
         }
 
-        RevWalk revWalk = new RevWalk(gr);
+        revWalk = new RevWalk(gr);
 
         converter = new GitChangesetConverter(gr, revWalk);
 
     finally
     {
       IOUtil.close(converter);
+      GitUtil.release(revWalk);
     }
 
     return changesets;

File support/scm-support-youdebug/GitFileLeak.ydb

+/**
+ * Copyright (c) 2010, Sebastian Sdorra
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are met:
+ *
+ * 1. Redistributions of source code must retain the above copyright notice,
+ *    this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright notice,
+ *    this list of conditions and the following disclaimer in the documentation
+ *    and/or other materials provided with the distribution.
+ * 3. Neither the name of SCM-Manager; nor the names of its
+ *    contributors may be used to endorse or promote products derived from this
+ *    software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ * DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE FOR ANY
+ * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
+ * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
+ * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
+ * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
+ * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ *
+ * http://bitbucket.org/sdorra/scm-manager
+ *
+ */
+ 
+ 
+vm.breakpoint("org.eclipse.jgit.lib.Repository", 133){
+  println "open repository " + gitDir;
+}
+
+vm.breakpoint("org.eclipse.jgit.lib.Repository", 808){
+  println "  open repository, counter: " + useCnt.get();
+}
+
+vm.breakpoint("org.eclipse.jgit.lib.Repository", 812){
+  println "  close repository, counter: " + useCnt.get();
+}
+
+vm.breakpoint("org.eclipse.jgit.lib.Repository", 813){
+  println "close repository";
+}
+
+vm.breakpoint("org.eclipse.jgit.revwalk.RevWalk", 215){
+  println "    open revwalk";
+}
+
+vm.breakpoint("org.eclipse.jgit.revwalk.RevWalk", 239){
+  println "    release revwalk";
+}