Skip to content

Instantly share code, notes, and snippets.

@eugeneia
Created March 22, 2016 23:13
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save eugeneia/7d34c270f8d1603c48f0 to your computer and use it in GitHub Desktop.
Save eugeneia/7d34c270f8d1603c48f0 to your computer and use it in GitHub Desktop.
#!/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