<commit_before>java_import org.geogit.api.porcelain.LogOp

module GeoGit
  module Command
    class Log < GenericCommand
      def initialize(repo_path, path = '', offset = 0, limit = 0)
        @repo_path = repo_path
        @path = path
        @offset = offset
        @limit = limit
      end

      def run
        geogit = GeoGit::Instance.new(@repo_path).instance
        command = geogit.command(LogOp.java_class)

        command.add_path @path unless @path.empty?

        rev_commits = command.call
        count = rev_commits.count

        commits = command.call
        
        if @offset >= 0 && @limit > 0
          unless @offset * @limit >= count
            commits = commits.drop(@offset * @limit).take(@limit)
          end
        end

        {count: count, commits: prepare_output(commits.to_a)}
      ensure
        geogit.close
      end

      private
      def prepare_output(commits)
        commits.to_a.map { |c|
          {
            id: c.id.to_s,
            message: c.message,
            author: {
              name: c.author.name.isPresent ? c.author.name.get : '',
              email: c.author.email.isPresent ? c.author.email.get : ''
            },
            committer: {
              name: c.committer.name.isPresent ? c.committer.name.get : '',
              email: c.committer.name.isPresent ? c.committer.email.get : ''
            }
          }
        }
      end
    end
  end
end
<commit_msg>Fix error in log offset/limit logic<commit_after>java_import org.geogit.api.porcelain.LogOp

module GeoGit
  module Command
    class Log < GenericCommand
      def initialize(repo_path, path = '', offset = 0, limit = 0)
        @repo_path = repo_path
        @path = path
        @offset = offset
        @limit = limit
      end

      def run
        geogit = GeoGit::Instance.new(@repo_path).instance
        command = geogit.command(LogOp.java_class)

        command.add_path @path unless @path.empty?

        rev_commits = command.call
        count = rev_commits.count

        commits = command.call
        
        if @limit > 0
          unless @offset >= count
            commits = commits.drop(@offset).take(@limit)
          else
            commits = []
          end
        end

        {count: count, commits: prepare_output(commits.to_a)}
      ensure
        geogit.close
      end

      private
      def prepare_output(commits)
        commits.map { |c|
          {
            id: c.id.to_s,
            message: c.message,
            author: {
              name: c.author.name.isPresent ? c.author.name.get : '',
              email: c.author.email.isPresent ? c.author.email.get : ''
            },
            committer: {
              name: c.committer.name.isPresent ? c.committer.name.get : '',
              email: c.committer.name.isPresent ? c.committer.email.get : ''
            }
          }
        }
      end
    end
  end
end

{'fraction_non_alphanumeric': 0.10201985621362547, 'fraction_numerical': 0.002396439575487847, 'mean_word_length': 1.5541958041958042, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 8, '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': '6480981', 'n_tokens_mistral': 897, 'n_tokens_neox': 865, 'n_words': 181}