mirror of
https://github.com/scm-manager/scm-manager.git
synced 2025-11-10 07:25:44 +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));
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
Reference in New Issue
Block a user