Skip to content

Commit

Permalink
git-find-commits-by-file-hash.sh refactor
Browse files Browse the repository at this point in the history
  • Loading branch information
oh2fih committed Apr 8, 2024
1 parent fc6bf8c commit 2c9ee1a
Showing 1 changed file with 13 additions and 9 deletions.
22 changes: 13 additions & 9 deletions bin/git-find-commits-by-file-hash.sh
Original file line number Diff line number Diff line change
Expand Up @@ -68,18 +68,22 @@ cd "$(git rev-parse --show-toplevel)" \

# Search for the hash & show stats of matching commits

print_commit_and_checksum() {
while read -r commit; do
echo "${commit}:$(
git show "${commit}:${1}" 2> /dev/null \
| sha256sum \
| awk '{print $1}'
)"
done
}

matches=$(
git log --oneline --no-abbrev-commit --follow -- "$2" \
| awk '{print $1}' \
| while read -r commit; do
echo "$commit: $(
git show "$commit:$2" 2> /dev/null \
| sha256sum \
| awk '{print $1}'
)"
done \
| grep -E "[0-9a-f]*:\ $1"
)
| print_commit_and_checksum "$2" \
| grep -E "[0-9a-f]*:${1}"
)

if [[ "$matches" =~ [0-9a-f]+ ]]; then
echo "$matches" \
Expand Down

0 comments on commit 2c9ee1a

Please sign in to comment.