Last active
December 27, 2015 04:29
-
-
Save rtraschke/7266824 to your computer and use it in GitHub Desktop.
Make a color bar showing the age of lines in a file from git blame output.
This file contains 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
--[[ | |
Little script that expects to be fed the output of "git blame -t -p" | |
and will generate SVG image 50 px high with horizontal lines coloured | |
by the age of a line of code. See the accompanying shells script for | |
an example invocation. | |
The SVG will be the number of code lines wide (plus a border). | |
The brightness of a vertical line shows the age, white being just now, | |
black, the time the file was first created. | |
A Gamma exponent is used to make aging non-linear. | |
]] | |
local gamma = 1.8 | |
local now = os.time() | |
local oldest = now | |
local line_time | |
local lines = {} | |
local line = io.read("*l") | |
while line do | |
if line:match("^committer%-time") then | |
_, _, line_time = line:find("^committer%-time (%d+)") | |
line_time = tonumber(line_time) | |
if line_time < oldest then | |
oldest = line_time | |
end | |
elseif line:match("^"..("%x"):rep(40)) then | |
lines[#lines+1] = line_time | |
end | |
line = io.read("*l") | |
end | |
print(string.format("<svg xmlns='http://www.w3.org/2000/svg' version='1.1' height='50' width='%d'>", #lines+2)) | |
print("<line x1='0' y1='0' x2='0' y2='50' stroke='black' />") | |
print(string.format("<line x1='0' y1='0' x2='%d' y2='0' stroke='black' />", #lines+1)) | |
local percent, adjusted | |
for i, n in ipairs(lines) do | |
percent = (n - oldest) / (now - oldest) | |
adjusted = math.pow(percent, gamma) | |
print(string.format("<line x1='%d' y1='1' x2='%d' y2='49' stroke='hsl(25, 75%%, %d%%)' />", i, i, adjusted*100)) | |
end | |
print(string.format("<line x1='0' y1='50' x2='%d' y2='50' stroke='black' />", #lines+1)) | |
print(string.format("<line x1='%d' y1='0' x2='%d' y2='50' stroke='black' />", #lines+1, #lines+1)) | |
print("</svg>") |
This file contains 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
RUNNER_SCRIPT_DIR=$(cd ${0%/*} && pwd) | |
echo "<html>" | |
echo "<style>" | |
echo "table { border-collapse:collapse; }" | |
echo "table, th { border: 1px solid black; }" | |
echo "td { border: 0px; }" | |
echo "<style>" | |
echo "</style>" | |
echo "<body>" | |
echo "<table>" | |
for i in `git ls-files` | |
do | |
echo "<tr>" | |
echo "<th>" $i "</th>" | |
echo "<td>" | |
git blame -t -p $i | lua $RUNNER_SCRIPT_DIR/gitcolorage.lua | |
echo "</td>" | |
echo "</tr>" | |
done | |
echo "</table>" | |
echo "</body>" | |
echo "</html>" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment