<commit_before>module Vim
  module Flavor
    class Flavor
      # A short name of a repository.
      # Possible formats are "$user/$repo", "$repo" and "$repo_uri".
      attr_accessor :repo_name

      # A constraint to choose a proper version.
      attr_accessor :version_constraint

      # A version of a plugin to be installed.
      attr_accessor :locked_version

      # Return true if this flavor's repository is already cloned.
      def cached?
        Dir.exists?(cached_repo_path)
      end

      def cached_repo_path
        @cached_repo_path ||=
          "#{ENV['HOME'].to_vimfiles_path}/repos/#{@repo_name.zap}"
      end

      def repo_uri
        @repo_uri ||=
          if /^([^\/]+)$/.match(repo_name)
            m = Regexp.last_match
            "git://github.com/vim-scripts/#{m[1]}.git"
          elsif /^([A-Za-z0-9_-]+)\/(.*)$/.match(repo_name)
            m = Regexp.last_match
            "git://github.com/#{m[1]}/#{m[2]}.git"
          elsif /^[a-z]+:\/\/.*$/.match(repo_name)
            repo_name
          else
            raise "Invalid repo_name: #{repo_name.inspect}"
          end
      end

      def clone()
        sh %Q[
          {
            git clone '#{repo_uri}' '#{cached_repo_path}'
          } 2>&1
        ]
        true
      end

      def deploy(vimfiles_path)
        deployment_path = "#{vimfiles_path.to_flavors_path}/#{repo_name.zap}"
        sh %Q[
          {
            cd '#{cached_repo_path}' &&
            git checkout -f '#{locked_version}' &&
            git checkout-index -a -f --prefix='#{deployment_path}/' &&
            {
              vim -u NONE -i NONE -n -N -e -s -c '
                silent! helptags #{deployment_path}/doc
                qall!
              ' || true
            }
          } 2>&1
        ]
        true
      end

      def use_appropriate_version()
        @locked_version =
          version_constraint.find_the_best_version(list_versions)
      end

      def list_versions()
        tags = sh %Q[
          {
            cd '#{cached_repo_path}' &&
            git tag
          } 2>&1
        ]

        tags.
          split(/[\r\n]/).
          select {|t| t != '' && Gem::Version.correct?(t)}.
          map {|t| Gem::Version.create(t)}
      end

      def sh script
        output = send(:`, script)
        if $? == 0
          output<commit_msg>Define Flavor#use_specific_version<commit_after>module Vim
  module Flavor
    class Flavor
      # A short name of a repository.
      # Possible formats are "$user/$repo", "$repo" and "$repo_uri".
      attr_accessor :repo_name

      # A constraint to choose a proper version.
      attr_accessor :version_constraint

      # A version of a plugin to be installed.
      attr_accessor :locked_version

      # Return true if this flavor's repository is already cloned.
      def cached?
        Dir.exists?(cached_repo_path)
      end

      def cached_repo_path
        @cached_repo_path ||=
          "#{ENV['HOME'].to_vimfiles_path}/repos/#{@repo_name.zap}"
      end

      def repo_uri
        @repo_uri ||=
          if /^([^\/]+)$/.match(repo_name)
            m = Regexp.last_match
            "git://github.com/vim-scripts/#{m[1]}.git"
          elsif /^([A-Za-z0-9_-]+)\/(.*)$/.match(repo_name)
            m = Regexp.last_match
            "git://github.com/#{m[1]}/#{m[2]}.git"
          elsif /^[a-z]+:\/\/.*$/.match(repo_name)
            repo_name
          else
            raise "Invalid repo_name: #{repo_name.inspect}"
          end
      end

      def clone()
        sh %Q[
          {
            git clone '#{repo_uri}' '#{cached_repo_path}'
          } 2>&1
        ]
        true
      end

      def deploy(vimfiles_path)
        deployment_path = "#{vimfiles_path.to_flavors_path}/#{repo_name.zap}"
        sh %Q[
          {
            cd '#{cached_repo_path}' &&
            git checkout -f '#{locked_version}' &&
            git checkout-index -a -f --prefix='#{deployment_path}/' &&
            {
              vim -u NONE -i NONE -n -N -e -s -c '
                silent! helptags #{deployment_path}/doc
                qall!
              ' || true
            }
          } 2>&1
        ]
        true
      end

      def use_appropriate_version()
        @locked_version =
          version_constraint.find_the_best_version(list_versions)
      end

      def use_specific_version(locked_version)
        @locked_version = locked_version
      end

      def list_versions()
        tags = sh %Q[
          {
            cd '#{cached_repo_path}' &&
            git tag
          } 2>&1
        ]

        tags.
          split(/[\r\n]/).
          select {|t| t != '' && Gem::Version.correct?(t)}.
          map {|t| Gem::Version.create(t)}
      end

      def sh script
        output = send(:`, script)
        if $? == 0
          output
{'fraction_non_alphanumeric': 0.13197026022304834, 'fraction_numerical': 0.004956629491945477, 'mean_word_length': 1.49510561566203, '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': '4705380', 'n_tokens_mistral': 1553, 'n_tokens_neox': 1504, 'n_words': 327}