<commit_before>/*
 * Copyright (c) 2011 <NAME>
 * Distributed under Apache License.
 */

package sshd.git

import org.apache.sshd.server.{Environment, ExitCallback, Command}
import org.eclipse.jgit.transport.UploadPack
import org.eclipse.jgit.lib.RepositoryCache.FileKey
import server.Server
import org.eclipse.jgit.util.FS
import org.eclipse.jgit.lib.{Repository, RepositoryCache}
import java.io.{File, OutputStream, InputStream}
import com.twitter.logging.Logger
import java.lang.Thread

/**
 * Created by IntelliJ IDEA.
 * User: den
 * Date: 06.08.11
 * Time: 12:58
 * To change this template use File | Settings | File Templates.
 */

abstract sealed class AbstractCommand extends Command {
  protected val log = Logger.get(this.getClass)

  protected var in: InputStream = null
  protected var out: OutputStream = null
  protected var err: OutputStream = null

  protected var callback: ExitCallback = null

  def setInputStream(in: InputStream) {
    this.in = in
  }

  def destroy() {}

  def setExitCallback(callback: ExitCallback) {
    this.callback = callback
  }

  def start(env: Environment) = {
    new Thread(
      new Runnable {
        def run() {
          try {
            runImpl(env)
          } finally {
            in.close();
            out.close();
            err.close();
            callback.onExit(127);
          }
        }
      }
    ).start();
  }

  def runImpl(env: Environment)

  def setErrorStream(err: OutputStream) {
    this.err = err
  }

  def setOutputStream(out: OutputStream) {
    this.out = out
  }


}

case class Upload(repoPath: String) extends AbstractCommand {
  def runImpl(env: Environment) = {
    val repo: Repository = RepositoryCache.open(
      FileKey.lenient(new File(Server.repoDir + repoPath), FS.DETECTED))
    val up = new UploadPack(repo)
    up.upload(in, out, err)
  }
}

case class Receive(repoPath: String) extends AbstractCommand {
  def runImpl(env: Environment) = {
    //UploadPack up = new UploadPack()
  }
}<commit_msg>Заменил потоки на акторы (не уверен, что это удачная идея)<commit_after>/*
 * Copyright (c) 2011 <NAME>
 * Distributed under Apache License.
 */

package sshd.git

import org.apache.sshd.server.{Environment, ExitCallback, Command}
import org.eclipse.jgit.transport.UploadPack
import org.eclipse.jgit.lib.RepositoryCache.FileKey
import server.Server
import org.eclipse.jgit.util.FS
import org.eclipse.jgit.lib.{Repository, RepositoryCache}
import java.io.{File, OutputStream, InputStream}
import com.twitter.logging.Logger
import actors.Actor

/**
 * Created by IntelliJ IDEA.
 * User: den
 * Date: 06.08.11
 * Time: 12:58
 * To change this template use File | Settings | File Templates.
 */

abstract sealed class AbstractCommand extends Command {
  protected val log = Logger.get(this.getClass)

  protected var in: InputStream = null
  protected var out: OutputStream = null
  protected var err: OutputStream = null

  protected var callback: ExitCallback = null

  def setInputStream(in: InputStream) {
    this.in = in
  }

  def destroy() {}

  def setExitCallback(callback: ExitCallback) {
    this.callback = callback
  }

  def start(env: Environment) = {
    new Actor {

      def act() {
        try {
          run(env)
        } finally {
          in.close();
          out.close();
          err.close();
          callback.onExit(127);
        }
      }

    }.start();
  }


  def run(env: Environment)

  def setErrorStream(err: OutputStream) {
    this.err = err
  }

  def setOutputStream(out: OutputStream) {
    this.out = out
  }


}

case class Upload(repoPath: String) extends AbstractCommand {
  def run(env: Environment) = {
    val repo: Repository = RepositoryCache.open(
      FileKey.lenient(new File(Server.repoDir + repoPath), FS.DETECTED))
    val up = new UploadPack(repo)
    up.upload(in, out, err)
  }
}

case class Receive(repoPath: String) extends AbstractCommand {
  def run(env: Environment) = {
    //UploadPack up = new UploadPack()
  }
}
{'fraction_non_alphanumeric': 0.10740276035131745, 'fraction_numerical': 0.008531994981179424, 'mean_word_length': 3.022199798183653, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6879582', 'n_tokens_mistral': 1287, 'n_tokens_neox': 1218, 'n_words': 331}