From 8c1b42667ec8bd32622cfa3dc546434fb6cbf7e3 Mon Sep 17 00:00:00 2001 From: Christophe Nanteuil Date: Sun, 14 May 2023 12:41:02 +0200 Subject: [PATCH] Simple tool to ease resolving fuzzies --- .scripts/fuzzy_diff | 40 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 40 insertions(+) create mode 100755 .scripts/fuzzy_diff diff --git a/.scripts/fuzzy_diff b/.scripts/fuzzy_diff new file mode 100755 index 00000000..bc608bb6 --- /dev/null +++ b/.scripts/fuzzy_diff @@ -0,0 +1,40 @@ +#!/bin/sh + +if [[ $# -ne 1 ]]; then + echo "usage: $0 PO_FILE" + echo "Ease the correction of fuzzies inserted by merge commits" + exit +fi + +# Temp directory to filter files before display +TMP_DIR=$(mktemp -d /tmp/fuzzy_diff.XXXXXX || exit 1) +trap 'rm --force --recursive "$TMP_DIR"' EXIT + + +PO_EDITOR=$(which poedit) +DIFFTOOL=$(which meld) +PO_FILE=$1 + +# search for revs where fuzzy was added or suppressed +# and filter where commit message contains 'merge' +FUZZY_REVS=$(git log --oneline -S '#, fuzzy' ${PO_FILE} | \ + grep -i 'merge' | \ + awk '{ print $1 }') + +{PO_EDITOR} ${PO_FILE} 2>/dev/null & +for sha in ${FUZZY_REVS} ; do + # show the diff between parent rev and fuzzy rev + + # simple version which includes all modifications + #git difftool --no-prompt ${sha}^ ${sha} -- ${PO_FILE} + + # filter files à la mode textconv + git show ${sha}:${PO_FILE} | grep -v -e '^#:' -e '^"PO' > ${TMP_DIR}/right.po + git show ${sha}^:${PO_FILE} | grep -v -e '^#:' -e '^"PO' > ${TMP_DIR}/left.po + ${DIFFTOOL} ${TMP_DIR}/left.po ${TMP_DIR}/right.po +done + +# clean up temp directory +rm --force --recursive "$TMP_DIR" +trap - EXIT +