added to view history of the specific file.

This commit is contained in:
youngwan
2011-11-14 10:43:34 +09:00
parent 996ad0b044
commit c0905b8a14
9 changed files with 300 additions and 11 deletions

View File

@@ -55,4 +55,12 @@ public interface ClientChangesetHandler
* @return
*/
public ChangesetPagingResult getChangesets(int start, int limit);
/**
* @param path
* @param start
* @param limit
* @return
*/
public ChangesetPagingResult getChangesets(String path, int start, int limit);
}

View File

@@ -247,11 +247,12 @@ public class ScmUrlProvider
* @param repositoryId
* @since 1.8
*
* @param path
* @param start
* @param limit
* @return
*/
public String getRepositoryChangesetUrl(String repositoryId, int start,
public String getRepositoryChangesetUrl(String repositoryId, String path, int start,
int limit)
{
String url = MessageFormat.format(getResourceUrl(URLPATTERN_CHANGESETS),
@@ -268,10 +269,31 @@ public class ScmUrlProvider
{
url = url.concat(s).concat("limit=").concat(String.valueOf(limit));
}
if (path != null) {
url = url.concat(s).concat("path=").concat(path);
}
return url;
}
/**
* Method description
*
*
* @param repositoryId
* @since 1.8
*
* @param start
* @param limit
* @return
*/
public String getRepositoryChangesetUrl(String repositoryId, int start,
int limit)
{
return getRepositoryChangesetUrl(repositoryId, null, start, limit);
}
/**
* Method description
*

View File

@@ -103,6 +103,43 @@ public class JerseyClientChangesetHandler implements ClientChangesetHandler
return result;
}
/**
* Method description
*
*
* @param start
* @param limit
*
* @return
*/
@Override
public ChangesetPagingResult getChangesets(String path, int start, int limit)
{
ChangesetPagingResult result = null;
String url =
session.getUrlProvider().getRepositoryChangesetUrl(repository.getId(),
start, limit);
WebResource resource = session.getClient().resource(url);
ClientResponse response = null;
try
{
response = resource.get(ClientResponse.class);
if (response.getStatus() != ScmClientException.SC_NOTFOUND)
{
ClientUtil.checkResponse(response, 200);
result = response.getEntity(ChangesetPagingResult.class);
}
}
finally
{
ClientUtil.close(response);
}
return result;
}
//~--- fields ---------------------------------------------------------------
/** Field description */

View File

@@ -60,4 +60,22 @@ public interface ChangesetViewer
*/
public ChangesetPagingResult getChangesets(int start, int max)
throws IOException, RepositoryException;
/**
* Method description
*
*
*
*
* @param path
* @param start
* @param max
*
* @return
*
* @throws IOException
* @throws RepositoryException
*/
public ChangesetPagingResult getChangesets(String path, int start, int max)
throws IOException, RepositoryException;
}

View File

@@ -127,6 +127,38 @@ public class ChangesetViewerUtil extends PartCacheClearHook
return getChangesets(repository, start, max);
}
/**
* Method description
*
*
* @param repositoryId
* @param start
* @param max
*
* @return
*
*
* @throws IOException
* @throws NotSupportedFeatuerException
* @throws RepositoryException
*/
public ChangesetPagingResult getChangesets(String repositoryId, String path,
int start, int max)
throws IOException, RepositoryException, NotSupportedFeatuerException
{
AssertUtil.assertIsNotEmpty(repositoryId);
Repository repository = repositoryManager.get(repositoryId);
if (repository == null)
{
throw new RepositoryNotFoundException(
"could not find repository with id ".concat(repositoryId));
}
return getChangesets(repository, path, start, max);
}
/**
* Method description
*
@@ -158,7 +190,7 @@ public class ChangesetViewerUtil extends PartCacheClearHook
}
ChangesetViewerCacheKey key =
new ChangesetViewerCacheKey(repository.getId(), start, max);
new ChangesetViewerCacheKey(repository.getId(), "", start, max);
ChangesetPagingResult result = cache.get(key);
if (result == null)
@@ -188,6 +220,67 @@ public class ChangesetViewerUtil extends PartCacheClearHook
return result;
}
/**
* Method description
*
*
* @param repository
* @param path
* @param start
* @param max
*
* @return
*
*
* @throws IOException
* @throws NotSupportedFeatuerException
* @throws RepositoryException
*/
public ChangesetPagingResult getChangesets(Repository repository, String path,
int start, int max)
throws IOException, RepositoryException, NotSupportedFeatuerException
{
AssertUtil.assertIsNotNull(repository);
ChangesetViewer viewer = repositoryManager.getChangesetViewer(repository);
if (viewer == null)
{
throw new NotSupportedFeatuerException(
"ChangesetViewer is not supported for type ".concat(
repository.getType()));
}
ChangesetViewerCacheKey key =
new ChangesetViewerCacheKey(repository.getId(), path, start, max);
ChangesetPagingResult result = cache.get(key);
if (result == null)
{
result = viewer.getChangesets(path, start, max);
if (result != null)
{
if (Util.isNotEmpty(result.getChangesets()))
{
callPreProcessors(result);
callPreProcessorFactories(repository, result);
}
cache.put(key, result);
}
else
{
throw new RepositoryException("could not fetch changesets");
}
}
else if (logger.isDebugEnabled())
{
logger.debug("fetch changesetviewer results from cache");
}
return result;
}
//~--- methods --------------------------------------------------------------
/**
@@ -259,9 +352,10 @@ public class ChangesetViewerUtil extends PartCacheClearHook
* @param start
* @param max
*/
public ChangesetViewerCacheKey(String repository, int start, int max)
public ChangesetViewerCacheKey(String repository, String path, int start, int max)
{
this.repository = repository;
this.path = path;
this.start = start;
this.max = max;
}
@@ -297,6 +391,13 @@ public class ChangesetViewerUtil extends PartCacheClearHook
{
return false;
}
if ((this.path == null)
? (other.path != null)
: !this.path.equals(other.path))
{
return false;
}
if (this.start != other.start)
{
@@ -338,6 +439,9 @@ public class ChangesetViewerUtil extends PartCacheClearHook
/** Field description */
private String repository;
/** Field description */
private String path;
/** Field description */
private int start;

View File

@@ -150,6 +150,76 @@ public class GitChangesetViewer implements ChangesetViewer
return changesets;
}
/**
* Method description
*
*
* @param path
* @param start
* @param max
*
* @return
*/
@Override
public ChangesetPagingResult getChangesets(String path, int start, int max)
{
ChangesetPagingResult changesets = null;
File directory = handler.getDirectory(repository);
org.eclipse.jgit.lib.Repository gr = null;
GitChangesetConverter converter = null;
try
{
gr = GitUtil.open(directory);
int counter = 0;
List<Changeset> changesetList = new ArrayList<Changeset>();
if (!gr.getAllRefs().isEmpty())
{
converter = new GitChangesetConverter(gr, GitUtil.ID_LENGTH);
Git git = new Git(gr);
ObjectId headId = GitUtil.getRepositoryHead(gr);
if (headId != null)
{
for (RevCommit commit : git.log().addPath(path).call())
{
if ((counter >= start) && (counter < start + max))
{
changesetList.add(converter.createChangeset(commit));
}
counter++;
}
}
else if (logger.isWarnEnabled())
{
logger.warn("could not find repository head of repository {}",
repository.getName());
}
}
changesets = new ChangesetPagingResult(counter, changesetList);
}
catch (NoHeadException ex)
{
logger.error("could not read changesets", ex);
}
catch (IOException ex)
{
logger.error("could not open repository", ex);
}
finally
{
IOUtil.close(converter);
GitUtil.close(gr);
}
return changesets;
}
//~--- fields ---------------------------------------------------------------
/** Field description */

View File

@@ -114,6 +114,13 @@ public class HgChangesetViewer extends AbstractHgHandler
null);
}
@Override
public ChangesetPagingResult getChangesets(String path, int start, int max)
throws IOException, RepositoryException {
// TODO Auto-generated method stub
return null;
}
/**
* Method description
*

View File

@@ -47,6 +47,7 @@ import org.tmatesoft.svn.core.io.SVNRepositoryFactory;
//~--- JDK imports ------------------------------------------------------------
import java.io.File;
import java.io.IOException;
import java.util.ArrayList;
import java.util.Collection;
@@ -92,6 +93,21 @@ public class SvnChangesetViewer implements ChangesetViewer
@Override
public ChangesetPagingResult getChangesets(int start, int max)
{
return getChangesets("", start, max);
}
/**
* Method description
*
*
* @param path
* @param start
* @param max
*
* @return
*/
@Override
public ChangesetPagingResult getChangesets(String path, int start, int max) {
ChangesetPagingResult changesets = null;
File directory = handler.getDirectory(repostory);
SVNRepository repository = null;
@@ -110,9 +126,9 @@ public class SvnChangesetViewer implements ChangesetViewer
}
List<Changeset> changesetList = new ArrayList<Changeset>();
Collection<SVNLogEntry> entries = repository.log(new String[] { "" },
Collection<SVNLogEntry> entries = repository.log(new String[] { path },
null, startRev, endRev, true, true);
for (SVNLogEntry entry : entries)
{
changesetList.add(SvnUtil.createChangeset(entry));
@@ -132,12 +148,11 @@ public class SvnChangesetViewer implements ChangesetViewer
return changesets;
}
//~--- fields ---------------------------------------------------------------
/** Field description */
private SvnRepositoryHandler handler;
/** Field description */
private Repository repostory;
/** Field description */
private Repository repostory;
}

View File

@@ -35,6 +35,8 @@ package sonia.scm.api.rest.resources;
//~--- non-JDK imports --------------------------------------------------------
import antlr.StringUtils;
import com.google.inject.Inject;
import com.google.inject.Provider;
import com.google.inject.Singleton;
@@ -434,7 +436,8 @@ public class RepositoryResource
@Path("{id}/changesets")
@TypeHint(ChangesetPagingResult.class)
@Produces({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON })
public Response getChangesets(@PathParam("id") String id, @DefaultValue("0")
public Response getChangesets(@PathParam("id") String id, @DefaultValue("")
@QueryParam("path") String path, @DefaultValue("0")
@QueryParam("start") int start, @DefaultValue("20")
@QueryParam("limit") int limit) throws RepositoryException, IOException
{
@@ -442,8 +445,13 @@ public class RepositoryResource
try
{
ChangesetPagingResult changesets = changesetViewerUtil.getChangesets(id,
start, limit);
ChangesetPagingResult changesets;
if ("".equals(path)) {
changesets = changesetViewerUtil.getChangesets(id, start, limit);
}
else {
changesets = changesetViewerUtil.getChangesets(id, path, start, limit);
}
if (changesets != null)
{