Created
October 24, 2017 20:37
-
-
Save KevinGreene/0ce9539c57923a406506ddfe72865c1a to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(ns gitfun.core | |
(:require [planck.shell :refer [sh]] | |
[clojure.string :refer [split-lines split]])) | |
(def relevant-regex #"changed, |^commit") | |
(def stat-regex #"(\d+) files? changed, (\d+) insert.+, (\d+) delet.+") | |
(def deletion-regex #"(\d+) files? changed, (\d+) delet") | |
(def insertion-regex #"(\d+) files? changed, (\d+) insertions?\(\+\)$") | |
(defn is-relevant [s] | |
(re-find relevant-regex s)) | |
(defn ->i [s] | |
(js/parseInt s)) | |
;; This function is bad and makes me feel bad | |
(defn change-line->counts [commit-line] | |
(if-let [[_ changed insertions] (re-find insertion-regex commit-line)] | |
{:changed (->i changed) :insertions (->i insertions) :deletions 0} | |
(if-let [[_ changed deletions] (re-find deletion-regex commit-line)] | |
{:changed (->i changed) :insertions 0 :deletions (->i deletions)} | |
(let [[_ changed i d] (re-find stat-regex commit-line)] | |
{:changed (->i changed) :insertions (->i i) :deletions (->i d)})))) | |
(defn partition->commit [[commit-line change-line]] | |
(let [commit-hash (second (split commit-line #"\s+")) | |
counts (change-line->counts change-line)] | |
(assoc counts :hash commit-hash))) | |
(defn add-diff [commit] | |
(let [diff (- (:insertions commit) (:deletions commit))] | |
(assoc commit :diff diff))) | |
(defn get-most-destructive [] | |
(->> (sh "git" "log" "--shortstat" "--no-merges") | |
:out | |
split-lines | |
(filter is-relevant) | |
(partition 2) | |
(map partition->commit) | |
(map add-diff) | |
(sort-by :diff) | |
first)) | |
(prn (get-most-destructive)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment