forked from AFPy/python-docs-fr
76 lines
1.8 KiB
Bash
Executable File
76 lines
1.8 KiB
Bash
Executable File
#!/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" = "-n" ] || [ "$1" = "--no-edit" ]; then
|
|
LAUNCH_EDIT=0
|
|
else
|
|
_usage
|
|
fi
|
|
shift
|
|
fi
|
|
|
|
if [ $# -ne 1 ]; then
|
|
_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
|
|
|
|
|
|
PO_EDITOR=poedit
|
|
DIFFTOOL=$(which $(git config diff.tool))
|
|
|
|
if [ ! -x "$DIFFTOOL" ]; then
|
|
echo "git diff.tool seems not configured"
|
|
_usage
|
|
fi
|
|
|
|
PO_FILE=$1
|
|
|
|
if [ ${LAUNCH_EDIT} -eq 1 ]; then
|
|
${PO_EDITOR} "${PO_FILE}" 2>/dev/null &
|
|
fi
|
|
|
|
while read line ; do
|
|
gdh=$(date --date=@${line:0:10})
|
|
sha=${line:11:40}
|
|
author=${line:52}
|
|
echo "Comparing with: ${gdh} - ${author}"
|
|
# filter files à la mode textconv
|
|
git show ${sha}^:${PO_FILE} | \
|
|
grep --invert-match \
|
|
--regexp='^#:' \
|
|
--regexp='^"PO' > "${TMP_DIR}/${gdh}.po"
|
|
# reload current file every time as it may has been modified
|
|
grep --invert-match \
|
|
--regexp='^#:' \
|
|
--regexp='^"PO' ${PO_FILE} > ${TMP_DIR}/current.po
|
|
"${DIFFTOOL}" "${TMP_DIR}/${gdh}.po" ${TMP_DIR}/current.po
|
|
done <<< $(git blame --line-porcelain ${PO_FILE} | \
|
|
awk '/^[0-9a-f]{40} / { sha=$1 }
|
|
/^author / {$1="" ; author=$0 }
|
|
/^committer-time / { $1="" ; date=$0 }
|
|
/^\s#, fuzzy/ { printf "%-10s %-40s %s\n", date, sha, author}' |
|
|
sort --numeric-sort --unique --reverse)
|
|
|
|
# clean up temp directory
|
|
rm --force --recursive "${TMP_DIR}"
|
|
trap - EXIT
|
|
|