Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
#!/bin/bash
set -euo pipefail
commit=$1
parent=$1^1
function commit_path_sha512 {
git cat-file blob $(git rev-parse $1:$2) | sha512sum | cut -d " " -f 1
}
function diff_path { echo ${1:6}; }
function diff_a { expr match "$1" '^--- a/' >/dev/null; }
function diff_b { expr match "$1" '^+++ b/' >/dev/null; }
function v_improve {
while read line; do
if diff_a "$line"; then
local path=$(diff_path "$line")
local sha512=$(commit_path_sha512 "$parent" "$path")
echo "$line $sha512"
elif diff_b "$line"; then
local path=$(diff_path "$line")
local sha512=$(commit_path_sha512 "$commit" "$path")
echo "$line $sha512"
else
echo "$line"
fi
done
}
git diff $parent..$commit | v_improve
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.