logo

shit

Unnamed repository; edit this file 'description' to name the repository. git clone https://hacktivis.me/git/mirror/shit.git

ls-files (1456B)


  1. #!/bin/sh -eu
  2. SHIT_PATH=$(dirname "$0")
  3. . $SHIT_PATH/common.sh
  4. index="$GIT_DIR"/index
  5. magic=$(od -An -tc -N4 "$index" | tr -d ' ')
  6. version=$(read_int32 "$index" 4)
  7. nentries=$(read_int32 "$index" 8)
  8. if [ "$magic" != "DIRC" ]
  9. then
  10. printf "Invalid git index format\n" >&2
  11. exit
  12. fi
  13. if [ $version -ne 2 ]
  14. then
  15. printf "Only git index version %d is supported, %d was found\n" \
  16. "$INDEX_VERSION" "$version" >&2
  17. exit 1
  18. fi
  19. offs=12
  20. while [ $nentries -gt 0 ]
  21. do
  22. # mode @ 24 bytes
  23. # sha @ 40 bytes
  24. # flags @ 60 bytes
  25. # name @ 62 bytes
  26. mode=$(read_int32 "$index" $((offs+24)))
  27. sha=$(read_hex "$index" $((offs+40)) 20)
  28. flags=$(read_int16 "$index" $((offs+60)))
  29. # 0bNNNNxxxMMMMMMMMM
  30. # NNNN -> object type
  31. # MMMMMMMMM -> unix file mode (644 or 755)
  32. case $(printf "%X" $((mode & 0xF000))) in
  33. 8000)
  34. objtype=file
  35. ;;
  36. A000)
  37. objtype=link
  38. ;;
  39. E000)
  40. objtype=gitlink
  41. ;;
  42. *)
  43. printf "Invalid object type %x\n" $(((mode & 0xF000) >> 12)) >&2
  44. exit 1
  45. ;;
  46. esac
  47. unixmode=$((mode & 0x1FF))
  48. if [ $unixmode -ne $((0644)) ] && [ $unixmode -ne $((0755)) ] && [ $unixmode -ne 0 ]
  49. then
  50. printf "Invalid file mode %o\n" $unixmode >&2
  51. exit 1
  52. fi
  53. pathlen=$((flags & 0xFFF))
  54. path="$(read_text "$index" $((offs+62)) $pathlen)"
  55. printf "%o %s %s\n" "$mode" "$sha" "$path"
  56. padding=$((${#path} + 1 + 62))
  57. padding=$((padding % 8))
  58. padding=$(((8 - padding) % 8))
  59. offs=$((offs+62+${#path}+1+padding))
  60. nentries=$((nentries-1))
  61. done