Last active
September 6, 2022 09:34
-
-
Save felipec/ed96a45615bb0058563243e06fe9eb5e to your computer and use it in GitHub Desktop.
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
#!/bin/bash | |
d=/tmp/git-test | |
git init -q -b master "$d" | |
cd "$d" || exit | |
for i in $(seq 1000); do | |
git commit -q -m commit --allow-empty | |
done | |
cd "$d" || exit | |
echo -e "\n# warm cache" | |
time git log > /dev/null | |
echo -e "\n# felipec" | |
git_log_branches_f() { | |
while read -r id; do | |
IFS=$'\n' read -r -d '' -a branches < <(git branch --format='%(refname:short)' --contains "$id") | |
git --no-pager show --format="commit %H%nAuthor: %an <%ae>%nDate: %ad%nBranches: ${branches[*]}%n%n%w(76,4,4)%B" --quiet "$id" | |
done < <(git log --format='%H' "$@") | |
} | |
time git_log_branches_f > /dev/null | |
time git_log_branches_f > /dev/null | |
time git_log_branches_f > /dev/null | |
echo -e "\n# felipec original" | |
git_log_branches_fo() { | |
while read -r -d $'\0' commit; do | |
id=${commit#commit } | |
id=${id%%$'\n'*} | |
IFS=$'\n' read -r -d '' -a branches < <(git branch --format='%(refname:short)' --contains "$id") | |
echo -e "${commit/BRANCHES/${branches[*]}}\n" | |
done < <(git log --format="tformat:commit %H%nAuthor: %an <%ae>%nDate: %ad%nBranches: BRANCHES%n%n%w(76,4,4)%B%w()%x00" "$@") | |
} | |
time git_log_branches_fo > /dev/null | |
time git_log_branches_fo > /dev/null | |
time git_log_branches_fo > /dev/null | |
echo -e "\n# kriegaex" | |
git_log_branches_k() { | |
git log --pretty=format:"commit %H%nAuthor: %an %ae%nDate: %ad%nBranches:%H%n%n%s%n%n%b%n" "$@" | | |
sed -E "s/^(Branches:)(.*)/echo -n '\1'; git branch --contains \2 --format=' %(refname:strip=2)' | tr '\n' ','/e" | |
} | |
time git_log_branches_k > /dev/null | |
time git_log_branches_k > /dev/null | |
time git_log_branches_k > /dev/null | |
echo -e "\n# kriegaex new" | |
git_log_branches_kn() { | |
git --no-pager log --quiet --pretty=format:"commit %H%nAuthor: %an <%ae>%nDate: %ad%nBranches: %H%n%n%w(76,4,4)%B" "$@" | while read -r LINE; do | |
if [ "${LINE:0:10}" = "Branches: " ]; then | |
echo "Branches: $(git branch --contains ${LINE:10} --format='%(refname:short)' | tr '\n' ' ')" | |
else | |
echo "$LINE" | |
fi | |
done | |
} | |
time git_log_branches_kn > /dev/null | |
time git_log_branches_kn > /dev/null | |
time git_log_branches_kn > /dev/null |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment