mirror of
https://github.com/scm-manager/scm-manager.git
synced 2025-11-01 11:05:56 +01:00
Introduce new API for modifications
New modifications includes list of 'renames'. Therefore we introduce a new base class Modification.
This commit is contained in:
@@ -21,7 +21,7 @@
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
* SOFTWARE.
|
||||
*/
|
||||
|
||||
|
||||
package sonia.scm.repository;
|
||||
|
||||
//~--- non-JDK imports --------------------------------------------------------
|
||||
@@ -49,7 +49,11 @@ import java.io.IOException;
|
||||
import java.io.PrintWriter;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Optional;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
import static java.util.Collections.emptyList;
|
||||
import static java.util.Optional.empty;
|
||||
import static sonia.scm.ContextEntry.ContextBuilder.entity;
|
||||
import static sonia.scm.NotFoundException.notFound;
|
||||
|
||||
@@ -116,30 +120,23 @@ public final class SvnUtil
|
||||
|
||||
|
||||
public static Modifications createModifications(SVNLogEntry entry, String revision) {
|
||||
Modifications modifications = new Modifications();
|
||||
modifications.setRevision(revision);
|
||||
Map<String, SVNLogEntryPath> changeMap = entry.getChangedPaths();
|
||||
|
||||
List<Modification> modificationList;
|
||||
if (Util.isNotEmpty(changeMap)) {
|
||||
|
||||
for (SVNLogEntryPath e : changeMap.values()) {
|
||||
appendModification(modifications, e.getType(), e.getPath());
|
||||
}
|
||||
modificationList = changeMap.values().stream()
|
||||
.map(e -> asModification(e.getType(), e.getPath()))
|
||||
.filter(Optional::isPresent)
|
||||
.map(Optional::get)
|
||||
.collect(Collectors.toList());
|
||||
} else {
|
||||
modificationList = emptyList();
|
||||
}
|
||||
return modifications;
|
||||
|
||||
return new Modifications(revision, modificationList);
|
||||
}
|
||||
|
||||
/**
|
||||
* Method description
|
||||
*
|
||||
*
|
||||
* @param modifications
|
||||
* @param type
|
||||
* @param path
|
||||
*/
|
||||
public static void appendModification(Modifications modifications, char type,
|
||||
String path)
|
||||
{
|
||||
public static Optional<Modification> asModification(char type, String path) {
|
||||
if (path.startsWith("/"))
|
||||
{
|
||||
path = path.substring(1);
|
||||
@@ -148,23 +145,18 @@ public final class SvnUtil
|
||||
switch (type)
|
||||
{
|
||||
case SVNLogEntryPath.TYPE_ADDED :
|
||||
modifications.getAdded().add(path);
|
||||
|
||||
break;
|
||||
return Optional.of(new Modification.Added(path));
|
||||
|
||||
case SVNLogEntryPath.TYPE_DELETED :
|
||||
modifications.getRemoved().add(path);
|
||||
|
||||
break;
|
||||
return Optional.of(new Modification.Removed(path));
|
||||
|
||||
case TYPE_UPDATED :
|
||||
case SVNLogEntryPath.TYPE_MODIFIED :
|
||||
modifications.getModified().add(path);
|
||||
|
||||
break;
|
||||
return Optional.of(new Modification.Modified(path));
|
||||
|
||||
default :
|
||||
logger.debug("unknown modification type {}", type);
|
||||
return empty();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -31,10 +31,12 @@ import org.tmatesoft.svn.core.io.SVNRepository;
|
||||
import org.tmatesoft.svn.core.wc.SVNClientManager;
|
||||
import org.tmatesoft.svn.core.wc.admin.SVNLookClient;
|
||||
import sonia.scm.repository.InternalRepositoryException;
|
||||
import sonia.scm.repository.Modification;
|
||||
import sonia.scm.repository.Modifications;
|
||||
import sonia.scm.repository.SvnUtil;
|
||||
import sonia.scm.util.Util;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
|
||||
@Slf4j
|
||||
@@ -78,12 +80,12 @@ public class SvnModificationsCommand extends AbstractSvnCommand implements Modif
|
||||
|
||||
private Modifications getModificationsFromTransaction(String transaction) throws SVNException {
|
||||
log.debug("get svn modifications from transaction: {}", transaction);
|
||||
final Modifications modifications = new Modifications();
|
||||
SVNLookClient client = SVNClientManager.newInstance().getLookClient();
|
||||
Collection<Modification> modificationList = new ArrayList<>();
|
||||
client.doGetChanged(context.getDirectory(), transaction,
|
||||
e -> SvnUtil.appendModification(modifications, e.getType(), e.getPath()), true);
|
||||
e -> SvnUtil.asModification(e.getType(), e.getPath()).ifPresent(modificationList::add), true);
|
||||
|
||||
return modifications;
|
||||
return new Modifications(null, modificationList);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -143,8 +143,8 @@ public class SvnLogCommandTest extends AbstractSvnCommandTestBase
|
||||
assertEquals(1, modifications.getModified().size());
|
||||
assertEquals(1, modifications.getRemoved().size());
|
||||
assertTrue("added list should be empty", modifications.getAdded().isEmpty());
|
||||
assertEquals("a.txt", modifications.getModified().get(0));
|
||||
assertEquals("b.txt", modifications.getRemoved().get(0));
|
||||
assertEquals("a.txt", modifications.getModified().get(0).getPath());
|
||||
assertEquals("b.txt", modifications.getRemoved().get(0).getPath());
|
||||
}
|
||||
|
||||
@Test
|
||||
|
||||
Reference in New Issue
Block a user