mirror of
https://github.com/scm-manager/scm-manager.git
synced 2025-11-06 13:35:44 +01:00
update jgit to version 2.0.0.201206130900-r
This commit is contained in:
@@ -37,6 +37,7 @@ package sonia.scm.repository;
|
||||
|
||||
import org.eclipse.jgit.api.BlameCommand;
|
||||
import org.eclipse.jgit.api.Git;
|
||||
import org.eclipse.jgit.api.errors.GitAPIException;
|
||||
import org.eclipse.jgit.blame.BlameResult;
|
||||
import org.eclipse.jgit.lib.ObjectId;
|
||||
import org.eclipse.jgit.lib.PersonIdent;
|
||||
@@ -123,20 +124,19 @@ public class GitBlameViewer implements BlameViewer
|
||||
List<BlameLine> blameLines = new ArrayList<BlameLine>();
|
||||
int total = gitBlameResult.getResultContents().size();
|
||||
int i = 0;
|
||||
|
||||
|
||||
for (; i < total; i++)
|
||||
{
|
||||
RevCommit commit = gitBlameResult.getSourceCommit(i);
|
||||
|
||||
if ( commit != null )
|
||||
{
|
||||
RevCommit commit = gitBlameResult.getSourceCommit(i);
|
||||
|
||||
if (commit != null)
|
||||
{
|
||||
PersonIdent author = gitBlameResult.getSourceAuthor(i);
|
||||
BlameLine blameLine = new BlameLine();
|
||||
|
||||
blameLine.setLineNumber(i + 1);
|
||||
blameLine.setAuthor(new Person(author.getName(),
|
||||
author.getEmailAddress()));
|
||||
|
||||
blameLine.setDescription(commit.getShortMessage());
|
||||
|
||||
long when = GitUtil.getCommitTime(commit);
|
||||
@@ -151,7 +151,7 @@ public class GitBlameViewer implements BlameViewer
|
||||
|
||||
blameLine.setCode(content);
|
||||
blameLines.add(blameLine);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
blameResult = new sonia.scm.repository.BlameResult(i, blameLines);
|
||||
@@ -160,6 +160,10 @@ public class GitBlameViewer implements BlameViewer
|
||||
{
|
||||
logger.error("could not open repository", ex);
|
||||
}
|
||||
catch (GitAPIException ex)
|
||||
{
|
||||
logger.error("could not create blame view", ex);
|
||||
}
|
||||
|
||||
return blameResult;
|
||||
}
|
||||
|
||||
@@ -36,6 +36,7 @@ package sonia.scm.repository;
|
||||
//~--- non-JDK imports --------------------------------------------------------
|
||||
|
||||
import org.eclipse.jgit.api.Git;
|
||||
import org.eclipse.jgit.api.errors.GitAPIException;
|
||||
import org.eclipse.jgit.api.errors.NoHeadException;
|
||||
import org.eclipse.jgit.lib.ObjectId;
|
||||
import org.eclipse.jgit.revwalk.RevCommit;
|
||||
@@ -198,6 +199,10 @@ public class GitChangesetViewer implements ChangesetViewer
|
||||
{
|
||||
logger.error("could not read changesets", ex);
|
||||
}
|
||||
catch (GitAPIException ex)
|
||||
{
|
||||
logger.error("could not read changesets", ex);
|
||||
}
|
||||
catch (IOException ex)
|
||||
{
|
||||
logger.error("could not open repository", ex);
|
||||
@@ -279,6 +284,10 @@ public class GitChangesetViewer implements ChangesetViewer
|
||||
{
|
||||
logger.error("could not read changesets", ex);
|
||||
}
|
||||
catch (GitAPIException ex)
|
||||
{
|
||||
logger.error("could not read changesets", ex);
|
||||
}
|
||||
catch (IOException ex)
|
||||
{
|
||||
logger.error("could not open repository", ex);
|
||||
|
||||
@@ -30,6 +30,7 @@
|
||||
*/
|
||||
|
||||
|
||||
|
||||
package sonia.scm.repository.spi;
|
||||
|
||||
//~--- non-JDK imports --------------------------------------------------------
|
||||
@@ -38,6 +39,7 @@ import com.google.common.base.Preconditions;
|
||||
import com.google.common.base.Strings;
|
||||
|
||||
import org.eclipse.jgit.api.Git;
|
||||
import org.eclipse.jgit.api.errors.GitAPIException;
|
||||
import org.eclipse.jgit.lib.ObjectId;
|
||||
import org.eclipse.jgit.lib.PersonIdent;
|
||||
import org.eclipse.jgit.revwalk.RevCommit;
|
||||
@@ -113,56 +115,68 @@ public class GitBlameCommand extends AbstractGitCommand implements BlameCommand
|
||||
Preconditions.checkArgument(!Strings.isNullOrEmpty(request.getPath()),
|
||||
"path is empty or null");
|
||||
|
||||
org.eclipse.jgit.lib.Repository gr = open();
|
||||
org.eclipse.jgit.api.BlameCommand blame = new Git(gr).blame();
|
||||
BlameResult result = null;
|
||||
|
||||
blame.setFilePath(request.getPath());
|
||||
|
||||
ObjectId revId = GitUtil.getRevisionId(gr, request.getRevision());
|
||||
|
||||
blame.setStartCommit(revId);
|
||||
|
||||
org.eclipse.jgit.blame.BlameResult gitBlameResult = blame.call();
|
||||
|
||||
if (gitBlameResult == null)
|
||||
try
|
||||
{
|
||||
throw new RepositoryException(
|
||||
"could not create blame result for path ".concat(request.getPath()));
|
||||
}
|
||||
org.eclipse.jgit.lib.Repository gr = open();
|
||||
org.eclipse.jgit.api.BlameCommand blame = new Git(gr).blame();
|
||||
|
||||
List<BlameLine> blameLines = new ArrayList<BlameLine>();
|
||||
int total = gitBlameResult.getResultContents().size();
|
||||
int i = 0;
|
||||
blame.setFilePath(request.getPath());
|
||||
|
||||
for (; i < total; i++)
|
||||
{
|
||||
RevCommit commit = gitBlameResult.getSourceCommit(i);
|
||||
ObjectId revId = GitUtil.getRevisionId(gr, request.getRevision());
|
||||
|
||||
if (commit != null)
|
||||
blame.setStartCommit(revId);
|
||||
|
||||
org.eclipse.jgit.blame.BlameResult gitBlameResult = blame.call();
|
||||
|
||||
if (gitBlameResult == null)
|
||||
{
|
||||
PersonIdent author = gitBlameResult.getSourceAuthor(i);
|
||||
BlameLine blameLine = new BlameLine();
|
||||
|
||||
blameLine.setLineNumber(i + 1);
|
||||
blameLine.setAuthor(new Person(author.getName(),
|
||||
author.getEmailAddress()));
|
||||
blameLine.setDescription(commit.getShortMessage());
|
||||
|
||||
long when = GitUtil.getCommitTime(commit);
|
||||
|
||||
blameLine.setWhen(when);
|
||||
|
||||
String rev = commit.getId().getName();
|
||||
|
||||
blameLine.setRevision(rev);
|
||||
|
||||
String content = gitBlameResult.getResultContents().getString(i);
|
||||
|
||||
blameLine.setCode(content);
|
||||
blameLines.add(blameLine);
|
||||
throw new RepositoryException(
|
||||
"could not create blame result for path ".concat(
|
||||
request.getPath()));
|
||||
}
|
||||
|
||||
List<BlameLine> blameLines = new ArrayList<BlameLine>();
|
||||
int total = gitBlameResult.getResultContents().size();
|
||||
int i = 0;
|
||||
|
||||
for (; i < total; i++)
|
||||
{
|
||||
RevCommit commit = gitBlameResult.getSourceCommit(i);
|
||||
|
||||
if (commit != null)
|
||||
{
|
||||
PersonIdent author = gitBlameResult.getSourceAuthor(i);
|
||||
BlameLine blameLine = new BlameLine();
|
||||
|
||||
blameLine.setLineNumber(i + 1);
|
||||
blameLine.setAuthor(new Person(author.getName(),
|
||||
author.getEmailAddress()));
|
||||
blameLine.setDescription(commit.getShortMessage());
|
||||
|
||||
long when = GitUtil.getCommitTime(commit);
|
||||
|
||||
blameLine.setWhen(when);
|
||||
|
||||
String rev = commit.getId().getName();
|
||||
|
||||
blameLine.setRevision(rev);
|
||||
|
||||
String content = gitBlameResult.getResultContents().getString(i);
|
||||
|
||||
blameLine.setCode(content);
|
||||
blameLines.add(blameLine);
|
||||
}
|
||||
}
|
||||
|
||||
result = new BlameResult(i, blameLines);
|
||||
}
|
||||
catch (GitAPIException ex)
|
||||
{
|
||||
throw new RepositoryException("could not create blame view", ex);
|
||||
}
|
||||
|
||||
return new sonia.scm.repository.BlameResult(i, blameLines);
|
||||
return result;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -30,6 +30,7 @@
|
||||
*/
|
||||
|
||||
|
||||
|
||||
package sonia.scm.repository.spi;
|
||||
|
||||
//~--- non-JDK imports --------------------------------------------------------
|
||||
@@ -38,6 +39,7 @@ import com.google.common.base.Strings;
|
||||
import com.google.common.collect.Lists;
|
||||
|
||||
import org.eclipse.jgit.api.Git;
|
||||
import org.eclipse.jgit.api.errors.GitAPIException;
|
||||
import org.eclipse.jgit.api.errors.NoHeadException;
|
||||
import org.eclipse.jgit.lib.ObjectId;
|
||||
import org.eclipse.jgit.lib.Repository;
|
||||
@@ -51,6 +53,7 @@ import sonia.scm.repository.Changeset;
|
||||
import sonia.scm.repository.ChangesetPagingResult;
|
||||
import sonia.scm.repository.GitChangesetConverter;
|
||||
import sonia.scm.repository.GitUtil;
|
||||
import sonia.scm.repository.RepositoryException;
|
||||
import sonia.scm.util.IOUtil;
|
||||
|
||||
//~--- JDK imports ------------------------------------------------------------
|
||||
@@ -154,10 +157,11 @@ public class GitLogCommand extends AbstractGitCommand implements LogCommand
|
||||
* @return
|
||||
*
|
||||
* @throws IOException
|
||||
* @throws RepositoryException
|
||||
*/
|
||||
@Override
|
||||
public ChangesetPagingResult getChangesets(LogCommandRequest request)
|
||||
throws IOException
|
||||
throws IOException, RepositoryException
|
||||
{
|
||||
if (logger.isDebugEnabled())
|
||||
{
|
||||
@@ -257,6 +261,10 @@ public class GitLogCommand extends AbstractGitCommand implements LogCommand
|
||||
|
||||
changesets = new ChangesetPagingResult(0, new ArrayList<Changeset>());
|
||||
}
|
||||
catch (GitAPIException ex)
|
||||
{
|
||||
throw new RepositoryException("could not create change log", ex);
|
||||
}
|
||||
finally
|
||||
{
|
||||
IOUtil.close(converter);
|
||||
|
||||
@@ -38,12 +38,16 @@ package sonia.scm.web;
|
||||
import org.apache.commons.lang.StringEscapeUtils;
|
||||
|
||||
import org.eclipse.jgit.api.Git;
|
||||
import org.eclipse.jgit.api.errors.GitAPIException;
|
||||
import org.eclipse.jgit.api.errors.NoHeadException;
|
||||
import org.eclipse.jgit.lib.ObjectId;
|
||||
import org.eclipse.jgit.lib.PersonIdent;
|
||||
import org.eclipse.jgit.lib.Repository;
|
||||
import org.eclipse.jgit.revwalk.RevCommit;
|
||||
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import sonia.scm.io.RegexResourceProcessor;
|
||||
import sonia.scm.io.ResourceProcessor;
|
||||
import sonia.scm.repository.GitUtil;
|
||||
@@ -75,6 +79,12 @@ public class GitRepositoryViewer
|
||||
/** Field description */
|
||||
public static final String RESOURCE_GITINDEX = "/sonia/scm/git.index.html";
|
||||
|
||||
/**
|
||||
* the logger for GitRepositoryViewer
|
||||
*/
|
||||
private static final Logger logger =
|
||||
LoggerFactory.getLogger(GitRepositoryViewer.class);
|
||||
|
||||
//~--- methods --------------------------------------------------------------
|
||||
|
||||
/**
|
||||
@@ -107,16 +117,23 @@ public class GitRepositoryViewer
|
||||
int c = 0;
|
||||
ObjectId head = GitUtil.getRepositoryHead(repository);
|
||||
|
||||
for (RevCommit commit : git.log().add(head).call())
|
||||
try
|
||||
{
|
||||
appendCommit(sb, commit);
|
||||
c++;
|
||||
|
||||
if (c > logSize)
|
||||
for (RevCommit commit : git.log().add(head).call())
|
||||
{
|
||||
break;
|
||||
appendCommit(sb, commit);
|
||||
c++;
|
||||
|
||||
if (c > logSize)
|
||||
{
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
catch (GitAPIException ex)
|
||||
{
|
||||
logger.error("could not read changesets", ex);
|
||||
}
|
||||
}
|
||||
|
||||
processor.addVariable("commits", sb.toString());
|
||||
|
||||
@@ -30,6 +30,7 @@
|
||||
*/
|
||||
|
||||
|
||||
|
||||
package sonia.scm.repository.spi;
|
||||
|
||||
//~--- non-JDK imports --------------------------------------------------------
|
||||
@@ -39,6 +40,7 @@ import org.junit.Test;
|
||||
import sonia.scm.repository.Changeset;
|
||||
import sonia.scm.repository.ChangesetPagingResult;
|
||||
import sonia.scm.repository.Modifications;
|
||||
import sonia.scm.repository.RepositoryException;
|
||||
|
||||
import static org.hamcrest.Matchers.*;
|
||||
|
||||
@@ -60,9 +62,10 @@ public class GitLogCommandTest extends AbstractGitCommandTestBase
|
||||
*
|
||||
*
|
||||
* @throws IOException
|
||||
* @throws RepositoryException
|
||||
*/
|
||||
@Test
|
||||
public void testGetAll() throws IOException
|
||||
public void testGetAll() throws IOException, RepositoryException
|
||||
{
|
||||
ChangesetPagingResult result =
|
||||
createCommand().getChangesets(new LogCommandRequest());
|
||||
@@ -77,9 +80,10 @@ public class GitLogCommandTest extends AbstractGitCommandTestBase
|
||||
*
|
||||
*
|
||||
* @throws IOException
|
||||
* @throws RepositoryException
|
||||
*/
|
||||
@Test
|
||||
public void testGetAllByPath() throws IOException
|
||||
public void testGetAllByPath() throws IOException, RepositoryException
|
||||
{
|
||||
LogCommandRequest request = new LogCommandRequest();
|
||||
|
||||
@@ -100,9 +104,10 @@ public class GitLogCommandTest extends AbstractGitCommandTestBase
|
||||
*
|
||||
*
|
||||
* @throws IOException
|
||||
* @throws RepositoryException
|
||||
*/
|
||||
@Test
|
||||
public void testGetAllWithLimit() throws IOException
|
||||
public void testGetAllWithLimit() throws IOException, RepositoryException
|
||||
{
|
||||
LogCommandRequest request = new LogCommandRequest();
|
||||
|
||||
@@ -130,9 +135,10 @@ public class GitLogCommandTest extends AbstractGitCommandTestBase
|
||||
*
|
||||
*
|
||||
* @throws IOException
|
||||
* @throws RepositoryException
|
||||
*/
|
||||
@Test
|
||||
public void testGetAllWithPaging() throws IOException
|
||||
public void testGetAllWithPaging() throws IOException, RepositoryException
|
||||
{
|
||||
LogCommandRequest request = new LogCommandRequest();
|
||||
|
||||
@@ -189,9 +195,10 @@ public class GitLogCommandTest extends AbstractGitCommandTestBase
|
||||
*
|
||||
*
|
||||
* @throws IOException
|
||||
* @throws RepositoryException
|
||||
*/
|
||||
@Test
|
||||
public void testGetRange() throws IOException
|
||||
public void testGetRange() throws IOException, RepositoryException
|
||||
{
|
||||
LogCommandRequest request = new LogCommandRequest();
|
||||
|
||||
|
||||
Reference in New Issue
Block a user