1234567891011121314151617181920212223 |
- #! /bin/bash
- source_file="$1"
- [[ ! -f "$source_file" ]] && echo "Usage: sgit-sha FILE
- Returns the sha1 value git associates with FILE." && exit 1
- # Every object header contains the object type
- # followed by the payload byte length terminated
- # with a null byte (\0).
- function header() {
- printf "blob $(wc -c $PWD/$source_file | awk '{print $1}')\0"
- }
- # A blob contains header + payload.
- function blob() {
- cat <(header) "$source_file"
- }
- blob | sha1sum | cut -f1 -d' '
|