From 6d386c6cfe3d04a3188b9d05b7656ffec2a8f51f Mon Sep 17 00:00:00 2001 From: Luke Shumaker Date: Mon, 14 Mar 2016 22:26:05 -0400 Subject: fixity fix --- modules/blobs/Makefile.inc.mk | 4 ++-- modules/blobs/_shlib.sh.m4 | 6 +++--- modules/blobs/commit.d.sh | 45 --------------------------------------- modules/blobs/commit.f.sh | 49 ------------------------------------------- modules/blobs/commit.l.sh | 34 ------------------------------ modules/blobs/commit.sh | 48 ------------------------------------------ modules/blobs/get.f.sh | 4 ++-- modules/blobs/put.d.sh | 45 +++++++++++++++++++++++++++++++++++++++ modules/blobs/put.f.sh | 49 +++++++++++++++++++++++++++++++++++++++++++ modules/blobs/put.l.sh | 34 ++++++++++++++++++++++++++++++ modules/blobs/put.sh | 48 ++++++++++++++++++++++++++++++++++++++++++ modules/blobs/tree.sh | 27 ++++++++++++++---------- wrapper/inner.sh.m4 | 25 +++++++++++++++++----- wrapper/runcmd.mk | 2 +- 14 files changed, 220 insertions(+), 200 deletions(-) delete mode 100644 modules/blobs/commit.d.sh delete mode 100644 modules/blobs/commit.f.sh delete mode 100644 modules/blobs/commit.l.sh delete mode 100644 modules/blobs/commit.sh create mode 100644 modules/blobs/put.d.sh create mode 100644 modules/blobs/put.f.sh create mode 100644 modules/blobs/put.l.sh create mode 100644 modules/blobs/put.sh diff --git a/modules/blobs/Makefile.inc.mk b/modules/blobs/Makefile.inc.mk index 484da13..2f91acd 100644 --- a/modules/blobs/Makefile.inc.mk +++ b/modules/blobs/Makefile.inc.mk @@ -1,5 +1,5 @@ -am_src_files += commit.d.sh commit.f.sh commit.l.sh commit.sh get.d.sh get.f.sh get.l.sh get.sh tree.sh init.sh -am_out_files += commit.d commit.f commit.l commit get.d get.f get.l.sh get tree init +am_src_files += put.d.sh put.f.sh put.l.sh put.sh get.d.sh get.f.sh get.l.sh get.sh tree.sh init.sh +am_out_files += put.d put.f put.l put get.d get.f get.l.sh get tree init am_src_files += _shlib.sh.m4 am_clean_files += _shlib.sh diff --git a/modules/blobs/_shlib.sh.m4 b/modules/blobs/_shlib.sh.m4 index 567486f..b58a20d 100644 --- a/modules/blobs/_shlib.sh.m4 +++ b/modules/blobs/_shlib.sh.m4 @@ -35,13 +35,13 @@ usage() { local form local pfix1="$(_ 'Usage:')" local pfix2="$(_ ' Or:')" - local pfix="pfix1" + local pfix="$pfix1" for form in "${usage[@]}"; do - printf '%s %q %q %s\n' "$pfix" "$RVS" "$form" + printf '%s %q %q %s\n' "$pfix" "$RVS" "${0##*/}" "$form" pfix="$pfix2" done - printf '%s\n' "$(_ "$desc")" if [[ -n "$doc" ]] && [[ "$volume" != '-q' ]]; then + printf '%s\n' "$(_ "$desc")" printf '\n\n%s\n' "$(_ "$doc")" fi } diff --git a/modules/blobs/commit.d.sh b/modules/blobs/commit.d.sh deleted file mode 100644 index 458f98e..0000000 --- a/modules/blobs/commit.d.sh +++ /dev/null @@ -1,45 +0,0 @@ -#!/usr/bin/env bash -name=blobs/commit.d -desc='Add a directory to the repository' -copyright=('2009-2010, 2015-2016 Luke Shumaker') -license='AGPLv3+' -# This file is part of rvs. -# -# This program is free software: you can redistribute it and/or modify -# it under the terms of the GNU Affero General Public License as published by -# the Free Software Foundation, either version 3 of the License, or -# (at your option) any later version. -# -# This program is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -# GNU Affero General Public License for more details. -# -# You should have received a copy of the GNU Affero General Public License -# along with this program. If not, see . - -usage=('DIRECTORY') -. "${0%/*}/_shlib.sh" - -main() { - [[ $# -eq 1 ]] || errusage - dir="$1" - - tmpfile="$(mktemp -t "${0##*/}.XXXXXXXXXX")" - trap 'rm -f -- "$tmpfile"' EXIT - ( - cd "$dir" - shopt -s dotglob nullglob - for file in *; do - if [[ "$RVS_REPO" -ef "$file" ]]; then - continue - fi - id="$("$RVS" commit "$file" 2>/dev/null)" - stat -c $'%a\t%u (%U)\t%g (%G)\t' -- "$file" - printf $'%s\t%s\n' "$id" "$file" - done > "$tmpfile" - ) - "$RVS" commit.f "$tmpfile" 'd' -} - -main "$@" diff --git a/modules/blobs/commit.f.sh b/modules/blobs/commit.f.sh deleted file mode 100644 index 233f7bb..0000000 --- a/modules/blobs/commit.f.sh +++ /dev/null @@ -1,49 +0,0 @@ -#!/usr/bin/env bash -name=blobs/commit.f -desc='Add a plain file to the repository' -copyright=('2009-2010, 2015-2016 Luke Shumaker') -license='AGPLv3+' -# This file is part of rvs. -# -# This program is free software: you can redistribute it and/or modify -# it under the terms of the GNU Affero General Public License as published by -# the Free Software Foundation, either version 3 of the License, or -# (at your option) any later version. -# -# This program is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -# GNU Affero General Public License for more details. -# -# You should have received a copy of the GNU Affero General Public License -# along with this program. If not, see . - -usage='FILENAME [TYPE]' -doc="Note that FILENAME must be a regular file; character devices such as -/dev/stdin or /dev/fd/n won't work." - -. "${0%/*}/_shlib.sh" - -main() { - case $# in - 0) errusage;; - 1) infile=$1; type=f;; - 2) infile=$1; type=$2;; - *) errusage;; - esac - - if ! [[ -f "$infile" ]]; then - error 'Not a regular file: %s' "$infile" - fi - - hash="$(<"$infile" sha1sum | cut -d ' ' -f1)" - outfile="$RVS_REPO/blobs/$hash" - if [ ! -f "$outfile" ]; then - mkdir -p -- "${outfile%/*}" - < "$infile" gzip -9 > "$outfile.tmp" - mv -T -- "$outfile.tmp" "$outfile" - fi - printf '%s:%s\n' "$type" "$hash" -} - -main "$@" diff --git a/modules/blobs/commit.l.sh b/modules/blobs/commit.l.sh deleted file mode 100644 index 54a2527..0000000 --- a/modules/blobs/commit.l.sh +++ /dev/null @@ -1,34 +0,0 @@ -#!/usr/bin/env bash -name=blobs/commit.l -desc='Add a symbolic link to the repository' -copyright=('2016 Luke Shumaker') -license='AGPLv3+' -# This file is part of rvs. -# -# This program is free software: you can redistribute it and/or modify -# it under the terms of the GNU Affero General Public License as published by -# the Free Software Foundation, either version 3 of the License, or -# (at your option) any later version. -# -# This program is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -# GNU Affero General Public License for more details. -# -# You should have received a copy of the GNU Affero General Public License -# along with this program. If not, see . - -usage=('DIRECTORY') -. "${0%/*}/_shlib.sh" - -main() { - [[ $# -eq 1 ]] || errusage - link="$1" - - tmpfile="$(mktemp -t "${0##*/}.XXXXXXXXXX")" - trap 'rm -f -- "$tmpfile"' EXIT - readlink -n -- "$link" > "$tmpfile" - "$RVS" commit.f "$tmpfile" 'l' -} - -main "$@" diff --git a/modules/blobs/commit.sh b/modules/blobs/commit.sh deleted file mode 100644 index 44a2465..0000000 --- a/modules/blobs/commit.sh +++ /dev/null @@ -1,48 +0,0 @@ -#!/usr/bin/env bash -name=blobs/commit -desc='Add files to the repository' -copyright=('2009-2010, 2015-2016 Luke Shumaker') -license='AGPLv3+' -# This file is part of rvs. -# -# This program is free software: you can redistribute it and/or modify -# it under the terms of the GNU Affero General Public License as published by -# the Free Software Foundation, either version 3 of the License, or -# (at your option) any later version. -# -# This program is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -# GNU Affero General Public License for more details. -# -# You should have received a copy of the GNU Affero General Public License -# along with this program. If not, see . - -usage=('[FILES...]') -. "${0%/*}/_shlib.sh" - -main() { - if [[ $# -lt 1 ]]; then - set -- . - fi - - for file in "$@"; do - if ! stat -c '' -- "$file" &>/dev/null; then - error 'No such file or directory: %s' "$file" - fi - - local type - if test -L "$file"; then - type=l - elif test -f "$file"; then - type=f - elif test -d "$file"; then - type=d - else - error 'File has unsupported file type: %s' "$file" - fi - "$RVS" "commit.$type" "$file" - done -} - -main "$@" diff --git a/modules/blobs/get.f.sh b/modules/blobs/get.f.sh index fafb076..7cc49c6 100644 --- a/modules/blobs/get.f.sh +++ b/modules/blobs/get.f.sh @@ -19,7 +19,7 @@ license='AGPLv3+' # along with this program. If not, see . usage="ID FILENAME" -doc="Unlike commit.f, FILENAME may be a character device such as +doc="Unlike put.f, FILENAME may be a character device such as /dev/stdout or /dev/fd/n." . "${0%/*}/_shlib.sh" @@ -29,7 +29,7 @@ main() { name=$2 mkdir -p -- "$(dirname -- "$name")" - < "$REPO/blobs/${id#*:}" gunzip > "$name" + < "$RVS_REPO/blobs/${id#*:}" gunzip > "$name" } main "$@" diff --git a/modules/blobs/put.d.sh b/modules/blobs/put.d.sh new file mode 100644 index 0000000..afd5e7d --- /dev/null +++ b/modules/blobs/put.d.sh @@ -0,0 +1,45 @@ +#!/usr/bin/env bash +name=blobs/put.d +desc='Put a directory into the repository' +copyright=('2009-2010, 2015-2016 Luke Shumaker') +license='AGPLv3+' +# This file is part of rvs. +# +# This program is free software: you can redistribute it and/or modify +# it under the terms of the GNU Affero General Public License as published by +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU Affero General Public License for more details. +# +# You should have received a copy of the GNU Affero General Public License +# along with this program. If not, see . + +usage=('DIRECTORY') +. "${0%/*}/_shlib.sh" + +main() { + [[ $# -eq 1 ]] || errusage + dir="$1" + + tmpfile="$(mktemp -t "${0##*/}.XXXXXXXXXX")" + trap 'rm -f -- "$tmpfile"' EXIT + ( + cd "$dir" + shopt -s dotglob nullglob + for file in *; do + if [[ "$RVS_REPO" -ef "$file" ]]; then + continue + fi + id="$("$RVS" blobs/put "$file")" + stat --printf $'%a\t%u (%U)\t%g (%G)\t' -- "$file" + printf $'%s\t%s\n' "$id" "$file" + done > "$tmpfile" + ) + "$RVS" blobs/put.f "$tmpfile" 'd' +} + +main "$@" diff --git a/modules/blobs/put.f.sh b/modules/blobs/put.f.sh new file mode 100644 index 0000000..01b421a --- /dev/null +++ b/modules/blobs/put.f.sh @@ -0,0 +1,49 @@ +#!/usr/bin/env bash +name=blobs/put.f +desc='Put a plain file into the repository' +copyright=('2009-2010, 2015-2016 Luke Shumaker') +license='AGPLv3+' +# This file is part of rvs. +# +# This program is free software: you can redistribute it and/or modify +# it under the terms of the GNU Affero General Public License as published by +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU Affero General Public License for more details. +# +# You should have received a copy of the GNU Affero General Public License +# along with this program. If not, see . + +usage='FILENAME [TYPE]' +doc="Note that FILENAME must be a regular file; character devices such as +/dev/stdin or /dev/fd/n won't work." + +. "${0%/*}/_shlib.sh" + +main() { + case $# in + 0) errusage;; + 1) infile=$1; type=f;; + 2) infile=$1; type=$2;; + *) errusage;; + esac + + if ! [[ -f "$infile" ]]; then + error 'Not a regular file: %s' "$infile" + fi + + hash="$(<"$infile" sha1sum | cut -d ' ' -f1)" + outfile="$RVS_REPO/blobs/$hash" + if [ ! -f "$outfile" ]; then + mkdir -p -- "${outfile%/*}" + < "$infile" gzip -9 > "$outfile.tmp" + mv -T -- "$outfile.tmp" "$outfile" + fi + printf '%s:%s\n' "$type" "$hash" +} + +main "$@" diff --git a/modules/blobs/put.l.sh b/modules/blobs/put.l.sh new file mode 100644 index 0000000..b3bc7e3 --- /dev/null +++ b/modules/blobs/put.l.sh @@ -0,0 +1,34 @@ +#!/usr/bin/env bash +name=blobs/put.l +desc='Put a symbolic link into the repository' +copyright=('2016 Luke Shumaker') +license='AGPLv3+' +# This file is part of rvs. +# +# This program is free software: you can redistribute it and/or modify +# it under the terms of the GNU Affero General Public License as published by +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU Affero General Public License for more details. +# +# You should have received a copy of the GNU Affero General Public License +# along with this program. If not, see . + +usage=('DIRECTORY') +. "${0%/*}/_shlib.sh" + +main() { + [[ $# -eq 1 ]] || errusage + link="$1" + + tmpfile="$(mktemp -t "${0##*/}.XXXXXXXXXX")" + trap 'rm -f -- "$tmpfile"' EXIT + readlink -n -- "$link" > "$tmpfile" + "$RVS" blobs/put.f "$tmpfile" 'l' +} + +main "$@" diff --git a/modules/blobs/put.sh b/modules/blobs/put.sh new file mode 100644 index 0000000..c92f161 --- /dev/null +++ b/modules/blobs/put.sh @@ -0,0 +1,48 @@ +#!/usr/bin/env bash +name=blobs/put +desc='Put files into the repository' +copyright=('2009-2010, 2015-2016 Luke Shumaker') +license='AGPLv3+' +# This file is part of rvs. +# +# This program is free software: you can redistribute it and/or modify +# it under the terms of the GNU Affero General Public License as published by +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU Affero General Public License for more details. +# +# You should have received a copy of the GNU Affero General Public License +# along with this program. If not, see . + +usage=('[FILES...]') +. "${0%/*}/_shlib.sh" + +main() { + if [[ $# -lt 1 ]]; then + set -- . + fi + + for file in "$@"; do + if ! stat -c '' -- "$file" &>/dev/null; then + error 'No such file or directory: %s' "$file" + fi + + local type + if test -L "$file"; then + type=l + elif test -f "$file"; then + type=f + elif test -d "$file"; then + type=d + else + error 'File has unsupported file type: %s' "$file" + fi + "$RVS" "blobs/put.$type" "$file" + done +} + +main "$@" diff --git a/modules/blobs/tree.sh b/modules/blobs/tree.sh index f08db42..3953219 100644 --- a/modules/blobs/tree.sh +++ b/modules/blobs/tree.sh @@ -25,10 +25,10 @@ main() { local id name prefix has_prefix last case $# in 0) errusage;; - 1) id=$1; name=.;; - 2) id=$1; name=$2;; prefix=''; has_prefix=false;; - 3) id=$1; name=$2;; prefix=$3; has_prefix=true;; - 3) id=$1; name=$2;; prefix=$3; has_prefix=true; last=$4;; + 1) id=$1; name=. ; prefix=''; has_prefix=false; last='';; + 2) id=$1; name=$2; prefix=''; has_prefix=false; last='';; + 3) id=$1; name=$2; prefix=$3; has_prefix=true ; last='';; + 4) id=$1; name=$2; prefix=$3; has_prefix=true ; last=$4;; *) errusage;; esac @@ -37,10 +37,12 @@ main() { a='├── ' b='│   ' c='└── ' + d='    ' else a='|-- ' b='| ' c='`-- ' + d=' ' fi local pfix_self pfix_chld @@ -48,25 +50,28 @@ main() { pfix_self='' pfix_chld='' else - pfix_self="$prefix$a" - pfix_chld="$prefix$b" - if [[ -n "$last" ]]; then + if [[ -z "$last" ]]; then + pfix_self="$prefix$a" + pfix_chld="$prefix$b" + else pfix_self="$prefix$c" + pfix_chld="$prefix$d" fi fi printf "%s$(_ '%s\t(%s)')\n" "$pfix_self" "$name" "$id" if [[ "$id" == d:* ]]; then local lastname - lastname="$("$RVS" get.d "$id" /dev/stdout | sed -n '$/.*\t//p')" + lastname="$("$RVS" blobs/get.f "$id" /dev/stdout| sed -n $'$s/.*\t//p')" local perm user group id name + IFS=$'\t' while read -r perm user group id name; do if [[ "$name" != "$lastname" ]]; then - "$RVS" tree "$id" "$name" "$pfix_chld" + "$RVS" blobs/tree "$id" "$name" "$pfix_chld" else - "$RVS" tree "$id" "$name" "$pfix_chld" t + "$RVS" blobs/tree "$id" "$name" "$pfix_chld" t fi - done < <("$RVS" get.d "$id" /dev/stdout) + done < <("$RVS" blobs/get.f "$id" /dev/stdout) fi } diff --git a/wrapper/inner.sh.m4 b/wrapper/inner.sh.m4 index 09c870d..bd67f02 100644 --- a/wrapper/inner.sh.m4 +++ b/wrapper/inner.sh.m4 @@ -64,17 +64,25 @@ errusage() { } _runcmd() { - [[ $# -ge 1 ]] || errusage 1 'Usage: %q []' + [[ $# -ge 1 ]] || errusage 1 'Usage: %q [/] []' + local mod='' local cmd=$1; shift local args_str='' [[ $# -eq 0 ]] || printf -v args_str '%q ' "$@" local exec_path="${!varname_EXEC_PATH:-$pkglibexecdir}" + if [[ "$cmd" == */* ]]; then + if ! [[ -f "${exec_path}/modules/$cmd" ]]; then + error 127 'Module/Command not found: %s' "$cmd" + fi + mod="${cmd%%/*}" + cmd="${cmd#*/}" + fi shopt -s nullglob local files=("${exec_path}"/modules/*/"$cmd") if [[ ${#files[@]} -eq 0 ]]; then - error 127 'Command not found: %s'"$cmd" + error 127 'Command not found: %s' "$cmd" fi files=("${files[@]#"${exec_path}/modules/"}") @@ -90,15 +98,22 @@ _runcmd() { local cwd printf -v cwd '%q' "$PWD" - make -j1 --no-print-directory --quiet \ + make --no-print-directory --quiet \ -f "$exec_path/runcmd.mk" \ -C "$tmpdir/output" \ CWD="$cwd" \ - ARGS="$args_str" \ + ARGS="${args_str//'$'/'$$'}" \ EXEC_PATH="$exec_path" \ TMPDIR="$tmpdir" \ -- "${files[@]}" - exit $? + local r=$? + cd "$tmpdir/output" + if [[ -n "$mod" ]]; then + cat "$mod/$cmd" + else + grep -r ^ * + fi + return $r } _repo() { diff --git a/wrapper/runcmd.mk b/wrapper/runcmd.mk index 40e791e..407ffdc 100644 --- a/wrapper/runcmd.mk +++ b/wrapper/runcmd.mk @@ -11,6 +11,6 @@ export OUTPUT_DIR := $(realpath .) $(MAKECMDGOALS): % : $(EXEC_PATH)/modules/% mkdir -p -- '$(@D)' - { (cd $(CWD) && '$<' $(ARGS)) | tee -- '$@' >&2; } 2>&1 | sed 's,^,$@:,' >&2 + +(cd $(CWD) && '$<' $(ARGS)) > '$@' include $(wildcard $(EXEC_PATH)/modules/*.mk) -- cgit v1.1-4-g5e80