From 8c1b42667ec8bd32622cfa3dc546434fb6cbf7e3 Mon Sep 17 00:00:00 2001 From: Christophe Nanteuil Date: Sun, 14 May 2023 12:41:02 +0200 Subject: [PATCH 1/4] 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 + -- 2.30.2 From e845e438470ce38d6110e7c35640bc329a252c38 Mon Sep 17 00:00:00 2001 From: Christophe Nanteuil Date: Sun, 14 May 2023 15:05:12 +0200 Subject: [PATCH 2/4] using git config diff.tool as difftool --- .scripts/fuzzy_diff | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.scripts/fuzzy_diff b/.scripts/fuzzy_diff index bc608bb6..a8a4c21e 100755 --- a/.scripts/fuzzy_diff +++ b/.scripts/fuzzy_diff @@ -12,7 +12,7 @@ trap 'rm --force --recursive "$TMP_DIR"' EXIT PO_EDITOR=$(which poedit) -DIFFTOOL=$(which meld) +DIFFTOOL=$(git config diff.tool) PO_FILE=$1 # search for revs where fuzzy was added or suppressed -- 2.30.2 From 2505128f8edeeb72bec8dc522959979da9c245f8 Mon Sep 17 00:00:00 2001 From: Christophe Nanteuil Date: Tue, 16 May 2023 21:25:54 +0200 Subject: [PATCH 3/4] Launching po editor is optional removed simple git diff in favor of textconv variant --- .scripts/fuzzy_diff | 46 ++++++++++++++++++++++++++++++++------------- 1 file changed, 33 insertions(+), 13 deletions(-) diff --git a/.scripts/fuzzy_diff b/.scripts/fuzzy_diff index a8a4c21e..76695b0c 100755 --- a/.scripts/fuzzy_diff +++ b/.scripts/fuzzy_diff @@ -1,17 +1,39 @@ #!/bin/sh + +_usage() { + echo "Usage: $0 [-n] PO_FILE" + echo "Ease the correction of fuzzies inserted by merge commits" + echo + echo "-n, --no-edit do not launch po editor" + exit +} + +LAUNCH_EDIT=1 +if [[ $# -eq 2 ]]; then + if [[ $1 -eq "-n" ]] || [[ $1 -eq "--no-edit" ]]; then + LAUNCH_EDIT=0 + else + _usage + fi + shift +fi + if [[ $# -ne 1 ]]; then - echo "usage: $0 PO_FILE" - echo "Ease the correction of fuzzies inserted by merge commits" - exit + _usage +fi + +if [[ ! -f $1 ]]; then + echo "$1: file not found" + _usage 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 +trap 'rm --force --recursive "${TMP_DIR}"' EXIT -PO_EDITOR=$(which poedit) +PO_EDITOR=poedit DIFFTOOL=$(git config diff.tool) PO_FILE=$1 @@ -21,20 +43,18 @@ FUZZY_REVS=$(git log --oneline -S '#, fuzzy' ${PO_FILE} | \ grep -i 'merge' | \ awk '{ print $1 }') -{PO_EDITOR} ${PO_FILE} 2>/dev/null & +if [[ ${LAUNCH_EDIT} -eq 1 ]]; then + ${PO_EDITOR} "${PO_FILE}" 2>/dev/null & +fi + 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 + "${DIFFTOOL}" ${TMP_DIR}/left.po ${TMP_DIR}/right.po done # clean up temp directory -rm --force --recursive "$TMP_DIR" +rm --force --recursive "${TMP_DIR}" trap - EXIT -- 2.30.2 From 759c9fa4a82c1480975096e83709f5e632eeb11b Mon Sep 17 00:00:00 2001 From: christopheNan Date: Tue, 23 May 2023 21:44:14 +0200 Subject: [PATCH 4/4] syntaxe sh et non bash. Merci @mdk --- .scripts/fuzzy_diff | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-) diff --git a/.scripts/fuzzy_diff b/.scripts/fuzzy_diff index 76695b0c..30251a64 100755 --- a/.scripts/fuzzy_diff +++ b/.scripts/fuzzy_diff @@ -10,8 +10,8 @@ _usage() { } LAUNCH_EDIT=1 -if [[ $# -eq 2 ]]; then - if [[ $1 -eq "-n" ]] || [[ $1 -eq "--no-edit" ]]; then +if [ $# -eq 2 ]; then + if [ "$1" -eq "-n" ] || [ "$1" -eq "--no-edit" ]; then LAUNCH_EDIT=0 else _usage @@ -19,11 +19,11 @@ if [[ $# -eq 2 ]]; then shift fi -if [[ $# -ne 1 ]]; then +if [ $# -ne 1 ]; then _usage fi -if [[ ! -f $1 ]]; then +if [ ! -f "$1" ]; then echo "$1: file not found" _usage fi @@ -34,7 +34,13 @@ trap 'rm --force --recursive "${TMP_DIR}"' EXIT PO_EDITOR=poedit -DIFFTOOL=$(git config diff.tool) +DIFFTOOL=$(which $(git config diff.tool)) + +if [ ! -x "$DIFFTOOL" ]; then + echo "git diff.tool seems not configured" + _usage +fi + PO_FILE=$1 # search for revs where fuzzy was added or suppressed @@ -43,7 +49,7 @@ FUZZY_REVS=$(git log --oneline -S '#, fuzzy' ${PO_FILE} | \ grep -i 'merge' | \ awk '{ print $1 }') -if [[ ${LAUNCH_EDIT} -eq 1 ]]; then +if [ ${LAUNCH_EDIT} -eq 1 ]; then ${PO_EDITOR} "${PO_FILE}" 2>/dev/null & fi -- 2.30.2