added missing revision parameter to changesetviewer api

This commit is contained in:
Sebastian Sdorra
2011-11-15 20:45:37 +01:00
parent f6b83ba815
commit c609df47ef
8 changed files with 114 additions and 31 deletions

View File

@@ -60,7 +60,7 @@ public interface ChangesetViewer
*/ */
public ChangesetPagingResult getChangesets(int start, int max) public ChangesetPagingResult getChangesets(int start, int max)
throws IOException, RepositoryException; throws IOException, RepositoryException;
/** /**
* Method description * Method description
* *
@@ -68,6 +68,7 @@ public interface ChangesetViewer
* *
* *
* @param path * @param path
* @param revision
* @param start * @param start
* @param max * @param max
* *
@@ -76,6 +77,7 @@ public interface ChangesetViewer
* @throws IOException * @throws IOException
* @throws RepositoryException * @throws RepositoryException
*/ */
public ChangesetPagingResult getChangesets(String path, int start, int max) public ChangesetPagingResult getChangesets(String path, String revision,
int start, int max)
throws IOException, RepositoryException; throws IOException, RepositoryException;
} }

View File

@@ -132,6 +132,7 @@ public class ChangesetViewerUtil extends PartCacheClearHook
* *
* @param repositoryId * @param repositoryId
* @param path * @param path
* @param revision
* @param start * @param start
* @param max * @param max
* *
@@ -143,7 +144,7 @@ public class ChangesetViewerUtil extends PartCacheClearHook
* @throws RepositoryException * @throws RepositoryException
*/ */
public ChangesetPagingResult getChangesets(String repositoryId, String path, public ChangesetPagingResult getChangesets(String repositoryId, String path,
int start, int max) String revision, int start, int max)
throws IOException, RepositoryException, NotSupportedFeatuerException throws IOException, RepositoryException, NotSupportedFeatuerException
{ {
AssertUtil.assertIsNotEmpty(repositoryId); AssertUtil.assertIsNotEmpty(repositoryId);
@@ -156,7 +157,7 @@ public class ChangesetViewerUtil extends PartCacheClearHook
"could not find repository with id ".concat(repositoryId)); "could not find repository with id ".concat(repositoryId));
} }
return getChangesets(repository, path, start, max); return getChangesets(repository, path, revision, start, max);
} }
/** /**
@@ -190,8 +191,7 @@ public class ChangesetViewerUtil extends PartCacheClearHook
} }
ChangesetViewerCacheKey key = ChangesetViewerCacheKey key =
new ChangesetViewerCacheKey(repository.getId(), Util.EMPTY_STRING, start, new ChangesetViewerCacheKey(repository.getId(), start, max);
max);
ChangesetPagingResult result = cache.get(key); ChangesetPagingResult result = cache.get(key);
if (result == null) if (result == null)
@@ -227,6 +227,7 @@ public class ChangesetViewerUtil extends PartCacheClearHook
* *
* @param repository * @param repository
* @param path * @param path
* @param revision
* @param start * @param start
* @param max * @param max
* *
@@ -238,7 +239,7 @@ public class ChangesetViewerUtil extends PartCacheClearHook
* @throws RepositoryException * @throws RepositoryException
*/ */
public ChangesetPagingResult getChangesets(Repository repository, public ChangesetPagingResult getChangesets(Repository repository,
String path, int start, int max) String path, String revision, int start, int max)
throws IOException, RepositoryException, NotSupportedFeatuerException throws IOException, RepositoryException, NotSupportedFeatuerException
{ {
AssertUtil.assertIsNotNull(repository); AssertUtil.assertIsNotNull(repository);
@@ -253,12 +254,13 @@ public class ChangesetViewerUtil extends PartCacheClearHook
} }
ChangesetViewerCacheKey key = ChangesetViewerCacheKey key =
new ChangesetViewerCacheKey(repository.getId(), path, start, max); new ChangesetViewerCacheKey(repository.getId(), path, revision, start,
max);
ChangesetPagingResult result = cache.get(key); ChangesetPagingResult result = cache.get(key);
if (result == null) if (result == null)
{ {
result = viewer.getChangesets(path, start, max); result = viewer.getChangesets(path, revision, start, max);
if (result != null) if (result != null)
{ {
@@ -351,15 +353,30 @@ public class ChangesetViewerUtil extends PartCacheClearHook
* *
* *
* @param repository * @param repository
* @param path
* @param start * @param start
* @param max * @param max
*/ */
public ChangesetViewerCacheKey(String repository, String path, int start, public ChangesetViewerCacheKey(String repository, int start, int max)
int max) {
this(repository, null, null, start, max);
}
/**
* Constructs ...
*
*
* @param repository
* @param path
* @param revision
* @param start
* @param max
*/
public ChangesetViewerCacheKey(String repository, String path,
String revision, int start, int max)
{ {
this.repository = repository; this.repository = repository;
this.path = path; this.path = path;
this.revision = revision;
this.start = start; this.start = start;
this.max = max; this.max = max;
} }
@@ -389,6 +406,13 @@ public class ChangesetViewerUtil extends PartCacheClearHook
final ChangesetViewerCacheKey other = (ChangesetViewerCacheKey) obj; final ChangesetViewerCacheKey other = (ChangesetViewerCacheKey) obj;
if ((this.revision == null)
? (other.revision != null)
: !this.revision.equals(other.revision))
{
return false;
}
if (this.max != other.max) if (this.max != other.max)
{ {
return false; return false;
@@ -425,16 +449,19 @@ public class ChangesetViewerUtil extends PartCacheClearHook
@Override @Override
public int hashCode() public int hashCode()
{ {
int hash = 7; int hash = 5;
hash = 89 * hash + this.max; hash = 47 * hash + ((this.revision != null)
hash = 89 * hash + ((this.path != null) ? this.revision.hashCode()
: 0);
hash = 47 * hash + this.max;
hash = 47 * hash + ((this.path != null)
? this.path.hashCode() ? this.path.hashCode()
: 0); : 0);
hash = 89 * hash + ((this.repository != null) hash = 47 * hash + ((this.repository != null)
? this.repository.hashCode() ? this.repository.hashCode()
: 0); : 0);
hash = 89 * hash + this.start; hash = 47 * hash + this.start;
return hash; return hash;
} }
@@ -464,6 +491,9 @@ public class ChangesetViewerUtil extends PartCacheClearHook
/** Field description */ /** Field description */
private String repository; private String repository;
/** Field description */
private String revision;
/** Field description */ /** Field description */
private int start; private int start;
} }

View File

@@ -155,13 +155,15 @@ public class GitChangesetViewer implements ChangesetViewer
* *
* *
* @param path * @param path
* @param revision
* @param start * @param start
* @param max * @param max
* *
* @return * @return
*/ */
@Override @Override
public ChangesetPagingResult getChangesets(String path, int start, int max) public ChangesetPagingResult getChangesets(String path, String revision,
int start, int max)
{ {
ChangesetPagingResult changesets = null; ChangesetPagingResult changesets = null;
File directory = handler.getDirectory(repository); File directory = handler.getDirectory(repository);
@@ -180,11 +182,12 @@ public class GitChangesetViewer implements ChangesetViewer
converter = new GitChangesetConverter(gr, GitUtil.ID_LENGTH); converter = new GitChangesetConverter(gr, GitUtil.ID_LENGTH);
Git git = new Git(gr); Git git = new Git(gr);
ObjectId headId = GitUtil.getRepositoryHead(gr); ObjectId revisionId = GitUtil.getRevisionId(gr, revision);
if (headId != null) if (revisionId != null)
{ {
for (RevCommit commit : git.log().addPath(path).call()) for (RevCommit commit :
git.log().add(revisionId).addPath(path).call())
{ {
if ((counter >= start) && (counter < start + max)) if ((counter >= start) && (counter < start + max))
{ {
@@ -219,7 +222,7 @@ public class GitChangesetViewer implements ChangesetViewer
return changesets; return changesets;
} }
//~--- fields --------------------------------------------------------------- //~--- fields ---------------------------------------------------------------
/** Field description */ /** Field description */

View File

@@ -399,6 +399,7 @@ public class AbstractHgHandler
} }
msg.append("]"); msg.append("]");
logger.debug(msg.toString());
} }
ProcessBuilder pb = new ProcessBuilder(cmdList); ProcessBuilder pb = new ProcessBuilder(cmdList);

View File

@@ -35,7 +35,11 @@ package sonia.scm.repository;
//~--- non-JDK imports -------------------------------------------------------- //~--- non-JDK imports --------------------------------------------------------
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import sonia.scm.util.Util; import sonia.scm.util.Util;
import sonia.scm.web.HgUtil;
//~--- JDK imports ------------------------------------------------------------ //~--- JDK imports ------------------------------------------------------------
@@ -58,6 +62,10 @@ public class HgChangesetViewer extends AbstractHgHandler
/** Field description */ /** Field description */
public static final String RESOURCE_LOG = "/sonia/scm/hglog.py"; public static final String RESOURCE_LOG = "/sonia/scm/hglog.py";
/** the logger for HgChangesetViewer */
private static final Logger logger =
LoggerFactory.getLogger(HgChangesetViewer.class);
//~--- constructors --------------------------------------------------------- //~--- constructors ---------------------------------------------------------
/** /**
@@ -110,6 +118,11 @@ public class HgChangesetViewer extends AbstractHgHandler
public ChangesetPagingResult getChangesets(int start, int max) public ChangesetPagingResult getChangesets(int start, int max)
throws IOException, RepositoryException throws IOException, RepositoryException
{ {
if (logger.isDebugEnabled())
{
logger.debug("fetch changesets. start: {}, max: {}", start, max);
}
return getChangesets(null, null, String.valueOf(start), return getChangesets(null, null, String.valueOf(start),
String.valueOf(max), null, null); String.valueOf(max), null, null);
} }
@@ -119,6 +132,7 @@ public class HgChangesetViewer extends AbstractHgHandler
* *
* *
* @param path * @param path
* @param revision
* @param start * @param start
* @param max * @param max
* *
@@ -128,10 +142,21 @@ public class HgChangesetViewer extends AbstractHgHandler
* @throws RepositoryException * @throws RepositoryException
*/ */
@Override @Override
public ChangesetPagingResult getChangesets(String path, int start, int max) public ChangesetPagingResult getChangesets(String path, String revision,
int start, int max)
throws IOException, RepositoryException throws IOException, RepositoryException
{ {
return getChangesets(path, null, String.valueOf(start), revision = HgUtil.getRevision(revision);
if (logger.isDebugEnabled())
{
logger.debug(
"fetch changesets for path {} and revision {}. start: {}, max: {}",
new Object[] { path,
revision, start, max });
}
return getChangesets(path, revision, String.valueOf(start),
String.valueOf(max), null, null); String.valueOf(max), null, null);
} }
@@ -184,6 +209,12 @@ public class HgChangesetViewer extends AbstractHgHandler
public ChangesetPagingResult getChangesets(String startNode, String endNode) public ChangesetPagingResult getChangesets(String startNode, String endNode)
throws IOException, RepositoryException throws IOException, RepositoryException
{ {
if (logger.isDebugEnabled())
{
logger.debug("fetch changesets. start-node: {}, end-node: {}", startNode,
endNode);
}
return getChangesets(null, null, null, null, startNode, endNode); return getChangesets(null, null, null, null, startNode, endNode);
} }
} }

View File

@@ -93,7 +93,7 @@ public class SvnChangesetViewer implements ChangesetViewer
@Override @Override
public ChangesetPagingResult getChangesets(int start, int max) public ChangesetPagingResult getChangesets(int start, int max)
{ {
return getChangesets("", start, max); return getChangesets("", null, start, max);
} }
/** /**
@@ -101,13 +101,18 @@ public class SvnChangesetViewer implements ChangesetViewer
* *
* *
* @param path * @param path
* @param revision
* @param start * @param start
* @param max * @param max
* *
* @return * @return
*/ */
@Override @Override
public ChangesetPagingResult getChangesets(String path, int start, int max) { public ChangesetPagingResult getChangesets(String path, String revision,
int start, int max)
{
// TODO implement revision
ChangesetPagingResult changesets = null; ChangesetPagingResult changesets = null;
File directory = handler.getDirectory(repostory); File directory = handler.getDirectory(repostory);
SVNRepository repository = null; SVNRepository repository = null;
@@ -128,7 +133,7 @@ public class SvnChangesetViewer implements ChangesetViewer
List<Changeset> changesetList = new ArrayList<Changeset>(); List<Changeset> changesetList = new ArrayList<Changeset>();
Collection<SVNLogEntry> entries = repository.log(new String[] { path }, Collection<SVNLogEntry> entries = repository.log(new String[] { path },
null, startRev, endRev, true, true); null, startRev, endRev, true, true);
for (SVNLogEntry entry : entries) for (SVNLogEntry entry : entries)
{ {
changesetList.add(SvnUtil.createChangeset(entry)); changesetList.add(SvnUtil.createChangeset(entry));
@@ -148,11 +153,12 @@ public class SvnChangesetViewer implements ChangesetViewer
return changesets; return changesets;
} }
//~--- fields --------------------------------------------------------------- //~--- fields ---------------------------------------------------------------
/** Field description */ /** Field description */
private SvnRepositoryHandler handler; private SvnRepositoryHandler handler;
/** Field description */ /** Field description */
private Repository repostory; private Repository repostory;
} }

View File

@@ -424,6 +424,7 @@ public class RepositoryResource
* *
* @param id the id of the repository * @param id the id of the repository
* @param path path of a file * @param path path of a file
* @param revision the revision of the file specified by the path parameter
* @param start the start value for paging * @param start the start value for paging
* @param limit the limit value for paging * @param limit the limit value for paging
* *
@@ -438,6 +439,7 @@ public class RepositoryResource
@Produces({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON }) @Produces({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON })
public Response getChangesets(@PathParam("id") String id, public Response getChangesets(@PathParam("id") String id,
@QueryParam("path") String path, @QueryParam("path") String path,
@QueryParam("revision") String revision,
@DefaultValue("0") @DefaultValue("0")
@QueryParam("start") int start, @DefaultValue("20") @QueryParam("start") int start, @DefaultValue("20")
@QueryParam("limit") int limit) throws RepositoryException, IOException @QueryParam("limit") int limit) throws RepositoryException, IOException
@@ -454,7 +456,8 @@ public class RepositoryResource
} }
else else
{ {
changesets = changesetViewerUtil.getChangesets(id, path, start, limit); changesets = changesetViewerUtil.getChangesets(id, path, revision,
start, limit);
} }
if (changesets != null) if (changesets != null)

View File

@@ -36,8 +36,11 @@ Sonia.repository.ChangesetViewerPanel = Ext.extend(Ext.Panel, {
pageSize: 20, pageSize: 20,
historyId: null, historyId: null,
changesetStore: null, changesetStore: null,
path: null,
// parameters for file history view
inline: false, inline: false,
path: null,
revision: null,
changesetViewerTitleText: 'Commits {0}', changesetViewerTitleText: 'Commits {0}',
@@ -61,6 +64,10 @@ Sonia.repository.ChangesetViewerPanel = Ext.extend(Ext.Panel, {
if (this.path){ if (this.path){
params.path = this.path; params.path = this.path;
} }
if (this.revision){
params.revision = this.revision;
}
this.changesetStore = new Sonia.rest.JsonStore({ this.changesetStore = new Sonia.rest.JsonStore({
id: 'changesetStore', id: 'changesetStore',