]> Untitled Git - hvutilities.git/commitdiff
hv-rsync: improve diff output
authorHugo Villeneuve <hugo@hugovil.co>
Thu, 2 Apr 2026 17:57:00 +0000 (13:57 -0400)
committerHugo Villeneuve <hugo@hugovil.com>
Thu, 2 Apr 2026 23:34:04 +0000 (19:34 -0400)
scripts/hv-rsync.sh

index 1f01802975803b3d5c01a9502b6f354563da5f5f..48845829a880fef9481bd3efcf962b5038c21ded 100755 (executable)
@@ -4,6 +4,8 @@ PROG_NAME=$(basename $0)
 
 HVRSYNC_CONF=${HOME}/.hv-rsync.conf
 
+RSYNC_DIFF_OPTS="-avun --itemize-changes --size-only --delete"
+
 print_usage()
 {
     echo "${PROG_NAME} -- synchronisation serveur RSYNC"
@@ -77,6 +79,25 @@ fi
 #     files, modification times, groups, owners, and permissions.
 # -n: dry-run
 
+delete_target=""
+
+rsync_itemize_parser()
+{
+    local stdin
+
+    read -d '' -u 0 stdin
+
+    # Show lines starting with >, <, c, or * (deletions), effectively
+    # hiding entries that were only checked but not changed:
+    #   grep -E '^([<>c\*])'
+    printf "%s\n" "$stdin" | \
+        grep -E '^([<>c\*])' | \
+        sed -e "s/^\*deleting\s\+/[${delete_target} DEL] /" | \
+        sed -e "s/^<[fLd][.cstpoaguax+]\{9\}/[SEND]      /" | \
+        sed -e "s/^>[fLd][.cstpoaguax+]\{9\}/[RECV]      /" | \
+        sed -e "s/^cd[.cstpoaguax+]\{9\}/[${delete_target} DIR]/"
+}
+
 for f in ${rsync_list}; do
     if [ x"${mode}" = x"diff" ]; then
 
@@ -86,18 +107,17 @@ for f in ${rsync_list}; do
         fi
 
         echo "Diff (push) for folder ${RSYNC_REMOTE_DIR}/${f}:"
-
-        rsync -avun --delete \
-              "${RSYNC_LOCAL_DIR}/${f}/" \
+        delete_target="REMOTE"
+        rsync ${RSYNC_DIFF_OPTS} "${RSYNC_LOCAL_DIR}/${f}/" \
               ${RSYNC_USER}@${RSYNC_SERVER}:"${RSYNC_REMOTE_DIR}/${f}" | \
-            grep "^deleting "
+              rsync_itemize_parser
 
         echo "Diff (pull) for folder ${RSYNC_REMOTE_DIR}/${f}:"
+        delete_target="LOCAL "
+        rsync ${RSYNC_DIFF_OPTS} ${RSYNC_USER}@${RSYNC_SERVER}:"${RSYNC_REMOTE_DIR}/${f}/" \
+            "${RSYNC_LOCAL_DIR}/${f}" | \
+            rsync_itemize_parser
 
-        rsync -avun --delete \
-              ${RSYNC_USER}@${RSYNC_SERVER}:"${RSYNC_REMOTE_DIR}/${f}/" \
-              "${RSYNC_LOCAL_DIR}/${f}" | \
-            grep "^deleting "
     elif [ x"${mode}" = x"pull" ]; then
         echo "RSYNC for folder ${RSYNC_REMOTE_DIR}/${f}:"
         mkdir -p ${RSYNC_LOCAL_DIR}/${f}