<commit_before>package git

import (
	"fmt"
	"io/ioutil"
	"os"
	"os/exec"
	"strconv"
)

// A HashDiff represents a single line in a git diff-index type output.
type HashDiff struct {
	Name     IndexPath
	Src, Dst TreeEntry
}

func (h HashDiff) String() string {
	var status string = "?"

	empty := Sha1{}
	if h.Src.Sha1 == empty && h.Dst.Sha1 != empty {
		status = "A"
	} else if h.Src.Sha1 != empty && h.Dst.Sha1 == empty {
		if h.Dst.FileMode == 0 {
			status = "D"
		} else {
			status = "M"
		}
	} else {
		status = "M"
	}
	return fmt.Sprintf(":%0.6o %0.6o %v %v %v	%v", h.Src.FileMode, h.Dst.FileMode, h.Src.Sha1, h.Dst.Sha1, status, h.Name)
}

// Returns a diff in the format of the command "diff". Note: this invokes
// an external diff tool. It should be rewritten in Go to avoid the overhead
// (and the possibility that diff isn't installed.)
func (h HashDiff) ExternalDiff(c *Client, s1, s2 TreeEntry, f File, opts DiffCommonOptions) (string, error) {
	tmpfile1, err := ioutil.TempFile("", "gitdiff")
	if err != nil {
		return "", err
	}
	//defer os.Remove(tmpfile1.Name())

	var emptySha Sha1
	if s1.Sha1 != emptySha {
		obj, err := c.GetObject(s1.Sha1)
		if err != nil {
			return "", err
		}
		tmpfile1.Write(obj.GetContent())
	}

	tmpfile1.Close()

	tmpfile2, err := ioutil.TempFile("", "gitdiff")
	if err != nil {
		return "", err<commit_msg>Don't leak temporary files when doing a git diff.<commit_after>package git

import (
	"fmt"
	"io/ioutil"
	"os"
	"os/exec"
	"strconv"
)

// A HashDiff represents a single line in a git diff-index type output.
type HashDiff struct {
	Name     IndexPath
	Src, Dst TreeEntry
}

func (h HashDiff) String() string {
	var status string = "?"

	empty := Sha1{}
	if h.Src.Sha1 == empty && h.Dst.Sha1 != empty {
		status = "A"
	} else if h.Src.Sha1 != empty && h.Dst.Sha1 == empty {
		if h.Dst.FileMode == 0 {
			status = "D"
		} else {
			status = "M"
		}
	} else {
		status = "M"
	}
	return fmt.Sprintf(":%0.6o %0.6o %v %v %v	%v", h.Src.FileMode, h.Dst.FileMode, h.Src.Sha1, h.Dst.Sha1, status, h.Name)
}

// Returns a diff in the format of the command "diff". Note: this invokes
// an external diff tool. It should be rewritten in Go to avoid the overhead
// (and the possibility that diff isn't installed.)
func (h HashDiff) ExternalDiff(c *Client, s1, s2 TreeEntry, f File, opts DiffCommonOptions) (string, error) {
	tmpfile1, err := ioutil.TempFile("", "gitdiff")
	if err != nil {
		return "", err
	}
	defer os.Remove(tmpfile1.Name())

	var emptySha Sha1
	if s1.Sha1 != emptySha {
		obj, err := c.GetObject(s1.Sha1)
		if err != nil {
			return "", err
		}
		tmpfile1.Write(obj.GetContent())
	}

	tmpfile1.Close()

	tmpfile2, err := ioutil.TempFile("", "gitdiff")
	if err != nil {
		return "", err
{'fraction_non_alphanumeric': 0.15418181818181817, 'fraction_numerical': 0.017454545454545455, 'mean_word_length': 3.168181818181818, 'pattern_counts': {'":': 2, '<': 3, '<?xml version=': 0, '>': 3, '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': '5782604', 'n_tokens_mistral': 1130, 'n_tokens_neox': 1080, 'n_words': 325}