<commit_before>require 'open-uri'
require "ssh2http/version"

class Ssh2http
  def initialize(destination, *cmds)
    @destination = destination
    @cmds = cmds
  end

  def run!
    case cmd
    when 'git-upload-pack'
      upload!
    when 'git-receive-pack'
      receive!
    else
      die 'Unknown command'
    end
  end

  def upload!
    open(url('/info/refs?service=git-upload-pack')) do |f|
      f.each_line do |line|
        if "001e# service=git-upload-pack\n" == line
          f.read(4) # skip "0000"
          next
        end
        print line
      end
    end
    STDOUT.flush

    input = ''
    while line = STDIN.gets
      input += line
      break if line =~ /0009done\n$/
    end

    url = URI.parse(url('/git-upload-pack'))
    http = Net::HTTP.new(url.host, url.port)
    request = Net::HTTP::Post.new(url.path)
    request.body = input
    request['Content-Type'] = 'application/x-git-upload-pack-request'
    response = http.request(request)
    print response.body
    STDOUT.flush
  end

  def receive!
    open(url('/info/refs?service=git-receive-pack')) do |f|
      f.each_line do |line|
        if "001f# service=git-receive-pack\n" == line
          f.read(4) # skip "0000"
          next
        end
        print line
      end
    end
    STDOUT.flush

    input = STDIN.read
    url = URI.parse(url('/git-receive-pack'))
    http = Net::HTTP.new(url.host, url.port)
    request = Net::HTTP::Post.new(url.path)
    request.body = input<commit_msg>Stream Response Bodies<commit_after>require 'open-uri'
require "ssh2http/version"

class Ssh2http
  def initialize(destination, *cmds)
    @destination = destination
    @cmds = cmds
  end

  def run!
    case cmd
    when 'git-upload-pack'
      upload!
    when 'git-receive-pack'
      receive!
    else
      die 'Unknown command'
    end
  end

  def upload!
    open(url('/info/refs?service=git-upload-pack')) do |f|
      f.each_line do |line|
        if "001e# service=git-upload-pack\n" == line
          f.read(4) # skip "0000"
          next
        end
        print line
      end
    end
    STDOUT.flush

    input = ''
    while line = STDIN.gets
      input += line
      break if line =~ /0009done\n$/
    end

    url = URI.parse(url('/git-upload-pack'))
    Net::HTTP.start(url.host, url.port) do |http|
      request = Net::HTTP::Post.new url.path
      request.body = input
      request['Content-Type'] = 'application/x-git-upload-pack-request'
      http.request request do |response|
        response.read_body do |chunk|
          STDOUT.write chunk
          STDOUT.flush
        end
      end
    end
  end

  def receive!
    open(url('/info/refs?service=git-receive-pack')) do |f|
      f.each_line do |line|
        if "001f# service=git-receive-pack\n" == line
          f.read(4) # skip "0000"
          next
        end
        print line
      end
    end
    STDOUT.flush

    input = STDIN.read
    url = URI.parse(url('/git-receive-pack'))
    http = Net::HTTP.new(url.host, url.port)
    request = Net::HTTP::Post.new(url.path)
    request.body = input
{'fraction_non_alphanumeric': 0.1262987012987013, 'fraction_numerical': 0.014285714285714285, 'mean_word_length': 2.068725099601594, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, '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': '1016642', 'n_tokens_mistral': 1088, 'n_tokens_neox': 1026, 'n_words': 237}