diff --git a/scm-core/src/main/java/sonia/scm/repository/ChangesetViewer.java b/scm-core/src/main/java/sonia/scm/repository/ChangesetViewer.java index 63b734f897..c862cc52b6 100644 --- a/scm-core/src/main/java/sonia/scm/repository/ChangesetViewer.java +++ b/scm-core/src/main/java/sonia/scm/repository/ChangesetViewer.java @@ -60,7 +60,7 @@ public interface ChangesetViewer */ public ChangesetPagingResult getChangesets(int start, int max) throws IOException, RepositoryException; - + /** * Method description * @@ -68,6 +68,7 @@ public interface ChangesetViewer * * * @param path + * @param revision * @param start * @param max * @@ -76,6 +77,7 @@ public interface ChangesetViewer * @throws IOException * @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; } diff --git a/scm-core/src/main/java/sonia/scm/repository/ChangesetViewerUtil.java b/scm-core/src/main/java/sonia/scm/repository/ChangesetViewerUtil.java index 01562dbe5a..04aca7f5f4 100644 --- a/scm-core/src/main/java/sonia/scm/repository/ChangesetViewerUtil.java +++ b/scm-core/src/main/java/sonia/scm/repository/ChangesetViewerUtil.java @@ -132,6 +132,7 @@ public class ChangesetViewerUtil extends PartCacheClearHook * * @param repositoryId * @param path + * @param revision * @param start * @param max * @@ -143,7 +144,7 @@ public class ChangesetViewerUtil extends PartCacheClearHook * @throws RepositoryException */ public ChangesetPagingResult getChangesets(String repositoryId, String path, - int start, int max) + String revision, int start, int max) throws IOException, RepositoryException, NotSupportedFeatuerException { AssertUtil.assertIsNotEmpty(repositoryId); @@ -156,7 +157,7 @@ public class ChangesetViewerUtil extends PartCacheClearHook "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 = - new ChangesetViewerCacheKey(repository.getId(), Util.EMPTY_STRING, start, - max); + new ChangesetViewerCacheKey(repository.getId(), start, max); ChangesetPagingResult result = cache.get(key); if (result == null) @@ -227,6 +227,7 @@ public class ChangesetViewerUtil extends PartCacheClearHook * * @param repository * @param path + * @param revision * @param start * @param max * @@ -238,7 +239,7 @@ public class ChangesetViewerUtil extends PartCacheClearHook * @throws RepositoryException */ public ChangesetPagingResult getChangesets(Repository repository, - String path, int start, int max) + String path, String revision, int start, int max) throws IOException, RepositoryException, NotSupportedFeatuerException { AssertUtil.assertIsNotNull(repository); @@ -253,12 +254,13 @@ public class ChangesetViewerUtil extends PartCacheClearHook } ChangesetViewerCacheKey key = - new ChangesetViewerCacheKey(repository.getId(), path, start, max); + new ChangesetViewerCacheKey(repository.getId(), path, revision, start, + max); ChangesetPagingResult result = cache.get(key); if (result == null) { - result = viewer.getChangesets(path, start, max); + result = viewer.getChangesets(path, revision, start, max); if (result != null) { @@ -351,15 +353,30 @@ public class ChangesetViewerUtil extends PartCacheClearHook * * * @param repository - * @param path * @param start * @param max */ - public ChangesetViewerCacheKey(String repository, String path, int start, - int max) + public ChangesetViewerCacheKey(String repository, int start, 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.path = path; + this.revision = revision; this.start = start; this.max = max; } @@ -389,6 +406,13 @@ public class ChangesetViewerUtil extends PartCacheClearHook final ChangesetViewerCacheKey other = (ChangesetViewerCacheKey) obj; + if ((this.revision == null) + ? (other.revision != null) + : !this.revision.equals(other.revision)) + { + return false; + } + if (this.max != other.max) { return false; @@ -425,16 +449,19 @@ public class ChangesetViewerUtil extends PartCacheClearHook @Override public int hashCode() { - int hash = 7; + int hash = 5; - hash = 89 * hash + this.max; - hash = 89 * hash + ((this.path != null) + hash = 47 * hash + ((this.revision != null) + ? this.revision.hashCode() + : 0); + hash = 47 * hash + this.max; + hash = 47 * hash + ((this.path != null) ? this.path.hashCode() : 0); - hash = 89 * hash + ((this.repository != null) + hash = 47 * hash + ((this.repository != null) ? this.repository.hashCode() : 0); - hash = 89 * hash + this.start; + hash = 47 * hash + this.start; return hash; } @@ -464,6 +491,9 @@ public class ChangesetViewerUtil extends PartCacheClearHook /** Field description */ private String repository; + /** Field description */ + private String revision; + /** Field description */ private int start; } diff --git a/scm-plugins/scm-git-plugin/src/main/java/sonia/scm/repository/GitChangesetViewer.java b/scm-plugins/scm-git-plugin/src/main/java/sonia/scm/repository/GitChangesetViewer.java index 2ed030615d..e308d83b33 100644 --- a/scm-plugins/scm-git-plugin/src/main/java/sonia/scm/repository/GitChangesetViewer.java +++ b/scm-plugins/scm-git-plugin/src/main/java/sonia/scm/repository/GitChangesetViewer.java @@ -155,13 +155,15 @@ public class GitChangesetViewer implements ChangesetViewer * * * @param path + * @param revision * @param start * @param max * * @return */ @Override - public ChangesetPagingResult getChangesets(String path, int start, int max) + public ChangesetPagingResult getChangesets(String path, String revision, + int start, int max) { ChangesetPagingResult changesets = null; File directory = handler.getDirectory(repository); @@ -180,11 +182,12 @@ public class GitChangesetViewer implements ChangesetViewer converter = new GitChangesetConverter(gr, GitUtil.ID_LENGTH); 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)) { @@ -219,7 +222,7 @@ public class GitChangesetViewer implements ChangesetViewer return changesets; } - + //~--- fields --------------------------------------------------------------- /** Field description */ diff --git a/scm-plugins/scm-hg-plugin/src/main/java/sonia/scm/repository/AbstractHgHandler.java b/scm-plugins/scm-hg-plugin/src/main/java/sonia/scm/repository/AbstractHgHandler.java index 200a9042a6..b6a0d8c611 100644 --- a/scm-plugins/scm-hg-plugin/src/main/java/sonia/scm/repository/AbstractHgHandler.java +++ b/scm-plugins/scm-hg-plugin/src/main/java/sonia/scm/repository/AbstractHgHandler.java @@ -399,6 +399,7 @@ public class AbstractHgHandler } msg.append("]"); + logger.debug(msg.toString()); } ProcessBuilder pb = new ProcessBuilder(cmdList); diff --git a/scm-plugins/scm-hg-plugin/src/main/java/sonia/scm/repository/HgChangesetViewer.java b/scm-plugins/scm-hg-plugin/src/main/java/sonia/scm/repository/HgChangesetViewer.java index 04ca3bd6f1..82a27ac620 100644 --- a/scm-plugins/scm-hg-plugin/src/main/java/sonia/scm/repository/HgChangesetViewer.java +++ b/scm-plugins/scm-hg-plugin/src/main/java/sonia/scm/repository/HgChangesetViewer.java @@ -35,7 +35,11 @@ package sonia.scm.repository; //~--- non-JDK imports -------------------------------------------------------- +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + import sonia.scm.util.Util; +import sonia.scm.web.HgUtil; //~--- JDK imports ------------------------------------------------------------ @@ -58,6 +62,10 @@ public class HgChangesetViewer extends AbstractHgHandler /** Field description */ public static final String RESOURCE_LOG = "/sonia/scm/hglog.py"; + /** the logger for HgChangesetViewer */ + private static final Logger logger = + LoggerFactory.getLogger(HgChangesetViewer.class); + //~--- constructors --------------------------------------------------------- /** @@ -110,6 +118,11 @@ public class HgChangesetViewer extends AbstractHgHandler public ChangesetPagingResult getChangesets(int start, int max) throws IOException, RepositoryException { + if (logger.isDebugEnabled()) + { + logger.debug("fetch changesets. start: {}, max: {}", start, max); + } + return getChangesets(null, null, String.valueOf(start), String.valueOf(max), null, null); } @@ -119,6 +132,7 @@ public class HgChangesetViewer extends AbstractHgHandler * * * @param path + * @param revision * @param start * @param max * @@ -128,10 +142,21 @@ public class HgChangesetViewer extends AbstractHgHandler * @throws RepositoryException */ @Override - public ChangesetPagingResult getChangesets(String path, int start, int max) + public ChangesetPagingResult getChangesets(String path, String revision, + int start, int max) 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); } @@ -184,6 +209,12 @@ public class HgChangesetViewer extends AbstractHgHandler public ChangesetPagingResult getChangesets(String startNode, String endNode) throws IOException, RepositoryException { + if (logger.isDebugEnabled()) + { + logger.debug("fetch changesets. start-node: {}, end-node: {}", startNode, + endNode); + } + return getChangesets(null, null, null, null, startNode, endNode); } } diff --git a/scm-plugins/scm-svn-plugin/src/main/java/sonia/scm/repository/SvnChangesetViewer.java b/scm-plugins/scm-svn-plugin/src/main/java/sonia/scm/repository/SvnChangesetViewer.java index 4e378a4ecb..8e604ee9ca 100644 --- a/scm-plugins/scm-svn-plugin/src/main/java/sonia/scm/repository/SvnChangesetViewer.java +++ b/scm-plugins/scm-svn-plugin/src/main/java/sonia/scm/repository/SvnChangesetViewer.java @@ -93,7 +93,7 @@ public class SvnChangesetViewer implements ChangesetViewer @Override 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 revision * @param start * @param max * * @return */ @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; File directory = handler.getDirectory(repostory); SVNRepository repository = null; @@ -128,7 +133,7 @@ public class SvnChangesetViewer implements ChangesetViewer List changesetList = new ArrayList(); Collection entries = repository.log(new String[] { path }, null, startRev, endRev, true, true); - + for (SVNLogEntry entry : entries) { changesetList.add(SvnUtil.createChangeset(entry)); @@ -148,11 +153,12 @@ public class SvnChangesetViewer implements ChangesetViewer return changesets; } + //~--- fields --------------------------------------------------------------- /** Field description */ private SvnRepositoryHandler handler; - /** Field description */ - private Repository repostory; + /** Field description */ + private Repository repostory; } diff --git a/scm-webapp/src/main/java/sonia/scm/api/rest/resources/RepositoryResource.java b/scm-webapp/src/main/java/sonia/scm/api/rest/resources/RepositoryResource.java index 315be56d51..15ea897589 100644 --- a/scm-webapp/src/main/java/sonia/scm/api/rest/resources/RepositoryResource.java +++ b/scm-webapp/src/main/java/sonia/scm/api/rest/resources/RepositoryResource.java @@ -424,6 +424,7 @@ public class RepositoryResource * * @param id the id of the repository * @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 limit the limit value for paging * @@ -438,6 +439,7 @@ public class RepositoryResource @Produces({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON }) public Response getChangesets(@PathParam("id") String id, @QueryParam("path") String path, + @QueryParam("revision") String revision, @DefaultValue("0") @QueryParam("start") int start, @DefaultValue("20") @QueryParam("limit") int limit) throws RepositoryException, IOException @@ -454,7 +456,8 @@ public class RepositoryResource } else { - changesets = changesetViewerUtil.getChangesets(id, path, start, limit); + changesets = changesetViewerUtil.getChangesets(id, path, revision, + start, limit); } if (changesets != null) diff --git a/scm-webapp/src/main/webapp/resources/js/repository/sonia.repository.changesetviewerpanel.js b/scm-webapp/src/main/webapp/resources/js/repository/sonia.repository.changesetviewerpanel.js index 2d2fe76600..3c9ca6a16e 100644 --- a/scm-webapp/src/main/webapp/resources/js/repository/sonia.repository.changesetviewerpanel.js +++ b/scm-webapp/src/main/webapp/resources/js/repository/sonia.repository.changesetviewerpanel.js @@ -36,8 +36,11 @@ Sonia.repository.ChangesetViewerPanel = Ext.extend(Ext.Panel, { pageSize: 20, historyId: null, changesetStore: null, - path: null, + + // parameters for file history view inline: false, + path: null, + revision: null, changesetViewerTitleText: 'Commits {0}', @@ -61,6 +64,10 @@ Sonia.repository.ChangesetViewerPanel = Ext.extend(Ext.Panel, { if (this.path){ params.path = this.path; } + + if (this.revision){ + params.revision = this.revision; + } this.changesetStore = new Sonia.rest.JsonStore({ id: 'changesetStore',