<commit_before>require 'GitDiffBuilder'
require 'GitDiffParser'
require 'Files'

module GitDiff

  # Top level function used by diff_controller.rb to create data structure
  # (to build view from) containing diffs for all files, for a given avatar, 
  # for a given tag.
  # See, test/functional/git_diff_view_tests.rb
  
  def git_diff_view(avatar, tag, visible_files = nil)
      builder = GitDiffBuilder.new()

      visible_files ||= avatar.visible_files(tag)      

      cmd  = "cd #{avatar.dir};"
      cmd += "git diff --ignore-space-at-eol --find-copies-harder #{tag-1} #{tag} sandbox;"   
      diff_lines = Files::popen_read(cmd)
  
      view = { }      
      diffs = GitDiffParser.new(diff_lines).parse_all           
      diffs.each do |sandbox_name,diff|        
        md = %r|^(.)/sandbox/(.*)|.match(sandbox_name)
        if !deleted_file?(md[1])
          name = md[2]
          file_content = visible_files[name]
          view[name] = builder.build(diff, line_split(file_content))
          visible_files.delete(name)
        end
      end

      # other files have not changed...      
      visible_files.each do |filename,content|
        view[filename] = sameify(content)
      end
      
      view
  end

  #-----------------------------------------------------------
  
  def deleted_file?(ch)
    # GitDiffParser uses names beginning with
    # a/... to indicate a deleted file 
    # b/... to indicate a new/modified file
    # This mirrors the git diff command output
    ch == 'a'
  end
  
  #-----------------------------------------------------------  
  
  def git_diff_prepare(diffed_files)
    n = 0
    diffs = [ ]
    diffed_files.sort.each do |name,diff|
      id = 'jj' + n
      n += 1
      diffs << {
        :deleted_line_count => diff.count { |line| line[:type] == :deleted },
        :id => id,          
        :name => name,
        :added_line_count => diff.count { |line| line[:type] == :added },
        :content => git_diff_html(diff),
      }
    end<commit_msg>diff-view fault fixed<commit_after>require 'GitDiffBuilder'
require 'GitDiffParser'
require 'Files'

module GitDiff

  # Top level function used by diff_controller.rb to create data structure
  # (to build view from) containing diffs for all files, for a given avatar, 
  # for a given tag.
  # See, test/functional/git_diff_view_tests.rb
  
  def git_diff_view(avatar, tag, visible_files = nil)
      builder = GitDiffBuilder.new()

      visible_files ||= avatar.visible_files(tag)      

      cmd  = "cd #{avatar.dir};"
      cmd += "git diff --ignore-space-at-eol --find-copies-harder #{tag-1} #{tag} sandbox;"   
      diff_lines = Files::popen_read(cmd)
  
      view = { }      
      diffs = GitDiffParser.new(diff_lines).parse_all           
      diffs.each do |sandbox_name,diff|        
        md = %r|^(.)/sandbox/(.*)|.match(sandbox_name)
        if !deleted_file?(md[1])
          name = md[2]
          file_content = visible_files[name]
          view[name] = builder.build(diff, line_split(file_content))
          visible_files.delete(name)
        end
      end

      # other files have not changed...      
      visible_files.each do |filename,content|
        view[filename] = sameify(content)
      end
      
      view
  end

  #-----------------------------------------------------------
  
  def deleted_file?(ch)
    # GitDiffParser uses names beginning with
    # a/... to indicate a deleted file 
    # b/... to indicate a new/modified file
    # This mirrors the git diff command output
    ch == 'a'
  end
  
  #-----------------------------------------------------------  
  
  def git_diff_prepare(diffed_files)
    n = 0
    diffs = [ ]
    diffed_files.sort.each do |name,diff|
      n += 1
      id = 'jj' + n.to_s
      diffs << {
        :deleted_line_count => diff.count { |line| line[:type] == :deleted },
        :id => id,          
        :name => name,
        :added_line_count => diff.count { |line| line[:type] == :added },
        :content => git_diff_html(diff),
      }
    end
{'fraction_non_alphanumeric': 0.1697508018751542, 'fraction_numerical': 0.002467308166790032, 'mean_word_length': 1.8172341904100069, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 13, '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': '5658029', 'n_tokens_mistral': 1271, 'n_tokens_neox': 1242, 'n_words': 305}