<commit_before>require 'open3'

# Some code is from https://github.com/gjtorikian/jekyll-last-modified-at

module Jekyll
  module Revision

    class Generator < Jekyll::Generator
      def generate(site)
        return if ARGV.include?("--no-revision")
        %w(posts).each do |type|
          site.send(type).each do |item|
            item.data['revisions'] = GitLogger.new(site.source, item.path, site.config['revision']).revisions
            item.data['last_modified_at'] = item.data['revisions'][0]['date']
          end
        end
      end
    end # Revision

    class GitLogger
      attr_reader :site_source, :page_path, :config

      def initialize(site_source, page_path, config = {})
        @site_source = site_source
        @page_path   = page_path
        @config      = config || {}
      end

      def revisions
        return nil unless is_git_repo?
        logs = Executor.sh('git', 'log', '--pretty=%ci|%an|%h|%H|%s', '--max-count=' + max_count.to_s, relative_path_from_git_dir)
        logs.lines.map do |line|
          parts = line.split('|')
          {"date" => parts[0], "author" => parts[1], "shorthash" => parts[2], "hash" => parts[3], "message" => parts[4..-1].join('|')}
        end
      end

      private
      
      def max_count
        config['max_count'] || 5
      end
      
      def is_git_repo?
        @@is_git_repo ||= begin
          Dir.chdir(site_source) do
            Executor.sh("git", "rev-parse", "--is-inside-work-tree").eql? "true"
          end<commit_msg>Use dummy values for draft revision history, fixes #2<commit_after>require 'open3'

# Some code is from https://github.com/gjtorikian/jekyll-last-modified-at

module Jekyll
  module Revision

    class Generator < Jekyll::Generator
      def generate(site)
        return if ARGV.include?("--no-revision")
        %w(posts).each do |type|
          site.send(type).each do |item|
            item.data['revisions'] = GitLogger.new(site.source, item.path, site.config['revision']).revisions
            item.data['last_modified_at'] = item.data['revisions'][0]['date']
          end
        end
      end
    end # Revision

    class GitLogger
      attr_reader :site_source, :page_path, :config

      def initialize(site_source, page_path, config = {})
        @site_source = site_source
        @page_path   = page_path
        @config      = config || {}
      end

      def revisions
        return nil unless is_git_repo?
        logs = Executor.sh('git', 'log', '--pretty=%ci|%an|%h|%H|%s', '--max-count=' + max_count.to_s, relative_path_from_git_dir)
        if logs.empty?
            [{"date" => Time.now.strftime("%Y-%m-%d %H:%M:%S %z"), "author" => "DRAFT", "shorthash" => "-------", "hash" => "", "message" => "DRAFT"}]
        else
            logs.lines.map do |line|
              parts = line.split('|')
              {"date" => parts[0], "author" => parts[1], "shorthash" => parts[2], "hash" => parts[3], "message" => parts[4..-1].join('|')}
            end
        end
      end

      private
      
      def max_count
        config['max_count'] || 5
      end
      
      def is_git_repo?
        @@is_git_repo ||= begin
          Dir.chdir(site_source) do
            Executor.sh("git", "rev-parse", "--is-inside-work-tree").eql? "true"
          end
{'fraction_non_alphanumeric': 0.15711252653927812, 'fraction_numerical': 0.005762814680012132, 'mean_word_length': 2.208171206225681, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 18, 'https://': 2, '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': '6159315', 'n_tokens_mistral': 1105, 'n_tokens_neox': 1074, 'n_words': 221}