commit e41adfeaab6dffd8c87b91d6a3d939c1fd80cf99
parent 44d1226fe37446fecb092d1bed4e89eec159013f
Author: Vincent Forest <vincent.forest@meso-star.com>
Date: Wed, 1 May 2024 14:35:36 +0200
Updating the logging strategy
Until now, the log function controlled the conditional printing of
messages according to the GIT_WAD_VERBOSE variable. Now, only messages
from the clean and smudge filters are printed conditionally, as these
are the only ones whose main purpose is debugging, and are therefore
dispensable. All other messages are part of the normal output, such as
error messages notifying user input errors or unexpected behavior.
In addition, the GIT_WAD_VERBOSE variable can now be controlled by the
user.
Diffstat:
| M | git-wad | | | 44 | +++++++++++++++++++++----------------------- |
| M | git-wad.1 | | | 9 | ++++++++- |
2 files changed, 29 insertions(+), 24 deletions(-)
diff --git a/git-wad b/git-wad
@@ -27,11 +27,9 @@ fi
GIT_WAD_HEADER="#\$# git-wad"
GIT_WAD_OBJDIR=".git/wad"
-GIT_WAD_VERBOSE=1
-########################################################################
-# Helper functions
-########################################################################
+[ -z "${GIT_WAD_VERBOSE}" ] && GIT_WAD_VERBOSE=0
+
if [ -z "${GIT_WAD_REMOTE_FETCH}" ] \
&& git remote | grep -qe "^origin$"; then
GIT_WAD_REMOTE_FETCH="$(git remote get-url origin)"
@@ -61,14 +59,6 @@ is_init()
&& git config --get filter.wad.smudge > /dev/null
}
-log() # str [, arg...]
-{
- if [ -n "${GIT_WAD_VERBOSE}" ] && [ ! "${GIT_WAD_VERBOSE}" -eq 0 ]; then
- # shellcheck disable=SC2059
- >&2 printf "$@"
- fi
-}
-
sizeof_header()
{
printf "%s" "${GIT_WAD_HEADER}" | wc -c
@@ -129,7 +119,7 @@ wad_objects() # [-1a]
1) rev="HEAD -1" ;; # Last commit only
a) rev="--all" ;;
*)
- >&2 log "Invalid option %s\n" "$1"
+ >&2 printf "Invalid option %s\n" "$1"
return 1
;;
esac
@@ -210,14 +200,14 @@ restore() # WAD file
digest=$(sed "s/^${GIT_WAD_HEADER} \([0-9a-z]\{64\}\) [0-9]\{1,\}$/\1/" "${wad}")
if [ -z "${digest}" ]; then
- log "Invalid WAD file %s\n" "$1"
+ >&2 printf "Invalid WAD file %s\n" "$1"
return 1
fi
if [ ! -f "${GIT_WAD_OBJDIR}"/"${digest}" ]; then
- log "WAD object unavailable %s %s\n" "${digest}" "${wad}"
+ >&2 printf "WAD object unavailable %s %s\n" "${digest}" "${wad}"
else
- log "Restoring %s\n" "${wad}"
+ >&2 printf "Restoring %s\n" "${wad}"
# Forces re-execution of the smudge filter to restore the WAD file.
# Note that git caches the state of the last time the file was
@@ -236,6 +226,14 @@ restore() # WAD file
########################################################################
# Git filters (plumbing)
########################################################################
+log() # str [, arg...]
+{
+ if [ -n "${GIT_WAD_VERBOSE}" ] && [ ! "${GIT_WAD_VERBOSE}" -eq 0 ]; then
+ # shellcheck disable=SC2059
+ >&2 printf "$@"
+ fi
+}
+
clean() # stdin
{
tmpfile="$(mktemp -p "${GIT_WAD_OBJDIR}")"
@@ -314,11 +312,11 @@ init()
{
# shellcheck disable=SC2310
if is_init; then
- log "git-wad is already initialized (check .git/config)\n"
+ >&2 printf "git-wad is already initialized (check .git/config)\n"
else
git config filter.wad.clean "git-wad filter-clean"
git config filter.wad.smudge "git-wad filter-smudge"
- log "git-wad is initialized\n"
+ >&2 printf "git-wad is initialized\n"
fi
}
@@ -326,11 +324,11 @@ init()
push() # [-1a]
{
if [ -z "${GIT_WAD_REMOTE_PUSH}" ]; then
- log "Remote undefined, i.e. variable GIT_WAD_REMOTE_PUSH is empty\n"
+ >&2 printf "Remote undefined, i.e. variable GIT_WAD_REMOTE_PUSH is empty\n"
return 1
fi
- log "Pushing to %s\n" "${GIT_WAD_REMOTE_PUSH}"
+ >&2 printf "Pushing to %s\n" "${GIT_WAD_REMOTE_PUSH}"
remote="${GIT_WAD_REMOTE_FETCH#file://}"
objects_to_push "$@" | rsync -av --progress --ignore-existing \
@@ -341,11 +339,11 @@ push() # [-1a]
fetch() # [-1a]
{
if [ -z "${GIT_WAD_REMOTE_FETCH}" ]; then
- log "Remote undefined, i.e. variable GIT_WAD_REMOTE_FETCH is empty\n"
+ >&2 printf "Remote undefined, i.e. variable GIT_WAD_REMOTE_FETCH is empty\n"
return 1
fi
- log "Fetching from %s\n" "${GIT_WAD_REMOTE_FETCH}"
+ >&2 printf "Fetching from %s\n" "${GIT_WAD_REMOTE_FETCH}"
# Use curl to download WAD objects via http[s] or gopher[s] protocol
if echo "${GIT_WAD_REMOTE_FETCH}" | grep -q \
@@ -386,7 +384,7 @@ prune() # [-1a]
{
unreferenced_objects "$@" \
| xargs -I {} sh -c \
- "printf \"Removing %s\n\" \"${GIT_WAD_OBJDIR}/{}\"; \
+ ">&2 printf \"Removing %s\n\" \"${GIT_WAD_OBJDIR}/{}\"; \
rm -f \"${GIT_WAD_OBJDIR}/{}\""
}
diff --git a/git-wad.1 b/git-wad.1
@@ -12,7 +12,7 @@
.\"
.\" You should have received a copy of the GNU General Public License
.\" along with this program. If not, see <http://www.gnu.org/licenses/>.
-.Dd February 18, 2024
+.Dd May 1, 2024
.Dt GIT-WAD 1
.Os
.Sh NAME
@@ -176,6 +176,13 @@ which WAD file data is transfered.
By default, this is the push URL of the
.Li origin
git repository.
+.It Ev GIT_WAD_VERBOSE
+Causes
+.Nm
+to print debugging messages.
+The default value is
+.Li 0 ,
+i.e. no debug messages are printed.
.El
.Sh FILES
.Bl -tag -width Ds