<commit_before>import git_helper
import sublime
import subprocess
import tempfile
import re

class GitGutterHandler:
  def __init__(self, view):
    self.view = view
    self.git_temp_file = tempfile.NamedTemporaryFile()
    self.buf_temp_file = tempfile.NamedTemporaryFile()
    self.git_tree = git_helper.git_tree(self.view)
    self.git_dir  = git_helper.git_dir(self.git_tree)
    self.git_path = git_helper.git_file_path(self.view, self.git_tree)

  def reset(self):
    if self.git_path:
      self.view.run_command('git_gutter')

  def get_git_path(self):
    return self.git_path

  def update_buf_file(self):
    chars = self.view.size() 
    region = sublime.Region(0,chars)
    contents = self.view.substr(region).encode("utf-8")
    f = open(self.buf_temp_file.name,'w')
    f.write(contents)
    f.close()

  def update_git_file(self):
    self.git_temp_file.truncate()
    args = ['git','--git-dir='+self.git_dir,'--work-tree='+self.git_tree,'show','head:'+self.git_path]
    subprocess.call(args, stdout=self.git_temp_file, stderr=subprocess.STDOUT)

  def process_diff(self,diff_str):
    print diff_str

    inserted = []
    modified = []
    deleted  = []

    lines = diff_str.splitlines()
    for line in lines:
      m = re.match("(\d+),?(\d*)(.)(\d+),?(\d*)", line)
      if not m:
        continue
      kind = m.group(3)
      original_line_start = int(m.group(1))
      if len(m.group(2)) > 0:
        original_line_end = int(m.group(2))
      else:
        original_line_end = original_line_start
      line_start = int(m.group(4))
      if len(m.group(5)) > 0:
        line_end = int(m.group(5))
      else:
        line_end = line_start

      print 'kind: '+kind

      if kind == 'c':
        modified += range(line_start,line_end+1) + [line_start]
      elif kind == 'a':
        inserted += range(line_start,line_end+1) + [line_start]
      elif kind == 'd':
        deleted.append(line_start+1)

    print inserted
    print modified
    print deleted

    return (inserted, modified, deleted)

  def diff(self):
    if self.git_path:
      self.update_git_file()
      self.update_buf_file()

      args = ['diff',self.git_temp_file.name,self.buf_temp_file.name]
      proc = subprocess.Popen(args, stdout=subprocess.PIPE, stderr=subprocess.STDOUT)
      results = proc.stdout.read()

      return self.process_diff(results)<commit_msg>This part is no longer needed<commit_after>import git_helper
import sublime
import subprocess
import tempfile
import re

class GitGutterHandler:
  def __init__(self, view):
    self.view = view
    self.git_temp_file = tempfile.NamedTemporaryFile()
    self.buf_temp_file = tempfile.NamedTemporaryFile()
    self.git_tree = git_helper.git_tree(self.view)
    self.git_dir  = git_helper.git_dir(self.git_tree)
    self.git_path = git_helper.git_file_path(self.view, self.git_tree)

  def reset(self):
    if self.git_path:
      self.view.run_command('git_gutter')

  def get_git_path(self):
    return self.git_path

  def update_buf_file(self):
    chars = self.view.size() 
    region = sublime.Region(0,chars)
    contents = self.view.substr(region).encode("utf-8")
    f = open(self.buf_temp_file.name,'w')
    f.write(contents)
    f.close()

  def update_git_file(self):
    self.git_temp_file.truncate()
    args = ['git','--git-dir='+self.git_dir,'--work-tree='+self.git_tree,'show','head:'+self.git_path]
    subprocess.call(args, stdout=self.git_temp_file, stderr=subprocess.STDOUT)

  def process_diff(self,diff_str):
    print diff_str

    inserted = []
    modified = []
    deleted  = []

    lines = diff_str.splitlines()
    for line in lines:
      m = re.match("(\d+),?(\d*)(.)(\d+),?(\d*)", line)
      if not m:
        continue
      kind = m.group(3)
      original_line_start = int(m.group(1))
      if len(m.group(2)) > 0:
        original_line_end = int(m.group(2))
      else:
        original_line_end = original_line_start
      line_start = int(m.group(4))
      if len(m.group(5)) > 0:
        line_end = int(m.group(5))
      else:
        line_end = line_start

      print 'kind: '+kind

      if kind == 'c':
        modified += range(line_start,line_end+1)
      elif kind == 'a':
        inserted += range(line_start,line_end+1)
      elif kind == 'd':
        deleted.append(line_start+1)

    print inserted
    print modified
    print deleted

    return (inserted, modified, deleted)

  def diff(self):
    if self.git_path:
      self.update_git_file()
      self.update_buf_file()

      args = ['diff',self.git_temp_file.name,self.buf_temp_file.name]
      proc = subprocess.Popen(args, stdout=subprocess.PIPE, stderr=subprocess.STDOUT)
      results = proc.stdout.read()

      return self.process_diff(results)
{'fraction_non_alphanumeric': 0.13451776649746192, 'fraction_numerical': 0.005922165820642978, 'mean_word_length': 3.0627147766323026, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 7, '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': '4293784', 'n_tokens_mistral': 1706, 'n_tokens_neox': 1664, 'n_words': 290}