sgit-sha 483 B

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