mirror of
https://github.com/scm-manager/scm-manager.git
synced 2025-11-06 05:25:44 +01:00
merge with branch issue-500
This commit is contained in:
@@ -189,6 +189,7 @@ public class GitHookChangesetCollector
|
||||
finally
|
||||
{
|
||||
IOUtil.close(converter);
|
||||
GitUtil.release(walk);
|
||||
}
|
||||
|
||||
return changesets;
|
||||
|
||||
@@ -48,9 +48,9 @@ import org.eclipse.jgit.errors.MissingObjectException;
|
||||
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;
|
||||
@@ -85,6 +85,15 @@ public final class GitUtil
|
||||
/** Field description */
|
||||
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/";
|
||||
|
||||
@@ -222,8 +231,23 @@ public final class GitUtil
|
||||
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();
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -599,10 +623,12 @@ public final class GitUtil
|
||||
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);
|
||||
}
|
||||
|
||||
@@ -626,6 +652,37 @@ public final class GitUtil
|
||||
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 --------------------------------------------------------------
|
||||
|
||||
/**
|
||||
|
||||
@@ -114,6 +114,7 @@ public class GitLogCommand extends AbstractGitCommand implements LogCommand
|
||||
Changeset changeset = null;
|
||||
Repository gr = null;
|
||||
GitChangesetConverter converter = null;
|
||||
RevWalk revWalk = null;
|
||||
|
||||
try
|
||||
{
|
||||
@@ -121,7 +122,7 @@ public class GitLogCommand extends AbstractGitCommand implements LogCommand
|
||||
|
||||
if (!gr.getAllRefs().isEmpty())
|
||||
{
|
||||
RevWalk revWalk = new RevWalk(gr);
|
||||
revWalk = new RevWalk(gr);
|
||||
ObjectId id = GitUtil.getRevisionId(gr, revision);
|
||||
RevCommit commit = revWalk.parseCommit(id);
|
||||
|
||||
@@ -143,6 +144,7 @@ public class GitLogCommand extends AbstractGitCommand implements LogCommand
|
||||
finally
|
||||
{
|
||||
IOUtil.close(converter);
|
||||
GitUtil.release(revWalk);
|
||||
GitUtil.close(gr);
|
||||
}
|
||||
|
||||
@@ -171,6 +173,7 @@ public class GitLogCommand extends AbstractGitCommand implements LogCommand
|
||||
|
||||
ChangesetPagingResult changesets = null;
|
||||
GitChangesetConverter converter = null;
|
||||
RevWalk revWalk = null;
|
||||
|
||||
try
|
||||
{
|
||||
@@ -207,7 +210,7 @@ public class GitLogCommand extends AbstractGitCommand implements LogCommand
|
||||
endId = gr.resolve(request.getEndChangeset());
|
||||
}
|
||||
|
||||
RevWalk revWalk = new RevWalk(gr);
|
||||
revWalk = new RevWalk(gr);
|
||||
|
||||
converter = new GitChangesetConverter(gr, revWalk);
|
||||
|
||||
@@ -278,6 +281,7 @@ public class GitLogCommand extends AbstractGitCommand implements LogCommand
|
||||
finally
|
||||
{
|
||||
IOUtil.close(converter);
|
||||
GitUtil.release(revWalk);
|
||||
}
|
||||
|
||||
return changesets;
|
||||
|
||||
Reference in New Issue
Block a user