use javahg for diff command

This commit is contained in:
Sebastian Sdorra
2012-07-01 19:30:23 +02:00
parent 41a8c515e3
commit 152943d15b
2 changed files with 21 additions and 24 deletions

View File

@@ -30,46 +30,38 @@
*/ */
package sonia.scm.repository.spi; package sonia.scm.repository.spi;
//~--- non-JDK imports -------------------------------------------------------- //~--- non-JDK imports --------------------------------------------------------
import com.google.common.io.ByteStreams; import com.google.common.base.Strings;
import com.google.common.io.Closeables;
import sonia.scm.repository.HgContext;
import sonia.scm.repository.HgRepositoryHandler;
import sonia.scm.repository.Repository; import sonia.scm.repository.Repository;
import sonia.scm.repository.RepositoryException; import sonia.scm.repository.RepositoryException;
import sonia.scm.util.Util;
//~--- JDK imports ------------------------------------------------------------ //~--- JDK imports ------------------------------------------------------------
import java.io.File;
import java.io.IOException; import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream; import java.io.OutputStream;
/** /**
* *
* @author Sebastian Sdorra * @author Sebastian Sdorra
*/ */
public class HgDiffCommand extends AbstractHgCommand implements DiffCommand public class HgDiffCommand extends AbstractCommand implements DiffCommand
{ {
/** /**
* Constructs ... * Constructs ...
* *
* *
* @param handler
* @param context * @param context
* @param repository * @param repository
* @param repositoryDirectory
*/ */
public HgDiffCommand(HgRepositoryHandler handler, HgContext context, HgDiffCommand(HgCommandContext context, Repository repository)
Repository repository, File repositoryDirectory)
{ {
super(handler, context, repository, repositoryDirectory); super(context, repository);
} }
//~--- get methods ---------------------------------------------------------- //~--- get methods ----------------------------------------------------------
@@ -88,19 +80,25 @@ public class HgDiffCommand extends AbstractHgCommand implements DiffCommand
public void getDiffResult(DiffCommandRequest request, OutputStream output) public void getDiffResult(DiffCommandRequest request, OutputStream output)
throws IOException, RepositoryException throws IOException, RepositoryException
{ {
Process p = createHgProcess("diff", "-c", request.getRevision(), com.aragost.javahg.commands.DiffCommand cmd =
Util.nonNull(request.getPath())); com.aragost.javahg.commands.DiffCommand.on(open());
InputStream input = null;
try if (!Strings.isNullOrEmpty(request.getRevision()))
{ {
handleErrorStream(p.getErrorStream()); cmd.change(request.getRevision());
input = p.getInputStream();
ByteStreams.copy(input, output);
} }
finally
String diff = null;
if (!Strings.isNullOrEmpty(request.getPath()))
{ {
Closeables.closeQuietly(input); diff = cmd.execute(request.getPath());
} }
else
{
diff = cmd.execute();
}
output.write(diff.getBytes());
} }
} }

View File

@@ -147,8 +147,7 @@ public class HgRepositoryServiceProvider extends RepositoryServiceProvider
@Override @Override
public HgDiffCommand getDiffCommand() public HgDiffCommand getDiffCommand()
{ {
return new HgDiffCommand(handler, hgContextProvider.get(), repository, return new HgDiffCommand(context, repository);
repositoryDirectory);
} }
/** /**