~sircmpwn/shit

221772b8f451e4b2db9d7eabf0c86f7691728191 — Drew DeVault 9 months ago 308ffec
Remove excess mode parsing from ls-file, write-tree
3 files changed, 6 insertions(+), 19 deletions(-)

M commit-tree
M ls-files
M write-tree
M commit-tree => commit-tree +1 -1
@@ 11,7 11,7 @@ while getopts p: opt
do
	case $opt in
		p)
			parents="$(printf "$s" "$parents" | tr -s , ' ')"
			parents="$(printf "%s" "$OPTARG" | tr -s , ' ')"
			;;
		?)
			printf "Usage: %s [-p <parents...>]\n" "$0" >&2

M ls-files => ls-files +4 -4
@@ 50,17 50,17 @@ do
			exit 1
			;;
	esac
	mode=$((mode & 0x1FF))
	if [ $mode -ne $((0644)) ] && [ $mode -ne $((0755)) ] && [ $mode -ne 0 ]
	unixmode=$((mode & 0x1FF))
	if [ $unixmode -ne $((0644)) ] && [ $unixmode -ne $((0755)) ] && [ $unixmode -ne 0 ]
	then
		printf "Invalid file mode %o\n" $mode >&2
		printf "Invalid file mode %o\n" $unixmode >&2
		exit 1
	fi

	pathlen=$((flags & 0xFFF))
	path="$(read_text "$index" $((offs+62)) $pathlen)"

	printf "%s %o %s %s\n" "$objtype" "$mode" "$sha" "$path"
	printf "%o %s %s\n" "$mode" "$sha" "$path"

	padding=$((${#path} + 1 + 62))
	padding=$((padding % 8))

M write-tree => write-tree +1 -14
@@ 2,22 2,9 @@
SHIT_PATH=$(dirname "$0")
. $SHIT_PATH/common.sh

"$SHIT_PATH"/ls-files | while read -r type mode sha path
"$SHIT_PATH"/ls-files | while read -r mode sha path
do
	case $type in
		file)
			mode=100$mode
			;;
		link)
			mode=012$mode
			;;
		gitlink)
			printf "submodules are unimplemented\n" >&2
			exit 1
			;;
	esac
	# TODO: subtrees
	objtype=blob
	printf "%s %s\0" $mode "$path"
	write_hex "$sha"
done