mirror of
https://github.com/scm-manager/scm-manager.git
synced 2025-11-11 07:55:47 +01:00
Merge with 2.0.0-m3
This commit is contained in:
@@ -0,0 +1,32 @@
|
||||
package sonia.scm.repository.spi;
|
||||
|
||||
import sonia.scm.repository.Modifications;
|
||||
import sonia.scm.repository.Repository;
|
||||
import sonia.scm.repository.spi.javahg.HgLogChangesetCommand;
|
||||
|
||||
import java.text.MessageFormat;
|
||||
|
||||
public class HgModificationsCommand extends AbstractCommand implements ModificationsCommand {
|
||||
|
||||
HgModificationsCommand(HgCommandContext context, Repository repository) {
|
||||
super(context, repository);
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public Modifications getModifications(String revision) {
|
||||
com.aragost.javahg.Repository repository = open();
|
||||
HgLogChangesetCommand hgLogChangesetCommand = HgLogChangesetCommand.on(repository, getContext().getConfig());
|
||||
int hgRevision = hgLogChangesetCommand.rev(revision).singleRevision();
|
||||
Modifications modifications = hgLogChangesetCommand.rev(MessageFormat.format("{0}:{0}", hgRevision)).extractModifications();
|
||||
modifications.setRevision(revision);
|
||||
return modifications;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Modifications getModifications(ModificationsCommandRequest request) {
|
||||
return getModifications(request.getRevision());
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
@@ -39,6 +39,7 @@ import sonia.scm.repository.HgHookManager;
|
||||
import sonia.scm.repository.HgRepositoryHandler;
|
||||
import sonia.scm.repository.Repository;
|
||||
import sonia.scm.repository.api.Command;
|
||||
import sonia.scm.repository.api.CommandNotSupportedException;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
@@ -185,6 +186,16 @@ public class HgRepositoryServiceProvider extends RepositoryServiceProvider
|
||||
return new HgLogCommand(context, repository);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the corresponding {@link ModificationsCommand} implemented from the Plugins
|
||||
*
|
||||
* @return the corresponding {@link ModificationsCommand} implemented from the Plugins
|
||||
* @throws CommandNotSupportedException if there is no Implementation
|
||||
*/
|
||||
public ModificationsCommand getModificationsCommand() {
|
||||
return new HgModificationsCommand(context,repository);
|
||||
}
|
||||
|
||||
/**
|
||||
* Method description
|
||||
*
|
||||
|
||||
@@ -41,21 +41,18 @@ import com.aragost.javahg.internals.AbstractCommand;
|
||||
import com.aragost.javahg.internals.HgInputStream;
|
||||
import com.aragost.javahg.internals.RuntimeIOException;
|
||||
import com.aragost.javahg.internals.Utils;
|
||||
|
||||
import com.google.common.collect.ImmutableMap;
|
||||
import com.google.common.collect.Lists;
|
||||
|
||||
import sonia.scm.repository.Changeset;
|
||||
import sonia.scm.repository.HgConfig;
|
||||
import sonia.scm.repository.Modifications;
|
||||
import sonia.scm.repository.Person;
|
||||
|
||||
//~--- JDK imports ------------------------------------------------------------
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
//~--- JDK imports ------------------------------------------------------------
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Sebastian Sdorra
|
||||
@@ -251,33 +248,14 @@ public abstract class AbstractChangesetCommand extends AbstractCommand
|
||||
changeset.getProperties().put(PROPERTY_CLOSE, "true");
|
||||
}
|
||||
|
||||
Modifications modifications = changeset.getModifications();
|
||||
|
||||
String line = in.textUpTo('\n');
|
||||
|
||||
while (line.length() > 0)
|
||||
{
|
||||
|
||||
if (line.startsWith("a "))
|
||||
{
|
||||
modifications.getAdded().add(line.substring(2));
|
||||
}
|
||||
else if (line.startsWith("m "))
|
||||
{
|
||||
modifications.getModified().add(line.substring(2));
|
||||
}
|
||||
else if (line.startsWith("d "))
|
||||
{
|
||||
modifications.getRemoved().add(line.substring(2));
|
||||
}
|
||||
else if (line.startsWith("t "))
|
||||
while (line.length() > 0) {
|
||||
if (line.startsWith("t "))
|
||||
{
|
||||
changeset.getTags().add(line.substring(2));
|
||||
}
|
||||
|
||||
line = in.textUpTo('\n');
|
||||
}
|
||||
|
||||
String message = in.textUpTo('\0');
|
||||
|
||||
changeset.setDescription(message);
|
||||
@@ -285,6 +263,36 @@ public abstract class AbstractChangesetCommand extends AbstractCommand
|
||||
return changeset;
|
||||
}
|
||||
|
||||
protected Modifications readModificationsFromStream(HgInputStream in) {
|
||||
try {
|
||||
boolean found = in.find(CHANGESET_PATTERN);
|
||||
if (found) {
|
||||
while (!in.match(CHANGESET_PATTERN)) {
|
||||
return extractModifications(in);
|
||||
}
|
||||
}
|
||||
} catch (IOException e) {
|
||||
throw new RuntimeIOException(e);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
private Modifications extractModifications(HgInputStream in) throws IOException {
|
||||
Modifications modifications = new Modifications();
|
||||
String line = in.textUpTo('\n');
|
||||
while (line.length() > 0) {
|
||||
if (line.startsWith("a ")) {
|
||||
modifications.getAdded().add(line.substring(2));
|
||||
} else if (line.startsWith("m ")) {
|
||||
modifications.getModified().add(line.substring(2));
|
||||
} else if (line.startsWith("d ")) {
|
||||
modifications.getRemoved().add(line.substring(2));
|
||||
}
|
||||
line = in.textUpTo('\n');
|
||||
}
|
||||
return modifications;
|
||||
}
|
||||
|
||||
/**
|
||||
* Method description
|
||||
*
|
||||
|
||||
@@ -38,14 +38,14 @@ package sonia.scm.repository.spi.javahg;
|
||||
import com.aragost.javahg.Repository;
|
||||
import com.aragost.javahg.internals.HgInputStream;
|
||||
import com.aragost.javahg.internals.Utils;
|
||||
|
||||
import sonia.scm.repository.Changeset;
|
||||
import sonia.scm.repository.HgConfig;
|
||||
|
||||
//~--- JDK imports ------------------------------------------------------------
|
||||
import sonia.scm.repository.Modifications;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
//~--- JDK imports ------------------------------------------------------------
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Sebastian Sdorra
|
||||
@@ -106,11 +106,22 @@ public class HgLogChangesetCommand extends AbstractChangesetCommand
|
||||
*/
|
||||
public List<Changeset> execute(String... files)
|
||||
{
|
||||
cmdAppend("--style", CHANGESET_EAGER_STYLE_PATH);
|
||||
return readListFromStream(getHgInputStream(files, CHANGESET_EAGER_STYLE_PATH));
|
||||
}
|
||||
|
||||
HgInputStream stream = launchStream(files);
|
||||
/**
|
||||
* Extract Modifications from the Repository files
|
||||
*
|
||||
* @param files repo files
|
||||
* @return modifications
|
||||
*/
|
||||
public Modifications extractModifications(String... files) {
|
||||
return readModificationsFromStream(getHgInputStream(files, CHANGESET_EAGER_STYLE_PATH));
|
||||
}
|
||||
|
||||
return readListFromStream(stream);
|
||||
HgInputStream getHgInputStream(String[] files, String changesetStylePath) {
|
||||
cmdAppend("--style", changesetStylePath);
|
||||
return launchStream(files);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -138,11 +149,7 @@ public class HgLogChangesetCommand extends AbstractChangesetCommand
|
||||
*/
|
||||
public List<Integer> loadRevisions(String... files)
|
||||
{
|
||||
cmdAppend("--style", CHANGESET_LAZY_STYLE_PATH);
|
||||
|
||||
HgInputStream stream = launchStream(files);
|
||||
|
||||
return loadRevisionsFromStream(stream);
|
||||
return loadRevisionsFromStream(getHgInputStream(files, CHANGESET_LAZY_STYLE_PATH));
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
//@flow
|
||||
import React from "react";
|
||||
import { Image } from "@scm-manager/ui-components";
|
||||
import {Image} from "@scm-manager/ui-components";
|
||||
|
||||
type Props = {
|
||||
};
|
||||
|
||||
@@ -32,11 +32,11 @@ package sonia.scm.repository.client.spi;
|
||||
|
||||
import com.aragost.javahg.Repository;
|
||||
import com.google.common.collect.Lists;
|
||||
import java.io.IOException;
|
||||
import sonia.scm.repository.Changeset;
|
||||
import sonia.scm.repository.Modifications;
|
||||
import sonia.scm.repository.Person;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
/**
|
||||
* Mercurial implementation of the {@link CommitCommand}.
|
||||
*
|
||||
@@ -70,9 +70,6 @@ public class HgCommitCommand implements CommitCommand
|
||||
|
||||
changeset.setBranches(Lists.newArrayList(c.getBranch()));
|
||||
changeset.setTags(c.tags());
|
||||
changeset.setModifications(
|
||||
new Modifications(c.getAddedFiles(), c.getModifiedFiles(), c.getDeletedFiles())
|
||||
);
|
||||
return changeset;
|
||||
}
|
||||
|
||||
|
||||
@@ -39,6 +39,9 @@ import org.junit.Test;
|
||||
import sonia.scm.repository.Changeset;
|
||||
import sonia.scm.repository.ChangesetPagingResult;
|
||||
import sonia.scm.repository.Modifications;
|
||||
import sonia.scm.repository.RevisionNotFoundException;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
import static org.hamcrest.Matchers.contains;
|
||||
import static org.junit.Assert.assertEquals;
|
||||
@@ -133,27 +136,28 @@ public class HgLogCommandTest extends AbstractHgCommandTestBase
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGetCommit() {
|
||||
public void testGetCommit() throws IOException, RevisionNotFoundException {
|
||||
HgLogCommand command = createComamnd();
|
||||
String revision = "a9bacaf1b7fa0cebfca71fed4e59ed69a6319427";
|
||||
Changeset c =
|
||||
command.getChangeset("a9bacaf1b7fa0cebfca71fed4e59ed69a6319427");
|
||||
command.getChangeset(revision);
|
||||
|
||||
assertNotNull(c);
|
||||
assertEquals("a9bacaf1b7fa0cebfca71fed4e59ed69a6319427", c.getId());
|
||||
assertEquals(revision, c.getId());
|
||||
assertEquals("added a and b files", c.getDescription());
|
||||
checkDate(c.getDate());
|
||||
assertEquals("Douglas Adams", c.getAuthor().getName());
|
||||
assertEquals("douglas.adams@hitchhiker.com", c.getAuthor().getMail());
|
||||
assertEquals("added a and b files", c.getDescription());
|
||||
ModificationsCommand modificationsCommand = new HgModificationsCommand(cmdContext, repository);
|
||||
Modifications modifications = modificationsCommand.getModifications(revision);
|
||||
|
||||
Modifications mods = c.getModifications();
|
||||
|
||||
assertNotNull(mods);
|
||||
assertTrue("modified list should be empty", mods.getModified().isEmpty());
|
||||
assertTrue("removed list should be empty", mods.getRemoved().isEmpty());
|
||||
assertFalse("added list should not be empty", mods.getAdded().isEmpty());
|
||||
assertEquals(2, mods.getAdded().size());
|
||||
assertThat(mods.getAdded(), contains("a.txt", "b.txt"));
|
||||
assertNotNull(modifications);
|
||||
assertTrue("modified list should be empty", modifications.getModified().isEmpty());
|
||||
assertTrue("removed list should be empty", modifications.getRemoved().isEmpty());
|
||||
assertFalse("added list should not be empty", modifications.getAdded().isEmpty());
|
||||
assertEquals(2, modifications.getAdded().size());
|
||||
assertThat(modifications.getAdded(), contains("a.txt", "b.txt"));
|
||||
}
|
||||
|
||||
@Test
|
||||
|
||||
@@ -0,0 +1,111 @@
|
||||
package sonia.scm.repository.spi;
|
||||
|
||||
import com.aragost.javahg.Changeset;
|
||||
import com.aragost.javahg.commands.RemoveCommand;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import sonia.scm.repository.HgTestUtil;
|
||||
import sonia.scm.repository.Modifications;
|
||||
|
||||
import java.io.File;
|
||||
import java.util.function.Consumer;
|
||||
|
||||
import static org.assertj.core.api.Java6Assertions.assertThat;
|
||||
|
||||
public class HgModificationsCommandTest extends IncomingOutgoingTestBase {
|
||||
|
||||
|
||||
private HgModificationsCommand outgoingModificationsCommand;
|
||||
|
||||
@Before
|
||||
public void init() {
|
||||
HgCommandContext outgoingContext = new HgCommandContext(HgTestUtil.createHookManager(), handler, outgoingRepository, outgoingDirectory);
|
||||
outgoingModificationsCommand = new HgModificationsCommand(outgoingContext, outgoingRepository);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void shouldReadAddedFiles() throws Exception {
|
||||
String fileName = "a.txt";
|
||||
writeNewFile(outgoing, outgoingDirectory, fileName, "bal bla");
|
||||
Changeset changeset = commit(outgoing, "added a.txt");
|
||||
String revision = String.valueOf(changeset.getRevision());
|
||||
Consumer<Modifications> assertModifications = assertAddedFile(fileName);
|
||||
assertModifications.accept(outgoingModificationsCommand.getModifications(revision));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void shouldReadModifiedFiles() throws Exception {
|
||||
String fileName = "a.txt";
|
||||
writeNewFile(outgoing, outgoingDirectory, fileName, "bal bla");
|
||||
commit(outgoing, "added a.txt");
|
||||
writeNewFile(outgoing, outgoingDirectory, fileName, "new content");
|
||||
Changeset changeset = commit(outgoing, "modified a.txt");
|
||||
String revision = String.valueOf(changeset.getRevision());
|
||||
Consumer<Modifications> assertModifications = assertModifiedFiles(fileName);
|
||||
assertModifications.accept(outgoingModificationsCommand.getModifications(revision));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void shouldReadRemovedFiles() throws Exception {
|
||||
String fileName = "a.txt";
|
||||
writeNewFile(outgoing, outgoingDirectory, fileName, "bal bla");
|
||||
commit(outgoing, "added a.txt");
|
||||
File file = new File(outgoingDirectory, fileName);
|
||||
file.delete();
|
||||
RemoveCommand.on(outgoing).execute(file);
|
||||
Changeset changeset = commit(outgoing, "removed a.txt");
|
||||
String revision = String.valueOf(changeset.getRevision());
|
||||
Consumer<Modifications> assertModifications = assertRemovedFiles(fileName);
|
||||
assertModifications.accept(outgoingModificationsCommand.getModifications(revision));
|
||||
}
|
||||
|
||||
|
||||
Consumer<Modifications> assertRemovedFiles(String fileName) {
|
||||
return (modifications) -> {
|
||||
assertThat(modifications).isNotNull();
|
||||
assertThat(modifications.getAdded())
|
||||
.as("added files modifications")
|
||||
.hasSize(0);
|
||||
assertThat(modifications.getModified())
|
||||
.as("modified files modifications")
|
||||
.hasSize(0);
|
||||
assertThat(modifications.getRemoved())
|
||||
.as("removed files modifications")
|
||||
.hasSize(1)
|
||||
.containsOnly(fileName);
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
Consumer<Modifications> assertModifiedFiles(String file) {
|
||||
return (modifications) -> {
|
||||
assertThat(modifications).isNotNull();
|
||||
assertThat(modifications.getAdded())
|
||||
.as("added files modifications")
|
||||
.hasSize(0);
|
||||
assertThat(modifications.getModified())
|
||||
.as("modified files modifications")
|
||||
.hasSize(1)
|
||||
.containsOnly(file);
|
||||
assertThat(modifications.getRemoved())
|
||||
.as("removed files modifications")
|
||||
.hasSize(0);
|
||||
};
|
||||
}
|
||||
|
||||
Consumer<Modifications> assertAddedFile(String addedFile) {
|
||||
return (modifications) -> {
|
||||
assertThat(modifications).isNotNull();
|
||||
assertThat(modifications.getAdded())
|
||||
.as("added files modifications")
|
||||
.hasSize(1)
|
||||
.containsOnly(addedFile);
|
||||
assertThat(modifications.getModified())
|
||||
.as("modified files modifications")
|
||||
.hasSize(0);
|
||||
assertThat(modifications.getRemoved())
|
||||
.as("removed files modifications")
|
||||
.hasSize(0);
|
||||
};
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user