<commit_before>require 'cmdb/namespace'
require 'git'
require 'logger'

class CMDB::Git
  def initialize(options={})
    @repo_url = options[:origin] || 'git@git:cmdb'
    @local_path = options[:local_path] || '/opt/orctool/data/cmdb/'
    @branch = options[:branch] || "master"
  end

  def update()
    if File.directory?(@local_path)
      @git = Git.open(@local_path, :log => Logger.new(STDOUT))
      @git.remotes.first.fetch
      @git.fetch( 'origin' )
      @git.merge('origin', 'merge concurrent modifications')
      @git.pull
    else
      @git = Git.clone(@repo_url,@local_path, :log => Logger.new(STDOUT))
    end

    if self.get_branch() != @branch
      @git.branch( @branch ).checkout
    end
  end

  def get_branch()
    return @git.current_branch
  end

  def commit_and_push()
    if File.directory?(@local_path)
      if (@git.status.changed.size>0)
        @git.commit_all('orc auto-updating cmdb')
        @git.fetch( 'origin' )
        @git.merge('origin', 'merge concurrent modifications')
        @git.push()
      end
    else
      raise "#{@local_path} doesn't exist"
    end
  end
end<commit_msg>Add a timeout to cmdb pushes / pulls.<commit_after>require 'cmdb/namespace'
require 'git'
require 'logger'

require 'dl/import'
module Alarm
  extend DL::Importable
  if RUBY_PLATFORM =~ /darwin/
    so_ext = 'dylib'
  else
    so_ext = 'so.6'
  end
  dlload "libc.#{so_ext}"
  extern "unsigned int alarm(unsigned int)"
end

class CMDB::Git
  def initialize(options={})
    @repo_url = options[:origin] || 'git@git:cmdb'
    @local_path = options[:local_path] || '/opt/orctool/data/cmdb/'
    @branch = options[:branch] || "master"
    @timeout = 10
  end

  def update()
    Alarm.alarm(@timeout)
    if File.directory?(@local_path)
      @git = Git.open(@local_path, :log => Logger.new(STDOUT))
      @git.remotes.first.fetch
      @git.fetch( 'origin' )
      @git.merge('origin', 'merge concurrent modifications')
      @git.pull
    else
      @git = Git.clone(@repo_url,@local_path, :log => Logger.new(STDOUT))
    end

    if self.get_branch() != @branch
      @git.branch( @branch ).checkout
    end
    Alarm.alarm(0)
  end

  def get_branch()
    return @git.current_branch
  end

  def commit_and_push()
    if File.directory?(@local_path)
      if (@git.status.changed.size>0)
        Alarm.alarm(@timeout)
        @git.commit_all('orc auto-updating cmdb')
        @git.fetch( 'origin' )
        @git.merge('origin', 'merge concurrent modifications')
        @git.push()
        Alarm.alarm(0)
      end
    else
      raise "#{@local_path} doesn't exist"
    end
  end
end

{'fraction_non_alphanumeric': 0.14690130068859986, 'fraction_numerical': 0.0026778882938026014, 'mean_word_length': 2.9146706586826348, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 9, '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': '3548947', 'n_tokens_mistral': 929, 'n_tokens_neox': 901, 'n_words': 194}