Created
October 25, 2022 17:21
-
-
Save tsibley/ee5046ccbe86e68d812535ddda3f714f 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
| #!/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