mirror of
https://github.com/scm-manager/scm-manager.git
synced 2025-12-24 01:09:48 +01:00
Add changesets command to enable commit search (#2106)
Introduce changesets command to find all changesets for a single repository. This is required to index all changesets for the commit search.
This commit is contained in:
2
gradle/changelog/commit_search.yaml
Normal file
2
gradle/changelog/commit_search.yaml
Normal file
@@ -0,0 +1,2 @@
|
|||||||
|
- type: added
|
||||||
|
description: Changesets command to find all repository changesets ([#2106](https://github.com/scm-manager/scm-manager/pull/2106))
|
||||||
@@ -0,0 +1,91 @@
|
|||||||
|
/*
|
||||||
|
* MIT License
|
||||||
|
*
|
||||||
|
* Copyright (c) 2020-present Cloudogu GmbH and Contributors
|
||||||
|
*
|
||||||
|
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
|
* of this software and associated documentation files (the "Software"), to deal
|
||||||
|
* in the Software without restriction, including without limitation the rights
|
||||||
|
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||||
|
* copies of the Software, and to permit persons to whom the Software is
|
||||||
|
* furnished to do so, subject to the following conditions:
|
||||||
|
*
|
||||||
|
* The above copyright notice and this permission notice shall be included in all
|
||||||
|
* copies or substantial portions of the Software.
|
||||||
|
*
|
||||||
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||||
|
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||||
|
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||||
|
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||||
|
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||||
|
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||||
|
* SOFTWARE.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package sonia.scm.repository.api;
|
||||||
|
|
||||||
|
import com.google.common.collect.Iterables;
|
||||||
|
import org.slf4j.Logger;
|
||||||
|
import org.slf4j.LoggerFactory;
|
||||||
|
import sonia.scm.cache.Cache;
|
||||||
|
import sonia.scm.cache.CacheManager;
|
||||||
|
import sonia.scm.repository.Changeset;
|
||||||
|
import sonia.scm.repository.Repository;
|
||||||
|
import sonia.scm.repository.RepositoryCacheKey;
|
||||||
|
import sonia.scm.repository.spi.ChangesetsCommand;
|
||||||
|
import sonia.scm.repository.spi.ChangesetsCommandRequest;
|
||||||
|
|
||||||
|
import java.io.Serializable;
|
||||||
|
import java.util.Optional;
|
||||||
|
|
||||||
|
public class ChangesetsCommandBuilder {
|
||||||
|
|
||||||
|
static final String CACHE_NAME = "sonia.cache.cmd.changesets";
|
||||||
|
private final Cache<CacheKey, Iterable<Changeset>> cache;
|
||||||
|
private static final Logger LOG = LoggerFactory.getLogger(ChangesetsCommandBuilder.class);
|
||||||
|
|
||||||
|
private final Repository repository;
|
||||||
|
private final ChangesetsCommand changesetsCommand;
|
||||||
|
|
||||||
|
private final ChangesetsCommandRequest request = new ChangesetsCommandRequest();
|
||||||
|
|
||||||
|
public ChangesetsCommandBuilder(CacheManager cacheManager, Repository repository, ChangesetsCommand changesetsCommand) {
|
||||||
|
this.repository = repository;
|
||||||
|
this.changesetsCommand = changesetsCommand;
|
||||||
|
this.cache = cacheManager.getCache(CACHE_NAME);
|
||||||
|
}
|
||||||
|
|
||||||
|
public Iterable<Changeset> getChangesets() {
|
||||||
|
CacheKey cacheKey = new CacheKey(repository);
|
||||||
|
Iterable<Changeset> changesets = cache.get(cacheKey);
|
||||||
|
|
||||||
|
if (changesets == null || Iterables.isEmpty(changesets)) {
|
||||||
|
LOG.debug("Retrieve all changesets from {{}}", repository);
|
||||||
|
changesets = changesetsCommand.getChangesets(request);
|
||||||
|
cache.put(cacheKey, changesets);
|
||||||
|
} else {
|
||||||
|
LOG.debug("Use cached changesets from {{}}", repository);
|
||||||
|
}
|
||||||
|
|
||||||
|
return changesets;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Optional<Changeset> getLatestChangeset() {
|
||||||
|
LOG.debug("Retrieve latest changeset from {{}}", repository);
|
||||||
|
return changesetsCommand.getLatestChangeset();
|
||||||
|
}
|
||||||
|
|
||||||
|
static class CacheKey implements RepositoryCacheKey, Serializable {
|
||||||
|
private final Repository repository;
|
||||||
|
|
||||||
|
CacheKey(Repository repository) {
|
||||||
|
this.repository = repository;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String getRepositoryId() {
|
||||||
|
return repository.getId();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@@ -87,5 +87,9 @@ public enum Command
|
|||||||
/**
|
/**
|
||||||
* @since 2.28.0
|
* @since 2.28.0
|
||||||
*/
|
*/
|
||||||
BRANCH_DETAILS
|
BRANCH_DETAILS,
|
||||||
|
/**
|
||||||
|
* @since 2.39.0
|
||||||
|
*/
|
||||||
|
CHANGESETS
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -21,7 +21,7 @@
|
|||||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||||
* SOFTWARE.
|
* SOFTWARE.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
package sonia.scm.repository.api;
|
package sonia.scm.repository.api;
|
||||||
|
|
||||||
//~--- non-JDK imports --------------------------------------------------------
|
//~--- non-JDK imports --------------------------------------------------------
|
||||||
@@ -46,6 +46,8 @@ import sonia.scm.repository.spi.HookChangesetResponse;
|
|||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
import java.util.stream.Collectors;
|
||||||
|
import java.util.stream.StreamSupport;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The {@link HookChangesetBuilder} is able to return all {@link Changeset}s
|
* The {@link HookChangesetBuilder} is able to return all {@link Changeset}s
|
||||||
@@ -147,6 +149,33 @@ public final class HookChangesetBuilder
|
|||||||
return changesets;
|
return changesets;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public Iterable<Changeset> getRemovedChangesets() {
|
||||||
|
HookChangesetResponse hookChangesetResponse = provider.handleRequest(request);
|
||||||
|
Iterable<Changeset> changesets = hookChangesetResponse.getRemovedChangesets();
|
||||||
|
|
||||||
|
if (!disablePreProcessors)
|
||||||
|
{
|
||||||
|
changesets = StreamSupport.stream(changesets.spliterator(), false).map(c -> {
|
||||||
|
Changeset copy = null;
|
||||||
|
|
||||||
|
try {
|
||||||
|
copy = DeepCopy.copy(c);
|
||||||
|
preProcessorUtil.prepareForReturn(repository, copy);
|
||||||
|
} catch (IOException ex) {
|
||||||
|
logger.error("could not create a copy of changeset", ex);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (copy == null) {
|
||||||
|
return c;
|
||||||
|
}
|
||||||
|
|
||||||
|
return copy;
|
||||||
|
}).collect(Collectors.toList());
|
||||||
|
}
|
||||||
|
|
||||||
|
return changesets;
|
||||||
|
}
|
||||||
|
|
||||||
//~--- set methods ----------------------------------------------------------
|
//~--- set methods ----------------------------------------------------------
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@@ -102,11 +102,11 @@ public final class RepositoryService implements Closeable {
|
|||||||
* Constructs a new {@link RepositoryService}. This constructor should only
|
* Constructs a new {@link RepositoryService}. This constructor should only
|
||||||
* be called from the {@link RepositoryServiceFactory}.
|
* be called from the {@link RepositoryServiceFactory}.
|
||||||
*
|
*
|
||||||
* @param cacheManager cache manager
|
* @param cacheManager cache manager
|
||||||
* @param provider implementation for {@link RepositoryServiceProvider}
|
* @param provider implementation for {@link RepositoryServiceProvider}
|
||||||
* @param repository the repository
|
* @param repository the repository
|
||||||
* @param workdirProvider provider for workdirs
|
* @param workdirProvider provider for workdirs
|
||||||
* @param eMail utility to compute email addresses if missing
|
* @param eMail utility to compute email addresses if missing
|
||||||
* @param repositoryExportingCheck
|
* @param repositoryExportingCheck
|
||||||
*/
|
*/
|
||||||
RepositoryService(CacheManager cacheManager,
|
RepositoryService(CacheManager cacheManager,
|
||||||
@@ -504,6 +504,11 @@ public final class RepositoryService implements Closeable {
|
|||||||
return new BranchDetailsCommandBuilder(repository, provider.getBranchDetailsCommand(), cacheManager);
|
return new BranchDetailsCommandBuilder(repository, provider.getBranchDetailsCommand(), cacheManager);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public ChangesetsCommandBuilder getChangesetsCommand() {
|
||||||
|
LOG.debug("create changesets command for repository {}", repository);
|
||||||
|
return new ChangesetsCommandBuilder(cacheManager, repository, provider.getChangesetsCommand());
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns true if the command is supported by the repository service.
|
* Returns true if the command is supported by the repository service.
|
||||||
*
|
*
|
||||||
|
|||||||
@@ -0,0 +1,49 @@
|
|||||||
|
/*
|
||||||
|
* MIT License
|
||||||
|
*
|
||||||
|
* Copyright (c) 2020-present Cloudogu GmbH and Contributors
|
||||||
|
*
|
||||||
|
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
|
* of this software and associated documentation files (the "Software"), to deal
|
||||||
|
* in the Software without restriction, including without limitation the rights
|
||||||
|
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||||
|
* copies of the Software, and to permit persons to whom the Software is
|
||||||
|
* furnished to do so, subject to the following conditions:
|
||||||
|
*
|
||||||
|
* The above copyright notice and this permission notice shall be included in all
|
||||||
|
* copies or substantial portions of the Software.
|
||||||
|
*
|
||||||
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||||
|
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||||
|
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||||
|
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||||
|
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||||
|
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||||
|
* SOFTWARE.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package sonia.scm.repository.spi;
|
||||||
|
|
||||||
|
import sonia.scm.repository.Changeset;
|
||||||
|
|
||||||
|
import java.util.Optional;
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* @since 2.39.0
|
||||||
|
*/
|
||||||
|
public interface ChangesetsCommand {
|
||||||
|
/**
|
||||||
|
* Retrieve all changesets (over all branches/tags) from the repository
|
||||||
|
* @param request
|
||||||
|
* @return iterable of all changesets
|
||||||
|
*/
|
||||||
|
Iterable<Changeset> getChangesets(ChangesetsCommandRequest request);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Retrieve the latest changeset (over all branches/tags) from the repository
|
||||||
|
* @return optional of latest changeset or empty
|
||||||
|
*/
|
||||||
|
Optional<Changeset> getLatestChangeset();
|
||||||
|
|
||||||
|
}
|
||||||
@@ -0,0 +1,29 @@
|
|||||||
|
/*
|
||||||
|
* MIT License
|
||||||
|
*
|
||||||
|
* Copyright (c) 2020-present Cloudogu GmbH and Contributors
|
||||||
|
*
|
||||||
|
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
|
* of this software and associated documentation files (the "Software"), to deal
|
||||||
|
* in the Software without restriction, including without limitation the rights
|
||||||
|
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||||
|
* copies of the Software, and to permit persons to whom the Software is
|
||||||
|
* furnished to do so, subject to the following conditions:
|
||||||
|
*
|
||||||
|
* The above copyright notice and this permission notice shall be included in all
|
||||||
|
* copies or substantial portions of the Software.
|
||||||
|
*
|
||||||
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||||
|
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||||
|
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||||
|
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||||
|
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||||
|
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||||
|
* SOFTWARE.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package sonia.scm.repository.spi;
|
||||||
|
|
||||||
|
public class ChangesetsCommandRequest {
|
||||||
|
|
||||||
|
}
|
||||||
@@ -21,24 +21,14 @@
|
|||||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||||
* SOFTWARE.
|
* SOFTWARE.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
package sonia.scm.repository.spi;
|
package sonia.scm.repository.spi;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
|
||||||
* @author Sebastian Sdorra
|
* @author Sebastian Sdorra
|
||||||
* @since 1.33
|
* @since 1.33
|
||||||
*/
|
*/
|
||||||
public interface HookChangesetProvider
|
public interface HookChangesetProvider {
|
||||||
{
|
|
||||||
|
|
||||||
/**
|
HookChangesetResponse handleRequest(HookChangesetRequest request);
|
||||||
* Method description
|
|
||||||
*
|
|
||||||
*
|
|
||||||
* @param request
|
|
||||||
*
|
|
||||||
* @return
|
|
||||||
*/
|
|
||||||
public HookChangesetResponse handleRequest(HookChangesetRequest request);
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -21,48 +21,50 @@
|
|||||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||||
* SOFTWARE.
|
* SOFTWARE.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
package sonia.scm.repository.spi;
|
|
||||||
|
|
||||||
//~--- non-JDK imports --------------------------------------------------------
|
package sonia.scm.repository.spi;
|
||||||
|
|
||||||
import sonia.scm.repository.Changeset;
|
import sonia.scm.repository.Changeset;
|
||||||
|
|
||||||
|
import static java.util.Collections.emptyList;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Response object to retrieve {@link Changeset}s during a hook.
|
* Response object to retrieve {@link Changeset}s during a hook.
|
||||||
*
|
*
|
||||||
* @author Sebastian Sdorra
|
* @author Sebastian Sdorra
|
||||||
* @since 1.33
|
* @since 1.33
|
||||||
*/
|
*/
|
||||||
public final class HookChangesetResponse
|
public final class HookChangesetResponse {
|
||||||
{
|
private final Iterable<Changeset> addedChangesets;
|
||||||
|
private final Iterable<Changeset> removedChangesets;
|
||||||
|
|
||||||
/**
|
public HookChangesetResponse(Iterable<Changeset> addedChangesets, Iterable<Changeset> removedChangesets) {
|
||||||
* Constructs a new {@link HookChangesetResponse}.
|
this.addedChangesets = addedChangesets;
|
||||||
*
|
this.removedChangesets = removedChangesets;
|
||||||
*
|
}
|
||||||
* @param changesets added changesets
|
|
||||||
*/
|
public HookChangesetResponse(Iterable<Changeset> changesets) {
|
||||||
public HookChangesetResponse(Iterable<Changeset> changesets)
|
this(changesets, emptyList());
|
||||||
{
|
|
||||||
this.changesets = changesets;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
//~--- get methods ----------------------------------------------------------
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Return added changesets.
|
* Return added changesets.
|
||||||
*
|
*
|
||||||
*
|
|
||||||
* @return added changesets
|
* @return added changesets
|
||||||
*/
|
*/
|
||||||
public Iterable<Changeset> getChangesets()
|
public Iterable<Changeset> getChangesets() {
|
||||||
{
|
return addedChangesets;
|
||||||
return changesets;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
//~--- fields ---------------------------------------------------------------
|
/**
|
||||||
|
* Return removed changesets.
|
||||||
|
*
|
||||||
|
* @return removed changesets
|
||||||
|
* @since 2.39.0
|
||||||
|
*/
|
||||||
|
public Iterable<Changeset> getRemovedChangesets() {
|
||||||
|
return removedChangesets;
|
||||||
|
}
|
||||||
|
|
||||||
/** added changesets */
|
|
||||||
private Iterable<Changeset> changesets;
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -318,4 +318,8 @@ public abstract class RepositoryServiceProvider implements Closeable
|
|||||||
public BranchDetailsCommand getBranchDetailsCommand() {
|
public BranchDetailsCommand getBranchDetailsCommand() {
|
||||||
throw new CommandNotSupportedException(Command.BRANCH_DETAILS);
|
throw new CommandNotSupportedException(Command.BRANCH_DETAILS);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public ChangesetsCommand getChangesetsCommand() {
|
||||||
|
throw new CommandNotSupportedException(Command.CHANGESETS);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,59 @@
|
|||||||
|
/*
|
||||||
|
* MIT License
|
||||||
|
*
|
||||||
|
* Copyright (c) 2020-present Cloudogu GmbH and Contributors
|
||||||
|
*
|
||||||
|
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
|
* of this software and associated documentation files (the "Software"), to deal
|
||||||
|
* in the Software without restriction, including without limitation the rights
|
||||||
|
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||||
|
* copies of the Software, and to permit persons to whom the Software is
|
||||||
|
* furnished to do so, subject to the following conditions:
|
||||||
|
*
|
||||||
|
* The above copyright notice and this permission notice shall be included in all
|
||||||
|
* copies or substantial portions of the Software.
|
||||||
|
*
|
||||||
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||||
|
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||||
|
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||||
|
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||||
|
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||||
|
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||||
|
* SOFTWARE.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package sonia.scm.repository.spi;
|
||||||
|
|
||||||
|
import sonia.scm.repository.Changeset;
|
||||||
|
import sonia.scm.repository.spi.javahg.HgLogChangesetCommand;
|
||||||
|
|
||||||
|
import java.util.Optional;
|
||||||
|
|
||||||
|
import static sonia.scm.repository.spi.javahg.HgLogChangesetCommand.on;
|
||||||
|
|
||||||
|
public class HgChangesetsCommand extends AbstractCommand implements ChangesetsCommand {
|
||||||
|
|
||||||
|
public HgChangesetsCommand(HgCommandContext context) {
|
||||||
|
super(context);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Iterable<Changeset> getChangesets(ChangesetsCommandRequest request) {
|
||||||
|
org.javahg.Repository repository = open();
|
||||||
|
HgLogChangesetCommand cmd = on(repository, context.getConfig());
|
||||||
|
// Get all changesets between the first changeset and the repository tip, both inclusive.
|
||||||
|
cmd.rev("tip:0");
|
||||||
|
return cmd.execute();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Optional<Changeset> getLatestChangeset() {
|
||||||
|
org.javahg.Repository repository = open();
|
||||||
|
HgLogChangesetCommand cmd = on(repository, context.getConfig());
|
||||||
|
Changeset tip = cmd.rev("tip").single();
|
||||||
|
if (tip != null) {
|
||||||
|
return Optional.of(tip);
|
||||||
|
}
|
||||||
|
return Optional.empty();
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -57,7 +57,8 @@ public class HgRepositoryServiceProvider extends RepositoryServiceProvider {
|
|||||||
Command.BUNDLE,
|
Command.BUNDLE,
|
||||||
Command.UNBUNDLE,
|
Command.UNBUNDLE,
|
||||||
Command.FULL_HEALTH_CHECK,
|
Command.FULL_HEALTH_CHECK,
|
||||||
Command.BRANCH_DETAILS
|
Command.BRANCH_DETAILS,
|
||||||
|
Command.CHANGESETS
|
||||||
);
|
);
|
||||||
|
|
||||||
public static final Set<Feature> FEATURES = EnumSet.of(
|
public static final Set<Feature> FEATURES = EnumSet.of(
|
||||||
@@ -194,4 +195,9 @@ public class HgRepositoryServiceProvider extends RepositoryServiceProvider {
|
|||||||
public BranchDetailsCommand getBranchDetailsCommand() {
|
public BranchDetailsCommand getBranchDetailsCommand() {
|
||||||
return new HgBranchDetailsCommand(context);
|
return new HgBranchDetailsCommand(context);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public ChangesetsCommand getChangesetsCommand() {
|
||||||
|
return new HgChangesetsCommand(context);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,61 @@
|
|||||||
|
/*
|
||||||
|
* MIT License
|
||||||
|
*
|
||||||
|
* Copyright (c) 2020-present Cloudogu GmbH and Contributors
|
||||||
|
*
|
||||||
|
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
|
* of this software and associated documentation files (the "Software"), to deal
|
||||||
|
* in the Software without restriction, including without limitation the rights
|
||||||
|
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||||
|
* copies of the Software, and to permit persons to whom the Software is
|
||||||
|
* furnished to do so, subject to the following conditions:
|
||||||
|
*
|
||||||
|
* The above copyright notice and this permission notice shall be included in all
|
||||||
|
* copies or substantial portions of the Software.
|
||||||
|
*
|
||||||
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||||
|
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||||
|
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||||
|
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||||
|
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||||
|
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||||
|
* SOFTWARE.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package sonia.scm.repository.spi;
|
||||||
|
|
||||||
|
import org.junit.Test;
|
||||||
|
import sonia.scm.repository.Changeset;
|
||||||
|
|
||||||
|
import java.util.Optional;
|
||||||
|
|
||||||
|
import static org.assertj.core.api.Assertions.assertThat;
|
||||||
|
|
||||||
|
public class HgChangesetsCommandTest extends AbstractHgCommandTestBase {
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void getAllChangesetsFromRepository() {
|
||||||
|
Iterable<Changeset> changesets = createCommand()
|
||||||
|
.getChangesets(new ChangesetsCommandRequest());
|
||||||
|
|
||||||
|
assertThat(changesets).hasSize(13);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void getLatestChangesetFromRepository() {
|
||||||
|
Optional<Changeset> changeset = createCommand()
|
||||||
|
.getLatestChangeset();
|
||||||
|
|
||||||
|
assertThat(changeset).isPresent();
|
||||||
|
assertThat(changeset.get().getId()).isEqualTo("67a658097e5aba664eaabb7a79a60f8d63c59b97");
|
||||||
|
}
|
||||||
|
|
||||||
|
private HgChangesetsCommand createCommand() {
|
||||||
|
return new HgChangesetsCommand(cmdContext);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected String getZippedRepositoryResource() {
|
||||||
|
return "sonia/scm/repository/spi/scm-hg-ahead-behind-test.zip";
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,49 @@
|
|||||||
|
/*
|
||||||
|
* MIT License
|
||||||
|
*
|
||||||
|
* Copyright (c) 2020-present Cloudogu GmbH and Contributors
|
||||||
|
*
|
||||||
|
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
|
* of this software and associated documentation files (the "Software"), to deal
|
||||||
|
* in the Software without restriction, including without limitation the rights
|
||||||
|
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||||
|
* copies of the Software, and to permit persons to whom the Software is
|
||||||
|
* furnished to do so, subject to the following conditions:
|
||||||
|
*
|
||||||
|
* The above copyright notice and this permission notice shall be included in all
|
||||||
|
* copies or substantial portions of the Software.
|
||||||
|
*
|
||||||
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||||
|
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||||
|
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||||
|
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||||
|
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||||
|
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||||
|
* SOFTWARE.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package sonia.scm.repository.spi;
|
||||||
|
|
||||||
|
import org.tmatesoft.svn.core.ISVNLogEntryHandler;
|
||||||
|
import org.tmatesoft.svn.core.SVNLogEntry;
|
||||||
|
import sonia.scm.repository.Changeset;
|
||||||
|
import sonia.scm.repository.SvnUtil;
|
||||||
|
|
||||||
|
import java.util.Collection;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Collect and convert changesets.
|
||||||
|
*/
|
||||||
|
class ChangesetCollector implements ISVNLogEntryHandler {
|
||||||
|
|
||||||
|
private final Collection<Changeset> changesets;
|
||||||
|
|
||||||
|
public ChangesetCollector(Collection<Changeset> changesets) {
|
||||||
|
this.changesets = changesets;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void handleLogEntry(SVNLogEntry logEntry) {
|
||||||
|
changesets.add(SvnUtil.createChangeset(logEntry));
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,75 @@
|
|||||||
|
/*
|
||||||
|
* MIT License
|
||||||
|
*
|
||||||
|
* Copyright (c) 2020-present Cloudogu GmbH and Contributors
|
||||||
|
*
|
||||||
|
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
|
* of this software and associated documentation files (the "Software"), to deal
|
||||||
|
* in the Software without restriction, including without limitation the rights
|
||||||
|
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||||
|
* copies of the Software, and to permit persons to whom the Software is
|
||||||
|
* furnished to do so, subject to the following conditions:
|
||||||
|
*
|
||||||
|
* The above copyright notice and this permission notice shall be included in all
|
||||||
|
* copies or substantial portions of the Software.
|
||||||
|
*
|
||||||
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||||
|
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||||
|
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||||
|
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||||
|
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||||
|
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||||
|
* SOFTWARE.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package sonia.scm.repository.spi;
|
||||||
|
|
||||||
|
import com.google.common.collect.Lists;
|
||||||
|
import org.tmatesoft.svn.core.SVNException;
|
||||||
|
import org.tmatesoft.svn.core.io.SVNRepository;
|
||||||
|
import sonia.scm.repository.Changeset;
|
||||||
|
import sonia.scm.repository.InternalRepositoryException;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.Optional;
|
||||||
|
|
||||||
|
public class SvnChangesetsCommand extends AbstractSvnCommand implements ChangesetsCommand {
|
||||||
|
|
||||||
|
SvnChangesetsCommand(SvnContext context) {
|
||||||
|
super(context);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Iterable<Changeset> getChangesets(ChangesetsCommandRequest request) {
|
||||||
|
try {
|
||||||
|
SVNRepository repo = open();
|
||||||
|
long startRev = repo.getLatestRevision();
|
||||||
|
// We ignore the changeset 0, because it doesn't have any values like author or description
|
||||||
|
long endRev = 1;
|
||||||
|
final List<Changeset> changesets = Lists.newArrayList();
|
||||||
|
|
||||||
|
repo.log(null, startRev, endRev, true, true, new ChangesetCollector(changesets));
|
||||||
|
return changesets;
|
||||||
|
} catch (SVNException ex) {
|
||||||
|
throw new InternalRepositoryException(repository, "could not open repository", ex);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Optional<Changeset> getLatestChangeset() {
|
||||||
|
try {
|
||||||
|
SVNRepository repo = open();
|
||||||
|
long latestRevision = repo.getLatestRevision();
|
||||||
|
final List<Changeset> changesets = Lists.newArrayList();
|
||||||
|
|
||||||
|
repo.log(null, latestRevision, latestRevision, true, true, new ChangesetCollector(changesets));
|
||||||
|
|
||||||
|
if (!changesets.isEmpty()) {
|
||||||
|
return Optional.of(changesets.get(0));
|
||||||
|
}
|
||||||
|
return Optional.empty();
|
||||||
|
} catch (SVNException ex) {
|
||||||
|
throw new InternalRepositoryException(repository, "could not open repository", ex);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -179,21 +179,4 @@ public class SvnLogCommand extends AbstractSvnCommand implements LogCommand {
|
|||||||
return new ChangesetPagingResult(total,
|
return new ChangesetPagingResult(total,
|
||||||
SvnUtil.createChangesets(changesetList));
|
SvnUtil.createChangesets(changesetList));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Collect and convert changesets.
|
|
||||||
*/
|
|
||||||
private static class ChangesetCollector implements ISVNLogEntryHandler {
|
|
||||||
|
|
||||||
private final Collection<Changeset> changesets;
|
|
||||||
|
|
||||||
public ChangesetCollector(Collection<Changeset> changesets) {
|
|
||||||
this.changesets = changesets;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void handleLogEntry(SVNLogEntry logEntry) {
|
|
||||||
changesets.add(SvnUtil.createChangeset(logEntry));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -56,7 +56,8 @@ public class SvnRepositoryServiceProvider extends RepositoryServiceProvider {
|
|||||||
Command.LOOKUP,
|
Command.LOOKUP,
|
||||||
Command.FULL_HEALTH_CHECK,
|
Command.FULL_HEALTH_CHECK,
|
||||||
Command.MIRROR,
|
Command.MIRROR,
|
||||||
Command.FILE_LOCK
|
Command.FILE_LOCK,
|
||||||
|
Command.CHANGESETS
|
||||||
);
|
);
|
||||||
|
|
||||||
public static final Set<Feature> FEATURES = EnumSet.of(
|
public static final Set<Feature> FEATURES = EnumSet.of(
|
||||||
@@ -161,4 +162,7 @@ public class SvnRepositoryServiceProvider extends RepositoryServiceProvider {
|
|||||||
public FileLockCommand getFileLockCommand() {
|
public FileLockCommand getFileLockCommand() {
|
||||||
return new SvnFileLockCommand(context);
|
return new SvnFileLockCommand(context);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public ChangesetsCommand getChangesetsCommand() { return new SvnChangesetsCommand(context);}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,56 @@
|
|||||||
|
/*
|
||||||
|
* MIT License
|
||||||
|
*
|
||||||
|
* Copyright (c) 2020-present Cloudogu GmbH and Contributors
|
||||||
|
*
|
||||||
|
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
|
* of this software and associated documentation files (the "Software"), to deal
|
||||||
|
* in the Software without restriction, including without limitation the rights
|
||||||
|
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||||
|
* copies of the Software, and to permit persons to whom the Software is
|
||||||
|
* furnished to do so, subject to the following conditions:
|
||||||
|
*
|
||||||
|
* The above copyright notice and this permission notice shall be included in all
|
||||||
|
* copies or substantial portions of the Software.
|
||||||
|
*
|
||||||
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||||
|
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||||
|
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||||
|
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||||
|
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||||
|
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||||
|
* SOFTWARE.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package sonia.scm.repository.spi;
|
||||||
|
|
||||||
|
import org.junit.Test;
|
||||||
|
import sonia.scm.repository.Changeset;
|
||||||
|
|
||||||
|
import java.util.Optional;
|
||||||
|
|
||||||
|
import static org.assertj.core.api.Assertions.assertThat;
|
||||||
|
|
||||||
|
public class SvnChangesetsCommandTest extends AbstractSvnCommandTestBase {
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void getAllChangesetsFromRepository() {
|
||||||
|
Iterable<Changeset> changesets = createCommand().getChangesets(new ChangesetsCommandRequest());
|
||||||
|
|
||||||
|
assertThat(changesets).hasSize(5);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void getLatestChangesetFromRepository() {
|
||||||
|
Optional<Changeset> changeset = createCommand().getLatestChangeset();
|
||||||
|
|
||||||
|
assertThat(changeset).isPresent();
|
||||||
|
assertThat(changeset.get().getId()).isEqualTo("5");
|
||||||
|
}
|
||||||
|
|
||||||
|
private SvnChangesetsCommand createCommand()
|
||||||
|
{
|
||||||
|
return new SvnChangesetsCommand(createContext());
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@@ -24,25 +24,25 @@
|
|||||||
-->
|
-->
|
||||||
|
|
||||||
<caches>
|
<caches>
|
||||||
|
|
||||||
<defaultCache
|
<defaultCache
|
||||||
maximumSize="200"
|
maximumSize="200"
|
||||||
expireAfterAccess="1200"
|
expireAfterAccess="1200"
|
||||||
expireAfterWrite="2400"
|
expireAfterWrite="2400"
|
||||||
/>
|
/>
|
||||||
|
|
||||||
<!--
|
<!--
|
||||||
External group cache
|
External group cache
|
||||||
average: 1K
|
average: 1K
|
||||||
-->
|
-->
|
||||||
|
|
||||||
<cache
|
<cache
|
||||||
name="sonia.cache.externalGroups"
|
name="sonia.cache.externalGroups"
|
||||||
maximumSize="1000"
|
maximumSize="1000"
|
||||||
expireAfterAccess="60"
|
expireAfterAccess="60"
|
||||||
expireAfterWrite="120"
|
expireAfterWrite="120"
|
||||||
/>
|
/>
|
||||||
|
|
||||||
<!--
|
<!--
|
||||||
Authorization cache
|
Authorization cache
|
||||||
average: 3K
|
average: 3K
|
||||||
@@ -50,11 +50,11 @@
|
|||||||
<cache
|
<cache
|
||||||
name="sonia.cache.authorizing"
|
name="sonia.cache.authorizing"
|
||||||
maximumSize="1000"
|
maximumSize="1000"
|
||||||
expireAfterAccess="1200"
|
expireAfterAccess="1200"
|
||||||
expireAfterWrite="2400"
|
expireAfterWrite="2400"
|
||||||
copyStrategy="read"
|
copyStrategy="read"
|
||||||
/>
|
/>
|
||||||
|
|
||||||
<!--
|
<!--
|
||||||
PluginCenter cache
|
PluginCenter cache
|
||||||
average: 30K
|
average: 30K
|
||||||
@@ -75,7 +75,7 @@
|
|||||||
expireAfterWrite="3600"
|
expireAfterWrite="3600"
|
||||||
/>
|
/>
|
||||||
|
|
||||||
<!--
|
<!--
|
||||||
Search cache for users
|
Search cache for users
|
||||||
average: 0.5K
|
average: 0.5K
|
||||||
-->
|
-->
|
||||||
@@ -94,7 +94,16 @@
|
|||||||
expireAfterAccess="60000"
|
expireAfterAccess="60000"
|
||||||
/>
|
/>
|
||||||
|
|
||||||
<!--
|
<!--
|
||||||
|
Search cache for repository changesets
|
||||||
|
-->
|
||||||
|
<cache
|
||||||
|
name="sonia.cache.cmd.changesets"
|
||||||
|
maximumSize="1000000"
|
||||||
|
expireAfterAccess="60000"
|
||||||
|
/>
|
||||||
|
|
||||||
|
<!--
|
||||||
Search cache for groups
|
Search cache for groups
|
||||||
average: 0.5K
|
average: 0.5K
|
||||||
-->
|
-->
|
||||||
@@ -103,9 +112,9 @@
|
|||||||
maximumSize="1000"
|
maximumSize="1000"
|
||||||
expireAfterWrite="5400"
|
expireAfterWrite="5400"
|
||||||
/>
|
/>
|
||||||
|
|
||||||
<!-- repository api -->
|
<!-- repository api -->
|
||||||
|
|
||||||
<!--
|
<!--
|
||||||
Changeset cache
|
Changeset cache
|
||||||
average: 25K
|
average: 25K
|
||||||
@@ -115,7 +124,7 @@
|
|||||||
maximumSize="500"
|
maximumSize="500"
|
||||||
copyStrategy="read-write"
|
copyStrategy="read-write"
|
||||||
/>
|
/>
|
||||||
|
|
||||||
<!--
|
<!--
|
||||||
FileObject cache
|
FileObject cache
|
||||||
average: 1.5K
|
average: 1.5K
|
||||||
@@ -135,7 +144,7 @@
|
|||||||
maximumSize="1000"
|
maximumSize="1000"
|
||||||
copyStrategy="read-write"
|
copyStrategy="read-write"
|
||||||
/>
|
/>
|
||||||
|
|
||||||
<!--
|
<!--
|
||||||
Tag cache
|
Tag cache
|
||||||
average: 5K
|
average: 5K
|
||||||
@@ -144,7 +153,7 @@
|
|||||||
name="sonia.cache.cmd.tags"
|
name="sonia.cache.cmd.tags"
|
||||||
maximumSize="500"
|
maximumSize="500"
|
||||||
/>
|
/>
|
||||||
|
|
||||||
<!--
|
<!--
|
||||||
Branch cache
|
Branch cache
|
||||||
average: 2.5K
|
average: 2.5K
|
||||||
|
|||||||
Reference in New Issue
Block a user