<commit_before><commit_msg>Adding git_churn() and sorted functions for git command line use<commit_after>#!/bin/bash

##
# Sum file and line modifications for all files from within a git project. 
# Basic results are provided via: 
#
# 'git log --stat'
#
# Additional arguments may be passed in via the command line similar
# to calling 'git log' directly. For example
# 
# 'git_file_churn --after="2014-06-21"'
# 'git_file_churn --after="2014-06-21 --author=dmillett'      
#
git_churn() {

  gitArguments=($@)
  git log --stat "${gitArguments[@]}" | grep -v -E "^[commit\|Author\|Date]" | grep \| | awk '{
    Mods[$1]++; 
    LineMods[$1] += $3;
    modLength = length($4) + 1;

    if ( index($4, "+") )
      Growth[$1] = modLength - index($4, "-");

     if ( index($4, "-") )
       Shrink[$1] = modLength - Growth[$1];
  }
  END {
    del="|"
    for (f in Mods)
      print del, Mods[f], del, LineMods[f], del, f, del, Growth[f], del, Shrink[f], del
  }'
}

#
# Sort file modification count ascending
git_file_churn_sorted() {
  git_churn $@ | sort -n --key=2
}

git_line_churn_sorted() {
  git_churn $@ | sort -n --key=4
  #echo ""
}
{'fraction_non_alphanumeric': 0.17935258092738407, 'fraction_numerical': 0.02537182852143482, 'mean_word_length': 3.1449275362318843, 'pattern_counts': {'":': 0, '<': 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': '5057457', 'n_tokens_mistral': 449, 'n_tokens_neox': 419, 'n_words': 116}