improve repository browser api

This commit is contained in:
Sebastian Sdorra
2011-06-18 16:41:23 +02:00
parent 7d758aed6c
commit 5adea3f28b
5 changed files with 149 additions and 75 deletions

View File

@@ -37,7 +37,6 @@ package sonia.scm.repository;
import org.eclipse.jgit.dircache.DirCache;
import org.eclipse.jgit.dircache.DirCacheIterator;
import org.eclipse.jgit.errors.MissingObjectException;
import org.eclipse.jgit.lib.Constants;
import org.eclipse.jgit.lib.ObjectId;
import org.eclipse.jgit.lib.ObjectLoader;
@@ -52,7 +51,7 @@ import sonia.scm.util.Util;
import java.io.File;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.util.ArrayList;
import java.util.List;
@@ -86,14 +85,14 @@ public class GitRepositoryBrowser implements RepositoryBrowser
*
* @param revision
* @param path
* @param output
*
* @return
*
* @throws IOException
* @throws RepositoryException
*/
@Override
public InputStream getContent(String revision, String path)
public void getContent(String revision, String path, OutputStream output)
throws IOException, RepositoryException
{
throw new UnsupportedOperationException("Not supported yet.");
@@ -123,9 +122,7 @@ public class GitRepositoryBrowser implements RepositoryBrowser
try
{
ObjectId revId = getRevisionId(repo, revision);
DirCache cache = new DirCache(directory, FS.DETECTED);
TreeWalk treeWalk = new TreeWalk(repo);
@@ -159,21 +156,6 @@ public class GitRepositoryBrowser implements RepositoryBrowser
return result;
}
private ObjectId getRevisionId( org.eclipse.jgit.lib.Repository repo, String revision ) throws IOException{
ObjectId revId = null;
if (Util.isNotEmpty(revision))
{
revId = repo.resolve(revision);
}
else
{
revId = repo.resolve(Constants.HEAD);
}
return revId;
}
//~--- methods --------------------------------------------------------------
@@ -187,7 +169,6 @@ public class GitRepositoryBrowser implements RepositoryBrowser
* @return
*
* @throws IOException
* @throws MissingObjectException
*/
private FileObject createFileObject(org.eclipse.jgit.lib.Repository repo,
TreeWalk treeWalk)
@@ -209,6 +190,37 @@ public class GitRepositoryBrowser implements RepositoryBrowser
return file;
}
//~--- get methods ----------------------------------------------------------
/**
* Method description
*
*
* @param repo
* @param revision
*
* @return
*
* @throws IOException
*/
private ObjectId getRevisionId(org.eclipse.jgit.lib.Repository repo,
String revision)
throws IOException
{
ObjectId revId = null;
if (Util.isNotEmpty(revision))
{
revId = repo.resolve(revision);
}
else
{
revId = repo.resolve(Constants.HEAD);
}
return revId;
}
//~--- fields ---------------------------------------------------------------
/** Field description */

View File

@@ -109,14 +109,14 @@ public class HgRepositoryBrowser implements RepositoryBrowser
*
* @param revision
* @param path
* @param output
*
* @return
*
* @throws IOException
* @throws RepositoryException
*/
@Override
public InputStream getContent(String revision, String path)
public void getContent(String revision, String path, OutputStream output)
throws IOException, RepositoryException
{
if (Util.isEmpty(revision))
@@ -141,7 +141,18 @@ public class HgRepositoryBrowser implements RepositoryBrowser
logger.debug(msg.toString());
}
return builder.directory(directory).start().getInputStream();
Process p = builder.directory(directory).start();
InputStream input = null;
try
{
input = p.getInputStream();
IOUtil.copy(input, output);
}
finally
{
IOUtil.close(input);
}
}
/**

View File

@@ -50,11 +50,9 @@ import sonia.scm.util.Util;
//~--- JDK imports ------------------------------------------------------------
import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.io.File;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.util.ArrayList;
import java.util.Collection;
@@ -95,30 +93,23 @@ public class SvnRepositoryBrowser implements RepositoryBrowser
*
* @param revision
* @param path
* @param output
*
* @return
*
* @throws IOException
* @throws RepositoryException
*/
@Override
public InputStream getContent(String revision, String path)
public void getContent(String revision, String path, OutputStream output)
throws IOException, RepositoryException
{
// TODO change the api, to remove the ByteArray streams
InputStream content = null;
long revisionNumber = getRevisionNumber(revision);
SVNRepository svnRepository = null;
try
{
svnRepository = getSvnRepository();
ByteArrayOutputStream baos = new ByteArrayOutputStream();
svnRepository.getFile(path, revisionNumber, new SVNProperties(), baos);
content = new ByteArrayInputStream(baos.toByteArray());
svnRepository.getFile(path, revisionNumber, new SVNProperties(), output);
}
catch (SVNException ex)
{
@@ -126,10 +117,8 @@ public class SvnRepositoryBrowser implements RepositoryBrowser
}
finally
{
svnRepository.closeSession();
close(svnRepository);
}
return content;
}
/**
@@ -202,7 +191,7 @@ public class SvnRepositoryBrowser implements RepositoryBrowser
}
finally
{
svnRepository.closeSession();
close(svnRepository);
}
return result;
@@ -210,6 +199,20 @@ public class SvnRepositoryBrowser implements RepositoryBrowser
//~--- methods --------------------------------------------------------------
/**
* Method description
*
*
* @param svnRepository
*/
private void close(SVNRepository svnRepository)
{
if (svnRepository != null)
{
svnRepository.closeSession();
}
}
/**
* Method description
*