Skip to content

Instantly share code, notes, and snippets.

@tsibley
Created October 25, 2022 17:21
Show Gist options
  • Select an option

  • Save tsibley/ee5046ccbe86e68d812535ddda3f714f to your computer and use it in GitHub Desktop.

Select an option

Save tsibley/ee5046ccbe86e68d812535ddda3f714f to your computer and use it in GitHub Desktop.
#!/bin/bash
set -euo pipefail
main() {
merge-commits | branch-ttl
}
merge-commits() {
git log --first-parent --format="%h %at %s" | grep Merge
}
branch-ttl() {
local rows=0
while read -r merge merge_ts subject; do
if [[ $rows -eq 0 ]]; then
emit-header
fi
emit-row "$merge" "$(( merge_ts - "$(earliest-commit-timestamp "$merge")" ))" "$subject"
: $(( rows++ ))
done
echo "Found $rows merges" >&2
}
emit-header() {
emit-row merge_commit branch_ttl merge_subject
}
emit-row() {
printf '%s\t%s\t%s\n' "$1" "$2" "$3"
}
earliest-commit-timestamp() {
local merge="$1"
git log --format="%at" "$merge^2" "^$merge^1" | sort -n | head -n1
}
main "$@"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment